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_DECODE_ORDER;
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 static gboolean
113 gst_ducati_mpeg2dec_set_sink_caps (GstDucatiVidDec * self, GstCaps * caps)
114 {
115 GstStructure *structure;
116 const gchar *profile;
118 GST_DEBUG_OBJECT (self, "set_sink_caps: %" GST_PTR_FORMAT, caps);
120 if (!GST_CALL_PARENT_WITH_DEFAULT (GST_DUCATIVIDDEC_CLASS, set_sink_caps,
121 (self, caps), TRUE))
122 return FALSE;
124 /* Simple profile does not have B frames */
125 structure = gst_caps_get_structure (caps, 0);
126 profile = gst_structure_get_string (structure, "profile");
127 if (!profile || strcmp (profile, "simple")) {
128 /* TODO: can a better bound be found from stream headers ? */
129 self->backlog_maxframes = MAX_BACKLOG_FRAMES;
130 }
132 return TRUE;
133 }
135 static GstFlowReturn
136 gst_ducati_mpeg2dec_push_output (GstDucatiVidDec * self, GstBuffer * buf)
137 {
138 GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_TIMESTAMP (buf);
139 return parent_class->push_output (self, buf);
140 }
142 /* GObject vmethod implementations */
144 static void
145 gst_ducati_mpeg2dec_base_init (gpointer gclass)
146 {
147 GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
149 gst_element_class_set_details_simple (element_class,
150 "DucatiMpeg2Dec",
151 "Codec/Decoder/Video",
152 "Decodes video in MPEG-2 format with ducati",
153 "Rob Clark <rob@ti.com>");
155 gst_element_class_add_pad_template (element_class,
156 gst_static_pad_template_get (&sink_factory));
157 }
159 static void
160 gst_ducati_mpeg2dec_class_init (GstDucatiMpeg2DecClass * klass)
161 {
162 GstDucatiVidDecClass *bclass = GST_DUCATIVIDDEC_CLASS (klass);
163 bclass->codec_name = "ivahd_mpeg2vdec";
164 bclass->update_buffer_size =
165 GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_update_buffer_size);
166 bclass->allocate_params =
167 GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_allocate_params);
168 bclass->push_input = GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_push_input);
169 bclass->set_sink_caps = GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_set_sink_caps);
170 bclass->push_output = GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_push_output);
171 }
173 static void
174 gst_ducati_mpeg2dec_init (GstDucatiMpeg2Dec * self,
175 GstDucatiMpeg2DecClass * gclass)
176 {
177 GstDucatiVidDec *vdec = GST_DUCATIVIDDEC (self);
178 vdec->pageMemType = XDM_MEMTYPE_RAW;
179 }