2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2002> David A. Schleef <ds@schleef.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * SECTION:element-videotestsrc
24 * The videotestsrc element is used to produce test video data in a wide variety
25 * of formats. The video test data produced can be controlled with the "pattern"
29 * <title>Example launch line</title>
31 * gst-launch -v videotestsrc pattern=snow ! ximagesink
32 * ]| Shows random noise in an X window.
39 #include "gstvideotestsrc.h"
40 #include "gstvideotestsrcorc.h"
41 #include "videotestsrc.h"
46 GST_DEBUG_CATEGORY_STATIC (video_test_src_debug);
47 #define GST_CAT_DEFAULT video_test_src_debug
49 #define DEFAULT_PATTERN GST_VIDEO_TEST_SRC_SMPTE
50 #define DEFAULT_TIMESTAMP_OFFSET 0
51 #define DEFAULT_IS_LIVE FALSE
52 #define DEFAULT_COLOR_SPEC GST_VIDEO_TEST_SRC_BT601
53 #define DEFAULT_FOREGROUND_COLOR 0xffffffff
54 #define DEFAULT_BACKGROUND_COLOR 0xff000000
55 #define DEFAULT_HORIZONTAL_SPEED 0
61 PROP_TIMESTAMP_OFFSET,
75 PROP_FOREGROUND_COLOR,
76 PROP_BACKGROUND_COLOR,
77 PROP_HORIZONTAL_SPEED,
82 #define VTS_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) ";" \
83 "video/x-bayer, format=(string) { bggr, rggb, grbg, gbrg }, " \
84 "width = " GST_VIDEO_SIZE_RANGE ", " \
85 "height = " GST_VIDEO_SIZE_RANGE ", " \
86 "framerate = " GST_VIDEO_FPS_RANGE
89 static GstStaticPadTemplate gst_video_test_src_template =
90 GST_STATIC_PAD_TEMPLATE ("src",
93 GST_STATIC_CAPS (VTS_VIDEO_CAPS)
96 #define gst_video_test_src_parent_class parent_class
97 G_DEFINE_TYPE (GstVideoTestSrc, gst_video_test_src, GST_TYPE_PUSH_SRC);
99 static void gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
101 static void gst_video_test_src_set_property (GObject * object, guint prop_id,
102 const GValue * value, GParamSpec * pspec);
103 static void gst_video_test_src_get_property (GObject * object, guint prop_id,
104 GValue * value, GParamSpec * pspec);
106 static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
107 static GstCaps *gst_video_test_src_src_fixate (GstBaseSrc * bsrc,
110 static gboolean gst_video_test_src_is_seekable (GstBaseSrc * psrc);
111 static gboolean gst_video_test_src_do_seek (GstBaseSrc * bsrc,
112 GstSegment * segment);
113 static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
115 static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
116 GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
117 static gboolean gst_video_test_src_decide_allocation (GstBaseSrc * bsrc,
119 static GstFlowReturn gst_video_test_src_fill (GstPushSrc * psrc,
121 static gboolean gst_video_test_src_start (GstBaseSrc * basesrc);
122 static gboolean gst_video_test_src_stop (GstBaseSrc * basesrc);
124 #define GST_TYPE_VIDEO_TEST_SRC_PATTERN (gst_video_test_src_pattern_get_type ())
126 gst_video_test_src_pattern_get_type (void)
128 static GType video_test_src_pattern_type = 0;
129 static const GEnumValue pattern_types[] = {
130 {GST_VIDEO_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
131 {GST_VIDEO_TEST_SRC_SNOW, "Random (television snow)", "snow"},
132 {GST_VIDEO_TEST_SRC_BLACK, "100% Black", "black"},
133 {GST_VIDEO_TEST_SRC_WHITE, "100% White", "white"},
134 {GST_VIDEO_TEST_SRC_RED, "Red", "red"},
135 {GST_VIDEO_TEST_SRC_GREEN, "Green", "green"},
136 {GST_VIDEO_TEST_SRC_BLUE, "Blue", "blue"},
137 {GST_VIDEO_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
138 {GST_VIDEO_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
139 {GST_VIDEO_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
140 {GST_VIDEO_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
141 {GST_VIDEO_TEST_SRC_CIRCULAR, "Circular", "circular"},
142 {GST_VIDEO_TEST_SRC_BLINK, "Blink", "blink"},
143 {GST_VIDEO_TEST_SRC_SMPTE75, "SMPTE 75% color bars", "smpte75"},
144 {GST_VIDEO_TEST_SRC_ZONE_PLATE, "Zone plate", "zone-plate"},
145 {GST_VIDEO_TEST_SRC_GAMUT, "Gamut checkers", "gamut"},
146 {GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE, "Chroma zone plate",
147 "chroma-zone-plate"},
148 {GST_VIDEO_TEST_SRC_SOLID, "Solid color", "solid-color"},
149 {GST_VIDEO_TEST_SRC_BALL, "Moving ball", "ball"},
150 {GST_VIDEO_TEST_SRC_SMPTE100, "SMPTE 100% color bars", "smpte100"},
151 {GST_VIDEO_TEST_SRC_BAR, "Bar", "bar"},
155 if (!video_test_src_pattern_type) {
156 video_test_src_pattern_type =
157 g_enum_register_static ("GstVideoTestSrcPattern", pattern_types);
159 return video_test_src_pattern_type;
163 gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
165 GObjectClass *gobject_class;
166 GstElementClass *gstelement_class;
167 GstBaseSrcClass *gstbasesrc_class;
168 GstPushSrcClass *gstpushsrc_class;
170 gobject_class = (GObjectClass *) klass;
171 gstelement_class = (GstElementClass *) klass;
172 gstbasesrc_class = (GstBaseSrcClass *) klass;
173 gstpushsrc_class = (GstPushSrcClass *) klass;
175 gobject_class->set_property = gst_video_test_src_set_property;
176 gobject_class->get_property = gst_video_test_src_get_property;
178 g_object_class_install_property (gobject_class, PROP_PATTERN,
179 g_param_spec_enum ("pattern", "Pattern",
180 "Type of test pattern to generate", GST_TYPE_VIDEO_TEST_SRC_PATTERN,
181 DEFAULT_PATTERN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
182 g_object_class_install_property (gobject_class, PROP_TIMESTAMP_OFFSET,
183 g_param_spec_int64 ("timestamp-offset", "Timestamp offset",
184 "An offset added to timestamps set on buffers (in ns)", G_MININT64,
185 G_MAXINT64, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
186 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
187 g_param_spec_boolean ("is-live", "Is Live",
188 "Whether to act as a live source", DEFAULT_IS_LIVE,
189 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
190 g_object_class_install_property (gobject_class, PROP_K0,
191 g_param_spec_int ("k0", "Zoneplate zero order phase",
192 "Zoneplate zero order phase, for generating plain fields or phase offsets",
193 G_MININT32, G_MAXINT32, 0,
194 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
195 g_object_class_install_property (gobject_class, PROP_KX,
196 g_param_spec_int ("kx", "Zoneplate 1st order x phase",
197 "Zoneplate 1st order x phase, for generating constant horizontal frequencies",
198 G_MININT32, G_MAXINT32, 0,
199 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
200 g_object_class_install_property (gobject_class, PROP_KY,
201 g_param_spec_int ("ky", "Zoneplate 1st order y phase",
202 "Zoneplate 1st order y phase, for generating contant vertical frequencies",
203 G_MININT32, G_MAXINT32, 0,
204 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
205 g_object_class_install_property (gobject_class, PROP_KT,
206 g_param_spec_int ("kt", "Zoneplate 1st order t phase",
207 "Zoneplate 1st order t phase, for generating phase rotation as a function of time",
208 G_MININT32, G_MAXINT32, 0,
209 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
210 g_object_class_install_property (gobject_class, PROP_KXT,
211 g_param_spec_int ("kxt", "Zoneplate x*t product phase",
212 "Zoneplate x*t product phase, normalised to kxy/256 cycles per vertical pixel at width/2 from origin",
213 G_MININT32, G_MAXINT32, 0,
214 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
215 g_object_class_install_property (gobject_class, PROP_KYT,
216 g_param_spec_int ("kyt", "Zoneplate y*t product phase",
217 "Zoneplate y*t product phase", G_MININT32, G_MAXINT32, 0,
218 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
219 g_object_class_install_property (gobject_class, PROP_KXY,
220 g_param_spec_int ("kxy", "Zoneplate x*y product phase",
221 "Zoneplate x*y product phase", G_MININT32, G_MAXINT32, 0,
222 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
223 g_object_class_install_property (gobject_class, PROP_KX2,
224 g_param_spec_int ("kx2", "Zoneplate 2nd order x phase",
225 "Zoneplate 2nd order x phase, normalised to kx2/256 cycles per horizontal pixel at width/2 from origin",
226 G_MININT32, G_MAXINT32, 0,
227 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
228 g_object_class_install_property (gobject_class, PROP_KY2,
229 g_param_spec_int ("ky2", "Zoneplate 2nd order y phase",
230 "Zoneplate 2nd order y phase, normailsed to ky2/256 cycles per vertical pixel at height/2 from origin",
231 G_MININT32, G_MAXINT32, 0,
232 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
233 g_object_class_install_property (gobject_class, PROP_KT2,
234 g_param_spec_int ("kt2", "Zoneplate 2nd order t phase",
235 "Zoneplate 2nd order t phase, t*t/256 cycles per picture", G_MININT32,
236 G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
237 g_object_class_install_property (gobject_class, PROP_XOFFSET,
238 g_param_spec_int ("xoffset", "Zoneplate 2nd order products x offset",
239 "Zoneplate 2nd order products x offset", G_MININT32, G_MAXINT32, 0,
240 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
241 g_object_class_install_property (gobject_class, PROP_YOFFSET,
242 g_param_spec_int ("yoffset", "Zoneplate 2nd order products y offset",
243 "Zoneplate 2nd order products y offset", G_MININT32, G_MAXINT32, 0,
244 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
246 * GstVideoTestSrc:foreground-color
248 * Color to use for solid-color pattern and foreground color of other
249 * patterns. Default is white (0xffffffff).
251 g_object_class_install_property (gobject_class, PROP_FOREGROUND_COLOR,
252 g_param_spec_uint ("foreground-color", "Foreground Color",
253 "Foreground color to use (big-endian ARGB)", 0, G_MAXUINT32,
254 DEFAULT_FOREGROUND_COLOR,
255 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
257 * GstVideoTestSrc:background-color
259 * Color to use for background color of some patterns. Default is
260 * black (0xff000000).
262 g_object_class_install_property (gobject_class, PROP_BACKGROUND_COLOR,
263 g_param_spec_uint ("background-color", "Background Color",
264 "Background color to use (big-endian ARGB)", 0, G_MAXUINT32,
265 DEFAULT_BACKGROUND_COLOR,
266 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
268 g_object_class_install_property (gobject_class, PROP_HORIZONTAL_SPEED,
269 g_param_spec_int ("horizontal-speed", "Horizontal Speed",
270 "Scroll image number of pixels per frame (positive is scroll to the left)",
271 G_MININT32, G_MAXINT32, DEFAULT_HORIZONTAL_SPEED,
272 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
274 gst_element_class_set_static_metadata (gstelement_class,
275 "Video test source", "Source/Video",
276 "Creates a test video stream", "David A. Schleef <ds@schleef.org>");
278 gst_element_class_add_pad_template (gstelement_class,
279 gst_static_pad_template_get (&gst_video_test_src_template));
281 gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
282 gstbasesrc_class->fixate = gst_video_test_src_src_fixate;
283 gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
284 gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
285 gstbasesrc_class->query = gst_video_test_src_query;
286 gstbasesrc_class->get_times = gst_video_test_src_get_times;
287 gstbasesrc_class->start = gst_video_test_src_start;
288 gstbasesrc_class->stop = gst_video_test_src_stop;
289 gstbasesrc_class->decide_allocation = gst_video_test_src_decide_allocation;
291 gstpushsrc_class->fill = gst_video_test_src_fill;
295 gst_video_test_src_init (GstVideoTestSrc * src)
297 gst_video_test_src_set_pattern (src, DEFAULT_PATTERN);
299 src->timestamp_offset = DEFAULT_TIMESTAMP_OFFSET;
300 src->foreground_color = DEFAULT_FOREGROUND_COLOR;
301 src->background_color = DEFAULT_BACKGROUND_COLOR;
302 src->horizontal_speed = DEFAULT_HORIZONTAL_SPEED;
304 /* we operate in time */
305 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
306 gst_base_src_set_live (GST_BASE_SRC (src), DEFAULT_IS_LIVE);
310 gst_video_test_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
312 GstStructure *structure;
314 caps = gst_caps_make_writable (caps);
316 structure = gst_caps_get_structure (caps, 0);
318 gst_structure_fixate_field_nearest_int (structure, "width", 320);
319 gst_structure_fixate_field_nearest_int (structure, "height", 240);
320 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
321 if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
322 gst_structure_fixate_field_nearest_fraction (structure,
323 "pixel-aspect-ratio", 1, 1);
324 if (gst_structure_has_field (structure, "colorimetry"))
325 gst_structure_fixate_field_string (structure, "colorimetry", "bt601");
326 if (gst_structure_has_field (structure, "chroma-site"))
327 gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
329 if (gst_structure_has_field (structure, "interlace-mode"))
330 gst_structure_fixate_field_string (structure, "interlace-mode",
333 caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
339 gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
342 videotestsrc->pattern_type = pattern_type;
344 GST_DEBUG_OBJECT (videotestsrc, "setting pattern to %d", pattern_type);
346 switch (pattern_type) {
347 case GST_VIDEO_TEST_SRC_SMPTE:
348 videotestsrc->make_image = gst_video_test_src_smpte;
350 case GST_VIDEO_TEST_SRC_SNOW:
351 videotestsrc->make_image = gst_video_test_src_snow;
353 case GST_VIDEO_TEST_SRC_BLACK:
354 videotestsrc->make_image = gst_video_test_src_black;
356 case GST_VIDEO_TEST_SRC_WHITE:
357 videotestsrc->make_image = gst_video_test_src_white;
359 case GST_VIDEO_TEST_SRC_RED:
360 videotestsrc->make_image = gst_video_test_src_red;
362 case GST_VIDEO_TEST_SRC_GREEN:
363 videotestsrc->make_image = gst_video_test_src_green;
365 case GST_VIDEO_TEST_SRC_BLUE:
366 videotestsrc->make_image = gst_video_test_src_blue;
368 case GST_VIDEO_TEST_SRC_CHECKERS1:
369 videotestsrc->make_image = gst_video_test_src_checkers1;
371 case GST_VIDEO_TEST_SRC_CHECKERS2:
372 videotestsrc->make_image = gst_video_test_src_checkers2;
374 case GST_VIDEO_TEST_SRC_CHECKERS4:
375 videotestsrc->make_image = gst_video_test_src_checkers4;
377 case GST_VIDEO_TEST_SRC_CHECKERS8:
378 videotestsrc->make_image = gst_video_test_src_checkers8;
380 case GST_VIDEO_TEST_SRC_CIRCULAR:
381 videotestsrc->make_image = gst_video_test_src_circular;
383 case GST_VIDEO_TEST_SRC_BLINK:
384 videotestsrc->make_image = gst_video_test_src_blink;
386 case GST_VIDEO_TEST_SRC_SMPTE75:
387 videotestsrc->make_image = gst_video_test_src_smpte75;
389 case GST_VIDEO_TEST_SRC_ZONE_PLATE:
390 videotestsrc->make_image = gst_video_test_src_zoneplate;
392 case GST_VIDEO_TEST_SRC_GAMUT:
393 videotestsrc->make_image = gst_video_test_src_gamut;
395 case GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE:
396 videotestsrc->make_image = gst_video_test_src_chromazoneplate;
398 case GST_VIDEO_TEST_SRC_SOLID:
399 videotestsrc->make_image = gst_video_test_src_solid;
401 case GST_VIDEO_TEST_SRC_BALL:
402 videotestsrc->make_image = gst_video_test_src_ball;
404 case GST_VIDEO_TEST_SRC_SMPTE100:
405 videotestsrc->make_image = gst_video_test_src_smpte100;
407 case GST_VIDEO_TEST_SRC_BAR:
408 videotestsrc->make_image = gst_video_test_src_bar;
411 g_assert_not_reached ();
416 gst_video_test_src_set_property (GObject * object, guint prop_id,
417 const GValue * value, GParamSpec * pspec)
419 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
423 gst_video_test_src_set_pattern (src, g_value_get_enum (value));
425 case PROP_TIMESTAMP_OFFSET:
426 src->timestamp_offset = g_value_get_int64 (value);
429 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
432 src->k0 = g_value_get_int (value);
435 src->kx = g_value_get_int (value);
438 src->ky = g_value_get_int (value);
441 src->kt = g_value_get_int (value);
444 src->kxt = g_value_get_int (value);
447 src->kyt = g_value_get_int (value);
450 src->kxy = g_value_get_int (value);
453 src->kx2 = g_value_get_int (value);
456 src->ky2 = g_value_get_int (value);
459 src->kt2 = g_value_get_int (value);
462 src->xoffset = g_value_get_int (value);
465 src->yoffset = g_value_get_int (value);
467 case PROP_FOREGROUND_COLOR:
468 src->foreground_color = g_value_get_uint (value);
470 case PROP_BACKGROUND_COLOR:
471 src->background_color = g_value_get_uint (value);
473 case PROP_HORIZONTAL_SPEED:
474 src->horizontal_speed = g_value_get_int (value);
481 gst_video_test_src_get_property (GObject * object, guint prop_id,
482 GValue * value, GParamSpec * pspec)
484 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
488 g_value_set_enum (value, src->pattern_type);
490 case PROP_TIMESTAMP_OFFSET:
491 g_value_set_int64 (value, src->timestamp_offset);
494 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
497 g_value_set_int (value, src->k0);
500 g_value_set_int (value, src->kx);
503 g_value_set_int (value, src->ky);
506 g_value_set_int (value, src->kt);
509 g_value_set_int (value, src->kxt);
512 g_value_set_int (value, src->kyt);
515 g_value_set_int (value, src->kxy);
518 g_value_set_int (value, src->kx2);
521 g_value_set_int (value, src->ky2);
524 g_value_set_int (value, src->kt2);
527 g_value_set_int (value, src->xoffset);
530 g_value_set_int (value, src->yoffset);
532 case PROP_FOREGROUND_COLOR:
533 g_value_set_uint (value, src->foreground_color);
535 case PROP_BACKGROUND_COLOR:
536 g_value_set_uint (value, src->background_color);
538 case PROP_HORIZONTAL_SPEED:
539 g_value_set_int (value, src->horizontal_speed);
542 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
548 gst_video_test_src_parse_caps (const GstCaps * caps,
549 gint * width, gint * height, gint * fps_n, gint * fps_d,
550 GstVideoColorimetry * colorimetry, gint * x_inv, gint * y_inv)
552 const GstStructure *structure;
553 GstPadLinkReturn ret;
554 const GValue *framerate;
557 GST_DEBUG ("parsing caps");
559 structure = gst_caps_get_structure (caps, 0);
561 ret = gst_structure_get_int (structure, "width", width);
562 ret &= gst_structure_get_int (structure, "height", height);
563 framerate = gst_structure_get_value (structure, "framerate");
566 *fps_n = gst_value_get_fraction_numerator (framerate);
567 *fps_d = gst_value_get_fraction_denominator (framerate);
571 if ((str = gst_structure_get_string (structure, "colorimetry")))
572 gst_video_colorimetry_from_string (colorimetry, str);
574 if ((str = gst_structure_get_string (structure, "format"))) {
575 if (g_str_equal (str, "bggr")) {
577 } else if (g_str_equal (str, "rggb")) {
579 } else if (g_str_equal (str, "grbg")) {
582 } else if (g_str_equal (str, "grbg")) {
593 GST_DEBUG ("videotestsrc no framerate given");
598 GST_DEBUG ("videotestsrc invalid bayer format given");
604 gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
606 GstVideoTestSrc *videotestsrc;
609 guint size, min, max;
610 GstStructure *config;
612 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
614 if (gst_query_get_n_allocation_pools (query) > 0) {
615 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
618 size = MAX (size, videotestsrc->info.size);
622 size = videotestsrc->info.size;
627 /* no downstream pool, make our own */
629 if (videotestsrc->bayer)
630 pool = gst_buffer_pool_new ();
632 pool = gst_video_buffer_pool_new ();
635 config = gst_buffer_pool_get_config (pool);
636 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
637 gst_buffer_pool_config_add_option (config,
638 GST_BUFFER_POOL_OPTION_VIDEO_META);
640 gst_buffer_pool_set_config (pool, config);
643 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
645 gst_query_add_allocation_pool (query, pool, size, min, max);
648 gst_object_unref (pool);
650 return GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query);
654 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
656 const GstStructure *structure;
657 GstVideoTestSrc *videotestsrc;
663 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
665 structure = gst_caps_get_structure (caps, 0);
667 if (gst_structure_has_name (structure, "video/x-raw")) {
668 /* we can use the parsing code */
669 if (!gst_video_info_from_caps (&info, caps))
672 } else if (gst_structure_has_name (structure, "video/x-bayer")) {
673 gint x_inv = 0, y_inv = 0;
675 gst_video_info_init (&info);
677 info.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8);
679 if (!gst_video_test_src_parse_caps (caps, &info.width, &info.height,
680 &info.fps_n, &info.fps_d, &info.colorimetry, &x_inv, &y_inv))
683 info.size = GST_ROUND_UP_4 (info.width) * info.height;
684 info.stride[0] = GST_ROUND_UP_4 (info.width);
686 videotestsrc->bayer = TRUE;
687 videotestsrc->x_invert = x_inv;
688 videotestsrc->y_invert = y_inv;
691 /* create chroma subsampler */
692 if (videotestsrc->subsample)
693 gst_video_chroma_resample_free (videotestsrc->subsample);
694 videotestsrc->subsample = gst_video_chroma_resample_new (0,
695 info.chroma_site, 0, info.finfo->unpack_format, -info.finfo->w_sub[2],
696 -info.finfo->h_sub[2]);
698 for (i = 0; i < videotestsrc->n_lines; i++)
699 g_free (videotestsrc->lines[i]);
700 g_free (videotestsrc->lines);
702 if (videotestsrc->subsample != NULL) {
703 gst_video_chroma_resample_get_info (videotestsrc->subsample,
710 videotestsrc->lines = g_malloc (sizeof (gpointer) * n_lines);
711 for (i = 0; i < n_lines; i++)
712 videotestsrc->lines[i] = g_malloc ((info.width + 16) * 8);
713 videotestsrc->n_lines = n_lines;
714 videotestsrc->offset = offset;
717 videotestsrc->info = info;
719 GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
720 info.width, info.height, info.fps_n, info.fps_d);
722 g_free (videotestsrc->tmpline);
723 g_free (videotestsrc->tmpline2);
724 g_free (videotestsrc->tmpline_u8);
725 g_free (videotestsrc->tmpline_u16);
726 videotestsrc->tmpline_u8 = g_malloc (info.width + 8);
727 videotestsrc->tmpline = g_malloc ((info.width + 8) * 4);
728 videotestsrc->tmpline2 = g_malloc ((info.width + 8) * 4);
729 videotestsrc->tmpline_u16 = g_malloc ((info.width + 16) * 8);
731 videotestsrc->accum_rtime += videotestsrc->running_time;
732 videotestsrc->accum_frames += videotestsrc->n_frames;
734 videotestsrc->running_time = 0;
735 videotestsrc->n_frames = 0;
742 GST_DEBUG_OBJECT (bsrc, "failed to parse caps");
748 gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
751 GstVideoTestSrc *src;
753 src = GST_VIDEO_TEST_SRC (bsrc);
755 switch (GST_QUERY_TYPE (query)) {
756 case GST_QUERY_CONVERT:
758 GstFormat src_fmt, dest_fmt;
759 gint64 src_val, dest_val;
761 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
763 gst_video_info_convert (&src->info, src_fmt, src_val, dest_fmt,
765 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
769 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
776 gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
777 GstClockTime * start, GstClockTime * end)
779 /* for live sources, sync on the timestamp of the buffer */
780 if (gst_base_src_is_live (basesrc)) {
781 GstClockTime timestamp = GST_BUFFER_DTS (buffer);
783 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
784 /* get duration to calculate end time */
785 GstClockTime duration = GST_BUFFER_DURATION (buffer);
787 if (GST_CLOCK_TIME_IS_VALID (duration)) {
788 *end = timestamp + duration;
799 gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
801 GstClockTime position;
802 GstVideoTestSrc *src;
804 src = GST_VIDEO_TEST_SRC (bsrc);
806 segment->time = segment->start;
807 position = segment->position;
809 /* now move to the position indicated */
810 if (src->info.fps_n) {
811 src->n_frames = gst_util_uint64_scale (position,
812 src->info.fps_n, src->info.fps_d * GST_SECOND);
816 src->accum_frames = 0;
817 src->accum_rtime = 0;
818 if (src->info.fps_n) {
819 src->running_time = gst_util_uint64_scale (src->n_frames,
820 src->info.fps_d * GST_SECOND, src->info.fps_n);
822 /* FIXME : Not sure what to set here */
823 src->running_time = 0;
826 g_assert (src->running_time <= position);
832 gst_video_test_src_is_seekable (GstBaseSrc * psrc)
834 /* we're seekable... */
839 gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
841 GstVideoTestSrc *src;
842 GstClockTime next_time;
847 src = GST_VIDEO_TEST_SRC (psrc);
849 if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&src->info) ==
850 GST_VIDEO_FORMAT_UNKNOWN))
853 /* 0 framerate and we are at the second frame, eos */
854 if (G_UNLIKELY (src->info.fps_n == 0 && src->n_frames == 1))
858 "creating buffer from pool for frame %d", (gint) src->n_frames);
860 if (!gst_video_frame_map (&frame, &src->info, buffer, GST_MAP_WRITE))
863 GST_BUFFER_DTS (buffer) =
864 src->accum_rtime + src->timestamp_offset + src->running_time;
865 GST_BUFFER_PTS (buffer) = GST_BUFFER_DTS (buffer);
867 gst_object_sync_values (GST_OBJECT (psrc), GST_BUFFER_DTS (buffer));
869 src->make_image (src, &frame);
871 if ((pal = gst_video_format_get_palette (GST_VIDEO_FRAME_FORMAT (&frame),
873 memcpy (GST_VIDEO_FRAME_PLANE_DATA (&frame, 1), pal, palsize);
876 gst_video_frame_unmap (&frame);
878 GST_DEBUG_OBJECT (src, "Timestamp: %" GST_TIME_FORMAT " = accumulated %"
879 GST_TIME_FORMAT " + offset: %"
880 GST_TIME_FORMAT " + running time: %" GST_TIME_FORMAT,
881 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)), GST_TIME_ARGS (src->accum_rtime),
882 GST_TIME_ARGS (src->timestamp_offset), GST_TIME_ARGS (src->running_time));
884 GST_BUFFER_OFFSET (buffer) = src->accum_frames + src->n_frames;
886 GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET (buffer) + 1;
887 if (src->info.fps_n) {
888 next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
889 src->info.fps_d, src->info.fps_n);
890 GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
892 next_time = src->timestamp_offset;
893 /* NONE means forever */
894 GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
897 src->running_time = next_time;
903 return GST_FLOW_NOT_NEGOTIATED;
907 GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
912 GST_DEBUG_OBJECT (src, "invalid frame");
918 gst_video_test_src_start (GstBaseSrc * basesrc)
920 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
922 src->running_time = 0;
924 src->accum_frames = 0;
925 src->accum_rtime = 0;
927 gst_video_info_init (&src->info);
933 gst_video_test_src_stop (GstBaseSrc * basesrc)
935 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
938 g_free (src->tmpline);
940 g_free (src->tmpline2);
941 src->tmpline2 = NULL;
942 g_free (src->tmpline_u8);
943 src->tmpline_u8 = NULL;
944 g_free (src->tmpline_u16);
945 src->tmpline_u16 = NULL;
947 gst_video_chroma_resample_free (src->subsample);
948 src->subsample = NULL;
950 for (i = 0; i < src->n_lines; i++)
951 g_free (src->lines[i]);
960 plugin_init (GstPlugin * plugin)
962 GST_DEBUG_CATEGORY_INIT (video_test_src_debug, "videotestsrc", 0,
963 "Video Test Source");
965 return gst_element_register (plugin, "videotestsrc", GST_RANK_NONE,
966 GST_TYPE_VIDEO_TEST_SRC);
969 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
972 "Creates a test video stream",
973 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)