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
23 * @title: videotestsrc
25 * The videotestsrc element is used to produce test video data in a wide variety
26 * of formats. The video test data produced can be controlled with the "pattern"
29 * ## Example launch line
31 * gst-launch-1.0 -v videotestsrc pattern=snow ! video/x-raw,width=1280,height=720 ! autovideosink
33 * Shows random noise in a video window.
40 #include "gstvideotestsrc.h"
41 #include "gstvideotestsrcorc.h"
42 #include "videotestsrc.h"
47 GST_DEBUG_CATEGORY_STATIC (video_test_src_debug);
48 #define GST_CAT_DEFAULT video_test_src_debug
50 #define DEFAULT_PATTERN GST_VIDEO_TEST_SRC_SMPTE
51 #define DEFAULT_ANIMATION_MODE GST_VIDEO_TEST_SRC_FRAMES
52 #define DEFAULT_MOTION_TYPE GST_VIDEO_TEST_SRC_WAVY
53 #define DEFAULT_FLIP FALSE
54 #define DEFAULT_TIMESTAMP_OFFSET 0
55 #define DEFAULT_IS_LIVE FALSE
56 #define DEFAULT_COLOR_SPEC GST_VIDEO_TEST_SRC_BT601
57 #define DEFAULT_FOREGROUND_COLOR 0xffffffff
58 #define DEFAULT_BACKGROUND_COLOR 0xff000000
59 #define DEFAULT_HORIZONTAL_SPEED 0
65 PROP_TIMESTAMP_OFFSET,
79 PROP_FOREGROUND_COLOR,
80 PROP_BACKGROUND_COLOR,
81 PROP_HORIZONTAL_SPEED,
89 #define VTS_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) "," \
90 "multiview-mode = { mono, left, right }" \
92 "video/x-bayer, format=(string) { bggr, rggb, grbg, gbrg }, " \
93 "width = " GST_VIDEO_SIZE_RANGE ", " \
94 "height = " GST_VIDEO_SIZE_RANGE ", " \
95 "framerate = " GST_VIDEO_FPS_RANGE ", " \
96 "multiview-mode = { mono, left, right }"
99 static GstStaticPadTemplate gst_video_test_src_template =
100 GST_STATIC_PAD_TEMPLATE ("src",
103 GST_STATIC_CAPS (VTS_VIDEO_CAPS)
106 #define gst_video_test_src_parent_class parent_class
107 G_DEFINE_TYPE (GstVideoTestSrc, gst_video_test_src, GST_TYPE_PUSH_SRC);
109 static void gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
111 static void gst_video_test_src_set_property (GObject * object, guint prop_id,
112 const GValue * value, GParamSpec * pspec);
113 static void gst_video_test_src_get_property (GObject * object, guint prop_id,
114 GValue * value, GParamSpec * pspec);
116 static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
117 static GstCaps *gst_video_test_src_src_fixate (GstBaseSrc * bsrc,
120 static gboolean gst_video_test_src_is_seekable (GstBaseSrc * psrc);
121 static gboolean gst_video_test_src_do_seek (GstBaseSrc * bsrc,
122 GstSegment * segment);
123 static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
125 static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
126 GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
127 static gboolean gst_video_test_src_decide_allocation (GstBaseSrc * bsrc,
129 static GstFlowReturn gst_video_test_src_fill (GstPushSrc * psrc,
131 static gboolean gst_video_test_src_start (GstBaseSrc * basesrc);
132 static gboolean gst_video_test_src_stop (GstBaseSrc * basesrc);
134 #define GST_TYPE_VIDEO_TEST_SRC_PATTERN (gst_video_test_src_pattern_get_type ())
136 gst_video_test_src_pattern_get_type (void)
138 static GType video_test_src_pattern_type = 0;
139 static const GEnumValue pattern_types[] = {
140 {GST_VIDEO_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
141 {GST_VIDEO_TEST_SRC_SNOW, "Random (television snow)", "snow"},
142 {GST_VIDEO_TEST_SRC_BLACK, "100% Black", "black"},
143 {GST_VIDEO_TEST_SRC_WHITE, "100% White", "white"},
144 {GST_VIDEO_TEST_SRC_RED, "Red", "red"},
145 {GST_VIDEO_TEST_SRC_GREEN, "Green", "green"},
146 {GST_VIDEO_TEST_SRC_BLUE, "Blue", "blue"},
147 {GST_VIDEO_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
148 {GST_VIDEO_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
149 {GST_VIDEO_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
150 {GST_VIDEO_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
151 {GST_VIDEO_TEST_SRC_CIRCULAR, "Circular", "circular"},
152 {GST_VIDEO_TEST_SRC_BLINK, "Blink", "blink"},
153 {GST_VIDEO_TEST_SRC_SMPTE75, "SMPTE 75% color bars", "smpte75"},
154 {GST_VIDEO_TEST_SRC_ZONE_PLATE, "Zone plate", "zone-plate"},
155 {GST_VIDEO_TEST_SRC_GAMUT, "Gamut checkers", "gamut"},
156 {GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE, "Chroma zone plate",
157 "chroma-zone-plate"},
158 {GST_VIDEO_TEST_SRC_SOLID, "Solid color", "solid-color"},
159 {GST_VIDEO_TEST_SRC_BALL, "Moving ball", "ball"},
160 {GST_VIDEO_TEST_SRC_SMPTE100, "SMPTE 100% color bars", "smpte100"},
161 {GST_VIDEO_TEST_SRC_BAR, "Bar", "bar"},
162 {GST_VIDEO_TEST_SRC_PINWHEEL, "Pinwheel", "pinwheel"},
163 {GST_VIDEO_TEST_SRC_SPOKES, "Spokes", "spokes"},
164 {GST_VIDEO_TEST_SRC_GRADIENT, "Gradient", "gradient"},
165 {GST_VIDEO_TEST_SRC_COLORS, "Colors", "colors"},
169 if (!video_test_src_pattern_type) {
170 video_test_src_pattern_type =
171 g_enum_register_static ("GstVideoTestSrcPattern", pattern_types);
173 return video_test_src_pattern_type;
177 /*"animation-mode", which can
178 * take the following values: frames (current behaviour that should stay the
179 * default), running time, wall clock time.
182 #define GST_TYPE_VIDEO_TEST_SRC_ANIMATION_MODE (gst_video_test_src_animation_mode_get_type ())
184 gst_video_test_src_animation_mode_get_type (void)
186 static GType video_test_src_animation_mode = 0;
187 static const GEnumValue animation_modes[] = {
189 {GST_VIDEO_TEST_SRC_FRAMES, "frame count", "frames"},
190 {GST_VIDEO_TEST_SRC_WALL_TIME, "wall clock time", "wall-time"},
191 {GST_VIDEO_TEST_SRC_RUNNING_TIME, "running time", "running-time"},
195 if (!video_test_src_animation_mode) {
196 video_test_src_animation_mode =
197 g_enum_register_static ("GstVideoTestSrcAnimationMode",
200 return video_test_src_animation_mode;
204 #define GST_TYPE_VIDEO_TEST_SRC_MOTION_TYPE (gst_video_test_src_motion_type_get_type ())
206 gst_video_test_src_motion_type_get_type (void)
208 static GType video_test_src_motion_type = 0;
209 static const GEnumValue motion_types[] = {
210 {GST_VIDEO_TEST_SRC_WAVY, "Ball waves back and forth, up and down",
212 {GST_VIDEO_TEST_SRC_SWEEP, "1 revolution per second", "sweep"},
213 {GST_VIDEO_TEST_SRC_HSWEEP, "1/2 revolution per second, then reset to top",
218 if (!video_test_src_motion_type) {
219 video_test_src_motion_type =
220 g_enum_register_static ("GstVideoTestSrcMotionType", motion_types);
222 return video_test_src_motion_type;
227 gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
229 GObjectClass *gobject_class;
230 GstElementClass *gstelement_class;
231 GstBaseSrcClass *gstbasesrc_class;
232 GstPushSrcClass *gstpushsrc_class;
234 gobject_class = (GObjectClass *) klass;
235 gstelement_class = (GstElementClass *) klass;
236 gstbasesrc_class = (GstBaseSrcClass *) klass;
237 gstpushsrc_class = (GstPushSrcClass *) klass;
239 gobject_class->set_property = gst_video_test_src_set_property;
240 gobject_class->get_property = gst_video_test_src_get_property;
242 g_object_class_install_property (gobject_class, PROP_PATTERN,
243 g_param_spec_enum ("pattern", "Pattern",
244 "Type of test pattern to generate", GST_TYPE_VIDEO_TEST_SRC_PATTERN,
245 DEFAULT_PATTERN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
247 g_object_class_install_property (gobject_class, PROP_ANIMATION_MODE,
248 g_param_spec_enum ("animation-mode", "Animation mode",
249 "For pattern=ball, which counter defines the position of the ball.",
250 GST_TYPE_VIDEO_TEST_SRC_ANIMATION_MODE, DEFAULT_ANIMATION_MODE,
251 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
253 g_object_class_install_property (gobject_class, PROP_MOTION_TYPE,
254 g_param_spec_enum ("motion", "Motion",
255 "For pattern=ball, what motion the ball does",
256 GST_TYPE_VIDEO_TEST_SRC_MOTION_TYPE, DEFAULT_MOTION_TYPE,
257 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
259 g_object_class_install_property (gobject_class, PROP_FLIP,
260 g_param_spec_boolean ("flip", "Flip",
261 "For pattern=ball, invert colors every second.",
262 DEFAULT_FLIP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
264 g_object_class_install_property (gobject_class, PROP_TIMESTAMP_OFFSET,
265 g_param_spec_int64 ("timestamp-offset", "Timestamp offset",
266 "An offset added to timestamps set on buffers (in ns)", 0,
267 (G_MAXLONG == G_MAXINT64) ? G_MAXINT64 : (G_MAXLONG * GST_SECOND - 1),
268 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
269 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
270 g_param_spec_boolean ("is-live", "Is Live",
271 "Whether to act as a live source", DEFAULT_IS_LIVE,
272 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
273 g_object_class_install_property (gobject_class, PROP_K0,
274 g_param_spec_int ("k0", "Zoneplate zero order phase",
275 "Zoneplate zero order phase, for generating plain fields or phase offsets",
276 G_MININT32, G_MAXINT32, 0,
277 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
278 g_object_class_install_property (gobject_class, PROP_KX,
279 g_param_spec_int ("kx", "Zoneplate 1st order x phase",
280 "Zoneplate 1st order x phase, for generating constant horizontal frequencies",
281 G_MININT32, G_MAXINT32, 0,
282 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
283 g_object_class_install_property (gobject_class, PROP_KY,
284 g_param_spec_int ("ky", "Zoneplate 1st order y phase",
285 "Zoneplate 1st order y phase, for generating contant vertical frequencies",
286 G_MININT32, G_MAXINT32, 0,
287 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
288 g_object_class_install_property (gobject_class, PROP_KT,
289 g_param_spec_int ("kt", "Zoneplate 1st order t phase",
290 "Zoneplate 1st order t phase, for generating phase rotation as a function of time",
291 G_MININT32, G_MAXINT32, 0,
292 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
293 g_object_class_install_property (gobject_class, PROP_KXT,
294 g_param_spec_int ("kxt", "Zoneplate x*t product phase",
295 "Zoneplate x*t product phase, normalised to kxy/256 cycles per vertical pixel at width/2 from origin",
296 G_MININT32, G_MAXINT32, 0,
297 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
298 g_object_class_install_property (gobject_class, PROP_KYT,
299 g_param_spec_int ("kyt", "Zoneplate y*t product phase",
300 "Zoneplate y*t product phase", G_MININT32, G_MAXINT32, 0,
301 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
302 g_object_class_install_property (gobject_class, PROP_KXY,
303 g_param_spec_int ("kxy", "Zoneplate x*y product phase",
304 "Zoneplate x*y product phase", G_MININT32, G_MAXINT32, 0,
305 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
306 g_object_class_install_property (gobject_class, PROP_KX2,
307 g_param_spec_int ("kx2", "Zoneplate 2nd order x phase",
308 "Zoneplate 2nd order x phase, normalised to kx2/256 cycles per horizontal pixel at width/2 from origin",
309 G_MININT32, G_MAXINT32, 0,
310 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
311 g_object_class_install_property (gobject_class, PROP_KY2,
312 g_param_spec_int ("ky2", "Zoneplate 2nd order y phase",
313 "Zoneplate 2nd order y phase, normailsed to ky2/256 cycles per vertical pixel at height/2 from origin",
314 G_MININT32, G_MAXINT32, 0,
315 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
316 g_object_class_install_property (gobject_class, PROP_KT2,
317 g_param_spec_int ("kt2", "Zoneplate 2nd order t phase",
318 "Zoneplate 2nd order t phase, t*t/256 cycles per picture", G_MININT32,
319 G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
320 g_object_class_install_property (gobject_class, PROP_XOFFSET,
321 g_param_spec_int ("xoffset", "Zoneplate 2nd order products x offset",
322 "Zoneplate 2nd order products x offset", G_MININT32, G_MAXINT32, 0,
323 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
324 g_object_class_install_property (gobject_class, PROP_YOFFSET,
325 g_param_spec_int ("yoffset", "Zoneplate 2nd order products y offset",
326 "Zoneplate 2nd order products y offset", G_MININT32, G_MAXINT32, 0,
327 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
329 * GstVideoTestSrc:foreground-color
331 * Color to use for solid-color pattern and foreground color of other
332 * patterns. Default is white (0xffffffff).
334 g_object_class_install_property (gobject_class, PROP_FOREGROUND_COLOR,
335 g_param_spec_uint ("foreground-color", "Foreground Color",
336 "Foreground color to use (big-endian ARGB)", 0, G_MAXUINT32,
337 DEFAULT_FOREGROUND_COLOR,
338 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
340 * GstVideoTestSrc:background-color
342 * Color to use for background color of some patterns. Default is
343 * black (0xff000000).
345 g_object_class_install_property (gobject_class, PROP_BACKGROUND_COLOR,
346 g_param_spec_uint ("background-color", "Background Color",
347 "Background color to use (big-endian ARGB)", 0, G_MAXUINT32,
348 DEFAULT_BACKGROUND_COLOR,
349 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
351 g_object_class_install_property (gobject_class, PROP_HORIZONTAL_SPEED,
352 g_param_spec_int ("horizontal-speed", "Horizontal Speed",
353 "Scroll image number of pixels per frame (positive is scroll to the left)",
354 G_MININT32, G_MAXINT32, DEFAULT_HORIZONTAL_SPEED,
355 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
357 gst_element_class_set_static_metadata (gstelement_class,
358 "Video test source", "Source/Video",
359 "Creates a test video stream", "David A. Schleef <ds@schleef.org>");
361 gst_element_class_add_static_pad_template (gstelement_class,
362 &gst_video_test_src_template);
364 gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
365 gstbasesrc_class->fixate = gst_video_test_src_src_fixate;
366 gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
367 gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
368 gstbasesrc_class->query = gst_video_test_src_query;
369 gstbasesrc_class->get_times = gst_video_test_src_get_times;
370 gstbasesrc_class->start = gst_video_test_src_start;
371 gstbasesrc_class->stop = gst_video_test_src_stop;
372 gstbasesrc_class->decide_allocation = gst_video_test_src_decide_allocation;
374 gstpushsrc_class->fill = gst_video_test_src_fill;
378 gst_video_test_src_init (GstVideoTestSrc * src)
380 gst_video_test_src_set_pattern (src, DEFAULT_PATTERN);
382 src->timestamp_offset = DEFAULT_TIMESTAMP_OFFSET;
383 src->foreground_color = DEFAULT_FOREGROUND_COLOR;
384 src->background_color = DEFAULT_BACKGROUND_COLOR;
385 src->horizontal_speed = DEFAULT_HORIZONTAL_SPEED;
386 src->random_state = 0;
388 /* we operate in time */
389 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
390 gst_base_src_set_live (GST_BASE_SRC (src), DEFAULT_IS_LIVE);
392 src->animation_mode = DEFAULT_ANIMATION_MODE;
393 src->motion_type = DEFAULT_MOTION_TYPE;
394 src->flip = DEFAULT_FLIP;
399 gst_video_test_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
401 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (bsrc);
402 GstStructure *structure;
404 /* Check if foreground color has alpha, if it is the case,
405 * force color format with an alpha channel downstream */
406 if (src->foreground_color >> 24 != 255) {
408 GstCaps *alpha_only_caps = gst_caps_new_empty ();
410 for (i = 0; i < gst_caps_get_size (caps); i++) {
411 const GstVideoFormatInfo *info;
412 const GValue *formats =
413 gst_structure_get_value (gst_caps_get_structure (caps, i),
416 if (GST_VALUE_HOLDS_LIST (formats)) {
417 GValue possible_formats = { 0, };
418 guint list_size = gst_value_list_get_size (formats);
421 g_value_init (&possible_formats, GST_TYPE_LIST);
422 for (index = 0; index < list_size; index++) {
423 const GValue *list_item = gst_value_list_get_value (formats, index);
425 gst_video_format_get_info (gst_video_format_from_string
426 (g_value_get_string (list_item)));
427 if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
430 gst_value_init_and_copy (&tmp, list_item);
431 gst_value_list_append_value (&possible_formats, &tmp);
435 if (gst_value_list_get_size (&possible_formats)) {
436 GstStructure *astruct =
437 gst_structure_copy (gst_caps_get_structure (caps, i));
439 gst_structure_set_value (astruct, "format", &possible_formats);
440 gst_caps_append_structure (alpha_only_caps, astruct);
443 } else if (G_VALUE_HOLDS_STRING (formats)) {
445 gst_video_format_get_info (gst_video_format_from_string
446 (g_value_get_string (formats)));
448 if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
449 gst_caps_append_structure (alpha_only_caps,
450 gst_structure_copy (gst_caps_get_structure (caps, i)));
453 g_assert_not_reached ();
454 GST_WARNING ("Unexpected type for video 'format' field: %s",
455 G_VALUE_TYPE_NAME (formats));
459 if (gst_caps_is_empty (alpha_only_caps)) {
460 GST_WARNING_OBJECT (src,
461 "Foreground color contains alpha, but downstream can't support alpha.");
463 gst_caps_replace (&caps, alpha_only_caps);
467 caps = gst_caps_make_writable (caps);
468 structure = gst_caps_get_structure (caps, 0);
470 gst_structure_fixate_field_nearest_int (structure, "width", 320);
471 gst_structure_fixate_field_nearest_int (structure, "height", 240);
473 if (gst_structure_has_field (structure, "framerate"))
474 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
476 gst_structure_set (structure, "framerate", GST_TYPE_FRACTION, 30, 1, NULL);
478 if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
479 gst_structure_fixate_field_nearest_fraction (structure,
480 "pixel-aspect-ratio", 1, 1);
482 gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
485 if (gst_structure_has_field (structure, "colorimetry"))
486 gst_structure_fixate_field_string (structure, "colorimetry", "bt601");
487 if (gst_structure_has_field (structure, "chroma-site"))
488 gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
490 if (gst_structure_has_field (structure, "interlace-mode"))
491 gst_structure_fixate_field_string (structure, "interlace-mode",
494 gst_structure_set (structure, "interlace-mode", G_TYPE_STRING,
495 "progressive", NULL);
497 if (gst_structure_has_field (structure, "multiview-mode"))
498 gst_structure_fixate_field_string (structure, "multiview-mode",
499 gst_video_multiview_mode_to_caps_string
500 (GST_VIDEO_MULTIVIEW_MODE_MONO));
502 gst_structure_set (structure, "multiview-mode", G_TYPE_STRING,
503 gst_video_multiview_mode_to_caps_string (GST_VIDEO_MULTIVIEW_MODE_MONO),
506 caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
512 gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
515 videotestsrc->pattern_type = pattern_type;
517 GST_DEBUG_OBJECT (videotestsrc, "setting pattern to %d", pattern_type);
519 switch (pattern_type) {
520 case GST_VIDEO_TEST_SRC_SMPTE:
521 videotestsrc->make_image = gst_video_test_src_smpte;
523 case GST_VIDEO_TEST_SRC_SNOW:
524 videotestsrc->make_image = gst_video_test_src_snow;
526 case GST_VIDEO_TEST_SRC_BLACK:
527 videotestsrc->make_image = gst_video_test_src_black;
529 case GST_VIDEO_TEST_SRC_WHITE:
530 videotestsrc->make_image = gst_video_test_src_white;
532 case GST_VIDEO_TEST_SRC_RED:
533 videotestsrc->make_image = gst_video_test_src_red;
535 case GST_VIDEO_TEST_SRC_GREEN:
536 videotestsrc->make_image = gst_video_test_src_green;
538 case GST_VIDEO_TEST_SRC_BLUE:
539 videotestsrc->make_image = gst_video_test_src_blue;
541 case GST_VIDEO_TEST_SRC_CHECKERS1:
542 videotestsrc->make_image = gst_video_test_src_checkers1;
544 case GST_VIDEO_TEST_SRC_CHECKERS2:
545 videotestsrc->make_image = gst_video_test_src_checkers2;
547 case GST_VIDEO_TEST_SRC_CHECKERS4:
548 videotestsrc->make_image = gst_video_test_src_checkers4;
550 case GST_VIDEO_TEST_SRC_CHECKERS8:
551 videotestsrc->make_image = gst_video_test_src_checkers8;
553 case GST_VIDEO_TEST_SRC_CIRCULAR:
554 videotestsrc->make_image = gst_video_test_src_circular;
556 case GST_VIDEO_TEST_SRC_BLINK:
557 videotestsrc->make_image = gst_video_test_src_blink;
559 case GST_VIDEO_TEST_SRC_SMPTE75:
560 videotestsrc->make_image = gst_video_test_src_smpte75;
562 case GST_VIDEO_TEST_SRC_ZONE_PLATE:
563 videotestsrc->make_image = gst_video_test_src_zoneplate;
565 case GST_VIDEO_TEST_SRC_GAMUT:
566 videotestsrc->make_image = gst_video_test_src_gamut;
568 case GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE:
569 videotestsrc->make_image = gst_video_test_src_chromazoneplate;
571 case GST_VIDEO_TEST_SRC_SOLID:
572 videotestsrc->make_image = gst_video_test_src_solid;
574 case GST_VIDEO_TEST_SRC_BALL:
575 videotestsrc->make_image = gst_video_test_src_ball;
577 case GST_VIDEO_TEST_SRC_SMPTE100:
578 videotestsrc->make_image = gst_video_test_src_smpte100;
580 case GST_VIDEO_TEST_SRC_BAR:
581 videotestsrc->make_image = gst_video_test_src_bar;
583 case GST_VIDEO_TEST_SRC_PINWHEEL:
584 videotestsrc->make_image = gst_video_test_src_pinwheel;
586 case GST_VIDEO_TEST_SRC_SPOKES:
587 videotestsrc->make_image = gst_video_test_src_spokes;
589 case GST_VIDEO_TEST_SRC_GRADIENT:
590 videotestsrc->make_image = gst_video_test_src_gradient;
592 case GST_VIDEO_TEST_SRC_COLORS:
593 videotestsrc->make_image = gst_video_test_src_colors;
596 g_assert_not_reached ();
601 gst_video_test_src_set_property (GObject * object, guint prop_id,
602 const GValue * value, GParamSpec * pspec)
604 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
608 gst_video_test_src_set_pattern (src, g_value_get_enum (value));
610 case PROP_TIMESTAMP_OFFSET:
611 src->timestamp_offset = g_value_get_int64 (value);
614 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
617 src->k0 = g_value_get_int (value);
620 src->kx = g_value_get_int (value);
623 src->ky = g_value_get_int (value);
626 src->kt = g_value_get_int (value);
629 src->kxt = g_value_get_int (value);
632 src->kyt = g_value_get_int (value);
635 src->kxy = g_value_get_int (value);
638 src->kx2 = g_value_get_int (value);
641 src->ky2 = g_value_get_int (value);
644 src->kt2 = g_value_get_int (value);
647 src->xoffset = g_value_get_int (value);
650 src->yoffset = g_value_get_int (value);
652 case PROP_FOREGROUND_COLOR:
653 src->foreground_color = g_value_get_uint (value);
655 case PROP_BACKGROUND_COLOR:
656 src->background_color = g_value_get_uint (value);
658 case PROP_HORIZONTAL_SPEED:
659 src->horizontal_speed = g_value_get_int (value);
661 case PROP_ANIMATION_MODE:
662 src->animation_mode = g_value_get_enum (value);
664 case PROP_MOTION_TYPE:
665 src->motion_type = g_value_get_enum (value);
668 src->flip = g_value_get_boolean (value);
676 gst_video_test_src_get_property (GObject * object, guint prop_id,
677 GValue * value, GParamSpec * pspec)
679 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
683 g_value_set_enum (value, src->pattern_type);
685 case PROP_TIMESTAMP_OFFSET:
686 g_value_set_int64 (value, src->timestamp_offset);
689 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
692 g_value_set_int (value, src->k0);
695 g_value_set_int (value, src->kx);
698 g_value_set_int (value, src->ky);
701 g_value_set_int (value, src->kt);
704 g_value_set_int (value, src->kxt);
707 g_value_set_int (value, src->kyt);
710 g_value_set_int (value, src->kxy);
713 g_value_set_int (value, src->kx2);
716 g_value_set_int (value, src->ky2);
719 g_value_set_int (value, src->kt2);
722 g_value_set_int (value, src->xoffset);
725 g_value_set_int (value, src->yoffset);
727 case PROP_FOREGROUND_COLOR:
728 g_value_set_uint (value, src->foreground_color);
730 case PROP_BACKGROUND_COLOR:
731 g_value_set_uint (value, src->background_color);
733 case PROP_HORIZONTAL_SPEED:
734 g_value_set_int (value, src->horizontal_speed);
736 case PROP_ANIMATION_MODE:
737 g_value_set_enum (value, src->animation_mode);
739 case PROP_MOTION_TYPE:
740 g_value_set_enum (value, src->motion_type);
743 g_value_set_boolean (value, src->flip);
746 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
752 gst_video_test_src_parse_caps (const GstCaps * caps,
753 gint * width, gint * height, gint * fps_n, gint * fps_d,
754 GstVideoColorimetry * colorimetry, gint * x_inv, gint * y_inv)
756 const GstStructure *structure;
757 GstPadLinkReturn ret;
758 const GValue *framerate;
761 GST_DEBUG ("parsing caps");
763 structure = gst_caps_get_structure (caps, 0);
765 ret = gst_structure_get_int (structure, "width", width);
766 ret &= gst_structure_get_int (structure, "height", height);
767 framerate = gst_structure_get_value (structure, "framerate");
770 *fps_n = gst_value_get_fraction_numerator (framerate);
771 *fps_d = gst_value_get_fraction_denominator (framerate);
775 if ((str = gst_structure_get_string (structure, "colorimetry")))
776 gst_video_colorimetry_from_string (colorimetry, str);
778 if ((str = gst_structure_get_string (structure, "format"))) {
779 if (g_str_equal (str, "bggr")) {
781 } else if (g_str_equal (str, "rggb")) {
783 } else if (g_str_equal (str, "grbg")) {
786 } else if (g_str_equal (str, "gbrg")) {
797 GST_DEBUG ("videotestsrc no framerate given");
802 GST_DEBUG ("videotestsrc invalid bayer format given");
808 gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
810 GstVideoTestSrc *videotestsrc;
813 guint size, min, max;
814 GstStructure *config;
815 GstCaps *caps = NULL;
817 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
819 if (gst_query_get_n_allocation_pools (query) > 0) {
820 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
823 size = MAX (size, videotestsrc->info.size);
827 size = videotestsrc->info.size;
832 /* no downstream pool, make our own */
834 if (videotestsrc->bayer)
835 pool = gst_buffer_pool_new ();
837 pool = gst_video_buffer_pool_new ();
840 config = gst_buffer_pool_get_config (pool);
842 gst_query_parse_allocation (query, &caps, NULL);
844 gst_buffer_pool_config_set_params (config, caps, size, min, max);
846 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
847 gst_buffer_pool_config_add_option (config,
848 GST_BUFFER_POOL_OPTION_VIDEO_META);
850 gst_buffer_pool_set_config (pool, config);
853 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
855 gst_query_add_allocation_pool (query, pool, size, min, max);
858 gst_object_unref (pool);
860 return GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query);
864 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
866 const GstStructure *structure;
867 GstVideoTestSrc *videotestsrc;
873 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
875 structure = gst_caps_get_structure (caps, 0);
877 GST_OBJECT_LOCK (videotestsrc);
879 if (gst_structure_has_name (structure, "video/x-raw")) {
880 /* we can use the parsing code */
881 if (!gst_video_info_from_caps (&info, caps))
884 } else if (gst_structure_has_name (structure, "video/x-bayer")) {
885 gint x_inv = 0, y_inv = 0;
887 gst_video_info_init (&info);
889 info.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8);
891 if (!gst_video_test_src_parse_caps (caps, &info.width, &info.height,
892 &info.fps_n, &info.fps_d, &info.colorimetry, &x_inv, &y_inv))
895 info.size = GST_ROUND_UP_4 (info.width) * info.height;
896 info.stride[0] = GST_ROUND_UP_4 (info.width);
898 videotestsrc->bayer = TRUE;
899 videotestsrc->x_invert = x_inv;
900 videotestsrc->y_invert = y_inv;
902 goto unsupported_caps;
905 /* create chroma subsampler */
906 if (videotestsrc->subsample)
907 gst_video_chroma_resample_free (videotestsrc->subsample);
908 videotestsrc->subsample = gst_video_chroma_resample_new (0,
909 info.chroma_site, 0, info.finfo->unpack_format, -info.finfo->w_sub[2],
910 -info.finfo->h_sub[2]);
912 for (i = 0; i < videotestsrc->n_lines; i++)
913 g_free (videotestsrc->lines[i]);
914 g_free (videotestsrc->lines);
916 if (videotestsrc->subsample != NULL) {
917 gst_video_chroma_resample_get_info (videotestsrc->subsample,
924 videotestsrc->lines = g_malloc (sizeof (gpointer) * n_lines);
925 for (i = 0; i < n_lines; i++)
926 videotestsrc->lines[i] = g_malloc ((info.width + 16) * 8);
927 videotestsrc->n_lines = n_lines;
928 videotestsrc->offset = offset;
931 videotestsrc->info = info;
933 GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
934 info.width, info.height, info.fps_n, info.fps_d);
936 g_free (videotestsrc->tmpline);
937 g_free (videotestsrc->tmpline2);
938 g_free (videotestsrc->tmpline_u8);
939 g_free (videotestsrc->tmpline_u16);
940 videotestsrc->tmpline_u8 = g_malloc (info.width + 8);
941 videotestsrc->tmpline = g_malloc ((info.width + 8) * 4);
942 videotestsrc->tmpline2 = g_malloc ((info.width + 8) * 4);
943 videotestsrc->tmpline_u16 = g_malloc ((info.width + 16) * 8);
945 videotestsrc->accum_rtime += videotestsrc->running_time;
946 videotestsrc->accum_frames += videotestsrc->n_frames;
948 videotestsrc->running_time = 0;
949 videotestsrc->n_frames = 0;
951 GST_OBJECT_UNLOCK (videotestsrc);
958 GST_OBJECT_UNLOCK (videotestsrc);
959 GST_DEBUG_OBJECT (bsrc, "failed to parse caps");
964 GST_OBJECT_UNLOCK (videotestsrc);
965 GST_DEBUG_OBJECT (bsrc, "unsupported caps: %" GST_PTR_FORMAT, caps);
971 gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
973 gboolean res = FALSE;
974 GstVideoTestSrc *src;
976 src = GST_VIDEO_TEST_SRC (bsrc);
978 switch (GST_QUERY_TYPE (query)) {
979 case GST_QUERY_CONVERT:
981 GstFormat src_fmt, dest_fmt;
982 gint64 src_val, dest_val;
984 GST_OBJECT_LOCK (src);
985 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
987 gst_video_info_convert (&src->info, src_fmt, src_val, dest_fmt,
989 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
990 GST_OBJECT_UNLOCK (src);
993 case GST_QUERY_LATENCY:
995 GST_OBJECT_LOCK (src);
996 if (src->info.fps_n > 0) {
997 GstClockTime latency;
1000 gst_util_uint64_scale (GST_SECOND, src->info.fps_d,
1002 GST_OBJECT_UNLOCK (src);
1003 gst_query_set_latency (query,
1004 gst_base_src_is_live (GST_BASE_SRC_CAST (src)), latency,
1005 GST_CLOCK_TIME_NONE);
1006 GST_DEBUG_OBJECT (src, "Reporting latency of %" GST_TIME_FORMAT,
1007 GST_TIME_ARGS (latency));
1010 GST_OBJECT_UNLOCK (src);
1014 case GST_QUERY_DURATION:{
1015 if (bsrc->num_buffers != -1) {
1018 gst_query_parse_duration (query, &format, NULL);
1020 case GST_FORMAT_TIME:{
1023 GST_OBJECT_LOCK (src);
1024 dur = gst_util_uint64_scale_int_round (bsrc->num_buffers
1025 * GST_SECOND, src->info.fps_d, src->info.fps_n);
1027 gst_query_set_duration (query, GST_FORMAT_TIME, dur);
1028 GST_OBJECT_UNLOCK (src);
1031 case GST_FORMAT_BYTES:
1032 GST_OBJECT_LOCK (src);
1034 gst_query_set_duration (query, GST_FORMAT_BYTES,
1035 bsrc->num_buffers * src->info.size);
1036 GST_OBJECT_UNLOCK (src);
1045 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
1053 gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
1054 GstClockTime * start, GstClockTime * end)
1056 /* for live sources, sync on the timestamp of the buffer */
1057 if (gst_base_src_is_live (basesrc)) {
1058 GstClockTime timestamp = GST_BUFFER_PTS (buffer);
1060 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
1061 /* get duration to calculate end time */
1062 GstClockTime duration = GST_BUFFER_DURATION (buffer);
1064 if (GST_CLOCK_TIME_IS_VALID (duration)) {
1065 *end = timestamp + duration;
1076 gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
1078 GstClockTime position;
1079 GstVideoTestSrc *src;
1081 src = GST_VIDEO_TEST_SRC (bsrc);
1083 segment->time = segment->start;
1084 position = segment->position;
1085 src->reverse = segment->rate < 0;
1087 /* now move to the position indicated */
1088 if (src->info.fps_n) {
1089 src->n_frames = gst_util_uint64_scale (position,
1090 src->info.fps_n, src->info.fps_d * GST_SECOND);
1094 src->accum_frames = 0;
1095 src->accum_rtime = 0;
1096 if (src->info.fps_n) {
1097 src->running_time = gst_util_uint64_scale (src->n_frames,
1098 src->info.fps_d * GST_SECOND, src->info.fps_n);
1100 /* FIXME : Not sure what to set here */
1101 src->running_time = 0;
1104 g_assert (src->running_time <= position);
1110 gst_video_test_src_is_seekable (GstBaseSrc * psrc)
1112 /* we're seekable... */
1116 static GstFlowReturn
1117 gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
1119 GstVideoTestSrc *src;
1120 GstClockTime next_time;
1121 GstVideoFrame frame;
1125 src = GST_VIDEO_TEST_SRC (psrc);
1127 if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&src->info) ==
1128 GST_VIDEO_FORMAT_UNKNOWN))
1129 goto not_negotiated;
1131 /* 0 framerate and we are at the second frame, eos */
1132 if (G_UNLIKELY (src->info.fps_n == 0 && src->n_frames == 1))
1135 if (G_UNLIKELY (src->n_frames == -1)) {
1136 /* EOS for reverse playback */
1140 GST_LOG_OBJECT (src,
1141 "creating buffer from pool for frame %d", (gint) src->n_frames);
1143 if (!gst_video_frame_map (&frame, &src->info, buffer, GST_MAP_WRITE))
1146 GST_BUFFER_PTS (buffer) =
1147 src->accum_rtime + src->timestamp_offset + src->running_time;
1148 GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE;
1150 gst_object_sync_values (GST_OBJECT (psrc), GST_BUFFER_PTS (buffer));
1152 src->make_image (src, GST_BUFFER_PTS (buffer), &frame);
1154 if ((pal = gst_video_format_get_palette (GST_VIDEO_FRAME_FORMAT (&frame),
1156 memcpy (GST_VIDEO_FRAME_PLANE_DATA (&frame, 1), pal, palsize);
1159 gst_video_frame_unmap (&frame);
1161 GST_DEBUG_OBJECT (src, "Timestamp: %" GST_TIME_FORMAT " = accumulated %"
1162 GST_TIME_FORMAT " + offset: %"
1163 GST_TIME_FORMAT " + running time: %" GST_TIME_FORMAT,
1164 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)), GST_TIME_ARGS (src->accum_rtime),
1165 GST_TIME_ARGS (src->timestamp_offset), GST_TIME_ARGS (src->running_time));
1167 GST_BUFFER_OFFSET (buffer) = src->accum_frames + src->n_frames;
1173 GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET (buffer) + 1;
1174 if (src->info.fps_n) {
1175 next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
1176 src->info.fps_d, src->info.fps_n);
1178 GST_BUFFER_DURATION (buffer) = src->running_time - next_time;
1180 GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
1183 next_time = src->timestamp_offset;
1184 /* NONE means forever */
1185 GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
1188 src->running_time = next_time;
1194 return GST_FLOW_NOT_NEGOTIATED;
1198 GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
1199 return GST_FLOW_EOS;
1203 GST_DEBUG_OBJECT (src, "invalid frame");
1209 gst_video_test_src_start (GstBaseSrc * basesrc)
1211 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
1213 GST_OBJECT_LOCK (src);
1214 src->running_time = 0;
1216 src->accum_frames = 0;
1217 src->accum_rtime = 0;
1219 gst_video_info_init (&src->info);
1220 GST_OBJECT_UNLOCK (src);
1226 gst_video_test_src_stop (GstBaseSrc * basesrc)
1228 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
1231 g_free (src->tmpline);
1232 src->tmpline = NULL;
1233 g_free (src->tmpline2);
1234 src->tmpline2 = NULL;
1235 g_free (src->tmpline_u8);
1236 src->tmpline_u8 = NULL;
1237 g_free (src->tmpline_u16);
1238 src->tmpline_u16 = NULL;
1240 gst_video_chroma_resample_free (src->subsample);
1241 src->subsample = NULL;
1243 for (i = 0; i < src->n_lines; i++)
1244 g_free (src->lines[i]);
1245 g_free (src->lines);
1253 plugin_init (GstPlugin * plugin)
1255 GST_DEBUG_CATEGORY_INIT (video_test_src_debug, "videotestsrc", 0,
1256 "Video Test Source");
1258 return gst_element_register (plugin, "videotestsrc", GST_RANK_NONE,
1259 GST_TYPE_VIDEO_TEST_SRC);
1262 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1265 "Creates a test video stream",
1266 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)