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 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include "gstducatividdec.h"
25 #include "gstducatibufferpriv.h"
27 GST_BOILERPLATE (GstDucatiVidDec, gst_ducati_viddec, GstElement,
28 GST_TYPE_ELEMENT);
30 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
31 GST_PAD_SRC,
32 GST_PAD_ALWAYS,
33 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV_STRIDED ("NV12", "[ 0, max ]"))
34 );
36 enum
37 {
38 PROP_0,
39 PROP_VERSION,
40 };
42 /* helper functions */
44 static void
45 engine_close (GstDucatiVidDec * self)
46 {
47 if (self->engine) {
48 Engine_close (self->engine);
49 self->engine = NULL;
50 }
52 if (self->params) {
53 dce_free (self->params);
54 self->params = NULL;
55 }
57 if (self->dynParams) {
58 dce_free (self->dynParams);
59 self->dynParams = NULL;
60 }
62 if (self->status) {
63 dce_free (self->status);
64 self->status = NULL;
65 }
67 if (self->inBufs) {
68 dce_free (self->inBufs);
69 self->inBufs = NULL;
70 }
72 if (self->outBufs) {
73 dce_free (self->outBufs);
74 self->outBufs = NULL;
75 }
77 if (self->inArgs) {
78 dce_free (self->inArgs);
79 self->inArgs = NULL;
80 }
82 if (self->outArgs) {
83 dce_free (self->outArgs);
84 self->outArgs = NULL;
85 }
87 if (self->device) {
88 dce_deinit (self->device);
89 self->device = NULL;
90 }
91 }
93 static gboolean
94 engine_open (GstDucatiVidDec * self)
95 {
96 gboolean ret;
97 int ec;
99 if (G_UNLIKELY (self->engine)) {
100 return TRUE;
101 }
103 if (self->device == NULL) {
104 self->device = dce_init ();
105 if (self->device == NULL) {
106 GST_ERROR_OBJECT (self, "dce_init() failed");
107 return FALSE;
108 }
109 }
111 GST_DEBUG_OBJECT (self, "opening engine");
113 self->engine = Engine_open ((String) "ivahd_vidsvr", NULL, &ec);
114 if (G_UNLIKELY (!self->engine)) {
115 GST_ERROR_OBJECT (self, "could not create engine");
116 return FALSE;
117 }
119 ret = GST_DUCATIVIDDEC_GET_CLASS (self)->allocate_params (self,
120 sizeof (IVIDDEC3_Params), sizeof (IVIDDEC3_DynamicParams),
121 sizeof (IVIDDEC3_Status), sizeof (IVIDDEC3_InArgs),
122 sizeof (IVIDDEC3_OutArgs));
124 return ret;
125 }
127 static void
128 codec_delete (GstDucatiVidDec * self)
129 {
130 if (self->pool) {
131 gst_drm_buffer_pool_destroy (self->pool);
132 self->pool = NULL;
133 }
135 if (self->codec) {
136 VIDDEC3_delete (self->codec);
137 self->codec = NULL;
138 }
140 if (self->input_bo) {
141 omap_bo_del (self->input_bo);
142 self->input_bo = NULL;
143 }
144 }
146 static gboolean
147 codec_create (GstDucatiVidDec * self)
148 {
149 gint err;
150 const gchar *codec_name;
152 codec_delete (self);
154 if (G_UNLIKELY (!self->engine)) {
155 GST_ERROR_OBJECT (self, "no engine");
156 return FALSE;
157 }
159 /* these need to be set before VIDDEC3_create */
160 self->params->maxWidth = self->width;
161 self->params->maxHeight = self->height;
163 codec_name = GST_DUCATIVIDDEC_GET_CLASS (self)->codec_name;
165 /* create codec: */
166 GST_DEBUG_OBJECT (self, "creating codec: %s", codec_name);
167 self->codec =
168 VIDDEC3_create (self->engine, (String) codec_name, self->params);
170 if (!self->codec) {
171 return FALSE;
172 }
174 err =
175 VIDDEC3_control (self->codec, XDM_SETPARAMS, self->dynParams,
176 self->status);
177 if (err) {
178 GST_ERROR_OBJECT (self, "failed XDM_SETPARAMS");
179 return FALSE;
180 }
182 self->first_in_buffer = TRUE;
183 self->first_out_buffer = TRUE;
185 /* allocate input buffer and initialize inBufs: */
186 self->input_bo = omap_bo_new (self->device,
187 self->width * self->height, OMAP_BO_WC);
188 self->input = omap_bo_map (self->input_bo);
189 self->inBufs->numBufs = 1;
190 self->inBufs->descs[0].buf = (XDAS_Int8 *) omap_bo_handle (self->input_bo);
192 return TRUE;
193 }
195 static inline GstBuffer *
196 codec_buffer_pool_get (GstDucatiVidDec * self, GstBuffer * buf)
197 {
198 if (G_UNLIKELY (!self->pool)) {
199 guint size = gst_video_format_get_size (GST_VIDEO_FORMAT_NV12,
200 self->padded_width, self->padded_height);
202 GST_DEBUG_OBJECT (self, "creating bufferpool");
203 self->pool = gst_drm_buffer_pool_new (GST_ELEMENT (self),
204 dce_get_fd (), GST_PAD_CAPS (self->srcpad), size);
205 }
206 return GST_BUFFER (gst_drm_buffer_pool_get (self->pool, FALSE));
207 }
209 static GstDucatiBufferPriv *
210 get_buffer_priv (GstDucatiVidDec * self, GstBuffer * buf)
211 {
212 GstDucatiBufferPriv *priv = gst_ducati_buffer_priv_get (buf);
213 if (!priv) {
214 GstVideoFormat format = GST_VIDEO_FORMAT_NV12;
215 GstDmaBuf *dmabuf = gst_buffer_get_dma_buf (buf);
217 /* if it isn't a dmabuf buffer that we can import, then there
218 * is nothing we can do with it:
219 */
220 if (!dmabuf) {
221 GST_DEBUG_OBJECT (self, "not importing non dmabuf buffer");
222 return NULL;
223 }
225 priv = gst_ducati_buffer_priv_new ();
227 priv->bo = omap_bo_from_dmabuf (self->device, gst_dma_buf_get_fd (dmabuf));
229 priv->uv_offset = gst_video_format_get_component_offset (format,
230 1, self->stride, self->padded_height);
231 priv->size = gst_video_format_get_size (format,
232 self->stride, self->padded_height);
234 gst_ducati_buffer_priv_set (buf, priv);
235 gst_mini_object_unref (GST_MINI_OBJECT (priv));
236 }
237 return priv;
238 }
240 static XDAS_Int32
241 codec_prepare_outbuf (GstDucatiVidDec * self, GstBuffer ** buf,
242 gboolean force_internal)
243 {
244 GstDucatiBufferPriv *priv = NULL;
246 if (!force_internal)
247 priv = get_buffer_priv (self, *buf);
249 if (!priv) {
250 GstBuffer *orig = *buf;
252 GST_DEBUG_OBJECT (self, "internal bufferpool forced");
253 *buf = codec_buffer_pool_get (self, NULL);
254 GST_BUFFER_TIMESTAMP (*buf) = GST_BUFFER_TIMESTAMP (orig);
255 GST_BUFFER_DURATION (*buf) = GST_BUFFER_DURATION (orig);
256 gst_buffer_unref (orig);
257 return codec_prepare_outbuf (self, buf, FALSE);
258 }
260 self->outBufs->numBufs = 2;
261 self->outBufs->descs[0].memType = XDM_MEMTYPE_BO;
262 self->outBufs->descs[0].buf = (XDAS_Int8 *) omap_bo_handle (priv->bo);
263 self->outBufs->descs[0].bufSize.bytes = priv->uv_offset;
264 self->outBufs->descs[1].memType = XDM_MEMTYPE_BO_OFFSET;
265 self->outBufs->descs[1].buf = (XDAS_Int8 *) priv->uv_offset;
266 self->outBufs->descs[1].bufSize.bytes = priv->size - priv->uv_offset;
268 return (XDAS_Int32) * buf; // XXX use lookup table
269 }
271 static GstBuffer *
272 codec_get_outbuf (GstDucatiVidDec * self, XDAS_Int32 id)
273 {
274 GstBuffer *buf = (GstBuffer *) id; // XXX use lookup table
275 if (buf) {
276 gst_buffer_ref (buf);
277 }
278 return buf;
279 }
281 static void
282 codec_unlock_outbuf (GstDucatiVidDec * self, XDAS_Int32 id)
283 {
284 GstBuffer *buf = (GstBuffer *) id; // XXX use lookup table
285 if (buf) {
286 GST_DEBUG_OBJECT (self, "free buffer: %d %p", id, buf);
287 gst_buffer_unref (buf);
288 }
289 }
291 static gint
292 codec_process (GstDucatiVidDec * self, gboolean send, gboolean flush,
293 GstFlowReturn * flow_ret)
294 {
295 gint err;
296 GstClockTime t;
297 GstBuffer *outbuf = NULL;
298 gint i;
299 GstDucatiVidDecClass *klass = GST_DUCATIVIDDEC_GET_CLASS (self);
300 GstFlowReturn ret = GST_FLOW_OK;
301 if (flow_ret)
302 /* never leave flow_ret uninitialized */
303 *flow_ret = GST_FLOW_OK;
305 memset (&self->outArgs->outputID, 0, sizeof (self->outArgs->outputID));
306 memset (&self->outArgs->freeBufID, 0, sizeof (self->outArgs->freeBufID));
308 t = gst_util_get_timestamp ();
309 err = VIDDEC3_process (self->codec,
310 self->inBufs, self->outBufs, self->inArgs, self->outArgs);
311 GST_DEBUG_OBJECT (self, "%10dns", (gint) (gst_util_get_timestamp () - t));
313 if (err) {
314 GST_WARNING_OBJECT (self, "err=%d, extendedError=%08x",
315 err, self->outArgs->extendedError);
316 gst_ducati_log_extended_error_info (self->outArgs->extendedError);
318 err = VIDDEC3_control (self->codec, XDM_GETSTATUS,
319 self->dynParams, self->status);
320 if (!err) {
321 GST_WARNING_OBJECT (self, "XDM_GETSTATUS: err=%d, extendedError=%08x",
322 err, self->status->extendedError);
323 gst_ducati_log_extended_error_info (self->outArgs->extendedError);
324 }
326 if (flush)
327 err = XDM_EFAIL;
328 else
329 err = klass->handle_error (self, err,
330 self->outArgs->extendedError, self->status->extendedError);
331 }
333 for (i = 0; i < IVIDEO2_MAX_IO_BUFFERS && self->outArgs->outputID[i]; i++) {
334 gboolean interlaced;
336 outbuf = codec_get_outbuf (self, self->outArgs->outputID[i]);
338 interlaced =
339 self->outArgs->decodedBufs.contentType ==
340 IVIDEO_PROGRESSIVE ? FALSE : TRUE;
342 /* if send is FALSE, don't try to renegotiate as we could be flushing during
343 * a PAUSED->READY state change
344 */
345 if (send && interlaced != self->interlaced) {
346 GstCaps *caps;
348 GST_WARNING_OBJECT (self, "upstream set interlaced=%d but codec "
349 "thinks interlaced=%d... trusting codec", self->interlaced,
350 interlaced);
352 self->interlaced = interlaced;
354 caps =
355 gst_caps_make_writable (gst_pad_get_negotiated_caps (self->srcpad));
356 GST_INFO_OBJECT (self, "changing interlace field in caps");
357 gst_caps_set_simple (caps, "interlaced", G_TYPE_BOOLEAN, interlaced,
358 NULL);
359 gst_drm_buffer_pool_set_caps (self->pool, caps);
360 if (!gst_pad_set_caps (self->srcpad, caps)) {
361 GST_ERROR_OBJECT (self,
362 "downstream didn't want to change interlace mode");
363 err = XDM_EFAIL;
364 }
365 gst_caps_unref (caps);
367 /* this buffer still has the old caps so we skip it */
368 send = FALSE;
369 }
371 if (G_UNLIKELY (self->send_crop_event) && send) {
372 gint crop_width, crop_height;
373 GstDucatiVidDecClass *klass = GST_DUCATIVIDDEC_GET_CLASS (self);
375 /* send region of interest to sink on first buffer: */
376 XDM_Rect *r = &(self->outArgs->displayBufs.bufDesc[0].activeFrameRegion);
378 crop_width = r->bottomRight.x - r->topLeft.x;
379 crop_height = r->bottomRight.y - r->topLeft.y;
381 if (crop_width > self->input_width)
382 crop_width = self->input_width;
383 if (crop_height > self->input_height)
384 crop_height = self->input_height;
386 if (self->interlaced && !strcmp (klass->codec_name, "ivahd_mpeg2vdec"))
387 crop_height = crop_height / 2;
389 GST_INFO_OBJECT (self, "active frame region %d, %d, %d, %d, crop %dx%d",
390 r->topLeft.x, r->topLeft.y, r->bottomRight.x, r->bottomRight.y,
391 crop_width, crop_height);
393 gst_pad_push_event (self->srcpad,
394 gst_event_new_crop (r->topLeft.y, r->topLeft.x,
395 crop_width, crop_height));
397 if (self->crop)
398 gst_video_crop_unref (self->crop);
400 self->crop = gst_video_crop_new (r->topLeft.y, r->topLeft.x,
401 crop_width, crop_height);
403 self->send_crop_event = FALSE;
404 }
406 if (G_UNLIKELY (self->first_out_buffer) && send) {
407 GstDRMBufferPool *pool;
408 self->first_out_buffer = FALSE;
410 /* Destroy the pool so the buffers we used so far are eventually released.
411 * The pool will be recreated if needed.
412 */
413 pool = self->pool;
414 self->pool = NULL;
415 gst_drm_buffer_pool_destroy (pool);
416 }
418 if (send) {
419 GstClockTime ts;
421 ts = GST_BUFFER_TIMESTAMP (outbuf);
423 GST_DEBUG_OBJECT (self, "got buffer: %d %p (%" GST_TIME_FORMAT ")",
424 i, outbuf, GST_TIME_ARGS (ts));
426 if (self->ts_may_be_pts) {
427 if ((self->last_pts != GST_CLOCK_TIME_NONE) && (self->last_pts > ts)) {
428 GST_DEBUG_OBJECT (self, "detected PTS going backwards, "
429 "enabling ts_is_pts");
430 self->ts_is_pts = TRUE;
431 }
432 }
434 self->last_pts = ts;
436 if (self->dts_ridx != self->dts_widx) {
437 ts = self->dts_queue[self->dts_ridx++ % NDTS];
438 }
440 if (self->ts_is_pts) {
441 /* if we have a queued DTS from demuxer, use that instead: */
442 GST_BUFFER_TIMESTAMP (outbuf) = ts;
443 GST_DEBUG_OBJECT (self, "fixed ts: %d %p (%" GST_TIME_FORMAT ")",
444 i, outbuf, GST_TIME_ARGS (ts));
445 }
447 if (GST_BUFFER_CAPS (outbuf) &&
448 !gst_caps_is_equal (GST_BUFFER_CAPS (outbuf),
449 GST_PAD_CAPS (self->srcpad))) {
450 /* this looks a bit scary but it's really just to change the interlace=
451 * field in caps when we start as !interlaced and the codec detects
452 * otherwise */
453 GST_WARNING_OBJECT (self, "overriding buffer caps to fix "
454 "interlace mismatch");
455 outbuf = gst_buffer_make_metadata_writable (outbuf);
456 gst_buffer_set_caps (outbuf, GST_PAD_CAPS (self->srcpad));
457 }
459 if (self->crop)
460 gst_buffer_set_video_crop (outbuf, self->crop);
462 ret = gst_pad_push (self->srcpad, outbuf);
463 if (flow_ret)
464 *flow_ret = ret;
465 if (ret != GST_FLOW_OK) {
466 GST_WARNING_OBJECT (self, "push failed %s", gst_flow_get_name (ret));
467 /* just unref the remaining buffers (if any) */
468 send = FALSE;
469 }
470 } else {
471 GST_DEBUG_OBJECT (self, "free buffer: %d %p", i, outbuf);
472 gst_buffer_unref (outbuf);
473 }
474 }
476 for (i = 0; i < IVIDEO2_MAX_IO_BUFFERS && self->outArgs->freeBufID[i]; i++) {
477 codec_unlock_outbuf (self, self->outArgs->freeBufID[i]);
478 }
480 return err;
481 }
483 /** call control(FLUSH), and then process() to pop out all buffers */
484 gboolean
485 gst_ducati_viddec_codec_flush (GstDucatiVidDec * self, gboolean eos)
486 {
487 gint err = FALSE;
489 GST_DEBUG_OBJECT (self, "flush: eos=%d", eos);
491 /* note: flush is synchronized against _chain() to avoid calling
492 * the codec from multiple threads
493 */
494 GST_PAD_STREAM_LOCK (self->sinkpad);
496 self->dts_ridx = self->dts_widx = 0;
497 self->last_dts = self->last_pts = GST_CLOCK_TIME_NONE;
498 self->ts_may_be_pts = TRUE;
499 self->ts_is_pts = FALSE;
500 self->wait_keyframe = TRUE;
502 if (G_UNLIKELY (self->first_in_buffer)) {
503 goto out;
504 }
506 if (G_UNLIKELY (!self->codec)) {
507 GST_WARNING_OBJECT (self, "no codec");
508 goto out;
509 }
511 err = VIDDEC3_control (self->codec, XDM_FLUSH, self->dynParams, self->status);
512 if (err) {
513 GST_ERROR_OBJECT (self, "failed XDM_FLUSH");
514 goto out;
515 }
517 self->inBufs->descs[0].bufSize.bytes = 0;
518 self->inArgs->numBytes = 0;
519 self->inArgs->inputID = 0;
521 do {
522 err = codec_process (self, eos, TRUE, NULL);
523 } while (err != XDM_EFAIL);
525 /* reset outArgs in case we're flushing in codec_process trying to do error
526 * recovery */
527 memset (&self->outArgs->outputID, 0, sizeof (self->outArgs->outputID));
528 memset (&self->outArgs->freeBufID, 0, sizeof (self->outArgs->freeBufID));
530 /* on a flush, it is normal (and not an error) for the last _process() call
531 * to return an error..
532 */
533 err = XDM_EOK;
535 out:
536 GST_PAD_STREAM_UNLOCK (self->sinkpad);
537 GST_DEBUG_OBJECT (self, "done");
539 return !err;
540 }
542 /* GstDucatiVidDec vmethod default implementations */
544 static gboolean
545 gst_ducati_viddec_parse_caps (GstDucatiVidDec * self, GstStructure * s)
546 {
547 const GValue *codec_data;
548 gint w, h;
550 if (gst_structure_get_int (s, "width", &self->input_width) &&
551 gst_structure_get_int (s, "height", &self->input_height)) {
553 h = ALIGN2 (self->input_height, 4); /* round up to MB */
554 w = ALIGN2 (self->input_width, 4); /* round up to MB */
556 /* if we've already created codec, but the resolution has changed, we
557 * need to re-create the codec:
558 */
559 if (G_UNLIKELY (self->codec)) {
560 if ((h != self->height) || (w != self->width)) {
561 codec_delete (self);
562 }
563 }
565 self->width = w;
566 self->height = h;
568 codec_data = gst_structure_get_value (s, "codec_data");
570 if (codec_data) {
571 GstBuffer *buffer = gst_value_get_buffer (codec_data);
572 GST_DEBUG_OBJECT (self, "codec_data: %" GST_PTR_FORMAT, buffer);
573 self->codec_data = gst_buffer_ref (buffer);
574 }
576 return TRUE;
577 }
579 return FALSE;
580 }
582 static gboolean
583 gst_ducati_viddec_allocate_params (GstDucatiVidDec * self, gint params_sz,
584 gint dynparams_sz, gint status_sz, gint inargs_sz, gint outargs_sz)
585 {
587 /* allocate params: */
588 self->params = dce_alloc (params_sz);
589 if (G_UNLIKELY (!self->params)) {
590 return FALSE;
591 }
592 self->params->size = params_sz;
593 self->params->maxFrameRate = 30000;
594 self->params->maxBitRate = 10000000;
596 self->params->dataEndianness = XDM_BYTE;
597 self->params->forceChromaFormat = XDM_YUV_420SP;
598 self->params->operatingMode = IVIDEO_DECODE_ONLY;
600 self->params->displayBufsMode = IVIDDEC3_DISPLAYBUFS_EMBEDDED;
601 self->params->inputDataMode = IVIDEO_ENTIREFRAME;
602 self->params->outputDataMode = IVIDEO_ENTIREFRAME;
603 self->params->numInputDataUnits = 0;
604 self->params->numOutputDataUnits = 0;
606 self->params->metadataType[0] = IVIDEO_METADATAPLANE_NONE;
607 self->params->metadataType[1] = IVIDEO_METADATAPLANE_NONE;
608 self->params->metadataType[2] = IVIDEO_METADATAPLANE_NONE;
609 self->params->errorInfoMode = IVIDEO_ERRORINFO_OFF;
611 /* allocate dynParams: */
612 self->dynParams = dce_alloc (dynparams_sz);
613 if (G_UNLIKELY (!self->dynParams)) {
614 return FALSE;
615 }
616 self->dynParams->size = dynparams_sz;
617 self->dynParams->decodeHeader = XDM_DECODE_AU;
618 self->dynParams->displayWidth = 0;
619 self->dynParams->frameSkipMode = IVIDEO_NO_SKIP;
620 self->dynParams->newFrameFlag = XDAS_TRUE;
622 /* allocate status: */
623 self->status = dce_alloc (status_sz);
624 if (G_UNLIKELY (!self->status)) {
625 return FALSE;
626 }
627 self->status->size = status_sz;
629 /* allocate inBufs/outBufs: */
630 self->inBufs = dce_alloc (sizeof (XDM2_BufDesc));
631 self->outBufs = dce_alloc (sizeof (XDM2_BufDesc));
632 if (G_UNLIKELY (!self->inBufs) || G_UNLIKELY (!self->outBufs)) {
633 return FALSE;
634 }
636 /* allocate inArgs/outArgs: */
637 self->inArgs = dce_alloc (inargs_sz);
638 self->outArgs = dce_alloc (outargs_sz);
639 if (G_UNLIKELY (!self->inArgs) || G_UNLIKELY (!self->outArgs)) {
640 return FALSE;
641 }
642 self->inArgs->size = inargs_sz;
643 self->outArgs->size = outargs_sz;
645 return TRUE;
646 }
648 static GstBuffer *
649 gst_ducati_viddec_push_input (GstDucatiVidDec * self, GstBuffer * buf)
650 {
651 if (G_UNLIKELY (self->first_in_buffer) && self->codec_data) {
652 push_input (self, GST_BUFFER_DATA (self->codec_data),
653 GST_BUFFER_SIZE (self->codec_data));
654 }
656 /* just copy entire buffer */
657 push_input (self, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
658 gst_buffer_unref (buf);
660 return NULL;
661 }
663 static gint
664 gst_ducati_viddec_handle_error (GstDucatiVidDec * self, gint ret,
665 gint extended_error, gint status_extended_error)
666 {
667 if (XDM_ISFATALERROR (extended_error))
668 ret = XDM_EFAIL;
669 else
670 ret = XDM_EOK;
672 return ret;
673 }
675 /* GstElement vmethod implementations */
677 static gboolean
678 gst_ducati_viddec_sink_setcaps (GstPad * pad, GstCaps * caps)
679 {
680 gboolean ret = TRUE;
681 GstDucatiVidDec *self = GST_DUCATIVIDDEC (gst_pad_get_parent (pad));
682 GstDucatiVidDecClass *klass = GST_DUCATIVIDDEC_GET_CLASS (self);
683 GstStructure *s;
684 GstCaps *outcaps = NULL;
685 GstStructure *out_s;
686 gint par_width, par_height;
687 gboolean par_present;
689 GST_INFO_OBJECT (self, "setcaps (sink): %" GST_PTR_FORMAT, caps);
691 s = gst_caps_get_structure (caps, 0);
692 if (!klass->parse_caps (self, s)) {
693 GST_WARNING_OBJECT (self, "missing required fields");
694 ret = FALSE;
695 goto out;
696 }
698 /* update output/padded sizes */
699 klass->update_buffer_size (self);
701 if (!gst_structure_get_fraction (s, "framerate", &self->fps_n, &self->fps_d)) {
702 self->fps_n = 0;
703 self->fps_d = 1;
704 }
705 gst_structure_get_boolean (s, "interlaced", &self->interlaced);
706 par_present = gst_structure_get_fraction (s, "pixel-aspect-ratio",
707 &par_width, &par_height);
709 outcaps = gst_pad_get_allowed_caps (self->srcpad);
710 if (outcaps) {
711 outcaps = gst_caps_make_writable (outcaps);
712 gst_caps_truncate (outcaps);
713 if (gst_caps_is_empty (outcaps)) {
714 gst_caps_unref (outcaps);
715 outcaps = NULL;
716 }
717 }
719 if (!outcaps) {
720 /* note: default to non-strided for better compatibility with
721 * other gst elements that don't understand stride:
722 */
723 outcaps = gst_caps_new_simple ("video/x-raw-yuv",
724 "format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('N', 'V', '1', '2'), NULL);
725 }
727 out_s = gst_caps_get_structure (outcaps, 0);
728 gst_structure_set (out_s,
729 "width", G_TYPE_INT, self->padded_width,
730 "height", G_TYPE_INT, self->padded_height,
731 "framerate", GST_TYPE_FRACTION, self->fps_n, self->fps_d, NULL);
732 if (par_present)
733 gst_structure_set (out_s, "pixel-aspect-ratio", GST_TYPE_FRACTION,
734 par_width, par_height, NULL);
736 if (self->interlaced)
737 gst_structure_set (out_s, "interlaced", G_TYPE_BOOLEAN, TRUE, NULL);
739 if (!strcmp (gst_structure_get_name (out_s), "video/x-raw-yuv-strided")) {
740 if (!gst_structure_get_int (out_s, "rowstride", &self->stride)) {
741 self->stride = 4096;
742 gst_structure_set (out_s, "rowstride", G_TYPE_INT, self->stride, NULL);
743 }
744 } else {
745 self->stride = gst_video_format_get_row_stride (GST_VIDEO_FORMAT_NV12,
746 0, self->padded_width);
747 }
749 self->outsize = gst_video_format_get_size (GST_VIDEO_FORMAT_NV12,
750 self->stride, self->padded_height);
752 GST_INFO_OBJECT (self, "outsize %d stride %d outcaps: %" GST_PTR_FORMAT,
753 self->outsize, self->stride, outcaps);
755 if (!self->first_in_buffer) {
756 /* Caps changed mid stream. We flush the codec to unlock all the potentially
757 * locked buffers. This is needed for downstream sinks that provide a
758 * buffer pool and need to destroy all the outstanding buffers before they
759 * can negotiate new caps (hello v4l2sink).
760 */
761 gst_ducati_viddec_codec_flush (self, FALSE);
762 }
764 /* (re)send a crop event when caps change */
765 self->send_crop_event = TRUE;
767 ret = gst_pad_set_caps (self->srcpad, outcaps);
769 GST_INFO_OBJECT (self, "set caps done %d, %" GST_PTR_FORMAT, ret, outcaps);
771 out:
772 if (outcaps)
773 gst_caps_unref (outcaps);
774 gst_object_unref (self);
776 return ret;
777 }
779 static GstCaps *
780 gst_ducati_viddec_src_getcaps (GstPad * pad)
781 {
782 GstCaps *caps = NULL;
783 GstCaps *outcaps = NULL;
784 int i;
786 caps = GST_PAD_CAPS (pad);
787 if (caps == NULL) {
788 outcaps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
789 return outcaps;
790 }
792 outcaps = gst_caps_new_empty ();
794 /* allow -rowstrided and regular yuv */
795 for (i = 0; i < gst_caps_get_size (caps); i++) {
796 GstStructure *structure;
797 GstStructure *modified_structure;
798 GValue value = { 0 };
800 structure = gst_caps_get_structure (caps, i);
801 gst_caps_append_structure (outcaps, gst_structure_copy (structure));
802 modified_structure = gst_structure_copy (structure);
804 if (gst_structure_has_name (structure, "video/x-raw-yuv")) {
805 gst_structure_set_name (modified_structure, "video/x-raw-yuv-strided");
806 g_value_init (&value, GST_TYPE_INT_RANGE);
807 gst_value_set_int_range (&value, 0, G_MAXINT);
808 gst_structure_set_value (modified_structure, "rowstride", &value);
809 gst_caps_append_structure (outcaps, modified_structure);
810 g_value_unset (&value);
811 } else {
812 gst_structure_set_name (modified_structure, "video/x-raw-yuv");
813 gst_structure_remove_field (modified_structure, "rowstride");
814 gst_caps_append_structure (outcaps, modified_structure);
815 }
816 }
817 return outcaps;
818 }
820 static gboolean
821 gst_ducati_viddec_query (GstDucatiVidDec * self, GstPad * pad,
822 GstQuery * query, gboolean * forward)
823 {
824 gboolean res = TRUE;
826 switch (GST_QUERY_TYPE (query)) {
827 case GST_QUERY_BUFFERS:
828 GST_DEBUG_OBJECT (self, "min buffers: %d", self->min_buffers);
829 gst_query_set_buffers_count (query, self->min_buffers);
831 GST_DEBUG_OBJECT (self, "min dimensions: %dx%d",
832 self->padded_width, self->padded_height);
833 gst_query_set_buffers_dimensions (query,
834 self->padded_width, self->padded_height);
835 *forward = FALSE;
836 break;
837 default:
838 break;
839 }
842 return res;
843 }
845 static gboolean
846 gst_ducati_viddec_src_query (GstPad * pad, GstQuery * query)
847 {
848 gboolean res = TRUE, forward = TRUE;
849 GstDucatiVidDec *self = GST_DUCATIVIDDEC (GST_OBJECT_PARENT (pad));
850 GstDucatiVidDecClass *klass = GST_DUCATIVIDDEC_GET_CLASS (self);
852 GST_DEBUG_OBJECT (self, "query: %" GST_PTR_FORMAT, query);
853 res = klass->query (self, pad, query, &forward);
854 if (res && forward)
855 res = gst_pad_query_default (pad, query);
857 return res;
858 }
860 static gboolean
861 gst_ducati_viddec_do_qos (GstDucatiVidDec * self, GstBuffer * buf)
862 {
863 GstClockTime timestamp, qostime;
864 GstDucatiVidDecClass *klass = GST_DUCATIVIDDEC_GET_CLASS (self);
865 gint64 diff;
867 if (self->wait_keyframe) {
868 if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
869 GST_INFO_OBJECT (self, "skipping until the next keyframe");
870 return FALSE;
871 }
873 self->wait_keyframe = FALSE;
874 }
876 timestamp = GST_BUFFER_TIMESTAMP (buf);
877 if (self->segment.format != GST_FORMAT_TIME ||
878 self->qos_earliest_time == GST_CLOCK_TIME_NONE)
879 goto no_qos;
881 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (timestamp)))
882 goto no_qos;
884 qostime = gst_segment_to_running_time (&self->segment,
885 GST_FORMAT_TIME, timestamp);
886 if (G_UNLIKELY (!GST_CLOCK_TIME_IS_VALID (qostime)))
887 /* out of segment */
888 goto no_qos;
890 /* see how our next timestamp relates to the latest qos timestamp. negative
891 * values mean we are early, positive values mean we are too late. */
892 diff = GST_CLOCK_DIFF (qostime, self->qos_earliest_time);
894 GST_DEBUG_OBJECT (self, "QOS: qostime %" GST_TIME_FORMAT
895 ", earliest %" GST_TIME_FORMAT " diff %" G_GINT64_FORMAT " proportion %f",
896 GST_TIME_ARGS (qostime), GST_TIME_ARGS (self->qos_earliest_time), diff,
897 self->qos_proportion);
899 if (klass->drop_frame (self, buf, diff)) {
900 GST_INFO_OBJECT (self, "dropping frame");
901 return FALSE;
902 }
904 no_qos:
905 return TRUE;
906 }
908 static gboolean
909 gst_ducati_viddec_drop_frame (GstDucatiVidDec * self, GstBuffer * buf,
910 gint64 diff)
911 {
912 gboolean is_keyframe = !GST_BUFFER_FLAG_IS_SET (buf,
913 GST_BUFFER_FLAG_DELTA_UNIT);
915 if (diff >= 0 && !is_keyframe)
916 return TRUE;
918 return FALSE;
919 }
921 static GstFlowReturn
922 gst_ducati_viddec_chain (GstPad * pad, GstBuffer * buf)
923 {
924 GstDucatiVidDec *self = GST_DUCATIVIDDEC (GST_OBJECT_PARENT (pad));
925 GstClockTime ts = GST_BUFFER_TIMESTAMP (buf);
926 GstFlowReturn ret = GST_FLOW_OK;
927 Int32 err;
928 GstBuffer *outbuf = NULL;
929 GstCaps *outcaps = NULL;
930 gboolean decode;
932 if (G_UNLIKELY (!self->engine)) {
933 GST_ERROR_OBJECT (self, "no engine");
934 gst_buffer_unref (buf);
935 return GST_FLOW_ERROR;
936 }
938 GST_DEBUG_OBJECT (self, "chain: %" GST_TIME_FORMAT " (%d bytes, flags %d)",
939 GST_TIME_ARGS (ts), GST_BUFFER_SIZE (buf), GST_BUFFER_FLAGS (buf));
941 decode = gst_ducati_viddec_do_qos (self, buf);
942 if (!decode) {
943 gst_buffer_unref (buf);
944 return GST_FLOW_OK;
945 }
947 if (!self->need_out_buf)
948 goto have_out_buf;
950 /* do this before creating codec to ensure reverse caps negotiation
951 * happens first:
952 */
953 allocate_buffer:
954 ret = gst_pad_alloc_buffer (self->srcpad, 0, self->outsize,
955 GST_PAD_CAPS (self->srcpad), &outbuf);
956 if (ret != GST_FLOW_OK) {
957 GST_WARNING_OBJECT (self, "alloc_buffer failed %s",
958 gst_flow_get_name (ret));
959 gst_buffer_unref (buf);
960 return ret;
961 }
963 outcaps = GST_BUFFER_CAPS (outbuf);
964 if (outcaps && !gst_caps_is_equal (outcaps, GST_PAD_CAPS (self->srcpad))) {
965 GstStructure *s;
967 GST_INFO_OBJECT (self, "doing upstream negotiation bufsize %d",
968 GST_BUFFER_SIZE (outbuf));
970 s = gst_caps_get_structure (outcaps, 0);
971 gst_structure_get_int (s, "rowstride", &self->stride);
972 self->outsize = gst_video_format_get_size (GST_VIDEO_FORMAT_NV12,
973 self->stride, self->padded_height);
975 GST_INFO_OBJECT (self, "outsize %d stride %d outcaps: %" GST_PTR_FORMAT,
976 self->outsize, self->stride, outcaps);
978 gst_pad_set_caps (self->srcpad, outcaps);
980 if (GST_BUFFER_SIZE (outbuf) != self->outsize) {
981 GST_INFO_OBJECT (self, "dropping buffer (bufsize %d != outsize %d)",
982 GST_BUFFER_SIZE (outbuf), self->outsize);
983 gst_buffer_unref (outbuf);
984 goto allocate_buffer;
985 }
986 }
988 if (G_UNLIKELY (!self->codec)) {
989 if (!codec_create (self)) {
990 GST_ERROR_OBJECT (self, "could not create codec");
991 gst_buffer_unref (buf);
992 gst_buffer_unref (outbuf);
993 return GST_FLOW_ERROR;
994 }
995 }
997 GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
998 GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
1000 /* Pass new output buffer to the decoder to decode into. Use buffers from the
1001 * internal pool while self->first_out_buffer == TRUE in order to simplify
1002 * things in case we need to renegotiate */
1003 self->inArgs->inputID =
1004 codec_prepare_outbuf (self, &outbuf, self->first_out_buffer);
1005 if (!self->inArgs->inputID) {
1006 GST_ERROR_OBJECT (self, "could not prepare output buffer");
1007 gst_buffer_unref (buf);
1008 return GST_FLOW_ERROR;
1009 }
1011 have_out_buf:
1012 self->in_size = 0;
1013 buf = GST_DUCATIVIDDEC_GET_CLASS (self)->push_input (self, buf);
1015 if (ts != GST_CLOCK_TIME_NONE) {
1016 self->dts_queue[self->dts_widx++ % NDTS] = ts;
1017 /* if next buffer has earlier ts than previous, then the ts
1018 * we are getting are definitely decode order (DTS):
1019 */
1020 if ((self->last_dts != GST_CLOCK_TIME_NONE) && (self->last_dts > ts)) {
1021 GST_DEBUG_OBJECT (self, "input timestamp definitely DTS");
1022 self->ts_may_be_pts = FALSE;
1023 }
1024 self->last_dts = ts;
1025 }
1027 if (self->in_size == 0 && outbuf) {
1028 GST_DEBUG_OBJECT (self, "no input, skipping process");
1029 gst_buffer_unref (outbuf);
1030 return GST_FLOW_OK;
1031 }
1033 self->inArgs->numBytes = self->in_size;
1034 self->inBufs->descs[0].bufSize.bytes = self->in_size;
1035 self->inBufs->descs[0].memType = XDM_MEMTYPE_BO;
1037 err = codec_process (self, TRUE, FALSE, &ret);
1038 if (err) {
1039 GST_ELEMENT_ERROR (self, STREAM, DECODE, (NULL),
1040 ("process returned error: %d %08x", err, self->outArgs->extendedError));
1041 gst_ducati_log_extended_error_info (self->outArgs->extendedError);
1042 return GST_FLOW_ERROR;
1043 }
1044 if (ret != GST_FLOW_OK) {
1045 GST_WARNING_OBJECT (self, "push from codec_process failed %s",
1046 gst_flow_get_name (ret));
1047 return ret;
1048 }
1050 self->first_in_buffer = FALSE;
1052 if (self->outArgs->outBufsInUseFlag) {
1053 GST_DEBUG_OBJECT (self, "outBufsInUseFlag set");
1054 self->need_out_buf = FALSE;
1055 } else {
1056 self->need_out_buf = TRUE;
1057 }
1059 if (buf) {
1060 GST_DEBUG_OBJECT (self, "found remaining data: %d bytes",
1061 GST_BUFFER_SIZE (buf));
1062 ts = GST_BUFFER_TIMESTAMP (buf);
1063 goto allocate_buffer;
1064 }
1066 return GST_FLOW_OK;
1067 }
1069 static gboolean
1070 gst_ducati_viddec_event (GstPad * pad, GstEvent * event)
1071 {
1072 GstDucatiVidDec *self = GST_DUCATIVIDDEC (GST_OBJECT_PARENT (pad));
1073 gboolean ret = TRUE;
1075 GST_DEBUG_OBJECT (self, "begin: event=%s", GST_EVENT_TYPE_NAME (event));
1077 switch (GST_EVENT_TYPE (event)) {
1078 case GST_EVENT_NEWSEGMENT:
1079 {
1080 gboolean update;
1081 GstFormat fmt;
1082 gint64 start, stop, time;
1083 gdouble rate, arate;
1085 gst_event_parse_new_segment_full (event, &update, &rate, &arate, &fmt,
1086 &start, &stop, &time);
1087 gst_segment_set_newsegment_full (&self->segment, update,
1088 rate, arate, fmt, start, stop, time);
1089 break;
1090 }
1091 case GST_EVENT_EOS:
1092 if (!gst_ducati_viddec_codec_flush (self, TRUE)) {
1093 GST_ERROR_OBJECT (self, "could not flush on eos");
1094 ret = FALSE;
1095 }
1096 break;
1097 case GST_EVENT_FLUSH_STOP:
1098 if (!gst_ducati_viddec_codec_flush (self, FALSE)) {
1099 GST_ERROR_OBJECT (self, "could not flush");
1100 gst_event_unref (event);
1101 ret = FALSE;
1102 }
1103 gst_segment_init (&self->segment, GST_FORMAT_UNDEFINED);
1104 self->qos_earliest_time = GST_CLOCK_TIME_NONE;
1105 self->qos_proportion = 1;
1106 self->need_out_buf = TRUE;
1107 break;
1108 default:
1109 break;
1110 }
1112 if (ret)
1113 ret = gst_pad_push_event (self->srcpad, event);
1114 GST_LOG_OBJECT (self, "end");
1116 return ret;
1117 }
1119 static gboolean
1120 gst_ducati_viddec_src_event (GstPad * pad, GstEvent * event)
1121 {
1122 GstDucatiVidDec *self = GST_DUCATIVIDDEC (GST_OBJECT_PARENT (pad));
1123 gboolean ret = TRUE;
1125 GST_LOG_OBJECT (self, "begin: event=%s", GST_EVENT_TYPE_NAME (event));
1127 switch (GST_EVENT_TYPE (event)) {
1128 case GST_EVENT_QOS:
1129 {
1130 gdouble proportion;
1131 GstClockTimeDiff diff;
1132 GstClockTime timestamp;
1134 gst_event_parse_qos (event, &proportion, &diff, ×tamp);
1136 GST_OBJECT_LOCK (self);
1137 self->qos_proportion = proportion;
1138 self->qos_earliest_time = timestamp + 2 * diff;
1139 GST_OBJECT_UNLOCK (self);
1141 GST_DEBUG_OBJECT (self,
1142 "got QoS proportion %f %" GST_TIME_FORMAT ", %" G_GINT64_FORMAT,
1143 proportion, GST_TIME_ARGS (timestamp), diff);
1145 ret = gst_pad_push_event (self->sinkpad, event);
1146 break;
1147 }
1148 default:
1149 ret = gst_pad_push_event (self->sinkpad, event);
1150 break;
1151 }
1153 GST_LOG_OBJECT (self, "end");
1155 return ret;
1156 }
1158 static GstStateChangeReturn
1159 gst_ducati_viddec_change_state (GstElement * element, GstStateChange transition)
1160 {
1161 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
1162 GstDucatiVidDec *self = GST_DUCATIVIDDEC (element);
1163 gboolean supported;
1165 GST_DEBUG_OBJECT (self, "begin: changing state %s -> %s",
1166 gst_element_state_get_name (GST_STATE_TRANSITION_CURRENT (transition)),
1167 gst_element_state_get_name (GST_STATE_TRANSITION_NEXT (transition)));
1169 switch (transition) {
1170 case GST_STATE_CHANGE_NULL_TO_READY:
1171 if (!engine_open (self)) {
1172 GST_ERROR_OBJECT (self, "could not open");
1173 return GST_STATE_CHANGE_FAILURE;
1174 }
1175 /* try to create/destroy the codec here, it may not be supported */
1176 supported = codec_create (self);
1177 codec_delete (self);
1178 self->codec = NULL;
1179 if (!supported) {
1180 GST_ERROR_OBJECT (element, "Failed to create codec %s, not supported",
1181 GST_DUCATIVIDDEC_GET_CLASS (self)->codec_name);
1182 engine_close (self);
1183 return GST_STATE_CHANGE_FAILURE;
1184 }
1185 break;
1186 default:
1187 break;
1188 }
1190 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1192 if (ret == GST_STATE_CHANGE_FAILURE)
1193 goto leave;
1195 switch (transition) {
1196 case GST_STATE_CHANGE_PAUSED_TO_READY:
1197 self->interlaced = FALSE;
1198 self->send_crop_event = TRUE;
1199 gst_ducati_viddec_codec_flush (self, FALSE);
1200 break;
1201 case GST_STATE_CHANGE_READY_TO_NULL:
1202 codec_delete (self);
1203 engine_close (self);
1204 break;
1205 default:
1206 break;
1207 }
1209 leave:
1210 GST_LOG_OBJECT (self, "end");
1212 return ret;
1213 }
1215 /* GObject vmethod implementations */
1217 #define VERSION_LENGTH 256
1219 static void
1220 gst_ducati_viddec_get_property (GObject * obj,
1221 guint prop_id, GValue * value, GParamSpec * pspec)
1222 {
1223 GstDucatiVidDec *self = GST_DUCATIVIDDEC (obj);
1226 switch (prop_id) {
1227 case PROP_VERSION:{
1228 int err;
1229 char *version = NULL;
1231 if (!self->engine)
1232 engine_open (self);
1234 if (!self->codec)
1235 codec_create (self);
1237 if (self->codec) {
1238 version = dce_alloc (VERSION_LENGTH);
1239 self->status->data.buf = (XDAS_Int8 *) version;
1240 self->status->data.bufSize = VERSION_LENGTH;
1242 err = VIDDEC3_control (self->codec, XDM_GETVERSION,
1243 self->dynParams, self->status);
1244 if (err) {
1245 GST_ERROR_OBJECT (self, "failed XDM_GETVERSION");
1246 }
1248 self->status->data.buf = NULL;
1249 self->status->data.bufSize = 0;
1250 }
1252 g_value_set_string (value, version);
1253 if (version)
1254 dce_free (version);
1256 break;
1257 }
1258 default:{
1259 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
1260 break;
1261 }
1262 }
1263 }
1265 static void
1266 gst_ducati_viddec_finalize (GObject * obj)
1267 {
1268 GstDucatiVidDec *self = GST_DUCATIVIDDEC (obj);
1270 codec_delete (self);
1271 engine_close (self);
1273 if (self->codec_data) {
1274 gst_buffer_unref (self->codec_data);
1275 self->codec_data = NULL;
1276 }
1278 G_OBJECT_CLASS (parent_class)->finalize (obj);
1279 }
1281 static void
1282 gst_ducati_viddec_base_init (gpointer gclass)
1283 {
1284 GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
1286 gst_element_class_add_pad_template (element_class,
1287 gst_static_pad_template_get (&src_factory));
1288 }
1290 static void
1291 gst_ducati_viddec_class_init (GstDucatiVidDecClass * klass)
1292 {
1293 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1294 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
1296 gobject_class->get_property =
1297 GST_DEBUG_FUNCPTR (gst_ducati_viddec_get_property);
1298 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_ducati_viddec_finalize);
1299 gstelement_class->change_state =
1300 GST_DEBUG_FUNCPTR (gst_ducati_viddec_change_state);
1302 klass->parse_caps = GST_DEBUG_FUNCPTR (gst_ducati_viddec_parse_caps);
1303 klass->allocate_params =
1304 GST_DEBUG_FUNCPTR (gst_ducati_viddec_allocate_params);
1305 klass->push_input = GST_DEBUG_FUNCPTR (gst_ducati_viddec_push_input);
1306 klass->handle_error = GST_DEBUG_FUNCPTR (gst_ducati_viddec_handle_error);
1307 klass->drop_frame = GST_DEBUG_FUNCPTR (gst_ducati_viddec_drop_frame);
1308 klass->query = GST_DEBUG_FUNCPTR (gst_ducati_viddec_query);
1310 g_object_class_install_property (gobject_class, PROP_VERSION,
1311 g_param_spec_string ("version", "Version",
1312 "The codec version string", "",
1313 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
1314 }
1316 static void
1317 gst_ducati_viddec_init (GstDucatiVidDec * self, GstDucatiVidDecClass * klass)
1318 {
1319 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
1321 self->sinkpad =
1322 gst_pad_new_from_template (gst_element_class_get_pad_template
1323 (gstelement_class, "sink"), "sink");
1324 gst_pad_set_setcaps_function (self->sinkpad,
1325 GST_DEBUG_FUNCPTR (gst_ducati_viddec_sink_setcaps));
1326 gst_pad_set_chain_function (self->sinkpad,
1327 GST_DEBUG_FUNCPTR (gst_ducati_viddec_chain));
1328 gst_pad_set_event_function (self->sinkpad,
1329 GST_DEBUG_FUNCPTR (gst_ducati_viddec_event));
1331 self->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
1332 gst_pad_set_event_function (self->srcpad,
1333 GST_DEBUG_FUNCPTR (gst_ducati_viddec_src_event));
1334 gst_pad_set_query_function (self->srcpad,
1335 GST_DEBUG_FUNCPTR (gst_ducati_viddec_src_query));
1336 gst_pad_set_getcaps_function (self->srcpad,
1337 GST_DEBUG_FUNCPTR (gst_ducati_viddec_src_getcaps));
1339 gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
1340 gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
1342 self->input_width = 0;
1343 self->input_height = 0;
1344 /* sane defaults in case we need to create codec without caps negotiation
1345 * (for example, to get 'version' property)
1346 */
1347 self->width = 128;
1348 self->height = 128;
1349 self->fps_n = -1;
1350 self->fps_d = -1;
1352 self->first_in_buffer = TRUE;
1353 self->first_out_buffer = TRUE;
1354 self->interlaced = FALSE;
1355 self->send_crop_event = TRUE;
1357 self->dts_ridx = self->dts_widx = 0;
1358 self->last_dts = self->last_pts = GST_CLOCK_TIME_NONE;
1359 self->ts_may_be_pts = TRUE;
1360 self->ts_is_pts = FALSE;
1362 self->pageMemType = XDM_MEMTYPE_TILEDPAGE;
1364 gst_segment_init (&self->segment, GST_FORMAT_UNDEFINED);
1366 self->qos_proportion = 1;
1367 self->qos_earliest_time = GST_CLOCK_TIME_NONE;
1368 self->wait_keyframe = TRUE;
1370 self->need_out_buf = TRUE;
1371 self->device = NULL;
1372 self->input_bo = NULL;
1373 }