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., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:element-videotestsrc
24 * The videotestsrc element is used to produce test video data in a wide variaty
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_PEER_ALLOC TRUE
53 #define DEFAULT_COLOR_SPEC GST_VIDEO_TEST_SRC_BT601
54 #define DEFAULT_FOREGROUND_COLOR 0xffffffff
55 #define DEFAULT_BACKGROUND_COLOR 0xff000000
56 #define DEFAULT_HORIZONTAL_SPEED 0
62 PROP_TIMESTAMP_OFFSET,
78 PROP_FOREGROUND_COLOR,
79 PROP_BACKGROUND_COLOR,
80 PROP_HORIZONTAL_SPEED,
85 GST_BOILERPLATE (GstVideoTestSrc, gst_video_test_src, GstPushSrc,
89 static void gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
91 static void gst_video_test_src_set_property (GObject * object, guint prop_id,
92 const GValue * value, GParamSpec * pspec);
93 static void gst_video_test_src_get_property (GObject * object, guint prop_id,
94 GValue * value, GParamSpec * pspec);
96 static GstCaps *gst_video_test_src_getcaps (GstBaseSrc * bsrc);
97 static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
98 static void gst_video_test_src_src_fixate (GstPad * pad, GstCaps * caps);
100 static gboolean gst_video_test_src_is_seekable (GstBaseSrc * psrc);
101 static gboolean gst_video_test_src_do_seek (GstBaseSrc * bsrc,
102 GstSegment * segment);
103 static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
105 static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
106 GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
107 static GstFlowReturn gst_video_test_src_create (GstPushSrc * psrc,
108 GstBuffer ** buffer);
109 static gboolean gst_video_test_src_start (GstBaseSrc * basesrc);
111 #define GST_TYPE_VIDEO_TEST_SRC_PATTERN (gst_video_test_src_pattern_get_type ())
113 gst_video_test_src_pattern_get_type (void)
115 static GType video_test_src_pattern_type = 0;
116 static const GEnumValue pattern_types[] = {
117 {GST_VIDEO_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
118 {GST_VIDEO_TEST_SRC_SNOW, "Random (television snow)", "snow"},
119 {GST_VIDEO_TEST_SRC_BLACK, "100% Black", "black"},
120 {GST_VIDEO_TEST_SRC_WHITE, "100% White", "white"},
121 {GST_VIDEO_TEST_SRC_RED, "Red", "red"},
122 {GST_VIDEO_TEST_SRC_GREEN, "Green", "green"},
123 {GST_VIDEO_TEST_SRC_BLUE, "Blue", "blue"},
124 {GST_VIDEO_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
125 {GST_VIDEO_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
126 {GST_VIDEO_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
127 {GST_VIDEO_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
128 {GST_VIDEO_TEST_SRC_CIRCULAR, "Circular", "circular"},
129 {GST_VIDEO_TEST_SRC_BLINK, "Blink", "blink"},
130 {GST_VIDEO_TEST_SRC_SMPTE75, "SMPTE 75% color bars", "smpte75"},
131 {GST_VIDEO_TEST_SRC_ZONE_PLATE, "Zone plate", "zone-plate"},
132 {GST_VIDEO_TEST_SRC_GAMUT, "Gamut checkers", "gamut"},
133 {GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE, "Chroma zone plate",
134 "chroma-zone-plate"},
135 {GST_VIDEO_TEST_SRC_SOLID, "Solid color", "solid-color"},
136 {GST_VIDEO_TEST_SRC_BALL, "Moving ball", "ball"},
137 {GST_VIDEO_TEST_SRC_SMPTE100, "SMPTE 100% color bars", "smpte100"},
138 {GST_VIDEO_TEST_SRC_BAR, "Bar", "bar"},
142 if (!video_test_src_pattern_type) {
143 video_test_src_pattern_type =
144 g_enum_register_static ("GstVideoTestSrcPattern", pattern_types);
146 return video_test_src_pattern_type;
149 #define GST_TYPE_VIDEO_TEST_SRC_COLOR_SPEC (gst_video_test_src_color_spec_get_type ())
151 gst_video_test_src_color_spec_get_type (void)
153 static GType video_test_src_color_spec_type = 0;
154 static const GEnumValue color_spec_types[] = {
155 {GST_VIDEO_TEST_SRC_BT601, "ITU-R Rec. BT.601", "bt601"},
156 {GST_VIDEO_TEST_SRC_BT709, "ITU-R Rec. BT.709", "bt709"},
160 if (!video_test_src_color_spec_type) {
161 video_test_src_color_spec_type =
162 g_enum_register_static ("GstVideoTestSrcColorSpec", color_spec_types);
164 return video_test_src_color_spec_type;
168 gst_video_test_src_base_init (gpointer g_class)
170 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
172 gst_element_class_set_details_simple (element_class,
173 "Video test source", "Source/Video",
174 "Creates a test video stream", "David A. Schleef <ds@schleef.org>");
176 gst_element_class_add_pad_template (element_class,
177 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
178 gst_video_test_src_getcaps (NULL)));
182 gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
184 GObjectClass *gobject_class;
185 GstBaseSrcClass *gstbasesrc_class;
186 GstPushSrcClass *gstpushsrc_class;
188 gobject_class = (GObjectClass *) klass;
189 gstbasesrc_class = (GstBaseSrcClass *) klass;
190 gstpushsrc_class = (GstPushSrcClass *) klass;
192 gobject_class->set_property = gst_video_test_src_set_property;
193 gobject_class->get_property = gst_video_test_src_get_property;
195 g_object_class_install_property (gobject_class, PROP_PATTERN,
196 g_param_spec_enum ("pattern", "Pattern",
197 "Type of test pattern to generate", GST_TYPE_VIDEO_TEST_SRC_PATTERN,
198 DEFAULT_PATTERN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
199 g_object_class_install_property (gobject_class, PROP_TIMESTAMP_OFFSET,
200 g_param_spec_int64 ("timestamp-offset", "Timestamp offset",
201 "An offset added to timestamps set on buffers (in ns)", G_MININT64,
202 G_MAXINT64, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
203 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
204 g_param_spec_boolean ("is-live", "Is Live",
205 "Whether to act as a live source", DEFAULT_IS_LIVE,
206 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
207 g_object_class_install_property (gobject_class, PROP_PEER_ALLOC,
208 g_param_spec_boolean ("peer-alloc", "Peer Alloc",
209 "Ask the peer to allocate an output buffer", DEFAULT_PEER_ALLOC,
210 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
211 g_object_class_install_property (gobject_class, PROP_COLOR_SPEC,
212 g_param_spec_enum ("colorspec", "Color Specification",
213 "Generate video in the given color specification (Deprecated: "
214 "use a caps filter with video/x-raw-yuv,color-matrix=\"sdtv\" or "
216 GST_TYPE_VIDEO_TEST_SRC_COLOR_SPEC,
217 DEFAULT_COLOR_SPEC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
218 g_object_class_install_property (gobject_class, PROP_K0,
219 g_param_spec_int ("k0", "Zoneplate zero order phase",
220 "Zoneplate zero order phase, for generating plain fields or phase offsets",
221 G_MININT32, G_MAXINT32, 0,
222 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
223 g_object_class_install_property (gobject_class, PROP_KX,
224 g_param_spec_int ("kx", "Zoneplate 1st order x phase",
225 "Zoneplate 1st order x phase, for generating constant horizontal frequencies",
226 G_MININT32, G_MAXINT32, 0,
227 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
228 g_object_class_install_property (gobject_class, PROP_KY,
229 g_param_spec_int ("ky", "Zoneplate 1st order y phase",
230 "Zoneplate 1st order y phase, for generating contant vertical frequencies",
231 G_MININT32, G_MAXINT32, 0,
232 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
233 g_object_class_install_property (gobject_class, PROP_KT,
234 g_param_spec_int ("kt", "Zoneplate 1st order t phase",
235 "Zoneplate 1st order t phase, for generating phase rotation as a function of time",
236 G_MININT32, G_MAXINT32, 0,
237 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
238 g_object_class_install_property (gobject_class, PROP_KXT,
239 g_param_spec_int ("kxt", "Zoneplate x*t product phase",
240 "Zoneplate x*t product phase, normalised to kxy/256 cycles per vertical pixel at width/2 from origin",
241 G_MININT32, G_MAXINT32, 0,
242 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
243 g_object_class_install_property (gobject_class, PROP_KYT,
244 g_param_spec_int ("kyt", "Zoneplate y*t product phase",
245 "Zoneplate y*t product phase", G_MININT32, G_MAXINT32, 0,
246 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
247 g_object_class_install_property (gobject_class, PROP_KXY,
248 g_param_spec_int ("kxy", "Zoneplate x*y product phase",
249 "Zoneplate x*y product phase", G_MININT32, G_MAXINT32, 0,
250 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
251 g_object_class_install_property (gobject_class, PROP_KX2,
252 g_param_spec_int ("kx2", "Zoneplate 2nd order x phase",
253 "Zoneplate 2nd order x phase, normalised to kx2/256 cycles per horizontal pixel at width/2 from origin",
254 G_MININT32, G_MAXINT32, 0,
255 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
256 g_object_class_install_property (gobject_class, PROP_KY2,
257 g_param_spec_int ("ky2", "Zoneplate 2nd order y phase",
258 "Zoneplate 2nd order y phase, normailsed to ky2/256 cycles per vertical pixel at height/2 from origin",
259 G_MININT32, G_MAXINT32, 0,
260 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
261 g_object_class_install_property (gobject_class, PROP_KT2,
262 g_param_spec_int ("kt2", "Zoneplate 2nd order t phase",
263 "Zoneplate 2nd order t phase, t*t/256 cycles per picture", G_MININT32,
264 G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
265 g_object_class_install_property (gobject_class, PROP_XOFFSET,
266 g_param_spec_int ("xoffset", "Zoneplate 2nd order products x offset",
267 "Zoneplate 2nd order products x offset", G_MININT32, G_MAXINT32, 0,
268 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
269 g_object_class_install_property (gobject_class, PROP_YOFFSET,
270 g_param_spec_int ("yoffset", "Zoneplate 2nd order products y offset",
271 "Zoneplate 2nd order products y offset", G_MININT32, G_MAXINT32, 0,
272 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
274 * GstVideoTestSrc:foreground-color
276 * Color to use for solid-color pattern and foreground color of other
277 * patterns. Default is white (0xffffffff).
281 g_object_class_install_property (gobject_class, PROP_FOREGROUND_COLOR,
282 g_param_spec_uint ("foreground-color", "Foreground Color",
283 "Foreground color to use (big-endian ARGB)", 0, G_MAXUINT32,
284 DEFAULT_FOREGROUND_COLOR,
285 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
287 * GstVideoTestSrc:background-color
289 * Color to use for background color of some patterns. Default is
290 * black (0xff000000).
294 g_object_class_install_property (gobject_class, PROP_BACKGROUND_COLOR,
295 g_param_spec_uint ("background-color", "Background Color",
296 "Background color to use (big-endian ARGB)", 0, G_MAXUINT32,
297 DEFAULT_BACKGROUND_COLOR,
298 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
300 g_object_class_install_property (gobject_class, PROP_HORIZONTAL_SPEED,
301 g_param_spec_int ("horizontal-speed", "Horizontal Speed",
302 "Scroll image number of pixels per frame (positive is scroll to the left)",
303 G_MININT32, G_MAXINT32, DEFAULT_HORIZONTAL_SPEED,
304 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
306 gstbasesrc_class->get_caps = gst_video_test_src_getcaps;
307 gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
308 gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
309 gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
310 gstbasesrc_class->query = gst_video_test_src_query;
311 gstbasesrc_class->get_times = gst_video_test_src_get_times;
312 gstbasesrc_class->start = gst_video_test_src_start;
314 gstpushsrc_class->create = gst_video_test_src_create;
318 gst_video_test_src_init (GstVideoTestSrc * src, GstVideoTestSrcClass * g_class)
320 GstPad *pad = GST_BASE_SRC_PAD (src);
322 gst_pad_set_fixatecaps_function (pad, gst_video_test_src_src_fixate);
324 gst_video_test_src_set_pattern (src, DEFAULT_PATTERN);
326 src->timestamp_offset = DEFAULT_TIMESTAMP_OFFSET;
327 src->foreground_color = DEFAULT_FOREGROUND_COLOR;
328 src->background_color = DEFAULT_BACKGROUND_COLOR;
329 src->horizontal_speed = DEFAULT_HORIZONTAL_SPEED;
331 /* we operate in time */
332 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
333 gst_base_src_set_live (GST_BASE_SRC (src), DEFAULT_IS_LIVE);
334 src->peer_alloc = DEFAULT_PEER_ALLOC;
338 gst_video_test_src_src_fixate (GstPad * pad, GstCaps * caps)
340 GstStructure *structure;
342 structure = gst_caps_get_structure (caps, 0);
344 gst_structure_fixate_field_nearest_int (structure, "width", 320);
345 gst_structure_fixate_field_nearest_int (structure, "height", 240);
346 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
347 if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
348 gst_structure_fixate_field_nearest_fraction (structure,
349 "pixel-aspect-ratio", 1, 1);
350 if (gst_structure_has_field (structure, "color-matrix"))
351 gst_structure_fixate_field_string (structure, "color-matrix", "sdtv");
352 if (gst_structure_has_field (structure, "chroma-site"))
353 gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
355 if (gst_structure_has_field (structure, "interlaced"))
356 gst_structure_fixate_field_boolean (structure, "interlaced", FALSE);
360 gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
363 videotestsrc->pattern_type = pattern_type;
365 GST_DEBUG_OBJECT (videotestsrc, "setting pattern to %d", pattern_type);
367 switch (pattern_type) {
368 case GST_VIDEO_TEST_SRC_SMPTE:
369 videotestsrc->make_image = gst_video_test_src_smpte;
371 case GST_VIDEO_TEST_SRC_SNOW:
372 videotestsrc->make_image = gst_video_test_src_snow;
374 case GST_VIDEO_TEST_SRC_BLACK:
375 videotestsrc->make_image = gst_video_test_src_black;
377 case GST_VIDEO_TEST_SRC_WHITE:
378 videotestsrc->make_image = gst_video_test_src_white;
380 case GST_VIDEO_TEST_SRC_RED:
381 videotestsrc->make_image = gst_video_test_src_red;
383 case GST_VIDEO_TEST_SRC_GREEN:
384 videotestsrc->make_image = gst_video_test_src_green;
386 case GST_VIDEO_TEST_SRC_BLUE:
387 videotestsrc->make_image = gst_video_test_src_blue;
389 case GST_VIDEO_TEST_SRC_CHECKERS1:
390 videotestsrc->make_image = gst_video_test_src_checkers1;
392 case GST_VIDEO_TEST_SRC_CHECKERS2:
393 videotestsrc->make_image = gst_video_test_src_checkers2;
395 case GST_VIDEO_TEST_SRC_CHECKERS4:
396 videotestsrc->make_image = gst_video_test_src_checkers4;
398 case GST_VIDEO_TEST_SRC_CHECKERS8:
399 videotestsrc->make_image = gst_video_test_src_checkers8;
401 case GST_VIDEO_TEST_SRC_CIRCULAR:
402 videotestsrc->make_image = gst_video_test_src_circular;
404 case GST_VIDEO_TEST_SRC_BLINK:
405 videotestsrc->make_image = gst_video_test_src_blink;
407 case GST_VIDEO_TEST_SRC_SMPTE75:
408 videotestsrc->make_image = gst_video_test_src_smpte75;
410 case GST_VIDEO_TEST_SRC_ZONE_PLATE:
411 videotestsrc->make_image = gst_video_test_src_zoneplate;
413 case GST_VIDEO_TEST_SRC_GAMUT:
414 videotestsrc->make_image = gst_video_test_src_gamut;
416 case GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE:
417 videotestsrc->make_image = gst_video_test_src_chromazoneplate;
419 case GST_VIDEO_TEST_SRC_SOLID:
420 videotestsrc->make_image = gst_video_test_src_solid;
422 case GST_VIDEO_TEST_SRC_BALL:
423 videotestsrc->make_image = gst_video_test_src_ball;
425 case GST_VIDEO_TEST_SRC_SMPTE100:
426 videotestsrc->make_image = gst_video_test_src_smpte100;
428 case GST_VIDEO_TEST_SRC_BAR:
429 videotestsrc->make_image = gst_video_test_src_bar;
432 g_assert_not_reached ();
437 gst_video_test_src_set_property (GObject * object, guint prop_id,
438 const GValue * value, GParamSpec * pspec)
440 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
444 gst_video_test_src_set_pattern (src, g_value_get_enum (value));
446 case PROP_TIMESTAMP_OFFSET:
447 src->timestamp_offset = g_value_get_int64 (value);
450 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
452 case PROP_PEER_ALLOC:
453 src->peer_alloc = g_value_get_boolean (value);
455 case PROP_COLOR_SPEC:
458 src->k0 = g_value_get_int (value);
461 src->kx = g_value_get_int (value);
464 src->ky = g_value_get_int (value);
467 src->kt = g_value_get_int (value);
470 src->kxt = g_value_get_int (value);
473 src->kyt = g_value_get_int (value);
476 src->kxy = g_value_get_int (value);
479 src->kx2 = g_value_get_int (value);
482 src->ky2 = g_value_get_int (value);
485 src->kt2 = g_value_get_int (value);
488 src->xoffset = g_value_get_int (value);
491 src->yoffset = g_value_get_int (value);
493 case PROP_FOREGROUND_COLOR:
494 src->foreground_color = g_value_get_uint (value);
496 case PROP_BACKGROUND_COLOR:
497 src->background_color = g_value_get_uint (value);
499 case PROP_HORIZONTAL_SPEED:
500 src->horizontal_speed = g_value_get_int (value);
507 gst_video_test_src_get_property (GObject * object, guint prop_id,
508 GValue * value, GParamSpec * pspec)
510 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
514 g_value_set_enum (value, src->pattern_type);
516 case PROP_TIMESTAMP_OFFSET:
517 g_value_set_int64 (value, src->timestamp_offset);
520 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
522 case PROP_PEER_ALLOC:
523 g_value_set_boolean (value, src->peer_alloc);
525 case PROP_COLOR_SPEC:
528 g_value_set_int (value, src->k0);
531 g_value_set_int (value, src->kx);
534 g_value_set_int (value, src->ky);
537 g_value_set_int (value, src->kt);
540 g_value_set_int (value, src->kxt);
543 g_value_set_int (value, src->kyt);
546 g_value_set_int (value, src->kxy);
549 g_value_set_int (value, src->kx2);
552 g_value_set_int (value, src->ky2);
555 g_value_set_int (value, src->kt2);
558 g_value_set_int (value, src->xoffset);
561 g_value_set_int (value, src->yoffset);
563 case PROP_FOREGROUND_COLOR:
564 g_value_set_uint (value, src->foreground_color);
566 case PROP_BACKGROUND_COLOR:
567 g_value_set_uint (value, src->background_color);
569 case PROP_HORIZONTAL_SPEED:
570 g_value_set_int (value, src->horizontal_speed);
573 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
578 /* threadsafe because this gets called as the plugin is loaded */
580 gst_video_test_src_getcaps (GstBaseSrc * bsrc)
582 static GstCaps *capslist = NULL;
586 GstStructure *structure;
589 caps = gst_caps_new_empty ();
590 for (i = 0; i < n_fourccs; i++) {
591 structure = paint_get_structure (fourcc_list + i);
592 gst_structure_set (structure,
593 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
594 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
595 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
596 gst_caps_append_structure (caps, structure);
602 return gst_caps_copy (capslist);
606 gst_video_test_src_parse_caps (const GstCaps * caps,
607 gint * width, gint * height, gint * rate_numerator, gint * rate_denominator,
608 struct fourcc_list_struct **fourcc, GstVideoTestSrcColorSpec * color_spec)
610 const GstStructure *structure;
611 GstPadLinkReturn ret;
612 const GValue *framerate;
615 GST_DEBUG ("parsing caps");
617 if (gst_caps_get_size (caps) < 1)
620 structure = gst_caps_get_structure (caps, 0);
622 if (!(*fourcc = paintinfo_find_by_structure (structure)))
625 ret = gst_structure_get_int (structure, "width", width);
626 ret &= gst_structure_get_int (structure, "height", height);
627 framerate = gst_structure_get_value (structure, "framerate");
630 *rate_numerator = gst_value_get_fraction_numerator (framerate);
631 *rate_denominator = gst_value_get_fraction_denominator (framerate);
635 csp = gst_structure_get_string (structure, "color-matrix");
637 if (strcmp (csp, "sdtv") == 0) {
638 *color_spec = GST_VIDEO_TEST_SRC_BT601;
639 } else if (strcmp (csp, "hdtv") == 0) {
640 *color_spec = GST_VIDEO_TEST_SRC_BT709;
642 GST_DEBUG ("unknown color-matrix");
646 *color_spec = GST_VIDEO_TEST_SRC_BT601;
654 GST_DEBUG ("videotestsrc format not found");
659 GST_DEBUG ("videotestsrc no framerate given");
665 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
668 gint width, height, rate_denominator, rate_numerator;
669 struct fourcc_list_struct *fourcc;
670 GstVideoTestSrc *videotestsrc;
671 GstVideoTestSrcColorSpec color_spec;
673 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
675 res = gst_video_test_src_parse_caps (caps, &width, &height,
676 &rate_numerator, &rate_denominator, &fourcc, &color_spec);
679 videotestsrc->fourcc = fourcc;
680 videotestsrc->width = width;
681 videotestsrc->height = height;
682 videotestsrc->rate_numerator = rate_numerator;
683 videotestsrc->rate_denominator = rate_denominator;
684 videotestsrc->bpp = videotestsrc->fourcc->bitspp;
685 videotestsrc->color_spec = color_spec;
687 GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
688 videotestsrc->width, videotestsrc->height,
689 videotestsrc->rate_numerator, videotestsrc->rate_denominator);
695 gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
698 GstVideoTestSrc *src;
700 src = GST_VIDEO_TEST_SRC (bsrc);
702 switch (GST_QUERY_TYPE (query)) {
703 case GST_QUERY_CONVERT:
705 GstFormat src_fmt, dest_fmt;
706 gint64 src_val, dest_val;
708 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
709 if (src_fmt == dest_fmt) {
715 case GST_FORMAT_DEFAULT:
717 case GST_FORMAT_TIME:
719 if (src->rate_numerator) {
720 dest_val = gst_util_uint64_scale (src_val,
721 src->rate_denominator * GST_SECOND, src->rate_numerator);
730 case GST_FORMAT_TIME:
732 case GST_FORMAT_DEFAULT:
734 if (src->rate_numerator) {
735 dest_val = gst_util_uint64_scale (src_val,
736 src->rate_numerator, src->rate_denominator * GST_SECOND);
749 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
754 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
761 GST_DEBUG_OBJECT (src, "query failed");
767 gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
768 GstClockTime * start, GstClockTime * end)
770 /* for live sources, sync on the timestamp of the buffer */
771 if (gst_base_src_is_live (basesrc)) {
772 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
774 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
775 /* get duration to calculate end time */
776 GstClockTime duration = GST_BUFFER_DURATION (buffer);
778 if (GST_CLOCK_TIME_IS_VALID (duration)) {
779 *end = timestamp + duration;
790 gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
793 GstVideoTestSrc *src;
795 src = GST_VIDEO_TEST_SRC (bsrc);
797 segment->time = segment->start;
798 time = segment->last_stop;
800 /* now move to the time indicated */
801 if (src->rate_numerator) {
802 src->n_frames = gst_util_uint64_scale (time,
803 src->rate_numerator, src->rate_denominator * GST_SECOND);
807 if (src->rate_numerator) {
808 src->running_time = gst_util_uint64_scale (src->n_frames,
809 src->rate_denominator * GST_SECOND, src->rate_numerator);
811 /* FIXME : Not sure what to set here */
812 src->running_time = 0;
815 g_assert (src->running_time <= time);
821 gst_video_test_src_is_seekable (GstBaseSrc * psrc)
823 /* we're seekable... */
828 gst_video_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
830 GstVideoTestSrc *src;
831 gulong newsize, size;
832 GstBuffer *outbuf = NULL;
834 GstClockTime next_time;
836 src = GST_VIDEO_TEST_SRC (psrc);
838 if (G_UNLIKELY (src->fourcc == NULL))
841 /* 0 framerate and we are at the second frame, eos */
842 if (G_UNLIKELY (src->rate_numerator == 0 && src->n_frames == 1))
845 newsize = gst_video_test_src_get_size (src, src->width, src->height);
847 g_return_val_if_fail (newsize > 0, GST_FLOW_ERROR);
850 "creating buffer of %lu bytes with %dx%d image for frame %d", newsize,
851 src->width, src->height, (gint) src->n_frames);
853 if (src->peer_alloc) {
855 gst_pad_alloc_buffer_and_set_caps (GST_BASE_SRC_PAD (psrc),
856 GST_BUFFER_OFFSET_NONE, newsize, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)),
858 if (res != GST_FLOW_OK)
861 /* the buffer could have renegotiated, we need to discard any buffers of the
863 size = GST_BUFFER_SIZE (outbuf);
864 newsize = gst_video_test_src_get_size (src, src->width, src->height);
866 if (size != newsize) {
867 gst_buffer_unref (outbuf);
872 if (outbuf == NULL) {
873 outbuf = gst_buffer_new_and_alloc (newsize);
874 gst_buffer_set_caps (outbuf, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)));
877 memset (GST_BUFFER_DATA (outbuf), 0, GST_BUFFER_SIZE (outbuf));
878 src->tmpline_u8 = g_malloc (src->width + 8);
879 src->tmpline = g_malloc ((src->width + 8) * 4);
880 src->tmpline2 = g_malloc ((src->width + 8) * 4);
882 src->make_image (src, (void *) GST_BUFFER_DATA (outbuf),
883 src->width, src->height);
885 g_free (src->tmpline);
886 g_free (src->tmpline2);
887 g_free (src->tmpline_u8);
889 GST_BUFFER_TIMESTAMP (outbuf) = src->timestamp_offset + src->running_time;
890 GST_BUFFER_OFFSET (outbuf) = src->n_frames;
892 GST_BUFFER_OFFSET_END (outbuf) = src->n_frames;
893 if (src->rate_numerator) {
894 next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
895 src->rate_denominator, src->rate_numerator);
896 GST_BUFFER_DURATION (outbuf) = next_time - src->running_time;
898 next_time = src->timestamp_offset;
899 /* NONE means forever */
900 GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
903 src->running_time = next_time;
911 GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),
912 ("format wasn't negotiated before get function"));
913 return GST_FLOW_NOT_NEGOTIATED;
917 GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
918 return GST_FLOW_UNEXPECTED;
922 GST_DEBUG_OBJECT (src, "could not allocate buffer, reason %s",
923 gst_flow_get_name (res));
929 gst_video_test_src_start (GstBaseSrc * basesrc)
931 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
933 src->running_time = 0;
940 plugin_init (GstPlugin * plugin)
942 gst_videotestsrc_orc_init ();
944 GST_DEBUG_CATEGORY_INIT (video_test_src_debug, "videotestsrc", 0,
945 "Video Test Source");
947 return gst_element_register (plugin, "videotestsrc", GST_RANK_NONE,
948 GST_TYPE_VIDEO_TEST_SRC);
951 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
954 "Creates a test video stream",
955 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)