]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gst-plugin-ducati.git/blob - src/gstducatividdec.h
ducatividdec: send a crop event every time caps change
[glsdk/gst-plugin-ducati.git] / src / gstducatividdec.h
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 #ifndef __GST_DUCATIVIDDEC_H__
21 #define __GST_DUCATIVIDDEC_H__
23 #include "gstducati.h"
24 #include "gstducatibufferpool.h"
26 #include <gst/video/video.h>
28 G_BEGIN_DECLS
31 #define GST_TYPE_DUCATIVIDDEC               (gst_ducati_viddec_get_type())
32 #define GST_DUCATIVIDDEC(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_DUCATIVIDDEC, GstDucatiVidDec))
33 #define GST_DUCATIVIDDEC_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_DUCATIVIDDEC, GstDucatiVidDecClass))
34 #define GST_IS_DUCATIVIDDEC(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_DUCATIVIDDEC))
35 #define GST_IS_DUCATIVIDDEC_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_DUCATIVIDDEC))
36 #define GST_DUCATIVIDDEC_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_DUCATIVIDDEC, GstDucatiVidDecClass))
38 typedef struct _GstDucatiVidDec      GstDucatiVidDec;
39 typedef struct _GstDucatiVidDecClass GstDucatiVidDecClass;
41 struct _GstDucatiVidDec
42 {
43   GstElement parent;
45   GstPad *sinkpad, *srcpad;
47   GstDucatiBufferPool *pool;
49   /* minimum output size required by the codec: */
50   gint outsize;
52   /* minimum number of buffers required by the codec: */
53   gint min_buffers;
55   /* input (unpadded, unaligned) size of video: */
56   gint input_width, input_height;
58   /* input (unpadded, aligned to MB) size of video: */
59   gint width, height;
61   /* output (padded) size including any codec padding: */
62   gint padded_width, padded_height;
64   /* output stride (>= padded_width) */
65   gint stride;
67   gboolean interlaced;
69   /* input buffer, allocated when codec is created: */
70   guint8 *input;
72   /* number of bytes pushed to input on current frame: */
73   gint in_size;
75   /* on first output buffer, we need to send crop info to sink.. and some
76    * operations like flushing should be avoided if we haven't sent any
77    * input buffers:
78    */
79   gboolean first_out_buffer, first_in_buffer;
80   gboolean send_crop_event;
82   GstSegment segment;
83   gdouble qos_proportion;
84   GstClockTime qos_earliest_time;
86   gboolean need_out_buf;
88   /* by default, codec_data from sinkpad is prepended to first buffer: */
89   GstBuffer *codec_data;
91   /* workaround enabled to indicate that timestamp from demuxer is PTS,
92    * not DTS (cough, cough.. avi):
93    */
94   gboolean ts_is_pts;
96   /* auto-detection for ts_is_pts workaround.. if we detect out of order
97    * timestamps from demuxer/parser, then the ts is definitely DTS,
98    * otherwise it may be PTS and out of order timestamps out of decoder
99    * will trigger the ts_is_pts workaround.
100    */
101   gboolean ts_may_be_pts;
103   gboolean wait_keyframe;
105 #define NDTS 32
106   GstClockTime dts_queue[NDTS];
107   gint dts_ridx, dts_widx;
108   GstClockTime last_dts, last_pts;
110   Engine_Handle           engine;
111   VIDDEC3_Handle          codec;
112   VIDDEC3_Params         *params;
113   VIDDEC3_DynamicParams  *dynParams;
114   VIDDEC3_Status         *status;
115   XDM2_BufDesc           *inBufs;
116   XDM2_BufDesc           *outBufs;
117   VIDDEC3_InArgs         *inArgs;
118   VIDDEC3_OutArgs        *outArgs;
120   XDAS_Int16 pageMemType;
121 };
123 struct _GstDucatiVidDecClass
125   GstElementClass parent_class;
127   const gchar *codec_name;
129   /**
130    * Parse codec specific fields the given caps structure.  The base-
131    * class implementation of this method handles standard stuff like
132    * width/height/framerate/codec_data.
133    */
134   gboolean (*parse_caps) (GstDucatiVidDec * self, GstStructure * s);
136   /**
137    * Called when the input buffer size changes, to recalculate codec required
138    * output buffer size and minimum count
139    */
140   void (*update_buffer_size) (GstDucatiVidDec * self);
142   /**
143    * Called to allocate/initialize  params/dynParams/status/inArgs/outArgs
144    */
145   gboolean (*allocate_params) (GstDucatiVidDec * self, gint params_sz,
146       gint dynparams_sz, gint status_sz, gint inargs_sz, gint outargs_sz);
148   /**
149    * Push input data into codec's input buffer, returning a sub-buffer of
150    * any remaining data, or NULL if none.  Consumes reference to 'buf'
151    */
152   GstBuffer * (*push_input) (GstDucatiVidDec * self, GstBuffer * buf);
154   /**
155    * Called to handle errors returned by VIDDEC3_process.
156    */
157   gint (*handle_error) (GstDucatiVidDec * self, gint ret, gint extended_error,
158       gint status_extended_error);
160   /**
161    * Called to check whether it's a good idea to drop buf or not.
162    */
163   gboolean (*drop_frame) (GstDucatiVidDec * self, GstBuffer * buf, gint64 diff);
164 };
166 GType gst_ducati_viddec_get_type (void);
168 /* helper methods for derived classes: */
170 static inline void
171 push_input (GstDucatiVidDec * self, const guint8 *in, gint sz)
173   GST_DEBUG_OBJECT (self, "push: %d bytes)", sz);
174   memcpy (self->input + self->in_size, in, sz);
175   self->in_size += sz;
178 static inline int
179 check_start_code (const guint8 *sc, gint scsize,
180     const guint8 *inbuf, gint insize)
182   if (insize < scsize)
183     return FALSE;
185   while (scsize) {
186     if (*sc != *inbuf)
187       return FALSE;
188     scsize--;
189     sc++;
190     inbuf++;
191   }
193   return TRUE;
196 static inline int
197 find_start_code (const guint8 *sc, gint scsize,
198     const guint8 *inbuf, gint insize)
200   gint size = 0;
201   while (insize) {
202     if (check_start_code (sc, scsize, inbuf, insize))
203       break;
204     insize--;
205     size++;
206     inbuf++;
207   }
208   return size;
211 gboolean
212 gst_ducati_viddec_codec_flush (GstDucatiVidDec * self, gboolean eos);
214 G_END_DECLS
216 #endif /* __GST_DUCATIVIDDEC_H__ */