]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gst-plugin-ducati.git/blob - src/gstducatividdec.h
f4fbc2b727120dc1ae93b0e87f8ebe00e26a2df9
[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   /* For storing the external pool query history */
101   gboolean queried_external_pool;
102   GstBufferPool *externalpool;
104   /* by default, codec_data from sinkpad is prepended to first buffer: */
106   guint8 *codecdata;
107   gsize codecdatasize;
109   /* workaround enabled to indicate that timestamp from demuxer is PTS,
110    * not DTS (cough, cough.. avi):
111    */
112   gboolean ts_is_pts;
114   /* auto-detection for ts_is_pts workaround.. if we detect out of order
115    * timestamps from demuxer/parser, then the ts is definitely DTS,
116    * otherwise it may be PTS and out of order timestamps out of decoder
117    * will trigger the ts_is_pts workaround.
118    */
119   gboolean ts_may_be_pts;
121   gboolean wait_keyframe;
123   gboolean needs_flushing;
125   gboolean codec_create_params_changed;
127   GHashTable *passed_in_bufs;
129   GHashTable *dce_locked_bufs;
131 #define NDTS 32
132   GstClockTime dts_queue[NDTS];
133   gint dts_ridx, dts_widx;
134   GstClockTime last_dts, last_pts;
136   Engine_Handle engine;
137   VIDDEC3_Handle codec;
138   VIDDEC3_Params *params;
139   VIDDEC3_DynamicParams *dynParams;
140   VIDDEC3_Status *status;
141   XDM2_BufDesc *inBufs;
142   XDM2_BufDesc *outBufs;
143   VIDDEC3_InArgs *inArgs;
144   VIDDEC3_OutArgs *outArgs;
146   XDAS_Int16 pageMemType;
147   struct omap_device *device;
149   GstCaps *sinkcaps;
151   /* Frames waiting to be reordered */
152   GstBuffer *backlog_frames[MAX_BACKLOG_ARRAY_SIZE + 1];
153   gint backlog_maxframes;
154   gint backlog_nframes;
155   gint backlog_max_maxframes;
157   gboolean codec_debug_info;
159   const char *error_strings[32];
160 };
162 struct _GstDucatiVidDecClass
164   GstElementClass parent_class;
166   const gchar *codec_name;
168   /**
169    * Parse codec specific fields the given caps structure.  The base-
170    * class implementation of this method handles standard stuff like
171    * width/height/framerate/codec_data.
172    */
173     gboolean (*parse_caps) (GstDucatiVidDec * self, GstStructure * s);
175   /**
176    * Called when the input buffer size changes, to recalculate codec required
177    * output buffer size and minimum count
178    */
179   void (*update_buffer_size) (GstDucatiVidDec * self);
181   /**
182    * Called to allocate/initialize  params/dynParams/status/inArgs/outArgs
183    */
184     gboolean (*allocate_params) (GstDucatiVidDec * self, gint params_sz,
185       gint dynparams_sz, gint status_sz, gint inargs_sz, gint outargs_sz);
187   /**
188    * Push input data into codec's input buffer, returning a sub-buffer of
189    * any remaining data, or NULL if none.  Consumes reference to 'buf'
190    */
191   GstBuffer *(*push_input) (GstDucatiVidDec * self, GstBuffer * buf);
193   /**
194    * Called to handle errors returned by VIDDEC3_process.
195    */
196     gint (*handle_error) (GstDucatiVidDec * self, gint ret, gint extended_error,
197       gint status_extended_error);
199   /**
200    * Called to check whether it's a good idea to drop buf or not.
201    */
202     gboolean (*can_drop_frame) (GstDucatiVidDec * self, GstBuffer * buf,
203       gint64 diff);
205     gboolean (*query) (GstDucatiVidDec * self, GstPad * pad, GstQuery * query,
206       gboolean * forward);
208   /**
209    * Called to push a decoder buffer. Consumes reference to 'buf'.
210    */
211     GstFlowReturn (*push_output) (GstDucatiVidDec * self, GstBuffer * buf);
213   /**
214    * Called before a flush happens.
215    */
216   void (*on_flush) (GstDucatiVidDec * self, gboolean eos);
218   /**
219    * Called to set new caps on the sink pad.
220    */
221     gboolean (*set_sink_caps) (GstDucatiVidDec * self, GstCaps * caps);
222 };
224 GType gst_ducati_viddec_get_type (void);
226 /* helper methods for derived classes: */
228 static inline void
229 push_input (GstDucatiVidDec * self, const guint8 * in, gint sz)
231   GST_DEBUG_OBJECT (self, "push: %d bytes)", sz);
232   memcpy (self->input + self->in_size, in, sz);
233   self->in_size += sz;
236 static inline int
237 check_start_code (const guint8 * sc, gint scsize,
238     const guint8 * inbuf, gint insize)
240   if (insize < scsize)
241     return FALSE;
243   while (scsize) {
244     if (*sc != *inbuf)
245       return FALSE;
246     scsize--;
247     sc++;
248     inbuf++;
249   }
251   return TRUE;
254 static inline int
255 find_start_code (const guint8 * sc, gint scsize,
256     const guint8 * inbuf, gint insize)
258   gint size = 0;
259   while (insize) {
260     if (check_start_code (sc, scsize, inbuf, insize))
261       break;
262     insize--;
263     size++;
264     inbuf++;
265   }
266   return size;
269 gboolean gst_ducati_viddec_codec_flush (GstDucatiVidDec * self, gboolean eos);
271 G_END_DECLS
272 #endif /* __GST_DUCATIVIDDEC_H__ */