2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
27 #include <libavcodec/avcodec.h>
30 #include <gst/video/video.h>
31 #include <gst/video/gstvideodecoder.h>
32 #include <gst/video/gstvideometa.h>
33 #include <gst/video/gstvideopool.h>
36 #include "gstavcodecmap.h"
37 #include "gstavutils.h"
38 #include "gstavviddec.h"
40 GST_DEBUG_CATEGORY_EXTERN (GST_CAT_PERFORMANCE);
42 #define MAX_TS_MASK 0xff
44 #define DEFAULT_LOWRES 0
45 #define DEFAULT_SKIPFRAME 0
46 #define DEFAULT_DIRECT_RENDERING TRUE
47 #define DEFAULT_DEBUG_MV FALSE
48 #define DEFAULT_MAX_THREADS 0
49 #define DEFAULT_OUTPUT_CORRUPT TRUE
50 #define REQUIRED_POOL_MAX_BUFFERS 32
57 PROP_DIRECT_RENDERING,
64 /* A number of function prototypes are given so we can refer to them later. */
65 static void gst_ffmpegviddec_base_init (GstFFMpegVidDecClass * klass);
66 static void gst_ffmpegviddec_class_init (GstFFMpegVidDecClass * klass);
67 static void gst_ffmpegviddec_init (GstFFMpegVidDec * ffmpegdec);
68 static void gst_ffmpegviddec_finalize (GObject * object);
70 static gboolean gst_ffmpegviddec_set_format (GstVideoDecoder * decoder,
71 GstVideoCodecState * state);
72 static GstFlowReturn gst_ffmpegviddec_handle_frame (GstVideoDecoder * decoder,
73 GstVideoCodecFrame * frame);
74 static gboolean gst_ffmpegviddec_start (GstVideoDecoder * decoder);
75 static gboolean gst_ffmpegviddec_stop (GstVideoDecoder * decoder);
76 static gboolean gst_ffmpegviddec_flush (GstVideoDecoder * decoder);
77 static gboolean gst_ffmpegviddec_decide_allocation (GstVideoDecoder * decoder,
79 static gboolean gst_ffmpegviddec_propose_allocation (GstVideoDecoder * decoder,
82 static void gst_ffmpegviddec_set_property (GObject * object,
83 guint prop_id, const GValue * value, GParamSpec * pspec);
84 static void gst_ffmpegviddec_get_property (GObject * object,
85 guint prop_id, GValue * value, GParamSpec * pspec);
87 static gboolean gst_ffmpegviddec_negotiate (GstFFMpegVidDec * ffmpegdec,
88 AVCodecContext * context, AVFrame * picture, gboolean force);
90 /* some sort of bufferpool handling, but different */
91 static int gst_ffmpegviddec_get_buffer2 (AVCodecContext * context,
92 AVFrame * picture, int flags);
94 static GstFlowReturn gst_ffmpegviddec_finish (GstVideoDecoder * decoder);
95 static void gst_ffmpegviddec_drain (GstFFMpegVidDec * ffmpegdec);
97 static gboolean picture_changed (GstFFMpegVidDec * ffmpegdec,
99 static gboolean context_changed (GstFFMpegVidDec * ffmpegdec,
100 AVCodecContext * context);
102 #define GST_FFDEC_PARAMS_QDATA g_quark_from_static_string("avdec-params")
104 static GstElementClass *parent_class = NULL;
106 #define GST_FFMPEGVIDDEC_TYPE_LOWRES (gst_ffmpegviddec_lowres_get_type())
108 gst_ffmpegviddec_lowres_get_type (void)
110 static GType ffmpegdec_lowres_type = 0;
112 if (!ffmpegdec_lowres_type) {
113 static const GEnumValue ffmpegdec_lowres[] = {
115 {1, "1", "1/2-size"},
116 {2, "2", "1/4-size"},
120 ffmpegdec_lowres_type =
121 g_enum_register_static ("GstLibAVVidDecLowres", ffmpegdec_lowres);
124 return ffmpegdec_lowres_type;
127 #define GST_FFMPEGVIDDEC_TYPE_SKIPFRAME (gst_ffmpegviddec_skipframe_get_type())
129 gst_ffmpegviddec_skipframe_get_type (void)
131 static GType ffmpegdec_skipframe_type = 0;
133 if (!ffmpegdec_skipframe_type) {
134 static const GEnumValue ffmpegdec_skipframe[] = {
135 {0, "0", "Skip nothing"},
136 {1, "1", "Skip B-frames"},
137 {2, "2", "Skip IDCT/Dequantization"},
138 {5, "5", "Skip everything"},
142 ffmpegdec_skipframe_type =
143 g_enum_register_static ("GstLibAVVidDecSkipFrame", ffmpegdec_skipframe);
146 return ffmpegdec_skipframe_type;
150 gst_ffmpegviddec_base_init (GstFFMpegVidDecClass * klass)
152 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
153 GstPadTemplate *sinktempl, *srctempl;
154 GstCaps *sinkcaps, *srccaps;
156 gchar *longname, *description;
159 (AVCodec *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
160 GST_FFDEC_PARAMS_QDATA);
161 g_assert (in_plugin != NULL);
163 /* construct the element details struct */
164 longname = g_strdup_printf ("libav %s decoder", in_plugin->long_name);
165 description = g_strdup_printf ("libav %s decoder", in_plugin->name);
166 gst_element_class_set_metadata (element_class, longname,
167 "Codec/Decoder/Video", description,
168 "Wim Taymans <wim.taymans@gmail.com>, "
169 "Ronald Bultje <rbultje@ronald.bitfreak.net>, "
170 "Edward Hervey <bilboed@bilboed.com>");
172 g_free (description);
175 sinkcaps = gst_ffmpeg_codecid_to_caps (in_plugin->id, NULL, FALSE);
177 GST_DEBUG ("Couldn't get sink caps for decoder '%s'", in_plugin->name);
178 sinkcaps = gst_caps_new_empty_simple ("unknown/unknown");
180 srccaps = gst_ffmpeg_codectype_to_video_caps (NULL,
181 in_plugin->id, FALSE, in_plugin);
183 GST_DEBUG ("Couldn't get source caps for decoder '%s'", in_plugin->name);
184 srccaps = gst_caps_from_string ("video/x-raw");
188 sinktempl = gst_pad_template_new ("sink", GST_PAD_SINK,
189 GST_PAD_ALWAYS, sinkcaps);
190 srctempl = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, srccaps);
192 gst_element_class_add_pad_template (element_class, srctempl);
193 gst_element_class_add_pad_template (element_class, sinktempl);
195 klass->in_plugin = in_plugin;
199 gst_ffmpegviddec_class_init (GstFFMpegVidDecClass * klass)
201 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
202 GstVideoDecoderClass *viddec_class = GST_VIDEO_DECODER_CLASS (klass);
205 parent_class = g_type_class_peek_parent (klass);
207 gobject_class->finalize = gst_ffmpegviddec_finalize;
209 gobject_class->set_property = gst_ffmpegviddec_set_property;
210 gobject_class->get_property = gst_ffmpegviddec_get_property;
212 g_object_class_install_property (gobject_class, PROP_SKIPFRAME,
213 g_param_spec_enum ("skip-frame", "Skip frames",
214 "Which types of frames to skip during decoding",
215 GST_FFMPEGVIDDEC_TYPE_SKIPFRAME, 0,
216 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
217 g_object_class_install_property (gobject_class, PROP_LOWRES,
218 g_param_spec_enum ("lowres", "Low resolution",
219 "At which resolution to decode images",
220 GST_FFMPEGVIDDEC_TYPE_LOWRES, 0,
221 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
222 g_object_class_install_property (gobject_class, PROP_DIRECT_RENDERING,
223 g_param_spec_boolean ("direct-rendering", "Direct Rendering",
224 "Enable direct rendering", DEFAULT_DIRECT_RENDERING,
225 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
226 g_object_class_install_property (gobject_class, PROP_DEBUG_MV,
227 g_param_spec_boolean ("debug-mv", "Debug motion vectors",
228 "Whether libav should print motion vectors on top of the image",
229 DEFAULT_DEBUG_MV, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
230 g_object_class_install_property (gobject_class, PROP_OUTPUT_CORRUPT,
231 g_param_spec_boolean ("output-corrupt", "Output corrupt buffers",
232 "Whether libav should output frames even if corrupted",
233 DEFAULT_OUTPUT_CORRUPT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
235 caps = klass->in_plugin->capabilities;
236 if (caps & (CODEC_CAP_FRAME_THREADS | CODEC_CAP_SLICE_THREADS)) {
237 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_THREADS,
238 g_param_spec_int ("max-threads", "Maximum decode threads",
239 "Maximum number of worker threads to spawn. (0 = auto)",
240 0, G_MAXINT, DEFAULT_MAX_THREADS,
241 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
244 viddec_class->set_format = gst_ffmpegviddec_set_format;
245 viddec_class->handle_frame = gst_ffmpegviddec_handle_frame;
246 viddec_class->start = gst_ffmpegviddec_start;
247 viddec_class->stop = gst_ffmpegviddec_stop;
248 viddec_class->flush = gst_ffmpegviddec_flush;
249 viddec_class->finish = gst_ffmpegviddec_finish;
250 viddec_class->drain = gst_ffmpegviddec_finish; /* drain and finish are the same to us */
251 viddec_class->decide_allocation = gst_ffmpegviddec_decide_allocation;
252 viddec_class->propose_allocation = gst_ffmpegviddec_propose_allocation;
256 gst_ffmpegviddec_init (GstFFMpegVidDec * ffmpegdec)
258 GstFFMpegVidDecClass *klass =
259 (GstFFMpegVidDecClass *) G_OBJECT_GET_CLASS (ffmpegdec);
261 /* some ffmpeg data */
262 ffmpegdec->context = avcodec_alloc_context3 (klass->in_plugin);
263 ffmpegdec->context->opaque = ffmpegdec;
264 ffmpegdec->picture = av_frame_alloc ();
265 ffmpegdec->opened = FALSE;
266 ffmpegdec->skip_frame = ffmpegdec->lowres = 0;
267 ffmpegdec->direct_rendering = DEFAULT_DIRECT_RENDERING;
268 ffmpegdec->debug_mv = DEFAULT_DEBUG_MV;
269 ffmpegdec->max_threads = DEFAULT_MAX_THREADS;
270 ffmpegdec->output_corrupt = DEFAULT_OUTPUT_CORRUPT;
272 gst_video_decoder_set_needs_format (GST_VIDEO_DECODER (ffmpegdec), TRUE);
276 gst_ffmpegviddec_finalize (GObject * object)
278 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object;
280 av_frame_free (&ffmpegdec->picture);
282 if (ffmpegdec->context != NULL) {
283 gst_ffmpeg_avcodec_close (ffmpegdec->context);
284 av_free (ffmpegdec->context);
285 ffmpegdec->context = NULL;
288 G_OBJECT_CLASS (parent_class)->finalize (object);
292 gst_ffmpegviddec_context_set_flags (AVCodecContext * context, guint flags,
295 g_return_if_fail (context != NULL);
298 context->flags |= flags;
300 context->flags &= ~flags;
305 gst_ffmpegviddec_close (GstFFMpegVidDec * ffmpegdec, gboolean reset)
307 GstFFMpegVidDecClass *oclass;
310 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
312 GST_LOG_OBJECT (ffmpegdec, "closing ffmpeg codec");
314 gst_caps_replace (&ffmpegdec->last_caps, NULL);
316 gst_ffmpeg_avcodec_close (ffmpegdec->context);
317 ffmpegdec->opened = FALSE;
319 for (i = 0; i < G_N_ELEMENTS (ffmpegdec->stride); i++)
320 ffmpegdec->stride[i] = -1;
322 gst_buffer_replace (&ffmpegdec->palette, NULL);
324 if (ffmpegdec->context->extradata) {
325 av_free (ffmpegdec->context->extradata);
326 ffmpegdec->context->extradata = NULL;
328 if (ffmpegdec->context->slice_offset) {
329 g_free (ffmpegdec->context->slice_offset);
330 ffmpegdec->context->slice_offset = NULL;
333 if (avcodec_get_context_defaults3 (ffmpegdec->context,
334 oclass->in_plugin) < 0) {
335 GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
338 ffmpegdec->context->opaque = ffmpegdec;
345 gst_ffmpegviddec_open (GstFFMpegVidDec * ffmpegdec)
347 GstFFMpegVidDecClass *oclass;
350 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
352 if (gst_ffmpeg_avcodec_open (ffmpegdec->context, oclass->in_plugin) < 0)
355 for (i = 0; i < G_N_ELEMENTS (ffmpegdec->stride); i++)
356 ffmpegdec->stride[i] = -1;
358 ffmpegdec->opened = TRUE;
359 ffmpegdec->is_realvideo = FALSE;
361 GST_LOG_OBJECT (ffmpegdec, "Opened libav codec %s, id %d",
362 oclass->in_plugin->name, oclass->in_plugin->id);
364 switch (oclass->in_plugin->id) {
365 case AV_CODEC_ID_RV10:
366 case AV_CODEC_ID_RV30:
367 case AV_CODEC_ID_RV20:
368 case AV_CODEC_ID_RV40:
369 ffmpegdec->is_realvideo = TRUE;
372 GST_LOG_OBJECT (ffmpegdec, "Parser deactivated for format");
376 gst_ffmpegviddec_context_set_flags (ffmpegdec->context,
377 CODEC_FLAG_OUTPUT_CORRUPT, ffmpegdec->output_corrupt);
384 gst_ffmpegviddec_close (ffmpegdec, TRUE);
385 GST_DEBUG_OBJECT (ffmpegdec, "avdec_%s: Failed to open libav codec",
386 oclass->in_plugin->name);
392 gst_ffmpegviddec_get_palette (GstFFMpegVidDec * ffmpegdec,
393 GstVideoCodecState * state)
395 GstStructure *str = gst_caps_get_structure (state->caps, 0);
396 const GValue *palette_v;
399 /* do we have a palette? */
400 if ((palette_v = gst_structure_get_value (str, "palette_data"))) {
401 palette = gst_value_get_buffer (palette_v);
402 GST_DEBUG ("got palette data %p", palette);
403 if (gst_buffer_get_size (palette) >= AVPALETTE_SIZE) {
404 gst_buffer_replace (&ffmpegdec->palette, palette);
411 gst_ffmpegviddec_set_format (GstVideoDecoder * decoder,
412 GstVideoCodecState * state)
414 GstFFMpegVidDec *ffmpegdec;
415 GstFFMpegVidDecClass *oclass;
416 GstClockTime latency = GST_CLOCK_TIME_NONE;
417 gboolean ret = FALSE;
419 ffmpegdec = (GstFFMpegVidDec *) decoder;
420 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
422 if (ffmpegdec->last_caps != NULL &&
423 gst_caps_is_equal (ffmpegdec->last_caps, state->caps)) {
427 GST_DEBUG_OBJECT (ffmpegdec, "setcaps called");
429 GST_OBJECT_LOCK (ffmpegdec);
430 /* stupid check for VC1 */
431 if ((oclass->in_plugin->id == AV_CODEC_ID_WMV3) ||
432 (oclass->in_plugin->id == AV_CODEC_ID_VC1))
433 oclass->in_plugin->id = gst_ffmpeg_caps_to_codecid (state->caps, NULL);
435 /* close old session */
436 if (ffmpegdec->opened) {
437 GST_OBJECT_UNLOCK (ffmpegdec);
438 gst_ffmpegviddec_drain (ffmpegdec);
439 GST_OBJECT_LOCK (ffmpegdec);
440 if (!gst_ffmpegviddec_close (ffmpegdec, TRUE)) {
441 GST_OBJECT_UNLOCK (ffmpegdec);
444 ffmpegdec->pic_pix_fmt = 0;
445 ffmpegdec->pic_width = 0;
446 ffmpegdec->pic_height = 0;
447 ffmpegdec->pic_par_n = 0;
448 ffmpegdec->pic_par_d = 0;
449 ffmpegdec->ctx_ticks = 0;
450 ffmpegdec->ctx_time_n = 0;
451 ffmpegdec->ctx_time_d = 0;
454 gst_caps_replace (&ffmpegdec->last_caps, state->caps);
456 /* set buffer functions */
457 ffmpegdec->context->get_buffer2 = gst_ffmpegviddec_get_buffer2;
458 ffmpegdec->context->get_buffer = NULL;
459 ffmpegdec->context->reget_buffer = NULL;
460 ffmpegdec->context->release_buffer = NULL;
461 ffmpegdec->context->draw_horiz_band = NULL;
463 /* reset coded_width/_height to prevent it being reused from last time when
464 * the codec is opened again, causing a mismatch and possible
465 * segfault/corruption. (Common scenario when renegotiating caps) */
466 ffmpegdec->context->coded_width = 0;
467 ffmpegdec->context->coded_height = 0;
469 GST_LOG_OBJECT (ffmpegdec, "size %dx%d", ffmpegdec->context->width,
470 ffmpegdec->context->height);
472 /* FIXME : Create a method that takes GstVideoCodecState instead */
473 /* get size and so */
474 gst_ffmpeg_caps_with_codecid (oclass->in_plugin->id,
475 oclass->in_plugin->type, state->caps, ffmpegdec->context);
477 GST_LOG_OBJECT (ffmpegdec, "size after %dx%d", ffmpegdec->context->width,
478 ffmpegdec->context->height);
480 gst_ffmpegviddec_get_palette (ffmpegdec, state);
482 if (!ffmpegdec->context->time_base.den || !ffmpegdec->context->time_base.num) {
483 GST_DEBUG_OBJECT (ffmpegdec, "forcing 25/1 framerate");
484 ffmpegdec->context->time_base.num = 1;
485 ffmpegdec->context->time_base.den = 25;
488 /* workaround encoder bugs */
489 ffmpegdec->context->workaround_bugs |= FF_BUG_AUTODETECT;
490 ffmpegdec->context->err_recognition = 1;
493 ffmpegdec->context->lowres = ffmpegdec->lowres;
494 ffmpegdec->context->skip_frame = ffmpegdec->skip_frame;
496 /* ffmpeg can draw motion vectors on top of the image (not every decoder
498 ffmpegdec->context->debug_mv = ffmpegdec->debug_mv;
504 if (ffmpegdec->max_threads == 0) {
505 if (!(oclass->in_plugin->capabilities & CODEC_CAP_AUTO_THREADS))
506 ffmpegdec->context->thread_count = gst_ffmpeg_auto_max_threads ();
508 ffmpegdec->context->thread_count = 0;
510 ffmpegdec->context->thread_count = ffmpegdec->max_threads;
512 query = gst_query_new_latency ();
514 /* Check if upstream is live. If it isn't we can enable frame based
515 * threading, which is adding latency */
516 if (gst_pad_peer_query (GST_VIDEO_DECODER_SINK_PAD (ffmpegdec), query)) {
517 gst_query_parse_latency (query, &is_live, NULL, NULL);
519 gst_query_unref (query);
522 ffmpegdec->context->thread_type = FF_THREAD_SLICE;
524 ffmpegdec->context->thread_type = FF_THREAD_SLICE | FF_THREAD_FRAME;
527 /* open codec - we don't select an output pix_fmt yet,
528 * simply because we don't know! We only get it
529 * during playback... */
530 if (!gst_ffmpegviddec_open (ffmpegdec))
533 if (ffmpegdec->input_state)
534 gst_video_codec_state_unref (ffmpegdec->input_state);
535 ffmpegdec->input_state = gst_video_codec_state_ref (state);
537 if (ffmpegdec->input_state->info.fps_n) {
538 GstVideoInfo *info = &ffmpegdec->input_state->info;
539 latency = gst_util_uint64_scale_ceil (
540 (ffmpegdec->context->has_b_frames) * GST_SECOND, info->fps_d,
547 GST_OBJECT_UNLOCK (ffmpegdec);
549 if (GST_CLOCK_TIME_IS_VALID (latency))
550 gst_video_decoder_set_latency (decoder, latency, latency);
557 GST_DEBUG_OBJECT (ffmpegdec, "Failed to open");
564 GstFFMpegVidDec *ffmpegdec;
565 GstVideoCodecFrame *frame;
567 GstVideoFrame vframe;
569 AVBufferRef *avbuffer;
570 } GstFFMpegVidDecVideoFrame;
572 static GstFFMpegVidDecVideoFrame *
573 gst_ffmpegviddec_video_frame_new (GstFFMpegVidDec * ffmpegdec,
574 GstVideoCodecFrame * frame)
576 GstFFMpegVidDecVideoFrame *dframe;
578 dframe = g_slice_new0 (GstFFMpegVidDecVideoFrame);
579 dframe->ffmpegdec = ffmpegdec;
580 dframe->frame = frame;
582 GST_DEBUG_OBJECT (ffmpegdec, "new video frame %p", dframe);
588 gst_ffmpegviddec_video_frame_free (GstFFMpegVidDec * ffmpegdec,
589 GstFFMpegVidDecVideoFrame * frame)
591 GST_DEBUG_OBJECT (ffmpegdec, "free video frame %p", frame);
594 gst_video_frame_unmap (&frame->vframe);
595 gst_video_decoder_release_frame (GST_VIDEO_DECODER (ffmpegdec), frame->frame);
596 gst_buffer_replace (&frame->buffer, NULL);
597 if (frame->avbuffer) {
598 av_buffer_unref (&frame->avbuffer);
600 g_slice_free (GstFFMpegVidDecVideoFrame, frame);
604 dummy_free_buffer (void *opaque, uint8_t * data)
606 GstFFMpegVidDecVideoFrame *frame = opaque;
608 gst_ffmpegviddec_video_frame_free (frame->ffmpegdec, frame);
611 /* called when ffmpeg wants us to allocate a buffer to write the decoded frame
612 * into. We try to give it memory from our pool */
614 gst_ffmpegviddec_get_buffer2 (AVCodecContext * context, AVFrame * picture,
617 GstVideoCodecFrame *frame;
618 GstFFMpegVidDecVideoFrame *dframe;
619 GstFFMpegVidDec *ffmpegdec;
624 ffmpegdec = (GstFFMpegVidDec *) context->opaque;
626 GST_DEBUG_OBJECT (ffmpegdec, "getting buffer picture %p", picture);
628 /* apply the last info we have seen to this picture, when we get the
629 * picture back from ffmpeg we can use this to correctly timestamp the output
631 GST_DEBUG_OBJECT (ffmpegdec, "opaque value SN %d",
632 (gint32) picture->reordered_opaque);
635 gst_video_decoder_get_frame (GST_VIDEO_DECODER (ffmpegdec),
636 picture->reordered_opaque);
637 if (G_UNLIKELY (frame == NULL))
640 /* now it has a buffer allocated, so it is real and will also
642 GST_VIDEO_CODEC_FRAME_FLAG_UNSET (frame,
643 GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY);
645 if (G_UNLIKELY (frame->output_buffer != NULL))
646 goto duplicate_frame;
648 /* GstFFMpegVidDecVideoFrame receives the frame ref */
649 if (picture->opaque) {
650 dframe = picture->opaque;
651 dframe->frame = frame;
653 picture->opaque = dframe =
654 gst_ffmpegviddec_video_frame_new (ffmpegdec, frame);
657 GST_DEBUG_OBJECT (ffmpegdec, "storing opaque %p", dframe);
659 /* If the picture format changed but we already negotiated before,
660 * we will have to do fallback allocation until output and input
661 * formats are in sync again. We will renegotiate on the output
663 if (ffmpegdec->pic_width != 0 && picture_changed (ffmpegdec, picture))
666 /* see if we need renegotiation */
667 if (G_UNLIKELY (!gst_ffmpegviddec_negotiate (ffmpegdec, context, picture,
669 goto negotiate_failed;
671 if (!ffmpegdec->current_dr)
675 gst_video_decoder_allocate_output_frame (GST_VIDEO_DECODER (ffmpegdec),
677 if (ret != GST_FLOW_OK)
680 /* piggy-backed alloc'ed on the frame,
681 * and there was much rejoicing and we are grateful.
682 * Now take away buffer from frame, we will give it back later when decoded.
683 * This allows multiple request for a buffer per frame; unusual but possible. */
684 gst_buffer_replace (&dframe->buffer, frame->output_buffer);
685 gst_buffer_replace (&frame->output_buffer, NULL);
688 info = &ffmpegdec->output_state->info;
689 if (!gst_video_frame_map (&dframe->vframe, info, dframe->buffer,
692 dframe->mapped = TRUE;
694 for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
695 if (c < GST_VIDEO_INFO_N_PLANES (info)) {
696 picture->data[c] = GST_VIDEO_FRAME_PLANE_DATA (&dframe->vframe, c);
697 picture->linesize[c] = GST_VIDEO_FRAME_PLANE_STRIDE (&dframe->vframe, c);
699 /* libav does not allow stride changes currently, fall back to
700 * non-direct rendering here:
701 * https://bugzilla.gnome.org/show_bug.cgi?id=704769
702 * https://bugzilla.libav.org/show_bug.cgi?id=556
704 if (ffmpegdec->stride[c] == -1) {
705 ffmpegdec->stride[c] = picture->linesize[c];
706 } else if (picture->linesize[c] != ffmpegdec->stride[c]) {
707 GST_LOG_OBJECT (ffmpegdec,
708 "No direct rendering, stride changed c=%d %d->%d", c,
709 ffmpegdec->stride[c], picture->linesize[c]);
711 for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
712 picture->data[c] = NULL;
713 picture->linesize[c] = 0;
714 av_buffer_unref (&picture->buf[c]);
716 gst_video_frame_unmap (&dframe->vframe);
717 dframe->mapped = FALSE;
718 gst_buffer_replace (&dframe->buffer, NULL);
719 ffmpegdec->current_dr = FALSE;
724 picture->data[c] = NULL;
725 picture->linesize[c] = 0;
727 GST_LOG_OBJECT (ffmpegdec, "linesize %d, data %p", picture->linesize[c],
731 picture->buf[0] = av_buffer_create (NULL, 0, dummy_free_buffer, dframe, 0);
733 /* tell ffmpeg we own this buffer, tranfer the ref we have on the buffer to
734 * the opaque data. */
735 picture->type = FF_BUFFER_TYPE_USER;
737 GST_LOG_OBJECT (ffmpegdec, "returned frame %p", dframe->buffer);
744 GST_DEBUG_OBJECT (ffmpegdec, "negotiate failed");
749 GST_LOG_OBJECT (ffmpegdec, "direct rendering disabled, fallback alloc");
754 /* alloc default buffer when we can't get one from downstream */
755 GST_LOG_OBJECT (ffmpegdec, "alloc failed, fallback alloc");
760 /* alloc default buffer when we can't get one from downstream */
761 GST_LOG_OBJECT (ffmpegdec, "failed to map frame, fallback alloc");
762 gst_buffer_replace (&dframe->buffer, NULL);
768 int ret = avcodec_default_get_buffer2 (context, picture, flags);
770 for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
771 ffmpegdec->stride[c] = picture->linesize[c];
773 /* Wrap our buffer around the default one to be able to have a callback
774 * when our data can be freed. Just putting our data into the first free
775 * buffer might not work if there are too many allocated already
778 if (picture->buf[c]) {
779 dframe->avbuffer = picture->buf[c];
781 av_buffer_create (picture->buf[c]->data, picture->buf[c]->size,
782 dummy_free_buffer, dframe, 0);
785 av_buffer_create (NULL, 0, dummy_free_buffer, dframe, 0);
794 GST_WARNING_OBJECT (ffmpegdec, "already alloc'ed output buffer for frame");
795 gst_video_codec_frame_unref (frame);
800 GST_WARNING_OBJECT (ffmpegdec, "Couldn't get codec frame !");
806 picture_changed (GstFFMpegVidDec * ffmpegdec, AVFrame * picture)
808 return !(ffmpegdec->pic_width == picture->width
809 && ffmpegdec->pic_height == picture->height
810 && ffmpegdec->pic_pix_fmt == picture->format
811 && ffmpegdec->pic_par_n == picture->sample_aspect_ratio.num
812 && ffmpegdec->pic_par_d == picture->sample_aspect_ratio.den
813 && ffmpegdec->pic_interlaced == picture->interlaced_frame);
817 context_changed (GstFFMpegVidDec * ffmpegdec, AVCodecContext * context)
819 return !(ffmpegdec->ctx_ticks == context->ticks_per_frame
820 && ffmpegdec->ctx_time_n == context->time_base.num
821 && ffmpegdec->ctx_time_d == context->time_base.den);
825 update_video_context (GstFFMpegVidDec * ffmpegdec, AVCodecContext * context,
826 AVFrame * picture, gboolean force)
828 if (!force && !picture_changed (ffmpegdec, picture)
829 && !context_changed (ffmpegdec, context))
832 GST_DEBUG_OBJECT (ffmpegdec,
833 "Renegotiating video from %dx%d@ %d:%d PAR %d/%d fps pixfmt %d to %dx%d@ %d:%d PAR %d/%d fps pixfmt %d",
834 ffmpegdec->pic_width, ffmpegdec->pic_height,
835 ffmpegdec->pic_par_n, ffmpegdec->pic_par_d,
836 ffmpegdec->ctx_time_n, ffmpegdec->ctx_time_d,
837 ffmpegdec->pic_pix_fmt,
838 picture->width, picture->height,
839 picture->sample_aspect_ratio.num,
840 picture->sample_aspect_ratio.den,
841 context->time_base.num, context->time_base.den, picture->format);
843 ffmpegdec->pic_pix_fmt = picture->format;
844 ffmpegdec->pic_width = picture->width;
845 ffmpegdec->pic_height = picture->height;
846 ffmpegdec->pic_par_n = picture->sample_aspect_ratio.num;
847 ffmpegdec->pic_par_d = picture->sample_aspect_ratio.den;
848 ffmpegdec->pic_interlaced = picture->interlaced_frame;
849 ffmpegdec->ctx_ticks = context->ticks_per_frame;
850 ffmpegdec->ctx_time_n = context->time_base.num;
851 ffmpegdec->ctx_time_d = context->time_base.den;
857 gst_ffmpegviddec_update_par (GstFFMpegVidDec * ffmpegdec,
858 GstVideoInfo * in_info, GstVideoInfo * out_info)
860 gboolean demuxer_par_set = FALSE;
861 gboolean decoder_par_set = FALSE;
862 gint demuxer_num = 1, demuxer_denom = 1;
863 gint decoder_num = 1, decoder_denom = 1;
865 if (in_info->par_n && in_info->par_d) {
866 demuxer_num = in_info->par_n;
867 demuxer_denom = in_info->par_d;
868 demuxer_par_set = TRUE;
869 GST_DEBUG_OBJECT (ffmpegdec, "Demuxer PAR: %d:%d", demuxer_num,
873 if (ffmpegdec->pic_par_n && ffmpegdec->pic_par_d) {
874 decoder_num = ffmpegdec->pic_par_n;
875 decoder_denom = ffmpegdec->pic_par_d;
876 decoder_par_set = TRUE;
877 GST_DEBUG_OBJECT (ffmpegdec, "Decoder PAR: %d:%d", decoder_num,
881 if (!demuxer_par_set && !decoder_par_set)
884 if (demuxer_par_set && !decoder_par_set)
885 goto use_demuxer_par;
887 if (decoder_par_set && !demuxer_par_set)
888 goto use_decoder_par;
890 /* Both the demuxer and the decoder provide a PAR. If one of
891 * the two PARs is 1:1 and the other one is not, use the one
892 * that is not 1:1. */
893 if (demuxer_num == demuxer_denom && decoder_num != decoder_denom)
894 goto use_decoder_par;
896 if (decoder_num == decoder_denom && demuxer_num != demuxer_denom)
897 goto use_demuxer_par;
899 /* Both PARs are non-1:1, so use the PAR provided by the demuxer */
900 goto use_demuxer_par;
904 GST_DEBUG_OBJECT (ffmpegdec,
905 "Setting decoder provided pixel-aspect-ratio of %u:%u", decoder_num,
907 out_info->par_n = decoder_num;
908 out_info->par_d = decoder_denom;
913 GST_DEBUG_OBJECT (ffmpegdec,
914 "Setting demuxer provided pixel-aspect-ratio of %u:%u", demuxer_num,
916 out_info->par_n = demuxer_num;
917 out_info->par_d = demuxer_denom;
922 GST_DEBUG_OBJECT (ffmpegdec,
923 "Neither demuxer nor codec provide a pixel-aspect-ratio");
931 gst_ffmpegviddec_negotiate (GstFFMpegVidDec * ffmpegdec,
932 AVCodecContext * context, AVFrame * picture, gboolean force)
935 GstVideoInfo *in_info, *out_info;
936 GstVideoCodecState *output_state;
939 if (!update_video_context (ffmpegdec, context, picture, force))
942 fmt = gst_ffmpeg_pixfmt_to_videoformat (ffmpegdec->pic_pix_fmt);
943 if (G_UNLIKELY (fmt == GST_VIDEO_FORMAT_UNKNOWN))
947 gst_video_decoder_set_output_state (GST_VIDEO_DECODER (ffmpegdec), fmt,
948 ffmpegdec->pic_width, ffmpegdec->pic_height, ffmpegdec->input_state);
949 if (ffmpegdec->output_state)
950 gst_video_codec_state_unref (ffmpegdec->output_state);
951 ffmpegdec->output_state = output_state;
953 in_info = &ffmpegdec->input_state->info;
954 out_info = &ffmpegdec->output_state->info;
956 /* set the interlaced flag */
957 if (ffmpegdec->pic_interlaced)
958 out_info->interlace_mode = GST_VIDEO_INTERLACE_MODE_MIXED;
960 out_info->interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
962 switch (context->chroma_sample_location) {
964 out_info->chroma_site = GST_VIDEO_CHROMA_SITE_MPEG2;
967 out_info->chroma_site = GST_VIDEO_CHROMA_SITE_JPEG;
970 out_info->chroma_site = GST_VIDEO_CHROMA_SITE_DV;
973 out_info->chroma_site = GST_VIDEO_CHROMA_SITE_V_COSITED;
979 /* try to find a good framerate */
980 if ((in_info->fps_d && in_info->fps_n) ||
981 GST_VIDEO_INFO_FLAG_IS_SET (in_info, GST_VIDEO_FLAG_VARIABLE_FPS)) {
982 /* take framerate from input when it was specified (#313970) */
983 fps_n = in_info->fps_n;
984 fps_d = in_info->fps_d;
986 fps_n = ffmpegdec->ctx_time_d / ffmpegdec->ctx_ticks;
987 fps_d = ffmpegdec->ctx_time_n;
990 GST_LOG_OBJECT (ffmpegdec, "invalid framerate: %d/0, -> %d/1", fps_n,
994 if (gst_util_fraction_compare (fps_n, fps_d, 1000, 1) > 0) {
995 GST_LOG_OBJECT (ffmpegdec, "excessive framerate: %d/%d, -> 0/1", fps_n,
1002 GST_LOG_OBJECT (ffmpegdec, "setting framerate: %d/%d", fps_n, fps_d);
1003 out_info->fps_n = fps_n;
1004 out_info->fps_d = fps_d;
1006 /* calculate and update par now */
1007 gst_ffmpegviddec_update_par (ffmpegdec, in_info, out_info);
1009 /* Copy stereo/multiview info from upstream if set */
1010 if (GST_VIDEO_INFO_MULTIVIEW_MODE (in_info) != GST_VIDEO_MULTIVIEW_MODE_NONE) {
1011 GST_VIDEO_INFO_MULTIVIEW_MODE (out_info) =
1012 GST_VIDEO_INFO_MULTIVIEW_MODE (in_info);
1013 GST_VIDEO_INFO_MULTIVIEW_FLAGS (out_info) =
1014 GST_VIDEO_INFO_MULTIVIEW_FLAGS (in_info);
1017 if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (ffmpegdec)))
1018 goto negotiate_failed;
1025 GST_ERROR_OBJECT (ffmpegdec,
1026 "decoder requires a video format unsupported by GStreamer");
1031 /* Reset so we try again next time even if force==FALSE */
1032 ffmpegdec->pic_pix_fmt = 0;
1033 ffmpegdec->pic_width = 0;
1034 ffmpegdec->pic_height = 0;
1035 ffmpegdec->pic_par_n = 0;
1036 ffmpegdec->pic_par_d = 0;
1037 ffmpegdec->ctx_ticks = 0;
1038 ffmpegdec->ctx_time_n = 0;
1039 ffmpegdec->ctx_time_d = 0;
1041 GST_ERROR_OBJECT (ffmpegdec, "negotiation failed");
1046 /* perform qos calculations before decoding the next frame.
1048 * Sets the skip_frame flag and if things are really bad, skips to the next
1053 gst_ffmpegviddec_do_qos (GstFFMpegVidDec * ffmpegdec,
1054 GstVideoCodecFrame * frame, gboolean * mode_switch)
1056 GstClockTimeDiff diff;
1057 GstSegmentFlags skip_flags =
1058 GST_VIDEO_DECODER_INPUT_SEGMENT (ffmpegdec).flags;
1060 *mode_switch = FALSE;
1065 if (skip_flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
1066 ffmpegdec->context->skip_frame = AVDISCARD_NONKEY;
1067 *mode_switch = TRUE;
1068 } else if (skip_flags & GST_SEGMENT_FLAG_TRICKMODE) {
1069 ffmpegdec->context->skip_frame = AVDISCARD_NONREF;
1070 *mode_switch = TRUE;
1074 gst_video_decoder_get_max_decode_time (GST_VIDEO_DECODER (ffmpegdec),
1077 /* if we don't have timing info, then we don't do QoS */
1078 if (G_UNLIKELY (diff == G_MAXINT64))
1081 GST_DEBUG_OBJECT (ffmpegdec, "decoding time %" G_GINT64_FORMAT, diff);
1083 if (*mode_switch == FALSE) {
1084 if (diff > 0 && ffmpegdec->context->skip_frame != AVDISCARD_DEFAULT) {
1085 ffmpegdec->context->skip_frame = AVDISCARD_DEFAULT;
1086 *mode_switch = TRUE;
1087 GST_DEBUG_OBJECT (ffmpegdec, "QOS: normal mode");
1090 else if (diff <= 0 && ffmpegdec->context->skip_frame != AVDISCARD_NONREF) {
1091 ffmpegdec->context->skip_frame = AVDISCARD_NONREF;
1092 *mode_switch = TRUE;
1093 GST_DEBUG_OBJECT (ffmpegdec,
1094 "QOS: hurry up, diff %" G_GINT64_FORMAT " >= 0", diff);
1099 /* get an outbuf buffer with the current picture */
1100 static GstFlowReturn
1101 get_output_buffer (GstFFMpegVidDec * ffmpegdec, GstVideoCodecFrame * frame)
1103 GstFlowReturn ret = GST_FLOW_OK;
1104 AVPicture pic, *outpic;
1105 GstVideoFrame vframe;
1109 GST_LOG_OBJECT (ffmpegdec, "get output buffer");
1111 if (!ffmpegdec->output_state)
1112 goto not_negotiated;
1115 gst_video_decoder_allocate_output_frame (GST_VIDEO_DECODER (ffmpegdec),
1117 if (G_UNLIKELY (ret != GST_FLOW_OK))
1120 /* original ffmpeg code does not handle odd sizes correctly.
1121 * This patched up version does */
1122 /* Fill avpicture */
1123 info = &ffmpegdec->output_state->info;
1124 if (!gst_video_frame_map (&vframe, info, frame->output_buffer,
1125 GST_MAP_READ | GST_MAP_WRITE))
1128 for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
1129 if (c < GST_VIDEO_INFO_N_PLANES (info)) {
1130 pic.data[c] = GST_VIDEO_FRAME_PLANE_DATA (&vframe, c);
1131 pic.linesize[c] = GST_VIDEO_FRAME_PLANE_STRIDE (&vframe, c);
1134 pic.linesize[c] = 0;
1136 GST_LOG_OBJECT (ffmpegdec, "linesize %d, data %p", pic.linesize[c],
1140 outpic = (AVPicture *) ffmpegdec->picture;
1142 av_picture_copy (&pic, outpic, ffmpegdec->context->pix_fmt,
1143 GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info));
1145 gst_video_frame_unmap (&vframe);
1147 ffmpegdec->picture->reordered_opaque = -1;
1154 GST_DEBUG_OBJECT (ffmpegdec, "allocation failed");
1159 GST_DEBUG_OBJECT (ffmpegdec, "not negotiated");
1160 return GST_FLOW_NOT_NEGOTIATED;
1165 gst_avpacket_init (AVPacket * packet, guint8 * data, guint size)
1167 memset (packet, 0, sizeof (AVPacket));
1168 packet->data = data;
1169 packet->size = size;
1172 /* gst_ffmpegviddec_[video|audio]_frame:
1174 * data: pointer to the data to decode
1175 * size: size of data in bytes
1176 * in_timestamp: incoming timestamp.
1177 * in_duration: incoming duration.
1178 * in_offset: incoming offset (frame number).
1181 * Returns: number of bytes used in decoding. The check for successful decode is
1182 * outbuf being non-NULL.
1185 gst_ffmpegviddec_video_frame (GstFFMpegVidDec * ffmpegdec,
1186 guint8 * data, guint size, gint * have_data, GstVideoCodecFrame * frame,
1187 GstFlowReturn * ret)
1190 gboolean mode_switch;
1191 GstVideoCodecFrame *out_frame;
1192 GstFFMpegVidDecVideoFrame *out_dframe;
1197 /* in case we skip frames */
1198 ffmpegdec->picture->pict_type = -1;
1200 /* run QoS code, we don't stop decoding the frame when we are late because
1201 * else we might skip a reference frame */
1202 gst_ffmpegviddec_do_qos (ffmpegdec, frame, &mode_switch);
1204 if (ffmpegdec->is_realvideo && data != NULL) {
1208 /* setup the slice table for realvideo */
1209 if (ffmpegdec->context->slice_offset == NULL)
1210 ffmpegdec->context->slice_offset = g_malloc (sizeof (guint32) * 1000);
1212 slice_count = (*data++) + 1;
1213 ffmpegdec->context->slice_count = slice_count;
1215 for (i = 0; i < slice_count; i++) {
1217 ffmpegdec->context->slice_offset[i] = GST_READ_UINT32_LE (data);
1223 /* save reference to the timing info */
1224 ffmpegdec->context->reordered_opaque = (gint64) frame->system_frame_number;
1225 ffmpegdec->picture->reordered_opaque = (gint64) frame->system_frame_number;
1227 GST_DEBUG_OBJECT (ffmpegdec, "stored opaque values idx %d",
1228 frame->system_frame_number);
1231 /* now decode the frame */
1232 gst_avpacket_init (&packet, data, size);
1234 if (ffmpegdec->palette) {
1237 pal = av_packet_new_side_data (&packet, AV_PKT_DATA_PALETTE,
1239 gst_buffer_extract (ffmpegdec->palette, 0, pal, AVPALETTE_SIZE);
1240 GST_DEBUG_OBJECT (ffmpegdec, "copy pal %p %p", &packet, pal);
1243 /* This might call into get_buffer() from another thread,
1244 * which would cause a deadlock. Release the lock here
1245 * and taking it again later seems safe
1246 * See https://bugzilla.gnome.org/show_bug.cgi?id=726020
1248 GST_VIDEO_DECODER_STREAM_UNLOCK (ffmpegdec);
1249 len = avcodec_decode_video2 (ffmpegdec->context,
1250 ffmpegdec->picture, have_data, &packet);
1251 GST_VIDEO_DECODER_STREAM_LOCK (ffmpegdec);
1253 GST_DEBUG_OBJECT (ffmpegdec, "after decode: len %d, have_data %d",
1256 /* when we are in skip_frame mode, don't complain when ffmpeg returned
1257 * no data because we told it to skip stuff. */
1258 if (len < 0 && (mode_switch || ffmpegdec->context->skip_frame))
1261 /* no data, we're done */
1262 if (len < 0 || *have_data == 0)
1265 /* get the output picture timing info again */
1266 out_dframe = ffmpegdec->picture->opaque;
1267 out_frame = gst_video_codec_frame_ref (out_dframe->frame);
1269 /* also give back a buffer allocated by the frame, if any */
1270 gst_buffer_replace (&out_frame->output_buffer, out_dframe->buffer);
1271 gst_buffer_replace (&out_dframe->buffer, NULL);
1273 GST_DEBUG_OBJECT (ffmpegdec,
1274 "pts %" G_GUINT64_FORMAT " duration %" G_GUINT64_FORMAT,
1275 out_frame->pts, out_frame->duration);
1276 GST_DEBUG_OBJECT (ffmpegdec, "picture: pts %" G_GUINT64_FORMAT,
1277 (guint64) ffmpegdec->picture->pts);
1278 GST_DEBUG_OBJECT (ffmpegdec, "picture: num %d",
1279 ffmpegdec->picture->coded_picture_number);
1280 GST_DEBUG_OBJECT (ffmpegdec, "picture: ref %d",
1281 ffmpegdec->picture->reference);
1282 GST_DEBUG_OBJECT (ffmpegdec, "picture: display %d",
1283 ffmpegdec->picture->display_picture_number);
1284 GST_DEBUG_OBJECT (ffmpegdec, "picture: opaque %p",
1285 ffmpegdec->picture->opaque);
1286 GST_DEBUG_OBJECT (ffmpegdec, "picture: reordered opaque %" G_GUINT64_FORMAT,
1287 (guint64) ffmpegdec->picture->reordered_opaque);
1288 GST_DEBUG_OBJECT (ffmpegdec, "repeat_pict:%d",
1289 ffmpegdec->picture->repeat_pict);
1290 GST_DEBUG_OBJECT (ffmpegdec, "corrupted frame: %d",
1291 ! !(ffmpegdec->picture->flags & AV_FRAME_FLAG_CORRUPT));
1293 if (!gst_ffmpegviddec_negotiate (ffmpegdec, ffmpegdec->context,
1294 ffmpegdec->picture, FALSE))
1295 goto negotiation_error;
1297 if (G_UNLIKELY (out_frame->output_buffer == NULL))
1298 *ret = get_output_buffer (ffmpegdec, out_frame);
1300 if (G_UNLIKELY (*ret != GST_FLOW_OK))
1303 /* Mark corrupted frames as corrupted */
1304 if (ffmpegdec->picture->flags & AV_FRAME_FLAG_CORRUPT)
1305 GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_BUFFER_FLAG_CORRUPTED);
1307 if (ffmpegdec->pic_interlaced) {
1308 /* set interlaced flags */
1309 if (ffmpegdec->picture->repeat_pict)
1310 GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_VIDEO_BUFFER_FLAG_RFF);
1311 if (ffmpegdec->picture->top_field_first)
1312 GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_VIDEO_BUFFER_FLAG_TFF);
1313 if (ffmpegdec->picture->interlaced_frame)
1314 GST_BUFFER_FLAG_SET (out_frame->output_buffer,
1315 GST_VIDEO_BUFFER_FLAG_INTERLACED);
1319 /* so we decoded this frame, frames preceding it in decoding order
1320 * that still do not have a buffer allocated seem rather useless,
1321 * and can be discarded, due to e.g. misparsed bogus frame
1322 * or non-keyframe in skipped decoding, ...
1323 * In any case, not likely to be seen again, so discard those,
1324 * before they pile up and/or mess with timestamping */
1327 GstVideoDecoder *dec = GST_VIDEO_DECODER (ffmpegdec);
1328 gboolean old = TRUE;
1330 ol = l = gst_video_decoder_get_frames (dec);
1332 GstVideoCodecFrame *tmp = l->data;
1337 if (old && GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY (tmp)) {
1338 GST_LOG_OBJECT (dec,
1339 "discarding ghost frame %p (#%d) PTS:%" GST_TIME_FORMAT " DTS:%"
1340 GST_TIME_FORMAT, tmp, tmp->system_frame_number,
1341 GST_TIME_ARGS (tmp->pts), GST_TIME_ARGS (tmp->dts));
1342 /* drop extra ref and remove from frame list */
1343 gst_video_decoder_release_frame (dec, tmp);
1345 /* drop extra ref we got */
1346 gst_video_codec_frame_unref (tmp);
1353 av_frame_unref (ffmpegdec->picture);
1355 /* FIXME: Ideally we would remap the buffer read-only now before pushing but
1356 * libav might still have a reference to it!
1360 gst_video_decoder_finish_frame (GST_VIDEO_DECODER (ffmpegdec), out_frame);
1363 GST_DEBUG_OBJECT (ffmpegdec, "return flow %s, len %d",
1364 gst_flow_get_name (*ret), len);
1370 GST_DEBUG_OBJECT (ffmpegdec, "no output buffer");
1371 gst_video_decoder_drop_frame (GST_VIDEO_DECODER (ffmpegdec), out_frame);
1378 if (GST_PAD_IS_FLUSHING (GST_VIDEO_DECODER_SRC_PAD (ffmpegdec))) {
1379 *ret = GST_FLOW_FLUSHING;
1382 GST_WARNING_OBJECT (ffmpegdec, "Error negotiating format");
1383 *ret = GST_FLOW_NOT_NEGOTIATED;
1389 /* gst_ffmpegviddec_frame:
1391 * data: pointer to the data to decode
1392 * size: size of data in bytes
1393 * got_data: 0 if no data was decoded, != 0 otherwise.
1394 * in_time: timestamp of data
1395 * in_duration: duration of data
1396 * ret: GstFlowReturn to return in the chain function
1398 * Decode the given frame and pushes it downstream.
1400 * Returns: Number of bytes used in decoding, -1 on error/failure.
1404 gst_ffmpegviddec_frame (GstFFMpegVidDec * ffmpegdec,
1405 guint8 * data, guint size, gint * have_data, GstVideoCodecFrame * frame,
1406 GstFlowReturn * ret)
1408 GstFFMpegVidDecClass *oclass;
1411 if (G_UNLIKELY (ffmpegdec->context->codec == NULL))
1414 GST_LOG_OBJECT (ffmpegdec, "data:%p, size:%d", data, size);
1417 ffmpegdec->context->frame_number++;
1419 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
1422 gst_ffmpegviddec_video_frame (ffmpegdec, data, size, have_data, frame,
1426 GST_WARNING_OBJECT (ffmpegdec,
1427 "avdec_%s: decoding error (len: %d, have_data: %d)",
1428 oclass->in_plugin->name, len, *have_data);
1436 GST_ERROR_OBJECT (ffmpegdec, "no codec context");
1437 *ret = GST_FLOW_NOT_NEGOTIATED;
1443 gst_ffmpegviddec_drain (GstFFMpegVidDec * ffmpegdec)
1445 GstFFMpegVidDecClass *oclass;
1447 if (!ffmpegdec->opened)
1450 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
1452 if (oclass->in_plugin->capabilities & CODEC_CAP_DELAY) {
1453 gint have_data, len;
1456 GST_LOG_OBJECT (ffmpegdec,
1457 "codec has delay capabilities, calling until ffmpeg has drained everything");
1460 len = gst_ffmpegviddec_frame (ffmpegdec, NULL, 0, &have_data, NULL, &ret);
1461 } while (len >= 0 && have_data == 1 && ret == GST_FLOW_OK);
1462 avcodec_flush_buffers (ffmpegdec->context);
1466 static GstFlowReturn
1467 gst_ffmpegviddec_handle_frame (GstVideoDecoder * decoder,
1468 GstVideoCodecFrame * frame)
1470 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1471 guint8 *data, *bdata;
1472 gint size, len, have_data, bsize;
1474 GstFlowReturn ret = GST_FLOW_OK;
1475 gboolean do_padding;
1477 GST_LOG_OBJECT (ffmpegdec,
1478 "Received new data of size %" G_GSIZE_FORMAT ", dts %" GST_TIME_FORMAT
1479 ", pts:%" GST_TIME_FORMAT ", dur:%" GST_TIME_FORMAT,
1480 gst_buffer_get_size (frame->input_buffer), GST_TIME_ARGS (frame->dts),
1481 GST_TIME_ARGS (frame->pts), GST_TIME_ARGS (frame->duration));
1483 if (!gst_buffer_map (frame->input_buffer, &minfo, GST_MAP_READ)) {
1484 GST_ELEMENT_ERROR (ffmpegdec, STREAM, DECODE, ("Decoding problem"),
1485 ("Failed to map buffer for reading"));
1486 return GST_FLOW_ERROR;
1489 /* treat frame as void until a buffer is requested for it */
1490 GST_VIDEO_CODEC_FRAME_FLAG_SET (frame,
1491 GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY);
1496 if (bsize > 0 && (!GST_MEMORY_IS_ZERO_PADDED (minfo.memory)
1497 || (minfo.maxsize - minfo.size) < FF_INPUT_BUFFER_PADDING_SIZE)) {
1499 if (ffmpegdec->padded_size < bsize + FF_INPUT_BUFFER_PADDING_SIZE) {
1500 ffmpegdec->padded_size = bsize + FF_INPUT_BUFFER_PADDING_SIZE;
1501 ffmpegdec->padded = g_realloc (ffmpegdec->padded, ffmpegdec->padded_size);
1502 GST_LOG_OBJECT (ffmpegdec, "resized padding buffer to %d",
1503 ffmpegdec->padded_size);
1505 GST_CAT_TRACE_OBJECT (GST_CAT_PERFORMANCE, ffmpegdec,
1506 "Copy input to add padding");
1507 memcpy (ffmpegdec->padded, bdata, bsize);
1508 memset (ffmpegdec->padded + bsize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
1510 bdata = ffmpegdec->padded;
1517 guint8 tmp_padding[FF_INPUT_BUFFER_PADDING_SIZE];
1519 /* parse, if at all possible */
1524 /* add temporary padding */
1525 GST_CAT_TRACE_OBJECT (GST_CAT_PERFORMANCE, ffmpegdec,
1526 "Add temporary input padding");
1527 memcpy (tmp_padding, data + size, FF_INPUT_BUFFER_PADDING_SIZE);
1528 memset (data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
1531 /* decode a frame of audio/video now */
1533 gst_ffmpegviddec_frame (ffmpegdec, data, size, &have_data, frame, &ret);
1535 if (ret != GST_FLOW_OK) {
1536 GST_LOG_OBJECT (ffmpegdec, "breaking because of flow ret %s",
1537 gst_flow_get_name (ret));
1538 /* bad flow return, make sure we discard all data and exit */
1544 memcpy (data + size, tmp_padding, FF_INPUT_BUFFER_PADDING_SIZE);
1547 if (len == 0 && have_data == 0) {
1548 /* nothing was decoded, this could be because no data was available or
1549 * because we were skipping frames.
1550 * If we have no context we must exit and wait for more data, we keep the
1552 GST_LOG_OBJECT (ffmpegdec, "Decoding didn't return any data, breaking");
1557 /* a decoding error happened, we must break and try again with next data. */
1558 GST_LOG_OBJECT (ffmpegdec, "Decoding error, breaking");
1563 /* prepare for the next round, for codecs with a context we did this
1564 * already when using the parser. */
1570 GST_LOG_OBJECT (ffmpegdec, "Before (while bsize>0). bsize:%d , bdata:%p",
1572 } while (bsize > 0);
1575 GST_DEBUG_OBJECT (ffmpegdec, "Dropping %d bytes of data", bsize);
1577 gst_buffer_unmap (frame->input_buffer, &minfo);
1578 gst_video_codec_frame_unref (frame);
1585 gst_ffmpegviddec_start (GstVideoDecoder * decoder)
1587 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1588 GstFFMpegVidDecClass *oclass;
1590 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
1592 GST_OBJECT_LOCK (ffmpegdec);
1593 gst_ffmpeg_avcodec_close (ffmpegdec->context);
1594 if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) {
1595 GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
1596 GST_OBJECT_UNLOCK (ffmpegdec);
1599 ffmpegdec->context->opaque = ffmpegdec;
1600 GST_OBJECT_UNLOCK (ffmpegdec);
1606 gst_ffmpegviddec_stop (GstVideoDecoder * decoder)
1608 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1610 GST_OBJECT_LOCK (ffmpegdec);
1611 gst_ffmpegviddec_close (ffmpegdec, FALSE);
1612 GST_OBJECT_UNLOCK (ffmpegdec);
1613 g_free (ffmpegdec->padded);
1614 ffmpegdec->padded = NULL;
1615 ffmpegdec->padded_size = 0;
1616 if (ffmpegdec->input_state)
1617 gst_video_codec_state_unref (ffmpegdec->input_state);
1618 ffmpegdec->input_state = NULL;
1619 if (ffmpegdec->output_state)
1620 gst_video_codec_state_unref (ffmpegdec->output_state);
1621 ffmpegdec->output_state = NULL;
1623 ffmpegdec->pic_pix_fmt = 0;
1624 ffmpegdec->pic_width = 0;
1625 ffmpegdec->pic_height = 0;
1626 ffmpegdec->pic_par_n = 0;
1627 ffmpegdec->pic_par_d = 0;
1628 ffmpegdec->ctx_ticks = 0;
1629 ffmpegdec->ctx_time_n = 0;
1630 ffmpegdec->ctx_time_d = 0;
1635 static GstFlowReturn
1636 gst_ffmpegviddec_finish (GstVideoDecoder * decoder)
1638 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1640 gst_ffmpegviddec_drain (ffmpegdec);
1646 gst_ffmpegviddec_flush (GstVideoDecoder * decoder)
1648 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1650 if (ffmpegdec->opened)
1651 avcodec_flush_buffers (ffmpegdec->context);
1657 gst_ffmpegviddec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query)
1659 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1660 GstVideoCodecState *state;
1661 GstBufferPool *pool;
1662 guint size, min, max;
1663 GstStructure *config;
1664 gboolean have_videometa, have_alignment, update_pool = FALSE;
1665 GstAllocator *allocator = NULL;
1666 GstAllocationParams params = { 0, 15, 0, 0, };
1668 if (!GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder,
1672 state = gst_video_decoder_get_output_state (decoder);
1674 if (gst_query_get_n_allocation_params (query) > 0) {
1675 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
1676 params.align = MAX (params.align, 15);
1678 gst_query_add_allocation_param (query, allocator, ¶ms);
1681 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
1683 /* Don't use pool that can't grow, as we don't know how many buffer we'll
1684 * need, otherwise we may stall */
1685 if (max != 0 && max < REQUIRED_POOL_MAX_BUFFERS) {
1686 gst_object_unref (pool);
1687 pool = gst_video_buffer_pool_new ();
1691 /* if there is an allocator, also drop it, as it might be the reason we
1692 * have this limit. Default will be used */
1694 gst_object_unref (allocator);
1699 config = gst_buffer_pool_get_config (pool);
1700 gst_buffer_pool_config_set_params (config, state->caps, size, min, max);
1701 /* we are happy with the default allocator but we would like to have 16 bytes
1702 * aligned and padded memory */
1703 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
1706 gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
1708 gst_buffer_pool_config_add_option (config,
1709 GST_BUFFER_POOL_OPTION_VIDEO_META);
1712 gst_buffer_pool_has_option (pool, GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
1714 /* we can only enable the alignment if downstream supports the
1716 if (have_alignment && have_videometa) {
1717 GstVideoAlignment align;
1719 gint linesize_align[4];
1723 width = GST_VIDEO_INFO_WIDTH (&state->info);
1724 height = GST_VIDEO_INFO_HEIGHT (&state->info);
1725 /* let ffmpeg find the alignment and padding */
1726 avcodec_align_dimensions2 (ffmpegdec->context, &width, &height,
1730 context->flags & CODEC_FLAG_EMU_EDGE ? 0 : avcodec_get_edge_width ();
1731 /* increase the size for the padding */
1733 height += edge << 1;
1735 align.padding_top = edge;
1736 align.padding_left = edge;
1737 align.padding_right = width - GST_VIDEO_INFO_WIDTH (&state->info) - edge;
1738 align.padding_bottom = height - GST_VIDEO_INFO_HEIGHT (&state->info) - edge;
1740 /* add extra padding to match libav buffer allocation sizes */
1741 align.padding_bottom++;
1743 for (i = 0; i < GST_VIDEO_MAX_PLANES; i++)
1744 align.stride_align[i] =
1745 (linesize_align[i] > 0 ? linesize_align[i] - 1 : 0);
1747 GST_DEBUG_OBJECT (ffmpegdec, "aligned dimension %dx%d -> %dx%d "
1748 "padding t:%u l:%u r:%u b:%u, stride_align %d:%d:%d:%d",
1749 GST_VIDEO_INFO_WIDTH (&state->info),
1750 GST_VIDEO_INFO_HEIGHT (&state->info), width, height, align.padding_top,
1751 align.padding_left, align.padding_right, align.padding_bottom,
1752 align.stride_align[0], align.stride_align[1], align.stride_align[2],
1753 align.stride_align[3]);
1755 gst_buffer_pool_config_add_option (config,
1756 GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
1757 gst_buffer_pool_config_set_video_alignment (config, &align);
1759 if (ffmpegdec->direct_rendering) {
1760 GstFFMpegVidDecClass *oclass;
1762 GST_DEBUG_OBJECT (ffmpegdec, "trying to enable direct rendering");
1764 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
1766 if (oclass->in_plugin->capabilities & CODEC_CAP_DR1) {
1767 GST_DEBUG_OBJECT (ffmpegdec, "enabled direct rendering");
1768 ffmpegdec->current_dr = TRUE;
1770 GST_DEBUG_OBJECT (ffmpegdec, "direct rendering not supported");
1774 GST_DEBUG_OBJECT (ffmpegdec,
1775 "alignment or videometa not supported, disable direct rendering");
1777 /* disable direct rendering. This will make us use the fallback ffmpeg
1778 * picture allocation code with padding etc. We will then do the final
1779 * copy (with cropping) into a buffer from our pool */
1780 ffmpegdec->current_dr = FALSE;
1784 gst_buffer_pool_set_config (pool, config);
1787 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
1789 gst_object_unref (pool);
1791 gst_object_unref (allocator);
1792 gst_video_codec_state_unref (state);
1798 gst_ffmpegviddec_propose_allocation (GstVideoDecoder * decoder,
1801 GstAllocationParams params;
1803 gst_allocation_params_init (¶ms);
1804 params.flags = GST_MEMORY_FLAG_ZERO_PADDED;
1806 params.padding = FF_INPUT_BUFFER_PADDING_SIZE;
1807 /* we would like to have some padding so that we don't have to
1808 * memcpy. We don't suggest an allocator. */
1809 gst_query_add_allocation_param (query, NULL, ¶ms);
1811 return GST_VIDEO_DECODER_CLASS (parent_class)->propose_allocation (decoder,
1816 gst_ffmpegviddec_set_property (GObject * object,
1817 guint prop_id, const GValue * value, GParamSpec * pspec)
1819 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object;
1823 ffmpegdec->lowres = ffmpegdec->context->lowres = g_value_get_enum (value);
1825 case PROP_SKIPFRAME:
1826 ffmpegdec->skip_frame = ffmpegdec->context->skip_frame =
1827 g_value_get_enum (value);
1829 case PROP_DIRECT_RENDERING:
1830 ffmpegdec->direct_rendering = g_value_get_boolean (value);
1833 ffmpegdec->debug_mv = ffmpegdec->context->debug_mv =
1834 g_value_get_boolean (value);
1836 case PROP_MAX_THREADS:
1837 ffmpegdec->max_threads = g_value_get_int (value);
1839 case PROP_OUTPUT_CORRUPT:
1840 ffmpegdec->output_corrupt = g_value_get_boolean (value);
1843 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1849 gst_ffmpegviddec_get_property (GObject * object,
1850 guint prop_id, GValue * value, GParamSpec * pspec)
1852 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object;
1856 g_value_set_enum (value, ffmpegdec->context->lowres);
1858 case PROP_SKIPFRAME:
1859 g_value_set_enum (value, ffmpegdec->context->skip_frame);
1861 case PROP_DIRECT_RENDERING:
1862 g_value_set_boolean (value, ffmpegdec->direct_rendering);
1865 g_value_set_boolean (value, ffmpegdec->context->debug_mv);
1867 case PROP_MAX_THREADS:
1868 g_value_set_int (value, ffmpegdec->max_threads);
1870 case PROP_OUTPUT_CORRUPT:
1871 g_value_set_boolean (value, ffmpegdec->output_corrupt);
1874 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1880 gst_ffmpegviddec_register (GstPlugin * plugin)
1882 GTypeInfo typeinfo = {
1883 sizeof (GstFFMpegVidDecClass),
1884 (GBaseInitFunc) gst_ffmpegviddec_base_init,
1886 (GClassInitFunc) gst_ffmpegviddec_class_init,
1889 sizeof (GstFFMpegVidDec),
1891 (GInstanceInitFunc) gst_ffmpegviddec_init,
1897 in_plugin = av_codec_next (NULL);
1899 GST_LOG ("Registering decoders");
1905 /* only video decoders */
1906 if (!av_codec_is_decoder (in_plugin)
1907 || in_plugin->type != AVMEDIA_TYPE_VIDEO)
1910 /* no quasi-codecs, please */
1911 if (in_plugin->id == AV_CODEC_ID_RAWVIDEO ||
1912 in_plugin->id == AV_CODEC_ID_V210 ||
1913 in_plugin->id == AV_CODEC_ID_V210X ||
1914 in_plugin->id == AV_CODEC_ID_R210 ||
1915 (in_plugin->id >= AV_CODEC_ID_PCM_S16LE &&
1916 in_plugin->id <= AV_CODEC_ID_PCM_BLURAY)) {
1920 /* No decoders depending on external libraries (we don't build them, but
1921 * people who build against an external ffmpeg might have them.
1922 * We have native gstreamer plugins for all of those libraries anyway. */
1923 if (!strncmp (in_plugin->name, "lib", 3)) {
1925 ("Not using external library decoder %s. Use the gstreamer-native ones instead.",
1930 /* No vdpau plugins until we can figure out how to properly use them
1931 * outside of ffmpeg. */
1932 if (g_str_has_suffix (in_plugin->name, "_vdpau")) {
1934 ("Ignoring VDPAU decoder %s. We can't handle this outside of ffmpeg",
1939 if (g_str_has_suffix (in_plugin->name, "_xvmc")) {
1941 ("Ignoring XVMC decoder %s. We can't handle this outside of ffmpeg",
1946 GST_DEBUG ("Trying plugin %s [%s]", in_plugin->name, in_plugin->long_name);
1948 /* no codecs for which we're GUARANTEED to have better alternatives */
1949 /* MPEG1VIDEO : the mpeg2video decoder is preferred */
1950 /* MP1 : Use MP3 for decoding */
1951 /* MP2 : Use MP3 for decoding */
1952 /* Theora: Use libtheora based theoradec */
1953 if (!strcmp (in_plugin->name, "gif") ||
1954 !strcmp (in_plugin->name, "theora") ||
1955 !strcmp (in_plugin->name, "mpeg1video") ||
1956 strstr (in_plugin->name, "crystalhd") != NULL ||
1957 !strcmp (in_plugin->name, "ass") ||
1958 !strcmp (in_plugin->name, "srt") ||
1959 !strcmp (in_plugin->name, "pgssub") ||
1960 !strcmp (in_plugin->name, "dvdsub") ||
1961 !strcmp (in_plugin->name, "dvbsub")) {
1962 GST_LOG ("Ignoring decoder %s", in_plugin->name);
1966 /* construct the type */
1967 if (!strcmp (in_plugin->name, "hevc")) {
1968 plugin_name = g_strdup ("h265");
1970 plugin_name = g_strdup ((gchar *) in_plugin->name);
1972 g_strdelimit (plugin_name, NULL, '_');
1973 type_name = g_strdup_printf ("avdec_%s", plugin_name);
1974 g_free (plugin_name);
1976 type = g_type_from_name (type_name);
1979 /* create the gtype now */
1981 g_type_register_static (GST_TYPE_VIDEO_DECODER, type_name, &typeinfo,
1983 g_type_set_qdata (type, GST_FFDEC_PARAMS_QDATA, (gpointer) in_plugin);
1986 /* (Ronald) MPEG-4 gets a higher priority because it has been well-
1987 * tested and by far outperforms divxdec/xviddec - so we prefer it.
1988 * msmpeg4v3 same, as it outperforms divxdec for divx3 playback.
1989 * VC1/WMV3 are not working and thus unpreferred for now. */
1990 switch (in_plugin->id) {
1991 case AV_CODEC_ID_MPEG4:
1992 case AV_CODEC_ID_MSMPEG4V3:
1993 case AV_CODEC_ID_H264:
1994 case AV_CODEC_ID_HEVC:
1995 case AV_CODEC_ID_RV10:
1996 case AV_CODEC_ID_RV20:
1997 case AV_CODEC_ID_RV30:
1998 case AV_CODEC_ID_RV40:
1999 rank = GST_RANK_PRIMARY;
2001 /* DVVIDEO: we have a good dv decoder, fast on both ppc as well as x86.
2002 * They say libdv's quality is better though. leave as secondary.
2003 * note: if you change this, see the code in gstdv.c in good/ext/dv.
2005 case AV_CODEC_ID_DVVIDEO:
2006 rank = GST_RANK_SECONDARY;
2009 rank = GST_RANK_MARGINAL;
2012 if (!gst_element_register (plugin, type_name, rank, type)) {
2013 g_warning ("Failed to register %s", type_name);
2021 in_plugin = av_codec_next (in_plugin);
2024 GST_LOG ("Finished Registering decoders");