3d481f42ba16160a1547035efa7558f9e46b8715
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 #define MAX_BACKLOG_FRAMES 16
49 struct _GstDucatiVidDec
50 {
51 GstElement parent;
53 GstPad *sinkpad, *srcpad;
55 GstDRMBufferPool *pool;
57 /* minimum output size required by the codec: */
58 gint outsize;
60 /* minimum number of buffers required by the codec: */
61 gint min_buffers;
63 /* input (unpadded, unaligned) size of video: */
64 gint input_width, input_height;
66 /* input (unpadded, aligned to MB) size of video: */
67 gint width, height;
69 gint fps_n, fps_d;
71 /* output (padded) size including any codec padding: */
72 gint padded_width, padded_height;
74 /* output stride (>= padded_width) */
75 gint stride;
77 gboolean interlaced;
79 struct omap_bo *input_bo;
80 /* input buffer, allocated when codec is created: */
81 guint8 *input;
83 /* number of bytes pushed to input on current frame: */
84 gint in_size;
86 /* the crop to attach to output buffers: */
87 GstVideoCrop *crop;
89 /* on first output buffer, we need to send crop info to sink.. and some
90 * operations like flushing should be avoided if we haven't sent any
91 * input buffers:
92 */
93 gboolean first_out_buffer, first_in_buffer;
94 gboolean send_crop_event;
96 GstSegment segment;
97 gdouble qos_proportion;
98 GstClockTime qos_earliest_time;
100 gboolean need_out_buf;
102 /* by default, codec_data from sinkpad is prepended to first buffer: */
103 GstBuffer *codec_data;
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 GHashTable *passed_in_bufs;
123 #define NDTS 32
124 GstClockTime dts_queue[NDTS];
125 gint dts_ridx, dts_widx;
126 GstClockTime last_dts, last_pts;
128 Engine_Handle engine;
129 VIDDEC3_Handle codec;
130 VIDDEC3_Params *params;
131 VIDDEC3_DynamicParams *dynParams;
132 VIDDEC3_Status *status;
133 XDM2_BufDesc *inBufs;
134 XDM2_BufDesc *outBufs;
135 VIDDEC3_InArgs *inArgs;
136 VIDDEC3_OutArgs *outArgs;
138 XDAS_Int16 pageMemType;
139 struct omap_device *device;
141 /* Frames waiting to be reordered */
142 GstBuffer *backlog_frames[MAX_BACKLOG_FRAMES + 1];
143 gint backlog_maxframes;
144 gint backlog_nframes;
145 gint backlog_default_maxframes;
146 };
148 struct _GstDucatiVidDecClass
149 {
150 GstElementClass parent_class;
152 const gchar *codec_name;
154 /**
155 * Parse codec specific fields the given caps structure. The base-
156 * class implementation of this method handles standard stuff like
157 * width/height/framerate/codec_data.
158 */
159 gboolean (*parse_caps) (GstDucatiVidDec * self, GstStructure * s);
161 /**
162 * Called when the input buffer size changes, to recalculate codec required
163 * output buffer size and minimum count
164 */
165 void (*update_buffer_size) (GstDucatiVidDec * self);
167 /**
168 * Called to allocate/initialize params/dynParams/status/inArgs/outArgs
169 */
170 gboolean (*allocate_params) (GstDucatiVidDec * self, gint params_sz,
171 gint dynparams_sz, gint status_sz, gint inargs_sz, gint outargs_sz);
173 /**
174 * Push input data into codec's input buffer, returning a sub-buffer of
175 * any remaining data, or NULL if none. Consumes reference to 'buf'
176 */
177 GstBuffer * (*push_input) (GstDucatiVidDec * self, GstBuffer * buf);
179 /**
180 * Called to handle errors returned by VIDDEC3_process.
181 */
182 gint (*handle_error) (GstDucatiVidDec * self, gint ret, gint extended_error,
183 gint status_extended_error);
185 /**
186 * Called to check whether it's a good idea to drop buf or not.
187 */
188 gboolean (*can_drop_frame) (GstDucatiVidDec * self, GstBuffer * buf, gint64 diff);
190 gboolean (*query) (GstDucatiVidDec * self, GstPad * pad, GstQuery * query,
191 gboolean * forward);
193 /**
194 * Called to push a decoder buffer. Consumes reference to 'buf'.
195 */
196 GstFlowReturn (*push_output) (GstDucatiVidDec * self, GstBuffer * buf);
198 /**
199 * Called before a flush happens.
200 */
201 void (*on_flush) (GstDucatiVidDec * self, gboolean eos);
203 /**
204 * Called to set new caps on the sink pad.
205 */
206 gboolean (*set_sink_caps) (GstDucatiVidDec * self, GstCaps *caps);
207 };
209 GType gst_ducati_viddec_get_type (void);
211 /* helper methods for derived classes: */
213 static inline void
214 push_input (GstDucatiVidDec * self, const guint8 *in, gint sz)
215 {
216 GST_DEBUG_OBJECT (self, "push: %d bytes)", sz);
217 memcpy (self->input + self->in_size, in, sz);
218 self->in_size += sz;
219 }
221 static inline int
222 check_start_code (const guint8 *sc, gint scsize,
223 const guint8 *inbuf, gint insize)
224 {
225 if (insize < scsize)
226 return FALSE;
228 while (scsize) {
229 if (*sc != *inbuf)
230 return FALSE;
231 scsize--;
232 sc++;
233 inbuf++;
234 }
236 return TRUE;
237 }
239 static inline int
240 find_start_code (const guint8 *sc, gint scsize,
241 const guint8 *inbuf, gint insize)
242 {
243 gint size = 0;
244 while (insize) {
245 if (check_start_code (sc, scsize, inbuf, insize))
246 break;
247 insize--;
248 size++;
249 inbuf++;
250 }
251 return size;
252 }
254 gboolean
255 gst_ducati_viddec_codec_flush (GstDucatiVidDec * self, gboolean eos);
257 G_END_DECLS
259 #endif /* __GST_DUCATIVIDDEC_H__ */