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 *
23 * smpte can accept I420 video streams with the same width, height and
24 * framerate. The two incoming buffers are blended together using an effect
25 * specific alpha mask.
26 *
27 * The #GstSmpte:depth property defines the presision in bits of the mask. A
28 * higher presision will create a mask with smoother gradients in order to avoid
29 * banding.
30 *
31 * <refsect2>
32 * <title>Sample pipelines</title>
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 * </refsect2>
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
153 static void
gst_smpte_class_init(GstSMPTEClass * klass)154 gst_smpte_class_init (GstSMPTEClass * klass)
155 {
156 GObjectClass *gobject_class;
157 GstElementClass *gstelement_class;
158
159 gobject_class = (GObjectClass *) klass;
160 gstelement_class = (GstElementClass *) klass;
161
162 parent_class = g_type_class_peek_parent (klass);
163
164 gobject_class->set_property = gst_smpte_set_property;
165 gobject_class->get_property = gst_smpte_get_property;
166 gobject_class->finalize = (GObjectFinalizeFunc) gst_smpte_finalize;
167
168 _gst_mask_init ();
169
170 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_TYPE,
171 g_param_spec_enum ("type", "Type", "The type of transition to use",
172 GST_TYPE_SMPTE_TRANSITION_TYPE, DEFAULT_PROP_TYPE,
173 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
174 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BORDER,
175 g_param_spec_int ("border", "Border",
176 "The border width of the transition", 0, G_MAXINT,
177 DEFAULT_PROP_BORDER, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
178 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DEPTH,
179 g_param_spec_int ("depth", "Depth", "Depth of the mask in bits", 1, 24,
180 DEFAULT_PROP_DEPTH, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
181 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DURATION,
182 g_param_spec_uint64 ("duration", "Duration",
183 "Duration of the transition effect in nanoseconds", 0, G_MAXUINT64,
184 DEFAULT_PROP_DURATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
185 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_INVERT,
186 g_param_spec_boolean ("invert", "Invert",
187 "Invert transition mask", DEFAULT_PROP_INVERT,
188 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
189
190 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_smpte_change_state);
191
192 gst_element_class_add_static_pad_template (gstelement_class,
193 &gst_smpte_sink1_template);
194 gst_element_class_add_static_pad_template (gstelement_class,
195 &gst_smpte_sink2_template);
196 gst_element_class_add_static_pad_template (gstelement_class,
197 &gst_smpte_src_template);
198 gst_element_class_set_static_metadata (gstelement_class, "SMPTE transitions",
199 "Filter/Editor/Video",
200 "Apply the standard SMPTE transitions on video images",
201 "Wim Taymans <wim.taymans@chello.be>");
202 }
203
204 /* wht yel cya grn mag red blu blk -I Q */
205 static const int y_colors[] = { 255, 226, 179, 150, 105, 76, 29, 16, 16, 0 };
206 static const int u_colors[] = { 128, 0, 170, 46, 212, 85, 255, 128, 0, 128 };
207 static const int v_colors[] = { 128, 155, 0, 21, 235, 255, 107, 128, 128, 255 };
208
209 static void
fill_i420(GstVideoInfo * vinfo,guint8 * data,gint height,gint color)210 fill_i420 (GstVideoInfo * vinfo, guint8 * data, gint height, gint color)
211 {
212 gint size = GST_VIDEO_INFO_COMP_STRIDE (vinfo, 0) * GST_ROUND_UP_2 (height);
213 gint size4 = size >> 2;
214 guint8 *yp = data;
215 guint8 *up = data + GST_VIDEO_INFO_COMP_OFFSET (vinfo, 1);
216 guint8 *vp = data + GST_VIDEO_INFO_COMP_OFFSET (vinfo, 2);
217
218 memset (yp, y_colors[color], size);
219 memset (up, u_colors[color], size4);
220 memset (vp, v_colors[color], size4);
221 }
222
223 static gboolean
gst_smpte_update_mask(GstSMPTE * smpte,gint type,gboolean invert,gint depth,gint width,gint height)224 gst_smpte_update_mask (GstSMPTE * smpte, gint type, gboolean invert,
225 gint depth, gint width, gint height)
226 {
227 GstMask *newmask;
228
229 if (smpte->mask) {
230 if (smpte->type == type &&
231 smpte->invert == invert &&
232 smpte->depth == depth &&
233 smpte->width == width && smpte->height == height)
234 return TRUE;
235 }
236
237 newmask = gst_mask_factory_new (type, invert, depth, width, height);
238 if (newmask) {
239 if (smpte->mask) {
240 gst_mask_destroy (smpte->mask);
241 }
242 smpte->mask = newmask;
243 smpte->type = type;
244 smpte->invert = invert;
245 smpte->depth = depth;
246 smpte->width = width;
247 smpte->height = height;
248
249 return TRUE;
250 }
251 return FALSE;
252 }
253
254 static gboolean
gst_smpte_setcaps(GstPad * pad,GstCaps * caps)255 gst_smpte_setcaps (GstPad * pad, GstCaps * caps)
256 {
257 GstSMPTE *smpte;
258 gboolean ret;
259 GstVideoInfo vinfo;
260
261 smpte = GST_SMPTE (GST_PAD_PARENT (pad));
262
263 gst_video_info_init (&vinfo);
264 if (!gst_video_info_from_caps (&vinfo, caps))
265 return FALSE;
266
267 smpte->width = GST_VIDEO_INFO_WIDTH (&vinfo);
268 smpte->height = GST_VIDEO_INFO_HEIGHT (&vinfo);
269 smpte->fps_num = GST_VIDEO_INFO_FPS_N (&vinfo);
270 smpte->fps_denom = GST_VIDEO_INFO_FPS_D (&vinfo);
271
272 /* figure out the duration in frames */
273 smpte->end_position = gst_util_uint64_scale (smpte->duration,
274 smpte->fps_num, GST_SECOND * smpte->fps_denom);
275
276 GST_DEBUG_OBJECT (smpte, "duration: %d frames", smpte->end_position);
277
278 ret =
279 gst_smpte_update_mask (smpte, smpte->type, smpte->invert, smpte->depth,
280 smpte->width, smpte->height);
281
282 if (pad == smpte->sinkpad1) {
283 GST_DEBUG_OBJECT (smpte, "setting pad1 info");
284 smpte->vinfo1 = vinfo;
285 } else {
286 GST_DEBUG_OBJECT (smpte, "setting pad2 info");
287 smpte->vinfo2 = vinfo;
288 }
289
290 return ret;
291 }
292
293 static gboolean
gst_smpte_sink_event(GstCollectPads * pads,GstCollectData * data,GstEvent * event,gpointer user_data)294 gst_smpte_sink_event (GstCollectPads * pads,
295 GstCollectData * data, GstEvent * event, gpointer user_data)
296 {
297 GstPad *pad;
298 gboolean ret = FALSE;
299
300 pad = data->pad;
301
302 switch (GST_EVENT_TYPE (event)) {
303 case GST_EVENT_CAPS:
304 {
305 GstCaps *caps;
306
307 gst_event_parse_caps (event, &caps);
308 ret = gst_smpte_setcaps (pad, caps);
309 gst_event_unref (event);
310 event = NULL;
311 break;
312 }
313 default:
314 break;
315 }
316
317 if (event != NULL)
318 return gst_collect_pads_event_default (pads, data, event, FALSE);
319
320 return ret;
321 }
322
323 static void
gst_smpte_init(GstSMPTE * smpte)324 gst_smpte_init (GstSMPTE * smpte)
325 {
326 smpte->sinkpad1 =
327 gst_pad_new_from_static_template (&gst_smpte_sink1_template, "sink1");
328 GST_PAD_SET_PROXY_CAPS (smpte->sinkpad1);
329 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad1);
330
331 smpte->sinkpad2 =
332 gst_pad_new_from_static_template (&gst_smpte_sink2_template, "sink2");
333 GST_PAD_SET_PROXY_CAPS (smpte->sinkpad2);
334 gst_element_add_pad (GST_ELEMENT (smpte), smpte->sinkpad2);
335
336 smpte->srcpad =
337 gst_pad_new_from_static_template (&gst_smpte_src_template, "src");
338 gst_element_add_pad (GST_ELEMENT (smpte), smpte->srcpad);
339
340 smpte->collect = gst_collect_pads_new ();
341 gst_collect_pads_set_function (smpte->collect,
342 (GstCollectPadsFunction) GST_DEBUG_FUNCPTR (gst_smpte_collected), smpte);
343 gst_collect_pads_set_event_function (smpte->collect,
344 GST_DEBUG_FUNCPTR (gst_smpte_sink_event), smpte);
345
346 gst_collect_pads_add_pad (smpte->collect, smpte->sinkpad1,
347 sizeof (GstCollectData), NULL, TRUE);
348 gst_collect_pads_add_pad (smpte->collect, smpte->sinkpad2,
349 sizeof (GstCollectData), NULL, TRUE);
350
351 smpte->type = DEFAULT_PROP_TYPE;
352 smpte->border = DEFAULT_PROP_BORDER;
353 smpte->depth = DEFAULT_PROP_DEPTH;
354 smpte->duration = DEFAULT_PROP_DURATION;
355 smpte->invert = DEFAULT_PROP_INVERT;
356 smpte->fps_num = 0;
357 smpte->fps_denom = 1;
358 }
359
360 static void
gst_smpte_finalize(GstSMPTE * smpte)361 gst_smpte_finalize (GstSMPTE * smpte)
362 {
363 if (smpte->collect) {
364 gst_object_unref (smpte->collect);
365 }
366 if (smpte->mask) {
367 gst_mask_destroy (smpte->mask);
368 }
369
370 G_OBJECT_CLASS (parent_class)->finalize ((GObject *) smpte);
371 }
372
373 static void
gst_smpte_reset(GstSMPTE * smpte)374 gst_smpte_reset (GstSMPTE * smpte)
375 {
376 smpte->width = -1;
377 smpte->height = -1;
378 smpte->position = 0;
379 smpte->end_position = 0;
380 smpte->send_stream_start = TRUE;
381 }
382
383 static void
gst_smpte_blend_i420(GstVideoFrame * frame1,GstVideoFrame * frame2,GstVideoFrame * oframe,GstMask * mask,gint border,gint pos)384 gst_smpte_blend_i420 (GstVideoFrame * frame1, GstVideoFrame * frame2,
385 GstVideoFrame * oframe, GstMask * mask, gint border, gint pos)
386 {
387 guint32 *maskp;
388 gint value;
389 gint i, j;
390 gint min, max;
391 guint8 *in1, *in2, *out, *in1u, *in1v, *in2u, *in2v, *outu, *outv;
392 gint width, height;
393
394 if (border == 0)
395 border++;
396
397 min = pos - border;
398 max = pos;
399
400 width = GST_VIDEO_FRAME_WIDTH (frame1);
401 height = GST_VIDEO_FRAME_HEIGHT (frame1);
402
403 in1 = GST_VIDEO_FRAME_COMP_DATA (frame1, 0);
404 in2 = GST_VIDEO_FRAME_COMP_DATA (frame2, 0);
405 out = GST_VIDEO_FRAME_COMP_DATA (oframe, 0);
406
407 in1u = GST_VIDEO_FRAME_COMP_DATA (frame1, 1);
408 in1v = GST_VIDEO_FRAME_COMP_DATA (frame1, 2);
409 in2u = GST_VIDEO_FRAME_COMP_DATA (frame2, 1);
410 in2v = GST_VIDEO_FRAME_COMP_DATA (frame2, 2);
411 outu = GST_VIDEO_FRAME_COMP_DATA (oframe, 1);
412 outv = GST_VIDEO_FRAME_COMP_DATA (oframe, 2);
413
414 maskp = mask->data;
415
416 for (i = 0; i < height; i++) {
417 for (j = 0; j < width; j++) {
418 value = *maskp++;
419 value = ((CLAMP (value, min, max) - min) << 8) / border;
420
421 out[j] = ((in1[j] * value) + (in2[j] * (256 - value))) >> 8;
422 if (!(i & 1) && !(j & 1)) {
423 outu[j / 2] =
424 ((in1u[j / 2] * value) + (in2u[j / 2] * (256 - value))) >> 8;
425 outv[j / 2] =
426 ((in1v[j / 2] * value) + (in2v[j / 2] * (256 - value))) >> 8;
427 }
428 }
429
430 in1 += GST_VIDEO_FRAME_COMP_STRIDE (frame1, 0);
431 in2 += GST_VIDEO_FRAME_COMP_STRIDE (frame2, 0);
432 out += GST_VIDEO_FRAME_COMP_STRIDE (oframe, 0);
433
434 if (!(i & 1)) {
435 in1u += GST_VIDEO_FRAME_COMP_STRIDE (frame1, 1);
436 in2u += GST_VIDEO_FRAME_COMP_STRIDE (frame2, 1);
437 in1v += GST_VIDEO_FRAME_COMP_STRIDE (frame1, 2);
438 in2v += GST_VIDEO_FRAME_COMP_STRIDE (frame1, 2);
439 outu += GST_VIDEO_FRAME_COMP_STRIDE (oframe, 1);
440 outv += GST_VIDEO_FRAME_COMP_STRIDE (oframe, 2);
441 }
442 }
443 }
444
445 static GstFlowReturn
gst_smpte_collected(GstCollectPads * pads,GstSMPTE * smpte)446 gst_smpte_collected (GstCollectPads * pads, GstSMPTE * smpte)
447 {
448 GstBuffer *outbuf;
449 GstClockTime ts;
450 GstBuffer *in1 = NULL, *in2 = NULL;
451 GSList *collected;
452 GstMapInfo map;
453 GstVideoFrame frame1, frame2, oframe;
454
455 if (G_UNLIKELY (smpte->fps_num == 0))
456 goto not_negotiated;
457
458 if (!gst_pad_has_current_caps (smpte->sinkpad1) ||
459 !gst_pad_has_current_caps (smpte->sinkpad2))
460 goto not_negotiated;
461
462 if (!gst_video_info_is_equal (&smpte->vinfo1, &smpte->vinfo2))
463 goto input_formats_do_not_match;
464
465 if (smpte->send_stream_start) {
466 gchar s_id[32];
467
468 /* stream-start (FIXME: create id based on input ids) */
469 g_snprintf (s_id, sizeof (s_id), "smpte-%08x", g_random_int ());
470 gst_pad_push_event (smpte->srcpad, gst_event_new_stream_start (s_id));
471 smpte->send_stream_start = FALSE;
472 }
473
474 ts = gst_util_uint64_scale_int (smpte->position * GST_SECOND,
475 smpte->fps_denom, smpte->fps_num);
476
477 for (collected = pads->data; collected; collected = g_slist_next (collected)) {
478 GstCollectData *data;
479
480 data = (GstCollectData *) collected->data;
481
482 if (data->pad == smpte->sinkpad1)
483 in1 = gst_collect_pads_pop (pads, data);
484 else if (data->pad == smpte->sinkpad2)
485 in2 = gst_collect_pads_pop (pads, data);
486 }
487
488 if (in1 == NULL) {
489 /* if no input, make picture black */
490 in1 = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&smpte->vinfo1));
491 gst_buffer_map (in1, &map, GST_MAP_WRITE);
492 fill_i420 (&smpte->vinfo1, map.data, smpte->height, 7);
493 gst_buffer_unmap (in1, &map);
494 }
495 if (in2 == NULL) {
496 /* if no input, make picture white */
497 in2 = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&smpte->vinfo2));
498 gst_buffer_map (in2, &map, GST_MAP_WRITE);
499 fill_i420 (&smpte->vinfo2, map.data, smpte->height, 0);
500 gst_buffer_unmap (in2, &map);
501 }
502
503 if (smpte->position < smpte->end_position) {
504 outbuf = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (&smpte->vinfo1));
505
506 /* set caps if not done yet */
507 if (!gst_pad_has_current_caps (smpte->srcpad)) {
508 GstCaps *caps;
509 GstSegment segment;
510
511 caps = gst_video_info_to_caps (&smpte->vinfo1);
512
513 gst_pad_set_caps (smpte->srcpad, caps);
514 gst_caps_unref (caps);
515
516 gst_segment_init (&segment, GST_FORMAT_TIME);
517 gst_pad_push_event (smpte->srcpad, gst_event_new_segment (&segment));
518 }
519
520 gst_video_frame_map (&frame1, &smpte->vinfo1, in1, GST_MAP_READ);
521 gst_video_frame_map (&frame2, &smpte->vinfo2, in2, GST_MAP_READ);
522 /* re-use either info, now know they are essentially identical */
523 gst_video_frame_map (&oframe, &smpte->vinfo1, outbuf, GST_MAP_WRITE);
524 gst_smpte_blend_i420 (&frame1, &frame2, &oframe, smpte->mask, smpte->border,
525 ((1 << smpte->depth) + smpte->border) *
526 smpte->position / smpte->end_position);
527 gst_video_frame_unmap (&frame1);
528 gst_video_frame_unmap (&frame2);
529 gst_video_frame_unmap (&oframe);
530 } else {
531 outbuf = in2;
532 gst_buffer_ref (in2);
533 }
534
535 smpte->position++;
536
537 if (in1)
538 gst_buffer_unref (in1);
539 if (in2)
540 gst_buffer_unref (in2);
541
542 GST_BUFFER_TIMESTAMP (outbuf) = ts;
543
544 return gst_pad_push (smpte->srcpad, outbuf);
545
546 /* ERRORS */
547 not_negotiated:
548 {
549 GST_ELEMENT_ERROR (smpte, CORE, NEGOTIATION, (NULL),
550 ("No input format negotiated"));
551 return GST_FLOW_NOT_NEGOTIATED;
552 }
553 input_formats_do_not_match:
554 {
555 GstCaps *caps1, *caps2;
556
557 caps1 = gst_pad_get_current_caps (smpte->sinkpad1);
558 caps2 = gst_pad_get_current_caps (smpte->sinkpad2);
559 GST_ELEMENT_ERROR (smpte, CORE, NEGOTIATION, (NULL),
560 ("input formats don't match: %" GST_PTR_FORMAT " vs. %" GST_PTR_FORMAT,
561 caps1, caps2));
562 if (caps1)
563 gst_caps_unref (caps1);
564 if (caps2)
565 gst_caps_unref (caps2);
566 return GST_FLOW_ERROR;
567 }
568 }
569
570 static void
gst_smpte_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)571 gst_smpte_set_property (GObject * object, guint prop_id,
572 const GValue * value, GParamSpec * pspec)
573 {
574 GstSMPTE *smpte;
575
576 smpte = GST_SMPTE (object);
577
578 switch (prop_id) {
579 case PROP_TYPE:
580 smpte->type = g_value_get_enum (value);
581 break;
582 case PROP_BORDER:
583 smpte->border = g_value_get_int (value);
584 break;
585 case PROP_DEPTH:
586 smpte->depth = g_value_get_int (value);
587 break;
588 case PROP_DURATION:
589 smpte->duration = g_value_get_uint64 (value);
590 break;
591 case PROP_INVERT:
592 smpte->invert = g_value_get_boolean (value);
593 break;
594 default:
595 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
596 break;
597 }
598 }
599
600 static void
gst_smpte_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)601 gst_smpte_get_property (GObject * object, guint prop_id,
602 GValue * value, GParamSpec * pspec)
603 {
604 GstSMPTE *smpte;
605
606 smpte = GST_SMPTE (object);
607
608 switch (prop_id) {
609 case PROP_TYPE:
610 g_value_set_enum (value, smpte->type);
611 break;
612 case PROP_BORDER:
613 g_value_set_int (value, smpte->border);
614 break;
615 case PROP_DEPTH:
616 g_value_set_int (value, smpte->depth);
617 break;
618 case PROP_DURATION:
619 g_value_set_uint64 (value, smpte->duration);
620 break;
621 case PROP_INVERT:
622 g_value_set_boolean (value, smpte->invert);
623 break;
624 default:
625 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
626 break;
627 }
628 }
629
630 static GstStateChangeReturn
gst_smpte_change_state(GstElement * element,GstStateChange transition)631 gst_smpte_change_state (GstElement * element, GstStateChange transition)
632 {
633 GstStateChangeReturn ret;
634 GstSMPTE *smpte;
635
636 smpte = GST_SMPTE (element);
637
638 switch (transition) {
639 case GST_STATE_CHANGE_READY_TO_PAUSED:
640 gst_smpte_reset (smpte);
641 GST_LOG_OBJECT (smpte, "starting collectpads");
642 gst_collect_pads_start (smpte->collect);
643 break;
644 case GST_STATE_CHANGE_PAUSED_TO_READY:
645 GST_LOG_OBJECT (smpte, "stopping collectpads");
646 gst_collect_pads_stop (smpte->collect);
647 break;
648 default:
649 break;
650 }
651
652 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
653
654 switch (transition) {
655 case GST_STATE_CHANGE_PAUSED_TO_READY:
656 gst_smpte_reset (smpte);
657 break;
658 default:
659 break;
660 }
661 return ret;
662 }
663
664 gboolean
gst_smpte_plugin_init(GstPlugin * plugin)665 gst_smpte_plugin_init (GstPlugin * plugin)
666 {
667 GST_DEBUG_CATEGORY_INIT (gst_smpte_debug, "smpte", 0,
668 "SMPTE transition effect");
669
670 return gst_element_register (plugin, "smpte", GST_RANK_NONE, GST_TYPE_SMPTE);
671 }
672