1 /* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * <2005> Wim Taymans <wim@fluendo.com>
4 *
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.
9 *
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.
14 *
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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 /**
22 * SECTION:element-dvdec
23 * @title: dvdec
24 *
25 * dvdec decodes DV video into raw video. The element expects a full DV frame
26 * as input, which is 120000 bytes for NTSC and 144000 for PAL video.
27 *
28 * This element can perform simple frame dropping with the #GstDVDec:drop-factor
29 * property. Setting this property to a value N > 1 will only decode every
30 * Nth frame.
31 *
32 * ## Example launch line
33 * |[
34 * gst-launch-1.0 filesrc location=test.dv ! dvdemux name=demux ! dvdec ! xvimagesink
35 * ]| This pipeline decodes and renders the raw DV stream to a videosink.
36 *
37 */
38
39 #ifdef HAVE_CONFIG_H
40 #include "config.h"
41 #endif
42 #include <string.h>
43 #include <math.h>
44 #include <gst/video/video.h>
45 #include <gst/video/gstvideometa.h>
46 #include <gst/video/gstvideopool.h>
47
48 #include "gstdvelements.h"
49 #include "gstdvdec.h"
50
51 /* sizes of one input buffer */
52 #define NTSC_HEIGHT 480
53 #define NTSC_BUFFER 120000
54 #define NTSC_FRAMERATE_NUMERATOR 30000
55 #define NTSC_FRAMERATE_DENOMINATOR 1001
56
57 #define PAL_HEIGHT 576
58 #define PAL_BUFFER 144000
59 #define PAL_FRAMERATE_NUMERATOR 25
60 #define PAL_FRAMERATE_DENOMINATOR 1
61
62 #define PAL_NORMAL_PAR_X 16
63 #define PAL_NORMAL_PAR_Y 15
64 #define PAL_WIDE_PAR_X 64
65 #define PAL_WIDE_PAR_Y 45
66
67 #define NTSC_NORMAL_PAR_X 8
68 #define NTSC_NORMAL_PAR_Y 9
69 #define NTSC_WIDE_PAR_X 32
70 #define NTSC_WIDE_PAR_Y 27
71
72 #define DV_DEFAULT_QUALITY DV_QUALITY_BEST
73 #define DV_DEFAULT_DECODE_NTH 1
74
75 GST_DEBUG_CATEGORY_STATIC (dvdec_debug);
76 #define GST_CAT_DEFAULT dvdec_debug
77
78 enum
79 {
80 PROP_0,
81 PROP_CLAMP_LUMA,
82 PROP_CLAMP_CHROMA,
83 PROP_QUALITY,
84 PROP_DECODE_NTH
85 };
86
87 const gint qualities[] = {
88 DV_QUALITY_DC,
89 DV_QUALITY_AC_1,
90 DV_QUALITY_AC_2,
91 DV_QUALITY_DC | DV_QUALITY_COLOR,
92 DV_QUALITY_AC_1 | DV_QUALITY_COLOR,
93 DV_QUALITY_AC_2 | DV_QUALITY_COLOR
94 };
95
96 static GstStaticPadTemplate sink_temp = GST_STATIC_PAD_TEMPLATE ("sink",
97 GST_PAD_SINK,
98 GST_PAD_ALWAYS,
99 GST_STATIC_CAPS ("video/x-dv, systemstream = (boolean) false")
100 );
101
102 static GstStaticPadTemplate src_temp = GST_STATIC_PAD_TEMPLATE ("src",
103 GST_PAD_SRC,
104 GST_PAD_ALWAYS,
105 GST_STATIC_CAPS ("video/x-raw, "
106 "format = (string) { YUY2, BGRx, RGB }, "
107 "framerate = (fraction) [ 1/1, 60/1 ], "
108 "width = (int) 720, " "height = (int) { 576, 480 }")
109 );
110
111 #define GST_TYPE_DVDEC_QUALITY (gst_dvdec_quality_get_type())
112 static GType
gst_dvdec_quality_get_type(void)113 gst_dvdec_quality_get_type (void)
114 {
115 static GType qtype = 0;
116
117 if (qtype == 0) {
118 static const GEnumValue values[] = {
119 {0, "Monochrome, DC (Fastest)", "fastest"},
120 {1, "Monochrome, first AC coefficient", "monochrome-ac"},
121 {2, "Monochrome, highest quality", "monochrome-best"},
122 {3, "Colour, DC, fastest", "colour-fastest"},
123 {4, "Colour, using only the first AC coefficient", "colour-ac"},
124 {5, "Highest quality colour decoding", "best"},
125 {0, NULL, NULL},
126 };
127
128 qtype = g_enum_register_static ("GstDVDecQualityEnum", values);
129 }
130 return qtype;
131 }
132
133 #define gst_dvdec_parent_class parent_class
134 G_DEFINE_TYPE (GstDVDec, gst_dvdec, GST_TYPE_ELEMENT);
135 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (dvdec, "dvdec", GST_RANK_MARGINAL,
136 GST_TYPE_DVDEC, dv_element_init (plugin));
137
138 static GstFlowReturn gst_dvdec_chain (GstPad * pad, GstObject * parent,
139 GstBuffer * buffer);
140 static gboolean gst_dvdec_sink_event (GstPad * pad, GstObject * parent,
141 GstEvent * event);
142
143 static GstStateChangeReturn gst_dvdec_change_state (GstElement * element,
144 GstStateChange transition);
145
146 static void gst_dvdec_set_property (GObject * object, guint prop_id,
147 const GValue * value, GParamSpec * pspec);
148 static void gst_dvdec_get_property (GObject * object, guint prop_id,
149 GValue * value, GParamSpec * pspec);
150
151 static void
gst_dvdec_class_init(GstDVDecClass * klass)152 gst_dvdec_class_init (GstDVDecClass * klass)
153 {
154 GObjectClass *gobject_class;
155 GstElementClass *gstelement_class;
156
157 gobject_class = (GObjectClass *) klass;
158 gstelement_class = (GstElementClass *) klass;
159
160 gobject_class->set_property = gst_dvdec_set_property;
161 gobject_class->get_property = gst_dvdec_get_property;
162
163 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CLAMP_LUMA,
164 g_param_spec_boolean ("clamp-luma", "Clamp luma", "Clamp luma",
165 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
166 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CLAMP_CHROMA,
167 g_param_spec_boolean ("clamp-chroma", "Clamp chroma", "Clamp chroma",
168 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
169 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_QUALITY,
170 g_param_spec_enum ("quality", "Quality", "Decoding quality",
171 GST_TYPE_DVDEC_QUALITY, DV_DEFAULT_QUALITY,
172 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
173 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DECODE_NTH,
174 g_param_spec_int ("drop-factor", "Drop Factor", "Only decode Nth frame",
175 1, G_MAXINT, DV_DEFAULT_DECODE_NTH,
176 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
177
178 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_dvdec_change_state);
179
180 gst_element_class_add_static_pad_template (gstelement_class, &sink_temp);
181 gst_element_class_add_static_pad_template (gstelement_class, &src_temp);
182
183 gst_element_class_set_static_metadata (gstelement_class, "DV video decoder",
184 "Codec/Decoder/Video",
185 "Uses libdv to decode DV video (smpte314) (libdv.sourceforge.net)",
186 "Erik Walthinsen <omega@cse.ogi.edu>," "Wim Taymans <wim@fluendo.com>");
187
188 GST_DEBUG_CATEGORY_INIT (dvdec_debug, "dvdec", 0, "DV decoding element");
189
190 gst_type_mark_as_plugin_api (GST_TYPE_DVDEC_QUALITY, 0);
191 }
192
193 static void
gst_dvdec_init(GstDVDec * dvdec)194 gst_dvdec_init (GstDVDec * dvdec)
195 {
196 dvdec->sinkpad = gst_pad_new_from_static_template (&sink_temp, "sink");
197 gst_pad_set_chain_function (dvdec->sinkpad, gst_dvdec_chain);
198 gst_pad_set_event_function (dvdec->sinkpad, gst_dvdec_sink_event);
199 gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad);
200
201 dvdec->srcpad = gst_pad_new_from_static_template (&src_temp, "src");
202 gst_pad_use_fixed_caps (dvdec->srcpad);
203 gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->srcpad);
204
205 dvdec->framerate_numerator = 0;
206 dvdec->framerate_denominator = 0;
207 dvdec->wide = FALSE;
208 dvdec->drop_factor = 1;
209
210 dvdec->clamp_luma = FALSE;
211 dvdec->clamp_chroma = FALSE;
212 dvdec->quality = DV_DEFAULT_QUALITY;
213 }
214
215 static gboolean
gst_dvdec_sink_setcaps(GstDVDec * dvdec,GstCaps * caps)216 gst_dvdec_sink_setcaps (GstDVDec * dvdec, GstCaps * caps)
217 {
218 GstStructure *s;
219 const GValue *par = NULL, *rate = NULL;
220
221 /* first parse the caps */
222 s = gst_caps_get_structure (caps, 0);
223
224 /* we allow framerate and PAR to be overwritten. framerate is mandatory. */
225 if (!(rate = gst_structure_get_value (s, "framerate")))
226 goto no_framerate;
227 par = gst_structure_get_value (s, "pixel-aspect-ratio");
228
229 if (par) {
230 dvdec->par_x = gst_value_get_fraction_numerator (par);
231 dvdec->par_y = gst_value_get_fraction_denominator (par);
232 dvdec->need_par = FALSE;
233 } else {
234 dvdec->par_x = 0;
235 dvdec->par_y = 0;
236 dvdec->need_par = TRUE;
237 }
238 dvdec->framerate_numerator = gst_value_get_fraction_numerator (rate);
239 dvdec->framerate_denominator = gst_value_get_fraction_denominator (rate);
240 dvdec->sink_negotiated = TRUE;
241 dvdec->src_negotiated = FALSE;
242
243 return TRUE;
244
245 /* ERRORS */
246 no_framerate:
247 {
248 GST_DEBUG_OBJECT (dvdec, "no framerate specified in caps");
249 return FALSE;
250 }
251 }
252
253 static void
gst_dvdec_negotiate_pool(GstDVDec * dec,GstCaps * caps,GstVideoInfo * info)254 gst_dvdec_negotiate_pool (GstDVDec * dec, GstCaps * caps, GstVideoInfo * info)
255 {
256 GstQuery *query;
257 GstBufferPool *pool;
258 guint size, min, max;
259 GstStructure *config;
260
261 /* find a pool for the negotiated caps now */
262 query = gst_query_new_allocation (caps, TRUE);
263
264 if (!gst_pad_peer_query (dec->srcpad, query)) {
265 GST_DEBUG_OBJECT (dec, "didn't get downstream ALLOCATION hints");
266 }
267
268 if (gst_query_get_n_allocation_pools (query) > 0) {
269 /* we got configuration from our peer, parse them */
270 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
271 size = MAX (size, info->size);
272 } else {
273 pool = NULL;
274 size = info->size;
275 min = max = 0;
276 }
277
278 if (pool == NULL) {
279 /* we did not get a pool, make one ourselves then */
280 pool = gst_video_buffer_pool_new ();
281 }
282
283 if (dec->pool) {
284 gst_buffer_pool_set_active (dec->pool, FALSE);
285 gst_object_unref (dec->pool);
286 }
287 dec->pool = pool;
288
289 config = gst_buffer_pool_get_config (pool);
290 gst_buffer_pool_config_set_params (config, caps, size, min, max);
291
292 if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
293 /* just set the option, if the pool can support it we will transparently use
294 * it through the video info API. We could also see if the pool support this
295 * option and only activate it then. */
296 gst_buffer_pool_config_add_option (config,
297 GST_BUFFER_POOL_OPTION_VIDEO_META);
298 }
299 gst_buffer_pool_set_config (pool, config);
300
301 /* and activate */
302 gst_buffer_pool_set_active (pool, TRUE);
303
304 gst_query_unref (query);
305 }
306
307 static gboolean
gst_dvdec_src_negotiate(GstDVDec * dvdec)308 gst_dvdec_src_negotiate (GstDVDec * dvdec)
309 {
310 GstCaps *othercaps;
311 gboolean ret;
312
313 /* no PAR was specified in input, derive from encoded data */
314 if (dvdec->need_par) {
315 if (dvdec->PAL) {
316 if (dvdec->wide) {
317 dvdec->par_x = PAL_WIDE_PAR_X;
318 dvdec->par_y = PAL_WIDE_PAR_Y;
319 } else {
320 dvdec->par_x = PAL_NORMAL_PAR_X;
321 dvdec->par_y = PAL_NORMAL_PAR_Y;
322 }
323 } else {
324 if (dvdec->wide) {
325 dvdec->par_x = NTSC_WIDE_PAR_X;
326 dvdec->par_y = NTSC_WIDE_PAR_Y;
327 } else {
328 dvdec->par_x = NTSC_NORMAL_PAR_X;
329 dvdec->par_y = NTSC_NORMAL_PAR_Y;
330 }
331 }
332 GST_DEBUG_OBJECT (dvdec, "Inferred PAR %d/%d from video format",
333 dvdec->par_x, dvdec->par_y);
334 }
335
336 /* ignoring rgb, bgr0 for now */
337 dvdec->bpp = 2;
338
339 gst_video_info_set_format (&dvdec->vinfo, GST_VIDEO_FORMAT_YUY2,
340 720, dvdec->height);
341 dvdec->vinfo.fps_n = dvdec->framerate_numerator;
342 dvdec->vinfo.fps_d = dvdec->framerate_denominator;
343 dvdec->vinfo.par_n = dvdec->par_x;
344 dvdec->vinfo.par_d = dvdec->par_y;
345 if (dvdec->interlaced) {
346 dvdec->vinfo.interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
347 } else {
348 dvdec->vinfo.interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
349 }
350
351 othercaps = gst_video_info_to_caps (&dvdec->vinfo);
352 ret = gst_pad_set_caps (dvdec->srcpad, othercaps);
353
354 gst_dvdec_negotiate_pool (dvdec, othercaps, &dvdec->vinfo);
355 gst_caps_unref (othercaps);
356
357 dvdec->src_negotiated = TRUE;
358
359 return ret;
360 }
361
362 static gboolean
gst_dvdec_sink_event(GstPad * pad,GstObject * parent,GstEvent * event)363 gst_dvdec_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
364 {
365 GstDVDec *dvdec;
366 gboolean res = TRUE;
367
368 dvdec = GST_DVDEC (parent);
369
370 switch (GST_EVENT_TYPE (event)) {
371 case GST_EVENT_FLUSH_STOP:
372 gst_segment_init (&dvdec->segment, GST_FORMAT_UNDEFINED);
373 dvdec->need_segment = FALSE;
374 break;
375 case GST_EVENT_SEGMENT:{
376 const GstSegment *segment;
377
378 gst_event_parse_segment (event, &segment);
379
380 GST_DEBUG_OBJECT (dvdec, "Got SEGMENT %" GST_SEGMENT_FORMAT, &segment);
381
382 gst_segment_copy_into (segment, &dvdec->segment);
383 if (!gst_pad_has_current_caps (dvdec->srcpad)) {
384 dvdec->need_segment = TRUE;
385 gst_event_unref (event);
386 event = NULL;
387 res = TRUE;
388 } else {
389 dvdec->need_segment = FALSE;
390 }
391 break;
392 }
393 case GST_EVENT_CAPS:
394 {
395 GstCaps *caps;
396
397 gst_event_parse_caps (event, &caps);
398 res = gst_dvdec_sink_setcaps (dvdec, caps);
399 gst_event_unref (event);
400 event = NULL;
401 break;
402 }
403
404 default:
405 break;
406 }
407
408 if (event)
409 res = gst_pad_push_event (dvdec->srcpad, event);
410
411 return res;
412 }
413
414 static GstFlowReturn
gst_dvdec_chain(GstPad * pad,GstObject * parent,GstBuffer * buf)415 gst_dvdec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
416 {
417 GstDVDec *dvdec;
418 guint8 *inframe;
419 guint8 *outframe_ptrs[3];
420 gint outframe_pitches[3];
421 GstMapInfo map;
422 GstVideoFrame frame;
423 GstBuffer *outbuf;
424 GstFlowReturn ret = GST_FLOW_OK;
425 guint length;
426 guint64 cstart = GST_CLOCK_TIME_NONE, cstop = GST_CLOCK_TIME_NONE;
427 gboolean PAL, wide;
428
429 dvdec = GST_DVDEC (parent);
430
431 gst_buffer_map (buf, &map, GST_MAP_READ);
432 inframe = map.data;
433
434 /* buffer should be at least the size of one NTSC frame, this should
435 * be enough to decode the header. */
436 if (G_UNLIKELY (map.size < NTSC_BUFFER))
437 goto wrong_size;
438
439 /* preliminary dropping. unref and return if outside of configured segment */
440 if ((dvdec->segment.format == GST_FORMAT_TIME) &&
441 (!(gst_segment_clip (&dvdec->segment, GST_FORMAT_TIME,
442 GST_BUFFER_TIMESTAMP (buf),
443 GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf),
444 &cstart, &cstop))))
445 goto dropping;
446
447 if (G_UNLIKELY (dv_parse_header (dvdec->decoder, inframe) < 0))
448 goto parse_header_error;
449
450 /* get size */
451 PAL = dv_system_50_fields (dvdec->decoder);
452 wide = dv_format_wide (dvdec->decoder);
453
454 /* check the buffer is of right size after we know if we are
455 * dealing with PAL or NTSC */
456 length = (PAL ? PAL_BUFFER : NTSC_BUFFER);
457 if (G_UNLIKELY (map.size < length))
458 goto wrong_size;
459
460 dv_parse_packs (dvdec->decoder, inframe);
461
462 if (dvdec->video_offset % dvdec->drop_factor != 0)
463 goto skip;
464
465 /* renegotiate on change */
466 if (PAL != dvdec->PAL || wide != dvdec->wide) {
467 dvdec->src_negotiated = FALSE;
468 dvdec->PAL = PAL;
469 dvdec->wide = wide;
470 }
471
472 dvdec->height = (dvdec->PAL ? PAL_HEIGHT : NTSC_HEIGHT);
473
474 dvdec->interlaced = !dv_is_progressive (dvdec->decoder);
475
476 /* negotiate if not done yet */
477 if (!dvdec->src_negotiated) {
478 if (!gst_dvdec_src_negotiate (dvdec))
479 goto not_negotiated;
480 }
481
482 if (gst_pad_check_reconfigure (dvdec->srcpad)) {
483 GstCaps *caps;
484
485 caps = gst_pad_get_current_caps (dvdec->srcpad);
486 if (!caps)
487 goto flushing;
488
489 gst_dvdec_negotiate_pool (dvdec, caps, &dvdec->vinfo);
490 gst_caps_unref (caps);
491 }
492
493 if (dvdec->need_segment) {
494 gst_pad_push_event (dvdec->srcpad, gst_event_new_segment (&dvdec->segment));
495 dvdec->need_segment = FALSE;
496 }
497
498 ret = gst_buffer_pool_acquire_buffer (dvdec->pool, &outbuf, NULL);
499 if (G_UNLIKELY (ret != GST_FLOW_OK))
500 goto no_buffer;
501
502 gst_video_frame_map (&frame, &dvdec->vinfo, outbuf, GST_MAP_WRITE);
503
504 outframe_ptrs[0] = GST_VIDEO_FRAME_COMP_DATA (&frame, 0);
505 outframe_pitches[0] = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 0);
506
507 /* the rest only matters for YUY2 */
508 if (dvdec->bpp < 3) {
509 outframe_ptrs[1] = GST_VIDEO_FRAME_COMP_DATA (&frame, 1);
510 outframe_ptrs[2] = GST_VIDEO_FRAME_COMP_DATA (&frame, 2);
511
512 outframe_pitches[1] = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 1);
513 outframe_pitches[2] = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 2);
514 }
515
516 GST_DEBUG_OBJECT (dvdec, "decoding and pushing buffer");
517 dv_decode_full_frame (dvdec->decoder, inframe,
518 e_dv_color_yuv, outframe_ptrs, outframe_pitches);
519
520 gst_video_frame_unmap (&frame);
521
522 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
523
524 GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buf);
525 GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET_END (buf);
526
527 /* FIXME : Compute values when using non-TIME segments,
528 * but for the moment make sure we at least don't set bogus values
529 */
530 if (GST_CLOCK_TIME_IS_VALID (cstart)) {
531 GST_BUFFER_TIMESTAMP (outbuf) = cstart;
532 if (GST_CLOCK_TIME_IS_VALID (cstop))
533 GST_BUFFER_DURATION (outbuf) = cstop - cstart;
534 }
535
536 ret = gst_pad_push (dvdec->srcpad, outbuf);
537
538 skip:
539 dvdec->video_offset++;
540
541 done:
542 gst_buffer_unmap (buf, &map);
543 gst_buffer_unref (buf);
544
545 return ret;
546
547 /* ERRORS */
548 wrong_size:
549 {
550 GST_ELEMENT_ERROR (dvdec, STREAM, DECODE,
551 (NULL), ("Input buffer too small"));
552 ret = GST_FLOW_ERROR;
553 goto done;
554 }
555 parse_header_error:
556 {
557 GST_ELEMENT_ERROR (dvdec, STREAM, DECODE,
558 (NULL), ("Error parsing DV header"));
559 ret = GST_FLOW_ERROR;
560 goto done;
561 }
562 not_negotiated:
563 {
564 GST_DEBUG_OBJECT (dvdec, "could not negotiate output");
565 if (GST_PAD_IS_FLUSHING (dvdec->srcpad))
566 ret = GST_FLOW_FLUSHING;
567 else
568 ret = GST_FLOW_NOT_NEGOTIATED;
569 goto done;
570 }
571 flushing:
572 {
573 GST_DEBUG_OBJECT (dvdec, "have no current caps");
574 ret = GST_FLOW_FLUSHING;
575 goto done;
576 }
577 no_buffer:
578 {
579 GST_DEBUG_OBJECT (dvdec, "could not allocate buffer");
580 goto done;
581 }
582
583 dropping:
584 {
585 GST_DEBUG_OBJECT (dvdec,
586 "dropping buffer since it's out of the configured segment");
587 goto done;
588 }
589 }
590
591 static GstStateChangeReturn
gst_dvdec_change_state(GstElement * element,GstStateChange transition)592 gst_dvdec_change_state (GstElement * element, GstStateChange transition)
593 {
594 GstDVDec *dvdec = GST_DVDEC (element);
595 GstStateChangeReturn ret;
596
597
598 switch (transition) {
599 case GST_STATE_CHANGE_NULL_TO_READY:
600 break;
601 case GST_STATE_CHANGE_READY_TO_PAUSED:
602 dvdec->decoder =
603 dv_decoder_new (0, dvdec->clamp_luma, dvdec->clamp_chroma);
604 dvdec->decoder->quality = qualities[dvdec->quality];
605 dv_set_error_log (dvdec->decoder, NULL);
606 gst_video_info_init (&dvdec->vinfo);
607 gst_segment_init (&dvdec->segment, GST_FORMAT_UNDEFINED);
608 dvdec->src_negotiated = FALSE;
609 dvdec->sink_negotiated = FALSE;
610 dvdec->need_segment = FALSE;
611 /*
612 * Enable this function call when libdv2 0.100 or higher is more
613 * common
614 */
615 /* dv_set_quality (dvdec->decoder, qualities [dvdec->quality]); */
616 break;
617 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
618 break;
619 default:
620 break;
621 }
622
623 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
624
625 switch (transition) {
626 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
627 break;
628 case GST_STATE_CHANGE_PAUSED_TO_READY:
629 dv_decoder_free (dvdec->decoder);
630 dvdec->decoder = NULL;
631 if (dvdec->pool) {
632 gst_buffer_pool_set_active (dvdec->pool, FALSE);
633 gst_object_unref (dvdec->pool);
634 dvdec->pool = NULL;
635 }
636 break;
637 case GST_STATE_CHANGE_READY_TO_NULL:
638 break;
639 default:
640 break;
641 }
642 return ret;
643 }
644
645 static void
gst_dvdec_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)646 gst_dvdec_set_property (GObject * object, guint prop_id, const GValue * value,
647 GParamSpec * pspec)
648 {
649 GstDVDec *dvdec = GST_DVDEC (object);
650
651 switch (prop_id) {
652 case PROP_CLAMP_LUMA:
653 dvdec->clamp_luma = g_value_get_boolean (value);
654 break;
655 case PROP_CLAMP_CHROMA:
656 dvdec->clamp_chroma = g_value_get_boolean (value);
657 break;
658 case PROP_QUALITY:
659 dvdec->quality = g_value_get_enum (value);
660 if ((dvdec->quality < 0) || (dvdec->quality > 5))
661 dvdec->quality = 0;
662 break;
663 case PROP_DECODE_NTH:
664 dvdec->drop_factor = g_value_get_int (value);
665 break;
666 default:
667 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
668 break;
669 }
670 }
671
672 static void
gst_dvdec_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)673 gst_dvdec_get_property (GObject * object, guint prop_id, GValue * value,
674 GParamSpec * pspec)
675 {
676 GstDVDec *dvdec = GST_DVDEC (object);
677
678 switch (prop_id) {
679 case PROP_CLAMP_LUMA:
680 g_value_set_boolean (value, dvdec->clamp_luma);
681 break;
682 case PROP_CLAMP_CHROMA:
683 g_value_set_boolean (value, dvdec->clamp_chroma);
684 break;
685 case PROP_QUALITY:
686 g_value_set_enum (value, dvdec->quality);
687 break;
688 case PROP_DECODE_NTH:
689 g_value_set_int (value, dvdec->drop_factor);
690 break;
691 default:
692 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
693 break;
694 }
695 }
696