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, gboolean force);
90 /* some sort of bufferpool handling, but different */
91 static int gst_ffmpegviddec_get_buffer (AVCodecContext * context,
93 static int gst_ffmpegviddec_reget_buffer (AVCodecContext * context,
95 static void gst_ffmpegviddec_release_buffer (AVCodecContext * context,
98 static GstFlowReturn gst_ffmpegviddec_finish (GstVideoDecoder * decoder);
99 static void gst_ffmpegviddec_drain (GstFFMpegVidDec * ffmpegdec);
101 #define GST_FFDEC_PARAMS_QDATA g_quark_from_static_string("avdec-params")
103 static GstElementClass *parent_class = NULL;
105 #define GST_FFMPEGVIDDEC_TYPE_LOWRES (gst_ffmpegviddec_lowres_get_type())
107 gst_ffmpegviddec_lowres_get_type (void)
109 static GType ffmpegdec_lowres_type = 0;
111 if (!ffmpegdec_lowres_type) {
112 static const GEnumValue ffmpegdec_lowres[] = {
114 {1, "1", "1/2-size"},
115 {2, "2", "1/4-size"},
119 ffmpegdec_lowres_type =
120 g_enum_register_static ("GstLibAVVidDecLowres", ffmpegdec_lowres);
123 return ffmpegdec_lowres_type;
126 #define GST_FFMPEGVIDDEC_TYPE_SKIPFRAME (gst_ffmpegviddec_skipframe_get_type())
128 gst_ffmpegviddec_skipframe_get_type (void)
130 static GType ffmpegdec_skipframe_type = 0;
132 if (!ffmpegdec_skipframe_type) {
133 static const GEnumValue ffmpegdec_skipframe[] = {
134 {0, "0", "Skip nothing"},
135 {1, "1", "Skip B-frames"},
136 {2, "2", "Skip IDCT/Dequantization"},
137 {5, "5", "Skip everything"},
141 ffmpegdec_skipframe_type =
142 g_enum_register_static ("GstLibAVVidDecSkipFrame", ffmpegdec_skipframe);
145 return ffmpegdec_skipframe_type;
149 gst_ffmpegviddec_base_init (GstFFMpegVidDecClass * klass)
151 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
152 GstPadTemplate *sinktempl, *srctempl;
153 GstCaps *sinkcaps, *srccaps;
155 gchar *longname, *description;
158 (AVCodec *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
159 GST_FFDEC_PARAMS_QDATA);
160 g_assert (in_plugin != NULL);
162 /* construct the element details struct */
163 longname = g_strdup_printf ("libav %s decoder", in_plugin->long_name);
164 description = g_strdup_printf ("libav %s decoder", in_plugin->name);
165 gst_element_class_set_metadata (element_class, longname,
166 "Codec/Decoder/Video", description,
167 "Wim Taymans <wim.taymans@gmail.com>, "
168 "Ronald Bultje <rbultje@ronald.bitfreak.net>, "
169 "Edward Hervey <bilboed@bilboed.com>");
171 g_free (description);
174 sinkcaps = gst_ffmpeg_codecid_to_caps (in_plugin->id, NULL, FALSE);
176 GST_DEBUG ("Couldn't get sink caps for decoder '%s'", in_plugin->name);
177 sinkcaps = gst_caps_new_empty_simple ("unknown/unknown");
179 srccaps = gst_ffmpeg_codectype_to_video_caps (NULL,
180 in_plugin->id, FALSE, in_plugin);
182 GST_DEBUG ("Couldn't get source caps for decoder '%s'", in_plugin->name);
183 srccaps = gst_caps_from_string ("video/x-raw");
187 sinktempl = gst_pad_template_new ("sink", GST_PAD_SINK,
188 GST_PAD_ALWAYS, sinkcaps);
189 srctempl = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, srccaps);
191 gst_element_class_add_pad_template (element_class, srctempl);
192 gst_element_class_add_pad_template (element_class, sinktempl);
194 klass->in_plugin = in_plugin;
198 gst_ffmpegviddec_class_init (GstFFMpegVidDecClass * klass)
200 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
201 GstVideoDecoderClass *viddec_class = GST_VIDEO_DECODER_CLASS (klass);
204 parent_class = g_type_class_peek_parent (klass);
206 gobject_class->finalize = gst_ffmpegviddec_finalize;
208 gobject_class->set_property = gst_ffmpegviddec_set_property;
209 gobject_class->get_property = gst_ffmpegviddec_get_property;
211 g_object_class_install_property (gobject_class, PROP_SKIPFRAME,
212 g_param_spec_enum ("skip-frame", "Skip frames",
213 "Which types of frames to skip during decoding",
214 GST_FFMPEGVIDDEC_TYPE_SKIPFRAME, 0,
215 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
216 g_object_class_install_property (gobject_class, PROP_LOWRES,
217 g_param_spec_enum ("lowres", "Low resolution",
218 "At which resolution to decode images",
219 GST_FFMPEGVIDDEC_TYPE_LOWRES, 0,
220 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
221 g_object_class_install_property (gobject_class, PROP_DIRECT_RENDERING,
222 g_param_spec_boolean ("direct-rendering", "Direct Rendering",
223 "Enable direct rendering", DEFAULT_DIRECT_RENDERING,
224 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
225 g_object_class_install_property (gobject_class, PROP_DEBUG_MV,
226 g_param_spec_boolean ("debug-mv", "Debug motion vectors",
227 "Whether libav should print motion vectors on top of the image",
228 DEFAULT_DEBUG_MV, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
229 g_object_class_install_property (gobject_class, PROP_OUTPUT_CORRUPT,
230 g_param_spec_boolean ("output-corrupt", "Output corrupt buffers",
231 "Whether libav should output frames even if corrupted",
232 DEFAULT_OUTPUT_CORRUPT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
234 caps = klass->in_plugin->capabilities;
235 if (caps & (CODEC_CAP_FRAME_THREADS | CODEC_CAP_SLICE_THREADS)) {
236 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_THREADS,
237 g_param_spec_int ("max-threads", "Maximum decode threads",
238 "Maximum number of worker threads to spawn. (0 = auto)",
239 0, G_MAXINT, DEFAULT_MAX_THREADS,
240 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
243 viddec_class->set_format = gst_ffmpegviddec_set_format;
244 viddec_class->handle_frame = gst_ffmpegviddec_handle_frame;
245 viddec_class->start = gst_ffmpegviddec_start;
246 viddec_class->stop = gst_ffmpegviddec_stop;
247 viddec_class->flush = gst_ffmpegviddec_flush;
248 viddec_class->finish = gst_ffmpegviddec_finish;
249 viddec_class->drain = gst_ffmpegviddec_finish; /* drain and finish are the same to us */
250 viddec_class->decide_allocation = gst_ffmpegviddec_decide_allocation;
251 viddec_class->propose_allocation = gst_ffmpegviddec_propose_allocation;
255 gst_ffmpegviddec_init (GstFFMpegVidDec * ffmpegdec)
257 GstFFMpegVidDecClass *klass =
258 (GstFFMpegVidDecClass *) G_OBJECT_GET_CLASS (ffmpegdec);
260 /* some ffmpeg data */
261 ffmpegdec->context = avcodec_alloc_context3 (klass->in_plugin);
262 ffmpegdec->context->opaque = ffmpegdec;
263 ffmpegdec->picture = avcodec_alloc_frame ();
264 ffmpegdec->opened = FALSE;
265 ffmpegdec->skip_frame = ffmpegdec->lowres = 0;
266 ffmpegdec->direct_rendering = DEFAULT_DIRECT_RENDERING;
267 ffmpegdec->debug_mv = DEFAULT_DEBUG_MV;
268 ffmpegdec->max_threads = DEFAULT_MAX_THREADS;
269 ffmpegdec->output_corrupt = DEFAULT_OUTPUT_CORRUPT;
271 gst_video_decoder_set_needs_format (GST_VIDEO_DECODER (ffmpegdec), TRUE);
275 gst_ffmpegviddec_finalize (GObject * object)
277 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object;
279 if (ffmpegdec->context != NULL) {
280 gst_ffmpeg_avcodec_close (ffmpegdec->context);
281 av_free (ffmpegdec->context);
282 ffmpegdec->context = NULL;
285 avcodec_free_frame (&ffmpegdec->picture);
287 G_OBJECT_CLASS (parent_class)->finalize (object);
291 gst_ffmpegviddec_context_set_flags (AVCodecContext * context, guint flags,
294 g_return_if_fail (context != NULL);
297 context->flags |= flags;
299 context->flags &= ~flags;
304 gst_ffmpegviddec_close (GstFFMpegVidDec * ffmpegdec, gboolean reset)
306 GstFFMpegVidDecClass *oclass;
309 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
311 GST_LOG_OBJECT (ffmpegdec, "closing ffmpeg codec");
313 gst_caps_replace (&ffmpegdec->last_caps, NULL);
315 gst_ffmpeg_avcodec_close (ffmpegdec->context);
316 ffmpegdec->opened = FALSE;
318 for (i = 0; i < G_N_ELEMENTS (ffmpegdec->stride); i++)
319 ffmpegdec->stride[i] = -1;
321 gst_buffer_replace (&ffmpegdec->palette, NULL);
323 if (ffmpegdec->context->extradata) {
324 av_free (ffmpegdec->context->extradata);
325 ffmpegdec->context->extradata = NULL;
329 if (avcodec_get_context_defaults3 (ffmpegdec->context,
330 oclass->in_plugin) < 0) {
331 GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
334 ffmpegdec->context->opaque = ffmpegdec;
341 gst_ffmpegviddec_open (GstFFMpegVidDec * ffmpegdec)
343 GstFFMpegVidDecClass *oclass;
346 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
348 if (gst_ffmpeg_avcodec_open (ffmpegdec->context, oclass->in_plugin) < 0)
351 for (i = 0; i < G_N_ELEMENTS (ffmpegdec->stride); i++)
352 ffmpegdec->stride[i] = -1;
354 ffmpegdec->opened = TRUE;
355 ffmpegdec->is_realvideo = FALSE;
357 GST_LOG_OBJECT (ffmpegdec, "Opened libav codec %s, id %d",
358 oclass->in_plugin->name, oclass->in_plugin->id);
360 switch (oclass->in_plugin->id) {
361 case AV_CODEC_ID_RV10:
362 case AV_CODEC_ID_RV30:
363 case AV_CODEC_ID_RV20:
364 case AV_CODEC_ID_RV40:
365 ffmpegdec->is_realvideo = TRUE;
368 GST_LOG_OBJECT (ffmpegdec, "Parser deactivated for format");
372 gst_ffmpegviddec_context_set_flags (ffmpegdec->context,
373 CODEC_FLAG_OUTPUT_CORRUPT, ffmpegdec->output_corrupt);
380 gst_ffmpegviddec_close (ffmpegdec, TRUE);
381 GST_DEBUG_OBJECT (ffmpegdec, "avdec_%s: Failed to open libav codec",
382 oclass->in_plugin->name);
388 gst_ffmpegviddec_get_palette (GstFFMpegVidDec * ffmpegdec,
389 GstVideoCodecState * state)
391 GstStructure *str = gst_caps_get_structure (state->caps, 0);
392 const GValue *palette_v;
395 /* do we have a palette? */
396 if ((palette_v = gst_structure_get_value (str, "palette_data"))) {
397 palette = gst_value_get_buffer (palette_v);
398 GST_DEBUG ("got palette data %p", palette);
399 if (gst_buffer_get_size (palette) >= AVPALETTE_SIZE) {
400 gst_buffer_replace (&ffmpegdec->palette, palette);
407 gst_ffmpegviddec_set_format (GstVideoDecoder * decoder,
408 GstVideoCodecState * state)
410 GstFFMpegVidDec *ffmpegdec;
411 GstFFMpegVidDecClass *oclass;
412 GstClockTime latency = GST_CLOCK_TIME_NONE;
413 gboolean ret = FALSE;
415 ffmpegdec = (GstFFMpegVidDec *) decoder;
416 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
418 if (ffmpegdec->last_caps != NULL &&
419 gst_caps_is_equal (ffmpegdec->last_caps, state->caps)) {
423 GST_DEBUG_OBJECT (ffmpegdec, "setcaps called");
425 GST_OBJECT_LOCK (ffmpegdec);
426 /* stupid check for VC1 */
427 if ((oclass->in_plugin->id == AV_CODEC_ID_WMV3) ||
428 (oclass->in_plugin->id == AV_CODEC_ID_VC1))
429 oclass->in_plugin->id = gst_ffmpeg_caps_to_codecid (state->caps, NULL);
431 /* close old session */
432 if (ffmpegdec->opened) {
433 GST_OBJECT_UNLOCK (ffmpegdec);
434 gst_ffmpegviddec_drain (ffmpegdec);
435 GST_OBJECT_LOCK (ffmpegdec);
436 if (!gst_ffmpegviddec_close (ffmpegdec, TRUE)) {
437 GST_OBJECT_UNLOCK (ffmpegdec);
442 gst_caps_replace (&ffmpegdec->last_caps, state->caps);
444 /* set buffer functions */
445 ffmpegdec->context->get_buffer = gst_ffmpegviddec_get_buffer;
446 ffmpegdec->context->reget_buffer = gst_ffmpegviddec_reget_buffer;
447 ffmpegdec->context->release_buffer = gst_ffmpegviddec_release_buffer;
448 ffmpegdec->context->draw_horiz_band = NULL;
450 /* reset coded_width/_height to prevent it being reused from last time when
451 * the codec is opened again, causing a mismatch and possible
452 * segfault/corruption. (Common scenario when renegotiating caps) */
453 ffmpegdec->context->coded_width = 0;
454 ffmpegdec->context->coded_height = 0;
456 GST_LOG_OBJECT (ffmpegdec, "size %dx%d", ffmpegdec->context->width,
457 ffmpegdec->context->height);
459 /* FIXME : Create a method that takes GstVideoCodecState instead */
460 /* get size and so */
461 gst_ffmpeg_caps_with_codecid (oclass->in_plugin->id,
462 oclass->in_plugin->type, state->caps, ffmpegdec->context);
464 GST_LOG_OBJECT (ffmpegdec, "size after %dx%d", ffmpegdec->context->width,
465 ffmpegdec->context->height);
467 gst_ffmpegviddec_get_palette (ffmpegdec, state);
469 if (!ffmpegdec->context->time_base.den || !ffmpegdec->context->time_base.num) {
470 GST_DEBUG_OBJECT (ffmpegdec, "forcing 25/1 framerate");
471 ffmpegdec->context->time_base.num = 1;
472 ffmpegdec->context->time_base.den = 25;
475 /* workaround encoder bugs */
476 ffmpegdec->context->workaround_bugs |= FF_BUG_AUTODETECT;
477 ffmpegdec->context->err_recognition = 1;
480 ffmpegdec->context->lowres = ffmpegdec->lowres;
481 ffmpegdec->context->skip_frame = ffmpegdec->skip_frame;
483 /* ffmpeg can draw motion vectors on top of the image (not every decoder
485 ffmpegdec->context->debug_mv = ffmpegdec->debug_mv;
491 if (ffmpegdec->max_threads == 0) {
492 if (!(oclass->in_plugin->capabilities & CODEC_CAP_AUTO_THREADS))
493 ffmpegdec->context->thread_count = gst_ffmpeg_auto_max_threads ();
495 ffmpegdec->context->thread_count = 0;
497 ffmpegdec->context->thread_count = ffmpegdec->max_threads;
499 query = gst_query_new_latency ();
501 /* Check if upstream is live. If it isn't we can enable frame based
502 * threading, which is adding latency */
503 if (gst_pad_peer_query (GST_VIDEO_DECODER_SINK_PAD (ffmpegdec), query)) {
504 gst_query_parse_latency (query, &is_live, NULL, NULL);
506 gst_query_unref (query);
509 ffmpegdec->context->thread_type = FF_THREAD_SLICE;
511 ffmpegdec->context->thread_type = FF_THREAD_SLICE | FF_THREAD_FRAME;
514 /* open codec - we don't select an output pix_fmt yet,
515 * simply because we don't know! We only get it
516 * during playback... */
517 if (!gst_ffmpegviddec_open (ffmpegdec))
520 if (ffmpegdec->input_state)
521 gst_video_codec_state_unref (ffmpegdec->input_state);
522 ffmpegdec->input_state = gst_video_codec_state_ref (state);
524 if (ffmpegdec->input_state->info.fps_n) {
525 GstVideoInfo *info = &ffmpegdec->input_state->info;
526 latency = gst_util_uint64_scale_ceil (
527 (ffmpegdec->context->has_b_frames) * GST_SECOND, info->fps_d,
534 GST_OBJECT_UNLOCK (ffmpegdec);
536 if (GST_CLOCK_TIME_IS_VALID (latency))
537 gst_video_decoder_set_latency (decoder, latency, latency);
544 GST_DEBUG_OBJECT (ffmpegdec, "Failed to open");
551 GstFFMpegVidDec *ffmpegdec;
552 GstVideoCodecFrame *frame;
554 GstVideoFrame vframe;
556 } GstFFMpegVidDecVideoFrame;
558 static GstFFMpegVidDecVideoFrame *
559 gst_ffmpegviddec_video_frame_new (GstFFMpegVidDec * ffmpegdec,
560 GstVideoCodecFrame * frame)
562 GstFFMpegVidDecVideoFrame *dframe;
564 dframe = g_slice_new0 (GstFFMpegVidDecVideoFrame);
565 dframe->ffmpegdec = ffmpegdec;
566 dframe->frame = frame;
568 GST_DEBUG_OBJECT (ffmpegdec, "new video frame %p", dframe);
574 gst_ffmpegviddec_video_frame_free (GstFFMpegVidDec * ffmpegdec,
575 GstFFMpegVidDecVideoFrame * frame)
577 GST_DEBUG_OBJECT (ffmpegdec, "free video frame %p", frame);
580 gst_video_frame_unmap (&frame->vframe);
581 gst_video_decoder_release_frame (GST_VIDEO_DECODER (ffmpegdec), frame->frame);
582 gst_buffer_replace (&frame->buffer, NULL);
583 g_slice_free (GstFFMpegVidDecVideoFrame, frame);
587 dummy_free_buffer (void *opaque, uint8_t * data)
589 GstFFMpegVidDecVideoFrame *frame = opaque;
591 gst_ffmpegviddec_video_frame_free (frame->ffmpegdec, frame);
594 /* called when ffmpeg wants us to allocate a buffer to write the decoded frame
595 * into. We try to give it memory from our pool */
597 gst_ffmpegviddec_get_buffer (AVCodecContext * context, AVFrame * picture)
599 GstVideoCodecFrame *frame;
600 GstFFMpegVidDecVideoFrame *dframe;
601 GstFFMpegVidDec *ffmpegdec;
606 ffmpegdec = (GstFFMpegVidDec *) context->opaque;
608 GST_DEBUG_OBJECT (ffmpegdec, "getting buffer picture %p", picture);
610 /* apply the last info we have seen to this picture, when we get the
611 * picture back from ffmpeg we can use this to correctly timestamp the output
613 picture->reordered_opaque = context->reordered_opaque;
614 GST_DEBUG_OBJECT (ffmpegdec, "opaque value SN %d",
615 (gint32) picture->reordered_opaque);
618 gst_video_decoder_get_frame (GST_VIDEO_DECODER (ffmpegdec),
619 picture->reordered_opaque);
620 if (G_UNLIKELY (frame == NULL))
623 /* now it has a buffer allocated, so it is real and will also
625 GST_VIDEO_CODEC_FRAME_FLAG_UNSET (frame,
626 GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY);
628 if (G_UNLIKELY (frame->output_buffer != NULL))
629 goto duplicate_frame;
631 /* GstFFMpegVidDecVideoFrame receives the frame ref */
632 picture->opaque = dframe =
633 gst_ffmpegviddec_video_frame_new (ffmpegdec, frame);
635 GST_DEBUG_OBJECT (ffmpegdec, "storing opaque %p", dframe);
637 ffmpegdec->context->pix_fmt = context->pix_fmt;
639 /* see if we need renegotiation */
640 if (G_UNLIKELY (!gst_ffmpegviddec_negotiate (ffmpegdec, context, FALSE)))
641 goto negotiate_failed;
643 if (!ffmpegdec->current_dr)
647 gst_video_decoder_allocate_output_frame (GST_VIDEO_DECODER (ffmpegdec),
649 if (ret != GST_FLOW_OK)
652 /* piggy-backed alloc'ed on the frame,
653 * and there was much rejoicing and we are grateful.
654 * Now take away buffer from frame, we will give it back later when decoded.
655 * This allows multiple request for a buffer per frame; unusual but possible. */
656 gst_buffer_replace (&dframe->buffer, frame->output_buffer);
657 gst_buffer_replace (&frame->output_buffer, NULL);
660 info = &ffmpegdec->output_state->info;
661 if (!gst_video_frame_map (&dframe->vframe, info, dframe->buffer,
664 dframe->mapped = TRUE;
666 for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
667 if (c < GST_VIDEO_INFO_N_PLANES (info)) {
668 picture->data[c] = GST_VIDEO_FRAME_PLANE_DATA (&dframe->vframe, c);
669 picture->linesize[c] = GST_VIDEO_FRAME_PLANE_STRIDE (&dframe->vframe, c);
671 /* libav does not allow stride changes currently, fall back to
672 * non-direct rendering here:
673 * https://bugzilla.gnome.org/show_bug.cgi?id=704769
674 * https://bugzilla.libav.org/show_bug.cgi?id=556
676 if (ffmpegdec->stride[c] == -1) {
677 ffmpegdec->stride[c] = picture->linesize[c];
678 } else if (picture->linesize[c] != ffmpegdec->stride[c]) {
679 GST_LOG_OBJECT (ffmpegdec,
680 "No direct rendering, stride changed c=%d %d->%d", c,
681 ffmpegdec->stride[c], picture->linesize[c]);
683 for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
684 picture->data[c] = NULL;
685 picture->linesize[c] = 0;
687 gst_video_frame_unmap (&dframe->vframe);
688 dframe->mapped = FALSE;
689 gst_buffer_replace (&dframe->buffer, NULL);
690 ffmpegdec->current_dr = FALSE;
695 picture->data[c] = NULL;
696 picture->linesize[c] = 0;
698 GST_LOG_OBJECT (ffmpegdec, "linesize %d, data %p", picture->linesize[c],
702 /* tell ffmpeg we own this buffer, tranfer the ref we have on the buffer to
703 * the opaque data. */
704 picture->type = FF_BUFFER_TYPE_USER;
706 GST_LOG_OBJECT (ffmpegdec, "returned frame %p", dframe->buffer);
713 GST_DEBUG_OBJECT (ffmpegdec, "negotiate failed");
718 GST_LOG_OBJECT (ffmpegdec, "direct rendering disabled, fallback alloc");
723 /* alloc default buffer when we can't get one from downstream */
724 GST_LOG_OBJECT (ffmpegdec, "alloc failed, fallback alloc");
729 /* alloc default buffer when we can't get one from downstream */
730 GST_LOG_OBJECT (ffmpegdec, "failed to map frame, fallback alloc");
731 gst_buffer_replace (&dframe->buffer, NULL);
737 gboolean first = TRUE;
738 int ret = avcodec_default_get_buffer (context, picture);
740 for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
741 ffmpegdec->stride[c] = picture->linesize[c];
743 if (picture->buf[c] == NULL && first) {
745 av_buffer_create (NULL, 0, dummy_free_buffer, dframe, 0);
754 GST_WARNING_OBJECT (ffmpegdec, "already alloc'ed output buffer for frame");
755 gst_video_codec_frame_unref (frame);
760 GST_WARNING_OBJECT (ffmpegdec, "Couldn't get codec frame !");
765 /* this should havesame effect as _get_buffer wrt opaque metadata,
766 * but preserving current content, if any */
768 gst_ffmpegviddec_reget_buffer (AVCodecContext * context, AVFrame * picture)
770 GstVideoCodecFrame *frame;
771 GstFFMpegVidDecVideoFrame *dframe;
772 GstFFMpegVidDec *ffmpegdec;
774 ffmpegdec = (GstFFMpegVidDec *) context->opaque;
776 GST_DEBUG_OBJECT (ffmpegdec, "regetting buffer picture %p", picture);
778 picture->reordered_opaque = context->reordered_opaque;
780 /* if there is no opaque, we didn't yet attach any frame to it. What usually
781 * happens is that avcodec_default_reget_buffer will call the getbuffer
783 dframe = picture->opaque;
788 gst_video_decoder_get_frame (GST_VIDEO_DECODER (ffmpegdec),
789 picture->reordered_opaque);
790 if (G_UNLIKELY (frame == NULL))
793 if (G_UNLIKELY (frame->output_buffer != NULL))
794 goto duplicate_frame;
796 /* replace the frame, this one contains the pts/dts for the correspoding input
797 * buffer, which we need after decoding. */
798 gst_video_codec_frame_unref (dframe->frame);
799 dframe->frame = frame;
802 return avcodec_default_reget_buffer (context, picture);
807 GST_WARNING_OBJECT (ffmpegdec, "Couldn't get codec frame !");
812 GST_WARNING_OBJECT (ffmpegdec, "already alloc'ed output buffer for frame");
817 /* called when ffmpeg is done with our buffer */
819 gst_ffmpegviddec_release_buffer (AVCodecContext * context, AVFrame * picture)
822 GstFFMpegVidDecVideoFrame *frame;
823 GstFFMpegVidDec *ffmpegdec;
825 ffmpegdec = (GstFFMpegVidDec *) context->opaque;
826 frame = (GstFFMpegVidDecVideoFrame *) picture->opaque;
827 GST_DEBUG_OBJECT (ffmpegdec, "release frame SN %d",
828 frame->frame->system_frame_number);
830 /* check if it was our buffer */
831 if (picture->type != FF_BUFFER_TYPE_USER) {
832 GST_DEBUG_OBJECT (ffmpegdec, "default release buffer");
833 avcodec_default_release_buffer (context, picture);
836 /* we remove the opaque data now */
837 picture->opaque = NULL;
839 gst_ffmpegviddec_video_frame_free (ffmpegdec, frame);
841 /* zero out the reference in ffmpeg */
842 for (i = 0; i < 4; i++) {
843 picture->data[i] = NULL;
844 picture->linesize[i] = 0;
849 update_video_context (GstFFMpegVidDec * ffmpegdec, AVCodecContext * context,
852 if (!force && ffmpegdec->ctx_width == context->width
853 && ffmpegdec->ctx_height == context->height
854 && ffmpegdec->ctx_ticks == context->ticks_per_frame
855 && ffmpegdec->ctx_time_n == context->time_base.num
856 && ffmpegdec->ctx_time_d == context->time_base.den
857 && ffmpegdec->ctx_pix_fmt == context->pix_fmt
858 && ffmpegdec->ctx_par_n == context->sample_aspect_ratio.num
859 && ffmpegdec->ctx_par_d == context->sample_aspect_ratio.den)
862 GST_DEBUG_OBJECT (ffmpegdec,
863 "Renegotiating video from %dx%d@ %d:%d PAR %d/%d fps to %dx%d@ %d:%d PAR %d/%d fps pixfmt %d",
864 ffmpegdec->ctx_width, ffmpegdec->ctx_height,
865 ffmpegdec->ctx_par_n, ffmpegdec->ctx_par_d,
866 ffmpegdec->ctx_time_n, ffmpegdec->ctx_time_d,
867 context->width, context->height,
868 context->sample_aspect_ratio.num,
869 context->sample_aspect_ratio.den,
870 context->time_base.num, context->time_base.den, context->pix_fmt);
872 ffmpegdec->ctx_width = context->width;
873 ffmpegdec->ctx_height = context->height;
874 ffmpegdec->ctx_ticks = context->ticks_per_frame;
875 ffmpegdec->ctx_time_n = context->time_base.num;
876 ffmpegdec->ctx_time_d = context->time_base.den;
877 ffmpegdec->ctx_pix_fmt = context->pix_fmt;
878 ffmpegdec->ctx_par_n = context->sample_aspect_ratio.num;
879 ffmpegdec->ctx_par_d = context->sample_aspect_ratio.den;
885 gst_ffmpegviddec_update_par (GstFFMpegVidDec * ffmpegdec,
886 GstVideoInfo * in_info, GstVideoInfo * out_info)
888 gboolean demuxer_par_set = FALSE;
889 gboolean decoder_par_set = FALSE;
890 gint demuxer_num = 1, demuxer_denom = 1;
891 gint decoder_num = 1, decoder_denom = 1;
893 if (in_info->par_n && in_info->par_d) {
894 demuxer_num = in_info->par_n;
895 demuxer_denom = in_info->par_d;
896 demuxer_par_set = TRUE;
897 GST_DEBUG_OBJECT (ffmpegdec, "Demuxer PAR: %d:%d", demuxer_num,
901 if (ffmpegdec->ctx_par_n && ffmpegdec->ctx_par_d) {
902 decoder_num = ffmpegdec->ctx_par_n;
903 decoder_denom = ffmpegdec->ctx_par_d;
904 decoder_par_set = TRUE;
905 GST_DEBUG_OBJECT (ffmpegdec, "Decoder PAR: %d:%d", decoder_num,
909 if (!demuxer_par_set && !decoder_par_set)
912 if (demuxer_par_set && !decoder_par_set)
913 goto use_demuxer_par;
915 if (decoder_par_set && !demuxer_par_set)
916 goto use_decoder_par;
918 /* Both the demuxer and the decoder provide a PAR. If one of
919 * the two PARs is 1:1 and the other one is not, use the one
920 * that is not 1:1. */
921 if (demuxer_num == demuxer_denom && decoder_num != decoder_denom)
922 goto use_decoder_par;
924 if (decoder_num == decoder_denom && demuxer_num != demuxer_denom)
925 goto use_demuxer_par;
927 /* Both PARs are non-1:1, so use the PAR provided by the demuxer */
928 goto use_demuxer_par;
932 GST_DEBUG_OBJECT (ffmpegdec,
933 "Setting decoder provided pixel-aspect-ratio of %u:%u", decoder_num,
935 out_info->par_n = decoder_num;
936 out_info->par_d = decoder_denom;
941 GST_DEBUG_OBJECT (ffmpegdec,
942 "Setting demuxer provided pixel-aspect-ratio of %u:%u", demuxer_num,
944 out_info->par_n = demuxer_num;
945 out_info->par_d = demuxer_denom;
950 GST_DEBUG_OBJECT (ffmpegdec,
951 "Neither demuxer nor codec provide a pixel-aspect-ratio");
959 gst_ffmpegviddec_negotiate (GstFFMpegVidDec * ffmpegdec,
960 AVCodecContext * context, gboolean force)
963 GstVideoInfo *in_info, *out_info;
964 GstVideoCodecState *output_state;
967 if (!update_video_context (ffmpegdec, context, force))
970 fmt = gst_ffmpeg_pixfmt_to_videoformat (ffmpegdec->ctx_pix_fmt);
971 if (G_UNLIKELY (fmt == GST_VIDEO_FORMAT_UNKNOWN))
975 gst_video_decoder_set_output_state (GST_VIDEO_DECODER (ffmpegdec), fmt,
976 ffmpegdec->ctx_width, ffmpegdec->ctx_height, ffmpegdec->input_state);
977 if (ffmpegdec->output_state)
978 gst_video_codec_state_unref (ffmpegdec->output_state);
979 ffmpegdec->output_state = output_state;
981 in_info = &ffmpegdec->input_state->info;
982 out_info = &ffmpegdec->output_state->info;
984 /* set the interlaced flag */
985 if (ffmpegdec->ctx_interlaced)
986 out_info->interlace_mode = GST_VIDEO_INTERLACE_MODE_MIXED;
988 out_info->interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
990 switch (context->chroma_sample_location) {
992 out_info->chroma_site = GST_VIDEO_CHROMA_SITE_MPEG2;
995 out_info->chroma_site = GST_VIDEO_CHROMA_SITE_JPEG;
998 out_info->chroma_site = GST_VIDEO_CHROMA_SITE_DV;
1001 out_info->chroma_site = GST_VIDEO_CHROMA_SITE_V_COSITED;
1007 /* try to find a good framerate */
1008 if ((in_info->fps_d && in_info->fps_n) ||
1009 GST_VIDEO_INFO_FLAG_IS_SET (in_info, GST_VIDEO_FLAG_VARIABLE_FPS)) {
1010 /* take framerate from input when it was specified (#313970) */
1011 fps_n = in_info->fps_n;
1012 fps_d = in_info->fps_d;
1014 fps_n = ffmpegdec->ctx_time_d / ffmpegdec->ctx_ticks;
1015 fps_d = ffmpegdec->ctx_time_n;
1018 GST_LOG_OBJECT (ffmpegdec, "invalid framerate: %d/0, -> %d/1", fps_n,
1022 if (gst_util_fraction_compare (fps_n, fps_d, 1000, 1) > 0) {
1023 GST_LOG_OBJECT (ffmpegdec, "excessive framerate: %d/%d, -> 0/1", fps_n,
1029 GST_LOG_OBJECT (ffmpegdec, "setting framerate: %d/%d", fps_n, fps_d);
1030 out_info->fps_n = fps_n;
1031 out_info->fps_d = fps_d;
1033 /* calculate and update par now */
1034 gst_ffmpegviddec_update_par (ffmpegdec, in_info, out_info);
1036 if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (ffmpegdec)))
1037 goto negotiate_failed;
1044 GST_ERROR_OBJECT (ffmpegdec,
1045 "decoder requires a video format unsupported by GStreamer");
1050 /* Reset so we try again next time even if force==FALSE */
1051 ffmpegdec->ctx_width = 0;
1052 ffmpegdec->ctx_height = 0;
1053 ffmpegdec->ctx_ticks = 0;
1054 ffmpegdec->ctx_time_n = 0;
1055 ffmpegdec->ctx_time_d = 0;
1056 ffmpegdec->ctx_pix_fmt = 0;
1057 ffmpegdec->ctx_par_n = 0;
1058 ffmpegdec->ctx_par_d = 0;
1060 GST_ERROR_OBJECT (ffmpegdec, "negotiation failed");
1065 /* perform qos calculations before decoding the next frame.
1067 * Sets the skip_frame flag and if things are really bad, skips to the next
1072 gst_ffmpegviddec_do_qos (GstFFMpegVidDec * ffmpegdec,
1073 GstVideoCodecFrame * frame, gboolean * mode_switch)
1075 GstClockTimeDiff diff;
1076 GstSegmentFlags skip_flags =
1077 GST_VIDEO_DECODER_INPUT_SEGMENT (ffmpegdec).flags;
1079 *mode_switch = FALSE;
1084 if (skip_flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
1085 ffmpegdec->context->skip_frame = AVDISCARD_NONKEY;
1086 *mode_switch = TRUE;
1087 } else if (skip_flags & GST_SEGMENT_FLAG_TRICKMODE) {
1088 ffmpegdec->context->skip_frame = AVDISCARD_NONREF;
1089 *mode_switch = TRUE;
1093 gst_video_decoder_get_max_decode_time (GST_VIDEO_DECODER (ffmpegdec),
1096 /* if we don't have timing info, then we don't do QoS */
1097 if (G_UNLIKELY (diff == G_MAXINT64))
1100 GST_DEBUG_OBJECT (ffmpegdec, "decoding time %" G_GINT64_FORMAT, diff);
1102 if (*mode_switch == FALSE) {
1103 if (diff > 0 && ffmpegdec->context->skip_frame != AVDISCARD_DEFAULT) {
1104 ffmpegdec->context->skip_frame = AVDISCARD_DEFAULT;
1105 *mode_switch = TRUE;
1106 GST_DEBUG_OBJECT (ffmpegdec, "QOS: normal mode");
1109 else if (diff <= 0 && ffmpegdec->context->skip_frame != AVDISCARD_NONREF) {
1110 ffmpegdec->context->skip_frame = AVDISCARD_NONREF;
1111 *mode_switch = TRUE;
1112 GST_DEBUG_OBJECT (ffmpegdec,
1113 "QOS: hurry up, diff %" G_GINT64_FORMAT " >= 0", diff);
1118 /* get an outbuf buffer with the current picture */
1119 static GstFlowReturn
1120 get_output_buffer (GstFFMpegVidDec * ffmpegdec, GstVideoCodecFrame * frame)
1122 GstFlowReturn ret = GST_FLOW_OK;
1123 AVPicture pic, *outpic;
1124 GstVideoFrame vframe;
1128 GST_LOG_OBJECT (ffmpegdec, "get output buffer");
1130 if (!ffmpegdec->output_state)
1131 goto not_negotiated;
1134 gst_video_decoder_allocate_output_frame (GST_VIDEO_DECODER (ffmpegdec),
1136 if (G_UNLIKELY (ret != GST_FLOW_OK))
1139 /* original ffmpeg code does not handle odd sizes correctly.
1140 * This patched up version does */
1141 /* Fill avpicture */
1142 info = &ffmpegdec->output_state->info;
1143 if (!gst_video_frame_map (&vframe, info, frame->output_buffer,
1144 GST_MAP_READ | GST_MAP_WRITE))
1147 for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
1148 if (c < GST_VIDEO_INFO_N_PLANES (info)) {
1149 pic.data[c] = GST_VIDEO_FRAME_PLANE_DATA (&vframe, c);
1150 pic.linesize[c] = GST_VIDEO_FRAME_PLANE_STRIDE (&vframe, c);
1153 pic.linesize[c] = 0;
1155 GST_LOG_OBJECT (ffmpegdec, "linesize %d, data %p", pic.linesize[c],
1159 outpic = (AVPicture *) ffmpegdec->picture;
1161 av_picture_copy (&pic, outpic, ffmpegdec->context->pix_fmt,
1162 GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info));
1164 gst_video_frame_unmap (&vframe);
1166 ffmpegdec->picture->reordered_opaque = -1;
1173 GST_DEBUG_OBJECT (ffmpegdec, "allocation failed");
1178 GST_DEBUG_OBJECT (ffmpegdec, "not negotiated");
1179 return GST_FLOW_NOT_NEGOTIATED;
1184 gst_avpacket_init (AVPacket * packet, guint8 * data, guint size)
1186 memset (packet, 0, sizeof (AVPacket));
1187 packet->data = data;
1188 packet->size = size;
1191 /* gst_ffmpegviddec_[video|audio]_frame:
1193 * data: pointer to the data to decode
1194 * size: size of data in bytes
1195 * in_timestamp: incoming timestamp.
1196 * in_duration: incoming duration.
1197 * in_offset: incoming offset (frame number).
1200 * Returns: number of bytes used in decoding. The check for successful decode is
1201 * outbuf being non-NULL.
1204 gst_ffmpegviddec_video_frame (GstFFMpegVidDec * ffmpegdec,
1205 guint8 * data, guint size, gint * have_data, GstVideoCodecFrame * frame,
1206 GstFlowReturn * ret)
1209 gboolean mode_switch;
1210 GstVideoCodecFrame *out_frame;
1211 GstFFMpegVidDecVideoFrame *out_dframe;
1216 /* in case we skip frames */
1217 ffmpegdec->picture->pict_type = -1;
1219 /* run QoS code, we don't stop decoding the frame when we are late because
1220 * else we might skip a reference frame */
1221 gst_ffmpegviddec_do_qos (ffmpegdec, frame, &mode_switch);
1223 if (ffmpegdec->is_realvideo && data != NULL) {
1227 /* setup the slice table for realvideo */
1228 if (ffmpegdec->context->slice_offset == NULL)
1229 ffmpegdec->context->slice_offset = g_malloc (sizeof (guint32) * 1000);
1231 slice_count = (*data++) + 1;
1232 ffmpegdec->context->slice_count = slice_count;
1234 for (i = 0; i < slice_count; i++) {
1236 ffmpegdec->context->slice_offset[i] = GST_READ_UINT32_LE (data);
1242 /* save reference to the timing info */
1243 ffmpegdec->context->reordered_opaque = (gint64) frame->system_frame_number;
1244 ffmpegdec->picture->reordered_opaque = (gint64) frame->system_frame_number;
1246 GST_DEBUG_OBJECT (ffmpegdec, "stored opaque values idx %d",
1247 frame->system_frame_number);
1250 /* now decode the frame */
1251 gst_avpacket_init (&packet, data, size);
1253 if (ffmpegdec->palette) {
1256 pal = av_packet_new_side_data (&packet, AV_PKT_DATA_PALETTE,
1258 gst_buffer_extract (ffmpegdec->palette, 0, pal, AVPALETTE_SIZE);
1259 GST_DEBUG_OBJECT (ffmpegdec, "copy pal %p %p", &packet, pal);
1262 len = avcodec_decode_video2 (ffmpegdec->context,
1263 ffmpegdec->picture, have_data, &packet);
1265 GST_DEBUG_OBJECT (ffmpegdec, "after decode: len %d, have_data %d",
1268 /* when we are in skip_frame mode, don't complain when ffmpeg returned
1269 * no data because we told it to skip stuff. */
1270 if (len < 0 && (mode_switch || ffmpegdec->context->skip_frame))
1273 /* no data, we're done */
1274 if (len < 0 || *have_data == 0)
1277 /* get the output picture timing info again */
1278 out_dframe = ffmpegdec->picture->opaque;
1279 out_frame = gst_video_codec_frame_ref (out_dframe->frame);
1281 /* also give back a buffer allocated by the frame, if any */
1282 gst_buffer_replace (&out_frame->output_buffer, out_dframe->buffer);
1283 gst_buffer_replace (&out_dframe->buffer, NULL);
1285 GST_DEBUG_OBJECT (ffmpegdec,
1286 "pts %" G_GUINT64_FORMAT " duration %" G_GUINT64_FORMAT,
1287 out_frame->pts, out_frame->duration);
1288 GST_DEBUG_OBJECT (ffmpegdec, "picture: pts %" G_GUINT64_FORMAT,
1289 (guint64) ffmpegdec->picture->pts);
1290 GST_DEBUG_OBJECT (ffmpegdec, "picture: num %d",
1291 ffmpegdec->picture->coded_picture_number);
1292 GST_DEBUG_OBJECT (ffmpegdec, "picture: ref %d",
1293 ffmpegdec->picture->reference);
1294 GST_DEBUG_OBJECT (ffmpegdec, "picture: display %d",
1295 ffmpegdec->picture->display_picture_number);
1296 GST_DEBUG_OBJECT (ffmpegdec, "picture: opaque %p",
1297 ffmpegdec->picture->opaque);
1298 GST_DEBUG_OBJECT (ffmpegdec, "picture: reordered opaque %" G_GUINT64_FORMAT,
1299 (guint64) ffmpegdec->picture->reordered_opaque);
1300 GST_DEBUG_OBJECT (ffmpegdec, "repeat_pict:%d",
1301 ffmpegdec->picture->repeat_pict);
1302 GST_DEBUG_OBJECT (ffmpegdec, "interlaced_frame:%d (current:%d)",
1303 ffmpegdec->picture->interlaced_frame, ffmpegdec->ctx_interlaced);
1304 GST_DEBUG_OBJECT (ffmpegdec, "corrupted frame: %d",
1305 ! !(ffmpegdec->picture->flags & AV_FRAME_FLAG_CORRUPT));
1307 if (G_UNLIKELY (ffmpegdec->picture->interlaced_frame !=
1308 ffmpegdec->ctx_interlaced)) {
1309 GST_WARNING ("Change in interlacing ! picture:%d, recorded:%d",
1310 ffmpegdec->picture->interlaced_frame, ffmpegdec->ctx_interlaced);
1311 ffmpegdec->ctx_interlaced = ffmpegdec->picture->interlaced_frame;
1312 if (!gst_ffmpegviddec_negotiate (ffmpegdec, ffmpegdec->context, TRUE))
1313 goto negotiation_error;
1316 if (G_UNLIKELY (out_frame->output_buffer == NULL))
1317 *ret = get_output_buffer (ffmpegdec, out_frame);
1319 if (G_UNLIKELY (*ret != GST_FLOW_OK))
1322 /* Mark corrupted frames as corrupted */
1323 if (ffmpegdec->picture->flags & AV_FRAME_FLAG_CORRUPT)
1324 GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_BUFFER_FLAG_CORRUPTED);
1326 if (ffmpegdec->ctx_interlaced) {
1327 /* set interlaced flags */
1328 if (ffmpegdec->picture->repeat_pict)
1329 GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_VIDEO_BUFFER_FLAG_RFF);
1330 if (ffmpegdec->picture->top_field_first)
1331 GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_VIDEO_BUFFER_FLAG_TFF);
1332 if (ffmpegdec->picture->interlaced_frame)
1333 GST_BUFFER_FLAG_SET (out_frame->output_buffer,
1334 GST_VIDEO_BUFFER_FLAG_INTERLACED);
1338 /* so we decoded this frame, frames preceding it in decoding order
1339 * that still do not have a buffer allocated seem rather useless,
1340 * and can be discarded, due to e.g. misparsed bogus frame
1341 * or non-keyframe in skipped decoding, ...
1342 * In any case, not likely to be seen again, so discard those,
1343 * before they pile up and/or mess with timestamping */
1346 GstVideoDecoder *dec = GST_VIDEO_DECODER (ffmpegdec);
1347 gboolean old = TRUE;
1349 ol = l = gst_video_decoder_get_frames (dec);
1351 GstVideoCodecFrame *tmp = l->data;
1356 if (old && GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY (tmp)) {
1357 GST_LOG_OBJECT (dec,
1358 "discarding ghost frame %p (#%d) PTS:%" GST_TIME_FORMAT " DTS:%"
1359 GST_TIME_FORMAT, tmp, tmp->system_frame_number,
1360 GST_TIME_ARGS (tmp->pts), GST_TIME_ARGS (tmp->dts));
1361 /* drop extra ref and remove from frame list */
1362 gst_video_decoder_release_frame (dec, tmp);
1364 /* drop extra ref we got */
1365 gst_video_codec_frame_unref (tmp);
1373 gst_video_decoder_finish_frame (GST_VIDEO_DECODER (ffmpegdec), out_frame);
1376 GST_DEBUG_OBJECT (ffmpegdec, "return flow %s, len %d",
1377 gst_flow_get_name (*ret), len);
1383 GST_DEBUG_OBJECT (ffmpegdec, "no output buffer");
1384 gst_video_decoder_drop_frame (GST_VIDEO_DECODER (ffmpegdec), out_frame);
1391 GST_WARNING_OBJECT (ffmpegdec, "Error negotiating format");
1392 *ret = GST_FLOW_NOT_NEGOTIATED;
1398 /* gst_ffmpegviddec_frame:
1400 * data: pointer to the data to decode
1401 * size: size of data in bytes
1402 * got_data: 0 if no data was decoded, != 0 otherwise.
1403 * in_time: timestamp of data
1404 * in_duration: duration of data
1405 * ret: GstFlowReturn to return in the chain function
1407 * Decode the given frame and pushes it downstream.
1409 * Returns: Number of bytes used in decoding, -1 on error/failure.
1413 gst_ffmpegviddec_frame (GstFFMpegVidDec * ffmpegdec,
1414 guint8 * data, guint size, gint * have_data, GstVideoCodecFrame * frame,
1415 GstFlowReturn * ret)
1417 GstFFMpegVidDecClass *oclass;
1420 if (G_UNLIKELY (ffmpegdec->context->codec == NULL))
1423 GST_LOG_OBJECT (ffmpegdec, "data:%p, size:%d", data, size);
1426 ffmpegdec->context->frame_number++;
1428 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
1431 gst_ffmpegviddec_video_frame (ffmpegdec, data, size, have_data, frame,
1435 GST_WARNING_OBJECT (ffmpegdec,
1436 "avdec_%s: decoding error (len: %d, have_data: %d)",
1437 oclass->in_plugin->name, len, *have_data);
1445 GST_ERROR_OBJECT (ffmpegdec, "no codec context");
1446 *ret = GST_FLOW_NOT_NEGOTIATED;
1452 gst_ffmpegviddec_drain (GstFFMpegVidDec * ffmpegdec)
1454 GstFFMpegVidDecClass *oclass;
1456 if (!ffmpegdec->opened)
1459 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
1461 if (oclass->in_plugin->capabilities & CODEC_CAP_DELAY) {
1462 gint have_data, len;
1465 GST_LOG_OBJECT (ffmpegdec,
1466 "codec has delay capabilities, calling until ffmpeg has drained everything");
1469 len = gst_ffmpegviddec_frame (ffmpegdec, NULL, 0, &have_data, NULL, &ret);
1470 } while (len >= 0 && have_data == 1 && ret == GST_FLOW_OK);
1471 avcodec_flush_buffers (ffmpegdec->context);
1475 static GstFlowReturn
1476 gst_ffmpegviddec_handle_frame (GstVideoDecoder * decoder,
1477 GstVideoCodecFrame * frame)
1479 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1480 guint8 *data, *bdata;
1481 gint size, len, have_data, bsize;
1483 GstFlowReturn ret = GST_FLOW_OK;
1484 gboolean do_padding;
1486 GST_LOG_OBJECT (ffmpegdec,
1487 "Received new data of size %" G_GSIZE_FORMAT ", dts %" GST_TIME_FORMAT
1488 ", pts:%" GST_TIME_FORMAT ", dur:%" GST_TIME_FORMAT,
1489 gst_buffer_get_size (frame->input_buffer), GST_TIME_ARGS (frame->dts),
1490 GST_TIME_ARGS (frame->pts), GST_TIME_ARGS (frame->duration));
1492 if (!gst_buffer_map (frame->input_buffer, &minfo, GST_MAP_READ)) {
1493 GST_ELEMENT_ERROR (ffmpegdec, STREAM, DECODE, ("Decoding problem"),
1494 ("Failed to map buffer for reading"));
1495 return GST_FLOW_ERROR;
1498 /* treat frame as void until a buffer is requested for it */
1499 GST_VIDEO_CODEC_FRAME_FLAG_SET (frame,
1500 GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY);
1505 if (bsize > 0 && (!GST_MEMORY_IS_ZERO_PADDED (minfo.memory)
1506 || (minfo.maxsize - minfo.size) < FF_INPUT_BUFFER_PADDING_SIZE)) {
1508 if (ffmpegdec->padded_size < bsize + FF_INPUT_BUFFER_PADDING_SIZE) {
1509 ffmpegdec->padded_size = bsize + FF_INPUT_BUFFER_PADDING_SIZE;
1510 ffmpegdec->padded = g_realloc (ffmpegdec->padded, ffmpegdec->padded_size);
1511 GST_LOG_OBJECT (ffmpegdec, "resized padding buffer to %d",
1512 ffmpegdec->padded_size);
1514 GST_CAT_TRACE_OBJECT (GST_CAT_PERFORMANCE, ffmpegdec,
1515 "Copy input to add padding");
1516 memcpy (ffmpegdec->padded, bdata, bsize);
1517 memset (ffmpegdec->padded + bsize, 0, FF_INPUT_BUFFER_PADDING_SIZE);
1519 bdata = ffmpegdec->padded;
1526 guint8 tmp_padding[FF_INPUT_BUFFER_PADDING_SIZE];
1528 /* parse, if at all possible */
1533 /* add temporary padding */
1534 GST_CAT_TRACE_OBJECT (GST_CAT_PERFORMANCE, ffmpegdec,
1535 "Add temporary input padding");
1536 memcpy (tmp_padding, data + size, FF_INPUT_BUFFER_PADDING_SIZE);
1537 memset (data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
1540 /* decode a frame of audio/video now */
1542 gst_ffmpegviddec_frame (ffmpegdec, data, size, &have_data, frame, &ret);
1544 if (ret != GST_FLOW_OK) {
1545 GST_LOG_OBJECT (ffmpegdec, "breaking because of flow ret %s",
1546 gst_flow_get_name (ret));
1547 /* bad flow return, make sure we discard all data and exit */
1553 memcpy (data + size, tmp_padding, FF_INPUT_BUFFER_PADDING_SIZE);
1556 if (len == 0 && have_data == 0) {
1557 /* nothing was decoded, this could be because no data was available or
1558 * because we were skipping frames.
1559 * If we have no context we must exit and wait for more data, we keep the
1561 GST_LOG_OBJECT (ffmpegdec, "Decoding didn't return any data, breaking");
1566 /* a decoding error happened, we must break and try again with next data. */
1567 GST_LOG_OBJECT (ffmpegdec, "Decoding error, breaking");
1572 /* prepare for the next round, for codecs with a context we did this
1573 * already when using the parser. */
1579 GST_LOG_OBJECT (ffmpegdec, "Before (while bsize>0). bsize:%d , bdata:%p",
1581 } while (bsize > 0);
1584 GST_DEBUG_OBJECT (ffmpegdec, "Dropping %d bytes of data", bsize);
1586 gst_buffer_unmap (frame->input_buffer, &minfo);
1587 gst_video_codec_frame_unref (frame);
1594 gst_ffmpegviddec_start (GstVideoDecoder * decoder)
1596 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1597 GstFFMpegVidDecClass *oclass;
1599 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
1601 GST_OBJECT_LOCK (ffmpegdec);
1602 gst_ffmpeg_avcodec_close (ffmpegdec->context);
1603 if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) {
1604 GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
1605 GST_OBJECT_UNLOCK (ffmpegdec);
1608 ffmpegdec->context->opaque = ffmpegdec;
1609 GST_OBJECT_UNLOCK (ffmpegdec);
1615 gst_ffmpegviddec_stop (GstVideoDecoder * decoder)
1617 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1619 GST_OBJECT_LOCK (ffmpegdec);
1620 gst_ffmpegviddec_close (ffmpegdec, FALSE);
1621 GST_OBJECT_UNLOCK (ffmpegdec);
1622 g_free (ffmpegdec->padded);
1623 ffmpegdec->padded = NULL;
1624 ffmpegdec->padded_size = 0;
1625 if (ffmpegdec->input_state)
1626 gst_video_codec_state_unref (ffmpegdec->input_state);
1627 ffmpegdec->input_state = NULL;
1628 if (ffmpegdec->output_state)
1629 gst_video_codec_state_unref (ffmpegdec->output_state);
1630 ffmpegdec->output_state = NULL;
1632 ffmpegdec->ctx_width = 0;
1633 ffmpegdec->ctx_height = 0;
1634 ffmpegdec->ctx_ticks = 0;
1635 ffmpegdec->ctx_time_n = 0;
1636 ffmpegdec->ctx_time_d = 0;
1637 ffmpegdec->ctx_pix_fmt = 0;
1638 ffmpegdec->ctx_par_n = 0;
1639 ffmpegdec->ctx_par_d = 0;
1644 static GstFlowReturn
1645 gst_ffmpegviddec_finish (GstVideoDecoder * decoder)
1647 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1649 gst_ffmpegviddec_drain (ffmpegdec);
1655 gst_ffmpegviddec_flush (GstVideoDecoder * decoder)
1657 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1659 if (ffmpegdec->opened)
1660 avcodec_flush_buffers (ffmpegdec->context);
1666 gst_ffmpegviddec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query)
1668 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) decoder;
1669 GstVideoCodecState *state;
1670 GstBufferPool *pool;
1671 guint size, min, max;
1672 GstStructure *config;
1673 gboolean have_videometa, have_alignment, update_pool = FALSE;
1674 GstAllocator *allocator = NULL;
1675 GstAllocationParams params = { 0, 15, 0, 0, };
1677 if (!GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder,
1681 state = gst_video_decoder_get_output_state (decoder);
1683 if (gst_query_get_n_allocation_params (query) > 0) {
1684 gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
1685 params.align = MAX (params.align, 15);
1687 gst_query_add_allocation_param (query, allocator, ¶ms);
1690 gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
1692 /* Don't use pool that can't grow, as we don't know how many buffer we'll
1693 * need, otherwise we may stall */
1694 if (max != 0 && max < REQUIRED_POOL_MAX_BUFFERS) {
1695 gst_object_unref (pool);
1696 pool = gst_video_buffer_pool_new ();
1700 /* if there is an allocator, also drop it, as it might be the reason we
1701 * have this limit. Default will be used */
1703 gst_object_unref (allocator);
1708 config = gst_buffer_pool_get_config (pool);
1709 gst_buffer_pool_config_set_params (config, state->caps, size, min, max);
1710 /* we are happy with the default allocator but we would like to have 16 bytes
1711 * aligned and padded memory */
1712 gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
1715 gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
1717 gst_buffer_pool_config_add_option (config,
1718 GST_BUFFER_POOL_OPTION_VIDEO_META);
1721 gst_buffer_pool_has_option (pool, GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
1723 /* we can only enable the alignment if downstream supports the
1725 if (have_alignment && have_videometa) {
1726 GstVideoAlignment align;
1728 gint linesize_align[4];
1732 width = GST_VIDEO_INFO_WIDTH (&state->info);
1733 height = GST_VIDEO_INFO_HEIGHT (&state->info);
1734 /* let ffmpeg find the alignment and padding */
1735 avcodec_align_dimensions2 (ffmpegdec->context, &width, &height,
1739 context->flags & CODEC_FLAG_EMU_EDGE ? 0 : avcodec_get_edge_width ();
1740 /* increase the size for the padding */
1742 height += edge << 1;
1744 align.padding_top = edge;
1745 align.padding_left = edge;
1746 align.padding_right = width - GST_VIDEO_INFO_WIDTH (&state->info) - edge;
1747 align.padding_bottom = height - GST_VIDEO_INFO_HEIGHT (&state->info) - edge;
1749 /* add extra padding to match libav buffer allocation sizes */
1750 align.padding_bottom++;
1752 for (i = 0; i < GST_VIDEO_MAX_PLANES; i++)
1753 align.stride_align[i] =
1754 (linesize_align[i] > 0 ? linesize_align[i] - 1 : 0);
1756 GST_DEBUG_OBJECT (ffmpegdec, "aligned dimension %dx%d -> %dx%d "
1757 "padding t:%u l:%u r:%u b:%u, stride_align %d:%d:%d:%d",
1758 GST_VIDEO_INFO_WIDTH (&state->info),
1759 GST_VIDEO_INFO_HEIGHT (&state->info), width, height, align.padding_top,
1760 align.padding_left, align.padding_right, align.padding_bottom,
1761 align.stride_align[0], align.stride_align[1], align.stride_align[2],
1762 align.stride_align[3]);
1764 gst_buffer_pool_config_add_option (config,
1765 GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
1766 gst_buffer_pool_config_set_video_alignment (config, &align);
1768 if (ffmpegdec->direct_rendering) {
1769 GstFFMpegVidDecClass *oclass;
1771 GST_DEBUG_OBJECT (ffmpegdec, "trying to enable direct rendering");
1773 oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
1775 if (oclass->in_plugin->capabilities & CODEC_CAP_DR1) {
1776 GST_DEBUG_OBJECT (ffmpegdec, "enabled direct rendering");
1777 ffmpegdec->current_dr = TRUE;
1779 GST_DEBUG_OBJECT (ffmpegdec, "direct rendering not supported");
1783 GST_DEBUG_OBJECT (ffmpegdec,
1784 "alignment or videometa not supported, disable direct rendering");
1786 /* disable direct rendering. This will make us use the fallback ffmpeg
1787 * picture allocation code with padding etc. We will then do the final
1788 * copy (with cropping) into a buffer from our pool */
1789 ffmpegdec->current_dr = FALSE;
1793 gst_buffer_pool_set_config (pool, config);
1796 gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
1798 gst_object_unref (pool);
1800 gst_object_unref (allocator);
1801 gst_video_codec_state_unref (state);
1807 gst_ffmpegviddec_propose_allocation (GstVideoDecoder * decoder,
1810 GstAllocationParams params;
1812 gst_allocation_params_init (¶ms);
1813 params.flags = GST_MEMORY_FLAG_ZERO_PADDED;
1815 params.padding = FF_INPUT_BUFFER_PADDING_SIZE;
1816 /* we would like to have some padding so that we don't have to
1817 * memcpy. We don't suggest an allocator. */
1818 gst_query_add_allocation_param (query, NULL, ¶ms);
1820 return GST_VIDEO_DECODER_CLASS (parent_class)->propose_allocation (decoder,
1825 gst_ffmpegviddec_set_property (GObject * object,
1826 guint prop_id, const GValue * value, GParamSpec * pspec)
1828 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object;
1832 ffmpegdec->lowres = ffmpegdec->context->lowres = g_value_get_enum (value);
1834 case PROP_SKIPFRAME:
1835 ffmpegdec->skip_frame = ffmpegdec->context->skip_frame =
1836 g_value_get_enum (value);
1838 case PROP_DIRECT_RENDERING:
1839 ffmpegdec->direct_rendering = g_value_get_boolean (value);
1842 ffmpegdec->debug_mv = ffmpegdec->context->debug_mv =
1843 g_value_get_boolean (value);
1845 case PROP_MAX_THREADS:
1846 ffmpegdec->max_threads = g_value_get_int (value);
1848 case PROP_OUTPUT_CORRUPT:
1849 ffmpegdec->output_corrupt = g_value_get_boolean (value);
1852 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1858 gst_ffmpegviddec_get_property (GObject * object,
1859 guint prop_id, GValue * value, GParamSpec * pspec)
1861 GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object;
1865 g_value_set_enum (value, ffmpegdec->context->lowres);
1867 case PROP_SKIPFRAME:
1868 g_value_set_enum (value, ffmpegdec->context->skip_frame);
1870 case PROP_DIRECT_RENDERING:
1871 g_value_set_boolean (value, ffmpegdec->direct_rendering);
1874 g_value_set_boolean (value, ffmpegdec->context->debug_mv);
1876 case PROP_MAX_THREADS:
1877 g_value_set_int (value, ffmpegdec->max_threads);
1879 case PROP_OUTPUT_CORRUPT:
1880 g_value_set_boolean (value, ffmpegdec->output_corrupt);
1883 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1889 gst_ffmpegviddec_register (GstPlugin * plugin)
1891 GTypeInfo typeinfo = {
1892 sizeof (GstFFMpegVidDecClass),
1893 (GBaseInitFunc) gst_ffmpegviddec_base_init,
1895 (GClassInitFunc) gst_ffmpegviddec_class_init,
1898 sizeof (GstFFMpegVidDec),
1900 (GInstanceInitFunc) gst_ffmpegviddec_init,
1906 in_plugin = av_codec_next (NULL);
1908 GST_LOG ("Registering decoders");
1914 /* only video decoders */
1915 if (!av_codec_is_decoder (in_plugin)
1916 || in_plugin->type != AVMEDIA_TYPE_VIDEO)
1919 /* no quasi-codecs, please */
1920 if (in_plugin->id == AV_CODEC_ID_RAWVIDEO ||
1921 in_plugin->id == AV_CODEC_ID_V210 ||
1922 in_plugin->id == AV_CODEC_ID_V210X ||
1923 in_plugin->id == AV_CODEC_ID_R210 ||
1924 (in_plugin->id >= AV_CODEC_ID_PCM_S16LE &&
1925 in_plugin->id <= AV_CODEC_ID_PCM_BLURAY)) {
1929 /* No decoders depending on external libraries (we don't build them, but
1930 * people who build against an external ffmpeg might have them.
1931 * We have native gstreamer plugins for all of those libraries anyway. */
1932 if (!strncmp (in_plugin->name, "lib", 3)) {
1934 ("Not using external library decoder %s. Use the gstreamer-native ones instead.",
1939 /* No vdpau plugins until we can figure out how to properly use them
1940 * outside of ffmpeg. */
1941 if (g_str_has_suffix (in_plugin->name, "_vdpau")) {
1943 ("Ignoring VDPAU decoder %s. We can't handle this outside of ffmpeg",
1948 if (g_str_has_suffix (in_plugin->name, "_xvmc")) {
1950 ("Ignoring XVMC decoder %s. We can't handle this outside of ffmpeg",
1955 GST_DEBUG ("Trying plugin %s [%s]", in_plugin->name, in_plugin->long_name);
1957 /* no codecs for which we're GUARANTEED to have better alternatives */
1958 /* MPEG1VIDEO : the mpeg2video decoder is preferred */
1959 /* MP1 : Use MP3 for decoding */
1960 /* MP2 : Use MP3 for decoding */
1961 /* Theora: Use libtheora based theoradec */
1962 if (!strcmp (in_plugin->name, "gif") ||
1963 !strcmp (in_plugin->name, "theora") ||
1964 !strcmp (in_plugin->name, "mpeg1video") ||
1965 strstr (in_plugin->name, "crystalhd") != NULL ||
1966 !strcmp (in_plugin->name, "ass") ||
1967 !strcmp (in_plugin->name, "srt") ||
1968 !strcmp (in_plugin->name, "pgssub") ||
1969 !strcmp (in_plugin->name, "dvdsub") ||
1970 !strcmp (in_plugin->name, "dvbsub")) {
1971 GST_LOG ("Ignoring decoder %s", in_plugin->name);
1975 /* construct the type */
1976 if (!strcmp (in_plugin->name, "hevc")) {
1977 plugin_name = g_strdup ("h265");
1979 plugin_name = g_strdup ((gchar *) in_plugin->name);
1981 g_strdelimit (plugin_name, NULL, '_');
1982 type_name = g_strdup_printf ("avdec_%s", plugin_name);
1983 g_free (plugin_name);
1985 type = g_type_from_name (type_name);
1988 /* create the gtype now */
1990 g_type_register_static (GST_TYPE_VIDEO_DECODER, type_name, &typeinfo,
1992 g_type_set_qdata (type, GST_FFDEC_PARAMS_QDATA, (gpointer) in_plugin);
1995 /* (Ronald) MPEG-4 gets a higher priority because it has been well-
1996 * tested and by far outperforms divxdec/xviddec - so we prefer it.
1997 * msmpeg4v3 same, as it outperforms divxdec for divx3 playback.
1998 * VC1/WMV3 are not working and thus unpreferred for now. */
1999 switch (in_plugin->id) {
2000 case AV_CODEC_ID_MPEG4:
2001 case AV_CODEC_ID_MSMPEG4V3:
2002 case AV_CODEC_ID_H264:
2003 case AV_CODEC_ID_HEVC:
2004 case AV_CODEC_ID_RV10:
2005 case AV_CODEC_ID_RV20:
2006 case AV_CODEC_ID_RV30:
2007 case AV_CODEC_ID_RV40:
2008 rank = GST_RANK_PRIMARY;
2010 /* DVVIDEO: we have a good dv decoder, fast on both ppc as well as x86.
2011 * They say libdv's quality is better though. leave as secondary.
2012 * note: if you change this, see the code in gstdv.c in good/ext/dv.
2014 case AV_CODEC_ID_DVVIDEO:
2015 rank = GST_RANK_SECONDARY;
2018 rank = GST_RANK_MARGINAL;
2021 if (!gst_element_register (plugin, type_name, rank, type)) {
2022 g_warning ("Failed to register %s", type_name);
2030 in_plugin = av_codec_next (in_plugin);
2033 GST_LOG ("Finished Registering decoders");