]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gst-plugin-ducati.git/blob - src/gstducatividdec.h
h264dec: Support for frame-processing for interlaced streams
[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 <stdint.h>
24 #include <stddef.h>
25 #include <unistd.h>
26 #include <omap_drm.h>
27 #include <omap_drmif.h>
29 #include "gstducati.h"
30 #include "gstducatibufferpriv.h"
32 #include <gst/drm/gstdrmallocator.h>
33 #include <gst/video/video.h>
34 #include <gst/video/gstvideometa.h>
36 G_BEGIN_DECLS
37 #define GST_TYPE_DUCATIVIDDEC               (gst_ducati_viddec_get_type())
38 #define GST_DUCATIVIDDEC(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_DUCATIVIDDEC, GstDucatiVidDec))
39 #define GST_DUCATIVIDDEC_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_DUCATIVIDDEC, GstDucatiVidDecClass))
40 #define GST_IS_DUCATIVIDDEC(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_DUCATIVIDDEC))
41 #define GST_IS_DUCATIVIDDEC_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_DUCATIVIDDEC))
42 #define GST_DUCATIVIDDEC_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_DUCATIVIDDEC, GstDucatiVidDecClass))
43 typedef struct _GstDucatiVidDec GstDucatiVidDec;
44 typedef struct _GstDucatiVidDecClass GstDucatiVidDecClass;
46 /* For re-ordering in normal playback */
47 #define MAX_BACKLOG_FRAMES 16
48 /* For re-ordering in reverse playback */
49 #define MAX_BACKLOG_ARRAY_SIZE 120
51 struct _GstDucatiVidDec
52 {
53   GstElement parent;
55   GstPad *sinkpad, *srcpad;
57   GstBufferPool *pool;
59   /* minimum output size required by the codec: */
60   gint outsize;
62   /* minimum number of buffers required by the codec: */
63   gint min_buffers;
65   /* input (unpadded, unaligned) size of video: */
66   gint input_width, input_height;
68   /* input (unpadded, aligned to MB) size of video: */
69   gint width, height;
71   gint fps_n, fps_d;
73   /* output (padded) size including any codec padding: */
74   gint padded_width, padded_height;
76   /* output stride (>= padded_width) */
77   gint stride;
79   gboolean interlaced;
81   struct omap_bo *input_bo;
82   /* input buffer, allocated when codec is created: */
83   guint8 *input;
85   /* number of bytes pushed to input on current frame: */
86   gint in_size;
88   /* on first output buffer, we need to send crop info to sink.. and some
89    * operations like flushing should be avoided if we haven't sent any
90    * input buffers:
91    */
92   gboolean first_out_buffer, first_in_buffer;
94   GstSegment segment;
95   gdouble qos_proportion;
96   GstClockTime qos_earliest_time;
98   gboolean need_out_buf;
100   /* by default, codec_data from sinkpad is prepended to first buffer: */
102   guint8 *codecdata;
103   gsize codecdatasize;
105   /* workaround enabled to indicate that timestamp from demuxer is PTS,
106    * not DTS (cough, cough.. avi):
107    */
108   gboolean ts_is_pts;
110   /* auto-detection for ts_is_pts workaround.. if we detect out of order
111    * timestamps from demuxer/parser, then the ts is definitely DTS,
112    * otherwise it may be PTS and out of order timestamps out of decoder
113    * will trigger the ts_is_pts workaround.
114    */
115   gboolean ts_may_be_pts;
117   gboolean wait_keyframe;
119   gboolean needs_flushing;
121   gboolean codec_create_params_changed;
123   GHashTable *passed_in_bufs;
125   GHashTable *dce_locked_bufs;
127 #define NDTS 32
128   GstClockTime dts_queue[NDTS];
129   gint dts_ridx, dts_widx;
130   GstClockTime last_dts, last_pts;
132   Engine_Handle engine;
133   VIDDEC3_Handle codec;
134   VIDDEC3_Params *params;
135   VIDDEC3_DynamicParams *dynParams;
136   VIDDEC3_Status *status;
137   XDM2_BufDesc *inBufs;
138   XDM2_BufDesc *outBufs;
139   VIDDEC3_InArgs *inArgs;
140   VIDDEC3_OutArgs *outArgs;
142   XDAS_Int16 pageMemType;
143   struct omap_device *device;
145   GstCaps *sinkcaps;
147   /* Frames waiting to be reordered */
148   GstBuffer *backlog_frames[MAX_BACKLOG_ARRAY_SIZE + 1];
149   gint backlog_maxframes;
150   gint backlog_nframes;
151   gint backlog_max_maxframes;
152   gint displayDelay;
154   gboolean codec_debug_info;
156   const char *error_strings[32];
157 };
159 struct _GstDucatiVidDecClass
161   GstElementClass parent_class;
163   const gchar *codec_name;
165   /**
166    * Parse codec specific fields the given caps structure.  The base-
167    * class implementation of this method handles standard stuff like
168    * width/height/framerate/codec_data.
169    */
170     gboolean (*parse_caps) (GstDucatiVidDec * self, GstStructure * s);
172   /**
173    * Called when the input buffer size changes, to recalculate codec required
174    * output buffer size and minimum count
175    */
176   void (*update_buffer_size) (GstDucatiVidDec * self);
178   /**
179    * Called to allocate/initialize  params/dynParams/status/inArgs/outArgs
180    */
181     gboolean (*allocate_params) (GstDucatiVidDec * self, gint params_sz,
182       gint dynparams_sz, gint status_sz, gint inargs_sz, gint outargs_sz);
184   /**
185    * Push input data into codec's input buffer, returning a sub-buffer of
186    * any remaining data, or NULL if none.  Consumes reference to 'buf'
187    */
188   GstBuffer *(*push_input) (GstDucatiVidDec * self, GstBuffer * buf);
190   /**
191    * Called to handle errors returned by VIDDEC3_process.
192    */
193     gint (*handle_error) (GstDucatiVidDec * self, gint ret, gint extended_error,
194       gint status_extended_error);
196   /**
197    * Called to check whether it's a good idea to drop buf or not.
198    */
199     gboolean (*can_drop_frame) (GstDucatiVidDec * self, GstBuffer * buf,
200       gint64 diff);
202     gboolean (*query) (GstDucatiVidDec * self, GstPad * pad, GstQuery * query,
203       gboolean * forward);
205   /**
206    * Called to push a decoder buffer. Consumes reference to 'buf'.
207    */
208     GstFlowReturn (*push_output) (GstDucatiVidDec * self, GstBuffer * buf);
210   /**
211    * Called before a flush happens.
212    */
213   void (*on_flush) (GstDucatiVidDec * self, gboolean eos);
215   /**
216    * Called to set new caps on the sink pad.
217    */
218     gboolean (*set_sink_caps) (GstDucatiVidDec * self, GstCaps * caps);
219 };
221 GType gst_ducati_viddec_get_type (void);
223 /* helper methods for derived classes: */
225 static inline void
226 push_input (GstDucatiVidDec * self, const guint8 * in, gint sz)
228   GST_DEBUG_OBJECT (self, "push: %d bytes)", sz);
229   memcpy (self->input + self->in_size, in, sz);
230   self->in_size += sz;
233 static inline int
234 check_start_code (const guint8 * sc, gint scsize,
235     const guint8 * inbuf, gint insize)
237   if (insize < scsize)
238     return FALSE;
240   while (scsize) {
241     if (*sc != *inbuf)
242       return FALSE;
243     scsize--;
244     sc++;
245     inbuf++;
246   }
248   return TRUE;
251 static inline int
252 find_start_code (const guint8 * sc, gint scsize,
253     const guint8 * inbuf, gint insize)
255   gint size = 0;
256   while (insize) {
257     if (check_start_code (sc, scsize, inbuf, insize))
258       break;
259     insize--;
260     size++;
261     inbuf++;
262   }
263   return size;
266 gboolean gst_ducati_viddec_codec_flush (GstDucatiVidDec * self, gboolean eos);
268 G_END_DECLS
269 #endif /* __GST_DUCATIVIDDEC_H__ */