6c7b9a54d798099efe4b384bd195a46e74be6ab9
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 <omap_drm.h>
26 #include <omap_drmif.h>
28 #include "gstducati.h"
29 #include "gstducatibufferpriv.h"
31 #include <gst/drm/gstdrmbufferpool.h>
32 #include <gst/video/video.h>
33 #include <gst/video/video-crop.h>
35 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))
44 typedef struct _GstDucatiVidDec GstDucatiVidDec;
45 typedef struct _GstDucatiVidDecClass GstDucatiVidDecClass;
47 /* For re-ordering in normal playback */
48 #define MAX_BACKLOG_FRAMES 16
49 /* For re-ordering in reverse playback */
50 #define MAX_BACKLOG_ARRAY_SIZE 120
52 struct _GstDucatiVidDec
53 {
54 GstElement parent;
56 GstPad *sinkpad, *srcpad;
58 GstDRMBufferPool *pool;
60 /* minimum output size required by the codec: */
61 gint outsize;
63 /* minimum number of buffers required by the codec: */
64 gint min_buffers;
66 /* input (unpadded, unaligned) size of video: */
67 gint input_width, input_height;
69 /* input (unpadded, aligned to MB) size of video: */
70 gint width, height;
72 gint fps_n, fps_d;
74 /* output (padded) size including any codec padding: */
75 gint padded_width, padded_height;
77 /* output stride (>= padded_width) */
78 gint stride;
80 gboolean interlaced;
82 struct omap_bo *input_bo;
83 /* input buffer, allocated when codec is created: */
84 guint8 *input;
86 /* number of bytes pushed to input on current frame: */
87 gint in_size;
89 /* the crop to attach to output buffers: */
90 GstVideoCrop *crop;
92 /* on first output buffer, we need to send crop info to sink.. and some
93 * operations like flushing should be avoided if we haven't sent any
94 * input buffers:
95 */
96 gboolean first_out_buffer, first_in_buffer;
97 gboolean send_crop_event;
99 GstSegment segment;
100 gdouble qos_proportion;
101 GstClockTime qos_earliest_time;
103 gboolean need_out_buf;
105 /* by default, codec_data from sinkpad is prepended to first buffer: */
106 GstBuffer *codec_data;
108 /* workaround enabled to indicate that timestamp from demuxer is PTS,
109 * not DTS (cough, cough.. avi):
110 */
111 gboolean ts_is_pts;
113 /* auto-detection for ts_is_pts workaround.. if we detect out of order
114 * timestamps from demuxer/parser, then the ts is definitely DTS,
115 * otherwise it may be PTS and out of order timestamps out of decoder
116 * will trigger the ts_is_pts workaround.
117 */
118 gboolean ts_may_be_pts;
120 gboolean wait_keyframe;
122 gboolean needs_flushing;
124 GHashTable *passed_in_bufs;
126 #define NDTS 32
127 GstClockTime dts_queue[NDTS];
128 gint dts_ridx, dts_widx;
129 GstClockTime last_dts, last_pts;
131 Engine_Handle engine;
132 VIDDEC3_Handle codec;
133 VIDDEC3_Params *params;
134 VIDDEC3_DynamicParams *dynParams;
135 VIDDEC3_Status *status;
136 XDM2_BufDesc *inBufs;
137 XDM2_BufDesc *outBufs;
138 VIDDEC3_InArgs *inArgs;
139 VIDDEC3_OutArgs *outArgs;
141 XDAS_Int16 pageMemType;
142 struct omap_device *device;
144 /* Frames waiting to be reordered */
145 GstBuffer *backlog_frames[MAX_BACKLOG_ARRAY_SIZE + 1];
146 gint backlog_maxframes;
147 gint backlog_nframes;
148 gint backlog_max_maxframes;
150 gboolean codec_debug_info;
152 const char *error_strings[32];
153 };
155 struct _GstDucatiVidDecClass
156 {
157 GstElementClass parent_class;
159 const gchar *codec_name;
161 /**
162 * Parse codec specific fields the given caps structure. The base-
163 * class implementation of this method handles standard stuff like
164 * width/height/framerate/codec_data.
165 */
166 gboolean (*parse_caps) (GstDucatiVidDec * self, GstStructure * s);
168 /**
169 * Called when the input buffer size changes, to recalculate codec required
170 * output buffer size and minimum count
171 */
172 void (*update_buffer_size) (GstDucatiVidDec * self);
174 /**
175 * Called to allocate/initialize params/dynParams/status/inArgs/outArgs
176 */
177 gboolean (*allocate_params) (GstDucatiVidDec * self, gint params_sz,
178 gint dynparams_sz, gint status_sz, gint inargs_sz, gint outargs_sz);
180 /**
181 * Push input data into codec's input buffer, returning a sub-buffer of
182 * any remaining data, or NULL if none. Consumes reference to 'buf'
183 */
184 GstBuffer * (*push_input) (GstDucatiVidDec * self, GstBuffer * buf);
186 /**
187 * Called to handle errors returned by VIDDEC3_process.
188 */
189 gint (*handle_error) (GstDucatiVidDec * self, gint ret, gint extended_error,
190 gint status_extended_error);
192 /**
193 * Called to check whether it's a good idea to drop buf or not.
194 */
195 gboolean (*can_drop_frame) (GstDucatiVidDec * self, GstBuffer * buf, gint64 diff);
197 gboolean (*query) (GstDucatiVidDec * self, GstPad * pad, GstQuery * query,
198 gboolean * forward);
200 /**
201 * Called to push a decoder buffer. Consumes reference to 'buf'.
202 */
203 GstFlowReturn (*push_output) (GstDucatiVidDec * self, GstBuffer * buf);
205 /**
206 * Called before a flush happens.
207 */
208 void (*on_flush) (GstDucatiVidDec * self, gboolean eos);
210 /**
211 * Called to set new caps on the sink pad.
212 */
213 gboolean (*set_sink_caps) (GstDucatiVidDec * self, GstCaps *caps);
214 };
216 GType gst_ducati_viddec_get_type (void);
218 /* helper methods for derived classes: */
220 static inline void
221 push_input (GstDucatiVidDec * self, const guint8 *in, gint sz)
222 {
223 GST_DEBUG_OBJECT (self, "push: %d bytes)", sz);
224 memcpy (self->input + self->in_size, in, sz);
225 self->in_size += sz;
226 }
228 static inline int
229 check_start_code (const guint8 *sc, gint scsize,
230 const guint8 *inbuf, gint insize)
231 {
232 if (insize < scsize)
233 return FALSE;
235 while (scsize) {
236 if (*sc != *inbuf)
237 return FALSE;
238 scsize--;
239 sc++;
240 inbuf++;
241 }
243 return TRUE;
244 }
246 static inline int
247 find_start_code (const guint8 *sc, gint scsize,
248 const guint8 *inbuf, gint insize)
249 {
250 gint size = 0;
251 while (insize) {
252 if (check_start_code (sc, scsize, inbuf, insize))
253 break;
254 insize--;
255 size++;
256 inbuf++;
257 }
258 return size;
259 }
261 gboolean
262 gst_ducati_viddec_codec_flush (GstDucatiVidDec * self, gboolean eos);
264 G_END_DECLS
266 #endif /* __GST_DUCATIVIDDEC_H__ */