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_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 gst_video_test_src_parent_class parent_class
83 G_DEFINE_TYPE (GstVideoTestSrc, gst_video_test_src, GST_TYPE_PUSH_SRC);
85 static void gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
87 static void gst_video_test_src_set_property (GObject * object, guint prop_id,
88 const GValue * value, GParamSpec * pspec);
89 static void gst_video_test_src_get_property (GObject * object, guint prop_id,
90 GValue * value, GParamSpec * pspec);
92 static GstCaps *gst_video_test_src_getcaps (GstBaseSrc * bsrc,
94 static gboolean gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
95 static void gst_video_test_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps);
97 static gboolean gst_video_test_src_is_seekable (GstBaseSrc * psrc);
98 static gboolean gst_video_test_src_do_seek (GstBaseSrc * bsrc,
99 GstSegment * segment);
100 static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
102 static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
103 GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
104 static gboolean gst_video_test_src_decide_allocation (GstBaseSrc * bsrc,
106 static GstFlowReturn gst_video_test_src_fill (GstPushSrc * psrc,
108 static gboolean gst_video_test_src_start (GstBaseSrc * basesrc);
109 static gboolean gst_video_test_src_stop (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;
150 gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
152 GObjectClass *gobject_class;
153 GstElementClass *gstelement_class;
154 GstBaseSrcClass *gstbasesrc_class;
155 GstPushSrcClass *gstpushsrc_class;
158 gobject_class = (GObjectClass *) klass;
159 gstelement_class = (GstElementClass *) klass;
160 gstbasesrc_class = (GstBaseSrcClass *) klass;
161 gstpushsrc_class = (GstPushSrcClass *) klass;
163 gobject_class->set_property = gst_video_test_src_set_property;
164 gobject_class->get_property = gst_video_test_src_get_property;
166 g_object_class_install_property (gobject_class, PROP_PATTERN,
167 g_param_spec_enum ("pattern", "Pattern",
168 "Type of test pattern to generate", GST_TYPE_VIDEO_TEST_SRC_PATTERN,
169 DEFAULT_PATTERN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
170 g_object_class_install_property (gobject_class, PROP_TIMESTAMP_OFFSET,
171 g_param_spec_int64 ("timestamp-offset", "Timestamp offset",
172 "An offset added to timestamps set on buffers (in ns)", G_MININT64,
173 G_MAXINT64, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
174 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
175 g_param_spec_boolean ("is-live", "Is Live",
176 "Whether to act as a live source", DEFAULT_IS_LIVE,
177 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
178 g_object_class_install_property (gobject_class, PROP_K0,
179 g_param_spec_int ("k0", "Zoneplate zero order phase",
180 "Zoneplate zero order phase, for generating plain fields or phase offsets",
181 G_MININT32, G_MAXINT32, 0,
182 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
183 g_object_class_install_property (gobject_class, PROP_KX,
184 g_param_spec_int ("kx", "Zoneplate 1st order x phase",
185 "Zoneplate 1st order x phase, for generating constant horizontal frequencies",
186 G_MININT32, G_MAXINT32, 0,
187 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
188 g_object_class_install_property (gobject_class, PROP_KY,
189 g_param_spec_int ("ky", "Zoneplate 1st order y phase",
190 "Zoneplate 1st order y phase, for generating contant vertical frequencies",
191 G_MININT32, G_MAXINT32, 0,
192 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
193 g_object_class_install_property (gobject_class, PROP_KT,
194 g_param_spec_int ("kt", "Zoneplate 1st order t phase",
195 "Zoneplate 1st order t phase, for generating phase rotation as a function of time",
196 G_MININT32, G_MAXINT32, 0,
197 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
198 g_object_class_install_property (gobject_class, PROP_KXT,
199 g_param_spec_int ("kxt", "Zoneplate x*t product phase",
200 "Zoneplate x*t product phase, normalised to kxy/256 cycles per vertical pixel at width/2 from origin",
201 G_MININT32, G_MAXINT32, 0,
202 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
203 g_object_class_install_property (gobject_class, PROP_KYT,
204 g_param_spec_int ("kyt", "Zoneplate y*t product phase",
205 "Zoneplate y*t product phase", G_MININT32, G_MAXINT32, 0,
206 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
207 g_object_class_install_property (gobject_class, PROP_KXY,
208 g_param_spec_int ("kxy", "Zoneplate x*y product phase",
209 "Zoneplate x*y product phase", G_MININT32, G_MAXINT32, 0,
210 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
211 g_object_class_install_property (gobject_class, PROP_KX2,
212 g_param_spec_int ("kx2", "Zoneplate 2nd order x phase",
213 "Zoneplate 2nd order x phase, normalised to kx2/256 cycles per horizontal pixel at width/2 from origin",
214 G_MININT32, G_MAXINT32, 0,
215 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
216 g_object_class_install_property (gobject_class, PROP_KY2,
217 g_param_spec_int ("ky2", "Zoneplate 2nd order y phase",
218 "Zoneplate 2nd order y phase, normailsed to ky2/256 cycles per vertical pixel at height/2 from origin",
219 G_MININT32, G_MAXINT32, 0,
220 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
221 g_object_class_install_property (gobject_class, PROP_KT2,
222 g_param_spec_int ("kt2", "Zoneplate 2nd order t phase",
223 "Zoneplate 2nd order t phase, t*t/256 cycles per picture", G_MININT32,
224 G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
225 g_object_class_install_property (gobject_class, PROP_XOFFSET,
226 g_param_spec_int ("xoffset", "Zoneplate 2nd order products x offset",
227 "Zoneplate 2nd order products x offset", G_MININT32, G_MAXINT32, 0,
228 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
229 g_object_class_install_property (gobject_class, PROP_YOFFSET,
230 g_param_spec_int ("yoffset", "Zoneplate 2nd order products y offset",
231 "Zoneplate 2nd order products y offset", G_MININT32, G_MAXINT32, 0,
232 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
234 * GstVideoTestSrc:foreground-color
236 * Color to use for solid-color pattern and foreground color of other
237 * patterns. Default is white (0xffffffff).
241 g_object_class_install_property (gobject_class, PROP_FOREGROUND_COLOR,
242 g_param_spec_uint ("foreground-color", "Foreground Color",
243 "Foreground color to use (big-endian ARGB)", 0, G_MAXUINT32,
244 DEFAULT_FOREGROUND_COLOR,
245 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
247 * GstVideoTestSrc:background-color
249 * Color to use for background color of some patterns. Default is
250 * black (0xff000000).
254 g_object_class_install_property (gobject_class, PROP_BACKGROUND_COLOR,
255 g_param_spec_uint ("background-color", "Background Color",
256 "Background color to use (big-endian ARGB)", 0, G_MAXUINT32,
257 DEFAULT_BACKGROUND_COLOR,
258 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
260 g_object_class_install_property (gobject_class, PROP_HORIZONTAL_SPEED,
261 g_param_spec_int ("horizontal-speed", "Horizontal Speed",
262 "Scroll image number of pixels per frame (positive is scroll to the left)",
263 G_MININT32, G_MAXINT32, DEFAULT_HORIZONTAL_SPEED,
264 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
266 gst_element_class_set_details_simple (gstelement_class,
267 "Video test source", "Source/Video",
268 "Creates a test video stream", "David A. Schleef <ds@schleef.org>");
270 templ_caps = gst_video_test_src_getcaps (NULL, NULL);
271 gst_element_class_add_pad_template (gstelement_class,
272 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, templ_caps));
273 gst_caps_unref (templ_caps);
275 gstbasesrc_class->get_caps = gst_video_test_src_getcaps;
276 gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
277 gstbasesrc_class->fixate = gst_video_test_src_src_fixate;
278 gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
279 gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
280 gstbasesrc_class->query = gst_video_test_src_query;
281 gstbasesrc_class->get_times = gst_video_test_src_get_times;
282 gstbasesrc_class->start = gst_video_test_src_start;
283 gstbasesrc_class->stop = gst_video_test_src_stop;
284 gstbasesrc_class->decide_allocation = gst_video_test_src_decide_allocation;
286 gstpushsrc_class->fill = gst_video_test_src_fill;
290 gst_video_test_src_init (GstVideoTestSrc * src)
292 gst_video_test_src_set_pattern (src, DEFAULT_PATTERN);
294 src->timestamp_offset = DEFAULT_TIMESTAMP_OFFSET;
295 src->foreground_color = DEFAULT_FOREGROUND_COLOR;
296 src->background_color = DEFAULT_BACKGROUND_COLOR;
297 src->horizontal_speed = DEFAULT_HORIZONTAL_SPEED;
299 /* we operate in time */
300 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
301 gst_base_src_set_live (GST_BASE_SRC (src), DEFAULT_IS_LIVE);
305 gst_video_test_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
307 GstStructure *structure;
309 structure = gst_caps_get_structure (caps, 0);
311 gst_structure_fixate_field_nearest_int (structure, "width", 320);
312 gst_structure_fixate_field_nearest_int (structure, "height", 240);
313 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
314 if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
315 gst_structure_fixate_field_nearest_fraction (structure,
316 "pixel-aspect-ratio", 1, 1);
317 if (gst_structure_has_field (structure, "colorimetry"))
318 gst_structure_fixate_field_string (structure, "colorimetry", "bt601");
319 if (gst_structure_has_field (structure, "chroma-site"))
320 gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
322 if (gst_structure_has_field (structure, "interlaced"))
323 gst_structure_fixate_field_boolean (structure, "interlaced", FALSE);
325 GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
329 gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
332 videotestsrc->pattern_type = pattern_type;
334 GST_DEBUG_OBJECT (videotestsrc, "setting pattern to %d", pattern_type);
336 switch (pattern_type) {
337 case GST_VIDEO_TEST_SRC_SMPTE:
338 videotestsrc->make_image = gst_video_test_src_smpte;
340 case GST_VIDEO_TEST_SRC_SNOW:
341 videotestsrc->make_image = gst_video_test_src_snow;
343 case GST_VIDEO_TEST_SRC_BLACK:
344 videotestsrc->make_image = gst_video_test_src_black;
346 case GST_VIDEO_TEST_SRC_WHITE:
347 videotestsrc->make_image = gst_video_test_src_white;
349 case GST_VIDEO_TEST_SRC_RED:
350 videotestsrc->make_image = gst_video_test_src_red;
352 case GST_VIDEO_TEST_SRC_GREEN:
353 videotestsrc->make_image = gst_video_test_src_green;
355 case GST_VIDEO_TEST_SRC_BLUE:
356 videotestsrc->make_image = gst_video_test_src_blue;
358 case GST_VIDEO_TEST_SRC_CHECKERS1:
359 videotestsrc->make_image = gst_video_test_src_checkers1;
361 case GST_VIDEO_TEST_SRC_CHECKERS2:
362 videotestsrc->make_image = gst_video_test_src_checkers2;
364 case GST_VIDEO_TEST_SRC_CHECKERS4:
365 videotestsrc->make_image = gst_video_test_src_checkers4;
367 case GST_VIDEO_TEST_SRC_CHECKERS8:
368 videotestsrc->make_image = gst_video_test_src_checkers8;
370 case GST_VIDEO_TEST_SRC_CIRCULAR:
371 videotestsrc->make_image = gst_video_test_src_circular;
373 case GST_VIDEO_TEST_SRC_BLINK:
374 videotestsrc->make_image = gst_video_test_src_blink;
376 case GST_VIDEO_TEST_SRC_SMPTE75:
377 videotestsrc->make_image = gst_video_test_src_smpte75;
379 case GST_VIDEO_TEST_SRC_ZONE_PLATE:
380 videotestsrc->make_image = gst_video_test_src_zoneplate;
382 case GST_VIDEO_TEST_SRC_GAMUT:
383 videotestsrc->make_image = gst_video_test_src_gamut;
385 case GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE:
386 videotestsrc->make_image = gst_video_test_src_chromazoneplate;
388 case GST_VIDEO_TEST_SRC_SOLID:
389 videotestsrc->make_image = gst_video_test_src_solid;
391 case GST_VIDEO_TEST_SRC_BALL:
392 videotestsrc->make_image = gst_video_test_src_ball;
394 case GST_VIDEO_TEST_SRC_SMPTE100:
395 videotestsrc->make_image = gst_video_test_src_smpte100;
397 case GST_VIDEO_TEST_SRC_BAR:
398 videotestsrc->make_image = gst_video_test_src_bar;
401 g_assert_not_reached ();
406 gst_video_test_src_set_property (GObject * object, guint prop_id,
407 const GValue * value, GParamSpec * pspec)
409 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
413 gst_video_test_src_set_pattern (src, g_value_get_enum (value));
415 case PROP_TIMESTAMP_OFFSET:
416 src->timestamp_offset = g_value_get_int64 (value);
419 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
422 src->k0 = g_value_get_int (value);
425 src->kx = g_value_get_int (value);
428 src->ky = g_value_get_int (value);
431 src->kt = g_value_get_int (value);
434 src->kxt = g_value_get_int (value);
437 src->kyt = g_value_get_int (value);
440 src->kxy = g_value_get_int (value);
443 src->kx2 = g_value_get_int (value);
446 src->ky2 = g_value_get_int (value);
449 src->kt2 = g_value_get_int (value);
452 src->xoffset = g_value_get_int (value);
455 src->yoffset = g_value_get_int (value);
457 case PROP_FOREGROUND_COLOR:
458 src->foreground_color = g_value_get_uint (value);
460 case PROP_BACKGROUND_COLOR:
461 src->background_color = g_value_get_uint (value);
463 case PROP_HORIZONTAL_SPEED:
464 src->horizontal_speed = g_value_get_int (value);
471 gst_video_test_src_get_property (GObject * object, guint prop_id,
472 GValue * value, GParamSpec * pspec)
474 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
478 g_value_set_enum (value, src->pattern_type);
480 case PROP_TIMESTAMP_OFFSET:
481 g_value_set_int64 (value, src->timestamp_offset);
484 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
487 g_value_set_int (value, src->k0);
490 g_value_set_int (value, src->kx);
493 g_value_set_int (value, src->ky);
496 g_value_set_int (value, src->kt);
499 g_value_set_int (value, src->kxt);
502 g_value_set_int (value, src->kyt);
505 g_value_set_int (value, src->kxy);
508 g_value_set_int (value, src->kx2);
511 g_value_set_int (value, src->ky2);
514 g_value_set_int (value, src->kt2);
517 g_value_set_int (value, src->xoffset);
520 g_value_set_int (value, src->yoffset);
522 case PROP_FOREGROUND_COLOR:
523 g_value_set_uint (value, src->foreground_color);
525 case PROP_BACKGROUND_COLOR:
526 g_value_set_uint (value, src->background_color);
528 case PROP_HORIZONTAL_SPEED:
529 g_value_set_int (value, src->horizontal_speed);
532 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
537 /* threadsafe because this gets called as the plugin is loaded */
539 gst_video_test_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
541 static GstCaps *capslist = NULL;
545 GstStructure *structure;
548 caps = gst_caps_new_empty ();
549 for (i = 0; i < n_formats; i++) {
550 structure = paint_get_structure (format_list + i);
551 gst_structure_set (structure,
552 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
553 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
554 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
555 gst_caps_append_structure (caps, structure);
562 return gst_caps_intersect_full (filter, capslist, GST_CAPS_INTERSECT_FIRST);
564 return gst_caps_ref (capslist);
568 gst_video_test_src_parse_caps (const GstCaps * caps,
569 gint * width, gint * height, gint * fps_n, gint * fps_d,
570 GstVideoColorimetry * colorimetry)
572 const GstStructure *structure;
573 GstPadLinkReturn ret;
574 const GValue *framerate;
577 GST_DEBUG ("parsing caps");
579 structure = gst_caps_get_structure (caps, 0);
581 ret = gst_structure_get_int (structure, "width", width);
582 ret &= gst_structure_get_int (structure, "height", height);
583 framerate = gst_structure_get_value (structure, "framerate");
586 *fps_n = gst_value_get_fraction_numerator (framerate);
587 *fps_d = gst_value_get_fraction_denominator (framerate);
591 if ((csp = gst_structure_get_string (structure, "colorimetry")))
592 gst_video_colorimetry_from_string (colorimetry, csp);
599 GST_DEBUG ("videotestsrc no framerate given");
605 gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
607 GstVideoTestSrc *videotestsrc;
609 guint size, min, max, prefix, alignment;
611 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
613 gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
616 size = MAX (size, videotestsrc->info.size);
619 GstStructure *config;
621 config = gst_buffer_pool_get_config (pool);
622 gst_buffer_pool_config_add_option (config,
623 GST_BUFFER_POOL_OPTION_VIDEO_META);
624 gst_buffer_pool_set_config (pool, config);
626 gst_query_set_allocation_params (query, size, min, max, prefix,
633 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
635 struct format_list_struct *format;
636 const GstStructure *structure;
637 GstVideoTestSrc *videotestsrc;
640 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
642 structure = gst_caps_get_structure (caps, 0);
644 if (gst_structure_has_name (structure, "video/x-raw")) {
645 /* we can use the parsing code */
646 if (!gst_video_info_from_caps (&info, caps))
649 } else if (gst_structure_has_name (structure, "video/x-raw-bayer")) {
650 if (!gst_video_test_src_parse_caps (caps, &info.width, &info.height,
651 &info.fps_n, &info.fps_d, &info.colorimetry))
655 gst_video_test_src_get_size (videotestsrc, info.width, info.height);
658 if (!(format = paintinfo_find_by_structure (structure)))
662 videotestsrc->format = format;
663 videotestsrc->info = info;
665 GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
666 info.width, info.height, info.fps_n, info.fps_d);
668 g_free (videotestsrc->tmpline);
669 g_free (videotestsrc->tmpline2);
670 g_free (videotestsrc->tmpline_u8);
671 videotestsrc->tmpline_u8 = g_malloc (info.width + 8);
672 videotestsrc->tmpline = g_malloc ((info.width + 8) * 4);
673 videotestsrc->tmpline2 = g_malloc ((info.width + 8) * 4);
680 GST_DEBUG_OBJECT (bsrc, "failed to parse caps");
685 GST_DEBUG ("videotestsrc format not found");
691 gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
694 GstVideoTestSrc *src;
696 src = GST_VIDEO_TEST_SRC (bsrc);
698 switch (GST_QUERY_TYPE (query)) {
699 case GST_QUERY_CONVERT:
701 GstFormat src_fmt, dest_fmt;
702 gint64 src_val, dest_val;
704 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
706 gst_video_info_convert (&src->info, src_fmt, src_val, dest_fmt,
708 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
712 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
719 gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
720 GstClockTime * start, GstClockTime * end)
722 /* for live sources, sync on the timestamp of the buffer */
723 if (gst_base_src_is_live (basesrc)) {
724 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
726 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
727 /* get duration to calculate end time */
728 GstClockTime duration = GST_BUFFER_DURATION (buffer);
730 if (GST_CLOCK_TIME_IS_VALID (duration)) {
731 *end = timestamp + duration;
742 gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
744 GstClockTime position;
745 GstVideoTestSrc *src;
747 src = GST_VIDEO_TEST_SRC (bsrc);
749 segment->time = segment->start;
750 position = segment->position;
752 /* now move to the position indicated */
753 if (src->info.fps_n) {
754 src->n_frames = gst_util_uint64_scale (position,
755 src->info.fps_n, src->info.fps_d * GST_SECOND);
759 if (src->info.fps_n) {
760 src->running_time = gst_util_uint64_scale (src->n_frames,
761 src->info.fps_d * GST_SECOND, src->info.fps_n);
763 /* FIXME : Not sure what to set here */
764 src->running_time = 0;
767 g_assert (src->running_time <= position);
773 gst_video_test_src_is_seekable (GstBaseSrc * psrc)
775 /* we're seekable... */
780 gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
782 GstVideoTestSrc *src;
783 GstClockTime next_time;
786 src = GST_VIDEO_TEST_SRC (psrc);
788 if (G_UNLIKELY (src->format == NULL))
791 /* 0 framerate and we are at the second frame, eos */
792 if (G_UNLIKELY (src->info.fps_n == 0 && src->n_frames == 1))
796 "creating buffer from pool for frame %d", (gint) src->n_frames);
798 if (!gst_video_frame_map (&frame, &src->info, buffer, GST_MAP_WRITE))
801 src->make_image (src, &frame);
803 gst_video_frame_unmap (&frame);
805 GST_BUFFER_TIMESTAMP (buffer) = src->timestamp_offset + src->running_time;
806 GST_BUFFER_OFFSET (buffer) = src->n_frames;
808 GST_BUFFER_OFFSET_END (buffer) = src->n_frames;
809 if (src->info.fps_n) {
810 next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
811 src->info.fps_d, src->info.fps_n);
812 GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
814 next_time = src->timestamp_offset;
815 /* NONE means forever */
816 GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
819 src->running_time = next_time;
825 GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),
826 ("format wasn't negotiated before get function"));
827 return GST_FLOW_NOT_NEGOTIATED;
831 GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
836 GST_DEBUG_OBJECT (src, "invalid frame");
842 gst_video_test_src_start (GstBaseSrc * basesrc)
844 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
846 src->running_time = 0;
853 gst_video_test_src_stop (GstBaseSrc * basesrc)
855 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
857 g_free (src->tmpline);
859 g_free (src->tmpline2);
860 src->tmpline2 = NULL;
861 g_free (src->tmpline_u8);
862 src->tmpline_u8 = NULL;
868 plugin_init (GstPlugin * plugin)
870 gst_videotestsrc_orc_init ();
872 GST_DEBUG_CATEGORY_INIT (video_test_src_debug, "videotestsrc", 0,
873 "Video Test Source");
875 return gst_element_register (plugin, "videotestsrc", GST_RANK_NONE,
876 GST_TYPE_VIDEO_TEST_SRC);
879 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
882 "Creates a test video stream",
883 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)