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 * By default the videotestsrc will generate data indefinitely, but if the
30 * #GstBaseSrc:num-buffers property is non-zero it will instead generate a
31 * fixed number of video frames and then send EOS.
33 * ## Example launch line
35 * gst-launch-1.0 -v videotestsrc pattern=snow ! video/x-raw,width=1280,height=720 ! autovideosink
37 * Shows random noise in a video window.
44 #include "gstvideotestsrc.h"
45 #include "gstvideotestsrcorc.h"
46 #include "videotestsrc.h"
51 GST_DEBUG_CATEGORY_STATIC (video_test_src_debug);
52 #define GST_CAT_DEFAULT video_test_src_debug
54 #define DEFAULT_PATTERN GST_VIDEO_TEST_SRC_SMPTE
55 #define DEFAULT_ANIMATION_MODE GST_VIDEO_TEST_SRC_FRAMES
56 #define DEFAULT_MOTION_TYPE GST_VIDEO_TEST_SRC_WAVY
57 #define DEFAULT_FLIP FALSE
58 #define DEFAULT_TIMESTAMP_OFFSET 0
59 #define DEFAULT_IS_LIVE FALSE
60 #define DEFAULT_COLOR_SPEC GST_VIDEO_TEST_SRC_BT601
61 #define DEFAULT_FOREGROUND_COLOR 0xffffffff
62 #define DEFAULT_BACKGROUND_COLOR 0xff000000
63 #define DEFAULT_HORIZONTAL_SPEED 0
69 PROP_TIMESTAMP_OFFSET,
83 PROP_FOREGROUND_COLOR,
84 PROP_BACKGROUND_COLOR,
85 PROP_HORIZONTAL_SPEED,
93 #define VTS_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) "," \
94 "multiview-mode = { mono, left, right }" \
96 "video/x-bayer, format=(string) { bggr, rggb, grbg, gbrg }, " \
97 "width = " GST_VIDEO_SIZE_RANGE ", " \
98 "height = " GST_VIDEO_SIZE_RANGE ", " \
99 "framerate = " GST_VIDEO_FPS_RANGE ", " \
100 "multiview-mode = { mono, left, right }"
103 static GstStaticPadTemplate gst_video_test_src_template =
104 GST_STATIC_PAD_TEMPLATE ("src",
107 GST_STATIC_CAPS (VTS_VIDEO_CAPS)
110 #define gst_video_test_src_parent_class parent_class
111 G_DEFINE_TYPE (GstVideoTestSrc, gst_video_test_src, GST_TYPE_PUSH_SRC);
112 GST_ELEMENT_REGISTER_DEFINE (videotestsrc, "videotestsrc",
113 GST_RANK_NONE, GST_TYPE_VIDEO_TEST_SRC);
115 static void gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
117 static void gst_video_test_src_set_property (GObject * object, guint prop_id,
118 const GValue * value, GParamSpec * pspec);
119 static void gst_video_test_src_get_property (GObject * object, guint prop_id,
120 GValue * value, GParamSpec * pspec);
122 static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
123 static GstCaps *gst_video_test_src_src_fixate (GstBaseSrc * bsrc,
126 static gboolean gst_video_test_src_is_seekable (GstBaseSrc * psrc);
127 static gboolean gst_video_test_src_do_seek (GstBaseSrc * bsrc,
128 GstSegment * segment);
129 static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
131 static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
132 GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
133 static gboolean gst_video_test_src_decide_allocation (GstBaseSrc * bsrc,
135 static GstFlowReturn gst_video_test_src_fill (GstPushSrc * psrc,
137 static gboolean gst_video_test_src_start (GstBaseSrc * basesrc);
138 static gboolean gst_video_test_src_stop (GstBaseSrc * basesrc);
140 #define GST_TYPE_VIDEO_TEST_SRC_PATTERN (gst_video_test_src_pattern_get_type ())
142 gst_video_test_src_pattern_get_type (void)
144 static GType video_test_src_pattern_type = 0;
145 static const GEnumValue pattern_types[] = {
146 {GST_VIDEO_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
147 {GST_VIDEO_TEST_SRC_SNOW, "Random (television snow)", "snow"},
148 {GST_VIDEO_TEST_SRC_BLACK, "100% Black", "black"},
149 {GST_VIDEO_TEST_SRC_WHITE, "100% White", "white"},
150 {GST_VIDEO_TEST_SRC_RED, "Red", "red"},
151 {GST_VIDEO_TEST_SRC_GREEN, "Green", "green"},
152 {GST_VIDEO_TEST_SRC_BLUE, "Blue", "blue"},
153 {GST_VIDEO_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
154 {GST_VIDEO_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
155 {GST_VIDEO_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
156 {GST_VIDEO_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
157 {GST_VIDEO_TEST_SRC_CIRCULAR, "Circular", "circular"},
158 {GST_VIDEO_TEST_SRC_BLINK, "Blink", "blink"},
159 {GST_VIDEO_TEST_SRC_SMPTE75, "SMPTE 75% color bars", "smpte75"},
160 {GST_VIDEO_TEST_SRC_ZONE_PLATE, "Zone plate", "zone-plate"},
161 {GST_VIDEO_TEST_SRC_GAMUT, "Gamut checkers", "gamut"},
162 {GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE, "Chroma zone plate",
163 "chroma-zone-plate"},
164 {GST_VIDEO_TEST_SRC_SOLID, "Solid color", "solid-color"},
165 {GST_VIDEO_TEST_SRC_BALL, "Moving ball", "ball"},
166 {GST_VIDEO_TEST_SRC_SMPTE100, "SMPTE 100% color bars", "smpte100"},
167 {GST_VIDEO_TEST_SRC_BAR, "Bar", "bar"},
168 {GST_VIDEO_TEST_SRC_PINWHEEL, "Pinwheel", "pinwheel"},
169 {GST_VIDEO_TEST_SRC_SPOKES, "Spokes", "spokes"},
170 {GST_VIDEO_TEST_SRC_GRADIENT, "Gradient", "gradient"},
171 {GST_VIDEO_TEST_SRC_COLORS, "Colors", "colors"},
175 if (!video_test_src_pattern_type) {
176 video_test_src_pattern_type =
177 g_enum_register_static ("GstVideoTestSrcPattern", pattern_types);
179 return video_test_src_pattern_type;
183 /*"animation-mode", which can
184 * take the following values: frames (current behaviour that should stay the
185 * default), running time, wall clock time.
188 #define GST_TYPE_VIDEO_TEST_SRC_ANIMATION_MODE (gst_video_test_src_animation_mode_get_type ())
190 gst_video_test_src_animation_mode_get_type (void)
192 static GType video_test_src_animation_mode = 0;
193 static const GEnumValue animation_modes[] = {
195 {GST_VIDEO_TEST_SRC_FRAMES, "frame count", "frames"},
196 {GST_VIDEO_TEST_SRC_WALL_TIME, "wall clock time", "wall-time"},
197 {GST_VIDEO_TEST_SRC_RUNNING_TIME, "running time", "running-time"},
201 if (!video_test_src_animation_mode) {
202 video_test_src_animation_mode =
203 g_enum_register_static ("GstVideoTestSrcAnimationMode",
206 return video_test_src_animation_mode;
210 #define GST_TYPE_VIDEO_TEST_SRC_MOTION_TYPE (gst_video_test_src_motion_type_get_type ())
212 gst_video_test_src_motion_type_get_type (void)
214 static GType video_test_src_motion_type = 0;
215 static const GEnumValue motion_types[] = {
216 {GST_VIDEO_TEST_SRC_WAVY, "Ball waves back and forth, up and down",
218 {GST_VIDEO_TEST_SRC_SWEEP, "1 revolution per second", "sweep"},
219 {GST_VIDEO_TEST_SRC_HSWEEP, "1/2 revolution per second, then reset to top",
224 if (!video_test_src_motion_type) {
225 video_test_src_motion_type =
226 g_enum_register_static ("GstVideoTestSrcMotionType", motion_types);
228 return video_test_src_motion_type;
233 gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
235 GObjectClass *gobject_class;
236 GstElementClass *gstelement_class;
237 GstBaseSrcClass *gstbasesrc_class;
238 GstPushSrcClass *gstpushsrc_class;
240 gobject_class = (GObjectClass *) klass;
241 gstelement_class = (GstElementClass *) klass;
242 gstbasesrc_class = (GstBaseSrcClass *) klass;
243 gstpushsrc_class = (GstPushSrcClass *) klass;
245 gobject_class->set_property = gst_video_test_src_set_property;
246 gobject_class->get_property = gst_video_test_src_get_property;
248 g_object_class_install_property (gobject_class, PROP_PATTERN,
249 g_param_spec_enum ("pattern", "Pattern",
250 "Type of test pattern to generate", GST_TYPE_VIDEO_TEST_SRC_PATTERN,
251 DEFAULT_PATTERN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
253 g_object_class_install_property (gobject_class, PROP_ANIMATION_MODE,
254 g_param_spec_enum ("animation-mode", "Animation mode",
255 "For pattern=ball, which counter defines the position of the ball.",
256 GST_TYPE_VIDEO_TEST_SRC_ANIMATION_MODE, DEFAULT_ANIMATION_MODE,
257 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
259 g_object_class_install_property (gobject_class, PROP_MOTION_TYPE,
260 g_param_spec_enum ("motion", "Motion",
261 "For pattern=ball, what motion the ball does",
262 GST_TYPE_VIDEO_TEST_SRC_MOTION_TYPE, DEFAULT_MOTION_TYPE,
263 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
265 g_object_class_install_property (gobject_class, PROP_FLIP,
266 g_param_spec_boolean ("flip", "Flip",
267 "For pattern=ball, invert colors every second.",
268 DEFAULT_FLIP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
270 g_object_class_install_property (gobject_class, PROP_TIMESTAMP_OFFSET,
271 g_param_spec_int64 ("timestamp-offset", "Timestamp offset",
272 "An offset added to timestamps set on buffers (in ns)", 0,
273 (G_MAXLONG == G_MAXINT64) ? G_MAXINT64 : (G_MAXLONG * GST_SECOND - 1),
274 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
275 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
276 g_param_spec_boolean ("is-live", "Is Live",
277 "Whether to act as a live source", DEFAULT_IS_LIVE,
278 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
279 g_object_class_install_property (gobject_class, PROP_K0,
280 g_param_spec_int ("k0", "Zoneplate zero order phase",
281 "Zoneplate zero order phase, for generating plain fields or phase offsets",
282 G_MININT32, G_MAXINT32, 0,
283 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
284 g_object_class_install_property (gobject_class, PROP_KX,
285 g_param_spec_int ("kx", "Zoneplate 1st order x phase",
286 "Zoneplate 1st order x phase, for generating constant horizontal frequencies",
287 G_MININT32, G_MAXINT32, 0,
288 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
289 g_object_class_install_property (gobject_class, PROP_KY,
290 g_param_spec_int ("ky", "Zoneplate 1st order y phase",
291 "Zoneplate 1st order y phase, for generating content vertical frequencies",
292 G_MININT32, G_MAXINT32, 0,
293 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
294 g_object_class_install_property (gobject_class, PROP_KT,
295 g_param_spec_int ("kt", "Zoneplate 1st order t phase",
296 "Zoneplate 1st order t phase, for generating phase rotation as a function of time",
297 G_MININT32, G_MAXINT32, 0,
298 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
299 g_object_class_install_property (gobject_class, PROP_KXT,
300 g_param_spec_int ("kxt", "Zoneplate x*t product phase",
301 "Zoneplate x*t product phase, normalised to kxy/256 cycles per vertical pixel at width/2 from origin",
302 G_MININT32, G_MAXINT32, 0,
303 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
304 g_object_class_install_property (gobject_class, PROP_KYT,
305 g_param_spec_int ("kyt", "Zoneplate y*t product phase",
306 "Zoneplate y*t product phase", G_MININT32, G_MAXINT32, 0,
307 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
308 g_object_class_install_property (gobject_class, PROP_KXY,
309 g_param_spec_int ("kxy", "Zoneplate x*y product phase",
310 "Zoneplate x*y product phase", G_MININT32, G_MAXINT32, 0,
311 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
312 g_object_class_install_property (gobject_class, PROP_KX2,
313 g_param_spec_int ("kx2", "Zoneplate 2nd order x phase",
314 "Zoneplate 2nd order x phase, normalised to kx2/256 cycles per horizontal pixel at width/2 from origin",
315 G_MININT32, G_MAXINT32, 0,
316 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
317 g_object_class_install_property (gobject_class, PROP_KY2,
318 g_param_spec_int ("ky2", "Zoneplate 2nd order y phase",
319 "Zoneplate 2nd order y phase, normailsed to ky2/256 cycles per vertical pixel at height/2 from origin",
320 G_MININT32, G_MAXINT32, 0,
321 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
322 g_object_class_install_property (gobject_class, PROP_KT2,
323 g_param_spec_int ("kt2", "Zoneplate 2nd order t phase",
324 "Zoneplate 2nd order t phase, t*t/256 cycles per picture", G_MININT32,
325 G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
326 g_object_class_install_property (gobject_class, PROP_XOFFSET,
327 g_param_spec_int ("xoffset", "Zoneplate 2nd order products x offset",
328 "Zoneplate 2nd order products x offset", G_MININT32, G_MAXINT32, 0,
329 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
330 g_object_class_install_property (gobject_class, PROP_YOFFSET,
331 g_param_spec_int ("yoffset", "Zoneplate 2nd order products y offset",
332 "Zoneplate 2nd order products y offset", G_MININT32, G_MAXINT32, 0,
333 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
335 * GstVideoTestSrc:foreground-color
337 * Color to use for solid-color pattern and foreground color of other
338 * patterns. Default is white (0xffffffff).
340 g_object_class_install_property (gobject_class, PROP_FOREGROUND_COLOR,
341 g_param_spec_uint ("foreground-color", "Foreground Color",
342 "Foreground color to use (big-endian ARGB)", 0, G_MAXUINT32,
343 DEFAULT_FOREGROUND_COLOR,
344 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
346 * GstVideoTestSrc:background-color
348 * Color to use for background color of some patterns. Default is
349 * black (0xff000000).
351 g_object_class_install_property (gobject_class, PROP_BACKGROUND_COLOR,
352 g_param_spec_uint ("background-color", "Background Color",
353 "Background color to use (big-endian ARGB)", 0, G_MAXUINT32,
354 DEFAULT_BACKGROUND_COLOR,
355 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
357 g_object_class_install_property (gobject_class, PROP_HORIZONTAL_SPEED,
358 g_param_spec_int ("horizontal-speed", "Horizontal Speed",
359 "Scroll image number of pixels per frame (positive is scroll to the left)",
360 G_MININT32, G_MAXINT32, DEFAULT_HORIZONTAL_SPEED,
361 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
363 gst_element_class_set_static_metadata (gstelement_class,
364 "Video test source", "Source/Video",
365 "Creates a test video stream", "David A. Schleef <ds@schleef.org>");
367 gst_element_class_add_static_pad_template (gstelement_class,
368 &gst_video_test_src_template);
370 gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
371 gstbasesrc_class->fixate = gst_video_test_src_src_fixate;
372 gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
373 gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
374 gstbasesrc_class->query = gst_video_test_src_query;
375 gstbasesrc_class->get_times = gst_video_test_src_get_times;
376 gstbasesrc_class->start = gst_video_test_src_start;
377 gstbasesrc_class->stop = gst_video_test_src_stop;
378 gstbasesrc_class->decide_allocation = gst_video_test_src_decide_allocation;
380 gstpushsrc_class->fill = gst_video_test_src_fill;
382 gst_type_mark_as_plugin_api (GST_TYPE_VIDEO_TEST_SRC_ANIMATION_MODE, 0);
383 gst_type_mark_as_plugin_api (GST_TYPE_VIDEO_TEST_SRC_MOTION_TYPE, 0);
384 gst_type_mark_as_plugin_api (GST_TYPE_VIDEO_TEST_SRC_PATTERN, 0);
388 gst_video_test_src_init (GstVideoTestSrc * src)
390 gst_video_test_src_set_pattern (src, DEFAULT_PATTERN);
392 src->timestamp_offset = DEFAULT_TIMESTAMP_OFFSET;
393 src->foreground_color = DEFAULT_FOREGROUND_COLOR;
394 src->background_color = DEFAULT_BACKGROUND_COLOR;
395 src->horizontal_speed = DEFAULT_HORIZONTAL_SPEED;
396 src->random_state = 0;
398 /* we operate in time */
399 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
400 gst_base_src_set_live (GST_BASE_SRC (src), DEFAULT_IS_LIVE);
402 src->animation_mode = DEFAULT_ANIMATION_MODE;
403 src->motion_type = DEFAULT_MOTION_TYPE;
404 src->flip = DEFAULT_FLIP;
409 gst_video_test_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
411 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (bsrc);
412 GstStructure *structure;
414 /* Check if foreground color has alpha, if it is the case,
415 * force color format with an alpha channel downstream */
416 if (src->foreground_color >> 24 != 255) {
418 GstCaps *alpha_only_caps = gst_caps_new_empty ();
420 for (i = 0; i < gst_caps_get_size (caps); i++) {
421 const GstVideoFormatInfo *info;
422 const GValue *formats =
423 gst_structure_get_value (gst_caps_get_structure (caps, i),
426 if (GST_VALUE_HOLDS_LIST (formats)) {
427 GValue possible_formats = { 0, };
428 guint list_size = gst_value_list_get_size (formats);
431 g_value_init (&possible_formats, GST_TYPE_LIST);
432 for (index = 0; index < list_size; index++) {
433 const GValue *list_item = gst_value_list_get_value (formats, index);
435 gst_video_format_get_info (gst_video_format_from_string
436 (g_value_get_string (list_item)));
437 if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
440 gst_value_init_and_copy (&tmp, list_item);
441 gst_value_list_append_value (&possible_formats, &tmp);
445 if (gst_value_list_get_size (&possible_formats)) {
446 GstStructure *astruct =
447 gst_structure_copy (gst_caps_get_structure (caps, i));
449 gst_structure_set_value (astruct, "format", &possible_formats);
450 gst_caps_append_structure (alpha_only_caps, astruct);
453 } else if (G_VALUE_HOLDS_STRING (formats)) {
455 gst_video_format_get_info (gst_video_format_from_string
456 (g_value_get_string (formats)));
458 if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
459 gst_caps_append_structure (alpha_only_caps,
460 gst_structure_copy (gst_caps_get_structure (caps, i)));
463 g_assert_not_reached ();
464 GST_WARNING ("Unexpected type for video 'format' field: %s",
465 G_VALUE_TYPE_NAME (formats));
469 if (gst_caps_is_empty (alpha_only_caps)) {
470 GST_WARNING_OBJECT (src,
471 "Foreground color contains alpha, but downstream can't support alpha.");
473 gst_caps_replace (&caps, alpha_only_caps);
477 caps = gst_caps_make_writable (caps);
478 structure = gst_caps_get_structure (caps, 0);
480 gst_structure_fixate_field_nearest_int (structure, "width", 320);
481 gst_structure_fixate_field_nearest_int (structure, "height", 240);
483 if (gst_structure_has_field (structure, "framerate"))
484 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
486 gst_structure_set (structure, "framerate", GST_TYPE_FRACTION, 30, 1, NULL);
488 if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
489 gst_structure_fixate_field_nearest_fraction (structure,
490 "pixel-aspect-ratio", 1, 1);
492 gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
495 if (gst_structure_has_field (structure, "colorimetry"))
496 gst_structure_fixate_field_string (structure, "colorimetry", "bt601");
497 if (gst_structure_has_field (structure, "chroma-site"))
498 gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
500 if (gst_structure_has_field (structure, "interlace-mode"))
501 gst_structure_fixate_field_string (structure, "interlace-mode",
504 gst_structure_set (structure, "interlace-mode", G_TYPE_STRING,
505 "progressive", NULL);
507 if (gst_structure_has_field (structure, "multiview-mode"))
508 gst_structure_fixate_field_string (structure, "multiview-mode",
509 gst_video_multiview_mode_to_caps_string
510 (GST_VIDEO_MULTIVIEW_MODE_MONO));
512 gst_structure_set (structure, "multiview-mode", G_TYPE_STRING,
513 gst_video_multiview_mode_to_caps_string (GST_VIDEO_MULTIVIEW_MODE_MONO),
516 caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
522 gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
525 videotestsrc->pattern_type = pattern_type;
527 GST_DEBUG_OBJECT (videotestsrc, "setting pattern to %d", pattern_type);
529 switch (pattern_type) {
530 case GST_VIDEO_TEST_SRC_SMPTE:
531 videotestsrc->make_image = gst_video_test_src_smpte;
533 case GST_VIDEO_TEST_SRC_SNOW:
534 videotestsrc->make_image = gst_video_test_src_snow;
536 case GST_VIDEO_TEST_SRC_BLACK:
537 videotestsrc->make_image = gst_video_test_src_black;
539 case GST_VIDEO_TEST_SRC_WHITE:
540 videotestsrc->make_image = gst_video_test_src_white;
542 case GST_VIDEO_TEST_SRC_RED:
543 videotestsrc->make_image = gst_video_test_src_red;
545 case GST_VIDEO_TEST_SRC_GREEN:
546 videotestsrc->make_image = gst_video_test_src_green;
548 case GST_VIDEO_TEST_SRC_BLUE:
549 videotestsrc->make_image = gst_video_test_src_blue;
551 case GST_VIDEO_TEST_SRC_CHECKERS1:
552 videotestsrc->make_image = gst_video_test_src_checkers1;
554 case GST_VIDEO_TEST_SRC_CHECKERS2:
555 videotestsrc->make_image = gst_video_test_src_checkers2;
557 case GST_VIDEO_TEST_SRC_CHECKERS4:
558 videotestsrc->make_image = gst_video_test_src_checkers4;
560 case GST_VIDEO_TEST_SRC_CHECKERS8:
561 videotestsrc->make_image = gst_video_test_src_checkers8;
563 case GST_VIDEO_TEST_SRC_CIRCULAR:
564 videotestsrc->make_image = gst_video_test_src_circular;
566 case GST_VIDEO_TEST_SRC_BLINK:
567 videotestsrc->make_image = gst_video_test_src_blink;
569 case GST_VIDEO_TEST_SRC_SMPTE75:
570 videotestsrc->make_image = gst_video_test_src_smpte75;
572 case GST_VIDEO_TEST_SRC_ZONE_PLATE:
573 videotestsrc->make_image = gst_video_test_src_zoneplate;
575 case GST_VIDEO_TEST_SRC_GAMUT:
576 videotestsrc->make_image = gst_video_test_src_gamut;
578 case GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE:
579 videotestsrc->make_image = gst_video_test_src_chromazoneplate;
581 case GST_VIDEO_TEST_SRC_SOLID:
582 videotestsrc->make_image = gst_video_test_src_solid;
584 case GST_VIDEO_TEST_SRC_BALL:
585 videotestsrc->make_image = gst_video_test_src_ball;
587 case GST_VIDEO_TEST_SRC_SMPTE100:
588 videotestsrc->make_image = gst_video_test_src_smpte100;
590 case GST_VIDEO_TEST_SRC_BAR:
591 videotestsrc->make_image = gst_video_test_src_bar;
593 case GST_VIDEO_TEST_SRC_PINWHEEL:
594 videotestsrc->make_image = gst_video_test_src_pinwheel;
596 case GST_VIDEO_TEST_SRC_SPOKES:
597 videotestsrc->make_image = gst_video_test_src_spokes;
599 case GST_VIDEO_TEST_SRC_GRADIENT:
600 videotestsrc->make_image = gst_video_test_src_gradient;
602 case GST_VIDEO_TEST_SRC_COLORS:
603 videotestsrc->make_image = gst_video_test_src_colors;
606 g_assert_not_reached ();
611 gst_video_test_src_set_property (GObject * object, guint prop_id,
612 const GValue * value, GParamSpec * pspec)
614 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
618 gst_video_test_src_set_pattern (src, g_value_get_enum (value));
620 case PROP_TIMESTAMP_OFFSET:
621 src->timestamp_offset = g_value_get_int64 (value);
624 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
627 src->k0 = g_value_get_int (value);
630 src->kx = g_value_get_int (value);
633 src->ky = g_value_get_int (value);
636 src->kt = g_value_get_int (value);
639 src->kxt = g_value_get_int (value);
642 src->kyt = g_value_get_int (value);
645 src->kxy = g_value_get_int (value);
648 src->kx2 = g_value_get_int (value);
651 src->ky2 = g_value_get_int (value);
654 src->kt2 = g_value_get_int (value);
657 src->xoffset = g_value_get_int (value);
660 src->yoffset = g_value_get_int (value);
662 case PROP_FOREGROUND_COLOR:
663 src->foreground_color = g_value_get_uint (value);
665 case PROP_BACKGROUND_COLOR:
666 src->background_color = g_value_get_uint (value);
668 case PROP_HORIZONTAL_SPEED:
669 src->horizontal_speed = g_value_get_int (value);
671 case PROP_ANIMATION_MODE:
672 src->animation_mode = g_value_get_enum (value);
674 case PROP_MOTION_TYPE:
675 src->motion_type = g_value_get_enum (value);
678 src->flip = g_value_get_boolean (value);
686 gst_video_test_src_get_property (GObject * object, guint prop_id,
687 GValue * value, GParamSpec * pspec)
689 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
693 g_value_set_enum (value, src->pattern_type);
695 case PROP_TIMESTAMP_OFFSET:
696 g_value_set_int64 (value, src->timestamp_offset);
699 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
702 g_value_set_int (value, src->k0);
705 g_value_set_int (value, src->kx);
708 g_value_set_int (value, src->ky);
711 g_value_set_int (value, src->kt);
714 g_value_set_int (value, src->kxt);
717 g_value_set_int (value, src->kyt);
720 g_value_set_int (value, src->kxy);
723 g_value_set_int (value, src->kx2);
726 g_value_set_int (value, src->ky2);
729 g_value_set_int (value, src->kt2);
732 g_value_set_int (value, src->xoffset);
735 g_value_set_int (value, src->yoffset);
737 case PROP_FOREGROUND_COLOR:
738 g_value_set_uint (value, src->foreground_color);
740 case PROP_BACKGROUND_COLOR:
741 g_value_set_uint (value, src->background_color);
743 case PROP_HORIZONTAL_SPEED:
744 g_value_set_int (value, src->horizontal_speed);
746 case PROP_ANIMATION_MODE:
747 g_value_set_enum (value, src->animation_mode);
749 case PROP_MOTION_TYPE:
750 g_value_set_enum (value, src->motion_type);
753 g_value_set_boolean (value, src->flip);
756 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
762 gst_video_test_src_parse_caps (const GstCaps * caps,
763 gint * width, gint * height, gint * fps_n, gint * fps_d,
764 GstVideoColorimetry * colorimetry, gint * x_inv, gint * y_inv)
766 const GstStructure *structure;
767 GstPadLinkReturn ret;
768 const GValue *framerate;
771 GST_DEBUG ("parsing caps");
773 structure = gst_caps_get_structure (caps, 0);
775 ret = gst_structure_get_int (structure, "width", width);
776 ret &= gst_structure_get_int (structure, "height", height);
777 framerate = gst_structure_get_value (structure, "framerate");
780 *fps_n = gst_value_get_fraction_numerator (framerate);
781 *fps_d = gst_value_get_fraction_denominator (framerate);
785 if ((str = gst_structure_get_string (structure, "colorimetry")))
786 gst_video_colorimetry_from_string (colorimetry, str);
788 if ((str = gst_structure_get_string (structure, "format"))) {
789 if (g_str_equal (str, "bggr")) {
791 } else if (g_str_equal (str, "rggb")) {
793 } else if (g_str_equal (str, "grbg")) {
796 } else if (g_str_equal (str, "gbrg")) {
807 GST_DEBUG ("videotestsrc no framerate given");
812 GST_DEBUG ("videotestsrc invalid bayer format given");
818 gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
820 GstVideoTestSrc *videotestsrc;
823 guint size, min, max;
824 GstStructure *config;
825 GstCaps *caps = NULL;
827 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
829 if (gst_query_get_n_allocation_pools (query) > 0) {
830 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
833 size = MAX (size, videotestsrc->info.size);
837 size = videotestsrc->info.size;
842 /* no downstream pool, make our own */
844 if (videotestsrc->bayer)
845 pool = gst_buffer_pool_new ();
847 pool = gst_video_buffer_pool_new ();
850 config = gst_buffer_pool_get_config (pool);
852 gst_query_parse_allocation (query, &caps, NULL);
854 gst_buffer_pool_config_set_params (config, caps, size, min, max);
856 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
857 gst_buffer_pool_config_add_option (config,
858 GST_BUFFER_POOL_OPTION_VIDEO_META);
860 gst_buffer_pool_set_config (pool, config);
863 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
865 gst_query_add_allocation_pool (query, pool, size, min, max);
868 gst_object_unref (pool);
870 return GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query);
874 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
876 const GstStructure *structure;
877 GstVideoTestSrc *videotestsrc;
883 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
885 structure = gst_caps_get_structure (caps, 0);
887 GST_OBJECT_LOCK (videotestsrc);
889 if (gst_structure_has_name (structure, "video/x-raw")) {
890 /* we can use the parsing code */
891 if (!gst_video_info_from_caps (&info, caps))
894 } else if (gst_structure_has_name (structure, "video/x-bayer")) {
895 gint x_inv = 0, y_inv = 0;
897 gst_video_info_init (&info);
899 info.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8);
901 if (!gst_video_test_src_parse_caps (caps, &info.width, &info.height,
902 &info.fps_n, &info.fps_d, &info.colorimetry, &x_inv, &y_inv))
905 info.size = GST_ROUND_UP_4 (info.width) * info.height;
906 info.stride[0] = GST_ROUND_UP_4 (info.width);
908 videotestsrc->bayer = TRUE;
909 videotestsrc->x_invert = x_inv;
910 videotestsrc->y_invert = y_inv;
912 goto unsupported_caps;
915 /* create chroma subsampler */
916 if (videotestsrc->subsample)
917 gst_video_chroma_resample_free (videotestsrc->subsample);
918 videotestsrc->subsample = gst_video_chroma_resample_new (0,
919 info.chroma_site, 0, info.finfo->unpack_format, -info.finfo->w_sub[2],
920 -info.finfo->h_sub[2]);
922 for (i = 0; i < videotestsrc->n_lines; i++)
923 g_free (videotestsrc->lines[i]);
924 g_free (videotestsrc->lines);
926 if (videotestsrc->subsample != NULL) {
927 gst_video_chroma_resample_get_info (videotestsrc->subsample,
934 videotestsrc->lines = g_malloc (sizeof (gpointer) * n_lines);
935 for (i = 0; i < n_lines; i++)
936 videotestsrc->lines[i] = g_malloc ((info.width + 16) * 8);
937 videotestsrc->n_lines = n_lines;
938 videotestsrc->offset = offset;
941 videotestsrc->info = info;
943 GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
944 info.width, info.height, info.fps_n, info.fps_d);
946 g_free (videotestsrc->tmpline);
947 g_free (videotestsrc->tmpline2);
948 g_free (videotestsrc->tmpline_u8);
949 g_free (videotestsrc->tmpline_u16);
950 videotestsrc->tmpline_u8 = g_malloc (info.width + 8);
951 videotestsrc->tmpline = g_malloc ((info.width + 8) * 4);
952 videotestsrc->tmpline2 = g_malloc ((info.width + 8) * 4);
953 videotestsrc->tmpline_u16 = g_malloc ((info.width + 16) * 8);
955 videotestsrc->accum_rtime += videotestsrc->running_time;
956 videotestsrc->accum_frames += videotestsrc->n_frames;
958 videotestsrc->running_time = 0;
959 videotestsrc->n_frames = 0;
961 GST_OBJECT_UNLOCK (videotestsrc);
968 GST_OBJECT_UNLOCK (videotestsrc);
969 GST_DEBUG_OBJECT (bsrc, "failed to parse caps");
974 GST_OBJECT_UNLOCK (videotestsrc);
975 GST_DEBUG_OBJECT (bsrc, "unsupported caps: %" GST_PTR_FORMAT, caps);
981 gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
983 gboolean res = FALSE;
984 GstVideoTestSrc *src;
986 src = GST_VIDEO_TEST_SRC (bsrc);
988 switch (GST_QUERY_TYPE (query)) {
989 case GST_QUERY_CONVERT:
991 GstFormat src_fmt, dest_fmt;
992 gint64 src_val, dest_val;
994 GST_OBJECT_LOCK (src);
995 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
997 gst_video_info_convert (&src->info, src_fmt, src_val, dest_fmt,
999 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
1000 GST_OBJECT_UNLOCK (src);
1003 case GST_QUERY_LATENCY:
1005 GST_OBJECT_LOCK (src);
1006 if (src->info.fps_n > 0) {
1007 GstClockTime latency;
1010 gst_util_uint64_scale (GST_SECOND, src->info.fps_d,
1012 GST_OBJECT_UNLOCK (src);
1013 gst_query_set_latency (query,
1014 gst_base_src_is_live (GST_BASE_SRC_CAST (src)), latency,
1015 GST_CLOCK_TIME_NONE);
1016 GST_DEBUG_OBJECT (src, "Reporting latency of %" GST_TIME_FORMAT,
1017 GST_TIME_ARGS (latency));
1020 GST_OBJECT_UNLOCK (src);
1024 case GST_QUERY_DURATION:{
1025 if (bsrc->num_buffers != -1) {
1028 gst_query_parse_duration (query, &format, NULL);
1030 case GST_FORMAT_TIME:{
1033 GST_OBJECT_LOCK (src);
1034 if (src->info.fps_n) {
1035 dur = gst_util_uint64_scale_int_round (bsrc->num_buffers
1036 * GST_SECOND, src->info.fps_d, src->info.fps_n);
1038 gst_query_set_duration (query, GST_FORMAT_TIME, dur);
1040 GST_OBJECT_UNLOCK (src);
1043 case GST_FORMAT_BYTES:
1044 GST_OBJECT_LOCK (src);
1046 gst_query_set_duration (query, GST_FORMAT_BYTES,
1047 bsrc->num_buffers * src->info.size);
1048 GST_OBJECT_UNLOCK (src);
1057 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
1065 gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
1066 GstClockTime * start, GstClockTime * end)
1068 /* for live sources, sync on the timestamp of the buffer */
1069 if (gst_base_src_is_live (basesrc)) {
1070 GstClockTime timestamp = GST_BUFFER_PTS (buffer);
1072 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
1073 /* get duration to calculate end time */
1074 GstClockTime duration = GST_BUFFER_DURATION (buffer);
1076 if (GST_CLOCK_TIME_IS_VALID (duration)) {
1077 *end = timestamp + duration;
1088 gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
1090 GstClockTime position;
1091 GstVideoTestSrc *src;
1093 src = GST_VIDEO_TEST_SRC (bsrc);
1095 segment->time = segment->start;
1096 position = segment->position;
1097 src->reverse = segment->rate < 0;
1099 /* now move to the position indicated */
1100 if (src->info.fps_n) {
1101 src->n_frames = gst_util_uint64_scale (position,
1102 src->info.fps_n, src->info.fps_d * GST_SECOND);
1106 src->accum_frames = 0;
1107 src->accum_rtime = 0;
1108 if (src->info.fps_n) {
1109 src->running_time = gst_util_uint64_scale (src->n_frames,
1110 src->info.fps_d * GST_SECOND, src->info.fps_n);
1112 /* FIXME : Not sure what to set here */
1113 src->running_time = 0;
1116 g_assert (src->running_time <= position);
1122 gst_video_test_src_is_seekable (GstBaseSrc * psrc)
1124 /* we're seekable... */
1128 static GstFlowReturn
1129 gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
1131 GstVideoTestSrc *src;
1132 GstClockTime next_time;
1133 GstVideoFrame frame;
1137 src = GST_VIDEO_TEST_SRC (psrc);
1139 if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&src->info) ==
1140 GST_VIDEO_FORMAT_UNKNOWN))
1141 goto not_negotiated;
1143 /* 0 framerate and we are at the second frame, eos */
1144 if (G_UNLIKELY (src->info.fps_n == 0 && src->n_frames == 1))
1147 if (G_UNLIKELY (src->n_frames == -1)) {
1148 /* EOS for reverse playback */
1152 GST_LOG_OBJECT (src,
1153 "creating buffer from pool for frame %" G_GINT64_FORMAT, src->n_frames);
1155 if (!gst_video_frame_map (&frame, &src->info, buffer, GST_MAP_WRITE))
1158 GST_BUFFER_PTS (buffer) =
1159 src->accum_rtime + src->timestamp_offset + src->running_time;
1160 GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE;
1162 gst_object_sync_values (GST_OBJECT (psrc), GST_BUFFER_PTS (buffer));
1164 src->make_image (src, GST_BUFFER_PTS (buffer), &frame);
1166 if ((pal = gst_video_format_get_palette (GST_VIDEO_FRAME_FORMAT (&frame),
1168 memcpy (GST_VIDEO_FRAME_PLANE_DATA (&frame, 1), pal, palsize);
1171 gst_video_frame_unmap (&frame);
1173 GST_DEBUG_OBJECT (src, "Timestamp: %" GST_TIME_FORMAT " = accumulated %"
1174 GST_TIME_FORMAT " + offset: %"
1175 GST_TIME_FORMAT " + running time: %" GST_TIME_FORMAT,
1176 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)), GST_TIME_ARGS (src->accum_rtime),
1177 GST_TIME_ARGS (src->timestamp_offset), GST_TIME_ARGS (src->running_time));
1179 GST_BUFFER_OFFSET (buffer) = src->accum_frames + src->n_frames;
1185 GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET (buffer) + 1;
1186 if (src->info.fps_n) {
1187 next_time = gst_util_uint64_scale (src->n_frames,
1188 src->info.fps_d * GST_SECOND, src->info.fps_n);
1190 /* We already decremented to next frame */
1191 GstClockTime prev_pts = gst_util_uint64_scale (src->n_frames + 2,
1192 src->info.fps_d * GST_SECOND, src->info.fps_n);
1194 GST_BUFFER_DURATION (buffer) = prev_pts - GST_BUFFER_PTS (buffer);
1196 GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
1199 next_time = src->timestamp_offset;
1200 /* NONE means forever */
1201 GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
1204 src->running_time = next_time;
1210 return GST_FLOW_NOT_NEGOTIATED;
1214 GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
1215 return GST_FLOW_EOS;
1219 GST_DEBUG_OBJECT (src, "invalid frame");
1225 gst_video_test_src_start (GstBaseSrc * basesrc)
1227 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
1229 GST_OBJECT_LOCK (src);
1230 src->running_time = 0;
1232 src->accum_frames = 0;
1233 src->accum_rtime = 0;
1235 gst_video_info_init (&src->info);
1236 GST_OBJECT_UNLOCK (src);
1242 gst_video_test_src_stop (GstBaseSrc * basesrc)
1244 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
1247 g_free (src->tmpline);
1248 src->tmpline = NULL;
1249 g_free (src->tmpline2);
1250 src->tmpline2 = NULL;
1251 g_free (src->tmpline_u8);
1252 src->tmpline_u8 = NULL;
1253 g_free (src->tmpline_u16);
1254 src->tmpline_u16 = NULL;
1256 gst_video_chroma_resample_free (src->subsample);
1257 src->subsample = NULL;
1259 for (i = 0; i < src->n_lines; i++)
1260 g_free (src->lines[i]);
1261 g_free (src->lines);
1269 plugin_init (GstPlugin * plugin)
1271 GST_DEBUG_CATEGORY_INIT (video_test_src_debug, "videotestsrc", 0,
1272 "Video Test Source");
1274 return GST_ELEMENT_REGISTER (videotestsrc, plugin);
1277 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1280 "Creates a test video stream",
1281 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)