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