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 <gst/gst.h>
38 #include <gst/video/video.h>
40 #include "gstducatimpeg2dec.h"
42 GST_BOILERPLATE (GstDucatiMpeg2Dec, gst_ducati_mpeg2dec, GstDucatiVidDec,
43 GST_TYPE_DUCATIVIDDEC);
45 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
46 GST_PAD_SINK,
47 GST_PAD_ALWAYS,
48 GST_STATIC_CAPS ("video/mpeg, "
49 "mpegversion = (int)[ 1, 2 ], " // XXX check on MPEG-1..
50 "systemstream = (boolean)false, "
51 "width = (int)[ 64, 2048 ], "
52 "height = (int)[ 64, 2048 ], "
53 "framerate = (fraction)[ 0, max ];")
54 );
56 /* GstDucatiVidDec vmethod implementations */
58 static void
59 gst_ducati_mpeg2dec_update_buffer_size (GstDucatiVidDec * self)
60 {
61 gint w = self->width;
62 gint h = self->height;
64 /* calculate output buffer parameters: */
65 self->padded_width = ALIGN2 (w, 7);
66 self->padded_height = h;
67 self->min_buffers = 8;
68 }
70 static gboolean
71 gst_ducati_mpeg2dec_allocate_params (GstDucatiVidDec * self, gint params_sz,
72 gint dynparams_sz, gint status_sz, gint inargs_sz, gint outargs_sz)
73 {
74 gboolean ret = parent_class->allocate_params (self,
75 sizeof (IMPEG2VDEC_Params), sizeof (IMPEG2VDEC_DynamicParams),
76 sizeof (IMPEG2VDEC_Status), sizeof (IMPEG2VDEC_InArgs),
77 sizeof (IMPEG2VDEC_OutArgs));
79 if (ret) {
80 IMPEG2VDEC_Params *params = (IMPEG2VDEC_Params *) self->params;
81 self->params->displayDelay = IVIDDEC3_DISPLAY_DELAY_AUTO;
82 }
84 return ret;
85 }
87 static GstBuffer *
88 gst_ducati_mpeg2dec_push_input (GstDucatiVidDec * vdec, GstBuffer * buf)
89 {
90 GstDucatiMpeg2Dec *self = GST_DUCATIMPEG2DEC (vdec);
91 guint sz = GST_BUFFER_SIZE (buf);
92 guint8 *data = GST_BUFFER_DATA (buf);
94 /* skip codec_data, which is same as first buffer from mpegvideoparse (and
95 * appears to be periodically resent) and instead prepend to next frame..
96 */
97 if (vdec->codec_data && (sz == GST_BUFFER_SIZE (vdec->codec_data)) &&
98 !memcmp (data, GST_BUFFER_DATA (vdec->codec_data), sz)) {
99 GST_DEBUG_OBJECT (self, "skipping codec_data buffer");
100 self->prepend_codec_data = TRUE;
101 } else {
102 if (self->prepend_codec_data) {
103 GST_DEBUG_OBJECT (self, "prepending codec_data buffer");
104 push_input (vdec, GST_BUFFER_DATA (vdec->codec_data),
105 GST_BUFFER_SIZE (vdec->codec_data));
106 self->prepend_codec_data = FALSE;
107 }
108 push_input (vdec, data, sz);
109 }
111 gst_buffer_unref (buf);
113 return NULL;
114 }
116 /* GObject vmethod implementations */
118 static void
119 gst_ducati_mpeg2dec_base_init (gpointer gclass)
120 {
121 GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
123 gst_element_class_set_details_simple (element_class,
124 "DucatiMpeg2Dec",
125 "Codec/Decoder/Video",
126 "Decodes video in MPEG-2 format with ducati",
127 "Rob Clark <rob@ti.com>");
129 gst_element_class_add_pad_template (element_class,
130 gst_static_pad_template_get (&sink_factory));
131 }
133 static void
134 gst_ducati_mpeg2dec_class_init (GstDucatiMpeg2DecClass * klass)
135 {
136 GstDucatiVidDecClass *bclass = GST_DUCATIVIDDEC_CLASS (klass);
137 bclass->codec_name = "ivahd_mpeg2vdec";
138 bclass->update_buffer_size =
139 GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_update_buffer_size);
140 bclass->allocate_params =
141 GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_allocate_params);
142 bclass->push_input =
143 GST_DEBUG_FUNCPTR (gst_ducati_mpeg2dec_push_input);
144 }
146 static void
147 gst_ducati_mpeg2dec_init (GstDucatiMpeg2Dec * self,
148 GstDucatiMpeg2DecClass * gclass)
149 {
150 }