2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
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.
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.
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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 /* First, include the header file for the plugin, to bring in the
23 * object definition and other useful things.
27 #define NTSC_HEIGHT 480
28 #define NTSC_BUFFER 120000
29 #define PAL_HEIGHT 576
30 #define PAL_BUFFER 144000
32 /* The ElementDetails structure gives a human-readable description
33 * of the plugin, as well as author and version data.
35 static GstElementDetails dvdec_details = {
36 "DV (smpte314) decoder plugin",
38 "Uses libdv to decode DV video (libdv.sourceforge.net)",
40 "Erik Walthinsen <omega@cse.ogi.edu>\n"
41 "Wim Taymans <wim.taymans@tvd.be>",
46 /* These are the signals that this element can fire. They are zero-
47 * based because the numbers themselves are private to the object.
48 * LAST_SIGNAL is used for initialization of the signal array.
55 /* Arguments are identified the same way, but cannot be zero, so you
56 * must leave the ARG_0 entry in as a placeholder.
66 /* The PadFactory structures describe what pads the element has or
67 * can have. They can be quite complex, but for this dvdec plugin
68 * they are rather simple.
70 GST_PAD_TEMPLATE_FACTORY (sink_temp,
77 "format", GST_PROPS_LIST (
78 GST_PROPS_STRING ("PAL"),
79 GST_PROPS_STRING ("NTSC")
85 GST_PAD_TEMPLATE_FACTORY (video_src_temp,
92 "format", GST_PROPS_FOURCC (GST_MAKE_FOURCC ('Y','U','Y','2')),
93 "width", GST_PROPS_INT (720),
94 "height", GST_PROPS_INT_RANGE (NTSC_HEIGHT, PAL_HEIGHT)
99 "format", GST_PROPS_FOURCC(GST_MAKE_FOURCC('R','G','B',' ')),
100 "bpp", GST_PROPS_INT(32),
101 "depth", GST_PROPS_INT(32),
102 "endianness", GST_PROPS_INT (G_LITTLE_ENDIAN),
103 "red_mask", GST_PROPS_INT(0x00ff0000),
104 "green_mask", GST_PROPS_INT(0x0000ff00),
105 "blue_mask", GST_PROPS_INT(0x000000ff),
106 "width", GST_PROPS_INT (720),
107 "height", GST_PROPS_INT_RANGE (NTSC_HEIGHT, PAL_HEIGHT)
112 "format", GST_PROPS_FOURCC(GST_MAKE_FOURCC('R','G','B',' ')),
113 "bpp", GST_PROPS_INT(24),
114 "depth", GST_PROPS_INT(24),
115 "endianness", GST_PROPS_INT (G_LITTLE_ENDIAN),
116 "red_mask", GST_PROPS_INT(0x0000ff),
117 "green_mask", GST_PROPS_INT(0x00ff00),
118 "blue_mask", GST_PROPS_INT(0xff0000),
119 "width", GST_PROPS_INT (720),
120 "height", GST_PROPS_INT_RANGE (NTSC_HEIGHT, PAL_HEIGHT)
124 GST_PAD_TEMPLATE_FACTORY ( audio_src_temp,
131 "format", GST_PROPS_STRING ("int"),
132 "law", GST_PROPS_INT (0),
133 "depth", GST_PROPS_INT (16),
134 "width", GST_PROPS_INT (16),
135 "signed", GST_PROPS_BOOLEAN (TRUE),
136 "channels", GST_PROPS_INT (2),
137 "endianness", GST_PROPS_INT (G_LITTLE_ENDIAN)
143 dv_type_find (GstBuffer *buf, gpointer private)
145 gulong head = GULONG_FROM_BE(*((gulong *)GST_BUFFER_DATA(buf)));
148 /* check for DIF and DV flag */
149 if ((head & 0xffffff00) == 0x1f070000 && !(GST_BUFFER_DATA(buf)[4] & 0x01)) {
152 if ((head & 0x000000ff) & 0x80)
157 new = GST_CAPS_NEW ("dv_type_find",
159 "format", GST_PROPS_STRING (format)
165 static GstTypeDefinition dv_definition = {
166 "dv_video/dv", "video/dv", ".dv", dv_type_find
169 #define GST_TYPE_DVDEC_QUALITY (gst_dvdec_quality_get_type())
171 gst_dvdec_quality_get_type (void)
173 static GType qtype = 0;
175 static const GFlagsValue values[] = {
176 { DV_QUALITY_COLOR, "DV_QUALITY_COLOR", "Color or monochrome decoding" },
177 { DV_QUALITY_AC_1, "DV_QUALITY_AC_1", "AC 1 something" },
178 { DV_QUALITY_AC_2, "DV_QUALITY_AC_2", "AC 2 something" },
181 qtype = g_flags_register_static ("GstDVDecQualityFlags", values);
186 /* A number of functon prototypes are given so we can refer to them later. */
187 static void gst_dvdec_class_init (GstDVDecClass *klass);
188 static void gst_dvdec_init (GstDVDec *dvdec);
190 static const GstPadQueryType*
191 gst_dvdec_get_src_query_types (GstPad *pad);
192 static gboolean gst_dvdec_src_query (GstPad *pad, GstPadQueryType type,
193 GstFormat *format, gint64 *value);
194 static const GstFormat* gst_dvdec_get_formats (GstPad *pad);
195 static gboolean gst_dvdec_sink_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
196 GstFormat *dest_format, gint64 *dest_value);
197 static gboolean gst_dvdec_src_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
198 GstFormat *dest_format, gint64 *dest_value);
200 static const GstEventMask*
201 gst_dvdec_get_event_masks (GstPad *pad);
202 static gboolean gst_dvdec_handle_src_event (GstPad *pad, GstEvent *event);
204 static void gst_dvdec_loop (GstElement *element);
206 static GstElementStateReturn
207 gst_dvdec_change_state (GstElement *element);
209 static void gst_dvdec_set_property (GObject *object, guint prop_id,
210 const GValue *value, GParamSpec *pspec);
211 static void gst_dvdec_get_property (GObject *object, guint prop_id,
212 GValue *value, GParamSpec *pspec);
214 /* The parent class pointer needs to be kept around for some object
217 static GstElementClass *parent_class = NULL;
219 /* This array holds the ids of the signals registered for this object.
220 * The array indexes are based on the enum up above.
222 /*static guint gst_dvdec_signals[LAST_SIGNAL] = { 0 }; */
224 /* This function is used to register and subsequently return the type
225 * identifier for this object class. On first invocation, it will
226 * register the type, providing the name of the class, struct sizes,
227 * and pointers to the various functions that define the class.
230 gst_dvdec_get_type (void)
232 static GType dvdec_type = 0;
235 static const GTypeInfo dvdec_info = {
236 sizeof (GstDVDecClass),
239 (GClassInitFunc) gst_dvdec_class_init,
244 (GInstanceInitFunc) gst_dvdec_init,
246 dvdec_type = g_type_register_static (GST_TYPE_ELEMENT, "GstDVDec", &dvdec_info, 0);
251 /* In order to create an instance of an object, the class must be
252 * initialized by this function. GObject will take care of running
253 * it, based on the pointer to the function provided above.
256 gst_dvdec_class_init (GstDVDecClass *klass)
258 /* Class pointers are needed to supply pointers to the private
259 * implementations of parent class methods.
261 GObjectClass *gobject_class;
262 GstElementClass *gstelement_class;
264 /* Since the dvdec class contains the parent classes, you can simply
265 * cast the pointer to get access to the parent classes.
267 gobject_class = (GObjectClass*) klass;
268 gstelement_class = (GstElementClass*) klass;
270 /* The parent class is needed for class method overrides. */
271 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
273 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CLAMP_LUMA,
274 g_param_spec_boolean ("clamp_luma", "Clamp luma", "Clamp luma",
275 FALSE, G_PARAM_READWRITE));
276 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_CLAMP_CHROMA,
277 g_param_spec_boolean ("clamp_chroma", "Clamp chroma", "Clamp chroma",
278 FALSE, G_PARAM_READWRITE));
279 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_QUALITY,
280 g_param_spec_flags ("quality", "Quality", "Decoding quality",
281 GST_TYPE_DVDEC_QUALITY, DV_QUALITY_BEST, G_PARAM_READWRITE));
283 gobject_class->set_property = gst_dvdec_set_property;
284 gobject_class->get_property = gst_dvdec_get_property;
286 gstelement_class->change_state = gst_dvdec_change_state;
288 /* table initialization, only do once */
292 /* This function is responsible for initializing a specific instance of
296 gst_dvdec_init(GstDVDec *dvdec)
300 dvdec->sinkpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (sink_temp), "sink");
301 gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->sinkpad);
302 gst_pad_set_query_function (dvdec->sinkpad, NULL);
303 gst_pad_set_convert_function (dvdec->sinkpad, GST_DEBUG_FUNCPTR (gst_dvdec_sink_convert));
304 gst_pad_set_formats_function (dvdec->sinkpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_formats));
306 dvdec->videosrcpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET (video_src_temp), "video");
307 gst_element_add_pad (GST_ELEMENT (dvdec), dvdec->videosrcpad);
308 gst_pad_set_query_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_src_query));
309 gst_pad_set_query_type_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_src_query_types));
310 gst_pad_set_event_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_handle_src_event));
311 gst_pad_set_event_mask_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_event_masks));
312 gst_pad_set_convert_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_src_convert));
313 gst_pad_set_formats_function (dvdec->videosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_formats));
315 dvdec->audiosrcpad = gst_pad_new_from_template (GST_PAD_TEMPLATE_GET(audio_src_temp), "audio");
316 gst_element_add_pad(GST_ELEMENT(dvdec),dvdec->audiosrcpad);
317 gst_pad_set_query_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_src_query));
318 gst_pad_set_query_type_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_src_query_types));
319 gst_pad_set_event_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_handle_src_event));
320 gst_pad_set_event_mask_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_event_masks));
321 gst_pad_set_convert_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_src_convert));
322 gst_pad_set_formats_function (dvdec->audiosrcpad, GST_DEBUG_FUNCPTR (gst_dvdec_get_formats));
324 gst_element_set_loop_function (GST_ELEMENT (dvdec), gst_dvdec_loop);
328 dvdec->next_ts = 0LL;
329 dvdec->need_discont = FALSE;
330 dvdec->framerate = 0;
332 dvdec->clamp_luma = FALSE;
333 dvdec->clamp_chroma = FALSE;
334 dvdec->quality = DV_QUALITY_BEST;
336 for (i = 0; i <4; i++) {
337 dvdec->audio_buffers[i] = (gint16 *)g_malloc (DV_AUDIO_MAX_SAMPLES * sizeof (gint16));
341 static const GstFormat*
342 gst_dvdec_get_formats (GstPad *pad)
344 static const GstFormat src_formats[] = {
350 static const GstFormat sink_formats[] = {
356 return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
360 gst_dvdec_src_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
361 GstFormat *dest_format, gint64 *dest_value)
367 dvdec = GST_DVDEC (gst_pad_get_parent (pad));
369 if (dvdec->length == 0)
372 if (dvdec->decoder == NULL)
375 switch (src_format) {
376 case GST_FORMAT_BYTES:
377 switch (*dest_format) {
378 case GST_FORMAT_DEFAULT:
379 *dest_format = GST_FORMAT_TIME;
380 case GST_FORMAT_TIME:
385 case GST_FORMAT_TIME:
386 switch (*dest_format) {
387 case GST_FORMAT_DEFAULT:
388 *dest_format = GST_FORMAT_BYTES;
389 case GST_FORMAT_BYTES:
390 if (pad == dvdec->videosrcpad)
391 scale = 720 * dvdec->height * dvdec->bpp;
392 else if (pad == dvdec->audiosrcpad)
393 scale = dvdec->decoder->audio->num_channels * 2;
395 case GST_FORMAT_UNITS:
396 if (pad == dvdec->videosrcpad)
397 *dest_value = src_value * dvdec->framerate * scale / GST_SECOND;
398 else if (pad == dvdec->audiosrcpad)
399 *dest_value = src_value * dvdec->decoder->audio->frequency * scale / GST_SECOND;
412 gst_dvdec_sink_convert (GstPad *pad, GstFormat src_format, gint64 src_value,
413 GstFormat *dest_format, gint64 *dest_value)
418 dvdec = GST_DVDEC (gst_pad_get_parent (pad));
420 if (dvdec->length == 0)
423 switch (src_format) {
424 case GST_FORMAT_BYTES:
425 switch (*dest_format) {
426 case GST_FORMAT_DEFAULT:
427 *dest_format = GST_FORMAT_TIME;
428 case GST_FORMAT_TIME:
429 *dest_value = src_value * GST_SECOND / (dvdec->length * dvdec->framerate);
435 case GST_FORMAT_TIME:
436 switch (*dest_format) {
437 case GST_FORMAT_DEFAULT:
438 *dest_format = GST_FORMAT_BYTES;
439 case GST_FORMAT_BYTES:
442 /* calculate the frame */
443 frame = src_value * dvdec->framerate / GST_SECOND;
444 /* calculate the offset */
445 *dest_value = frame * dvdec->length;
458 static const GstPadQueryType*
459 gst_dvdec_get_src_query_types (GstPad *pad)
461 static const GstPadQueryType src_query_types[] = {
463 GST_PAD_QUERY_POSITION,
466 return src_query_types;
470 gst_dvdec_src_query (GstPad *pad, GstPadQueryType type,
471 GstFormat *format, gint64 *value)
476 dvdec = GST_DVDEC (gst_pad_get_parent (pad));
479 case GST_PAD_QUERY_TOTAL:
481 case GST_FORMAT_DEFAULT:
482 *format = GST_FORMAT_TIME;
486 GstFormat tmp_format;
488 len = gst_bytestream_length (dvdec->bs);
489 tmp_format = GST_FORMAT_TIME;
490 if (len == -1 || !gst_pad_convert (dvdec->sinkpad,
497 if (!gst_pad_convert (pad, GST_FORMAT_TIME, *value, format, value)) {
504 case GST_PAD_QUERY_POSITION:
506 case GST_FORMAT_DEFAULT:
507 *format = GST_FORMAT_TIME;
509 res = gst_pad_convert (pad, GST_FORMAT_TIME, dvdec->next_ts, format, value);
520 static const GstEventMask*
521 gst_dvdec_get_event_masks (GstPad *pad)
523 static const GstEventMask src_event_masks[] = {
524 { GST_EVENT_SEEK, GST_SEEK_METHOD_SET |
525 GST_SEEK_FLAG_FLUSH },
528 static const GstEventMask sink_event_masks[] = {
529 { GST_EVENT_EOS, 0 },
530 { GST_EVENT_DISCONTINUOUS, 0 },
531 { GST_EVENT_FLUSH, 0 },
535 return (GST_PAD_IS_SRC (pad) ? src_event_masks : sink_event_masks);
539 gst_dvdec_handle_sink_event (GstDVDec *dvdec)
545 gst_bytestream_get_status (dvdec->bs, &remaining, &event);
547 type = event? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
551 gst_pad_event_default (dvdec->sinkpad, event);
553 case GST_EVENT_FLUSH:
555 case GST_EVENT_DISCONTINUOUS:
558 gboolean found = FALSE;
561 format = GST_FORMAT_TIME;
562 /* try to get a timestamp from the discont formats */
563 for (i = 0; i < GST_EVENT_DISCONT_OFFSET_LEN(event); i++) {
564 if (gst_pad_convert (dvdec->sinkpad,
565 GST_EVENT_DISCONT_OFFSET(event,i).format,
566 GST_EVENT_DISCONT_OFFSET(event,i).value,
567 &format, &dvdec->next_ts))
575 dvdec->next_ts = 0LL;
577 dvdec->need_discont = TRUE;
581 g_warning ("unhandled event %d\n", type);
584 gst_event_unref (event);
589 gst_dvdec_handle_src_event (GstPad *pad, GstEvent *event)
594 dvdec = GST_DVDEC (gst_pad_get_parent (pad));
596 switch (GST_EVENT_TYPE (event)) {
602 /* first bring the format to time */
603 format = GST_FORMAT_TIME;
604 if (!gst_pad_convert (pad,
605 GST_EVENT_SEEK_FORMAT (event),
606 GST_EVENT_SEEK_OFFSET (event),
609 /* could not convert seek format to byte offset */
613 /* then try to figure out the byteoffset for this time */
614 format = GST_FORMAT_BYTES;
615 if (!gst_pad_convert (dvdec->sinkpad, GST_FORMAT_TIME, position,
618 /* could not convert seek format to byte offset */
623 if (!gst_bytestream_seek (dvdec->bs, position, GST_SEEK_METHOD_SET)) {
632 gst_event_unref (event);
637 gst_dvdec_loop (GstElement *element)
640 GstBuffer *buf, *outbuf;
643 guint32 length, got_bytes;
647 dvdec = GST_DVDEC (element);
649 /* first read enough bytes to parse the header */
650 got_bytes = gst_bytestream_peek_bytes (dvdec->bs, &inframe, header_size);
651 if (got_bytes < header_size) {
652 gst_dvdec_handle_sink_event (dvdec);
655 dv_parse_header (dvdec->decoder, inframe);
656 /* after parsing the header we know the size of the data */
657 dvdec->PAL = dv_system_50_fields (dvdec->decoder);
659 dvdec->framerate = (dvdec->PAL ? 25 : 30);
660 dvdec->height = height = (dvdec->PAL ? PAL_HEIGHT : NTSC_HEIGHT);
661 length = (dvdec->PAL ? PAL_BUFFER : NTSC_BUFFER);
663 if (length != dvdec->length) {
664 dvdec->length = length;
665 gst_bytestream_size_hint (dvdec->bs, length);
668 /* then read the read data */
669 got_bytes = gst_bytestream_read (dvdec->bs, &buf, length);
670 if (got_bytes < length) {
671 gst_dvdec_handle_sink_event (dvdec);
675 /* if we did not negotiate yet, do it now */
676 if (!GST_PAD_CAPS (dvdec->videosrcpad)) {
680 /* we what we are allowed to do */
681 allowed = gst_pad_get_allowed_caps (dvdec->videosrcpad);
683 /* try to fix our height */
684 trylist = gst_caps_intersect (allowed,
688 "height", GST_PROPS_INT (height)
691 /* prepare for looping */
692 trylist = gst_caps_normalize (trylist);
695 GstCaps *to_try = gst_caps_copy_1 (trylist);
697 /* try each format */
698 if (gst_pad_try_set_caps (dvdec->videosrcpad, to_try) > 0) {
701 /* it worked, try to find what it was again */
702 gst_caps_get_fourcc_int (to_try, "format", &fourcc);
704 if (fourcc == GST_STR_FOURCC ("RGB ")) {
707 gst_caps_get_int (to_try, "bpp", &bpp);
709 dvdec->space = e_dv_color_rgb;
713 dvdec->space = e_dv_color_bgr0;
718 dvdec->space = e_dv_color_yuv;
723 trylist = trylist->next;
725 /* oops list exhausted an nothing was found... */
727 gst_element_error (element, "could not negotiate");
732 format = GST_FORMAT_TIME;
733 gst_pad_query (dvdec->videosrcpad, GST_PAD_QUERY_POSITION, &format, &ts);
735 if (GST_PAD_IS_CONNECTED (dvdec->audiosrcpad)) {
739 dv_decode_full_audio (dvdec->decoder, GST_BUFFER_DATA (buf), dvdec->audio_buffers);
741 /* if we did not negotiate yet, do it now */
742 if (!GST_PAD_CAPS (dvdec->audiosrcpad)) {
743 gst_pad_try_set_caps (dvdec->audiosrcpad,
747 "format", GST_PROPS_STRING ("int"),
748 "rate", GST_PROPS_INT (dvdec->decoder->audio->frequency),
749 "law", GST_PROPS_INT (0),
750 "depth", GST_PROPS_INT (16),
751 "width", GST_PROPS_INT (16),
752 "signed", GST_PROPS_BOOLEAN (TRUE),
753 "channels", GST_PROPS_INT (dvdec->decoder->audio->num_channels),
754 "endianness", GST_PROPS_INT (G_LITTLE_ENDIAN)
758 outbuf = gst_buffer_new ();
759 GST_BUFFER_SIZE (outbuf) = dvdec->decoder->audio->samples_this_frame *
760 sizeof (gint16) * dvdec->decoder->audio->num_channels;
761 GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
763 a_ptr = (gint16 *) GST_BUFFER_DATA (outbuf);
765 for (i = 0; i < dvdec->decoder->audio->samples_this_frame; i++) {
766 for (j = 0; j < dvdec->decoder->audio->num_channels; j++) {
767 *(a_ptr++) = dvdec->audio_buffers[j][i];
770 GST_BUFFER_TIMESTAMP (outbuf) = ts;
772 if (dvdec->need_discont) {
775 discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, ts, NULL);
776 gst_pad_push (dvdec->audiosrcpad, GST_BUFFER (discont));
779 gst_pad_push (dvdec->audiosrcpad, outbuf);
782 if (GST_PAD_IS_CONNECTED (dvdec->videosrcpad)) {
784 guint8 *outframe_ptrs[3];
785 gint outframe_pitches[3];
787 /* try to grab a pool */
789 dvdec->pool = gst_pad_get_bufferpool (dvdec->videosrcpad);
793 /* try to get a buffer from the pool if we have one */
795 outbuf = gst_buffer_new_from_pool (dvdec->pool, 0, 0);
797 /* no buffer from pool, allocate one ourselves */
799 outbuf = gst_buffer_new ();
801 GST_BUFFER_SIZE (outbuf) = (720 * height) * dvdec->bpp;
802 GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf));
805 outframe = GST_BUFFER_DATA (outbuf);
807 outframe_ptrs[0] = outframe;
808 outframe_pitches[0] = 720 * dvdec->bpp;
810 /* the rest only matters for YUY2 */
811 if (dvdec->bpp < 3) {
812 outframe_ptrs[1] = outframe_ptrs[0] + 720 * height;
813 outframe_ptrs[2] = outframe_ptrs[1] + 360 * height;
815 outframe_pitches[1] = height / 2;
816 outframe_pitches[2] = outframe_pitches[1];
819 dv_decode_full_frame (dvdec->decoder, GST_BUFFER_DATA (buf),
820 dvdec->space, outframe_ptrs, outframe_pitches);
822 GST_BUFFER_TIMESTAMP (outbuf) = ts;
824 if (dvdec->need_discont) {
827 discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, ts, NULL);
828 gst_pad_push (dvdec->videosrcpad, GST_BUFFER (discont));
831 gst_pad_push (dvdec->videosrcpad, outbuf);
834 /* FIXME this is inaccurate for NTSC */
835 dvdec->next_ts += GST_SECOND / dvdec->framerate;
837 if (dvdec->need_discont) {
838 dvdec->need_discont = FALSE;
841 gst_buffer_unref (buf);
844 static GstElementStateReturn
845 gst_dvdec_change_state (GstElement *element)
847 GstDVDec *dvdec = GST_DVDEC (element);
849 switch (GST_STATE_TRANSITION (element)) {
850 case GST_STATE_NULL_TO_READY:
852 case GST_STATE_READY_TO_PAUSED:
853 dvdec->bs = gst_bytestream_new (dvdec->sinkpad);
854 dvdec->decoder = dv_decoder_new (0, dvdec->clamp_luma, dvdec->clamp_chroma);
855 dvdec->decoder->quality = dvdec->quality;
857 case GST_STATE_PAUSED_TO_PLAYING:
859 case GST_STATE_PLAYING_TO_PAUSED:
861 gst_buffer_pool_unref (dvdec->pool);
864 case GST_STATE_PAUSED_TO_READY:
865 dv_decoder_free (dvdec->decoder);
866 dvdec->decoder = NULL;
867 gst_bytestream_destroy (dvdec->bs);
869 case GST_STATE_READY_TO_NULL:
872 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
876 parent_class->change_state (element);
878 return GST_STATE_SUCCESS;
881 /* Arguments are part of the Gtk+ object system, and these functions
882 * enable the element to respond to various arguments.
885 gst_dvdec_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
889 /* It's not null if we got it, but it might not be ours */
890 g_return_if_fail(GST_IS_DVDEC(object));
892 /* Get a pointer of the right type. */
893 dvdec = GST_DVDEC(object);
895 /* Check the argument id to see which argument we're setting. */
898 dvdec->clamp_luma = g_value_get_boolean (value);
900 case ARG_CLAMP_CHROMA:
901 dvdec->clamp_chroma = g_value_get_boolean (value);
904 dvdec->quality = g_value_get_flags (value);
907 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
912 /* The set function is simply the inverse of the get fuction. */
914 gst_dvdec_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
918 /* It's not null if we got it, but it might not be ours */
919 g_return_if_fail(GST_IS_DVDEC(object));
920 dvdec = GST_DVDEC(object);
924 g_value_set_boolean (value, dvdec->clamp_luma);
926 case ARG_CLAMP_CHROMA:
927 g_value_set_boolean (value, dvdec->clamp_chroma);
930 g_value_set_flags (value, dvdec->quality);
933 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
938 /* This is the entry into the plugin itself. When the plugin loads,
939 * this function is called to register everything that the plugin provides.
942 plugin_init (GModule *module, GstPlugin *plugin)
944 GstElementFactory *factory;
945 GstTypeFactory *type;
947 if (!gst_library_load ("gstbytestream"))
950 /* We need to create an ElementFactory for each element we provide.
951 * This consists of the name of the element, the GType identifier,
952 * and a pointer to the details structure at the top of the file.
954 factory = gst_element_factory_new("dvdec", GST_TYPE_DVDEC, &dvdec_details);
955 g_return_val_if_fail(factory != NULL, FALSE);
957 gst_element_factory_set_rank (factory, GST_ELEMENT_RANK_PRIMARY);
958 /* The pad templates can be easily generated from the factories above,
959 * and then added to the list of padtemplates for the elementfactory.
960 * Note that the generated padtemplates are stored in static global
961 * variables, for the gst_dvdec_init function to use later on.
963 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET(sink_temp));
964 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET(video_src_temp));
965 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET(audio_src_temp));
967 /* The very last thing is to register the elementfactory with the plugin. */
968 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
970 type = gst_type_factory_new (&dv_definition);
971 gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
976 GstPluginDesc plugin_desc = {