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 GstCaps *gst_video_test_src_src_fixate (GstBaseSrc * bsrc,
98 static gboolean gst_video_test_src_is_seekable (GstBaseSrc * psrc);
99 static gboolean gst_video_test_src_do_seek (GstBaseSrc * bsrc,
100 GstSegment * segment);
101 static gboolean gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query);
103 static void gst_video_test_src_get_times (GstBaseSrc * basesrc,
104 GstBuffer * buffer, GstClockTime * start, GstClockTime * end);
105 static gboolean gst_video_test_src_decide_allocation (GstBaseSrc * bsrc,
107 static GstFlowReturn gst_video_test_src_fill (GstPushSrc * psrc,
109 static gboolean gst_video_test_src_start (GstBaseSrc * basesrc);
110 static gboolean gst_video_test_src_stop (GstBaseSrc * basesrc);
112 #define GST_TYPE_VIDEO_TEST_SRC_PATTERN (gst_video_test_src_pattern_get_type ())
114 gst_video_test_src_pattern_get_type (void)
116 static GType video_test_src_pattern_type = 0;
117 static const GEnumValue pattern_types[] = {
118 {GST_VIDEO_TEST_SRC_SMPTE, "SMPTE 100% color bars", "smpte"},
119 {GST_VIDEO_TEST_SRC_SNOW, "Random (television snow)", "snow"},
120 {GST_VIDEO_TEST_SRC_BLACK, "100% Black", "black"},
121 {GST_VIDEO_TEST_SRC_WHITE, "100% White", "white"},
122 {GST_VIDEO_TEST_SRC_RED, "Red", "red"},
123 {GST_VIDEO_TEST_SRC_GREEN, "Green", "green"},
124 {GST_VIDEO_TEST_SRC_BLUE, "Blue", "blue"},
125 {GST_VIDEO_TEST_SRC_CHECKERS1, "Checkers 1px", "checkers-1"},
126 {GST_VIDEO_TEST_SRC_CHECKERS2, "Checkers 2px", "checkers-2"},
127 {GST_VIDEO_TEST_SRC_CHECKERS4, "Checkers 4px", "checkers-4"},
128 {GST_VIDEO_TEST_SRC_CHECKERS8, "Checkers 8px", "checkers-8"},
129 {GST_VIDEO_TEST_SRC_CIRCULAR, "Circular", "circular"},
130 {GST_VIDEO_TEST_SRC_BLINK, "Blink", "blink"},
131 {GST_VIDEO_TEST_SRC_SMPTE75, "SMPTE 75% color bars", "smpte75"},
132 {GST_VIDEO_TEST_SRC_ZONE_PLATE, "Zone plate", "zone-plate"},
133 {GST_VIDEO_TEST_SRC_GAMUT, "Gamut checkers", "gamut"},
134 {GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE, "Chroma zone plate",
135 "chroma-zone-plate"},
136 {GST_VIDEO_TEST_SRC_SOLID, "Solid color", "solid-color"},
137 {GST_VIDEO_TEST_SRC_BALL, "Moving ball", "ball"},
138 {GST_VIDEO_TEST_SRC_SMPTE100, "SMPTE 100% color bars", "smpte100"},
139 {GST_VIDEO_TEST_SRC_BAR, "Bar", "bar"},
143 if (!video_test_src_pattern_type) {
144 video_test_src_pattern_type =
145 g_enum_register_static ("GstVideoTestSrcPattern", pattern_types);
147 return video_test_src_pattern_type;
151 gst_video_test_src_class_init (GstVideoTestSrcClass * klass)
153 GObjectClass *gobject_class;
154 GstElementClass *gstelement_class;
155 GstBaseSrcClass *gstbasesrc_class;
156 GstPushSrcClass *gstpushsrc_class;
159 gobject_class = (GObjectClass *) klass;
160 gstelement_class = (GstElementClass *) klass;
161 gstbasesrc_class = (GstBaseSrcClass *) klass;
162 gstpushsrc_class = (GstPushSrcClass *) klass;
164 gobject_class->set_property = gst_video_test_src_set_property;
165 gobject_class->get_property = gst_video_test_src_get_property;
167 g_object_class_install_property (gobject_class, PROP_PATTERN,
168 g_param_spec_enum ("pattern", "Pattern",
169 "Type of test pattern to generate", GST_TYPE_VIDEO_TEST_SRC_PATTERN,
170 DEFAULT_PATTERN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
171 g_object_class_install_property (gobject_class, PROP_TIMESTAMP_OFFSET,
172 g_param_spec_int64 ("timestamp-offset", "Timestamp offset",
173 "An offset added to timestamps set on buffers (in ns)", G_MININT64,
174 G_MAXINT64, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
175 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
176 g_param_spec_boolean ("is-live", "Is Live",
177 "Whether to act as a live source", DEFAULT_IS_LIVE,
178 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
179 g_object_class_install_property (gobject_class, PROP_K0,
180 g_param_spec_int ("k0", "Zoneplate zero order phase",
181 "Zoneplate zero order phase, for generating plain fields or phase offsets",
182 G_MININT32, G_MAXINT32, 0,
183 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
184 g_object_class_install_property (gobject_class, PROP_KX,
185 g_param_spec_int ("kx", "Zoneplate 1st order x phase",
186 "Zoneplate 1st order x phase, for generating constant horizontal frequencies",
187 G_MININT32, G_MAXINT32, 0,
188 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
189 g_object_class_install_property (gobject_class, PROP_KY,
190 g_param_spec_int ("ky", "Zoneplate 1st order y phase",
191 "Zoneplate 1st order y phase, for generating contant vertical frequencies",
192 G_MININT32, G_MAXINT32, 0,
193 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
194 g_object_class_install_property (gobject_class, PROP_KT,
195 g_param_spec_int ("kt", "Zoneplate 1st order t phase",
196 "Zoneplate 1st order t phase, for generating phase rotation as a function of time",
197 G_MININT32, G_MAXINT32, 0,
198 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
199 g_object_class_install_property (gobject_class, PROP_KXT,
200 g_param_spec_int ("kxt", "Zoneplate x*t product phase",
201 "Zoneplate x*t product phase, normalised to kxy/256 cycles per vertical pixel at width/2 from origin",
202 G_MININT32, G_MAXINT32, 0,
203 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
204 g_object_class_install_property (gobject_class, PROP_KYT,
205 g_param_spec_int ("kyt", "Zoneplate y*t product phase",
206 "Zoneplate y*t product phase", G_MININT32, G_MAXINT32, 0,
207 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
208 g_object_class_install_property (gobject_class, PROP_KXY,
209 g_param_spec_int ("kxy", "Zoneplate x*y product phase",
210 "Zoneplate x*y product phase", G_MININT32, G_MAXINT32, 0,
211 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
212 g_object_class_install_property (gobject_class, PROP_KX2,
213 g_param_spec_int ("kx2", "Zoneplate 2nd order x phase",
214 "Zoneplate 2nd order x phase, normalised to kx2/256 cycles per horizontal 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_KY2,
218 g_param_spec_int ("ky2", "Zoneplate 2nd order y phase",
219 "Zoneplate 2nd order y phase, normailsed to ky2/256 cycles per vertical pixel at height/2 from origin",
220 G_MININT32, G_MAXINT32, 0,
221 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
222 g_object_class_install_property (gobject_class, PROP_KT2,
223 g_param_spec_int ("kt2", "Zoneplate 2nd order t phase",
224 "Zoneplate 2nd order t phase, t*t/256 cycles per picture", G_MININT32,
225 G_MAXINT32, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
226 g_object_class_install_property (gobject_class, PROP_XOFFSET,
227 g_param_spec_int ("xoffset", "Zoneplate 2nd order products x offset",
228 "Zoneplate 2nd order products x offset", G_MININT32, G_MAXINT32, 0,
229 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
230 g_object_class_install_property (gobject_class, PROP_YOFFSET,
231 g_param_spec_int ("yoffset", "Zoneplate 2nd order products y offset",
232 "Zoneplate 2nd order products y offset", G_MININT32, G_MAXINT32, 0,
233 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
235 * GstVideoTestSrc:foreground-color
237 * Color to use for solid-color pattern and foreground color of other
238 * patterns. Default is white (0xffffffff).
242 g_object_class_install_property (gobject_class, PROP_FOREGROUND_COLOR,
243 g_param_spec_uint ("foreground-color", "Foreground Color",
244 "Foreground color to use (big-endian ARGB)", 0, G_MAXUINT32,
245 DEFAULT_FOREGROUND_COLOR,
246 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
248 * GstVideoTestSrc:background-color
250 * Color to use for background color of some patterns. Default is
251 * black (0xff000000).
255 g_object_class_install_property (gobject_class, PROP_BACKGROUND_COLOR,
256 g_param_spec_uint ("background-color", "Background Color",
257 "Background color to use (big-endian ARGB)", 0, G_MAXUINT32,
258 DEFAULT_BACKGROUND_COLOR,
259 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
261 g_object_class_install_property (gobject_class, PROP_HORIZONTAL_SPEED,
262 g_param_spec_int ("horizontal-speed", "Horizontal Speed",
263 "Scroll image number of pixels per frame (positive is scroll to the left)",
264 G_MININT32, G_MAXINT32, DEFAULT_HORIZONTAL_SPEED,
265 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
267 gst_element_class_set_details_simple (gstelement_class,
268 "Video test source", "Source/Video",
269 "Creates a test video stream", "David A. Schleef <ds@schleef.org>");
271 templ_caps = gst_video_test_src_getcaps (NULL, NULL);
272 gst_element_class_add_pad_template (gstelement_class,
273 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, templ_caps));
274 gst_caps_unref (templ_caps);
276 gstbasesrc_class->get_caps = gst_video_test_src_getcaps;
277 gstbasesrc_class->set_caps = gst_video_test_src_setcaps;
278 gstbasesrc_class->fixate = gst_video_test_src_src_fixate;
279 gstbasesrc_class->is_seekable = gst_video_test_src_is_seekable;
280 gstbasesrc_class->do_seek = gst_video_test_src_do_seek;
281 gstbasesrc_class->query = gst_video_test_src_query;
282 gstbasesrc_class->get_times = gst_video_test_src_get_times;
283 gstbasesrc_class->start = gst_video_test_src_start;
284 gstbasesrc_class->stop = gst_video_test_src_stop;
285 gstbasesrc_class->decide_allocation = gst_video_test_src_decide_allocation;
287 gstpushsrc_class->fill = gst_video_test_src_fill;
291 gst_video_test_src_init (GstVideoTestSrc * src)
293 gst_video_test_src_set_pattern (src, DEFAULT_PATTERN);
295 src->timestamp_offset = DEFAULT_TIMESTAMP_OFFSET;
296 src->foreground_color = DEFAULT_FOREGROUND_COLOR;
297 src->background_color = DEFAULT_BACKGROUND_COLOR;
298 src->horizontal_speed = DEFAULT_HORIZONTAL_SPEED;
300 /* we operate in time */
301 gst_base_src_set_format (GST_BASE_SRC (src), GST_FORMAT_TIME);
302 gst_base_src_set_live (GST_BASE_SRC (src), DEFAULT_IS_LIVE);
306 gst_video_test_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
308 GstStructure *structure;
310 caps = gst_caps_make_writable (caps);
312 structure = gst_caps_get_structure (caps, 0);
314 gst_structure_fixate_field_nearest_int (structure, "width", 320);
315 gst_structure_fixate_field_nearest_int (structure, "height", 240);
316 gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
317 if (gst_structure_has_field (structure, "pixel-aspect-ratio"))
318 gst_structure_fixate_field_nearest_fraction (structure,
319 "pixel-aspect-ratio", 1, 1);
320 if (gst_structure_has_field (structure, "colorimetry"))
321 gst_structure_fixate_field_string (structure, "colorimetry", "bt601");
322 if (gst_structure_has_field (structure, "chroma-site"))
323 gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2");
325 if (gst_structure_has_field (structure, "interlaced"))
326 gst_structure_fixate_field_boolean (structure, "interlaced", FALSE);
328 caps = GST_BASE_SRC_CLASS (parent_class)->fixate (bsrc, caps);
334 gst_video_test_src_set_pattern (GstVideoTestSrc * videotestsrc,
337 videotestsrc->pattern_type = pattern_type;
339 GST_DEBUG_OBJECT (videotestsrc, "setting pattern to %d", pattern_type);
341 switch (pattern_type) {
342 case GST_VIDEO_TEST_SRC_SMPTE:
343 videotestsrc->make_image = gst_video_test_src_smpte;
345 case GST_VIDEO_TEST_SRC_SNOW:
346 videotestsrc->make_image = gst_video_test_src_snow;
348 case GST_VIDEO_TEST_SRC_BLACK:
349 videotestsrc->make_image = gst_video_test_src_black;
351 case GST_VIDEO_TEST_SRC_WHITE:
352 videotestsrc->make_image = gst_video_test_src_white;
354 case GST_VIDEO_TEST_SRC_RED:
355 videotestsrc->make_image = gst_video_test_src_red;
357 case GST_VIDEO_TEST_SRC_GREEN:
358 videotestsrc->make_image = gst_video_test_src_green;
360 case GST_VIDEO_TEST_SRC_BLUE:
361 videotestsrc->make_image = gst_video_test_src_blue;
363 case GST_VIDEO_TEST_SRC_CHECKERS1:
364 videotestsrc->make_image = gst_video_test_src_checkers1;
366 case GST_VIDEO_TEST_SRC_CHECKERS2:
367 videotestsrc->make_image = gst_video_test_src_checkers2;
369 case GST_VIDEO_TEST_SRC_CHECKERS4:
370 videotestsrc->make_image = gst_video_test_src_checkers4;
372 case GST_VIDEO_TEST_SRC_CHECKERS8:
373 videotestsrc->make_image = gst_video_test_src_checkers8;
375 case GST_VIDEO_TEST_SRC_CIRCULAR:
376 videotestsrc->make_image = gst_video_test_src_circular;
378 case GST_VIDEO_TEST_SRC_BLINK:
379 videotestsrc->make_image = gst_video_test_src_blink;
381 case GST_VIDEO_TEST_SRC_SMPTE75:
382 videotestsrc->make_image = gst_video_test_src_smpte75;
384 case GST_VIDEO_TEST_SRC_ZONE_PLATE:
385 videotestsrc->make_image = gst_video_test_src_zoneplate;
387 case GST_VIDEO_TEST_SRC_GAMUT:
388 videotestsrc->make_image = gst_video_test_src_gamut;
390 case GST_VIDEO_TEST_SRC_CHROMA_ZONE_PLATE:
391 videotestsrc->make_image = gst_video_test_src_chromazoneplate;
393 case GST_VIDEO_TEST_SRC_SOLID:
394 videotestsrc->make_image = gst_video_test_src_solid;
396 case GST_VIDEO_TEST_SRC_BALL:
397 videotestsrc->make_image = gst_video_test_src_ball;
399 case GST_VIDEO_TEST_SRC_SMPTE100:
400 videotestsrc->make_image = gst_video_test_src_smpte100;
402 case GST_VIDEO_TEST_SRC_BAR:
403 videotestsrc->make_image = gst_video_test_src_bar;
406 g_assert_not_reached ();
411 gst_video_test_src_set_property (GObject * object, guint prop_id,
412 const GValue * value, GParamSpec * pspec)
414 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
418 gst_video_test_src_set_pattern (src, g_value_get_enum (value));
420 case PROP_TIMESTAMP_OFFSET:
421 src->timestamp_offset = g_value_get_int64 (value);
424 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
427 src->k0 = g_value_get_int (value);
430 src->kx = g_value_get_int (value);
433 src->ky = g_value_get_int (value);
436 src->kt = g_value_get_int (value);
439 src->kxt = g_value_get_int (value);
442 src->kyt = g_value_get_int (value);
445 src->kxy = g_value_get_int (value);
448 src->kx2 = g_value_get_int (value);
451 src->ky2 = g_value_get_int (value);
454 src->kt2 = g_value_get_int (value);
457 src->xoffset = g_value_get_int (value);
460 src->yoffset = g_value_get_int (value);
462 case PROP_FOREGROUND_COLOR:
463 src->foreground_color = g_value_get_uint (value);
465 case PROP_BACKGROUND_COLOR:
466 src->background_color = g_value_get_uint (value);
468 case PROP_HORIZONTAL_SPEED:
469 src->horizontal_speed = g_value_get_int (value);
476 gst_video_test_src_get_property (GObject * object, guint prop_id,
477 GValue * value, GParamSpec * pspec)
479 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (object);
483 g_value_set_enum (value, src->pattern_type);
485 case PROP_TIMESTAMP_OFFSET:
486 g_value_set_int64 (value, src->timestamp_offset);
489 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
492 g_value_set_int (value, src->k0);
495 g_value_set_int (value, src->kx);
498 g_value_set_int (value, src->ky);
501 g_value_set_int (value, src->kt);
504 g_value_set_int (value, src->kxt);
507 g_value_set_int (value, src->kyt);
510 g_value_set_int (value, src->kxy);
513 g_value_set_int (value, src->kx2);
516 g_value_set_int (value, src->ky2);
519 g_value_set_int (value, src->kt2);
522 g_value_set_int (value, src->xoffset);
525 g_value_set_int (value, src->yoffset);
527 case PROP_FOREGROUND_COLOR:
528 g_value_set_uint (value, src->foreground_color);
530 case PROP_BACKGROUND_COLOR:
531 g_value_set_uint (value, src->background_color);
533 case PROP_HORIZONTAL_SPEED:
534 g_value_set_int (value, src->horizontal_speed);
537 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
542 /* threadsafe because this gets called as the plugin is loaded */
544 gst_video_test_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
546 static GstCaps *capslist = NULL;
550 GstStructure *structure;
553 caps = gst_caps_new_empty ();
554 for (i = 0; i < n_formats; i++) {
555 structure = paint_get_structure (format_list + i);
556 gst_structure_set (structure,
557 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
558 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
559 "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
560 gst_caps_append_structure (caps, structure);
567 return gst_caps_intersect_full (filter, capslist, GST_CAPS_INTERSECT_FIRST);
569 return gst_caps_ref (capslist);
573 gst_video_test_src_parse_caps (const GstCaps * caps,
574 gint * width, gint * height, gint * fps_n, gint * fps_d,
575 GstVideoColorimetry * colorimetry)
577 const GstStructure *structure;
578 GstPadLinkReturn ret;
579 const GValue *framerate;
582 GST_DEBUG ("parsing caps");
584 structure = gst_caps_get_structure (caps, 0);
586 ret = gst_structure_get_int (structure, "width", width);
587 ret &= gst_structure_get_int (structure, "height", height);
588 framerate = gst_structure_get_value (structure, "framerate");
591 *fps_n = gst_value_get_fraction_numerator (framerate);
592 *fps_d = gst_value_get_fraction_denominator (framerate);
596 if ((csp = gst_structure_get_string (structure, "colorimetry")))
597 gst_video_colorimetry_from_string (colorimetry, csp);
604 GST_DEBUG ("videotestsrc no framerate given");
610 gst_video_test_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
612 GstVideoTestSrc *videotestsrc;
615 guint size, min, max;
616 GstStructure *config;
618 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
620 if (gst_query_get_n_allocation_pools (query) > 0) {
621 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
624 size = MAX (size, videotestsrc->info.size);
628 size = videotestsrc->info.size;
633 /* no downstream pool, make our own */
635 pool = gst_video_buffer_pool_new ();
638 config = gst_buffer_pool_get_config (pool);
639 if (gst_query_has_allocation_meta (query, GST_VIDEO_META_API_TYPE)) {
640 gst_buffer_pool_config_add_option (config,
641 GST_BUFFER_POOL_OPTION_VIDEO_META);
643 gst_buffer_pool_set_config (pool, config);
646 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
648 gst_query_add_allocation_pool (query, pool, size, min, max);
651 gst_object_unref (pool);
657 gst_video_test_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
659 struct format_list_struct *format;
660 const GstStructure *structure;
661 GstVideoTestSrc *videotestsrc;
664 videotestsrc = GST_VIDEO_TEST_SRC (bsrc);
666 structure = gst_caps_get_structure (caps, 0);
668 if (gst_structure_has_name (structure, "video/x-raw")) {
669 /* we can use the parsing code */
670 if (!gst_video_info_from_caps (&info, caps))
673 } else if (gst_structure_has_name (structure, "video/x-bayer")) {
674 if (!gst_video_test_src_parse_caps (caps, &info.width, &info.height,
675 &info.fps_n, &info.fps_d, &info.colorimetry))
679 gst_video_test_src_get_size (videotestsrc, info.width, info.height);
682 if (!(format = paintinfo_find_by_structure (structure)))
686 videotestsrc->format = format;
687 videotestsrc->info = info;
689 GST_DEBUG_OBJECT (videotestsrc, "size %dx%d, %d/%d fps",
690 info.width, info.height, info.fps_n, info.fps_d);
692 g_free (videotestsrc->tmpline);
693 g_free (videotestsrc->tmpline2);
694 g_free (videotestsrc->tmpline_u8);
695 videotestsrc->tmpline_u8 = g_malloc (info.width + 8);
696 videotestsrc->tmpline = g_malloc ((info.width + 8) * 4);
697 videotestsrc->tmpline2 = g_malloc ((info.width + 8) * 4);
704 GST_DEBUG_OBJECT (bsrc, "failed to parse caps");
709 GST_DEBUG ("videotestsrc format not found");
715 gst_video_test_src_query (GstBaseSrc * bsrc, GstQuery * query)
718 GstVideoTestSrc *src;
720 src = GST_VIDEO_TEST_SRC (bsrc);
722 switch (GST_QUERY_TYPE (query)) {
723 case GST_QUERY_CONVERT:
725 GstFormat src_fmt, dest_fmt;
726 gint64 src_val, dest_val;
728 gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
730 gst_video_info_convert (&src->info, src_fmt, src_val, dest_fmt,
732 gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
736 res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
743 gst_video_test_src_get_times (GstBaseSrc * basesrc, GstBuffer * buffer,
744 GstClockTime * start, GstClockTime * end)
746 /* for live sources, sync on the timestamp of the buffer */
747 if (gst_base_src_is_live (basesrc)) {
748 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
750 if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
751 /* get duration to calculate end time */
752 GstClockTime duration = GST_BUFFER_DURATION (buffer);
754 if (GST_CLOCK_TIME_IS_VALID (duration)) {
755 *end = timestamp + duration;
766 gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
768 GstClockTime position;
769 GstVideoTestSrc *src;
771 src = GST_VIDEO_TEST_SRC (bsrc);
773 segment->time = segment->start;
774 position = segment->position;
776 /* now move to the position indicated */
777 if (src->info.fps_n) {
778 src->n_frames = gst_util_uint64_scale (position,
779 src->info.fps_n, src->info.fps_d * GST_SECOND);
783 if (src->info.fps_n) {
784 src->running_time = gst_util_uint64_scale (src->n_frames,
785 src->info.fps_d * GST_SECOND, src->info.fps_n);
787 /* FIXME : Not sure what to set here */
788 src->running_time = 0;
791 g_assert (src->running_time <= position);
797 gst_video_test_src_is_seekable (GstBaseSrc * psrc)
799 /* we're seekable... */
804 gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
806 GstVideoTestSrc *src;
807 GstClockTime next_time;
810 src = GST_VIDEO_TEST_SRC (psrc);
812 if (G_UNLIKELY (src->format == NULL))
815 /* 0 framerate and we are at the second frame, eos */
816 if (G_UNLIKELY (src->info.fps_n == 0 && src->n_frames == 1))
820 "creating buffer from pool for frame %d", (gint) src->n_frames);
822 if (!gst_video_frame_map (&frame, &src->info, buffer, GST_MAP_WRITE))
825 src->make_image (src, &frame);
827 gst_video_frame_unmap (&frame);
829 GST_BUFFER_TIMESTAMP (buffer) = src->timestamp_offset + src->running_time;
830 GST_BUFFER_OFFSET (buffer) = src->n_frames;
832 GST_BUFFER_OFFSET_END (buffer) = src->n_frames;
833 if (src->info.fps_n) {
834 next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
835 src->info.fps_d, src->info.fps_n);
836 GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
838 next_time = src->timestamp_offset;
839 /* NONE means forever */
840 GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE;
843 src->running_time = next_time;
849 GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL),
850 ("format wasn't negotiated before get function"));
851 return GST_FLOW_NOT_NEGOTIATED;
855 GST_DEBUG_OBJECT (src, "eos: 0 framerate, frame %d", (gint) src->n_frames);
860 GST_DEBUG_OBJECT (src, "invalid frame");
866 gst_video_test_src_start (GstBaseSrc * basesrc)
868 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
870 src->running_time = 0;
877 gst_video_test_src_stop (GstBaseSrc * basesrc)
879 GstVideoTestSrc *src = GST_VIDEO_TEST_SRC (basesrc);
881 g_free (src->tmpline);
883 g_free (src->tmpline2);
884 src->tmpline2 = NULL;
885 g_free (src->tmpline_u8);
886 src->tmpline_u8 = NULL;
892 plugin_init (GstPlugin * plugin)
894 GST_DEBUG_CATEGORY_INIT (video_test_src_debug, "videotestsrc", 0,
895 "Video Test Source");
897 return gst_element_register (plugin, "videotestsrc", GST_RANK_NONE,
898 GST_TYPE_VIDEO_TEST_SRC);
901 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
904 "Creates a test video stream",
905 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)