3cadcd99247684bf159eb95ef4177bfb28e080f2
[platform/upstream/gstreamer.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., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, 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 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/gstvideopool.h>
48
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        59
63 #define PAL_NORMAL_PAR_Y        54
64 #define PAL_WIDE_PAR_X          118
65 #define PAL_WIDE_PAR_Y          81
66
67 #define NTSC_NORMAL_PAR_X       10
68 #define NTSC_NORMAL_PAR_Y       11
69 #define NTSC_WIDE_PAR_X         40
70 #define NTSC_WIDE_PAR_Y         33
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
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
136 static GstFlowReturn gst_dvdec_chain (GstPad * pad, GstObject * parent,
137     GstBuffer * buffer);
138 static gboolean gst_dvdec_sink_event (GstPad * pad, GstObject * parent,
139     GstEvent * event);
140
141 static GstStateChangeReturn gst_dvdec_change_state (GstElement * element,
142     GstStateChange transition);
143
144 static void gst_dvdec_set_property (GObject * object, guint prop_id,
145     const GValue * value, GParamSpec * pspec);
146 static void gst_dvdec_get_property (GObject * object, guint prop_id,
147     GValue * value, GParamSpec * pspec);
148
149 static void
150 gst_dvdec_class_init (GstDVDecClass * klass)
151 {
152   GObjectClass *gobject_class;
153   GstElementClass *gstelement_class;
154
155   gobject_class = (GObjectClass *) klass;
156   gstelement_class = (GstElementClass *) klass;
157
158   gobject_class->set_property = gst_dvdec_set_property;
159   gobject_class->get_property = gst_dvdec_get_property;
160
161   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CLAMP_LUMA,
162       g_param_spec_boolean ("clamp-luma", "Clamp luma", "Clamp luma",
163           FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
164   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CLAMP_CHROMA,
165       g_param_spec_boolean ("clamp-chroma", "Clamp chroma", "Clamp chroma",
166           FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
167   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_QUALITY,
168       g_param_spec_enum ("quality", "Quality", "Decoding quality",
169           GST_TYPE_DVDEC_QUALITY, DV_DEFAULT_QUALITY,
170           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
171   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DECODE_NTH,
172       g_param_spec_int ("drop-factor", "Drop Factor", "Only decode Nth frame",
173           1, G_MAXINT, DV_DEFAULT_DECODE_NTH,
174           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
175
176   gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_dvdec_change_state);
177
178   gst_element_class_add_pad_template (gstelement_class,
179       gst_static_pad_template_get (&sink_temp));
180   gst_element_class_add_pad_template (gstelement_class,
181       gst_static_pad_template_get (&src_temp));
182
183   gst_element_class_set_details_simple (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
191 static void
192 gst_dvdec_init (GstDVDec * dvdec)
193 {
194   dvdec->sinkpad = gst_pad_new_from_static_template (&sink_temp, "sink");
195   gst_pad_set_chain_function (dvdec->sinkpad, gst_dvdec_chain);
196   gst_pad_set_event_function (dvdec->sinkpad, gst_dvdec_sink_event);
197   gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad);
198
199   dvdec->srcpad = gst_pad_new_from_static_template (&src_temp, "src");
200   gst_pad_use_fixed_caps (dvdec->srcpad);
201   gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->srcpad);
202
203   dvdec->framerate_numerator = 0;
204   dvdec->framerate_denominator = 0;
205   dvdec->wide = FALSE;
206   dvdec->drop_factor = 1;
207
208   dvdec->clamp_luma = FALSE;
209   dvdec->clamp_chroma = FALSE;
210   dvdec->quality = DV_DEFAULT_QUALITY;
211 }
212
213 static gboolean
214 gst_dvdec_sink_setcaps (GstDVDec * dvdec, GstCaps * caps)
215 {
216   GstStructure *s;
217   const GValue *par = NULL, *rate = NULL;
218
219   /* first parse the caps */
220   s = gst_caps_get_structure (caps, 0);
221
222   /* we allow framerate and PAR to be overwritten. framerate is mandatory. */
223   if (!(rate = gst_structure_get_value (s, "framerate")))
224     goto no_framerate;
225   par = gst_structure_get_value (s, "pixel-aspect-ratio");
226
227   if (par) {
228     dvdec->par_x = gst_value_get_fraction_numerator (par);
229     dvdec->par_y = gst_value_get_fraction_denominator (par);
230     dvdec->need_par = FALSE;
231   } else {
232     dvdec->par_x = 0;
233     dvdec->par_y = 0;
234     dvdec->need_par = TRUE;
235   }
236   dvdec->framerate_numerator = gst_value_get_fraction_numerator (rate);
237   dvdec->framerate_denominator = gst_value_get_fraction_denominator (rate);
238   dvdec->sink_negotiated = TRUE;
239   dvdec->src_negotiated = FALSE;
240
241   return TRUE;
242
243   /* ERRORS */
244 no_framerate:
245   {
246     GST_DEBUG_OBJECT (dvdec, "no framerate specified in caps");
247     return FALSE;
248   }
249 }
250
251 static void
252 gst_dvdec_negotiate_pool (GstDVDec * dec, GstCaps * caps, GstVideoInfo * info)
253 {
254   GstQuery *query;
255   GstBufferPool *pool = NULL;
256   guint size, min, max, prefix, padding, alignment;
257   GstStructure *config;
258
259   /* find a pool for the negotiated caps now */
260   query = gst_query_new_allocation (caps, TRUE);
261
262   if (gst_pad_peer_query (dec->srcpad, query)) {
263     GST_DEBUG_OBJECT (dec, "got downstream ALLOCATION hints");
264     /* we got configuration from our peer, parse them */
265     gst_query_parse_allocation_params (query, &size, &min, &max, &prefix,
266         &padding, &alignment, &pool);
267     size = MAX (size, info->size);
268   } else {
269     GST_DEBUG_OBJECT (dec, "didn't get downstream ALLOCATION hints");
270     size = info->size;
271     min = max = 0;
272     prefix = 0;
273     padding = 0;
274     alignment = 0;
275   }
276
277   if (pool == NULL) {
278     /* we did not get a pool, make one ourselves then */
279     pool = gst_buffer_pool_new ();
280   }
281
282   if (dec->pool)
283     gst_object_unref (dec->pool);
284   dec->pool = pool;
285
286   config = gst_buffer_pool_get_config (pool);
287   gst_buffer_pool_config_set (config, caps, size, min, max, prefix, padding,
288       alignment);
289   /* just set the option, if the pool can support it we will transparently use
290    * it through the video info API. We could also see if the pool support this
291    * option and only activate it then. */
292   gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
293
294   gst_buffer_pool_set_config (pool, config);
295   /* and activate */
296   gst_buffer_pool_set_active (pool, TRUE);
297
298   gst_query_unref (query);
299 }
300
301 static gboolean
302 gst_dvdec_src_negotiate (GstDVDec * dvdec)
303 {
304   GstCaps *othercaps;
305
306   /* no PAR was specified in input, derive from encoded data */
307   if (dvdec->need_par) {
308     if (dvdec->PAL) {
309       if (dvdec->wide) {
310         dvdec->par_x = PAL_WIDE_PAR_X;
311         dvdec->par_y = PAL_WIDE_PAR_Y;
312       } else {
313         dvdec->par_x = PAL_NORMAL_PAR_X;
314         dvdec->par_y = PAL_NORMAL_PAR_Y;
315       }
316     } else {
317       if (dvdec->wide) {
318         dvdec->par_x = NTSC_WIDE_PAR_X;
319         dvdec->par_y = NTSC_WIDE_PAR_Y;
320       } else {
321         dvdec->par_x = NTSC_NORMAL_PAR_X;
322         dvdec->par_y = NTSC_NORMAL_PAR_Y;
323       }
324     }
325     GST_DEBUG_OBJECT (dvdec, "Inferred PAR %d/%d from video format",
326         dvdec->par_x, dvdec->par_y);
327   }
328
329   /* ignoring rgb, bgr0 for now */
330   dvdec->bpp = 2;
331
332   gst_video_info_set_format (&dvdec->vinfo, GST_VIDEO_FORMAT_YUY2,
333       720, dvdec->height);
334   dvdec->vinfo.fps_n = dvdec->framerate_numerator;
335   dvdec->vinfo.fps_d = dvdec->framerate_denominator;
336   dvdec->vinfo.par_n = dvdec->par_x;
337   dvdec->vinfo.par_d = dvdec->par_y;
338   if (dvdec->interlaced) {
339     dvdec->vinfo.interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
340     dvdec->vinfo.flags |= GST_VIDEO_FLAG_INTERLACED;
341   } else {
342     dvdec->vinfo.interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
343     dvdec->vinfo.flags &= GST_VIDEO_FLAG_INTERLACED;
344   }
345
346   othercaps = gst_video_info_to_caps (&dvdec->vinfo);
347   gst_pad_set_caps (dvdec->srcpad, othercaps);
348
349   gst_dvdec_negotiate_pool (dvdec, othercaps, &dvdec->vinfo);
350   gst_caps_unref (othercaps);
351
352   dvdec->src_negotiated = TRUE;
353
354   return TRUE;
355 }
356
357 static gboolean
358 gst_dvdec_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
359 {
360   GstDVDec *dvdec;
361   gboolean res = TRUE;
362
363   dvdec = GST_DVDEC (parent);
364
365   switch (GST_EVENT_TYPE (event)) {
366     case GST_EVENT_FLUSH_STOP:
367       gst_segment_init (&dvdec->segment, GST_FORMAT_UNDEFINED);
368       break;
369     case GST_EVENT_SEGMENT:{
370       const GstSegment *segment;
371
372       gst_event_parse_segment (event, &segment);
373
374       GST_DEBUG_OBJECT (dvdec, "Got NEWSEGMENT %" GST_SEGMENT_FORMAT, &segment);
375
376       gst_segment_copy_into (segment, &dvdec->segment);
377       break;
378     }
379     case GST_EVENT_CAPS:
380     {
381       GstCaps *caps;
382
383       gst_event_parse_caps (event, &caps);
384       gst_dvdec_sink_setcaps (dvdec, caps);
385       gst_event_unref (event);
386       event = NULL;
387       res = TRUE;
388       break;
389     }
390
391     default:
392       break;
393   }
394
395   if (event)
396     res = gst_pad_push_event (dvdec->srcpad, event);
397
398   return res;
399 }
400
401 static GstFlowReturn
402 gst_dvdec_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
403 {
404   GstDVDec *dvdec;
405   guint8 *inframe;
406   guint8 *outframe_ptrs[3];
407   gint outframe_pitches[3];
408   GstMapInfo map;
409   GstVideoFrame frame;
410   GstBuffer *outbuf;
411   GstFlowReturn ret = GST_FLOW_OK;
412   guint length;
413   guint64 cstart, cstop;
414   gboolean PAL, wide;
415
416   dvdec = GST_DVDEC (parent);
417
418   gst_buffer_map (buf, &map, GST_MAP_READ);
419   inframe = map.data;
420
421   /* buffer should be at least the size of one NTSC frame, this should
422    * be enough to decode the header. */
423   if (G_UNLIKELY (map.size < NTSC_BUFFER))
424     goto wrong_size;
425
426   /* preliminary dropping. unref and return if outside of configured segment */
427   if ((dvdec->segment.format == GST_FORMAT_TIME) &&
428       (!(gst_segment_clip (&dvdec->segment, GST_FORMAT_TIME,
429                   GST_BUFFER_TIMESTAMP (buf),
430                   GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf),
431                   &cstart, &cstop))))
432     goto dropping;
433
434   if (G_UNLIKELY (dv_parse_header (dvdec->decoder, inframe) < 0))
435     goto parse_header_error;
436
437   /* get size */
438   PAL = dv_system_50_fields (dvdec->decoder);
439   wide = dv_format_wide (dvdec->decoder);
440
441   /* check the buffer is of right size after we know if we are
442    * dealing with PAL or NTSC */
443   length = (PAL ? PAL_BUFFER : NTSC_BUFFER);
444   if (G_UNLIKELY (map.size < length))
445     goto wrong_size;
446
447   dv_parse_packs (dvdec->decoder, inframe);
448
449   if (dvdec->video_offset % dvdec->drop_factor != 0)
450     goto skip;
451
452   /* renegotiate on change */
453   if (PAL != dvdec->PAL || wide != dvdec->wide) {
454     dvdec->src_negotiated = FALSE;
455     dvdec->PAL = PAL;
456     dvdec->wide = wide;
457   }
458
459   dvdec->height = (dvdec->PAL ? PAL_HEIGHT : NTSC_HEIGHT);
460
461   dvdec->interlaced = !dv_is_progressive (dvdec->decoder);
462
463   /* negotiate if not done yet */
464   if (!dvdec->src_negotiated) {
465     if (!gst_dvdec_src_negotiate (dvdec))
466       goto not_negotiated;
467   }
468
469   if (gst_pad_check_reconfigure (dvdec->srcpad)) {
470     GstCaps *caps;
471
472     caps = gst_pad_get_current_caps (dvdec->srcpad);
473     gst_dvdec_negotiate_pool (dvdec, caps, &dvdec->vinfo);
474     gst_caps_unref (caps);
475   }
476
477   ret = gst_buffer_pool_acquire_buffer (dvdec->pool, &outbuf, NULL);
478   if (G_UNLIKELY (ret != GST_FLOW_OK))
479     goto no_buffer;
480
481   gst_video_frame_map (&frame, &dvdec->vinfo, outbuf, GST_MAP_WRITE);
482
483   outframe_ptrs[0] = GST_VIDEO_FRAME_COMP_DATA (&frame, 0);
484   outframe_pitches[0] = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 0);
485
486   /* the rest only matters for YUY2 */
487   if (dvdec->bpp < 3) {
488     outframe_ptrs[1] = GST_VIDEO_FRAME_COMP_DATA (&frame, 1);
489     outframe_ptrs[2] = GST_VIDEO_FRAME_COMP_DATA (&frame, 2);
490
491     outframe_pitches[1] = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 1);
492     outframe_pitches[2] = GST_VIDEO_FRAME_COMP_STRIDE (&frame, 2);
493   }
494
495   GST_DEBUG_OBJECT (dvdec, "decoding and pushing buffer");
496   dv_decode_full_frame (dvdec->decoder, inframe,
497       e_dv_color_yuv, outframe_ptrs, outframe_pitches);
498
499   gst_video_frame_unmap (&frame);
500
501   GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
502
503   GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buf);
504   GST_BUFFER_OFFSET_END (outbuf) = GST_BUFFER_OFFSET_END (buf);
505   GST_BUFFER_TIMESTAMP (outbuf) = cstart;
506   GST_BUFFER_DURATION (outbuf) = cstop - cstart;
507
508   ret = gst_pad_push (dvdec->srcpad, outbuf);
509
510 skip:
511   dvdec->video_offset++;
512
513 done:
514   gst_buffer_unmap (buf, &map);
515   gst_buffer_unref (buf);
516
517   return ret;
518
519   /* ERRORS */
520 wrong_size:
521   {
522     GST_ELEMENT_ERROR (dvdec, STREAM, DECODE,
523         (NULL), ("Input buffer too small"));
524     ret = GST_FLOW_ERROR;
525     goto done;
526   }
527 parse_header_error:
528   {
529     GST_ELEMENT_ERROR (dvdec, STREAM, DECODE,
530         (NULL), ("Error parsing DV header"));
531     ret = GST_FLOW_ERROR;
532     goto done;
533   }
534 not_negotiated:
535   {
536     GST_DEBUG_OBJECT (dvdec, "could not negotiate output");
537     ret = GST_FLOW_NOT_NEGOTIATED;
538     goto done;
539   }
540 no_buffer:
541   {
542     GST_DEBUG_OBJECT (dvdec, "could not allocate buffer");
543     goto done;
544   }
545
546 dropping:
547   {
548     GST_DEBUG_OBJECT (dvdec,
549         "dropping buffer since it's out of the configured segment");
550     goto done;
551   }
552 }
553
554 static GstStateChangeReturn
555 gst_dvdec_change_state (GstElement * element, GstStateChange transition)
556 {
557   GstDVDec *dvdec = GST_DVDEC (element);
558   GstStateChangeReturn ret;
559
560
561   switch (transition) {
562     case GST_STATE_CHANGE_NULL_TO_READY:
563       break;
564     case GST_STATE_CHANGE_READY_TO_PAUSED:
565       dvdec->decoder =
566           dv_decoder_new (0, dvdec->clamp_luma, dvdec->clamp_chroma);
567       dvdec->decoder->quality = qualities[dvdec->quality];
568       dv_set_error_log (dvdec->decoder, NULL);
569       gst_video_info_init (&dvdec->vinfo);
570       gst_segment_init (&dvdec->segment, GST_FORMAT_UNDEFINED);
571       dvdec->src_negotiated = FALSE;
572       dvdec->sink_negotiated = FALSE;
573       /* 
574        * Enable this function call when libdv2 0.100 or higher is more
575        * common
576        */
577       /* dv_set_quality (dvdec->decoder, qualities [dvdec->quality]); */
578       break;
579     case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
580       break;
581     default:
582       break;
583   }
584
585   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
586
587   switch (transition) {
588     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
589       break;
590     case GST_STATE_CHANGE_PAUSED_TO_READY:
591       dv_decoder_free (dvdec->decoder);
592       dvdec->decoder = NULL;
593       if (dvdec->pool) {
594         gst_buffer_pool_set_active (dvdec->pool, FALSE);
595         gst_object_unref (dvdec->pool);
596         dvdec->pool = NULL;
597       }
598       break;
599     case GST_STATE_CHANGE_READY_TO_NULL:
600       break;
601     default:
602       break;
603   }
604   return ret;
605 }
606
607 static void
608 gst_dvdec_set_property (GObject * object, guint prop_id, const GValue * value,
609     GParamSpec * pspec)
610 {
611   GstDVDec *dvdec = GST_DVDEC (object);
612
613   switch (prop_id) {
614     case PROP_CLAMP_LUMA:
615       dvdec->clamp_luma = g_value_get_boolean (value);
616       break;
617     case PROP_CLAMP_CHROMA:
618       dvdec->clamp_chroma = g_value_get_boolean (value);
619       break;
620     case PROP_QUALITY:
621       dvdec->quality = g_value_get_enum (value);
622       if ((dvdec->quality < 0) || (dvdec->quality > 5))
623         dvdec->quality = 0;
624       break;
625     case PROP_DECODE_NTH:
626       dvdec->drop_factor = g_value_get_int (value);
627       break;
628     default:
629       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
630       break;
631   }
632 }
633
634 static void
635 gst_dvdec_get_property (GObject * object, guint prop_id, GValue * value,
636     GParamSpec * pspec)
637 {
638   GstDVDec *dvdec = GST_DVDEC (object);
639
640   switch (prop_id) {
641     case PROP_CLAMP_LUMA:
642       g_value_set_boolean (value, dvdec->clamp_luma);
643       break;
644     case PROP_CLAMP_CHROMA:
645       g_value_set_boolean (value, dvdec->clamp_chroma);
646       break;
647     case PROP_QUALITY:
648       g_value_set_enum (value, dvdec->quality);
649       break;
650     case PROP_DECODE_NTH:
651       g_value_set_int (value, dvdec->drop_factor);
652       break;
653     default:
654       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
655       break;
656   }
657 }