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);
113 static void gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
115 static void gst_video_test_src_set_property (GObject * object, guint prop_id,
116 const GValue * value, GParamSpec * pspec);
117 static void gst_video_test_src_get_property (GObject * object, guint prop_id,
118 GValue * value, GParamSpec * pspec);
120 static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
121 static GstCaps *gst_video_test_src_src_fixate (GstBaseSrc * bsrc,
124 static gboolean gst_video_test_src_is_seekable (GstBaseSrc * psrc);
125 static gboolean gst_video_test_src_do_seek (GstBaseSrc * bsrc,
126 GstSegment * segment);
127 static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
129 static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
130 GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
131 static gboolean gst_video_test_src_decide_allocation (GstBaseSrc * bsrc,
133 static GstFlowReturn gst_video_test_src_fill (GstPushSrc * psrc,
135 static gboolean gst_video_test_src_start (GstBaseSrc * basesrc);
136 static gboolean gst_video_test_src_stop (GstBaseSrc * basesrc);
138 #define GST_TYPE_VIDEO_TEST_SRC_PATTERN (gst_video_test_src_pattern_get_type ())
140 gst_video_test_src_pattern_get_type (void)
142 static GType video_test_src_pattern_type = 0;
143 static const GEnumValue pattern_types[] = {
144 {GST_VIDEO_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
145 {GST_VIDEO_TEST_SRC_SNOW, "Random (television snow)", "snow"},
146 {GST_VIDEO_TEST_SRC_BLACK, "100% Black", "black"},
147 {GST_VIDEO_TEST_SRC_WHITE, "100% White", "white"},
148 {GST_VIDEO_TEST_SRC_RED, "Red", "red"},
149 {GST_VIDEO_TEST_SRC_GREEN, "Green", "green"},
150 {GST_VIDEO_TEST_SRC_BLUE, "Blue", "blue"},
151 {GST_VIDEO_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
152 {GST_VIDEO_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
153 {GST_VIDEO_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
154 {GST_VIDEO_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
155 {GST_VIDEO_TEST_SRC_CIRCULAR, "Circular", "circular"},
156 {GST_VIDEO_TEST_SRC_BLINK, "Blink", "blink"},
157 {GST_VIDEO_TEST_SRC_SMPTE75, "SMPTE 75% color bars", "smpte75"},
158 {GST_VIDEO_TEST_SRC_ZONE_PLATE, "Zone plate", "zone-plate"},
159 {GST_VIDEO_TEST_SRC_GAMUT, "Gamut checkers", "gamut"},
160 {GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE, "Chroma zone plate",
161 "chroma-zone-plate"},
162 {GST_VIDEO_TEST_SRC_SOLID, "Solid color", "solid-color"},
163 {GST_VIDEO_TEST_SRC_BALL, "Moving ball", "ball"},
164 {GST_VIDEO_TEST_SRC_SMPTE100, "SMPTE 100% color bars", "smpte100"},
165 {GST_VIDEO_TEST_SRC_BAR, "Bar", "bar"},
166 {GST_VIDEO_TEST_SRC_PINWHEEL, "Pinwheel", "pinwheel"},
167 {GST_VIDEO_TEST_SRC_SPOKES, "Spokes", "spokes"},
168 {GST_VIDEO_TEST_SRC_GRADIENT, "Gradient", "gradient"},
169 {GST_VIDEO_TEST_SRC_COLORS, "Colors", "colors"},
173 if (!video_test_src_pattern_type) {
174 video_test_src_pattern_type =
175 g_enum_register_static ("GstVideoTestSrcPattern", pattern_types);
177 return video_test_src_pattern_type;
181 /*"animation-mode", which can
182 * take the following values: frames (current behaviour that should stay the
183 * default), running time, wall clock time.
186 #define GST_TYPE_VIDEO_TEST_SRC_ANIMATION_MODE (gst_video_test_src_animation_mode_get_type ())
188 gst_video_test_src_animation_mode_get_type (void)
190 static GType video_test_src_animation_mode = 0;
191 static const GEnumValue animation_modes[] = {
193 {GST_VIDEO_TEST_SRC_FRAMES, "frame count", "frames"},
194 {GST_VIDEO_TEST_SRC_WALL_TIME, "wall clock time", "wall-time"},
195 {GST_VIDEO_TEST_SRC_RUNNING_TIME, "running time", "running-time"},
199 if (!video_test_src_animation_mode) {
200 video_test_src_animation_mode =
201 g_enum_register_static ("GstVideoTestSrcAnimationMode",
204 return video_test_src_animation_mode;
208 #define GST_TYPE_VIDEO_TEST_SRC_MOTION_TYPE (gst_video_test_src_motion_type_get_type ())
210 gst_video_test_src_motion_type_get_type (void)
212 static GType video_test_src_motion_type = 0;
213 static const GEnumValue motion_types[] = {
214 {GST_VIDEO_TEST_SRC_WAVY, "Ball waves back and forth, up and down",
216 {GST_VIDEO_TEST_SRC_SWEEP, "1 revolution per second", "sweep"},
217 {GST_VIDEO_TEST_SRC_HSWEEP, "1/2 revolution per second, then reset to top",
222 if (!video_test_src_motion_type) {
223 video_test_src_motion_type =
224 g_enum_register_static ("GstVideoTestSrcMotionType", motion_types);
226 return video_test_src_motion_type;
231 gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
233 GObjectClass *gobject_class;
234 GstElementClass *gstelement_class;
235 GstBaseSrcClass *gstbasesrc_class;
236 GstPushSrcClass *gstpushsrc_class;
238 gobject_class = (GObjectClass *) klass;
239 gstelement_class = (GstElementClass *) klass;
240 gstbasesrc_class = (GstBaseSrcClass *) klass;
241 gstpushsrc_class = (GstPushSrcClass *) klass;
243 gobject_class->set_property = gst_video_test_src_set_property;
244 gobject_class->get_property = gst_video_test_src_get_property;
246 g_object_class_install_property (gobject_class, PROP_PATTERN,
247 g_param_spec_enum ("pattern", "Pattern",
248 "Type of test pattern to generate", GST_TYPE_VIDEO_TEST_SRC_PATTERN,
249 DEFAULT_PATTERN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
251 g_object_class_install_property (gobject_class, PROP_ANIMATION_MODE,
252 g_param_spec_enum ("animation-mode", "Animation mode",
253 "For pattern=ball, which counter defines the position of the ball.",
254 GST_TYPE_VIDEO_TEST_SRC_ANIMATION_MODE, DEFAULT_ANIMATION_MODE,
255 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
257 g_object_class_install_property (gobject_class, PROP_MOTION_TYPE,
258 g_param_spec_enum ("motion", "Motion",
259 "For pattern=ball, what motion the ball does",
260 GST_TYPE_VIDEO_TEST_SRC_MOTION_TYPE, DEFAULT_MOTION_TYPE,
261 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
263 g_object_class_install_property (gobject_class, PROP_FLIP,
264 g_param_spec_boolean ("flip", "Flip",
265 "For pattern=ball, invert colors every second.",
266 DEFAULT_FLIP, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
268 g_object_class_install_property (gobject_class, PROP_TIMESTAMP_OFFSET,
269 g_param_spec_int64 ("timestamp-offset", "Timestamp offset",
270 "An offset added to timestamps set on buffers (in ns)", 0,
271 (G_MAXLONG == G_MAXINT64) ? G_MAXINT64 : (G_MAXLONG * GST_SECOND - 1),
272 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
273 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
274 g_param_spec_boolean ("is-live", "Is Live",
275 "Whether to act as a live source", DEFAULT_IS_LIVE,
276 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
277 g_object_class_install_property (gobject_class, PROP_K0,
278 g_param_spec_int ("k0", "Zoneplate zero order phase",
279 "Zoneplate zero order phase, for generating plain fields or phase offsets",
280 G_MININT32, G_MAXINT32, 0,
281 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
282 g_object_class_install_property (gobject_class, PROP_KX,
283 g_param_spec_int ("kx", "Zoneplate 1st order x phase",
284 "Zoneplate 1st order x phase, for generating constant horizontal frequencies",
285 G_MININT32, G_MAXINT32, 0,
286 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
287 g_object_class_install_property (gobject_class, PROP_KY,
288 g_param_spec_int ("ky", "Zoneplate 1st order y phase",
289 "Zoneplate 1st order y phase, for generating content vertical frequencies",
290 G_MININT32, G_MAXINT32, 0,
291 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
292 g_object_class_install_property (gobject_class, PROP_KT,
293 g_param_spec_int ("kt", "Zoneplate 1st order t phase",
294 "Zoneplate 1st order t phase, for generating phase rotation as a function of time",
295 G_MININT32, G_MAXINT32, 0,
296 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
297 g_object_class_install_property (gobject_class, PROP_KXT,
298 g_param_spec_int ("kxt", "Zoneplate x*t product phase",
299 "Zoneplate x*t product phase, normalised to kxy/256 cycles per vertical pixel at width/2 from origin",
300 G_MININT32, G_MAXINT32, 0,
301 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
302 g_object_class_install_property (gobject_class, PROP_KYT,
303 g_param_spec_int ("kyt", "Zoneplate y*t product phase",
304 "Zoneplate y*t product phase", G_MININT32, G_MAXINT32, 0,
305 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
306 g_object_class_install_property (gobject_class, PROP_KXY,
307 g_param_spec_int ("kxy", "Zoneplate x*y product phase",
308 "Zoneplate x*y product phase", G_MININT32, G_MAXINT32, 0,
309 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
310 g_object_class_install_property (gobject_class, PROP_KX2,
311 g_param_spec_int ("kx2", "Zoneplate 2nd order x phase",
312 "Zoneplate 2nd order x phase, normalised to kx2/256 cycles per horizontal pixel at width/2 from origin",
313 G_MININT32, G_MAXINT32, 0,
314 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
315 g_object_class_install_property (gobject_class, PROP_KY2,
316 g_param_spec_int ("ky2", "Zoneplate 2nd order y phase",
317 "Zoneplate 2nd order y phase, normailsed to ky2/256 cycles per vertical pixel at height/2 from origin",
318 G_MININT32, G_MAXINT32, 0,
319 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
320 g_object_class_install_property (gobject_class, PROP_KT2,
321 g_param_spec_int ("kt2", "Zoneplate 2nd order t phase",
322 "Zoneplate 2nd order t phase, t*t/256 cycles per picture", G_MININT32,
323 G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
324 g_object_class_install_property (gobject_class, PROP_XOFFSET,
325 g_param_spec_int ("xoffset", "Zoneplate 2nd order products x offset",
326 "Zoneplate 2nd order products x offset", G_MININT32, G_MAXINT32, 0,
327 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
328 g_object_class_install_property (gobject_class, PROP_YOFFSET,
329 g_param_spec_int ("yoffset", "Zoneplate 2nd order products y offset",
330 "Zoneplate 2nd order products y offset", G_MININT32, G_MAXINT32, 0,
331 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
333 * GstVideoTestSrc:foreground-color
335 * Color to use for solid-color pattern and foreground color of other
336 * patterns. Default is white (0xffffffff).
338 g_object_class_install_property (gobject_class, PROP_FOREGROUND_COLOR,
339 g_param_spec_uint ("foreground-color", "Foreground Color",
340 "Foreground color to use (big-endian ARGB)", 0, G_MAXUINT32,
341 DEFAULT_FOREGROUND_COLOR,
342 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
344 * GstVideoTestSrc:background-color
346 * Color to use for background color of some patterns. Default is
347 * black (0xff000000).
349 g_object_class_install_property (gobject_class, PROP_BACKGROUND_COLOR,
350 g_param_spec_uint ("background-color", "Background Color",
351 "Background color to use (big-endian ARGB)", 0, G_MAXUINT32,
352 DEFAULT_BACKGROUND_COLOR,
353 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
355 g_object_class_install_property (gobject_class, PROP_HORIZONTAL_SPEED,
356 g_param_spec_int ("horizontal-speed", "Horizontal Speed",
357 "Scroll image number of pixels per frame (positive is scroll to the left)",
358 G_MININT32, G_MAXINT32, DEFAULT_HORIZONTAL_SPEED,
359 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
361 gst_element_class_set_static_metadata (gstelement_class,
362 "Video test source", "Source/Video",
363 "Creates a test video stream", "David A. Schleef <ds@schleef.org>");
365 gst_element_class_add_static_pad_template (gstelement_class,
366 &gst_video_test_src_template);
368 gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
369 gstbasesrc_class->fixate = gst_video_test_src_src_fixate;
370 gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
371 gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
372 gstbasesrc_class->query = gst_video_test_src_query;
373 gstbasesrc_class->get_times = gst_video_test_src_get_times;
374 gstbasesrc_class->start = gst_video_test_src_start;
375 gstbasesrc_class->stop = gst_video_test_src_stop;
376 gstbasesrc_class->decide_allocation = gst_video_test_src_decide_allocation;
378 gstpushsrc_class->fill = gst_video_test_src_fill;
380 gst_type_mark_as_plugin_api (GST_TYPE_VIDEO_TEST_SRC_ANIMATION_MODE, 0);
381 gst_type_mark_as_plugin_api (GST_TYPE_VIDEO_TEST_SRC_MOTION_TYPE, 0);
382 gst_type_mark_as_plugin_api (GST_TYPE_VIDEO_TEST_SRC_PATTERN, 0);
386 gst_video_test_src_init (GstVideoTestSrc * src)
388 gst_video_test_src_set_pattern (src, DEFAULT_PATTERN);
390 src->timestamp_offset = DEFAULT_TIMESTAMP_OFFSET;
391 src->foreground_color = DEFAULT_FOREGROUND_COLOR;
392 src->background_color = DEFAULT_BACKGROUND_COLOR;
393 src->horizontal_speed = DEFAULT_HORIZONTAL_SPEED;
394 src->random_state = 0;
396 /* we operate in time */
397 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
398 gst_base_src_set_live (GST_BASE_SRC (src), DEFAULT_IS_LIVE);
400 src->animation_mode = DEFAULT_ANIMATION_MODE;
401 src->motion_type = DEFAULT_MOTION_TYPE;
402 src->flip = DEFAULT_FLIP;
407 gst_video_test_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
409 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (bsrc);
410 GstStructure *structure;
412 /* Check if foreground color has alpha, if it is the case,
413 * force color format with an alpha channel downstream */
414 if (src->foreground_color >> 24 != 255) {
416 GstCaps *alpha_only_caps = gst_caps_new_empty ();
418 for (i = 0; i < gst_caps_get_size (caps); i++) {
419 const GstVideoFormatInfo *info;
420 const GValue *formats =
421 gst_structure_get_value (gst_caps_get_structure (caps, i),
424 if (GST_VALUE_HOLDS_LIST (formats)) {
425 GValue possible_formats = { 0, };
426 guint list_size = gst_value_list_get_size (formats);
429 g_value_init (&possible_formats, GST_TYPE_LIST);
430 for (index = 0; index < list_size; index++) {
431 const GValue *list_item = gst_value_list_get_value (formats, index);
433 gst_video_format_get_info (gst_video_format_from_string
434 (g_value_get_string (list_item)));
435 if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
438 gst_value_init_and_copy (&tmp, list_item);
439 gst_value_list_append_value (&possible_formats, &tmp);
443 if (gst_value_list_get_size (&possible_formats)) {
444 GstStructure *astruct =
445 gst_structure_copy (gst_caps_get_structure (caps, i));
447 gst_structure_set_value (astruct, "format", &possible_formats);
448 gst_caps_append_structure (alpha_only_caps, astruct);
451 } else if (G_VALUE_HOLDS_STRING (formats)) {
453 gst_video_format_get_info (gst_video_format_from_string
454 (g_value_get_string (formats)));
456 if (GST_VIDEO_FORMAT_INFO_HAS_ALPHA (info)) {
457 gst_caps_append_structure (alpha_only_caps,
458 gst_structure_copy (gst_caps_get_structure (caps, i)));
461 g_assert_not_reached ();
462 GST_WARNING ("Unexpected type for video 'format' field: %s",
463 G_VALUE_TYPE_NAME (formats));
467 if (gst_caps_is_empty (alpha_only_caps)) {
468 GST_WARNING_OBJECT (src,
469 "Foreground color contains alpha, but downstream can't support alpha.");
471 gst_caps_replace (&caps, alpha_only_caps);
475 caps = gst_caps_make_writable (caps);
476 structure = gst_caps_get_structure (caps, 0);
478 gst_structure_fixate_field_nearest_int (structure, "width", 320);
479 gst_structure_fixate_field_nearest_int (structure, "height", 240);
481 if (gst_structure_has_field (structure, "framerate"))
482 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
484 gst_structure_set (structure, "framerate", GST_TYPE_FRACTION, 30, 1, NULL);
486 if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
487 gst_structure_fixate_field_nearest_fraction (structure,
488 "pixel-aspect-ratio", 1, 1);
490 gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
493 if (gst_structure_has_field (structure, "colorimetry"))
494 gst_structure_fixate_field_string (structure, "colorimetry", "bt601");
495 if (gst_structure_has_field (structure, "chroma-site"))
496 gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
498 if (gst_structure_has_field (structure, "interlace-mode"))
499 gst_structure_fixate_field_string (structure, "interlace-mode",
502 gst_structure_set (structure, "interlace-mode", G_TYPE_STRING,
503 "progressive", NULL);
505 if (gst_structure_has_field (structure, "multiview-mode"))
506 gst_structure_fixate_field_string (structure, "multiview-mode",
507 gst_video_multiview_mode_to_caps_string
508 (GST_VIDEO_MULTIVIEW_MODE_MONO));
510 gst_structure_set (structure, "multiview-mode", G_TYPE_STRING,
511 gst_video_multiview_mode_to_caps_string (GST_VIDEO_MULTIVIEW_MODE_MONO),
514 caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
520 gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
523 videotestsrc->pattern_type = pattern_type;
525 GST_DEBUG_OBJECT (videotestsrc, "setting pattern to %d", pattern_type);
527 switch (pattern_type) {
528 case GST_VIDEO_TEST_SRC_SMPTE:
529 videotestsrc->make_image = gst_video_test_src_smpte;
531 case GST_VIDEO_TEST_SRC_SNOW:
532 videotestsrc->make_image = gst_video_test_src_snow;
534 case GST_VIDEO_TEST_SRC_BLACK:
535 videotestsrc->make_image = gst_video_test_src_black;
537 case GST_VIDEO_TEST_SRC_WHITE:
538 videotestsrc->make_image = gst_video_test_src_white;
540 case GST_VIDEO_TEST_SRC_RED:
541 videotestsrc->make_image = gst_video_test_src_red;
543 case GST_VIDEO_TEST_SRC_GREEN:
544 videotestsrc->make_image = gst_video_test_src_green;
546 case GST_VIDEO_TEST_SRC_BLUE:
547 videotestsrc->make_image = gst_video_test_src_blue;
549 case GST_VIDEO_TEST_SRC_CHECKERS1:
550 videotestsrc->make_image = gst_video_test_src_checkers1;
552 case GST_VIDEO_TEST_SRC_CHECKERS2:
553 videotestsrc->make_image = gst_video_test_src_checkers2;
555 case GST_VIDEO_TEST_SRC_CHECKERS4:
556 videotestsrc->make_image = gst_video_test_src_checkers4;
558 case GST_VIDEO_TEST_SRC_CHECKERS8:
559 videotestsrc->make_image = gst_video_test_src_checkers8;
561 case GST_VIDEO_TEST_SRC_CIRCULAR:
562 videotestsrc->make_image = gst_video_test_src_circular;
564 case GST_VIDEO_TEST_SRC_BLINK:
565 videotestsrc->make_image = gst_video_test_src_blink;
567 case GST_VIDEO_TEST_SRC_SMPTE75:
568 videotestsrc->make_image = gst_video_test_src_smpte75;
570 case GST_VIDEO_TEST_SRC_ZONE_PLATE:
571 videotestsrc->make_image = gst_video_test_src_zoneplate;
573 case GST_VIDEO_TEST_SRC_GAMUT:
574 videotestsrc->make_image = gst_video_test_src_gamut;
576 case GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE:
577 videotestsrc->make_image = gst_video_test_src_chromazoneplate;
579 case GST_VIDEO_TEST_SRC_SOLID:
580 videotestsrc->make_image = gst_video_test_src_solid;
582 case GST_VIDEO_TEST_SRC_BALL:
583 videotestsrc->make_image = gst_video_test_src_ball;
585 case GST_VIDEO_TEST_SRC_SMPTE100:
586 videotestsrc->make_image = gst_video_test_src_smpte100;
588 case GST_VIDEO_TEST_SRC_BAR:
589 videotestsrc->make_image = gst_video_test_src_bar;
591 case GST_VIDEO_TEST_SRC_PINWHEEL:
592 videotestsrc->make_image = gst_video_test_src_pinwheel;
594 case GST_VIDEO_TEST_SRC_SPOKES:
595 videotestsrc->make_image = gst_video_test_src_spokes;
597 case GST_VIDEO_TEST_SRC_GRADIENT:
598 videotestsrc->make_image = gst_video_test_src_gradient;
600 case GST_VIDEO_TEST_SRC_COLORS:
601 videotestsrc->make_image = gst_video_test_src_colors;
604 g_assert_not_reached ();
609 gst_video_test_src_set_property (GObject * object, guint prop_id,
610 const GValue * value, GParamSpec * pspec)
612 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
616 gst_video_test_src_set_pattern (src, g_value_get_enum (value));
618 case PROP_TIMESTAMP_OFFSET:
619 src->timestamp_offset = g_value_get_int64 (value);
622 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
625 src->k0 = g_value_get_int (value);
628 src->kx = g_value_get_int (value);
631 src->ky = g_value_get_int (value);
634 src->kt = g_value_get_int (value);
637 src->kxt = g_value_get_int (value);
640 src->kyt = g_value_get_int (value);
643 src->kxy = g_value_get_int (value);
646 src->kx2 = g_value_get_int (value);
649 src->ky2 = g_value_get_int (value);
652 src->kt2 = g_value_get_int (value);
655 src->xoffset = g_value_get_int (value);
658 src->yoffset = g_value_get_int (value);
660 case PROP_FOREGROUND_COLOR:
661 src->foreground_color = g_value_get_uint (value);
663 case PROP_BACKGROUND_COLOR:
664 src->background_color = g_value_get_uint (value);
666 case PROP_HORIZONTAL_SPEED:
667 src->horizontal_speed = g_value_get_int (value);
669 case PROP_ANIMATION_MODE:
670 src->animation_mode = g_value_get_enum (value);
672 case PROP_MOTION_TYPE:
673 src->motion_type = g_value_get_enum (value);
676 src->flip = g_value_get_boolean (value);
684 gst_video_test_src_get_property (GObject * object, guint prop_id,
685 GValue * value, GParamSpec * pspec)
687 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
691 g_value_set_enum (value, src->pattern_type);
693 case PROP_TIMESTAMP_OFFSET:
694 g_value_set_int64 (value, src->timestamp_offset);
697 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
700 g_value_set_int (value, src->k0);
703 g_value_set_int (value, src->kx);
706 g_value_set_int (value, src->ky);
709 g_value_set_int (value, src->kt);
712 g_value_set_int (value, src->kxt);
715 g_value_set_int (value, src->kyt);
718 g_value_set_int (value, src->kxy);
721 g_value_set_int (value, src->kx2);
724 g_value_set_int (value, src->ky2);
727 g_value_set_int (value, src->kt2);
730 g_value_set_int (value, src->xoffset);
733 g_value_set_int (value, src->yoffset);
735 case PROP_FOREGROUND_COLOR:
736 g_value_set_uint (value, src->foreground_color);
738 case PROP_BACKGROUND_COLOR:
739 g_value_set_uint (value, src->background_color);
741 case PROP_HORIZONTAL_SPEED:
742 g_value_set_int (value, src->horizontal_speed);
744 case PROP_ANIMATION_MODE:
745 g_value_set_enum (value, src->animation_mode);
747 case PROP_MOTION_TYPE:
748 g_value_set_enum (value, src->motion_type);
751 g_value_set_boolean (value, src->flip);
754 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
760 gst_video_test_src_parse_caps (const GstCaps * caps,
761 gint * width, gint * height, gint * fps_n, gint * fps_d,
762 GstVideoColorimetry * colorimetry, gint * x_inv, gint * y_inv)
764 const GstStructure *structure;
765 GstPadLinkReturn ret;
766 const GValue *framerate;
769 GST_DEBUG ("parsing caps");
771 structure = gst_caps_get_structure (caps, 0);
773 ret = gst_structure_get_int (structure, "width", width);
774 ret &= gst_structure_get_int (structure, "height", height);
775 framerate = gst_structure_get_value (structure, "framerate");
778 *fps_n = gst_value_get_fraction_numerator (framerate);
779 *fps_d = gst_value_get_fraction_denominator (framerate);
783 if ((str = gst_structure_get_string (structure, "colorimetry")))
784 gst_video_colorimetry_from_string (colorimetry, str);
786 if ((str = gst_structure_get_string (structure, "format"))) {
787 if (g_str_equal (str, "bggr")) {
789 } else if (g_str_equal (str, "rggb")) {
791 } else if (g_str_equal (str, "grbg")) {
794 } else if (g_str_equal (str, "gbrg")) {
805 GST_DEBUG ("videotestsrc no framerate given");
810 GST_DEBUG ("videotestsrc invalid bayer format given");
816 gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
818 GstVideoTestSrc *videotestsrc;
821 guint size, min, max;
822 GstStructure *config;
823 GstCaps *caps = NULL;
825 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
827 if (gst_query_get_n_allocation_pools (query) > 0) {
828 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
831 size = MAX (size, videotestsrc->info.size);
835 size = videotestsrc->info.size;
840 /* no downstream pool, make our own */
842 if (videotestsrc->bayer)
843 pool = gst_buffer_pool_new ();
845 pool = gst_video_buffer_pool_new ();
848 config = gst_buffer_pool_get_config (pool);
850 gst_query_parse_allocation (query, &caps, NULL);
852 gst_buffer_pool_config_set_params (config, caps, size, min, max);
854 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
855 gst_buffer_pool_config_add_option (config,
856 GST_BUFFER_POOL_OPTION_VIDEO_META);
858 gst_buffer_pool_set_config (pool, config);
861 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
863 gst_query_add_allocation_pool (query, pool, size, min, max);
866 gst_object_unref (pool);
868 return GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query);
872 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
874 const GstStructure *structure;
875 GstVideoTestSrc *videotestsrc;
881 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
883 structure = gst_caps_get_structure (caps, 0);
885 GST_OBJECT_LOCK (videotestsrc);
887 if (gst_structure_has_name (structure, "video/x-raw")) {
888 /* we can use the parsing code */
889 if (!gst_video_info_from_caps (&info, caps))
892 } else if (gst_structure_has_name (structure, "video/x-bayer")) {
893 gint x_inv = 0, y_inv = 0;
895 gst_video_info_init (&info);
897 info.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8);
899 if (!gst_video_test_src_parse_caps (caps, &info.width, &info.height,
900 &info.fps_n, &info.fps_d, &info.colorimetry, &x_inv, &y_inv))
903 info.size = GST_ROUND_UP_4 (info.width) * info.height;
904 info.stride[0] = GST_ROUND_UP_4 (info.width);
906 videotestsrc->bayer = TRUE;
907 videotestsrc->x_invert = x_inv;
908 videotestsrc->y_invert = y_inv;
910 goto unsupported_caps;
913 /* create chroma subsampler */
914 if (videotestsrc->subsample)
915 gst_video_chroma_resample_free (videotestsrc->subsample);
916 videotestsrc->subsample = gst_video_chroma_resample_new (0,
917 info.chroma_site, 0, info.finfo->unpack_format, -info.finfo->w_sub[2],
918 -info.finfo->h_sub[2]);
920 for (i = 0; i < videotestsrc->n_lines; i++)
921 g_free (videotestsrc->lines[i]);
922 g_free (videotestsrc->lines);
924 if (videotestsrc->subsample != NULL) {
925 gst_video_chroma_resample_get_info (videotestsrc->subsample,
932 videotestsrc->lines = g_malloc (sizeof (gpointer) * n_lines);
933 for (i = 0; i < n_lines; i++)
934 videotestsrc->lines[i] = g_malloc ((info.width + 16) * 8);
935 videotestsrc->n_lines = n_lines;
936 videotestsrc->offset = offset;
939 videotestsrc->info = info;
941 GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
942 info.width, info.height, info.fps_n, info.fps_d);
944 g_free (videotestsrc->tmpline);
945 g_free (videotestsrc->tmpline2);
946 g_free (videotestsrc->tmpline_u8);
947 g_free (videotestsrc->tmpline_u16);
948 videotestsrc->tmpline_u8 = g_malloc (info.width + 8);
949 videotestsrc->tmpline = g_malloc ((info.width + 8) * 4);
950 videotestsrc->tmpline2 = g_malloc ((info.width + 8) * 4);
951 videotestsrc->tmpline_u16 = g_malloc ((info.width + 16) * 8);
953 videotestsrc->accum_rtime += videotestsrc->running_time;
954 videotestsrc->accum_frames += videotestsrc->n_frames;
956 videotestsrc->running_time = 0;
957 videotestsrc->n_frames = 0;
959 GST_OBJECT_UNLOCK (videotestsrc);
966 GST_OBJECT_UNLOCK (videotestsrc);
967 GST_DEBUG_OBJECT (bsrc, "failed to parse caps");
972 GST_OBJECT_UNLOCK (videotestsrc);
973 GST_DEBUG_OBJECT (bsrc, "unsupported caps: %" GST_PTR_FORMAT, caps);
979 gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
981 gboolean res = FALSE;
982 GstVideoTestSrc *src;
984 src = GST_VIDEO_TEST_SRC (bsrc);
986 switch (GST_QUERY_TYPE (query)) {
987 case GST_QUERY_CONVERT:
989 GstFormat src_fmt, dest_fmt;
990 gint64 src_val, dest_val;
992 GST_OBJECT_LOCK (src);
993 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
995 gst_video_info_convert (&src->info, src_fmt, src_val, dest_fmt,
997 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
998 GST_OBJECT_UNLOCK (src);
1001 case GST_QUERY_LATENCY:
1003 GST_OBJECT_LOCK (src);
1004 if (src->info.fps_n > 0) {
1005 GstClockTime latency;
1008 gst_util_uint64_scale (GST_SECOND, src->info.fps_d,
1010 GST_OBJECT_UNLOCK (src);
1011 gst_query_set_latency (query,
1012 gst_base_src_is_live (GST_BASE_SRC_CAST (src)), latency,
1013 GST_CLOCK_TIME_NONE);
1014 GST_DEBUG_OBJECT (src, "Reporting latency of %" GST_TIME_FORMAT,
1015 GST_TIME_ARGS (latency));
1018 GST_OBJECT_UNLOCK (src);
1022 case GST_QUERY_DURATION:{
1023 if (bsrc->num_buffers != -1) {
1026 gst_query_parse_duration (query, &format, NULL);
1028 case GST_FORMAT_TIME:{
1031 GST_OBJECT_LOCK (src);
1032 dur = gst_util_uint64_scale_int_round (bsrc->num_buffers
1033 * GST_SECOND, src->info.fps_d, src->info.fps_n);
1035 gst_query_set_duration (query, GST_FORMAT_TIME, dur);
1036 GST_OBJECT_UNLOCK (src);
1039 case GST_FORMAT_BYTES:
1040 GST_OBJECT_LOCK (src);
1042 gst_query_set_duration (query, GST_FORMAT_BYTES,
1043 bsrc->num_buffers * src->info.size);
1044 GST_OBJECT_UNLOCK (src);
1053 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
1061 gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
1062 GstClockTime * start, GstClockTime * end)
1064 /* for live sources, sync on the timestamp of the buffer */
1065 if (gst_base_src_is_live (basesrc)) {
1066 GstClockTime timestamp = GST_BUFFER_PTS (buffer);
1068 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
1069 /* get duration to calculate end time */
1070 GstClockTime duration = GST_BUFFER_DURATION (buffer);
1072 if (GST_CLOCK_TIME_IS_VALID (duration)) {
1073 *end = timestamp + duration;
1084 gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
1086 GstClockTime position;
1087 GstVideoTestSrc *src;
1089 src = GST_VIDEO_TEST_SRC (bsrc);
1091 segment->time = segment->start;
1092 position = segment->position;
1093 src->reverse = segment->rate < 0;
1095 /* now move to the position indicated */
1096 if (src->info.fps_n) {
1097 src->n_frames = gst_util_uint64_scale (position,
1098 src->info.fps_n, src->info.fps_d * GST_SECOND);
1102 src->accum_frames = 0;
1103 src->accum_rtime = 0;
1104 if (src->info.fps_n) {
1105 src->running_time = gst_util_uint64_scale (src->n_frames,
1106 src->info.fps_d * GST_SECOND, src->info.fps_n);
1108 /* FIXME : Not sure what to set here */
1109 src->running_time = 0;
1112 g_assert (src->running_time <= position);
1118 gst_video_test_src_is_seekable (GstBaseSrc * psrc)
1120 /* we're seekable... */
1124 static GstFlowReturn
1125 gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
1127 GstVideoTestSrc *src;
1128 GstClockTime next_time;
1129 GstVideoFrame frame;
1133 src = GST_VIDEO_TEST_SRC (psrc);
1135 if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&src->info) ==
1136 GST_VIDEO_FORMAT_UNKNOWN))
1137 goto not_negotiated;
1139 /* 0 framerate and we are at the second frame, eos */
1140 if (G_UNLIKELY (src->info.fps_n == 0 && src->n_frames == 1))
1143 if (G_UNLIKELY (src->n_frames == -1)) {
1144 /* EOS for reverse playback */
1148 GST_LOG_OBJECT (src,
1149 "creating buffer from pool for frame %" G_GINT64_FORMAT, src->n_frames);
1151 if (!gst_video_frame_map (&frame, &src->info, buffer, GST_MAP_WRITE))
1154 GST_BUFFER_PTS (buffer) =
1155 src->accum_rtime + src->timestamp_offset + src->running_time;
1156 GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE;
1158 gst_object_sync_values (GST_OBJECT (psrc), GST_BUFFER_PTS (buffer));
1160 src->make_image (src, GST_BUFFER_PTS (buffer), &frame);
1162 if ((pal = gst_video_format_get_palette (GST_VIDEO_FRAME_FORMAT (&frame),
1164 memcpy (GST_VIDEO_FRAME_PLANE_DATA (&frame, 1), pal, palsize);
1167 gst_video_frame_unmap (&frame);
1169 GST_DEBUG_OBJECT (src, "Timestamp: %" GST_TIME_FORMAT " = accumulated %"
1170 GST_TIME_FORMAT " + offset: %"
1171 GST_TIME_FORMAT " + running time: %" GST_TIME_FORMAT,
1172 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)), GST_TIME_ARGS (src->accum_rtime),
1173 GST_TIME_ARGS (src->timestamp_offset), GST_TIME_ARGS (src->running_time));
1175 GST_BUFFER_OFFSET (buffer) = src->accum_frames + src->n_frames;
1181 GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET (buffer) + 1;
1182 if (src->info.fps_n) {
1183 next_time = gst_util_uint64_scale (src->n_frames,
1184 src->info.fps_d * GST_SECOND, src->info.fps_n);
1186 /* We already decremented to next frame */
1187 GstClockTime prev_pts = gst_util_uint64_scale (src->n_frames + 2,
1188 src->info.fps_d * GST_SECOND, src->info.fps_n);
1190 GST_BUFFER_DURATION (buffer) = prev_pts - GST_BUFFER_PTS (buffer);
1192 GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
1195 next_time = src->timestamp_offset;
1196 /* NONE means forever */
1197 GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
1200 src->running_time = next_time;
1206 return GST_FLOW_NOT_NEGOTIATED;
1210 GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
1211 return GST_FLOW_EOS;
1215 GST_DEBUG_OBJECT (src, "invalid frame");
1221 gst_video_test_src_start (GstBaseSrc * basesrc)
1223 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
1225 GST_OBJECT_LOCK (src);
1226 src->running_time = 0;
1228 src->accum_frames = 0;
1229 src->accum_rtime = 0;
1231 gst_video_info_init (&src->info);
1232 GST_OBJECT_UNLOCK (src);
1238 gst_video_test_src_stop (GstBaseSrc * basesrc)
1240 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
1243 g_free (src->tmpline);
1244 src->tmpline = NULL;
1245 g_free (src->tmpline2);
1246 src->tmpline2 = NULL;
1247 g_free (src->tmpline_u8);
1248 src->tmpline_u8 = NULL;
1249 g_free (src->tmpline_u16);
1250 src->tmpline_u16 = NULL;
1252 gst_video_chroma_resample_free (src->subsample);
1253 src->subsample = NULL;
1255 for (i = 0; i < src->n_lines; i++)
1256 g_free (src->lines[i]);
1257 g_free (src->lines);
1265 plugin_init (GstPlugin * plugin)
1267 GST_DEBUG_CATEGORY_INIT (video_test_src_debug, "videotestsrc", 0,
1268 "Video Test Source");
1270 return gst_element_register (plugin, "videotestsrc", GST_RANK_NONE,
1271 GST_TYPE_VIDEO_TEST_SRC);
1274 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1277 "Creates a test video stream",
1278 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)