2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * <2005> Wim Taymans <wim@fluendo.com>
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.
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.
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.
30 static GstElementDetails dvdec_details =
31 GST_ELEMENT_DETAILS ("DV (smpte314) decoder plugin",
32 "Codec/Decoder/Video",
33 "Uses libdv to decode DV video (libdv.sourceforge.net)",
34 "Erik Walthinsen <omega@cse.ogi.edu>," "Wim Taymans <wim@fluendo.com>");
37 #define DV_DEFAULT_QUALITY DV_QUALITY_BEST
38 #define DV_DEFAULT_DECODE_NTH 1
49 const gint qualities[] = {
53 DV_QUALITY_DC | DV_QUALITY_COLOR,
54 DV_QUALITY_AC_1 | DV_QUALITY_COLOR,
55 DV_QUALITY_AC_2 | DV_QUALITY_COLOR
58 static GstStaticPadTemplate sink_temp = GST_STATIC_PAD_TEMPLATE ("sink",
61 GST_STATIC_CAPS ("video/x-dv, systemstream = (boolean) false")
64 static GstStaticPadTemplate src_temp = GST_STATIC_PAD_TEMPLATE ("src",
67 GST_STATIC_CAPS ("video/x-raw-yuv, "
68 "format = (fourcc) YUY2, "
70 "framerate = (fraction) [ 1/1, 60/1 ];"
74 "endianness = (int) " G_STRINGIFY (G_BIG_ENDIAN) ", "
75 "red_mask = (int) 0x0000ff00, "
76 "green_mask = (int) 0x00ff0000, "
77 "blue_mask = (int) 0xff000000, "
79 "framerate = (fraction) [ 1/1, 60/1 ];"
83 "endianness = (int) " G_STRINGIFY (G_BIG_ENDIAN) ", "
84 "red_mask = (int) 0x00ff0000, "
85 "green_mask = (int) 0x0000ff00, "
86 "blue_mask = (int) 0x000000ff, "
87 "width = (int) 720, " "framerate = (fraction) [ 1/1, 60/1 ]")
90 #define GST_TYPE_DVDEC_QUALITY (gst_dvdec_quality_get_type())
92 gst_dvdec_quality_get_type (void)
94 static GType qtype = 0;
97 static const GEnumValue values[] = {
98 {0, "DV_QUALITY_FASTEST", "Fastest decoding, low-quality mono"},
99 {1, "DV_QUALITY_AC_1", "Mono decoding using the first AC coefficient"},
100 {2, "DV_QUALITY_AC_2", "Highest quality mono decoding"},
101 {3, "DV_QUALITY_DC|DV_QUALITY_COLOUR", "Fastest colour decoding"},
102 {4, "DV_QUALITY_AC_1|DV_QUALITY_COLOUR",
103 "Colour, using only the first AC coefficient"},
104 {5, "DV_QUALITY_BEST", "Highest quality colour decoding"},
108 qtype = g_enum_register_static ("GstDVDecQualityEnum", values);
113 GST_BOILERPLATE (GstDVDec, gst_dvdec, GstElement, GST_TYPE_ELEMENT);
115 static gboolean gst_dvdec_sink_setcaps (GstPad * pad, GstCaps * caps);
116 static GstFlowReturn gst_dvdec_chain (GstPad * pad, GstBuffer * buffer);
118 static GstStateChangeReturn gst_dvdec_change_state (GstElement * element,
119 GstStateChange transition);
121 static void gst_dvdec_set_property (GObject * object, guint prop_id,
122 const GValue * value, GParamSpec * pspec);
123 static void gst_dvdec_get_property (GObject * object, guint prop_id,
124 GValue * value, GParamSpec * pspec);
127 gst_dvdec_base_init (gpointer g_class)
129 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
131 gst_element_class_add_pad_template (element_class,
132 gst_static_pad_template_get (&sink_temp));
133 gst_element_class_add_pad_template (element_class,
134 gst_static_pad_template_get (&src_temp));
136 gst_element_class_set_details (element_class, &dvdec_details);
140 gst_dvdec_class_init (GstDVDecClass * klass)
142 GObjectClass *gobject_class;
143 GstElementClass *gstelement_class;
145 gobject_class = (GObjectClass *) klass;
146 gstelement_class = (GstElementClass *) klass;
148 gobject_class->set_property = gst_dvdec_set_property;
149 gobject_class->get_property = gst_dvdec_get_property;
151 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CLAMP_LUMA,
152 g_param_spec_boolean ("clamp_luma", "Clamp luma", "Clamp luma",
153 FALSE, G_PARAM_READWRITE));
154 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CLAMP_CHROMA,
155 g_param_spec_boolean ("clamp_chroma", "Clamp chroma", "Clamp chroma",
156 FALSE, G_PARAM_READWRITE));
157 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_QUALITY,
158 g_param_spec_enum ("quality", "Quality", "Decoding quality",
159 GST_TYPE_DVDEC_QUALITY, DV_DEFAULT_QUALITY, G_PARAM_READWRITE));
160 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_DECODE_NTH,
161 g_param_spec_int ("drop-factor", "Drop Factor", "Only decode Nth frame",
162 1, G_MAXINT, DV_DEFAULT_DECODE_NTH, G_PARAM_READWRITE));
164 gstelement_class->change_state = gst_dvdec_change_state;
166 /* table initialization, only do once */
171 gst_dvdec_init (GstDVDec * dvdec, GstDVDecClass * g_class)
174 gst_pad_new_from_template (gst_static_pad_template_get (&sink_temp),
176 gst_pad_set_setcaps_function (dvdec->sinkpad,
177 GST_DEBUG_FUNCPTR (gst_dvdec_sink_setcaps));
178 gst_pad_set_chain_function (dvdec->sinkpad, gst_dvdec_chain);
179 gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad);
182 gst_pad_new_from_template (gst_static_pad_template_get (&src_temp),
185 gst_pad_use_fixed_caps (dvdec->srcpad);
187 gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->srcpad);
189 dvdec->framerate_numerator = 0;
190 dvdec->framerate_denominator = 0;
193 dvdec->drop_factor = 1;
194 dvdec->headers_seen = FALSE;
196 dvdec->clamp_luma = FALSE;
197 dvdec->clamp_chroma = FALSE;
198 dvdec->quality = DV_DEFAULT_QUALITY;
202 gst_dvdec_sink_setcaps (GstPad * pad, GstCaps * caps)
207 const GValue *par, *rate;
209 dvdec = GST_DVDEC (gst_pad_get_parent (pad));
211 /* first parse the caps */
212 s = gst_caps_get_structure (caps, 0);
214 if (!gst_structure_get_int (s, "height", &dvdec->height))
216 if (!(par = gst_structure_get_value (s, "pixel-aspect-ratio")))
218 if (!(rate = gst_structure_get_value (s, "framerate")))
221 dvdec->framerate_numerator = gst_value_get_fraction_numerator (rate);
222 dvdec->framerate_denominator = gst_value_get_fraction_denominator (rate);
224 /* ignoring rgb, bgr0 for now */
228 othercaps = gst_caps_new_simple ("video/x-raw-yuv",
229 "format", GST_TYPE_FOURCC, GST_STR_FOURCC ("YUY2"),
230 "width", G_TYPE_INT, 720,
231 "height", G_TYPE_INT, dvdec->height,
232 "framerate", GST_TYPE_FRACTION, dvdec->framerate_numerator,
233 dvdec->framerate_denominator, NULL);
234 gst_structure_set_value (gst_caps_get_structure (othercaps, 0),
235 "pixel-aspect-ratio", par);
237 gst_pad_set_caps (dvdec->srcpad, othercaps);
239 gst_caps_unref (othercaps);
241 gst_object_unref (dvdec);
247 gst_object_unref (dvdec);
254 gst_dvdec_chain (GstPad * pad, GstBuffer * buf)
259 guint8 *outframe_ptrs[3];
260 gint outframe_pitches[3];
262 GstFlowReturn ret = GST_FLOW_OK;
264 dvdec = GST_DVDEC (gst_pad_get_parent (pad));
265 inframe = GST_BUFFER_DATA (buf);
267 if (dv_parse_header (dvdec->decoder, inframe) < 0)
268 g_assert_not_reached ();
269 dv_parse_packs (dvdec->decoder, inframe);
271 if (dvdec->video_offset % dvdec->drop_factor != 0)
275 gst_pad_alloc_buffer (dvdec->srcpad, 0,
276 (720 * dvdec->height) * dvdec->bpp,
277 GST_PAD_CAPS (dvdec->srcpad), &outbuf);
278 if (ret != GST_FLOW_OK)
281 outframe = GST_BUFFER_DATA (outbuf);
283 outframe_ptrs[0] = outframe;
284 outframe_pitches[0] = 720 * dvdec->bpp;
286 /* the rest only matters for YUY2 */
287 if (dvdec->bpp < 3) {
288 outframe_ptrs[1] = outframe_ptrs[0] + 720 * dvdec->height;
289 outframe_ptrs[2] = outframe_ptrs[1] + 360 * dvdec->height;
291 outframe_pitches[1] = dvdec->height / 2;
292 outframe_pitches[2] = outframe_pitches[1];
295 dv_decode_full_frame (dvdec->decoder, inframe,
296 e_dv_color_yuv, outframe_ptrs, outframe_pitches);
298 gst_buffer_stamp (outbuf, buf);
300 ret = gst_pad_push (dvdec->srcpad, outbuf);
303 gst_buffer_unref (buf);
304 dvdec->video_offset++;
305 gst_object_unref (dvdec);
312 gst_buffer_unref (buf);
313 gst_object_unref (dvdec);
318 static GstStateChangeReturn
319 gst_dvdec_change_state (GstElement * element, GstStateChange transition)
321 GstDVDec *dvdec = GST_DVDEC (element);
322 GstStateChangeReturn ret;
325 switch (transition) {
326 case GST_STATE_CHANGE_NULL_TO_READY:
328 case GST_STATE_CHANGE_READY_TO_PAUSED:
330 dv_decoder_new (0, dvdec->clamp_luma, dvdec->clamp_chroma);
331 dvdec->decoder->quality = qualities[dvdec->quality];
333 * Enable this function call when libdv2 0.100 or higher is more
336 /* dv_set_quality (dvdec->decoder, qualities [dvdec->quality]); */
338 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
344 ret = parent_class->change_state (element, transition);
346 switch (transition) {
347 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
349 case GST_STATE_CHANGE_PAUSED_TO_READY:
350 dv_decoder_free (dvdec->decoder);
351 dvdec->decoder = NULL;
352 dvdec->headers_seen = FALSE;
354 case GST_STATE_CHANGE_READY_TO_NULL:
363 gst_dvdec_set_property (GObject * object, guint prop_id, const GValue * value,
366 GstDVDec *dvdec = GST_DVDEC (object);
369 case PROP_CLAMP_LUMA:
370 dvdec->clamp_luma = g_value_get_boolean (value);
372 case PROP_CLAMP_CHROMA:
373 dvdec->clamp_chroma = g_value_get_boolean (value);
376 dvdec->quality = g_value_get_enum (value);
377 if ((dvdec->quality < 0) || (dvdec->quality > 5))
380 case PROP_DECODE_NTH:
381 dvdec->drop_factor = g_value_get_int (value);
384 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
390 gst_dvdec_get_property (GObject * object, guint prop_id, GValue * value,
393 GstDVDec *dvdec = GST_DVDEC (object);
396 case PROP_CLAMP_LUMA:
397 g_value_set_boolean (value, dvdec->clamp_luma);
399 case PROP_CLAMP_CHROMA:
400 g_value_set_boolean (value, dvdec->clamp_chroma);
403 g_value_set_enum (value, dvdec->quality);
405 case PROP_DECODE_NTH:
406 g_value_set_int (value, dvdec->drop_factor);
409 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);