f8ae4d68583ab3d6f2e28619f5a16fa1fc049bc7
1 /*
2 * GStreamer
3 * Copyright (c) 2010, Texas Instruments Incorporated
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation
8 * version 2.1 of the License.
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 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
20 /**
21 * SECTION:element-ducatimpeg2dec
22 *
23 * FIXME:Describe ducatimpeg2dec here.
24 *
25 * <refsect2>
26 * <title>Example launch line</title>
27 * |[
28 * gst-launch -v -m fakesrc ! ducatimpeg2dec ! fakesink silent=TRUE
29 * ]|
30 * </refsect2>
31 */
33 #ifdef HAVE_CONFIG_H
34 # include <config.h>
35 #endif
37 #include "gstducatimpeg2dec.h"
39 GST_BOILERPLATE (GstDucatiMpeg2Dec, gst_ducati_mpeg2dec, GstDucatiVidDec,
40 GST_TYPE_DUCATIVIDDEC);
42 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
43 GST_PAD_SINK,
44 GST_PAD_ALWAYS,
45 GST_STATIC_CAPS ("video/mpeg, "
46 "mpegversion = (int)[ 1, 2 ], " // XXX check on MPEG-1..
47 "systemstream = (boolean)false, "
48 "parsed = (boolean)true, "
49 "width = (int)[ 64, 2048 ], "
50 "height = (int)[ 64, 2048 ], "
51 "framerate = (fraction)[ 0, max ];")
52 );
54 /* GstDucatiVidDec vmethod implementations */
56 static void
57 gst_ducati_mpeg2dec_update_buffer_size (GstDucatiVidDec * self)
58 {
59 gint w = self->width;
60 gint h = self->height;
62 /* calculate output buffer parameters: */
63 self->padded_width = w;
64 self->padded_height = h;
65 self->min_buffers = 8;
66 }
68 static gboolean
69 gst_ducati_mpeg2dec_allocate_params (GstDucatiVidDec * self, gint params_sz,
70 gint dynparams_sz, gint status_sz, gint inargs_sz, gint outargs_sz)
71 {
72 gboolean ret = parent_class->allocate_params (self,
73 sizeof (IVIDDEC3_Params), sizeof (IVIDDEC3_DynamicParams),
74 sizeof (IVIDDEC3_Status), sizeof (IVIDDEC3_InArgs),
75 sizeof (IVIDDEC3_OutArgs));
77 if (ret)
78 self->params->displayDelay = IVIDDEC3_DISPLAY_DELAY_1;
80 return ret;
81 }
83 static GstBuffer *
84 gst_ducati_mpeg2dec_push_input (GstDucatiVidDec * vdec, GstBuffer * buf)
85 {
86 GstDucatiMpeg2Dec *self = GST_DUCATIMPEG2DEC (vdec);
87 guint sz = GST_BUFFER_SIZE (buf);
88 guint8 *data = GST_BUFFER_DATA (buf);
90 /* skip codec_data, which is same as first buffer from mpegvideoparse (and
91 * appears to be periodically resent) and instead prepend to next frame..
92 */
93 if (vdec->codec_data && (sz == GST_BUFFER_SIZE (vdec->codec_data)) &&
94 !memcmp (data, GST_BUFFER_DATA (vdec->codec_data), sz)) {
95 GST_DEBUG_OBJECT (self, "skipping codec_data buffer");
96 self->prepend_codec_data = TRUE;
97 } else {
98 if (self->prepend_codec_data) {
99 GST_DEBUG_OBJECT (self, "prepending codec_data buffer");
100 push_input (vdec, GST_BUFFER_DATA (vdec->codec_data),
101 GST_BUFFER_SIZE (vdec->codec_data));
102 self->prepend_codec_data = FALSE;
103 }
104 push_input (vdec, data, sz);
105 }
107 gst_buffer_unref (buf);
109 return NULL;
110 }
112 /* GObject vmethod implementations */
114 static void
115 gst_ducati_mpeg2dec_base_init (gpointer gclass)
116 {
117 GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
119 gst_element_class_set_details_simple (element_class,
120 "DucatiMpeg2Dec",
121 "Codec/Decoder/Video",
122 "Decodes video in MPEG-2 format with ducati",
123 "Rob Clark <rob@ti.com>");
125 gst_element_class_add_pad_template (element_class,
126 gst_static_pad_template_get (&sink_factory));
127 }
129 static void
130 gst_ducati_mpeg2dec_class_init (GstDucatiMpeg2DecClass * klass)
131 {
132 GstDucatiVidDecClass *bclass = GST_DUCATIVIDDEC_CLASS (klass);
133 bclass->codec_name = "ivahd_mpeg2vdec";
134 bclass->update_buffer_size =
135 GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_update_buffer_size);
136 bclass->allocate_params =
137 GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_allocate_params);
138 bclass->push_input =
139 GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_push_input);
140 }
142 static void
143 gst_ducati_mpeg2dec_init (GstDucatiMpeg2Dec * self,
144 GstDucatiMpeg2DecClass * gclass)
145 {
146 GstDucatiVidDec *vdec = GST_DUCATIVIDDEC (self);
147 vdec->pageMemType = XDM_MEMTYPE_RAW;
148 }