2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2002> David A. Schleef <ds@schleef.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * SECTION:element-videotestsrc
24 * The videotestsrc element is used to produce test video data in a wide variety
25 * of formats. The video test data produced can be controlled with the "pattern"
29 * <title>Example launch line</title>
31 * gst-launch -v videotestsrc pattern=snow ! ximagesink
32 * ]| Shows random noise in an X window.
39 #include "gstvideotestsrc.h"
40 #include "gstvideotestsrcorc.h"
41 #include "videotestsrc.h"
46 GST_DEBUG_CATEGORY_STATIC (video_test_src_debug);
47 #define GST_CAT_DEFAULT video_test_src_debug
49 #define DEFAULT_PATTERN GST_VIDEO_TEST_SRC_SMPTE
50 #define DEFAULT_TIMESTAMP_OFFSET 0
51 #define DEFAULT_IS_LIVE FALSE
52 #define DEFAULT_COLOR_SPEC GST_VIDEO_TEST_SRC_BT601
53 #define DEFAULT_FOREGROUND_COLOR 0xffffffff
54 #define DEFAULT_BACKGROUND_COLOR 0xff000000
55 #define DEFAULT_HORIZONTAL_SPEED 0
61 PROP_TIMESTAMP_OFFSET,
75 PROP_FOREGROUND_COLOR,
76 PROP_BACKGROUND_COLOR,
77 PROP_HORIZONTAL_SPEED,
82 #define VTS_VIDEO_CAPS GST_VIDEO_CAPS_MAKE (GST_VIDEO_FORMATS_ALL) ";" \
83 "video/x-bayer, format=(string) { bggr, rggb, grbg, gbrg }, " \
84 "width = " GST_VIDEO_SIZE_RANGE ", " \
85 "height = " GST_VIDEO_SIZE_RANGE ", " \
86 "framerate = " GST_VIDEO_FPS_RANGE
89 static GstStaticPadTemplate gst_video_test_src_template =
90 GST_STATIC_PAD_TEMPLATE ("src",
93 GST_STATIC_CAPS (VTS_VIDEO_CAPS)
96 #define gst_video_test_src_parent_class parent_class
97 G_DEFINE_TYPE (GstVideoTestSrc, gst_video_test_src, GST_TYPE_PUSH_SRC);
99 static void gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
101 static void gst_video_test_src_set_property (GObject * object, guint prop_id,
102 const GValue * value, GParamSpec * pspec);
103 static void gst_video_test_src_get_property (GObject * object, guint prop_id,
104 GValue * value, GParamSpec * pspec);
106 static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
107 static GstCaps *gst_video_test_src_src_fixate (GstBaseSrc * bsrc,
110 static gboolean gst_video_test_src_is_seekable (GstBaseSrc * psrc);
111 static gboolean gst_video_test_src_do_seek (GstBaseSrc * bsrc,
112 GstSegment * segment);
113 static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
115 static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
116 GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
117 static gboolean gst_video_test_src_decide_allocation (GstBaseSrc * bsrc,
119 static GstFlowReturn gst_video_test_src_fill (GstPushSrc * psrc,
121 static gboolean gst_video_test_src_start (GstBaseSrc * basesrc);
122 static gboolean gst_video_test_src_stop (GstBaseSrc * basesrc);
124 #define GST_TYPE_VIDEO_TEST_SRC_PATTERN (gst_video_test_src_pattern_get_type ())
126 gst_video_test_src_pattern_get_type (void)
128 static GType video_test_src_pattern_type = 0;
129 static const GEnumValue pattern_types[] = {
130 {GST_VIDEO_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
131 {GST_VIDEO_TEST_SRC_SNOW, "Random (television snow)", "snow"},
132 {GST_VIDEO_TEST_SRC_BLACK, "100% Black", "black"},
133 {GST_VIDEO_TEST_SRC_WHITE, "100% White", "white"},
134 {GST_VIDEO_TEST_SRC_RED, "Red", "red"},
135 {GST_VIDEO_TEST_SRC_GREEN, "Green", "green"},
136 {GST_VIDEO_TEST_SRC_BLUE, "Blue", "blue"},
137 {GST_VIDEO_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
138 {GST_VIDEO_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
139 {GST_VIDEO_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
140 {GST_VIDEO_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
141 {GST_VIDEO_TEST_SRC_CIRCULAR, "Circular", "circular"},
142 {GST_VIDEO_TEST_SRC_BLINK, "Blink", "blink"},
143 {GST_VIDEO_TEST_SRC_SMPTE75, "SMPTE 75% color bars", "smpte75"},
144 {GST_VIDEO_TEST_SRC_ZONE_PLATE, "Zone plate", "zone-plate"},
145 {GST_VIDEO_TEST_SRC_GAMUT, "Gamut checkers", "gamut"},
146 {GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE, "Chroma zone plate",
147 "chroma-zone-plate"},
148 {GST_VIDEO_TEST_SRC_SOLID, "Solid color", "solid-color"},
149 {GST_VIDEO_TEST_SRC_BALL, "Moving ball", "ball"},
150 {GST_VIDEO_TEST_SRC_SMPTE100, "SMPTE 100% color bars", "smpte100"},
151 {GST_VIDEO_TEST_SRC_BAR, "Bar", "bar"},
152 {GST_VIDEO_TEST_SRC_PINWHEEL, "Pinwheel", "pinwheel"},
153 {GST_VIDEO_TEST_SRC_SPOKES, "Spokes", "spokes"},
157 if (!video_test_src_pattern_type) {
158 video_test_src_pattern_type =
159 g_enum_register_static ("GstVideoTestSrcPattern", pattern_types);
161 return video_test_src_pattern_type;
165 gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
167 GObjectClass *gobject_class;
168 GstElementClass *gstelement_class;
169 GstBaseSrcClass *gstbasesrc_class;
170 GstPushSrcClass *gstpushsrc_class;
172 gobject_class = (GObjectClass *) klass;
173 gstelement_class = (GstElementClass *) klass;
174 gstbasesrc_class = (GstBaseSrcClass *) klass;
175 gstpushsrc_class = (GstPushSrcClass *) klass;
177 gobject_class->set_property = gst_video_test_src_set_property;
178 gobject_class->get_property = gst_video_test_src_get_property;
180 g_object_class_install_property (gobject_class, PROP_PATTERN,
181 g_param_spec_enum ("pattern", "Pattern",
182 "Type of test pattern to generate", GST_TYPE_VIDEO_TEST_SRC_PATTERN,
183 DEFAULT_PATTERN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
184 g_object_class_install_property (gobject_class, PROP_TIMESTAMP_OFFSET,
185 g_param_spec_int64 ("timestamp-offset", "Timestamp offset",
186 "An offset added to timestamps set on buffers (in ns)", G_MININT64,
187 G_MAXINT64, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
188 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
189 g_param_spec_boolean ("is-live", "Is Live",
190 "Whether to act as a live source", DEFAULT_IS_LIVE,
191 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
192 g_object_class_install_property (gobject_class, PROP_K0,
193 g_param_spec_int ("k0", "Zoneplate zero order phase",
194 "Zoneplate zero order phase, for generating plain fields or phase offsets",
195 G_MININT32, G_MAXINT32, 0,
196 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
197 g_object_class_install_property (gobject_class, PROP_KX,
198 g_param_spec_int ("kx", "Zoneplate 1st order x phase",
199 "Zoneplate 1st order x phase, for generating constant horizontal frequencies",
200 G_MININT32, G_MAXINT32, 0,
201 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
202 g_object_class_install_property (gobject_class, PROP_KY,
203 g_param_spec_int ("ky", "Zoneplate 1st order y phase",
204 "Zoneplate 1st order y phase, for generating contant vertical frequencies",
205 G_MININT32, G_MAXINT32, 0,
206 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
207 g_object_class_install_property (gobject_class, PROP_KT,
208 g_param_spec_int ("kt", "Zoneplate 1st order t phase",
209 "Zoneplate 1st order t phase, for generating phase rotation as a function of time",
210 G_MININT32, G_MAXINT32, 0,
211 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
212 g_object_class_install_property (gobject_class, PROP_KXT,
213 g_param_spec_int ("kxt", "Zoneplate x*t product phase",
214 "Zoneplate x*t product phase, normalised to kxy/256 cycles per vertical pixel at width/2 from origin",
215 G_MININT32, G_MAXINT32, 0,
216 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
217 g_object_class_install_property (gobject_class, PROP_KYT,
218 g_param_spec_int ("kyt", "Zoneplate y*t product phase",
219 "Zoneplate y*t product phase", G_MININT32, G_MAXINT32, 0,
220 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
221 g_object_class_install_property (gobject_class, PROP_KXY,
222 g_param_spec_int ("kxy", "Zoneplate x*y product phase",
223 "Zoneplate x*y product phase", G_MININT32, G_MAXINT32, 0,
224 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
225 g_object_class_install_property (gobject_class, PROP_KX2,
226 g_param_spec_int ("kx2", "Zoneplate 2nd order x phase",
227 "Zoneplate 2nd order x phase, normalised to kx2/256 cycles per horizontal pixel at width/2 from origin",
228 G_MININT32, G_MAXINT32, 0,
229 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
230 g_object_class_install_property (gobject_class, PROP_KY2,
231 g_param_spec_int ("ky2", "Zoneplate 2nd order y phase",
232 "Zoneplate 2nd order y phase, normailsed to ky2/256 cycles per vertical pixel at height/2 from origin",
233 G_MININT32, G_MAXINT32, 0,
234 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
235 g_object_class_install_property (gobject_class, PROP_KT2,
236 g_param_spec_int ("kt2", "Zoneplate 2nd order t phase",
237 "Zoneplate 2nd order t phase, t*t/256 cycles per picture", G_MININT32,
238 G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
239 g_object_class_install_property (gobject_class, PROP_XOFFSET,
240 g_param_spec_int ("xoffset", "Zoneplate 2nd order products x offset",
241 "Zoneplate 2nd order products x offset", G_MININT32, G_MAXINT32, 0,
242 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
243 g_object_class_install_property (gobject_class, PROP_YOFFSET,
244 g_param_spec_int ("yoffset", "Zoneplate 2nd order products y offset",
245 "Zoneplate 2nd order products y offset", G_MININT32, G_MAXINT32, 0,
246 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
248 * GstVideoTestSrc:foreground-color
250 * Color to use for solid-color pattern and foreground color of other
251 * patterns. Default is white (0xffffffff).
253 g_object_class_install_property (gobject_class, PROP_FOREGROUND_COLOR,
254 g_param_spec_uint ("foreground-color", "Foreground Color",
255 "Foreground color to use (big-endian ARGB)", 0, G_MAXUINT32,
256 DEFAULT_FOREGROUND_COLOR,
257 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
259 * GstVideoTestSrc:background-color
261 * Color to use for background color of some patterns. Default is
262 * black (0xff000000).
264 g_object_class_install_property (gobject_class, PROP_BACKGROUND_COLOR,
265 g_param_spec_uint ("background-color", "Background Color",
266 "Background color to use (big-endian ARGB)", 0, G_MAXUINT32,
267 DEFAULT_BACKGROUND_COLOR,
268 G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
270 g_object_class_install_property (gobject_class, PROP_HORIZONTAL_SPEED,
271 g_param_spec_int ("horizontal-speed", "Horizontal Speed",
272 "Scroll image number of pixels per frame (positive is scroll to the left)",
273 G_MININT32, G_MAXINT32, DEFAULT_HORIZONTAL_SPEED,
274 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
276 gst_element_class_set_static_metadata (gstelement_class,
277 "Video test source", "Source/Video",
278 "Creates a test video stream", "David A. Schleef <ds@schleef.org>");
280 gst_element_class_add_pad_template (gstelement_class,
281 gst_static_pad_template_get (&gst_video_test_src_template));
283 gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
284 gstbasesrc_class->fixate = gst_video_test_src_src_fixate;
285 gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
286 gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
287 gstbasesrc_class->query = gst_video_test_src_query;
288 gstbasesrc_class->get_times = gst_video_test_src_get_times;
289 gstbasesrc_class->start = gst_video_test_src_start;
290 gstbasesrc_class->stop = gst_video_test_src_stop;
291 gstbasesrc_class->decide_allocation = gst_video_test_src_decide_allocation;
293 gstpushsrc_class->fill = gst_video_test_src_fill;
297 gst_video_test_src_init (GstVideoTestSrc * src)
299 gst_video_test_src_set_pattern (src, DEFAULT_PATTERN);
301 src->timestamp_offset = DEFAULT_TIMESTAMP_OFFSET;
302 src->foreground_color = DEFAULT_FOREGROUND_COLOR;
303 src->background_color = DEFAULT_BACKGROUND_COLOR;
304 src->horizontal_speed = DEFAULT_HORIZONTAL_SPEED;
306 /* we operate in time */
307 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
308 gst_base_src_set_live (GST_BASE_SRC (src), DEFAULT_IS_LIVE);
312 gst_video_test_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
314 GstStructure *structure;
316 caps = gst_caps_make_writable (caps);
318 structure = gst_caps_get_structure (caps, 0);
320 gst_structure_fixate_field_nearest_int (structure, "width", 320);
321 gst_structure_fixate_field_nearest_int (structure, "height", 240);
322 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
324 if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
325 gst_structure_fixate_field_nearest_fraction (structure,
326 "pixel-aspect-ratio", 1, 1);
328 gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
331 if (gst_structure_has_field (structure, "colorimetry"))
332 gst_structure_fixate_field_string (structure, "colorimetry", "bt601");
333 if (gst_structure_has_field (structure, "chroma-site"))
334 gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
336 if (gst_structure_has_field (structure, "interlace-mode"))
337 gst_structure_fixate_field_string (structure, "interlace-mode",
340 gst_structure_set (structure, "interlace-mode", G_TYPE_STRING,
341 "progressive", NULL);
343 caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
349 gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
352 videotestsrc->pattern_type = pattern_type;
354 GST_DEBUG_OBJECT (videotestsrc, "setting pattern to %d", pattern_type);
356 switch (pattern_type) {
357 case GST_VIDEO_TEST_SRC_SMPTE:
358 videotestsrc->make_image = gst_video_test_src_smpte;
360 case GST_VIDEO_TEST_SRC_SNOW:
361 videotestsrc->make_image = gst_video_test_src_snow;
363 case GST_VIDEO_TEST_SRC_BLACK:
364 videotestsrc->make_image = gst_video_test_src_black;
366 case GST_VIDEO_TEST_SRC_WHITE:
367 videotestsrc->make_image = gst_video_test_src_white;
369 case GST_VIDEO_TEST_SRC_RED:
370 videotestsrc->make_image = gst_video_test_src_red;
372 case GST_VIDEO_TEST_SRC_GREEN:
373 videotestsrc->make_image = gst_video_test_src_green;
375 case GST_VIDEO_TEST_SRC_BLUE:
376 videotestsrc->make_image = gst_video_test_src_blue;
378 case GST_VIDEO_TEST_SRC_CHECKERS1:
379 videotestsrc->make_image = gst_video_test_src_checkers1;
381 case GST_VIDEO_TEST_SRC_CHECKERS2:
382 videotestsrc->make_image = gst_video_test_src_checkers2;
384 case GST_VIDEO_TEST_SRC_CHECKERS4:
385 videotestsrc->make_image = gst_video_test_src_checkers4;
387 case GST_VIDEO_TEST_SRC_CHECKERS8:
388 videotestsrc->make_image = gst_video_test_src_checkers8;
390 case GST_VIDEO_TEST_SRC_CIRCULAR:
391 videotestsrc->make_image = gst_video_test_src_circular;
393 case GST_VIDEO_TEST_SRC_BLINK:
394 videotestsrc->make_image = gst_video_test_src_blink;
396 case GST_VIDEO_TEST_SRC_SMPTE75:
397 videotestsrc->make_image = gst_video_test_src_smpte75;
399 case GST_VIDEO_TEST_SRC_ZONE_PLATE:
400 videotestsrc->make_image = gst_video_test_src_zoneplate;
402 case GST_VIDEO_TEST_SRC_GAMUT:
403 videotestsrc->make_image = gst_video_test_src_gamut;
405 case GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE:
406 videotestsrc->make_image = gst_video_test_src_chromazoneplate;
408 case GST_VIDEO_TEST_SRC_SOLID:
409 videotestsrc->make_image = gst_video_test_src_solid;
411 case GST_VIDEO_TEST_SRC_BALL:
412 videotestsrc->make_image = gst_video_test_src_ball;
414 case GST_VIDEO_TEST_SRC_SMPTE100:
415 videotestsrc->make_image = gst_video_test_src_smpte100;
417 case GST_VIDEO_TEST_SRC_BAR:
418 videotestsrc->make_image = gst_video_test_src_bar;
420 case GST_VIDEO_TEST_SRC_PINWHEEL:
421 videotestsrc->make_image = gst_video_test_src_pinwheel;
423 case GST_VIDEO_TEST_SRC_SPOKES:
424 videotestsrc->make_image = gst_video_test_src_spokes;
427 g_assert_not_reached ();
432 gst_video_test_src_set_property (GObject * object, guint prop_id,
433 const GValue * value, GParamSpec * pspec)
435 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
439 gst_video_test_src_set_pattern (src, g_value_get_enum (value));
441 case PROP_TIMESTAMP_OFFSET:
442 src->timestamp_offset = g_value_get_int64 (value);
445 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
448 src->k0 = g_value_get_int (value);
451 src->kx = g_value_get_int (value);
454 src->ky = g_value_get_int (value);
457 src->kt = g_value_get_int (value);
460 src->kxt = g_value_get_int (value);
463 src->kyt = g_value_get_int (value);
466 src->kxy = g_value_get_int (value);
469 src->kx2 = g_value_get_int (value);
472 src->ky2 = g_value_get_int (value);
475 src->kt2 = g_value_get_int (value);
478 src->xoffset = g_value_get_int (value);
481 src->yoffset = g_value_get_int (value);
483 case PROP_FOREGROUND_COLOR:
484 src->foreground_color = g_value_get_uint (value);
486 case PROP_BACKGROUND_COLOR:
487 src->background_color = g_value_get_uint (value);
489 case PROP_HORIZONTAL_SPEED:
490 src->horizontal_speed = g_value_get_int (value);
497 gst_video_test_src_get_property (GObject * object, guint prop_id,
498 GValue * value, GParamSpec * pspec)
500 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
504 g_value_set_enum (value, src->pattern_type);
506 case PROP_TIMESTAMP_OFFSET:
507 g_value_set_int64 (value, src->timestamp_offset);
510 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
513 g_value_set_int (value, src->k0);
516 g_value_set_int (value, src->kx);
519 g_value_set_int (value, src->ky);
522 g_value_set_int (value, src->kt);
525 g_value_set_int (value, src->kxt);
528 g_value_set_int (value, src->kyt);
531 g_value_set_int (value, src->kxy);
534 g_value_set_int (value, src->kx2);
537 g_value_set_int (value, src->ky2);
540 g_value_set_int (value, src->kt2);
543 g_value_set_int (value, src->xoffset);
546 g_value_set_int (value, src->yoffset);
548 case PROP_FOREGROUND_COLOR:
549 g_value_set_uint (value, src->foreground_color);
551 case PROP_BACKGROUND_COLOR:
552 g_value_set_uint (value, src->background_color);
554 case PROP_HORIZONTAL_SPEED:
555 g_value_set_int (value, src->horizontal_speed);
558 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
564 gst_video_test_src_parse_caps (const GstCaps * caps,
565 gint * width, gint * height, gint * fps_n, gint * fps_d,
566 GstVideoColorimetry * colorimetry, gint * x_inv, gint * y_inv)
568 const GstStructure *structure;
569 GstPadLinkReturn ret;
570 const GValue *framerate;
573 GST_DEBUG ("parsing caps");
575 structure = gst_caps_get_structure (caps, 0);
577 ret = gst_structure_get_int (structure, "width", width);
578 ret &= gst_structure_get_int (structure, "height", height);
579 framerate = gst_structure_get_value (structure, "framerate");
582 *fps_n = gst_value_get_fraction_numerator (framerate);
583 *fps_d = gst_value_get_fraction_denominator (framerate);
587 if ((str = gst_structure_get_string (structure, "colorimetry")))
588 gst_video_colorimetry_from_string (colorimetry, str);
590 if ((str = gst_structure_get_string (structure, "format"))) {
591 if (g_str_equal (str, "bggr")) {
593 } else if (g_str_equal (str, "rggb")) {
595 } else if (g_str_equal (str, "grbg")) {
598 } else if (g_str_equal (str, "grbg")) {
609 GST_DEBUG ("videotestsrc no framerate given");
614 GST_DEBUG ("videotestsrc invalid bayer format given");
620 gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
622 GstVideoTestSrc *videotestsrc;
625 guint size, min, max;
626 GstStructure *config;
628 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
630 if (gst_query_get_n_allocation_pools (query) > 0) {
631 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
634 size = MAX (size, videotestsrc->info.size);
638 size = videotestsrc->info.size;
643 /* no downstream pool, make our own */
645 if (videotestsrc->bayer)
646 pool = gst_buffer_pool_new ();
648 pool = gst_video_buffer_pool_new ();
651 config = gst_buffer_pool_get_config (pool);
652 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
653 gst_buffer_pool_config_add_option (config,
654 GST_BUFFER_POOL_OPTION_VIDEO_META);
656 gst_buffer_pool_set_config (pool, config);
659 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
661 gst_query_add_allocation_pool (query, pool, size, min, max);
664 gst_object_unref (pool);
666 return GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query);
670 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
672 const GstStructure *structure;
673 GstVideoTestSrc *videotestsrc;
679 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
681 structure = gst_caps_get_structure (caps, 0);
683 if (gst_structure_has_name (structure, "video/x-raw")) {
684 /* we can use the parsing code */
685 if (!gst_video_info_from_caps (&info, caps))
688 } else if (gst_structure_has_name (structure, "video/x-bayer")) {
689 gint x_inv = 0, y_inv = 0;
691 gst_video_info_init (&info);
693 info.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8);
695 if (!gst_video_test_src_parse_caps (caps, &info.width, &info.height,
696 &info.fps_n, &info.fps_d, &info.colorimetry, &x_inv, &y_inv))
699 info.size = GST_ROUND_UP_4 (info.width) * info.height;
700 info.stride[0] = GST_ROUND_UP_4 (info.width);
702 videotestsrc->bayer = TRUE;
703 videotestsrc->x_invert = x_inv;
704 videotestsrc->y_invert = y_inv;
707 /* create chroma subsampler */
708 if (videotestsrc->subsample)
709 gst_video_chroma_resample_free (videotestsrc->subsample);
710 videotestsrc->subsample = gst_video_chroma_resample_new (0,
711 info.chroma_site, 0, info.finfo->unpack_format, -info.finfo->w_sub[2],
712 -info.finfo->h_sub[2]);
714 for (i = 0; i < videotestsrc->n_lines; i++)
715 g_free (videotestsrc->lines[i]);
716 g_free (videotestsrc->lines);
718 if (videotestsrc->subsample != NULL) {
719 gst_video_chroma_resample_get_info (videotestsrc->subsample,
726 videotestsrc->lines = g_malloc (sizeof (gpointer) * n_lines);
727 for (i = 0; i < n_lines; i++)
728 videotestsrc->lines[i] = g_malloc ((info.width + 16) * 8);
729 videotestsrc->n_lines = n_lines;
730 videotestsrc->offset = offset;
733 videotestsrc->info = info;
735 GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
736 info.width, info.height, info.fps_n, info.fps_d);
738 g_free (videotestsrc->tmpline);
739 g_free (videotestsrc->tmpline2);
740 g_free (videotestsrc->tmpline_u8);
741 g_free (videotestsrc->tmpline_u16);
742 videotestsrc->tmpline_u8 = g_malloc (info.width + 8);
743 videotestsrc->tmpline = g_malloc ((info.width + 8) * 4);
744 videotestsrc->tmpline2 = g_malloc ((info.width + 8) * 4);
745 videotestsrc->tmpline_u16 = g_malloc ((info.width + 16) * 8);
747 videotestsrc->accum_rtime += videotestsrc->running_time;
748 videotestsrc->accum_frames += videotestsrc->n_frames;
750 videotestsrc->running_time = 0;
751 videotestsrc->n_frames = 0;
758 GST_DEBUG_OBJECT (bsrc, "failed to parse caps");
764 gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
767 GstVideoTestSrc *src;
769 src = GST_VIDEO_TEST_SRC (bsrc);
771 switch (GST_QUERY_TYPE (query)) {
772 case GST_QUERY_CONVERT:
774 GstFormat src_fmt, dest_fmt;
775 gint64 src_val, dest_val;
777 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
779 gst_video_info_convert (&src->info, src_fmt, src_val, dest_fmt,
781 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
784 case GST_QUERY_DURATION:{
785 if (bsrc->num_buffers != -1) {
788 gst_query_parse_duration (query, &format, NULL);
790 case GST_FORMAT_TIME:{
791 gint64 dur = gst_util_uint64_scale_int_round (bsrc->num_buffers
792 * GST_SECOND, src->info.fps_d, src->info.fps_n);
794 gst_query_set_duration (query, GST_FORMAT_TIME, dur);
797 case GST_FORMAT_BYTES:
798 gst_query_set_duration (query, GST_FORMAT_BYTES,
799 bsrc->num_buffers * src->info.size);
808 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
815 gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
816 GstClockTime * start, GstClockTime * end)
818 /* for live sources, sync on the timestamp of the buffer */
819 if (gst_base_src_is_live (basesrc)) {
820 GstClockTime timestamp = GST_BUFFER_DTS (buffer);
822 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
823 /* get duration to calculate end time */
824 GstClockTime duration = GST_BUFFER_DURATION (buffer);
826 if (GST_CLOCK_TIME_IS_VALID (duration)) {
827 *end = timestamp + duration;
838 gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
840 GstClockTime position;
841 GstVideoTestSrc *src;
843 src = GST_VIDEO_TEST_SRC (bsrc);
845 segment->time = segment->start;
846 position = segment->position;
847 src->reverse = segment->rate < 0;
849 /* now move to the position indicated */
850 if (src->info.fps_n) {
851 src->n_frames = gst_util_uint64_scale (position,
852 src->info.fps_n, src->info.fps_d * GST_SECOND);
856 src->accum_frames = 0;
857 src->accum_rtime = 0;
858 if (src->info.fps_n) {
859 src->running_time = gst_util_uint64_scale (src->n_frames,
860 src->info.fps_d * GST_SECOND, src->info.fps_n);
862 /* FIXME : Not sure what to set here */
863 src->running_time = 0;
866 g_assert (src->running_time <= position);
872 gst_video_test_src_is_seekable (GstBaseSrc * psrc)
874 /* we're seekable... */
879 gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
881 GstVideoTestSrc *src;
882 GstClockTime next_time;
887 src = GST_VIDEO_TEST_SRC (psrc);
889 if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&src->info) ==
890 GST_VIDEO_FORMAT_UNKNOWN))
893 /* 0 framerate and we are at the second frame, eos */
894 if (G_UNLIKELY (src->info.fps_n == 0 && src->n_frames == 1))
897 if (G_UNLIKELY (src->n_frames == -1)) {
898 /* EOS for reverse playback */
903 "creating buffer from pool for frame %d", (gint) src->n_frames);
905 if (!gst_video_frame_map (&frame, &src->info, buffer, GST_MAP_WRITE))
908 GST_BUFFER_DTS (buffer) =
909 src->accum_rtime + src->timestamp_offset + src->running_time;
910 GST_BUFFER_PTS (buffer) = GST_BUFFER_DTS (buffer);
912 gst_object_sync_values (GST_OBJECT (psrc), GST_BUFFER_DTS (buffer));
914 src->make_image (src, &frame);
916 if ((pal = gst_video_format_get_palette (GST_VIDEO_FRAME_FORMAT (&frame),
918 memcpy (GST_VIDEO_FRAME_PLANE_DATA (&frame, 1), pal, palsize);
921 gst_video_frame_unmap (&frame);
923 GST_DEBUG_OBJECT (src, "Timestamp: %" GST_TIME_FORMAT " = accumulated %"
924 GST_TIME_FORMAT " + offset: %"
925 GST_TIME_FORMAT " + running time: %" GST_TIME_FORMAT,
926 GST_TIME_ARGS (GST_BUFFER_PTS (buffer)), GST_TIME_ARGS (src->accum_rtime),
927 GST_TIME_ARGS (src->timestamp_offset), GST_TIME_ARGS (src->running_time));
929 GST_BUFFER_OFFSET (buffer) = src->accum_frames + src->n_frames;
935 GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET (buffer) + 1;
936 if (src->info.fps_n) {
937 next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
938 src->info.fps_d, src->info.fps_n);
940 GST_BUFFER_DURATION (buffer) = src->running_time - next_time;
942 GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
945 next_time = src->timestamp_offset;
946 /* NONE means forever */
947 GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
950 src->running_time = next_time;
956 return GST_FLOW_NOT_NEGOTIATED;
960 GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
965 GST_DEBUG_OBJECT (src, "invalid frame");
971 gst_video_test_src_start (GstBaseSrc * basesrc)
973 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
975 src->running_time = 0;
977 src->accum_frames = 0;
978 src->accum_rtime = 0;
980 gst_video_info_init (&src->info);
986 gst_video_test_src_stop (GstBaseSrc * basesrc)
988 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
991 g_free (src->tmpline);
993 g_free (src->tmpline2);
994 src->tmpline2 = NULL;
995 g_free (src->tmpline_u8);
996 src->tmpline_u8 = NULL;
997 g_free (src->tmpline_u16);
998 src->tmpline_u16 = NULL;
1000 gst_video_chroma_resample_free (src->subsample);
1001 src->subsample = NULL;
1003 for (i = 0; i < src->n_lines; i++)
1004 g_free (src->lines[i]);
1005 g_free (src->lines);
1013 plugin_init (GstPlugin * plugin)
1015 GST_DEBUG_CATEGORY_INIT (video_test_src_debug, "videotestsrc", 0,
1016 "Video Test Source");
1018 return gst_element_register (plugin, "videotestsrc", GST_RANK_NONE,
1019 GST_TYPE_VIDEO_TEST_SRC);
1022 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1025 "Creates a test video stream",
1026 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)