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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, 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 #define CAPS " capsfilter caps=\"video/x-raw, format=(string)I420, width=(int)640, height=(int)480\" "
29
30 static GstElement *
make_pipeline(gint type)31 make_pipeline (gint type)
32 {
33 GstElement *result;
34 gchar *pstr;
35
36 switch (type) {
37 case 0:
38 pstr =
39 g_strdup_printf ("videotestsrc ! " CAPS
40 " ! videobox name=box ! videoscale ! " CAPS
41 " ! videoconvert ! ximagesink");
42 break;
43 default:
44 return NULL;
45 }
46
47 result = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL);
48 g_print ("created test %d: \"%s\"\n", type, pstr);
49 g_free (pstr);
50
51 return result;
52 }
53
54 #define MAX_ROUND 100
55
56 int
main(int argc,char ** argv)57 main (int argc, char **argv)
58 {
59 GstElement *pipe, *filter;
60 gint left, right;
61 gint top, bottom;
62 gint rdir, ldir;
63 gint tdir, bdir;
64 gint round, type, stop;
65
66 gst_init (&argc, &argv);
67
68 type = 0;
69 stop = -1;
70
71 if (argc > 1) {
72 type = atoi (argv[1]);
73 stop = type + 1;
74 }
75
76 while (TRUE) {
77 GstMessage *message;
78
79 pipe = make_pipeline (type);
80 if (pipe == NULL)
81 break;
82
83 filter = gst_bin_get_by_name (GST_BIN (pipe), "box");
84 g_assert (filter);
85
86 /* start with no borders or cropping */
87 left = right = top = bottom = 0;
88 rdir = ldir = tdir = bdir = -10;
89
90 for (round = 0; round < MAX_ROUND; round++) {
91 g_print ("box to %dx%d %dx%d (%d/%d) \r", left, right, top, bottom,
92 round, MAX_ROUND);
93
94 g_object_set (filter, "left", left, "right", right, "top", top, "bottom",
95 bottom, NULL);
96
97 if (round == 0)
98 gst_element_set_state (pipe, GST_STATE_PLAYING);
99
100 left += ldir;
101 if (left >= 40)
102 ldir = -10;
103 else if (left < -30)
104 ldir = 10;
105
106 right += rdir;
107 if (right >= 30)
108 rdir = -10;
109 else if (right < -20)
110 rdir = 10;
111
112 top += tdir;
113 if (top >= 20)
114 tdir = -10;
115 else if (top < -30)
116 tdir = 10;
117
118 bottom += bdir;
119 if (bottom >= 60)
120 bdir = -10;
121 else if (bottom < -40)
122 bdir = 10;
123
124 message =
125 gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR,
126 50 * GST_MSECOND);
127 if (message) {
128 g_print ("got error \n");
129
130 gst_message_unref (message);
131 }
132 }
133 g_print ("test %d done \n", type);
134
135 gst_object_unref (filter);
136 gst_element_set_state (pipe, GST_STATE_NULL);
137 gst_object_unref (pipe);
138
139 type++;
140 if (type == stop)
141 break;
142 }
143 return 0;
144 }
145