1 /* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * SECTION:element-smpte
22 * @title: smpte
23 *
24 * smpte can accept I420 video streams with the same width, height and
25 * framerate. The two incoming buffers are blended together using an effect
26 * specific alpha mask.
27 *
28 * The #GstSMPTE:depth property defines the presision in bits of the mask. A
29 * higher presision will create a mask with smoother gradients in order to avoid
30 * banding.
31 *
32 * ## Sample pipelines
33 * |[
34 * gst-launch-1.0 -v videotestsrc pattern=1 ! smpte name=s border=20000 type=234 duration=2000000000 ! videoconvert ! ximagesink videotestsrc ! s.
35 * ]| A pipeline to demonstrate the smpte transition.
36 * It shows a pinwheel transition a from a snow videotestsrc to an smpte
37 * pattern videotestsrc. The transition will take 2 seconds to complete. The
38 * edges of the transition are smoothed with a 20000 big border.
39 *
40 */
41
42 #ifdef HAVE_CONFIG_H
43 #include "config.h"
44 #endif
45 #include <string.h>
46 #include "gstsmpte.h"
47 #include "paint.h"
48
49 GST_DEBUG_CATEGORY_STATIC (gst_smpte_debug);
50 #define GST_CAT_DEFAULT gst_smpte_debug
51
52 static GstStaticPadTemplate gst_smpte_src_template =
53 GST_STATIC_PAD_TEMPLATE ("src",
54 GST_PAD_SRC,
55 GST_PAD_ALWAYS,
56 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420")
57 )
58 );
59
60 static GstStaticPadTemplate gst_smpte_sink1_template =
61 GST_STATIC_PAD_TEMPLATE ("sink1",
62 GST_PAD_SINK,
63 GST_PAD_ALWAYS,
64 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420")
65 )
66 );
67
68 static GstStaticPadTemplate gst_smpte_sink2_template =
69 GST_STATIC_PAD_TEMPLATE ("sink2",
70 GST_PAD_SINK,
71 GST_PAD_ALWAYS,
72 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("I420")
73 )
74 );
75
76
77 /* SMPTE signals and args */
78 enum
79 {
80 /* FILL ME */
81 LAST_SIGNAL
82 };
83
84 #define DEFAULT_PROP_TYPE 1
85 #define DEFAULT_PROP_BORDER 0
86 #define DEFAULT_PROP_DEPTH 16
87 #define DEFAULT_PROP_DURATION GST_SECOND
88 #define DEFAULT_PROP_INVERT FALSE
89
90 enum
91 {
92 PROP_0,
93 PROP_TYPE,
94 PROP_BORDER,
95 PROP_DEPTH,
96 PROP_DURATION,
97 PROP_INVERT
98 };
99
100 #define GST_TYPE_SMPTE_TRANSITION_TYPE (gst_smpte_transition_type_get_type())
101 static GType
gst_smpte_transition_type_get_type(void)102 gst_smpte_transition_type_get_type (void)
103 {
104 static GType smpte_transition_type = 0;
105 GEnumValue *smpte_transitions;
106
107 if (!smpte_transition_type) {
108 const GList *definitions;
109 gint i = 0;
110
111 definitions = gst_mask_get_definitions ();
112 smpte_transitions =
113 g_new0 (GEnumValue, g_list_length ((GList *) definitions) + 1);
114
115 while (definitions) {
116 GstMaskDefinition *definition = (GstMaskDefinition *) definitions->data;
117
118 definitions = g_list_next (definitions);
119
120 smpte_transitions[i].value = definition->type;
121 /* older GLib versions have the two fields as non-const, hence the cast */
122 smpte_transitions[i].value_nick = (gchar *) definition->short_name;
123 smpte_transitions[i].value_name = (gchar *) definition->long_name;
124
125 i++;
126 }
127
128 smpte_transition_type =
129 g_enum_register_static ("GstSMPTETransitionType", smpte_transitions);
130 }
131 return smpte_transition_type;
132 }
133
134
135 static void gst_smpte_finalize (GstSMPTE * smpte);
136
137 static GstFlowReturn gst_smpte_collected (GstCollectPads * pads,
138 GstSMPTE * smpte);
139
140 static void gst_smpte_set_property (GObject * object, guint prop_id,
141 const GValue * value, GParamSpec * pspec);
142 static void gst_smpte_get_property (GObject * object, guint prop_id,
143 GValue * value, GParamSpec * pspec);
144
145 static GstStateChangeReturn gst_smpte_change_state (GstElement * element,
146 GstStateChange transition);
147
148 /*static guint gst_smpte_signals[LAST_SIGNAL] = { 0 }; */
149
150 #define gst_smpte_parent_class parent_class
151 G_DEFINE_TYPE (GstSMPTE, gst_smpte, GST_TYPE_ELEMENT);
152 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (smpte, "smpte", GST_RANK_NONE,
153 GST_TYPE_SMPTE, GST_DEBUG_CATEGORY_INIT (gst_smpte_debug, "smpte", 0,
154 "SMPTE transition effect"));
155
156 static void
gst_smpte_class_init(GstSMPTEClass * klass)157 gst_smpte_class_init (GstSMPTEClass * klass)
158 {
159 GObjectClass *gobject_class;
160 GstElementClass *gstelement_class;
161
162 gobject_class = (GObjectClass *) klass;
163 gstelement_class = (GstElementClass *) klass;
164
165 parent_class = g_type_class_peek_parent (klass);
166
167 gobject_class->set_property = gst_smpte_set_property;
168 gobject_class->get_property = gst_smpte_get_property;
169 gobject_class->finalize = (GObjectFinalizeFunc) gst_smpte_finalize;
170
171 _gst_mask_init ();
172
173 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_TYPE,
174 g_param_spec_enum ("type", "Type", "The type of transition to use",
175 GST_TYPE_SMPTE_TRANSITION_TYPE, DEFAULT_PROP_TYPE,
176 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
177 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BORDER,
178 g_param_spec_int ("border", "Border",
179 "The border width of the transition", 0, G_MAXINT,
180 DEFAULT_PROP_BORDER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
181 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DEPTH,
182 g_param_spec_int ("depth", "Depth", "Depth of the mask in bits", 1, 24,
183 DEFAULT_PROP_DEPTH, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
184 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DURATION,
185 g_param_spec_uint64 ("duration", "Duration",
186 "Duration of the transition effect in nanoseconds", 0, G_MAXUINT64,
187 DEFAULT_PROP_DURATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
188 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_INVERT,
189 g_param_spec_boolean ("invert", "Invert",
190 "Invert transition mask", DEFAULT_PROP_INVERT,
191 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
192
193 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_smpte_change_state);
194
195 gst_element_class_add_static_pad_template (gstelement_class,
196 &gst_smpte_sink1_template);
197 gst_element_class_add_static_pad_template (gstelement_class,
198 &gst_smpte_sink2_template);
199 gst_element_class_add_static_pad_template (gstelement_class,
200 &gst_smpte_src_template);
201 gst_element_class_set_static_metadata (gstelement_class, "SMPTE transitions",
202 "Filter/Editor/Video",
203 "Apply the standard SMPTE transitions on video images",
204 "Wim Taymans <wim.taymans@chello.be>");
205
206 gst_type_mark_as_plugin_api (GST_TYPE_SMPTE_TRANSITION_TYPE, 0);
207 }
208
209 /* wht yel cya grn mag red blu blk -I Q */
210 static const int y_colors[] = { 255, 226, 179, 150, 105, 76, 29, 16, 16, 0 };
211 static const int u_colors[] = { 128, 0, 170, 46, 212, 85, 255, 128, 0, 128 };
212 static const int v_colors[] = { 128, 155, 0, 21, 235, 255, 107, 128, 128, 255 };
213
214 static void
fill_i420(GstVideoInfo * vinfo,guint8 * data,gint height,gint color)215 fill_i420 (GstVideoInfo * vinfo, guint8 * data, gint height, gint color)
216 {
217 gint size = GST_VIDEO_INFO_COMP_STRIDE (vinfo, 0) * GST_ROUND_UP_2 (height);
218 gint size4 = size >> 2;
219 guint8 *yp = data;
220 guint8 *up = data + GST_VIDEO_INFO_COMP_OFFSET (vinfo, 1);
221 guint8 *vp = data + GST_VIDEO_INFO_COMP_OFFSET (vinfo, 2);
222
223 memset (yp, y_colors[color], size);
224 memset (up, u_colors[color], size4);
225 memset (vp, v_colors[color], size4);
226 }
227
228 static gboolean
gst_smpte_update_mask(GstSMPTE * smpte,gint type,gboolean invert,gint depth,gint width,gint height)229 gst_smpte_update_mask (GstSMPTE * smpte, gint type, gboolean invert,
230 gint depth, gint width, gint height)
231 {
232 GstMask *newmask;
233
234 if (smpte->mask) {
235 if (smpte->type == type &&
236 smpte->invert == invert &&
237 smpte->depth == depth &&
238 smpte->width == width && smpte->height == height)
239 return TRUE;
240 }
241
242 newmask = gst_mask_factory_new (type, invert, depth, width, height);
243 if (newmask) {
244 if (smpte->mask) {
245 gst_mask_destroy (smpte->mask);
246 }
247 smpte->mask = newmask;
248 smpte->type = type;
249 smpte->invert = invert;
250 smpte->depth = depth;
251 smpte->width = width;
252 smpte->height = height;
253
254 return TRUE;
255 }
256 return FALSE;
257 }
258
259 static gboolean
gst_smpte_setcaps(GstPad * pad,GstCaps * caps)260 gst_smpte_setcaps (GstPad * pad, GstCaps * caps)
261 {
262 GstSMPTE *smpte;
263 gboolean ret;
264 GstVideoInfo vinfo;
265
266 smpte = GST_SMPTE (GST_PAD_PARENT (pad));
267
268 gst_video_info_init (&vinfo);
269 if (!gst_video_info_from_caps (&vinfo, caps))
270 return FALSE;
271
272 smpte->width = GST_VIDEO_INFO_WIDTH (&vinfo);
273 smpte->height = GST_VIDEO_INFO_HEIGHT (&vinfo);
274 smpte->fps_num = GST_VIDEO_INFO_FPS_N (&vinfo);
275 smpte->fps_denom = GST_VIDEO_INFO_FPS_D (&vinfo);
276
277 /* figure out the duration in frames */
278 smpte->end_position = gst_util_uint64_scale (smpte->duration,
279 smpte->fps_num, GST_SECOND * smpte->fps_denom);
280
281 GST_DEBUG_OBJECT (smpte, "duration: %d frames", smpte->end_position);
282
283 ret =
284 gst_smpte_update_mask (smpte, smpte->type, smpte->invert, smpte->depth,
285 smpte->width, smpte->height);
286
287 if (pad == smpte->sinkpad1) {
288 GST_DEBUG_OBJECT (smpte, "setting pad1 info");
289 smpte->vinfo1 = vinfo;
290 } else {
291 GST_DEBUG_OBJECT (smpte, "setting pad2 info");
292 smpte->vinfo2 = vinfo;
293 }
294
295 return ret;
296 }
297
298 static gboolean
gst_smpte_sink_event(GstCollectPads * pads,GstCollectData * data,GstEvent * event,gpointer user_data)299 gst_smpte_sink_event (GstCollectPads * pads,
300 GstCollectData * data, GstEvent * event, gpointer user_data)
301 {
302 GstPad *pad;
303 gboolean ret = FALSE;
304
305 pad = data->pad;
306
307 switch (GST_EVENT_TYPE (event)) {
308 case GST_EVENT_CAPS:
309 {
310 GstCaps *caps;
311
312 gst_event_parse_caps (event, &caps);
313 ret = gst_smpte_setcaps (pad, caps);
314 gst_event_unref (event);
315 event = NULL;
316 break;
317 }
318 default:
319 break;
320 }
321
322 if (event != NULL)
323 return gst_collect_pads_event_default (pads, data, event, FALSE);
324
325 return ret;
326 }
327
328 static void
gst_smpte_init(GstSMPTE * smpte)329 gst_smpte_init (GstSMPTE * smpte)
330 {
331 smpte->sinkpad1 =
332 gst_pad_new_from_static_template (&gst_smpte_sink1_template, "sink1");
333 GST_PAD_SET_PROXY_CAPS (smpte->sinkpad1);
334 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad1);
335
336 smpte->sinkpad2 =
337 gst_pad_new_from_static_template (&gst_smpte_sink2_template, "sink2");
338 GST_PAD_SET_PROXY_CAPS (smpte->sinkpad2);
339 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad2);
340
341 smpte->srcpad =
342 gst_pad_new_from_static_template (&gst_smpte_src_template, "src");
343 gst_element_add_pad (GST_ELEMENT (smpte), smpte->srcpad);
344
345 smpte->collect = gst_collect_pads_new ();
346 gst_collect_pads_set_function (smpte->collect,
347 (GstCollectPadsFunction) GST_DEBUG_FUNCPTR (gst_smpte_collected), smpte);
348 gst_collect_pads_set_event_function (smpte->collect,
349 GST_DEBUG_FUNCPTR (gst_smpte_sink_event), smpte);
350
351 gst_collect_pads_add_pad (smpte->collect, smpte->sinkpad1,
352 sizeof (GstCollectData), NULL, TRUE);
353 gst_collect_pads_add_pad (smpte->collect, smpte->sinkpad2,
354 sizeof (GstCollectData), NULL, TRUE);
355
356 smpte->type = DEFAULT_PROP_TYPE;
357 smpte->border = DEFAULT_PROP_BORDER;
358 smpte->depth = DEFAULT_PROP_DEPTH;
359 smpte->duration = DEFAULT_PROP_DURATION;
360 smpte->invert = DEFAULT_PROP_INVERT;
361 smpte->fps_num = 0;
362 smpte->fps_denom = 1;
363 }
364
365 static void
gst_smpte_finalize(GstSMPTE * smpte)366 gst_smpte_finalize (GstSMPTE * smpte)
367 {
368 if (smpte->collect) {
369 gst_object_unref (smpte->collect);
370 }
371 if (smpte->mask) {
372 gst_mask_destroy (smpte->mask);
373 }
374
375 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) smpte);
376 }
377
378 static void
gst_smpte_reset(GstSMPTE * smpte)379 gst_smpte_reset (GstSMPTE * smpte)
380 {
381 smpte->width = -1;
382 smpte->height = -1;
383 smpte->position = 0;
384 smpte->end_position = 0;
385 smpte->send_stream_start = TRUE;
386 }
387
388 static void
gst_smpte_blend_i420(GstVideoFrame * frame1,GstVideoFrame * frame2,GstVideoFrame * oframe,GstMask * mask,gint border,gint pos)389 gst_smpte_blend_i420 (GstVideoFrame * frame1, GstVideoFrame * frame2,
390 GstVideoFrame * oframe, GstMask * mask, gint border, gint pos)
391 {
392 guint32 *maskp;
393 gint value;
394 gint i, j;
395 gint min, max;
396 guint8 *in1, *in2, *out, *in1u, *in1v, *in2u, *in2v, *outu, *outv;
397 gint width, height;
398
399 if (border == 0)
400 border++;
401
402 min = pos - border;
403 max = pos;
404
405 width = GST_VIDEO_FRAME_WIDTH (frame1);
406 height = GST_VIDEO_FRAME_HEIGHT (frame1);
407
408 in1 = GST_VIDEO_FRAME_COMP_DATA (frame1, 0);
409 in2 = GST_VIDEO_FRAME_COMP_DATA (frame2, 0);
410 out = GST_VIDEO_FRAME_COMP_DATA (oframe, 0);
411
412 in1u = GST_VIDEO_FRAME_COMP_DATA (frame1, 1);
413 in1v = GST_VIDEO_FRAME_COMP_DATA (frame1, 2);
414 in2u = GST_VIDEO_FRAME_COMP_DATA (frame2, 1);
415 in2v = GST_VIDEO_FRAME_COMP_DATA (frame2, 2);
416 outu = GST_VIDEO_FRAME_COMP_DATA (oframe, 1);
417 outv = GST_VIDEO_FRAME_COMP_DATA (oframe, 2);
418
419 maskp = mask->data;
420
421 for (i = 0; i < height; i++) {
422 for (j = 0; j < width; j++) {
423 value = *maskp++;
424 value = ((CLAMP (value, min, max) - min) << 8) / border;
425
426 out[j] = ((in1[j] * value) + (in2[j] * (256 - value))) >> 8;
427 if (!(i & 1) && !(j & 1)) {
428 outu[j / 2] =
429 ((in1u[j / 2] * value) + (in2u[j / 2] * (256 - value))) >> 8;
430 outv[j / 2] =
431 ((in1v[j / 2] * value) + (in2v[j / 2] * (256 - value))) >> 8;
432 }
433 }
434
435 in1 += GST_VIDEO_FRAME_COMP_STRIDE (frame1, 0);
436 in2 += GST_VIDEO_FRAME_COMP_STRIDE (frame2, 0);
437 out += GST_VIDEO_FRAME_COMP_STRIDE (oframe, 0);
438
439 if (!(i & 1)) {
440 in1u += GST_VIDEO_FRAME_COMP_STRIDE (frame1, 1);
441 in2u += GST_VIDEO_FRAME_COMP_STRIDE (frame2, 1);
442 in1v += GST_VIDEO_FRAME_COMP_STRIDE (frame1, 2);
443 in2v += GST_VIDEO_FRAME_COMP_STRIDE (frame1, 2);
444 outu += GST_VIDEO_FRAME_COMP_STRIDE (oframe, 1);
445 outv += GST_VIDEO_FRAME_COMP_STRIDE (oframe, 2);
446 }
447 }
448 }
449
450 static GstFlowReturn
gst_smpte_collected(GstCollectPads * pads,GstSMPTE * smpte)451 gst_smpte_collected (GstCollectPads * pads, GstSMPTE * smpte)
452 {
453 GstBuffer *outbuf;
454 GstClockTime ts;
455 GstBuffer *in1 = NULL, *in2 = NULL;
456 GSList *collected;
457 GstMapInfo map;
458 GstVideoFrame frame1, frame2, oframe;
459
460 if (G_UNLIKELY (smpte->fps_num == 0))
461 goto not_negotiated;
462
463 if (!gst_pad_has_current_caps (smpte->sinkpad1) ||
464 !gst_pad_has_current_caps (smpte->sinkpad2))
465 goto not_negotiated;
466
467 if (!gst_video_info_is_equal (&smpte->vinfo1, &smpte->vinfo2))
468 goto input_formats_do_not_match;
469
470 if (smpte->send_stream_start) {
471 gchar s_id[32];
472
473 /* stream-start (FIXME: create id based on input ids) */
474 g_snprintf (s_id, sizeof (s_id), "smpte-%08x", g_random_int ());
475 gst_pad_push_event (smpte->srcpad, gst_event_new_stream_start (s_id));
476 smpte->send_stream_start = FALSE;
477 }
478
479 ts = gst_util_uint64_scale_int (smpte->position * GST_SECOND,
480 smpte->fps_denom, smpte->fps_num);
481
482 for (collected = pads->data; collected; collected = g_slist_next (collected)) {
483 GstCollectData *data;
484
485 data = (GstCollectData *) collected->data;
486
487 if (data->pad == smpte->sinkpad1)
488 in1 = gst_collect_pads_pop (pads, data);
489 else if (data->pad == smpte->sinkpad2)
490 in2 = gst_collect_pads_pop (pads, data);
491 }
492
493 if (in1 == NULL) {
494 /* if no input, make picture black */
495 in1 = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&smpte->vinfo1));
496 gst_buffer_map (in1, &map, GST_MAP_WRITE);
497 fill_i420 (&smpte->vinfo1, map.data, smpte->height, 7);
498 gst_buffer_unmap (in1, &map);
499 }
500 if (in2 == NULL) {
501 /* if no input, make picture white */
502 in2 = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&smpte->vinfo2));
503 gst_buffer_map (in2, &map, GST_MAP_WRITE);
504 fill_i420 (&smpte->vinfo2, map.data, smpte->height, 0);
505 gst_buffer_unmap (in2, &map);
506 }
507
508 if (smpte->position < smpte->end_position) {
509 outbuf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&smpte->vinfo1));
510
511 /* set caps if not done yet */
512 if (!gst_pad_has_current_caps (smpte->srcpad)) {
513 GstCaps *caps;
514 GstSegment segment;
515
516 caps = gst_video_info_to_caps (&smpte->vinfo1);
517
518 gst_pad_set_caps (smpte->srcpad, caps);
519 gst_caps_unref (caps);
520
521 gst_segment_init (&segment, GST_FORMAT_TIME);
522 gst_pad_push_event (smpte->srcpad, gst_event_new_segment (&segment));
523 }
524
525 gst_video_frame_map (&frame1, &smpte->vinfo1, in1, GST_MAP_READ);
526 gst_video_frame_map (&frame2, &smpte->vinfo2, in2, GST_MAP_READ);
527 /* re-use either info, now know they are essentially identical */
528 gst_video_frame_map (&oframe, &smpte->vinfo1, outbuf, GST_MAP_WRITE);
529 gst_smpte_blend_i420 (&frame1, &frame2, &oframe, smpte->mask, smpte->border,
530 ((1 << smpte->depth) + smpte->border) *
531 smpte->position / smpte->end_position);
532 gst_video_frame_unmap (&frame1);
533 gst_video_frame_unmap (&frame2);
534 gst_video_frame_unmap (&oframe);
535 } else {
536 outbuf = in2;
537 gst_buffer_ref (in2);
538 }
539
540 smpte->position++;
541
542 if (in1)
543 gst_buffer_unref (in1);
544 if (in2)
545 gst_buffer_unref (in2);
546
547 GST_BUFFER_TIMESTAMP (outbuf) = ts;
548
549 return gst_pad_push (smpte->srcpad, outbuf);
550
551 /* ERRORS */
552 not_negotiated:
553 {
554 GST_ELEMENT_ERROR (smpte, CORE, NEGOTIATION, (NULL),
555 ("No input format negotiated"));
556 return GST_FLOW_NOT_NEGOTIATED;
557 }
558 input_formats_do_not_match:
559 {
560 GstCaps *caps1, *caps2;
561
562 caps1 = gst_pad_get_current_caps (smpte->sinkpad1);
563 caps2 = gst_pad_get_current_caps (smpte->sinkpad2);
564 GST_ELEMENT_ERROR (smpte, CORE, NEGOTIATION, (NULL),
565 ("input formats don't match: %" GST_PTR_FORMAT " vs. %" GST_PTR_FORMAT,
566 caps1, caps2));
567 if (caps1)
568 gst_caps_unref (caps1);
569 if (caps2)
570 gst_caps_unref (caps2);
571 return GST_FLOW_ERROR;
572 }
573 }
574
575 static void
gst_smpte_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)576 gst_smpte_set_property (GObject * object, guint prop_id,
577 const GValue * value, GParamSpec * pspec)
578 {
579 GstSMPTE *smpte;
580
581 smpte = GST_SMPTE (object);
582
583 switch (prop_id) {
584 case PROP_TYPE:
585 smpte->type = g_value_get_enum (value);
586 break;
587 case PROP_BORDER:
588 smpte->border = g_value_get_int (value);
589 break;
590 case PROP_DEPTH:
591 smpte->depth = g_value_get_int (value);
592 break;
593 case PROP_DURATION:
594 smpte->duration = g_value_get_uint64 (value);
595 break;
596 case PROP_INVERT:
597 smpte->invert = g_value_get_boolean (value);
598 break;
599 default:
600 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
601 break;
602 }
603 }
604
605 static void
gst_smpte_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)606 gst_smpte_get_property (GObject * object, guint prop_id,
607 GValue * value, GParamSpec * pspec)
608 {
609 GstSMPTE *smpte;
610
611 smpte = GST_SMPTE (object);
612
613 switch (prop_id) {
614 case PROP_TYPE:
615 g_value_set_enum (value, smpte->type);
616 break;
617 case PROP_BORDER:
618 g_value_set_int (value, smpte->border);
619 break;
620 case PROP_DEPTH:
621 g_value_set_int (value, smpte->depth);
622 break;
623 case PROP_DURATION:
624 g_value_set_uint64 (value, smpte->duration);
625 break;
626 case PROP_INVERT:
627 g_value_set_boolean (value, smpte->invert);
628 break;
629 default:
630 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
631 break;
632 }
633 }
634
635 static GstStateChangeReturn
gst_smpte_change_state(GstElement * element,GstStateChange transition)636 gst_smpte_change_state (GstElement * element, GstStateChange transition)
637 {
638 GstStateChangeReturn ret;
639 GstSMPTE *smpte;
640
641 smpte = GST_SMPTE (element);
642
643 switch (transition) {
644 case GST_STATE_CHANGE_READY_TO_PAUSED:
645 gst_smpte_reset (smpte);
646 GST_LOG_OBJECT (smpte, "starting collectpads");
647 gst_collect_pads_start (smpte->collect);
648 break;
649 case GST_STATE_CHANGE_PAUSED_TO_READY:
650 GST_LOG_OBJECT (smpte, "stopping collectpads");
651 gst_collect_pads_stop (smpte->collect);
652 break;
653 default:
654 break;
655 }
656
657 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
658
659 switch (transition) {
660 case GST_STATE_CHANGE_PAUSED_TO_READY:
661 gst_smpte_reset (smpte);
662 break;
663 default:
664 break;
665 }
666 return ret;
667 }
668