tizen 2.3 release
[framework/multimedia/gst-plugins-base0.10.git] / tests / icles / test-scale.c
1 /* GStreamer interactive videoscale test
2  * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <stdlib.h>
25
26 #include <gst/gst.h>
27
28 static GstElement *
29 make_pipeline (gint type)
30 {
31   GstElement *result;
32   gchar *pstr;
33
34   switch (type) {
35     case 0:
36       pstr = g_strdup_printf ("videotestsrc ! capsfilter name=filter ! "
37           "ximagesink");
38       break;
39     case 1:
40       pstr = g_strdup_printf ("videotestsrc ! queue ! capsfilter name=filter ! "
41           "ximagesink");
42       break;
43     case 2:
44       pstr = g_strdup_printf ("videotestsrc peer-alloc=0 ! videoscale ! "
45           "capsfilter name=filter ! " "ximagesink");
46       break;
47     case 3:
48       pstr =
49           g_strdup_printf ("videotestsrc peer-alloc=0 ! queue ! videoscale ! "
50           "capsfilter name=filter ! " "ximagesink");
51       break;
52     case 4:
53       pstr =
54           g_strdup_printf ("videotestsrc peer-alloc=0 ! videoscale ! queue ! "
55           "capsfilter name=filter ! " "ximagesink");
56       break;
57     case 5:
58       pstr = g_strdup_printf ("videotestsrc peer-alloc=0 ! "
59           "capsfilter name=filter ! " "ximagesink");
60       break;
61     case 6:
62       pstr = g_strdup_printf ("videotestsrc ! videoscale ! "
63           "capsfilter name=filter ! " "ximagesink");
64       break;
65     case 7:
66       pstr = g_strdup_printf ("v4l2src ! ffmpegcolorspace ! videoscale ! "
67           "capsfilter name=filter ! " "ximagesink");
68       break;
69     default:
70       return NULL;
71   }
72
73   result = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL);
74   g_print ("created test %d: \"%s\"\n", type, pstr);
75   g_free (pstr);
76
77   return result;
78 }
79
80 #define MAX_ROUND 100
81
82 int
83 main (int argc, char **argv)
84 {
85   GstElement *pipe, *filter;
86   GstCaps *caps;
87   gint width, height;
88   gint xdir, ydir;
89   gint round, type, stop;
90
91   gst_init (&argc, &argv);
92
93   type = 0;
94   stop = -1;
95
96   if (argc > 1) {
97     type = atoi (argv[1]);
98     stop = type + 1;
99   }
100
101   while (TRUE) {
102     GstMessage *message;
103
104     pipe = make_pipeline (type);
105     if (pipe == NULL)
106       break;
107
108     filter = gst_bin_get_by_name (GST_BIN (pipe), "filter");
109     g_assert (filter);
110
111     width = 320;
112     height = 240;
113     xdir = ydir = -10;
114
115     for (round = 0; round < MAX_ROUND; round++) {
116       gchar *capsstr;
117       g_print ("resize to %dx%d (%d/%d)   \r", width, height, round, MAX_ROUND);
118
119       /* we prefer our fixed width and height but allow other dimensions to pass
120        * as well */
121       capsstr =
122           g_strdup_printf ("video/x-raw-rgb, width=(int)%d, height=(int)%d;"
123           "video/x-raw-rgb", width, height);
124       caps = gst_caps_from_string (capsstr);
125       g_free (capsstr);
126       g_object_set (filter, "caps", caps, NULL);
127       gst_caps_unref (caps);
128
129       if (round == 0)
130         gst_element_set_state (pipe, GST_STATE_PLAYING);
131
132       width += xdir;
133       if (width >= 320)
134         xdir = -10;
135       else if (width < 200)
136         xdir = 10;
137
138       height += ydir;
139       if (height >= 240)
140         ydir = -10;
141       else if (height < 150)
142         ydir = 10;
143
144       message =
145           gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR,
146           50 * GST_MSECOND);
147       if (message) {
148         g_print ("got error           \n");
149
150         gst_message_unref (message);
151       }
152     }
153     g_print ("test %d done                    \n", type);
154
155     gst_object_unref (filter);
156     gst_element_set_state (pipe, GST_STATE_NULL);
157     gst_object_unref (pipe);
158
159     type++;
160     if (type == stop)
161       break;
162   }
163   return 0;
164 }