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 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_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);
171 GstPadTemplate *pad_template;
173 gst_element_class_set_details_simple (element_class,
174 "Video test source", "Source/Video",
175 "Creates a test video stream", "David A. Schleef <ds@schleef.org>");
178 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
179 gst_video_test_src_getcaps (NULL));
180 gst_element_class_add_pad_template (element_class, pad_template);
181 gst_object_unref (pad_template);
185 gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
187 GObjectClass *gobject_class;
188 GstBaseSrcClass *gstbasesrc_class;
189 GstPushSrcClass *gstpushsrc_class;
191 gobject_class = (GObjectClass *) klass;
192 gstbasesrc_class = (GstBaseSrcClass *) klass;
193 gstpushsrc_class = (GstPushSrcClass *) klass;
195 gobject_class->set_property = gst_video_test_src_set_property;
196 gobject_class->get_property = gst_video_test_src_get_property;
198 g_object_class_install_property (gobject_class, PROP_PATTERN,
199 g_param_spec_enum ("pattern", "Pattern",
200 "Type of test pattern to generate", GST_TYPE_VIDEO_TEST_SRC_PATTERN,
201 DEFAULT_PATTERN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
202 g_object_class_install_property (gobject_class, PROP_TIMESTAMP_OFFSET,
203 g_param_spec_int64 ("timestamp-offset", "Timestamp offset",
204 "An offset added to timestamps set on buffers (in ns)", G_MININT64,
205 G_MAXINT64, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
206 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
207 g_param_spec_boolean ("is-live", "Is Live",
208 "Whether to act as a live source", DEFAULT_IS_LIVE,
209 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
210 g_object_class_install_property (gobject_class, PROP_PEER_ALLOC,
211 g_param_spec_boolean ("peer-alloc", "Peer Alloc",
212 "Ask the peer to allocate an output buffer", DEFAULT_PEER_ALLOC,
213 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
214 g_object_class_install_property (gobject_class, PROP_COLOR_SPEC,
215 g_param_spec_enum ("colorspec", "Color Specification",
216 "Generate video in the given color specification (Deprecated: "
217 "use a caps filter with video/x-raw-yuv,color-matrix=\"sdtv\" or "
219 GST_TYPE_VIDEO_TEST_SRC_COLOR_SPEC,
220 DEFAULT_COLOR_SPEC, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
221 g_object_class_install_property (gobject_class, PROP_K0,
222 g_param_spec_int ("k0", "Zoneplate zero order phase",
223 "Zoneplate zero order phase, for generating plain fields or phase offsets",
224 G_MININT32, G_MAXINT32, 0,
225 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
226 g_object_class_install_property (gobject_class, PROP_KX,
227 g_param_spec_int ("kx", "Zoneplate 1st order x phase",
228 "Zoneplate 1st order x phase, for generating constant horizontal frequencies",
229 G_MININT32, G_MAXINT32, 0,
230 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
231 g_object_class_install_property (gobject_class, PROP_KY,
232 g_param_spec_int ("ky", "Zoneplate 1st order y phase",
233 "Zoneplate 1st order y phase, for generating contant vertical frequencies",
234 G_MININT32, G_MAXINT32, 0,
235 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
236 g_object_class_install_property (gobject_class, PROP_KT,
237 g_param_spec_int ("kt", "Zoneplate 1st order t phase",
238 "Zoneplate 1st order t phase, for generating phase rotation as a function of time",
239 G_MININT32, G_MAXINT32, 0,
240 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
241 g_object_class_install_property (gobject_class, PROP_KXT,
242 g_param_spec_int ("kxt", "Zoneplate x*t product phase",
243 "Zoneplate x*t product phase, normalised to kxy/256 cycles per vertical pixel at width/2 from origin",
244 G_MININT32, G_MAXINT32, 0,
245 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
246 g_object_class_install_property (gobject_class, PROP_KYT,
247 g_param_spec_int ("kyt", "Zoneplate y*t product phase",
248 "Zoneplate y*t product phase", G_MININT32, G_MAXINT32, 0,
249 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
250 g_object_class_install_property (gobject_class, PROP_KXY,
251 g_param_spec_int ("kxy", "Zoneplate x*y product phase",
252 "Zoneplate x*y product phase", G_MININT32, G_MAXINT32, 0,
253 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
254 g_object_class_install_property (gobject_class, PROP_KX2,
255 g_param_spec_int ("kx2", "Zoneplate 2nd order x phase",
256 "Zoneplate 2nd order x phase, normalised to kx2/256 cycles per horizontal pixel at width/2 from origin",
257 G_MININT32, G_MAXINT32, 0,
258 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
259 g_object_class_install_property (gobject_class, PROP_KY2,
260 g_param_spec_int ("ky2", "Zoneplate 2nd order y phase",
261 "Zoneplate 2nd order y phase, normailsed to ky2/256 cycles per vertical pixel at height/2 from origin",
262 G_MININT32, G_MAXINT32, 0,
263 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
264 g_object_class_install_property (gobject_class, PROP_KT2,
265 g_param_spec_int ("kt2", "Zoneplate 2nd order t phase",
266 "Zoneplate 2nd order t phase, t*t/256 cycles per picture", G_MININT32,
267 G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
268 g_object_class_install_property (gobject_class, PROP_XOFFSET,
269 g_param_spec_int ("xoffset", "Zoneplate 2nd order products x offset",
270 "Zoneplate 2nd order products x offset", G_MININT32, G_MAXINT32, 0,
271 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
272 g_object_class_install_property (gobject_class, PROP_YOFFSET,
273 g_param_spec_int ("yoffset", "Zoneplate 2nd order products y offset",
274 "Zoneplate 2nd order products y offset", G_MININT32, G_MAXINT32, 0,
275 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
277 * GstVideoTestSrc:foreground-color
279 * Color to use for solid-color pattern and foreground color of other
280 * patterns. Default is white (0xffffffff).
284 g_object_class_install_property (gobject_class, PROP_FOREGROUND_COLOR,
285 g_param_spec_uint ("foreground-color", "Foreground Color",
286 "Foreground color to use (big-endian ARGB)", 0, G_MAXUINT32,
287 DEFAULT_FOREGROUND_COLOR,
288 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
290 * GstVideoTestSrc:background-color
292 * Color to use for background color of some patterns. Default is
293 * black (0xff000000).
297 g_object_class_install_property (gobject_class, PROP_BACKGROUND_COLOR,
298 g_param_spec_uint ("background-color", "Background Color",
299 "Background color to use (big-endian ARGB)", 0, G_MAXUINT32,
300 DEFAULT_BACKGROUND_COLOR,
301 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
303 g_object_class_install_property (gobject_class, PROP_HORIZONTAL_SPEED,
304 g_param_spec_int ("horizontal-speed", "Horizontal Speed",
305 "Scroll image number of pixels per frame (positive is scroll to the left)",
306 G_MININT32, G_MAXINT32, DEFAULT_HORIZONTAL_SPEED,
307 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
309 gstbasesrc_class->get_caps = gst_video_test_src_getcaps;
310 gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
311 gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
312 gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
313 gstbasesrc_class->query = gst_video_test_src_query;
314 gstbasesrc_class->get_times = gst_video_test_src_get_times;
315 gstbasesrc_class->start = gst_video_test_src_start;
317 gstpushsrc_class->create = gst_video_test_src_create;
321 gst_video_test_src_init (GstVideoTestSrc * src, GstVideoTestSrcClass * g_class)
323 GstPad *pad = GST_BASE_SRC_PAD (src);
325 gst_pad_set_fixatecaps_function (pad, gst_video_test_src_src_fixate);
327 gst_video_test_src_set_pattern (src, DEFAULT_PATTERN);
329 src->timestamp_offset = DEFAULT_TIMESTAMP_OFFSET;
330 src->foreground_color = DEFAULT_FOREGROUND_COLOR;
331 src->background_color = DEFAULT_BACKGROUND_COLOR;
332 src->horizontal_speed = DEFAULT_HORIZONTAL_SPEED;
334 /* we operate in time */
335 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
336 gst_base_src_set_live (GST_BASE_SRC (src), DEFAULT_IS_LIVE);
337 src->peer_alloc = DEFAULT_PEER_ALLOC;
341 gst_video_test_src_src_fixate (GstPad * pad, GstCaps * caps)
343 GstStructure *structure;
345 structure = gst_caps_get_structure (caps, 0);
347 gst_structure_fixate_field_nearest_int (structure, "width", 320);
348 gst_structure_fixate_field_nearest_int (structure, "height", 240);
349 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
350 if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
351 gst_structure_fixate_field_nearest_fraction (structure,
352 "pixel-aspect-ratio", 1, 1);
353 if (gst_structure_has_field (structure, "color-matrix"))
354 gst_structure_fixate_field_string (structure, "color-matrix", "sdtv");
355 if (gst_structure_has_field (structure, "chroma-site"))
356 gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
358 if (gst_structure_has_field (structure, "interlaced"))
359 gst_structure_fixate_field_boolean (structure, "interlaced", FALSE);
363 gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
366 videotestsrc->pattern_type = pattern_type;
368 GST_DEBUG_OBJECT (videotestsrc, "setting pattern to %d", pattern_type);
370 switch (pattern_type) {
371 case GST_VIDEO_TEST_SRC_SMPTE:
372 videotestsrc->make_image = gst_video_test_src_smpte;
374 case GST_VIDEO_TEST_SRC_SNOW:
375 videotestsrc->make_image = gst_video_test_src_snow;
377 case GST_VIDEO_TEST_SRC_BLACK:
378 videotestsrc->make_image = gst_video_test_src_black;
380 case GST_VIDEO_TEST_SRC_WHITE:
381 videotestsrc->make_image = gst_video_test_src_white;
383 case GST_VIDEO_TEST_SRC_RED:
384 videotestsrc->make_image = gst_video_test_src_red;
386 case GST_VIDEO_TEST_SRC_GREEN:
387 videotestsrc->make_image = gst_video_test_src_green;
389 case GST_VIDEO_TEST_SRC_BLUE:
390 videotestsrc->make_image = gst_video_test_src_blue;
392 case GST_VIDEO_TEST_SRC_CHECKERS1:
393 videotestsrc->make_image = gst_video_test_src_checkers1;
395 case GST_VIDEO_TEST_SRC_CHECKERS2:
396 videotestsrc->make_image = gst_video_test_src_checkers2;
398 case GST_VIDEO_TEST_SRC_CHECKERS4:
399 videotestsrc->make_image = gst_video_test_src_checkers4;
401 case GST_VIDEO_TEST_SRC_CHECKERS8:
402 videotestsrc->make_image = gst_video_test_src_checkers8;
404 case GST_VIDEO_TEST_SRC_CIRCULAR:
405 videotestsrc->make_image = gst_video_test_src_circular;
407 case GST_VIDEO_TEST_SRC_BLINK:
408 videotestsrc->make_image = gst_video_test_src_blink;
410 case GST_VIDEO_TEST_SRC_SMPTE75:
411 videotestsrc->make_image = gst_video_test_src_smpte75;
413 case GST_VIDEO_TEST_SRC_ZONE_PLATE:
414 videotestsrc->make_image = gst_video_test_src_zoneplate;
416 case GST_VIDEO_TEST_SRC_GAMUT:
417 videotestsrc->make_image = gst_video_test_src_gamut;
419 case GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE:
420 videotestsrc->make_image = gst_video_test_src_chromazoneplate;
422 case GST_VIDEO_TEST_SRC_SOLID:
423 videotestsrc->make_image = gst_video_test_src_solid;
425 case GST_VIDEO_TEST_SRC_BALL:
426 videotestsrc->make_image = gst_video_test_src_ball;
428 case GST_VIDEO_TEST_SRC_SMPTE100:
429 videotestsrc->make_image = gst_video_test_src_smpte100;
431 case GST_VIDEO_TEST_SRC_BAR:
432 videotestsrc->make_image = gst_video_test_src_bar;
435 g_assert_not_reached ();
440 gst_video_test_src_set_property (GObject * object, guint prop_id,
441 const GValue * value, GParamSpec * pspec)
443 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
447 gst_video_test_src_set_pattern (src, g_value_get_enum (value));
449 case PROP_TIMESTAMP_OFFSET:
450 src->timestamp_offset = g_value_get_int64 (value);
453 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
455 case PROP_PEER_ALLOC:
456 src->peer_alloc = g_value_get_boolean (value);
458 case PROP_COLOR_SPEC:
461 src->k0 = g_value_get_int (value);
464 src->kx = g_value_get_int (value);
467 src->ky = g_value_get_int (value);
470 src->kt = g_value_get_int (value);
473 src->kxt = g_value_get_int (value);
476 src->kyt = g_value_get_int (value);
479 src->kxy = g_value_get_int (value);
482 src->kx2 = g_value_get_int (value);
485 src->ky2 = g_value_get_int (value);
488 src->kt2 = g_value_get_int (value);
491 src->xoffset = g_value_get_int (value);
494 src->yoffset = g_value_get_int (value);
496 case PROP_FOREGROUND_COLOR:
497 src->foreground_color = g_value_get_uint (value);
499 case PROP_BACKGROUND_COLOR:
500 src->background_color = g_value_get_uint (value);
502 case PROP_HORIZONTAL_SPEED:
503 src->horizontal_speed = g_value_get_int (value);
510 gst_video_test_src_get_property (GObject * object, guint prop_id,
511 GValue * value, GParamSpec * pspec)
513 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
517 g_value_set_enum (value, src->pattern_type);
519 case PROP_TIMESTAMP_OFFSET:
520 g_value_set_int64 (value, src->timestamp_offset);
523 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
525 case PROP_PEER_ALLOC:
526 g_value_set_boolean (value, src->peer_alloc);
528 case PROP_COLOR_SPEC:
531 g_value_set_int (value, src->k0);
534 g_value_set_int (value, src->kx);
537 g_value_set_int (value, src->ky);
540 g_value_set_int (value, src->kt);
543 g_value_set_int (value, src->kxt);
546 g_value_set_int (value, src->kyt);
549 g_value_set_int (value, src->kxy);
552 g_value_set_int (value, src->kx2);
555 g_value_set_int (value, src->ky2);
558 g_value_set_int (value, src->kt2);
561 g_value_set_int (value, src->xoffset);
564 g_value_set_int (value, src->yoffset);
566 case PROP_FOREGROUND_COLOR:
567 g_value_set_uint (value, src->foreground_color);
569 case PROP_BACKGROUND_COLOR:
570 g_value_set_uint (value, src->background_color);
572 case PROP_HORIZONTAL_SPEED:
573 g_value_set_int (value, src->horizontal_speed);
576 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
581 /* threadsafe because this gets called as the plugin is loaded */
583 gst_video_test_src_getcaps (GstBaseSrc * bsrc)
585 static GstCaps *capslist = NULL;
589 GstStructure *structure;
592 caps = gst_caps_new_empty ();
593 for (i = 0; i < n_fourccs; i++) {
594 structure = paint_get_structure (fourcc_list + i);
595 gst_structure_set (structure,
596 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
597 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
598 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
599 gst_caps_append_structure (caps, structure);
605 return gst_caps_copy (capslist);
609 gst_video_test_src_parse_caps (const GstCaps * caps,
610 gint * width, gint * height, gint * rate_numerator, gint * rate_denominator,
611 struct fourcc_list_struct **fourcc, GstVideoTestSrcColorSpec * color_spec)
613 const GstStructure *structure;
614 GstPadLinkReturn ret;
615 const GValue *framerate;
618 GST_DEBUG ("parsing caps");
620 if (gst_caps_get_size (caps) < 1)
623 structure = gst_caps_get_structure (caps, 0);
625 if (!(*fourcc = paintinfo_find_by_structure (structure)))
628 ret = gst_structure_get_int (structure, "width", width);
629 ret &= gst_structure_get_int (structure, "height", height);
630 framerate = gst_structure_get_value (structure, "framerate");
633 *rate_numerator = gst_value_get_fraction_numerator (framerate);
634 *rate_denominator = gst_value_get_fraction_denominator (framerate);
638 csp = gst_structure_get_string (structure, "color-matrix");
640 if (strcmp (csp, "sdtv") == 0) {
641 *color_spec = GST_VIDEO_TEST_SRC_BT601;
642 } else if (strcmp (csp, "hdtv") == 0) {
643 *color_spec = GST_VIDEO_TEST_SRC_BT709;
645 GST_DEBUG ("unknown color-matrix");
649 *color_spec = GST_VIDEO_TEST_SRC_BT601;
657 GST_DEBUG ("videotestsrc format not found");
662 GST_DEBUG ("videotestsrc no framerate given");
668 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
671 gint width, height, rate_denominator, rate_numerator;
672 struct fourcc_list_struct *fourcc;
673 GstVideoTestSrc *videotestsrc;
674 GstVideoTestSrcColorSpec color_spec;
676 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
678 res = gst_video_test_src_parse_caps (caps, &width, &height,
679 &rate_numerator, &rate_denominator, &fourcc, &color_spec);
682 videotestsrc->fourcc = fourcc;
683 videotestsrc->width = width;
684 videotestsrc->height = height;
685 videotestsrc->rate_numerator = rate_numerator;
686 videotestsrc->rate_denominator = rate_denominator;
687 videotestsrc->bpp = videotestsrc->fourcc->bitspp;
688 videotestsrc->color_spec = color_spec;
690 GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
691 videotestsrc->width, videotestsrc->height,
692 videotestsrc->rate_numerator, videotestsrc->rate_denominator);
698 gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
701 GstVideoTestSrc *src;
703 src = GST_VIDEO_TEST_SRC (bsrc);
705 switch (GST_QUERY_TYPE (query)) {
706 case GST_QUERY_CONVERT:
708 GstFormat src_fmt, dest_fmt;
709 gint64 src_val, dest_val;
711 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
712 if (src_fmt == dest_fmt) {
718 case GST_FORMAT_DEFAULT:
720 case GST_FORMAT_TIME:
722 if (src->rate_numerator) {
723 dest_val = gst_util_uint64_scale (src_val,
724 src->rate_denominator * GST_SECOND, src->rate_numerator);
733 case GST_FORMAT_TIME:
735 case GST_FORMAT_DEFAULT:
737 if (src->rate_numerator) {
738 dest_val = gst_util_uint64_scale (src_val,
739 src->rate_numerator, src->rate_denominator * GST_SECOND);
752 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
757 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
764 GST_DEBUG_OBJECT (src, "query failed");
770 gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
771 GstClockTime * start, GstClockTime * end)
773 /* for live sources, sync on the timestamp of the buffer */
774 if (gst_base_src_is_live (basesrc)) {
775 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
777 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
778 /* get duration to calculate end time */
779 GstClockTime duration = GST_BUFFER_DURATION (buffer);
781 if (GST_CLOCK_TIME_IS_VALID (duration)) {
782 *end = timestamp + duration;
793 gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
796 GstVideoTestSrc *src;
798 src = GST_VIDEO_TEST_SRC (bsrc);
800 segment->time = segment->start;
801 time = segment->last_stop;
803 /* now move to the time indicated */
804 if (src->rate_numerator) {
805 src->n_frames = gst_util_uint64_scale (time,
806 src->rate_numerator, src->rate_denominator * GST_SECOND);
810 if (src->rate_numerator) {
811 src->running_time = gst_util_uint64_scale (src->n_frames,
812 src->rate_denominator * GST_SECOND, src->rate_numerator);
814 /* FIXME : Not sure what to set here */
815 src->running_time = 0;
818 g_assert (src->running_time <= time);
824 gst_video_test_src_is_seekable (GstBaseSrc * psrc)
826 /* we're seekable... */
831 gst_video_test_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
833 GstVideoTestSrc *src;
834 gulong newsize, size;
835 GstBuffer *outbuf = NULL;
837 GstClockTime next_time;
839 src = GST_VIDEO_TEST_SRC (psrc);
841 if (G_UNLIKELY (src->fourcc == NULL))
844 /* 0 framerate and we are at the second frame, eos */
845 if (G_UNLIKELY (src->rate_numerator == 0 && src->n_frames == 1))
848 newsize = gst_video_test_src_get_size (src, src->width, src->height);
850 g_return_val_if_fail (newsize > 0, GST_FLOW_ERROR);
853 "creating buffer of %lu bytes with %dx%d image for frame %d", newsize,
854 src->width, src->height, (gint) src->n_frames);
856 if (src->peer_alloc) {
858 gst_pad_alloc_buffer_and_set_caps (GST_BASE_SRC_PAD (psrc),
859 GST_BUFFER_OFFSET_NONE, newsize, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)),
861 if (res != GST_FLOW_OK)
864 /* the buffer could have renegotiated, we need to discard any buffers of the
866 size = GST_BUFFER_SIZE (outbuf);
867 newsize = gst_video_test_src_get_size (src, src->width, src->height);
869 if (size != newsize) {
870 gst_buffer_unref (outbuf);
875 if (outbuf == NULL) {
876 outbuf = gst_buffer_new_and_alloc (newsize);
877 gst_buffer_set_caps (outbuf, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc)));
880 memset (GST_BUFFER_DATA (outbuf), 0, GST_BUFFER_SIZE (outbuf));
881 src->tmpline_u8 = g_malloc (src->width + 8);
882 src->tmpline = g_malloc ((src->width + 8) * 4);
883 src->tmpline2 = g_malloc ((src->width + 8) * 4);
885 src->make_image (src, (void *) GST_BUFFER_DATA (outbuf),
886 src->width, src->height);
888 g_free (src->tmpline);
889 g_free (src->tmpline2);
890 g_free (src->tmpline_u8);
892 GST_BUFFER_TIMESTAMP (outbuf) = src->timestamp_offset + src->running_time;
893 GST_BUFFER_OFFSET (outbuf) = src->n_frames;
895 GST_BUFFER_OFFSET_END (outbuf) = src->n_frames;
896 if (src->rate_numerator) {
897 next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
898 src->rate_denominator, src->rate_numerator);
899 GST_BUFFER_DURATION (outbuf) = next_time - src->running_time;
901 next_time = src->timestamp_offset;
902 /* NONE means forever */
903 GST_BUFFER_DURATION (outbuf) = GST_CLOCK_TIME_NONE;
906 src->running_time = next_time;
914 GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),
915 ("format wasn't negotiated before get function"));
916 return GST_FLOW_NOT_NEGOTIATED;
920 GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
921 return GST_FLOW_UNEXPECTED;
925 GST_DEBUG_OBJECT (src, "could not allocate buffer, reason %s",
926 gst_flow_get_name (res));
932 gst_video_test_src_start (GstBaseSrc * basesrc)
934 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
936 src->running_time = 0;
943 plugin_init (GstPlugin * plugin)
945 gst_videotestsrc_orc_init ();
947 GST_DEBUG_CATEGORY_INIT (video_test_src_debug, "videotestsrc", 0,
948 "Video Test Source");
950 return gst_element_register (plugin, "videotestsrc", GST_RANK_NONE,
951 GST_TYPE_VIDEO_TEST_SRC);
954 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
957 "Creates a test video stream",
958 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)