]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gst-plugin-ducati.git/blob - src/gstducatividdec.h
Reduce mem copying and code clean-up
[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/gstdrmbufferpool.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   GstDRMBufferPool *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   GHashTable *passed_in_bufs;
127   GHashTable *dce_locked_bufs;
129 #define NDTS 32
130   GstClockTime dts_queue[NDTS];
131   gint dts_ridx, dts_widx;
132   GstClockTime last_dts, last_pts;
134   Engine_Handle engine;
135   VIDDEC3_Handle codec;
136   VIDDEC3_Params *params;
137   VIDDEC3_DynamicParams *dynParams;
138   VIDDEC3_Status *status;
139   XDM2_BufDesc *inBufs;
140   XDM2_BufDesc *outBufs;
141   VIDDEC3_InArgs *inArgs;
142   VIDDEC3_OutArgs *outArgs;
144   XDAS_Int16 pageMemType;
145   struct omap_device *device;
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;
153   gboolean codec_debug_info;
155   const char *error_strings[32];
156 };
158 struct _GstDucatiVidDecClass
160   GstElementClass parent_class;
162   const gchar *codec_name;
164   /**
165    * Parse codec specific fields the given caps structure.  The base-
166    * class implementation of this method handles standard stuff like
167    * width/height/framerate/codec_data.
168    */
169     gboolean (*parse_caps) (GstDucatiVidDec * self, GstStructure * s);
171   /**
172    * Called when the input buffer size changes, to recalculate codec required
173    * output buffer size and minimum count
174    */
175   void (*update_buffer_size) (GstDucatiVidDec * self);
177   /**
178    * Called to allocate/initialize  params/dynParams/status/inArgs/outArgs
179    */
180     gboolean (*allocate_params) (GstDucatiVidDec * self, gint params_sz,
181       gint dynparams_sz, gint status_sz, gint inargs_sz, gint outargs_sz);
183   /**
184    * Push input data into codec's input buffer, returning a sub-buffer of
185    * any remaining data, or NULL if none.  Consumes reference to 'buf'
186    */
187   GstBuffer *(*push_input) (GstDucatiVidDec * self, GstBuffer * buf);
189   /**
190    * Called to handle errors returned by VIDDEC3_process.
191    */
192     gint (*handle_error) (GstDucatiVidDec * self, gint ret, gint extended_error,
193       gint status_extended_error);
195   /**
196    * Called to check whether it's a good idea to drop buf or not.
197    */
198     gboolean (*can_drop_frame) (GstDucatiVidDec * self, GstBuffer * buf,
199       gint64 diff);
201     gboolean (*query) (GstDucatiVidDec * self, GstPad * pad, GstQuery * query,
202       gboolean * forward);
204   /**
205    * Called to push a decoder buffer. Consumes reference to 'buf'.
206    */
207     GstFlowReturn (*push_output) (GstDucatiVidDec * self, GstBuffer * buf);
209   /**
210    * Called before a flush happens.
211    */
212   void (*on_flush) (GstDucatiVidDec * self, gboolean eos);
214   /**
215    * Called to set new caps on the sink pad.
216    */
217     gboolean (*set_sink_caps) (GstDucatiVidDec * self, GstCaps * caps);
218 };
220 GType gst_ducati_viddec_get_type (void);
222 /* helper methods for derived classes: */
224 static inline void
225 push_input (GstDucatiVidDec * self, const guint8 * in, gint sz)
227   GST_DEBUG_OBJECT (self, "push: %d bytes)", sz);
228   memcpy (self->input + self->in_size, in, sz);
229   self->in_size += sz;
232 static inline int
233 check_start_code (const guint8 * sc, gint scsize,
234     const guint8 * inbuf, gint insize)
236   if (insize < scsize)
237     return FALSE;
239   while (scsize) {
240     if (*sc != *inbuf)
241       return FALSE;
242     scsize--;
243     sc++;
244     inbuf++;
245   }
247   return TRUE;
250 static inline int
251 find_start_code (const guint8 * sc, gint scsize,
252     const guint8 * inbuf, gint insize)
254   gint size = 0;
255   while (insize) {
256     if (check_start_code (sc, scsize, inbuf, insize))
257       break;
258     insize--;
259     size++;
260     inbuf++;
261   }
262   return size;
265 gboolean gst_ducati_viddec_codec_flush (GstDucatiVidDec * self, gboolean eos);
267 G_END_DECLS
268 #endif /* __GST_DUCATIVIDDEC_H__ */