2012-04-07 08:36:04 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:22:16 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2012-04-07 08:36:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <libavcodec/avcodec.h>
|
2017-03-16 04:23:01 +00:00
|
|
|
#include <libavutil/stereo3d.h>
|
2019-02-18 11:53:58 +00:00
|
|
|
#include <libavutil/mastering_display_metadata.h>
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-09-10 15:53:54 +00:00
|
|
|
#include "gstav.h"
|
|
|
|
#include "gstavcodecmap.h"
|
|
|
|
#include "gstavutils.h"
|
2012-11-19 09:29:00 +00:00
|
|
|
#include "gstavviddec.h"
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2018-07-18 10:41:50 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_PERFORMANCE);
|
|
|
|
|
2023-02-13 22:02:01 +00:00
|
|
|
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,132,100)
|
|
|
|
#define AV_CODEC_CAP_OTHER_THREADS AV_CODEC_CAP_AUTO_THREADS
|
|
|
|
#endif
|
|
|
|
|
2020-01-22 17:39:47 +00:00
|
|
|
#define GST_FFMPEG_VIDEO_CODEC_FRAME_FLAG_ALLOCATED (1<<15)
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
#define MAX_TS_MASK 0xff
|
|
|
|
|
|
|
|
#define DEFAULT_LOWRES 0
|
|
|
|
#define DEFAULT_SKIPFRAME 0
|
|
|
|
#define DEFAULT_DIRECT_RENDERING TRUE
|
|
|
|
#define DEFAULT_MAX_THREADS 0
|
2014-01-17 20:38:23 +00:00
|
|
|
#define DEFAULT_OUTPUT_CORRUPT TRUE
|
2014-03-27 22:53:53 +00:00
|
|
|
#define REQUIRED_POOL_MAX_BUFFERS 32
|
2015-08-28 08:38:53 +00:00
|
|
|
#define DEFAULT_STRIDE_ALIGN 31
|
2015-08-16 17:08:16 +00:00
|
|
|
#define DEFAULT_ALLOC_PARAM { 0, DEFAULT_STRIDE_ALIGN, 0, 0, }
|
2018-10-06 09:51:58 +00:00
|
|
|
#define DEFAULT_THREAD_TYPE 0
|
2022-11-01 13:35:11 +00:00
|
|
|
#define DEFAULT_STD_COMPLIANCE GST_AV_CODEC_COMPLIANCE_AUTO
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LOWRES,
|
|
|
|
PROP_SKIPFRAME,
|
|
|
|
PROP_DIRECT_RENDERING,
|
|
|
|
PROP_DEBUG_MV,
|
|
|
|
PROP_MAX_THREADS,
|
2014-01-17 20:38:23 +00:00
|
|
|
PROP_OUTPUT_CORRUPT,
|
2018-10-06 09:51:58 +00:00
|
|
|
PROP_THREAD_TYPE,
|
2022-11-01 13:35:11 +00:00
|
|
|
PROP_STD_COMPLIANCE,
|
2012-04-07 08:36:04 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
/* A number of function prototypes are given so we can refer to them later. */
|
2012-04-07 09:14:45 +00:00
|
|
|
static void gst_ffmpegviddec_finalize (GObject * object);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
static gboolean gst_ffmpegviddec_set_format (GstVideoDecoder * decoder,
|
|
|
|
GstVideoCodecState * state);
|
|
|
|
static GstFlowReturn gst_ffmpegviddec_handle_frame (GstVideoDecoder * decoder,
|
|
|
|
GstVideoCodecFrame * frame);
|
2013-08-29 14:53:28 +00:00
|
|
|
static gboolean gst_ffmpegviddec_start (GstVideoDecoder * decoder);
|
2012-04-18 10:37:53 +00:00
|
|
|
static gboolean gst_ffmpegviddec_stop (GstVideoDecoder * decoder);
|
2013-08-15 13:51:52 +00:00
|
|
|
static gboolean gst_ffmpegviddec_flush (GstVideoDecoder * decoder);
|
2012-06-15 14:37:19 +00:00
|
|
|
static gboolean gst_ffmpegviddec_decide_allocation (GstVideoDecoder * decoder,
|
|
|
|
GstQuery * query);
|
|
|
|
static gboolean gst_ffmpegviddec_propose_allocation (GstVideoDecoder * decoder,
|
|
|
|
GstQuery * query);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
static void gst_ffmpegviddec_set_property (GObject * object,
|
2012-04-07 08:36:04 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
2012-04-07 09:14:45 +00:00
|
|
|
static void gst_ffmpegviddec_get_property (GObject * object,
|
2012-04-07 08:36:04 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
static gboolean gst_ffmpegviddec_negotiate (GstFFMpegVidDec * ffmpegdec,
|
2021-01-29 12:02:42 +00:00
|
|
|
AVCodecContext * context, AVFrame * picture, GstBufferFlags flags);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* some sort of bufferpool handling, but different */
|
2015-06-26 18:38:01 +00:00
|
|
|
static int gst_ffmpegviddec_get_buffer2 (AVCodecContext * context,
|
|
|
|
AVFrame * picture, int flags);
|
2021-01-28 06:11:14 +00:00
|
|
|
static gboolean gst_ffmpegviddec_can_direct_render (GstFFMpegVidDec *
|
|
|
|
ffmpegdec);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-26 15:00:43 +00:00
|
|
|
static GstFlowReturn gst_ffmpegviddec_finish (GstVideoDecoder * decoder);
|
2015-10-26 18:54:10 +00:00
|
|
|
static GstFlowReturn gst_ffmpegviddec_drain (GstVideoDecoder * decoder);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2015-06-26 13:34:30 +00:00
|
|
|
static gboolean picture_changed (GstFFMpegVidDec * ffmpegdec,
|
2022-10-26 20:30:31 +00:00
|
|
|
AVFrame * picture, gboolean one_field);
|
2015-06-26 13:34:30 +00:00
|
|
|
static gboolean context_changed (GstFFMpegVidDec * ffmpegdec,
|
|
|
|
AVCodecContext * context);
|
|
|
|
|
2022-11-01 15:13:23 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (GstFFMpegVidDec, gst_ffmpegviddec,
|
|
|
|
GST_TYPE_VIDEO_DECODER);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2022-11-01 15:13:23 +00:00
|
|
|
#define parent_class gst_ffmpegviddec_parent_class
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
#define GST_FFMPEGVIDDEC_TYPE_LOWRES (gst_ffmpegviddec_lowres_get_type())
|
2012-04-07 08:36:04 +00:00
|
|
|
static GType
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegviddec_lowres_get_type (void)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
|
|
|
static GType ffmpegdec_lowres_type = 0;
|
|
|
|
|
|
|
|
if (!ffmpegdec_lowres_type) {
|
|
|
|
static const GEnumValue ffmpegdec_lowres[] = {
|
|
|
|
{0, "0", "full"},
|
|
|
|
{1, "1", "1/2-size"},
|
|
|
|
{2, "2", "1/4-size"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
ffmpegdec_lowres_type =
|
2012-06-15 13:18:47 +00:00
|
|
|
g_enum_register_static ("GstLibAVVidDecLowres", ffmpegdec_lowres);
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ffmpegdec_lowres_type;
|
|
|
|
}
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
#define GST_FFMPEGVIDDEC_TYPE_SKIPFRAME (gst_ffmpegviddec_skipframe_get_type())
|
2012-04-07 08:36:04 +00:00
|
|
|
static GType
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegviddec_skipframe_get_type (void)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
|
|
|
static GType ffmpegdec_skipframe_type = 0;
|
|
|
|
|
|
|
|
if (!ffmpegdec_skipframe_type) {
|
|
|
|
static const GEnumValue ffmpegdec_skipframe[] = {
|
|
|
|
{0, "0", "Skip nothing"},
|
|
|
|
{1, "1", "Skip B-frames"},
|
|
|
|
{2, "2", "Skip IDCT/Dequantization"},
|
|
|
|
{5, "5", "Skip everything"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
ffmpegdec_skipframe_type =
|
2012-06-15 13:18:47 +00:00
|
|
|
g_enum_register_static ("GstLibAVVidDecSkipFrame", ffmpegdec_skipframe);
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ffmpegdec_skipframe_type;
|
|
|
|
}
|
|
|
|
|
2018-10-06 09:51:58 +00:00
|
|
|
static const GFlagsValue ffmpegdec_thread_types[] = {
|
|
|
|
{0x0, "Auto", "auto"},
|
|
|
|
{0x1, "Frame", "frame"},
|
|
|
|
{0x2, "Slice", "slice"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GST_FFMPEGVIDDEC_TYPE_THREAD_TYPE (gst_ffmpegviddec_thread_type_get_type())
|
|
|
|
static GType
|
|
|
|
gst_ffmpegviddec_thread_type_get_type (void)
|
|
|
|
{
|
|
|
|
static GType ffmpegdec_thread_type_type = 0;
|
|
|
|
|
|
|
|
if (!ffmpegdec_thread_type_type) {
|
|
|
|
ffmpegdec_thread_type_type =
|
|
|
|
g_flags_register_static ("GstLibAVVidDecThreadType",
|
|
|
|
ffmpegdec_thread_types);
|
|
|
|
}
|
|
|
|
return ffmpegdec_thread_type_type;
|
|
|
|
}
|
|
|
|
|
2021-01-29 12:02:42 +00:00
|
|
|
static GstCaps *
|
|
|
|
dup_caps_with_alternate (GstCaps * caps)
|
|
|
|
{
|
|
|
|
GstCaps *with_alternate;
|
|
|
|
GstCapsFeatures *features;
|
|
|
|
|
|
|
|
with_alternate = gst_caps_copy (caps);
|
|
|
|
features = gst_caps_features_new (GST_CAPS_FEATURE_FORMAT_INTERLACED, NULL);
|
|
|
|
gst_caps_set_features_simple (with_alternate, features);
|
|
|
|
|
|
|
|
gst_caps_set_simple (with_alternate, "interlace-mode", G_TYPE_STRING,
|
|
|
|
"alternate", NULL);
|
|
|
|
|
|
|
|
return with_alternate;
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
static void
|
2022-11-01 15:13:23 +00:00
|
|
|
gst_ffmpegviddec_class_init (GstFFMpegVidDecClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_ffmpegviddec_set_property;
|
|
|
|
gobject_class->get_property = gst_ffmpegviddec_get_property;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GstFFMpegVidDec:std-compliance:
|
|
|
|
*
|
|
|
|
* Specifies standard compliance mode to use
|
|
|
|
*
|
|
|
|
* Since: 1.22
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_STD_COMPLIANCE,
|
|
|
|
g_param_spec_enum ("std-compliance", "Standard Compliance",
|
|
|
|
"Standard compliance mode to use", GST_TYPE_AV_CODEC_COMPLIANCE,
|
|
|
|
DEFAULT_STD_COMPLIANCE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ffmpegviddec_subclass_init (GstFFMpegVidDecClass * klass,
|
|
|
|
gconstpointer class_data)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstVideoDecoderClass *viddec_class = GST_VIDEO_DECODER_CLASS (klass);
|
2012-04-07 08:36:04 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2022-11-01 15:13:23 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2012-04-07 08:36:04 +00:00
|
|
|
GstPadTemplate *sinktempl, *srctempl;
|
|
|
|
GstCaps *sinkcaps, *srccaps;
|
2022-11-01 15:13:23 +00:00
|
|
|
const AVCodec *in_plugin;
|
2012-04-07 09:14:45 +00:00
|
|
|
gchar *longname, *description;
|
2022-11-01 15:13:23 +00:00
|
|
|
int caps;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2022-11-01 15:13:23 +00:00
|
|
|
in_plugin = class_data;
|
2012-04-07 08:36:04 +00:00
|
|
|
g_assert (in_plugin != NULL);
|
|
|
|
|
|
|
|
/* construct the element details struct */
|
2012-06-15 13:18:47 +00:00
|
|
|
longname = g_strdup_printf ("libav %s decoder", in_plugin->long_name);
|
|
|
|
description = g_strdup_printf ("libav %s decoder", in_plugin->name);
|
|
|
|
gst_element_class_set_metadata (element_class, longname,
|
2012-04-07 09:14:45 +00:00
|
|
|
"Codec/Decoder/Video", description,
|
2012-04-07 08:36:04 +00:00
|
|
|
"Wim Taymans <wim.taymans@gmail.com>, "
|
|
|
|
"Ronald Bultje <rbultje@ronald.bitfreak.net>, "
|
|
|
|
"Edward Hervey <bilboed@bilboed.com>");
|
|
|
|
g_free (longname);
|
|
|
|
g_free (description);
|
|
|
|
|
|
|
|
/* get the caps */
|
|
|
|
sinkcaps = gst_ffmpeg_codecid_to_caps (in_plugin->id, NULL, FALSE);
|
|
|
|
if (!sinkcaps) {
|
|
|
|
GST_DEBUG ("Couldn't get sink caps for decoder '%s'", in_plugin->name);
|
2012-06-15 13:18:47 +00:00
|
|
|
sinkcaps = gst_caps_new_empty_simple ("unknown/unknown");
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
2012-12-12 15:42:09 +00:00
|
|
|
srccaps = gst_ffmpeg_codectype_to_video_caps (NULL,
|
|
|
|
in_plugin->id, FALSE, in_plugin);
|
|
|
|
if (!srccaps) {
|
|
|
|
GST_DEBUG ("Couldn't get source caps for decoder '%s'", in_plugin->name);
|
|
|
|
srccaps = gst_caps_from_string ("video/x-raw");
|
|
|
|
}
|
2021-01-29 12:02:42 +00:00
|
|
|
gst_caps_append (srccaps, dup_caps_with_alternate (srccaps));
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* pad templates */
|
|
|
|
sinktempl = gst_pad_template_new ("sink", GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS, sinkcaps);
|
|
|
|
srctempl = gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, srccaps);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class, srctempl);
|
|
|
|
gst_element_class_add_pad_template (element_class, sinktempl);
|
|
|
|
|
2017-01-02 03:36:09 +00:00
|
|
|
gst_caps_unref (sinkcaps);
|
|
|
|
gst_caps_unref (srccaps);
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
klass->in_plugin = in_plugin;
|
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
gobject_class->finalize = gst_ffmpegviddec_finalize;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
gobject_class->set_property = gst_ffmpegviddec_set_property;
|
|
|
|
gobject_class->get_property = gst_ffmpegviddec_get_property;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SKIPFRAME,
|
|
|
|
g_param_spec_enum ("skip-frame", "Skip frames",
|
|
|
|
"Which types of frames to skip during decoding",
|
|
|
|
GST_FFMPEGVIDDEC_TYPE_SKIPFRAME, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_LOWRES,
|
|
|
|
g_param_spec_enum ("lowres", "Low resolution",
|
|
|
|
"At which resolution to decode images",
|
|
|
|
GST_FFMPEGVIDDEC_TYPE_LOWRES, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_DIRECT_RENDERING,
|
|
|
|
g_param_spec_boolean ("direct-rendering", "Direct Rendering",
|
|
|
|
"Enable direct rendering", DEFAULT_DIRECT_RENDERING,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2021-04-12 23:45:41 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2012-04-18 10:37:53 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_DEBUG_MV,
|
|
|
|
g_param_spec_boolean ("debug-mv", "Debug motion vectors",
|
2021-04-12 23:45:41 +00:00
|
|
|
"Whether to print motion vectors on top of the image "
|
|
|
|
"(deprecated, non-functional)", FALSE,
|
|
|
|
G_PARAM_DEPRECATED | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
#endif
|
2014-01-17 20:38:23 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_OUTPUT_CORRUPT,
|
|
|
|
g_param_spec_boolean ("output-corrupt", "Output corrupt buffers",
|
|
|
|
"Whether libav should output frames even if corrupted",
|
|
|
|
DEFAULT_OUTPUT_CORRUPT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-04-18 10:37:53 +00:00
|
|
|
|
|
|
|
caps = klass->in_plugin->capabilities;
|
2018-04-30 19:54:44 +00:00
|
|
|
if (caps & (AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS)) {
|
2012-04-18 10:37:53 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_MAX_THREADS,
|
|
|
|
g_param_spec_int ("max-threads", "Maximum decode threads",
|
|
|
|
"Maximum number of worker threads to spawn. (0 = auto)",
|
|
|
|
0, G_MAXINT, DEFAULT_MAX_THREADS,
|
2012-04-07 08:36:04 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2018-10-06 09:51:58 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_THREAD_TYPE,
|
|
|
|
g_param_spec_flags ("thread-type", "Thread type",
|
|
|
|
"Multithreading methods to use",
|
|
|
|
GST_FFMPEGVIDDEC_TYPE_THREAD_TYPE,
|
|
|
|
DEFAULT_THREAD_TYPE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
viddec_class->set_format = gst_ffmpegviddec_set_format;
|
|
|
|
viddec_class->handle_frame = gst_ffmpegviddec_handle_frame;
|
2013-08-29 14:53:28 +00:00
|
|
|
viddec_class->start = gst_ffmpegviddec_start;
|
2012-04-18 10:37:53 +00:00
|
|
|
viddec_class->stop = gst_ffmpegviddec_stop;
|
2013-08-15 13:51:52 +00:00
|
|
|
viddec_class->flush = gst_ffmpegviddec_flush;
|
2012-04-26 15:00:43 +00:00
|
|
|
viddec_class->finish = gst_ffmpegviddec_finish;
|
2015-10-26 18:54:10 +00:00
|
|
|
viddec_class->drain = gst_ffmpegviddec_drain;
|
2012-06-15 14:37:19 +00:00
|
|
|
viddec_class->decide_allocation = gst_ffmpegviddec_decide_allocation;
|
|
|
|
viddec_class->propose_allocation = gst_ffmpegviddec_propose_allocation;
|
2018-07-18 10:41:50 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_GET (GST_CAT_PERFORMANCE, "GST_PERFORMANCE");
|
2020-05-31 07:02:12 +00:00
|
|
|
|
2020-06-05 22:43:02 +00:00
|
|
|
gst_type_mark_as_plugin_api (GST_FFMPEGVIDDEC_TYPE_LOWRES, 0);
|
|
|
|
gst_type_mark_as_plugin_api (GST_FFMPEGVIDDEC_TYPE_SKIPFRAME, 0);
|
|
|
|
gst_type_mark_as_plugin_api (GST_FFMPEGVIDDEC_TYPE_THREAD_TYPE, 0);
|
2022-11-01 13:35:11 +00:00
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_AV_CODEC_COMPLIANCE, 0);
|
2022-11-01 15:13:23 +00:00
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_FFMPEGVIDDEC, 0);
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegviddec_init (GstFFMpegVidDec * ffmpegdec)
|
2022-11-01 15:13:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ffmpegviddec_subinit (GstFFMpegVidDec * ffmpegdec)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-12-05 18:25:37 +00:00
|
|
|
GstFFMpegVidDecClass *klass =
|
|
|
|
(GstFFMpegVidDecClass *) G_OBJECT_GET_CLASS (ffmpegdec);
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
/* some ffmpeg data */
|
2012-12-05 18:25:37 +00:00
|
|
|
ffmpegdec->context = avcodec_alloc_context3 (klass->in_plugin);
|
2013-02-21 01:50:15 +00:00
|
|
|
ffmpegdec->context->opaque = ffmpegdec;
|
2015-06-27 18:15:20 +00:00
|
|
|
ffmpegdec->picture = av_frame_alloc ();
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegdec->opened = FALSE;
|
|
|
|
ffmpegdec->skip_frame = ffmpegdec->lowres = 0;
|
|
|
|
ffmpegdec->direct_rendering = DEFAULT_DIRECT_RENDERING;
|
|
|
|
ffmpegdec->max_threads = DEFAULT_MAX_THREADS;
|
2014-01-17 20:38:23 +00:00
|
|
|
ffmpegdec->output_corrupt = DEFAULT_OUTPUT_CORRUPT;
|
2018-10-06 09:51:58 +00:00
|
|
|
ffmpegdec->thread_type = DEFAULT_THREAD_TYPE;
|
2022-11-04 18:15:34 +00:00
|
|
|
ffmpegdec->std_compliance = DEFAULT_STD_COMPLIANCE;
|
2013-12-05 10:51:27 +00:00
|
|
|
|
2015-08-14 11:22:39 +00:00
|
|
|
GST_PAD_SET_ACCEPT_TEMPLATE (GST_VIDEO_DECODER_SINK_PAD (ffmpegdec));
|
2015-08-15 10:18:07 +00:00
|
|
|
gst_video_decoder_set_use_default_pad_acceptcaps (GST_VIDEO_DECODER_CAST
|
|
|
|
(ffmpegdec), TRUE);
|
2015-08-14 11:22:39 +00:00
|
|
|
|
2013-12-05 10:51:27 +00:00
|
|
|
gst_video_decoder_set_needs_format (GST_VIDEO_DECODER (ffmpegdec), TRUE);
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegviddec_finalize (GObject * object)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec = GST_FFMPEGVIDDEC (object);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2015-06-27 18:25:18 +00:00
|
|
|
av_frame_free (&ffmpegdec->picture);
|
2022-01-16 17:33:47 +00:00
|
|
|
avcodec_free_context (&ffmpegdec->context);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2014-01-17 20:38:23 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegviddec_context_set_flags (AVCodecContext * context, guint flags,
|
|
|
|
gboolean enable)
|
|
|
|
{
|
|
|
|
g_return_if_fail (context != NULL);
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
context->flags |= flags;
|
|
|
|
else
|
|
|
|
context->flags &= ~flags;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2020-01-22 17:41:27 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegviddec_context_set_flags2 (AVCodecContext * context, guint flags,
|
|
|
|
gboolean enable)
|
|
|
|
{
|
|
|
|
g_return_if_fail (context != NULL);
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
context->flags2 |= flags;
|
|
|
|
else
|
|
|
|
context->flags2 &= ~flags;
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
/* with LOCK */
|
2013-08-29 14:53:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ffmpegviddec_close (GstFFMpegVidDec * ffmpegdec, gboolean reset)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2013-08-29 14:53:28 +00:00
|
|
|
GstFFMpegVidDecClass *oclass;
|
2018-06-30 00:18:43 +00:00
|
|
|
guint i;
|
2013-08-29 14:53:28 +00:00
|
|
|
|
2022-11-01 15:13:23 +00:00
|
|
|
oclass = GST_FFMPEGVIDDEC_GET_CLASS (ffmpegdec);
|
2013-08-29 14:53:28 +00:00
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegdec, "closing ffmpeg codec");
|
|
|
|
|
2012-06-20 01:41:14 +00:00
|
|
|
gst_caps_replace (&ffmpegdec->last_caps, NULL);
|
|
|
|
|
2013-08-29 14:53:28 +00:00
|
|
|
gst_ffmpeg_avcodec_close (ffmpegdec->context);
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegdec->opened = FALSE;
|
|
|
|
|
2013-09-12 10:11:29 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (ffmpegdec->stride); i++)
|
|
|
|
ffmpegdec->stride[i] = -1;
|
|
|
|
|
2012-12-12 08:48:53 +00:00
|
|
|
gst_buffer_replace (&ffmpegdec->palette, NULL);
|
|
|
|
|
2022-01-16 17:33:47 +00:00
|
|
|
av_freep (&ffmpegdec->context->extradata);
|
2013-08-29 14:53:28 +00:00
|
|
|
if (reset) {
|
2022-01-16 17:33:47 +00:00
|
|
|
avcodec_free_context (&ffmpegdec->context);
|
|
|
|
ffmpegdec->context = avcodec_alloc_context3 (oclass->in_plugin);
|
|
|
|
if (ffmpegdec->context == NULL) {
|
2013-08-29 14:53:28 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ffmpegdec->context->opaque = ffmpegdec;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* with LOCK */
|
|
|
|
static gboolean
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegviddec_open (GstFFMpegVidDec * ffmpegdec)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegVidDecClass *oclass;
|
2018-06-30 00:18:43 +00:00
|
|
|
guint i;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2022-11-01 15:13:23 +00:00
|
|
|
oclass = GST_FFMPEGVIDDEC_GET_CLASS (ffmpegdec);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
if (gst_ffmpeg_avcodec_open (ffmpegdec->context, oclass->in_plugin) < 0)
|
|
|
|
goto could_not_open;
|
|
|
|
|
2013-09-12 10:11:29 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (ffmpegdec->stride); i++)
|
|
|
|
ffmpegdec->stride[i] = -1;
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegdec->opened = TRUE;
|
|
|
|
|
2012-06-15 13:18:47 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegdec, "Opened libav codec %s, id %d",
|
2012-04-07 08:36:04 +00:00
|
|
|
oclass->in_plugin->name, oclass->in_plugin->id);
|
|
|
|
|
2014-01-17 20:38:23 +00:00
|
|
|
gst_ffmpegviddec_context_set_flags (ffmpegdec->context,
|
2018-04-30 19:54:44 +00:00
|
|
|
AV_CODEC_FLAG_OUTPUT_CORRUPT, ffmpegdec->output_corrupt);
|
2014-01-17 20:38:23 +00:00
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
could_not_open:
|
|
|
|
{
|
2013-08-29 14:53:28 +00:00
|
|
|
gst_ffmpegviddec_close (ffmpegdec, TRUE);
|
2012-06-15 13:18:47 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "avdec_%s: Failed to open libav codec",
|
2012-04-07 08:36:04 +00:00
|
|
|
oclass->in_plugin->name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-12 08:48:53 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegviddec_get_palette (GstFFMpegVidDec * ffmpegdec,
|
|
|
|
GstVideoCodecState * state)
|
|
|
|
{
|
|
|
|
GstStructure *str = gst_caps_get_structure (state->caps, 0);
|
|
|
|
const GValue *palette_v;
|
|
|
|
GstBuffer *palette;
|
|
|
|
|
|
|
|
/* do we have a palette? */
|
|
|
|
if ((palette_v = gst_structure_get_value (str, "palette_data"))) {
|
|
|
|
palette = gst_value_get_buffer (palette_v);
|
|
|
|
GST_DEBUG ("got palette data %p", palette);
|
|
|
|
if (gst_buffer_get_size (palette) >= AVPALETTE_SIZE) {
|
|
|
|
gst_buffer_replace (&ffmpegdec->palette, palette);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 14:44:01 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ffmpegviddec_needs_reset (GstFFMpegVidDec * ffmpegdec,
|
|
|
|
GstVideoCodecState * state)
|
|
|
|
{
|
|
|
|
GstCaps *last_caps, *new_caps;
|
|
|
|
gboolean needs_reset;
|
|
|
|
|
|
|
|
if (ffmpegdec->last_caps == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
last_caps = gst_caps_copy (ffmpegdec->last_caps);
|
|
|
|
new_caps = gst_caps_copy (state->caps);
|
|
|
|
|
|
|
|
/* Simply ignore framerate for now, this could easily be evolved per CODEC if
|
|
|
|
* future issue are found.*/
|
|
|
|
gst_structure_remove_field (gst_caps_get_structure (last_caps, 0),
|
|
|
|
"framerate");
|
|
|
|
gst_structure_remove_field (gst_caps_get_structure (new_caps, 0),
|
|
|
|
"framerate");
|
|
|
|
|
|
|
|
needs_reset = !gst_caps_is_equal (last_caps, new_caps);
|
|
|
|
|
|
|
|
gst_caps_unref (last_caps);
|
|
|
|
gst_caps_unref (new_caps);
|
|
|
|
|
|
|
|
return needs_reset;
|
|
|
|
}
|
2012-12-12 08:48:53 +00:00
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
static gboolean
|
2012-04-18 10:37:53 +00:00
|
|
|
gst_ffmpegviddec_set_format (GstVideoDecoder * decoder,
|
|
|
|
GstVideoCodecState * state)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec;
|
|
|
|
GstFFMpegVidDecClass *oclass;
|
2012-09-13 13:36:14 +00:00
|
|
|
GstClockTime latency = GST_CLOCK_TIME_NONE;
|
2012-06-14 13:04:33 +00:00
|
|
|
gboolean ret = FALSE;
|
2022-11-01 13:35:11 +00:00
|
|
|
gboolean is_live;
|
|
|
|
GstQuery *query;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2022-11-01 15:13:23 +00:00
|
|
|
ffmpegdec = GST_FFMPEGVIDDEC (decoder);
|
|
|
|
oclass = GST_FFMPEGVIDDEC_GET_CLASS (ffmpegdec);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "setcaps called");
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (ffmpegdec);
|
|
|
|
|
2022-10-26 14:44:01 +00:00
|
|
|
if (!gst_ffmpegviddec_needs_reset (ffmpegdec, state)) {
|
|
|
|
gst_caps_replace (&ffmpegdec->last_caps, state->caps);
|
|
|
|
goto update_state;
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
/* close old session */
|
|
|
|
if (ffmpegdec->opened) {
|
|
|
|
GST_OBJECT_UNLOCK (ffmpegdec);
|
2015-10-26 18:54:10 +00:00
|
|
|
gst_ffmpegviddec_finish (decoder);
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_OBJECT_LOCK (ffmpegdec);
|
2013-08-29 14:53:28 +00:00
|
|
|
if (!gst_ffmpegviddec_close (ffmpegdec, TRUE)) {
|
|
|
|
GST_OBJECT_UNLOCK (ffmpegdec);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-06-26 13:34:30 +00:00
|
|
|
ffmpegdec->pic_pix_fmt = 0;
|
|
|
|
ffmpegdec->pic_width = 0;
|
|
|
|
ffmpegdec->pic_height = 0;
|
|
|
|
ffmpegdec->pic_par_n = 0;
|
|
|
|
ffmpegdec->pic_par_d = 0;
|
2016-09-29 12:35:01 +00:00
|
|
|
ffmpegdec->pic_interlaced = 0;
|
|
|
|
ffmpegdec->pic_field_order = 0;
|
|
|
|
ffmpegdec->pic_field_order_changed = FALSE;
|
2015-06-26 13:34:30 +00:00
|
|
|
ffmpegdec->ctx_ticks = 0;
|
|
|
|
ffmpegdec->ctx_time_n = 0;
|
|
|
|
ffmpegdec->ctx_time_d = 0;
|
2017-03-16 04:23:01 +00:00
|
|
|
ffmpegdec->cur_multiview_mode = GST_VIDEO_MULTIVIEW_MODE_NONE;
|
|
|
|
ffmpegdec->cur_multiview_flags = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-09 18:40:06 +00:00
|
|
|
gst_caps_replace (&ffmpegdec->last_caps, state->caps);
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
/* set buffer functions */
|
2015-06-26 18:38:01 +00:00
|
|
|
ffmpegdec->context->get_buffer2 = gst_ffmpegviddec_get_buffer2;
|
2012-04-18 10:37:53 +00:00
|
|
|
ffmpegdec->context->draw_horiz_band = NULL;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2013-06-11 11:24:17 +00:00
|
|
|
/* reset coded_width/_height to prevent it being reused from last time when
|
|
|
|
* the codec is opened again, causing a mismatch and possible
|
|
|
|
* segfault/corruption. (Common scenario when renegotiating caps) */
|
|
|
|
ffmpegdec->context->coded_width = 0;
|
|
|
|
ffmpegdec->context->coded_height = 0;
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegdec, "size %dx%d", ffmpegdec->context->width,
|
|
|
|
ffmpegdec->context->height);
|
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
/* FIXME : Create a method that takes GstVideoCodecState instead */
|
2012-04-07 08:36:04 +00:00
|
|
|
/* get size and so */
|
|
|
|
gst_ffmpeg_caps_with_codecid (oclass->in_plugin->id,
|
2012-04-18 10:37:53 +00:00
|
|
|
oclass->in_plugin->type, state->caps, ffmpegdec->context);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "size after %dx%d", ffmpegdec->context->width,
|
|
|
|
ffmpegdec->context->height);
|
|
|
|
|
2012-12-12 08:48:53 +00:00
|
|
|
gst_ffmpegviddec_get_palette (ffmpegdec, state);
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
if (!ffmpegdec->context->time_base.den || !ffmpegdec->context->time_base.num) {
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "forcing 25/1 framerate");
|
|
|
|
ffmpegdec->context->time_base.num = 1;
|
|
|
|
ffmpegdec->context->time_base.den = 25;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* workaround encoder bugs */
|
|
|
|
ffmpegdec->context->workaround_bugs |= FF_BUG_AUTODETECT;
|
2012-12-04 17:28:11 +00:00
|
|
|
ffmpegdec->context->err_recognition = 1;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* for slow cpus */
|
|
|
|
ffmpegdec->context->lowres = ffmpegdec->lowres;
|
|
|
|
ffmpegdec->context->skip_frame = ffmpegdec->skip_frame;
|
|
|
|
|
2022-11-01 13:35:11 +00:00
|
|
|
|
|
|
|
query = gst_query_new_latency ();
|
|
|
|
is_live = FALSE;
|
|
|
|
/* Check if upstream is live. If it isn't we can enable frame based
|
|
|
|
* threading, which is adding latency */
|
|
|
|
if (gst_pad_peer_query (GST_VIDEO_DECODER_SINK_PAD (ffmpegdec), query)) {
|
|
|
|
gst_query_parse_latency (query, &is_live, NULL, NULL);
|
|
|
|
}
|
|
|
|
gst_query_unref (query);
|
|
|
|
|
2018-10-06 09:51:58 +00:00
|
|
|
if (ffmpegdec->thread_type) {
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "Use requested thread type 0x%x",
|
|
|
|
ffmpegdec->thread_type);
|
|
|
|
ffmpegdec->context->thread_type = ffmpegdec->thread_type;
|
|
|
|
} else {
|
2013-04-23 12:10:54 +00:00
|
|
|
if (is_live)
|
|
|
|
ffmpegdec->context->thread_type = FF_THREAD_SLICE;
|
|
|
|
else
|
|
|
|
ffmpegdec->context->thread_type = FF_THREAD_SLICE | FF_THREAD_FRAME;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2019-07-17 22:20:16 +00:00
|
|
|
if (ffmpegdec->max_threads == 0) {
|
|
|
|
/* When thread type is FF_THREAD_FRAME, extra latency is introduced equal
|
|
|
|
* to one frame per thread. We thus need to calculate the thread count ourselves */
|
2023-02-13 22:02:01 +00:00
|
|
|
if ((!(oclass->in_plugin->capabilities & AV_CODEC_CAP_OTHER_THREADS)) ||
|
2019-07-17 22:20:16 +00:00
|
|
|
(ffmpegdec->context->thread_type & FF_THREAD_FRAME))
|
2019-12-19 16:58:56 +00:00
|
|
|
ffmpegdec->context->thread_count =
|
|
|
|
MIN (gst_ffmpeg_auto_max_threads (), 16);
|
2019-07-17 22:20:16 +00:00
|
|
|
else
|
|
|
|
ffmpegdec->context->thread_count = 0;
|
|
|
|
} else
|
|
|
|
ffmpegdec->context->thread_count = ffmpegdec->max_threads;
|
|
|
|
|
2022-11-01 13:35:11 +00:00
|
|
|
if (ffmpegdec->std_compliance == GST_AV_CODEC_COMPLIANCE_AUTO) {
|
|
|
|
/* Normal yields lower latency, but fails some compliance check */
|
|
|
|
if (is_live || ffmpegdec->context->thread_type == FF_THREAD_SLICE) {
|
|
|
|
ffmpegdec->context->strict_std_compliance =
|
|
|
|
GST_AV_CODEC_COMPLIANCE_NORMAL;
|
|
|
|
} else {
|
|
|
|
ffmpegdec->context->strict_std_compliance =
|
|
|
|
GST_AV_CODEC_COMPLIANCE_STRICT;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ffmpegdec->context->strict_std_compliance = ffmpegdec->std_compliance;
|
|
|
|
}
|
|
|
|
|
2020-01-22 17:41:27 +00:00
|
|
|
if (oclass->in_plugin->id == AV_CODEC_ID_H264) {
|
|
|
|
GstStructure *s = gst_caps_get_structure (state->caps, 0);
|
|
|
|
const char *alignment;
|
|
|
|
gboolean nal_aligned;
|
|
|
|
|
|
|
|
alignment = gst_structure_get_string (s, "alignment");
|
|
|
|
nal_aligned = !g_strcmp0 (alignment, "nal");
|
|
|
|
if (nal_aligned) {
|
|
|
|
if (ffmpegdec->context->thread_type == FF_THREAD_FRAME)
|
|
|
|
goto nal_only_slice;
|
|
|
|
ffmpegdec->context->thread_type = FF_THREAD_SLICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_ffmpegviddec_context_set_flags2 (ffmpegdec->context,
|
|
|
|
AV_CODEC_FLAG2_CHUNKS, nal_aligned);
|
|
|
|
gst_video_decoder_set_subframe_mode (decoder, nal_aligned);
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
/* open codec - we don't select an output pix_fmt yet,
|
|
|
|
* simply because we don't know! We only get it
|
|
|
|
* during playback... */
|
2012-04-07 09:14:45 +00:00
|
|
|
if (!gst_ffmpegviddec_open (ffmpegdec))
|
2012-04-07 08:36:04 +00:00
|
|
|
goto open_failed;
|
|
|
|
|
2022-10-26 14:44:01 +00:00
|
|
|
update_state:
|
2012-04-18 10:37:53 +00:00
|
|
|
if (ffmpegdec->input_state)
|
|
|
|
gst_video_codec_state_unref (ffmpegdec->input_state);
|
|
|
|
ffmpegdec->input_state = gst_video_codec_state_ref (state);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2022-11-11 08:06:55 +00:00
|
|
|
/* Use the framerate values stored in the decoder for calculating latency. The
|
|
|
|
* upstream framerate might not be set but we still want to report a latency
|
|
|
|
* if needed. */
|
|
|
|
if (ffmpegdec->context->time_base.den && ffmpegdec->context->ticks_per_frame) {
|
|
|
|
gint fps_n =
|
|
|
|
ffmpegdec->context->time_base.den / ffmpegdec->context->ticks_per_frame;
|
|
|
|
gint fps_d = ffmpegdec->context->time_base.num;
|
2012-09-13 13:36:14 +00:00
|
|
|
latency = gst_util_uint64_scale_ceil (
|
2022-11-11 08:06:55 +00:00
|
|
|
(ffmpegdec->context->has_b_frames) * GST_SECOND, fps_d, fps_n);
|
2019-07-17 22:20:16 +00:00
|
|
|
|
|
|
|
if (ffmpegdec->context->thread_type & FF_THREAD_FRAME) {
|
|
|
|
latency +=
|
|
|
|
gst_util_uint64_scale_ceil (ffmpegdec->context->thread_count *
|
2022-11-11 08:06:55 +00:00
|
|
|
GST_SECOND, fps_d, fps_n);
|
2019-07-17 22:20:16 +00:00
|
|
|
}
|
2012-09-13 13:36:14 +00:00
|
|
|
}
|
|
|
|
|
2012-06-14 13:04:33 +00:00
|
|
|
ret = TRUE;
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
done:
|
|
|
|
GST_OBJECT_UNLOCK (ffmpegdec);
|
|
|
|
|
2012-09-25 17:29:08 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (latency))
|
|
|
|
gst_video_decoder_set_latency (decoder, latency, latency);
|
2012-09-13 13:36:14 +00:00
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
open_failed:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "Failed to open");
|
|
|
|
goto done;
|
|
|
|
}
|
2020-01-22 17:41:27 +00:00
|
|
|
nal_only_slice:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (ffmpegdec,
|
|
|
|
"Can't do NAL aligned H.264 with frame threading.");
|
|
|
|
goto done;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 13:18:47 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-01-10 16:18:53 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec;
|
2012-06-15 13:18:47 +00:00
|
|
|
GstVideoCodecFrame *frame;
|
|
|
|
gboolean mapped;
|
|
|
|
GstVideoFrame vframe;
|
2013-12-07 10:35:09 +00:00
|
|
|
GstBuffer *buffer;
|
2015-06-26 14:50:16 +00:00
|
|
|
AVBufferRef *avbuffer;
|
2012-06-15 13:18:47 +00:00
|
|
|
} GstFFMpegVidDecVideoFrame;
|
|
|
|
|
|
|
|
static GstFFMpegVidDecVideoFrame *
|
2014-01-10 16:18:53 +00:00
|
|
|
gst_ffmpegviddec_video_frame_new (GstFFMpegVidDec * ffmpegdec,
|
|
|
|
GstVideoCodecFrame * frame)
|
2012-06-15 13:18:47 +00:00
|
|
|
{
|
|
|
|
GstFFMpegVidDecVideoFrame *dframe;
|
|
|
|
|
2023-01-24 20:19:06 +00:00
|
|
|
dframe = g_new0 (GstFFMpegVidDecVideoFrame, 1);
|
2014-01-10 16:18:53 +00:00
|
|
|
dframe->ffmpegdec = ffmpegdec;
|
2012-07-03 15:04:03 +00:00
|
|
|
dframe->frame = frame;
|
2012-06-15 13:18:47 +00:00
|
|
|
|
2014-01-10 16:18:53 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "new video frame %p", dframe);
|
|
|
|
|
2012-06-15 13:18:47 +00:00
|
|
|
return dframe;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-11-26 19:55:43 +00:00
|
|
|
gst_ffmpegviddec_video_frame_free (GstFFMpegVidDec * ffmpegdec,
|
|
|
|
GstFFMpegVidDecVideoFrame * frame)
|
2012-06-15 13:18:47 +00:00
|
|
|
{
|
2014-01-10 16:18:53 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "free video frame %p", frame);
|
|
|
|
|
2012-06-15 13:18:47 +00:00
|
|
|
if (frame->mapped)
|
|
|
|
gst_video_frame_unmap (&frame->vframe);
|
2020-01-22 17:39:47 +00:00
|
|
|
GST_VIDEO_CODEC_FRAME_FLAG_UNSET (frame->frame,
|
|
|
|
GST_FFMPEG_VIDEO_CODEC_FRAME_FLAG_ALLOCATED);
|
2013-11-26 19:55:43 +00:00
|
|
|
gst_video_decoder_release_frame (GST_VIDEO_DECODER (ffmpegdec), frame->frame);
|
2013-12-07 10:35:09 +00:00
|
|
|
gst_buffer_replace (&frame->buffer, NULL);
|
2015-06-26 14:50:16 +00:00
|
|
|
if (frame->avbuffer) {
|
|
|
|
av_buffer_unref (&frame->avbuffer);
|
|
|
|
}
|
2023-01-24 20:19:06 +00:00
|
|
|
g_free (frame);
|
2012-06-15 13:18:47 +00:00
|
|
|
}
|
|
|
|
|
2014-01-10 16:18:53 +00:00
|
|
|
static void
|
|
|
|
dummy_free_buffer (void *opaque, uint8_t * data)
|
|
|
|
{
|
|
|
|
GstFFMpegVidDecVideoFrame *frame = opaque;
|
|
|
|
|
|
|
|
gst_ffmpegviddec_video_frame_free (frame->ffmpegdec, frame);
|
|
|
|
}
|
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
/* This function prepares the pool configuration for direct rendering. To use
|
|
|
|
* this method, the codec should support direct rendering and the pool should
|
2015-09-11 22:19:21 +00:00
|
|
|
* support video meta and video alignment */
|
2015-08-16 17:08:16 +00:00
|
|
|
static void
|
|
|
|
gst_ffmpegvideodec_prepare_dr_pool (GstFFMpegVidDec * ffmpegdec,
|
|
|
|
GstBufferPool * pool, GstVideoInfo * info, GstStructure * config)
|
|
|
|
{
|
2015-09-11 22:19:21 +00:00
|
|
|
GstAllocationParams params;
|
2015-08-16 17:08:16 +00:00
|
|
|
GstVideoAlignment align;
|
2015-09-11 22:19:21 +00:00
|
|
|
GstAllocator *allocator = NULL;
|
2015-08-16 17:08:16 +00:00
|
|
|
gint width, height;
|
2021-06-03 10:01:30 +00:00
|
|
|
gint linesize_align[AV_NUM_DATA_POINTERS];
|
2015-08-16 17:08:16 +00:00
|
|
|
gint i;
|
2015-09-11 22:19:21 +00:00
|
|
|
gsize max_align;
|
2015-08-16 17:08:16 +00:00
|
|
|
|
|
|
|
width = GST_VIDEO_INFO_WIDTH (info);
|
2020-12-02 04:43:15 +00:00
|
|
|
height = MAX (GST_VIDEO_INFO_HEIGHT (info), ffmpegdec->context->coded_height);
|
2015-08-16 17:08:16 +00:00
|
|
|
|
|
|
|
/* let ffmpeg find the alignment and padding */
|
|
|
|
avcodec_align_dimensions2 (ffmpegdec->context, &width, &height,
|
|
|
|
linesize_align);
|
|
|
|
|
2018-04-30 20:02:21 +00:00
|
|
|
align.padding_top = 0;
|
|
|
|
align.padding_left = 0;
|
|
|
|
align.padding_right = width - GST_VIDEO_INFO_WIDTH (info);
|
|
|
|
align.padding_bottom = height - GST_VIDEO_INFO_HEIGHT (info);
|
2017-08-10 15:55:29 +00:00
|
|
|
|
|
|
|
/* add extra padding to match libav buffer allocation sizes */
|
|
|
|
align.padding_bottom++;
|
2015-08-16 17:08:16 +00:00
|
|
|
|
2015-09-11 22:19:21 +00:00
|
|
|
gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms);
|
|
|
|
|
|
|
|
max_align = DEFAULT_STRIDE_ALIGN;
|
|
|
|
max_align |= params.align;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
|
|
|
if (linesize_align[i] > 0)
|
|
|
|
max_align |= linesize_align[i] - 1;
|
|
|
|
}
|
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
for (i = 0; i < GST_VIDEO_MAX_PLANES; i++)
|
2015-09-11 22:19:21 +00:00
|
|
|
align.stride_align[i] = max_align;
|
|
|
|
|
|
|
|
params.align = max_align;
|
|
|
|
|
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
|
2015-08-16 17:08:16 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "aligned dimension %dx%d -> %dx%d "
|
|
|
|
"padding t:%u l:%u r:%u b:%u, stride_align %d:%d:%d:%d",
|
|
|
|
GST_VIDEO_INFO_WIDTH (info),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (info), width, height, align.padding_top,
|
|
|
|
align.padding_left, align.padding_right, align.padding_bottom,
|
|
|
|
align.stride_align[0], align.stride_align[1], align.stride_align[2],
|
|
|
|
align.stride_align[3]);
|
|
|
|
|
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
|
|
|
|
gst_buffer_pool_config_set_video_alignment (config, &align);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ffmpegviddec_ensure_internal_pool (GstFFMpegVidDec * ffmpegdec,
|
2021-01-29 12:02:42 +00:00
|
|
|
AVFrame * picture, GstVideoInterlaceMode interlace_mode)
|
2015-08-16 17:08:16 +00:00
|
|
|
{
|
|
|
|
GstAllocationParams params = DEFAULT_ALLOC_PARAM;
|
2015-08-20 15:02:11 +00:00
|
|
|
GstVideoInfo info;
|
2015-08-16 17:08:16 +00:00
|
|
|
GstVideoFormat format;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstStructure *config;
|
2018-06-30 00:18:43 +00:00
|
|
|
guint i;
|
2015-08-20 15:02:11 +00:00
|
|
|
|
2021-01-28 06:11:14 +00:00
|
|
|
format = gst_ffmpeg_pixfmt_to_videoformat (picture->format);
|
|
|
|
|
2015-08-20 15:02:11 +00:00
|
|
|
if (ffmpegdec->internal_pool != NULL &&
|
2021-01-28 06:11:14 +00:00
|
|
|
GST_VIDEO_INFO_FORMAT (&ffmpegdec->pool_info) == format &&
|
2015-08-20 15:02:11 +00:00
|
|
|
ffmpegdec->pool_width == picture->width &&
|
|
|
|
ffmpegdec->pool_height == picture->height &&
|
|
|
|
ffmpegdec->pool_format == picture->format)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "Updating internal pool (%i, %i)",
|
|
|
|
picture->width, picture->height);
|
2015-08-16 17:08:16 +00:00
|
|
|
|
2021-01-28 06:11:14 +00:00
|
|
|
/* if we are negotiating from get_buffer, then renegotiate later in order
|
|
|
|
* to potentially use a downstream pool */
|
|
|
|
if (gst_ffmpegviddec_can_direct_render (ffmpegdec))
|
|
|
|
gst_pad_mark_reconfigure (GST_VIDEO_DECODER_SRC_PAD (ffmpegdec));
|
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
format = gst_ffmpeg_pixfmt_to_videoformat (picture->format);
|
2021-01-29 12:02:42 +00:00
|
|
|
|
|
|
|
if (interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE) {
|
|
|
|
gst_video_info_set_interlaced_format (&info, format, interlace_mode,
|
|
|
|
picture->width, 2 * picture->height);
|
|
|
|
} else {
|
|
|
|
gst_video_info_set_format (&info, format, picture->width, picture->height);
|
|
|
|
}
|
2015-08-16 17:08:16 +00:00
|
|
|
|
2018-07-02 02:05:19 +00:00
|
|
|
/* If we have not yet been negotiated, a NONE format here would
|
|
|
|
* result in invalid initial dimension alignments, and potential
|
|
|
|
* out of bounds writes.
|
|
|
|
*/
|
|
|
|
ffmpegdec->context->pix_fmt = picture->format;
|
|
|
|
|
2015-08-20 15:02:11 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (ffmpegdec->stride); i++)
|
|
|
|
ffmpegdec->stride[i] = -1;
|
|
|
|
|
|
|
|
if (ffmpegdec->internal_pool)
|
|
|
|
gst_object_unref (ffmpegdec->internal_pool);
|
2015-08-16 17:08:16 +00:00
|
|
|
|
|
|
|
ffmpegdec->internal_pool = gst_video_buffer_pool_new ();
|
|
|
|
config = gst_buffer_pool_get_config (ffmpegdec->internal_pool);
|
|
|
|
|
2015-08-20 15:02:11 +00:00
|
|
|
caps = gst_video_info_to_caps (&info);
|
|
|
|
gst_buffer_pool_config_set_params (config, caps, info.size, 2, 0);
|
2015-08-16 17:08:16 +00:00
|
|
|
gst_buffer_pool_config_set_allocator (config, NULL, ¶ms);
|
|
|
|
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
|
|
|
|
gst_ffmpegvideodec_prepare_dr_pool (ffmpegdec,
|
2015-08-20 15:02:11 +00:00
|
|
|
ffmpegdec->internal_pool, &info, config);
|
2015-08-16 17:08:16 +00:00
|
|
|
/* generic video pool never fails */
|
|
|
|
gst_buffer_pool_set_config (ffmpegdec->internal_pool, config);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
gst_buffer_pool_set_active (ffmpegdec->internal_pool, TRUE);
|
2015-08-20 15:02:11 +00:00
|
|
|
|
|
|
|
/* Remember pool size so we can detect changes */
|
|
|
|
ffmpegdec->pool_width = picture->width;
|
2021-04-24 08:04:23 +00:00
|
|
|
ffmpegdec->pool_height =
|
|
|
|
MAX (picture->height, ffmpegdec->context->coded_height);
|
2015-08-20 15:02:11 +00:00
|
|
|
ffmpegdec->pool_format = picture->format;
|
|
|
|
ffmpegdec->pool_info = info;
|
2015-08-16 17:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_ffmpegviddec_can_direct_render (GstFFMpegVidDec * ffmpegdec)
|
|
|
|
{
|
|
|
|
GstFFMpegVidDecClass *oclass;
|
|
|
|
|
|
|
|
if (!ffmpegdec->direct_rendering)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-11-01 15:13:23 +00:00
|
|
|
oclass = GST_FFMPEGVIDDEC_GET_CLASS (ffmpegdec);
|
2018-04-30 19:54:44 +00:00
|
|
|
return ((oclass->in_plugin->capabilities & AV_CODEC_CAP_DR1) ==
|
|
|
|
AV_CODEC_CAP_DR1);
|
2015-08-16 17:08:16 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 14:37:19 +00:00
|
|
|
/* called when ffmpeg wants us to allocate a buffer to write the decoded frame
|
|
|
|
* into. We try to give it memory from our pool */
|
2012-04-07 08:36:04 +00:00
|
|
|
static int
|
2015-06-26 18:38:01 +00:00
|
|
|
gst_ffmpegviddec_get_buffer2 (AVCodecContext * context, AVFrame * picture,
|
|
|
|
int flags)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-04-18 10:37:53 +00:00
|
|
|
GstVideoCodecFrame *frame;
|
2012-12-11 09:22:34 +00:00
|
|
|
GstFFMpegVidDecVideoFrame *dframe;
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec;
|
2018-06-30 00:18:43 +00:00
|
|
|
guint c;
|
2012-04-07 09:14:45 +00:00
|
|
|
GstFlowReturn ret;
|
2019-10-29 02:43:05 +00:00
|
|
|
int create_buffer_flags = 0;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2022-11-01 15:13:23 +00:00
|
|
|
ffmpegdec = GST_FFMPEGVIDDEC (context->opaque);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-09-11 11:53:23 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "getting buffer picture %p", picture);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* apply the last info we have seen to this picture, when we get the
|
|
|
|
* picture back from ffmpeg we can use this to correctly timestamp the output
|
|
|
|
* buffer */
|
2013-12-07 10:35:09 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "opaque value SN %d",
|
|
|
|
(gint32) picture->reordered_opaque);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
frame =
|
|
|
|
gst_video_decoder_get_frame (GST_VIDEO_DECODER (ffmpegdec),
|
|
|
|
picture->reordered_opaque);
|
|
|
|
if (G_UNLIKELY (frame == NULL))
|
|
|
|
goto no_frame;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2013-11-26 19:57:37 +00:00
|
|
|
/* now it has a buffer allocated, so it is real and will also
|
|
|
|
* be _released */
|
2020-01-22 17:39:47 +00:00
|
|
|
GST_VIDEO_CODEC_FRAME_FLAG_SET (frame,
|
|
|
|
GST_FFMPEG_VIDEO_CODEC_FRAME_FLAG_ALLOCATED);
|
2013-11-26 19:57:37 +00:00
|
|
|
GST_VIDEO_CODEC_FRAME_FLAG_UNSET (frame,
|
|
|
|
GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY);
|
|
|
|
|
2012-07-23 13:02:11 +00:00
|
|
|
if (G_UNLIKELY (frame->output_buffer != NULL))
|
|
|
|
goto duplicate_frame;
|
|
|
|
|
2012-07-03 15:04:03 +00:00
|
|
|
/* GstFFMpegVidDecVideoFrame receives the frame ref */
|
2015-06-26 18:38:01 +00:00
|
|
|
if (picture->opaque) {
|
|
|
|
dframe = picture->opaque;
|
|
|
|
dframe->frame = frame;
|
|
|
|
} else {
|
|
|
|
picture->opaque = dframe =
|
|
|
|
gst_ffmpegviddec_video_frame_new (ffmpegdec, frame);
|
|
|
|
}
|
2012-06-20 01:41:14 +00:00
|
|
|
|
2012-09-14 11:24:37 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "storing opaque %p", dframe);
|
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
if (!gst_ffmpegviddec_can_direct_render (ffmpegdec))
|
2012-06-15 14:37:19 +00:00
|
|
|
goto no_dr;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2021-01-29 12:02:42 +00:00
|
|
|
gst_ffmpegviddec_ensure_internal_pool (ffmpegdec, picture,
|
|
|
|
GST_BUFFER_FLAG_IS_SET (frame->input_buffer,
|
|
|
|
GST_VIDEO_BUFFER_FLAG_ONEFIELD) ? GST_VIDEO_INTERLACE_MODE_ALTERNATE :
|
|
|
|
GST_VIDEO_INTERLACE_MODE_PROGRESSIVE);
|
2015-08-16 17:08:16 +00:00
|
|
|
|
|
|
|
ret = gst_buffer_pool_acquire_buffer (ffmpegdec->internal_pool,
|
|
|
|
&frame->output_buffer, NULL);
|
2012-06-15 14:37:19 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto alloc_failed;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2013-12-07 10:35:09 +00:00
|
|
|
/* piggy-backed alloc'ed on the frame,
|
|
|
|
* and there was much rejoicing and we are grateful.
|
|
|
|
* Now take away buffer from frame, we will give it back later when decoded.
|
|
|
|
* This allows multiple request for a buffer per frame; unusual but possible. */
|
|
|
|
gst_buffer_replace (&dframe->buffer, frame->output_buffer);
|
|
|
|
gst_buffer_replace (&frame->output_buffer, NULL);
|
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
/* Fill avpicture */
|
2015-08-20 15:02:11 +00:00
|
|
|
if (!gst_video_frame_map (&dframe->vframe, &ffmpegdec->pool_info,
|
|
|
|
dframe->buffer, GST_MAP_READWRITE))
|
2015-11-07 17:11:57 +00:00
|
|
|
goto map_failed;
|
2012-06-15 13:18:47 +00:00
|
|
|
dframe->mapped = TRUE;
|
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
|
2015-08-20 15:02:11 +00:00
|
|
|
if (c < GST_VIDEO_INFO_N_PLANES (&ffmpegdec->pool_info)) {
|
2012-06-15 13:18:47 +00:00
|
|
|
picture->data[c] = GST_VIDEO_FRAME_PLANE_DATA (&dframe->vframe, c);
|
2012-08-10 15:03:26 +00:00
|
|
|
picture->linesize[c] = GST_VIDEO_FRAME_PLANE_STRIDE (&dframe->vframe, c);
|
2013-09-12 10:11:29 +00:00
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
if (ffmpegdec->stride[c] == -1)
|
|
|
|
ffmpegdec->stride[c] = picture->linesize[c];
|
|
|
|
|
|
|
|
/* libav does not allow stride changes, decide allocation should check
|
|
|
|
* before replacing the internal pool with a downstream pool.
|
2013-09-12 10:11:29 +00:00
|
|
|
* https://bugzilla.gnome.org/show_bug.cgi?id=704769
|
|
|
|
* https://bugzilla.libav.org/show_bug.cgi?id=556
|
|
|
|
*/
|
2015-08-16 17:08:16 +00:00
|
|
|
g_assert (picture->linesize[c] == ffmpegdec->stride[c]);
|
2012-04-18 10:37:53 +00:00
|
|
|
} else {
|
|
|
|
picture->data[c] = NULL;
|
|
|
|
picture->linesize[c] = 0;
|
|
|
|
}
|
2012-08-10 15:03:26 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegdec, "linesize %d, data %p", picture->linesize[c],
|
|
|
|
picture->data[c]);
|
2012-04-18 10:37:53 +00:00
|
|
|
}
|
2012-04-07 09:14:45 +00:00
|
|
|
|
2019-10-23 15:25:28 +00:00
|
|
|
if ((flags & AV_GET_BUFFER_FLAG_REF) == AV_GET_BUFFER_FLAG_REF) {
|
|
|
|
/* decoder might reuse this AVFrame and it would result to no more
|
|
|
|
* get_buffer() call if the AVFrame's AVBuffer is writable
|
|
|
|
* (meaning that the refcount of AVBuffer == 1).
|
2019-10-29 02:43:05 +00:00
|
|
|
* To enforce get_buffer() for the every output frame, set read-only flag here
|
2019-10-23 15:25:28 +00:00
|
|
|
*/
|
2019-10-29 02:43:05 +00:00
|
|
|
create_buffer_flags = AV_BUFFER_FLAG_READONLY;
|
2019-10-23 15:25:28 +00:00
|
|
|
}
|
2019-10-29 02:43:05 +00:00
|
|
|
picture->buf[0] = av_buffer_create (NULL,
|
|
|
|
0, dummy_free_buffer, dframe, create_buffer_flags);
|
2015-07-27 22:44:53 +00:00
|
|
|
|
2013-12-07 10:35:09 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegdec, "returned frame %p", dframe->buffer);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-04-18 10:37:53 +00:00
|
|
|
|
2012-06-15 14:37:19 +00:00
|
|
|
no_dr:
|
|
|
|
{
|
2013-09-12 11:56:31 +00:00
|
|
|
int c;
|
2015-06-26 18:38:01 +00:00
|
|
|
int ret = avcodec_default_get_buffer2 (context, picture, flags);
|
2013-09-12 11:56:31 +00:00
|
|
|
|
2015-11-07 17:11:57 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegdec, "direct rendering disabled, fallback alloc");
|
|
|
|
|
2014-01-10 16:18:53 +00:00
|
|
|
for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
|
2013-09-12 11:56:31 +00:00
|
|
|
ffmpegdec->stride[c] = picture->linesize[c];
|
2015-07-27 22:49:49 +00:00
|
|
|
}
|
|
|
|
/* Wrap our buffer around the default one to be able to have a callback
|
|
|
|
* when our data can be freed. Just putting our data into the first free
|
|
|
|
* buffer might not work if there are too many allocated already
|
|
|
|
*/
|
|
|
|
if (picture->buf[0]) {
|
|
|
|
dframe->avbuffer = picture->buf[0];
|
|
|
|
picture->buf[0] =
|
|
|
|
av_buffer_create (picture->buf[0]->data, picture->buf[0]->size,
|
|
|
|
dummy_free_buffer, dframe, 0);
|
|
|
|
} else {
|
|
|
|
picture->buf[0] =
|
|
|
|
av_buffer_create (NULL, 0, dummy_free_buffer, dframe, 0);
|
2014-01-10 16:18:53 +00:00
|
|
|
}
|
|
|
|
|
2013-09-12 11:56:31 +00:00
|
|
|
return ret;
|
2012-06-15 14:37:19 +00:00
|
|
|
}
|
2015-11-07 17:11:57 +00:00
|
|
|
alloc_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (ffmpegdec, RESOURCE, FAILED,
|
|
|
|
("Unable to allocate memory"),
|
|
|
|
("The downstream pool failed to allocated buffer."));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
map_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (ffmpegdec, RESOURCE, OPEN_READ_WRITE,
|
|
|
|
("Cannot access memory for read and write operation."),
|
|
|
|
("The video memory allocated from downstream pool could not mapped for"
|
|
|
|
"read and write."));
|
|
|
|
return -1;
|
|
|
|
}
|
2012-07-23 13:02:11 +00:00
|
|
|
duplicate_frame:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (ffmpegdec, "already alloc'ed output buffer for frame");
|
2012-12-11 10:34:42 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2012-07-23 13:02:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2012-04-18 10:37:53 +00:00
|
|
|
no_frame:
|
2012-09-11 11:53:23 +00:00
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (ffmpegdec, "Couldn't get codec frame !");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
static gboolean
|
2022-10-26 20:30:31 +00:00
|
|
|
picture_changed (GstFFMpegVidDec * ffmpegdec, AVFrame * picture,
|
|
|
|
gboolean one_field)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2016-09-29 12:35:01 +00:00
|
|
|
gint pic_field_order = 0;
|
|
|
|
|
2022-10-26 20:30:31 +00:00
|
|
|
if (one_field) {
|
|
|
|
pic_field_order = ffmpegdec->pic_field_order;
|
|
|
|
} else if (picture->interlaced_frame) {
|
2016-09-29 12:35:01 +00:00
|
|
|
if (picture->repeat_pict)
|
|
|
|
pic_field_order |= GST_VIDEO_BUFFER_FLAG_RFF;
|
|
|
|
if (picture->top_field_first)
|
|
|
|
pic_field_order |= GST_VIDEO_BUFFER_FLAG_TFF;
|
|
|
|
}
|
|
|
|
|
2015-06-26 13:34:30 +00:00
|
|
|
return !(ffmpegdec->pic_width == picture->width
|
|
|
|
&& ffmpegdec->pic_height == picture->height
|
|
|
|
&& ffmpegdec->pic_pix_fmt == picture->format
|
|
|
|
&& ffmpegdec->pic_par_n == picture->sample_aspect_ratio.num
|
|
|
|
&& ffmpegdec->pic_par_d == picture->sample_aspect_ratio.den
|
2016-09-29 12:35:01 +00:00
|
|
|
&& ffmpegdec->pic_interlaced == picture->interlaced_frame
|
2017-03-16 04:23:01 +00:00
|
|
|
&& ffmpegdec->pic_field_order == pic_field_order
|
|
|
|
&& ffmpegdec->cur_multiview_mode == ffmpegdec->picture_multiview_mode
|
|
|
|
&& ffmpegdec->cur_multiview_flags == ffmpegdec->picture_multiview_flags);
|
2015-06-26 13:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
context_changed (GstFFMpegVidDec * ffmpegdec, AVCodecContext * context)
|
|
|
|
{
|
|
|
|
return !(ffmpegdec->ctx_ticks == context->ticks_per_frame
|
2012-06-19 10:23:32 +00:00
|
|
|
&& ffmpegdec->ctx_time_n == context->time_base.num
|
2015-06-26 13:34:30 +00:00
|
|
|
&& ffmpegdec->ctx_time_d == context->time_base.den);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
update_video_context (GstFFMpegVidDec * ffmpegdec, AVCodecContext * context,
|
2022-10-26 20:30:31 +00:00
|
|
|
AVFrame * picture, gboolean one_field)
|
2015-06-26 13:34:30 +00:00
|
|
|
{
|
2016-09-29 12:35:01 +00:00
|
|
|
gint pic_field_order = 0;
|
|
|
|
|
|
|
|
if (picture->interlaced_frame) {
|
|
|
|
if (picture->repeat_pict)
|
|
|
|
pic_field_order |= GST_VIDEO_BUFFER_FLAG_RFF;
|
|
|
|
if (picture->top_field_first)
|
|
|
|
pic_field_order |= GST_VIDEO_BUFFER_FLAG_TFF;
|
|
|
|
}
|
|
|
|
|
2022-10-26 20:30:31 +00:00
|
|
|
if (!picture_changed (ffmpegdec, picture, one_field)
|
2015-06-26 13:34:30 +00:00
|
|
|
&& !context_changed (ffmpegdec, context))
|
2012-06-19 10:23:32 +00:00
|
|
|
return FALSE;
|
2012-04-18 10:37:53 +00:00
|
|
|
|
2012-04-07 09:14:45 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec,
|
2015-06-26 13:34:30 +00:00
|
|
|
"Renegotiating video from %dx%d@ %d:%d PAR %d/%d fps pixfmt %d to %dx%d@ %d:%d PAR %d/%d fps pixfmt %d",
|
|
|
|
ffmpegdec->pic_width, ffmpegdec->pic_height,
|
|
|
|
ffmpegdec->pic_par_n, ffmpegdec->pic_par_d,
|
2012-06-19 10:23:32 +00:00
|
|
|
ffmpegdec->ctx_time_n, ffmpegdec->ctx_time_d,
|
2015-06-26 13:34:30 +00:00
|
|
|
ffmpegdec->pic_pix_fmt,
|
|
|
|
picture->width, picture->height,
|
|
|
|
picture->sample_aspect_ratio.num,
|
|
|
|
picture->sample_aspect_ratio.den,
|
|
|
|
context->time_base.num, context->time_base.den, picture->format);
|
|
|
|
|
|
|
|
ffmpegdec->pic_pix_fmt = picture->format;
|
|
|
|
ffmpegdec->pic_width = picture->width;
|
|
|
|
ffmpegdec->pic_height = picture->height;
|
|
|
|
ffmpegdec->pic_par_n = picture->sample_aspect_ratio.num;
|
|
|
|
ffmpegdec->pic_par_d = picture->sample_aspect_ratio.den;
|
2017-03-16 04:23:01 +00:00
|
|
|
ffmpegdec->cur_multiview_mode = ffmpegdec->picture_multiview_mode;
|
|
|
|
ffmpegdec->cur_multiview_flags = ffmpegdec->picture_multiview_flags;
|
2016-09-29 12:35:01 +00:00
|
|
|
|
|
|
|
/* Remember if we have interlaced content and the field order changed
|
2016-11-04 14:27:59 +00:00
|
|
|
* at least once. If that happens, we must be interlace-mode=mixed
|
2016-09-29 12:35:01 +00:00
|
|
|
*/
|
|
|
|
if (ffmpegdec->pic_field_order_changed ||
|
|
|
|
(ffmpegdec->pic_field_order != pic_field_order &&
|
|
|
|
ffmpegdec->pic_interlaced))
|
|
|
|
ffmpegdec->pic_field_order_changed = TRUE;
|
|
|
|
|
|
|
|
ffmpegdec->pic_field_order = pic_field_order;
|
2015-06-26 13:34:30 +00:00
|
|
|
ffmpegdec->pic_interlaced = picture->interlaced_frame;
|
2016-09-29 12:35:01 +00:00
|
|
|
|
|
|
|
if (!ffmpegdec->pic_interlaced)
|
|
|
|
ffmpegdec->pic_field_order_changed = FALSE;
|
|
|
|
|
2012-06-19 10:23:32 +00:00
|
|
|
ffmpegdec->ctx_ticks = context->ticks_per_frame;
|
|
|
|
ffmpegdec->ctx_time_n = context->time_base.num;
|
|
|
|
ffmpegdec->ctx_time_d = context->time_base.den;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_ffmpegviddec_update_par (GstFFMpegVidDec * ffmpegdec,
|
|
|
|
GstVideoInfo * in_info, GstVideoInfo * out_info)
|
|
|
|
{
|
|
|
|
gboolean demuxer_par_set = FALSE;
|
|
|
|
gboolean decoder_par_set = FALSE;
|
|
|
|
gint demuxer_num = 1, demuxer_denom = 1;
|
|
|
|
gint decoder_num = 1, decoder_denom = 1;
|
2022-06-08 16:18:48 +00:00
|
|
|
GstVideoCodecFrame *out_frame;
|
|
|
|
GstFFMpegVidDecVideoFrame *out_dframe;
|
2012-06-19 10:23:32 +00:00
|
|
|
|
|
|
|
if (in_info->par_n && in_info->par_d) {
|
|
|
|
demuxer_num = in_info->par_n;
|
|
|
|
demuxer_denom = in_info->par_d;
|
|
|
|
demuxer_par_set = TRUE;
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "Demuxer PAR: %d:%d", demuxer_num,
|
|
|
|
demuxer_denom);
|
|
|
|
}
|
|
|
|
|
2015-06-26 13:34:30 +00:00
|
|
|
if (ffmpegdec->pic_par_n && ffmpegdec->pic_par_d) {
|
|
|
|
decoder_num = ffmpegdec->pic_par_n;
|
|
|
|
decoder_denom = ffmpegdec->pic_par_d;
|
2012-06-19 10:23:32 +00:00
|
|
|
decoder_par_set = TRUE;
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "Decoder PAR: %d:%d", decoder_num,
|
|
|
|
decoder_denom);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!demuxer_par_set && !decoder_par_set)
|
|
|
|
goto no_par;
|
|
|
|
|
|
|
|
if (demuxer_par_set && !decoder_par_set)
|
|
|
|
goto use_demuxer_par;
|
|
|
|
|
|
|
|
if (decoder_par_set && !demuxer_par_set)
|
|
|
|
goto use_decoder_par;
|
|
|
|
|
2022-06-08 16:18:48 +00:00
|
|
|
/* Special case for some encoders which provide an 1:2 pixel aspect ratio
|
|
|
|
* for HEVC interlaced content, possibly to work around decoders that don't
|
|
|
|
* support field-based interlacing. Add some defensive checks to check for
|
|
|
|
* a "common" aspect ratio. */
|
|
|
|
out_dframe = ffmpegdec->picture->opaque;
|
|
|
|
out_frame = out_dframe->frame;
|
|
|
|
|
|
|
|
if (demuxer_num == 1 && demuxer_denom == 1 &&
|
|
|
|
decoder_num == 1 && decoder_denom == 2 &&
|
|
|
|
GST_BUFFER_FLAG_IS_SET (out_frame->input_buffer,
|
|
|
|
GST_VIDEO_BUFFER_FLAG_ONEFIELD) &&
|
|
|
|
gst_video_is_common_aspect_ratio (ffmpegdec->pic_width,
|
|
|
|
ffmpegdec->pic_height, 1, 2) &&
|
|
|
|
!gst_video_is_common_aspect_ratio (ffmpegdec->pic_width,
|
|
|
|
ffmpegdec->pic_height, 1, 1)) {
|
|
|
|
GST_WARNING_OBJECT (ffmpegdec,
|
|
|
|
"PAR 1/2 makes the aspect ratio of "
|
|
|
|
"a %d x %d frame uncommon. Switching to 1/1",
|
|
|
|
ffmpegdec->pic_width, ffmpegdec->pic_height);
|
|
|
|
goto use_demuxer_par;
|
|
|
|
}
|
|
|
|
|
2012-06-19 10:23:32 +00:00
|
|
|
/* Both the demuxer and the decoder provide a PAR. If one of
|
|
|
|
* the two PARs is 1:1 and the other one is not, use the one
|
|
|
|
* that is not 1:1. */
|
2022-06-08 16:18:48 +00:00
|
|
|
if (demuxer_num == demuxer_denom && decoder_num != decoder_denom) {
|
2012-06-19 10:23:32 +00:00
|
|
|
goto use_decoder_par;
|
2022-06-08 16:18:48 +00:00
|
|
|
}
|
2012-06-19 10:23:32 +00:00
|
|
|
|
2022-06-08 16:18:48 +00:00
|
|
|
if (decoder_num == decoder_denom && demuxer_num != demuxer_denom) {
|
2012-06-19 10:23:32 +00:00
|
|
|
goto use_demuxer_par;
|
2022-06-08 16:18:48 +00:00
|
|
|
}
|
2012-06-19 10:23:32 +00:00
|
|
|
|
|
|
|
/* Both PARs are non-1:1, so use the PAR provided by the demuxer */
|
|
|
|
goto use_demuxer_par;
|
|
|
|
|
|
|
|
use_decoder_par:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec,
|
|
|
|
"Setting decoder provided pixel-aspect-ratio of %u:%u", decoder_num,
|
|
|
|
decoder_denom);
|
|
|
|
out_info->par_n = decoder_num;
|
|
|
|
out_info->par_d = decoder_denom;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
use_demuxer_par:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec,
|
|
|
|
"Setting demuxer provided pixel-aspect-ratio of %u:%u", demuxer_num,
|
|
|
|
demuxer_denom);
|
|
|
|
out_info->par_n = demuxer_num;
|
|
|
|
out_info->par_d = demuxer_denom;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
no_par:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec,
|
|
|
|
"Neither demuxer nor codec provide a pixel-aspect-ratio");
|
|
|
|
out_info->par_n = 1;
|
|
|
|
out_info->par_d = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 04:23:01 +00:00
|
|
|
static GstVideoMultiviewMode
|
|
|
|
stereo_av_to_gst (enum AVStereo3DType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case AV_STEREO3D_SIDEBYSIDE:
|
|
|
|
return GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE;
|
|
|
|
case AV_STEREO3D_TOPBOTTOM:
|
|
|
|
return GST_VIDEO_MULTIVIEW_MODE_TOP_BOTTOM;
|
|
|
|
case AV_STEREO3D_FRAMESEQUENCE:
|
|
|
|
return GST_VIDEO_MULTIVIEW_MODE_FRAME_BY_FRAME;
|
|
|
|
case AV_STEREO3D_CHECKERBOARD:
|
|
|
|
return GST_VIDEO_MULTIVIEW_MODE_CHECKERBOARD;
|
|
|
|
case AV_STEREO3D_SIDEBYSIDE_QUINCUNX:
|
|
|
|
return GST_VIDEO_MULTIVIEW_MODE_SIDE_BY_SIDE_QUINCUNX;
|
|
|
|
case AV_STEREO3D_LINES:
|
|
|
|
return GST_VIDEO_MULTIVIEW_MODE_ROW_INTERLEAVED;
|
|
|
|
case AV_STEREO3D_COLUMNS:
|
|
|
|
return GST_VIDEO_MULTIVIEW_MODE_COLUMN_INTERLEAVED;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_VIDEO_MULTIVIEW_MODE_NONE;
|
|
|
|
}
|
|
|
|
|
2019-02-18 11:53:58 +00:00
|
|
|
static gboolean
|
|
|
|
mastering_display_metadata_av_to_gst (AVMasteringDisplayMetadata * av,
|
|
|
|
GstVideoMasteringDisplayInfo * gst)
|
|
|
|
{
|
2020-03-11 09:26:39 +00:00
|
|
|
const guint64 chroma_scale = 50000;
|
|
|
|
const guint64 luma_scale = 10000;
|
|
|
|
gint i;
|
|
|
|
|
2019-02-18 11:53:58 +00:00
|
|
|
/* Use only complete mastering meta */
|
|
|
|
if (!av->has_primaries || !av->has_luminance)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-03-11 09:26:39 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (gst->display_primaries); i++) {
|
|
|
|
gst->display_primaries[i].x = (guint16) gst_util_uint64_scale (chroma_scale,
|
|
|
|
av->display_primaries[i][0].num, av->display_primaries[i][0].den);
|
|
|
|
gst->display_primaries[i].y = (guint16) gst_util_uint64_scale (chroma_scale,
|
|
|
|
av->display_primaries[i][1].num, av->display_primaries[i][1].den);
|
|
|
|
}
|
2019-02-18 11:53:58 +00:00
|
|
|
|
2020-03-11 09:26:39 +00:00
|
|
|
gst->white_point.x = (guint16) gst_util_uint64_scale (chroma_scale,
|
|
|
|
av->white_point[0].num, av->white_point[0].den);
|
|
|
|
gst->white_point.y = (guint16) gst_util_uint64_scale (chroma_scale,
|
|
|
|
av->white_point[1].num, av->white_point[1].den);
|
2019-02-18 11:53:58 +00:00
|
|
|
|
|
|
|
|
2020-03-11 09:26:39 +00:00
|
|
|
gst->max_display_mastering_luminance =
|
|
|
|
(guint32) gst_util_uint64_scale (luma_scale,
|
|
|
|
av->max_luminance.num, av->max_luminance.den);
|
|
|
|
gst->min_display_mastering_luminance =
|
|
|
|
(guint32) gst_util_uint64_scale (luma_scale,
|
|
|
|
av->min_luminance.num, av->min_luminance.den);
|
2019-02-18 11:53:58 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
content_light_metadata_av_to_gst (AVContentLightMetadata * av,
|
|
|
|
GstVideoContentLightLevel * gst)
|
|
|
|
{
|
2020-03-11 09:26:39 +00:00
|
|
|
gst->max_content_light_level = av->MaxCLL;
|
|
|
|
gst->max_frame_average_light_level = av->MaxFALL;
|
2019-02-18 11:53:58 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-19 10:23:32 +00:00
|
|
|
static gboolean
|
2013-09-12 10:12:23 +00:00
|
|
|
gst_ffmpegviddec_negotiate (GstFFMpegVidDec * ffmpegdec,
|
2021-01-29 12:02:42 +00:00
|
|
|
AVCodecContext * context, AVFrame * picture, GstBufferFlags flags)
|
2012-06-19 10:23:32 +00:00
|
|
|
{
|
|
|
|
GstVideoFormat fmt;
|
|
|
|
GstVideoInfo *in_info, *out_info;
|
|
|
|
GstVideoCodecState *output_state;
|
|
|
|
gint fps_n, fps_d;
|
2016-05-12 09:09:13 +00:00
|
|
|
GstClockTime latency;
|
2016-09-29 10:10:58 +00:00
|
|
|
GstStructure *in_s;
|
2021-01-29 12:02:42 +00:00
|
|
|
GstVideoInterlaceMode interlace_mode;
|
|
|
|
gint caps_height;
|
2022-10-26 20:30:31 +00:00
|
|
|
gboolean one_field = !!(flags & GST_VIDEO_BUFFER_FLAG_ONEFIELD);
|
2012-04-18 10:37:53 +00:00
|
|
|
|
2022-10-26 20:30:31 +00:00
|
|
|
if (!update_video_context (ffmpegdec, context, picture, one_field))
|
2012-06-19 10:23:32 +00:00
|
|
|
return TRUE;
|
2012-04-18 10:37:53 +00:00
|
|
|
|
2021-01-29 12:02:42 +00:00
|
|
|
caps_height = ffmpegdec->pic_height;
|
|
|
|
|
2015-06-26 13:34:30 +00:00
|
|
|
fmt = gst_ffmpeg_pixfmt_to_videoformat (ffmpegdec->pic_pix_fmt);
|
2012-04-18 10:37:53 +00:00
|
|
|
if (G_UNLIKELY (fmt == GST_VIDEO_FORMAT_UNKNOWN))
|
|
|
|
goto unknown_format;
|
|
|
|
|
2012-06-19 10:23:32 +00:00
|
|
|
/* set the interlaced flag */
|
2016-09-29 10:10:58 +00:00
|
|
|
in_s = gst_caps_get_structure (ffmpegdec->input_state->caps, 0);
|
2021-01-29 12:02:42 +00:00
|
|
|
if (flags & GST_VIDEO_BUFFER_FLAG_ONEFIELD) {
|
|
|
|
/* TODO: we don't get that information from ffmpeg, so copy it from
|
|
|
|
* the parser */
|
|
|
|
interlace_mode = GST_VIDEO_INTERLACE_MODE_ALTERNATE;
|
|
|
|
caps_height = 2 * caps_height;
|
|
|
|
} else if (!gst_structure_has_field (in_s, "interlace-mode")) {
|
2016-09-29 12:35:01 +00:00
|
|
|
if (ffmpegdec->pic_interlaced) {
|
|
|
|
if (ffmpegdec->pic_field_order_changed ||
|
|
|
|
(ffmpegdec->pic_field_order & GST_VIDEO_BUFFER_FLAG_RFF)) {
|
2021-01-29 12:02:42 +00:00
|
|
|
interlace_mode = GST_VIDEO_INTERLACE_MODE_MIXED;
|
2016-09-29 12:35:01 +00:00
|
|
|
} else {
|
2021-01-29 12:02:42 +00:00
|
|
|
interlace_mode = GST_VIDEO_INTERLACE_MODE_INTERLEAVED;
|
2016-09-29 12:35:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-01-29 12:02:42 +00:00
|
|
|
interlace_mode = GST_VIDEO_INTERLACE_MODE_PROGRESSIVE;
|
2016-09-29 12:35:01 +00:00
|
|
|
}
|
2021-01-29 12:02:42 +00:00
|
|
|
} else {
|
|
|
|
GstVideoInfo info;
|
|
|
|
|
|
|
|
gst_video_info_from_caps (&info, ffmpegdec->input_state->caps);
|
|
|
|
interlace_mode = info.interlace_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interlace_mode == GST_VIDEO_INTERLACE_MODE_ALTERNATE)
|
|
|
|
output_state =
|
|
|
|
gst_video_decoder_set_interlaced_output_state (GST_VIDEO_DECODER
|
|
|
|
(ffmpegdec), fmt, interlace_mode, ffmpegdec->pic_width, caps_height,
|
|
|
|
ffmpegdec->input_state);
|
|
|
|
else
|
|
|
|
output_state =
|
|
|
|
gst_video_decoder_set_output_state (GST_VIDEO_DECODER
|
|
|
|
(ffmpegdec), fmt, ffmpegdec->pic_width, caps_height,
|
|
|
|
ffmpegdec->input_state);
|
|
|
|
if (ffmpegdec->output_state)
|
|
|
|
gst_video_codec_state_unref (ffmpegdec->output_state);
|
|
|
|
ffmpegdec->output_state = output_state;
|
|
|
|
|
|
|
|
in_info = &ffmpegdec->input_state->info;
|
|
|
|
out_info = &ffmpegdec->output_state->info;
|
|
|
|
|
|
|
|
out_info->interlace_mode = interlace_mode;
|
|
|
|
if (!gst_structure_has_field (in_s, "interlace-mode")
|
|
|
|
&& interlace_mode == GST_VIDEO_INTERLACE_MODE_INTERLEAVED) {
|
|
|
|
if ((ffmpegdec->pic_field_order & GST_VIDEO_BUFFER_FLAG_TFF))
|
|
|
|
GST_VIDEO_INFO_FIELD_ORDER (out_info) =
|
|
|
|
GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST;
|
|
|
|
else
|
|
|
|
GST_VIDEO_INFO_FIELD_ORDER (out_info) =
|
|
|
|
GST_VIDEO_FIELD_ORDER_BOTTOM_FIELD_FIRST;
|
2016-09-29 12:35:01 +00:00
|
|
|
}
|
|
|
|
|
2016-09-29 10:10:58 +00:00
|
|
|
if (!gst_structure_has_field (in_s, "chroma-site")) {
|
|
|
|
switch (context->chroma_sample_location) {
|
|
|
|
case AVCHROMA_LOC_LEFT:
|
|
|
|
out_info->chroma_site = GST_VIDEO_CHROMA_SITE_MPEG2;
|
|
|
|
break;
|
|
|
|
case AVCHROMA_LOC_CENTER:
|
|
|
|
out_info->chroma_site = GST_VIDEO_CHROMA_SITE_JPEG;
|
|
|
|
break;
|
|
|
|
case AVCHROMA_LOC_TOPLEFT:
|
|
|
|
out_info->chroma_site = GST_VIDEO_CHROMA_SITE_DV;
|
|
|
|
break;
|
|
|
|
case AVCHROMA_LOC_TOP:
|
|
|
|
out_info->chroma_site = GST_VIDEO_CHROMA_SITE_V_COSITED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_has_field (in_s, "colorimetry")
|
|
|
|
|| in_info->colorimetry.primaries == GST_VIDEO_COLOR_PRIMARIES_UNKNOWN) {
|
2019-09-24 14:51:33 +00:00
|
|
|
out_info->colorimetry.primaries =
|
|
|
|
gst_video_color_primaries_from_iso (context->color_primaries);
|
2016-09-29 10:10:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_has_field (in_s, "colorimetry")
|
|
|
|
|| in_info->colorimetry.transfer == GST_VIDEO_TRANSFER_UNKNOWN) {
|
2019-09-24 14:51:33 +00:00
|
|
|
out_info->colorimetry.transfer =
|
2020-09-07 09:15:17 +00:00
|
|
|
gst_video_transfer_function_from_iso (context->color_trc);
|
2016-09-29 10:10:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_has_field (in_s, "colorimetry")
|
|
|
|
|| in_info->colorimetry.matrix == GST_VIDEO_COLOR_MATRIX_UNKNOWN) {
|
2019-09-24 14:51:33 +00:00
|
|
|
out_info->colorimetry.matrix =
|
|
|
|
gst_video_color_matrix_from_iso (context->colorspace);
|
2016-09-29 10:10:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_has_field (in_s, "colorimetry")
|
|
|
|
|| in_info->colorimetry.range == GST_VIDEO_COLOR_RANGE_UNKNOWN) {
|
|
|
|
if (context->color_range == AVCOL_RANGE_JPEG) {
|
|
|
|
out_info->colorimetry.range = GST_VIDEO_COLOR_RANGE_0_255;
|
2020-05-08 17:16:41 +00:00
|
|
|
} else if (context->color_range == AVCOL_RANGE_MPEG) {
|
2016-09-29 10:10:58 +00:00
|
|
|
out_info->colorimetry.range = GST_VIDEO_COLOR_RANGE_16_235;
|
2020-05-08 17:16:41 +00:00
|
|
|
} else {
|
|
|
|
out_info->colorimetry.range = GST_VIDEO_COLOR_RANGE_UNKNOWN;
|
2016-09-29 10:10:58 +00:00
|
|
|
}
|
2014-01-13 15:31:05 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 10:23:32 +00:00
|
|
|
/* try to find a good framerate */
|
2022-11-11 08:06:55 +00:00
|
|
|
if ((in_info->fps_d && in_info->fps_n)) {
|
2012-06-19 10:23:32 +00:00
|
|
|
/* take framerate from input when it was specified (#313970) */
|
|
|
|
fps_n = in_info->fps_n;
|
|
|
|
fps_d = in_info->fps_d;
|
|
|
|
} else {
|
|
|
|
fps_n = ffmpegdec->ctx_time_d / ffmpegdec->ctx_ticks;
|
|
|
|
fps_d = ffmpegdec->ctx_time_n;
|
|
|
|
|
|
|
|
if (!fps_d) {
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "invalid framerate: %d/0, -> %d/1", fps_n,
|
|
|
|
fps_n);
|
|
|
|
fps_d = 1;
|
|
|
|
}
|
|
|
|
if (gst_util_fraction_compare (fps_n, fps_d, 1000, 1) > 0) {
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "excessive framerate: %d/%d, -> 0/1", fps_n,
|
|
|
|
fps_d);
|
|
|
|
fps_n = 0;
|
|
|
|
fps_d = 1;
|
|
|
|
}
|
|
|
|
}
|
2014-10-07 05:33:07 +00:00
|
|
|
|
2022-11-11 08:06:55 +00:00
|
|
|
if (GST_VIDEO_INFO_FLAG_IS_SET (in_info, GST_VIDEO_FLAG_VARIABLE_FPS)) {
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "setting framerate: %d/%d", in_info->fps_n,
|
|
|
|
in_info->fps_d);
|
|
|
|
out_info->fps_n = in_info->fps_n;
|
|
|
|
out_info->fps_d = in_info->fps_d;
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "setting framerate: %d/%d", fps_n, fps_d);
|
|
|
|
out_info->fps_n = fps_n;
|
|
|
|
out_info->fps_d = fps_d;
|
|
|
|
}
|
2012-06-19 10:23:32 +00:00
|
|
|
|
|
|
|
/* calculate and update par now */
|
|
|
|
gst_ffmpegviddec_update_par (ffmpegdec, in_info, out_info);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2017-03-16 04:23:01 +00:00
|
|
|
GST_VIDEO_INFO_MULTIVIEW_MODE (out_info) = ffmpegdec->cur_multiview_mode;
|
|
|
|
GST_VIDEO_INFO_MULTIVIEW_FLAGS (out_info) = ffmpegdec->cur_multiview_flags;
|
2014-10-07 05:33:07 +00:00
|
|
|
|
2019-02-18 11:53:58 +00:00
|
|
|
/* To passing HDR information to caps directly */
|
|
|
|
if (output_state->caps == NULL) {
|
|
|
|
output_state->caps = gst_video_info_to_caps (out_info);
|
|
|
|
} else {
|
|
|
|
output_state->caps = gst_caps_make_writable (output_state->caps);
|
|
|
|
}
|
|
|
|
|
2021-01-29 12:02:42 +00:00
|
|
|
if (flags & GST_VIDEO_BUFFER_FLAG_ONEFIELD) {
|
|
|
|
/* TODO: we don't get that information from ffmpeg, so copy it from
|
|
|
|
* the parser */
|
|
|
|
gst_caps_features_add (gst_caps_get_features (ffmpegdec->output_state->caps,
|
|
|
|
0), GST_CAPS_FEATURE_FORMAT_INTERLACED);
|
|
|
|
}
|
|
|
|
|
2019-02-18 11:53:58 +00:00
|
|
|
if (!gst_structure_has_field (in_s, "mastering-display-info")) {
|
|
|
|
AVFrameSideData *sd = av_frame_get_side_data (picture,
|
|
|
|
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
|
2020-03-11 09:26:39 +00:00
|
|
|
GstVideoMasteringDisplayInfo minfo;
|
2019-02-18 11:53:58 +00:00
|
|
|
|
|
|
|
if (sd
|
|
|
|
&& mastering_display_metadata_av_to_gst ((AVMasteringDisplayMetadata *)
|
2020-03-11 09:26:39 +00:00
|
|
|
sd->data, &minfo)) {
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "update mastering display info: "
|
|
|
|
"Red(%u, %u) "
|
|
|
|
"Green(%u, %u) "
|
|
|
|
"Blue(%u, %u) "
|
|
|
|
"White(%u, %u) "
|
|
|
|
"max_luminance(%u) "
|
|
|
|
"min_luminance(%u) ",
|
|
|
|
minfo.display_primaries[0].x, minfo.display_primaries[0].y,
|
|
|
|
minfo.display_primaries[1].x, minfo.display_primaries[1].y,
|
|
|
|
minfo.display_primaries[2].x, minfo.display_primaries[2].y,
|
|
|
|
minfo.white_point.x, minfo.white_point.y,
|
|
|
|
minfo.max_display_mastering_luminance,
|
|
|
|
minfo.min_display_mastering_luminance);
|
|
|
|
|
|
|
|
if (!gst_video_mastering_display_info_add_to_caps (&minfo,
|
2019-02-18 11:53:58 +00:00
|
|
|
output_state->caps)) {
|
|
|
|
GST_WARNING_OBJECT (ffmpegdec,
|
|
|
|
"Couldn't set mastering display info to caps");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_has_field (in_s, "content-light-level")) {
|
|
|
|
AVFrameSideData *sd = av_frame_get_side_data (picture,
|
|
|
|
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
|
2020-03-11 09:26:39 +00:00
|
|
|
GstVideoContentLightLevel cll;
|
2019-02-18 11:53:58 +00:00
|
|
|
|
|
|
|
if (sd && content_light_metadata_av_to_gst ((AVContentLightMetadata *)
|
2020-03-11 09:26:39 +00:00
|
|
|
sd->data, &cll)) {
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "update content light level: "
|
|
|
|
"maxCLL:(%u), maxFALL:(%u)", cll.max_content_light_level,
|
|
|
|
cll.max_frame_average_light_level);
|
2019-02-18 11:53:58 +00:00
|
|
|
|
2020-03-11 09:26:39 +00:00
|
|
|
if (!gst_video_content_light_level_add_to_caps (&cll, output_state->caps)) {
|
2019-02-18 11:53:58 +00:00
|
|
|
GST_WARNING_OBJECT (ffmpegdec,
|
|
|
|
"Couldn't set content light level to caps");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-02 10:51:40 +00:00
|
|
|
if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (ffmpegdec)))
|
|
|
|
goto negotiate_failed;
|
2012-07-18 16:30:53 +00:00
|
|
|
|
2016-05-12 09:09:13 +00:00
|
|
|
/* The decoder is configured, we now know the true latency */
|
2016-05-14 10:09:06 +00:00
|
|
|
if (fps_n) {
|
|
|
|
latency =
|
|
|
|
gst_util_uint64_scale_ceil (ffmpegdec->context->has_b_frames *
|
|
|
|
GST_SECOND, fps_d, fps_n);
|
2019-07-17 22:20:16 +00:00
|
|
|
if (ffmpegdec->context->thread_type & FF_THREAD_FRAME) {
|
|
|
|
latency +=
|
|
|
|
gst_util_uint64_scale_ceil (ffmpegdec->context->thread_count *
|
|
|
|
GST_SECOND, fps_d, fps_n);
|
|
|
|
}
|
2016-05-14 10:09:06 +00:00
|
|
|
gst_video_decoder_set_latency (GST_VIDEO_DECODER (ffmpegdec), latency,
|
|
|
|
latency);
|
|
|
|
}
|
2016-05-12 09:09:13 +00:00
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
2012-04-18 10:37:53 +00:00
|
|
|
unknown_format:
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-04-18 10:37:53 +00:00
|
|
|
GST_ERROR_OBJECT (ffmpegdec,
|
|
|
|
"decoder requires a video format unsupported by GStreamer");
|
2012-04-07 08:36:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-10-02 10:51:40 +00:00
|
|
|
negotiate_failed:
|
|
|
|
{
|
|
|
|
/* Reset so we try again next time even if force==FALSE */
|
2015-06-26 13:34:30 +00:00
|
|
|
ffmpegdec->pic_pix_fmt = 0;
|
|
|
|
ffmpegdec->pic_width = 0;
|
|
|
|
ffmpegdec->pic_height = 0;
|
|
|
|
ffmpegdec->pic_par_n = 0;
|
|
|
|
ffmpegdec->pic_par_d = 0;
|
2016-09-29 12:35:01 +00:00
|
|
|
ffmpegdec->pic_interlaced = 0;
|
|
|
|
ffmpegdec->pic_field_order = 0;
|
|
|
|
ffmpegdec->pic_field_order_changed = FALSE;
|
2013-10-02 10:51:40 +00:00
|
|
|
ffmpegdec->ctx_ticks = 0;
|
|
|
|
ffmpegdec->ctx_time_n = 0;
|
|
|
|
ffmpegdec->ctx_time_d = 0;
|
|
|
|
|
|
|
|
GST_ERROR_OBJECT (ffmpegdec, "negotiation failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* perform qos calculations before decoding the next frame.
|
|
|
|
*
|
|
|
|
* Sets the skip_frame flag and if things are really bad, skips to the next
|
|
|
|
* keyframe.
|
2012-06-19 10:23:32 +00:00
|
|
|
*
|
2012-04-07 08:36:04 +00:00
|
|
|
*/
|
2014-05-13 18:17:17 +00:00
|
|
|
static void
|
2012-04-18 10:37:53 +00:00
|
|
|
gst_ffmpegviddec_do_qos (GstFFMpegVidDec * ffmpegdec,
|
|
|
|
GstVideoCodecFrame * frame, gboolean * mode_switch)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
|
|
|
GstClockTimeDiff diff;
|
2014-12-11 10:07:44 +00:00
|
|
|
GstSegmentFlags skip_flags =
|
|
|
|
GST_VIDEO_DECODER_INPUT_SEGMENT (ffmpegdec).flags;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
*mode_switch = FALSE;
|
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
if (frame == NULL)
|
2014-05-13 18:17:17 +00:00
|
|
|
return;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2014-12-11 10:07:44 +00:00
|
|
|
if (skip_flags & GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS) {
|
|
|
|
ffmpegdec->context->skip_frame = AVDISCARD_NONKEY;
|
|
|
|
*mode_switch = TRUE;
|
|
|
|
} else if (skip_flags & GST_SEGMENT_FLAG_TRICKMODE) {
|
|
|
|
ffmpegdec->context->skip_frame = AVDISCARD_NONREF;
|
|
|
|
*mode_switch = TRUE;
|
|
|
|
}
|
|
|
|
|
2016-08-04 08:45:14 +00:00
|
|
|
if (*mode_switch == TRUE) {
|
|
|
|
/* We've already switched mode, we can return straight away
|
|
|
|
* without any further calculation */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
diff =
|
|
|
|
gst_video_decoder_get_max_decode_time (GST_VIDEO_DECODER (ffmpegdec),
|
|
|
|
frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
/* if we don't have timing info, then we don't do QoS */
|
2016-08-04 08:45:14 +00:00
|
|
|
if (G_UNLIKELY (diff == G_MAXINT64)) {
|
|
|
|
/* Ensure the skipping strategy is the default one */
|
|
|
|
ffmpegdec->context->skip_frame = ffmpegdec->skip_frame;
|
2014-05-13 18:17:17 +00:00
|
|
|
return;
|
2016-08-04 08:45:14 +00:00
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2014-05-13 18:17:17 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "decoding time %" G_GINT64_FORMAT, diff);
|
2012-04-18 10:37:53 +00:00
|
|
|
|
2016-08-04 08:45:14 +00:00
|
|
|
if (diff > 0 && ffmpegdec->context->skip_frame != AVDISCARD_DEFAULT) {
|
|
|
|
ffmpegdec->context->skip_frame = AVDISCARD_DEFAULT;
|
|
|
|
*mode_switch = TRUE;
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "QOS: normal mode");
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2016-08-04 08:45:14 +00:00
|
|
|
else if (diff <= 0 && ffmpegdec->context->skip_frame != AVDISCARD_NONREF) {
|
|
|
|
ffmpegdec->context->skip_frame = AVDISCARD_NONREF;
|
|
|
|
*mode_switch = TRUE;
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec,
|
|
|
|
"QOS: hurry up, diff %" G_GINT64_FORMAT " >= 0", diff);
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get an outbuf buffer with the current picture */
|
|
|
|
static GstFlowReturn
|
2012-04-18 10:37:53 +00:00
|
|
|
get_output_buffer (GstFFMpegVidDec * ffmpegdec, GstVideoCodecFrame * frame)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2012-04-18 10:37:53 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2016-01-20 08:31:40 +00:00
|
|
|
AVFrame pic, *outpic;
|
2012-06-15 13:18:47 +00:00
|
|
|
GstVideoFrame vframe;
|
2012-04-18 10:37:53 +00:00
|
|
|
GstVideoInfo *info;
|
2018-06-30 00:18:43 +00:00
|
|
|
guint c;
|
2012-04-18 10:37:53 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "get output buffer");
|
|
|
|
|
2015-03-09 21:01:43 +00:00
|
|
|
if (!ffmpegdec->output_state)
|
|
|
|
goto not_negotiated;
|
|
|
|
|
2012-06-15 14:37:19 +00:00
|
|
|
ret =
|
2012-07-23 08:34:23 +00:00
|
|
|
gst_video_decoder_allocate_output_frame (GST_VIDEO_DECODER (ffmpegdec),
|
2012-06-15 14:37:19 +00:00
|
|
|
frame);
|
2012-04-18 10:37:53 +00:00
|
|
|
if (G_UNLIKELY (ret != GST_FLOW_OK))
|
|
|
|
goto alloc_failed;
|
|
|
|
|
|
|
|
/* original ffmpeg code does not handle odd sizes correctly.
|
|
|
|
* This patched up version does */
|
|
|
|
/* Fill avpicture */
|
|
|
|
info = &ffmpegdec->output_state->info;
|
2012-06-15 13:18:47 +00:00
|
|
|
if (!gst_video_frame_map (&vframe, info, frame->output_buffer,
|
|
|
|
GST_MAP_READ | GST_MAP_WRITE))
|
2015-11-07 17:11:57 +00:00
|
|
|
goto map_failed;
|
2012-06-15 13:18:47 +00:00
|
|
|
|
2016-01-20 08:31:40 +00:00
|
|
|
memset (&pic, 0, sizeof (pic));
|
|
|
|
pic.format = ffmpegdec->pic_pix_fmt;
|
|
|
|
pic.width = GST_VIDEO_FRAME_WIDTH (&vframe);
|
|
|
|
pic.height = GST_VIDEO_FRAME_HEIGHT (&vframe);
|
2012-04-18 10:37:53 +00:00
|
|
|
for (c = 0; c < AV_NUM_DATA_POINTERS; c++) {
|
2012-08-10 15:03:26 +00:00
|
|
|
if (c < GST_VIDEO_INFO_N_PLANES (info)) {
|
2012-06-15 13:18:47 +00:00
|
|
|
pic.data[c] = GST_VIDEO_FRAME_PLANE_DATA (&vframe, c);
|
2012-08-10 15:03:26 +00:00
|
|
|
pic.linesize[c] = GST_VIDEO_FRAME_PLANE_STRIDE (&vframe, c);
|
2015-08-20 15:02:11 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegdec, "[%i] linesize %d, data %p", c,
|
|
|
|
pic.linesize[c], pic.data[c]);
|
2012-04-18 10:37:53 +00:00
|
|
|
} else {
|
|
|
|
pic.data[c] = NULL;
|
|
|
|
pic.linesize[c] = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2016-01-20 08:31:40 +00:00
|
|
|
outpic = ffmpegdec->picture;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2016-01-20 08:31:40 +00:00
|
|
|
if (av_frame_copy (&pic, outpic) != 0) {
|
|
|
|
GST_ERROR_OBJECT (ffmpegdec, "Failed to copy output frame");
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-06-15 13:18:47 +00:00
|
|
|
gst_video_frame_unmap (&vframe);
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegdec->picture->reordered_opaque = -1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* special cases */
|
|
|
|
alloc_failed:
|
|
|
|
{
|
2015-11-07 17:11:57 +00:00
|
|
|
GST_ELEMENT_ERROR (ffmpegdec, RESOURCE, FAILED,
|
|
|
|
("Unable to allocate memory"),
|
|
|
|
("The downstream pool failed to allocated buffer."));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
map_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (ffmpegdec, RESOURCE, OPEN_READ_WRITE,
|
|
|
|
("Cannot access memory for read and write operation."),
|
|
|
|
("The video memory allocated from downstream pool could not mapped for"
|
|
|
|
"read and write."));
|
2012-04-07 08:36:04 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-03-09 21:01:43 +00:00
|
|
|
not_negotiated:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "not negotiated");
|
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_avpacket_init (AVPacket * packet, guint8 * data, guint size)
|
|
|
|
{
|
|
|
|
memset (packet, 0, sizeof (AVPacket));
|
|
|
|
packet->data = data;
|
|
|
|
packet->size = size;
|
|
|
|
}
|
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
/*
|
|
|
|
* Returns: whether a frame was decoded
|
2012-04-07 08:36:04 +00:00
|
|
|
*/
|
2018-06-30 00:14:33 +00:00
|
|
|
static gboolean
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegviddec_video_frame (GstFFMpegVidDec * ffmpegdec,
|
2018-06-30 00:14:33 +00:00
|
|
|
GstVideoCodecFrame * frame, GstFlowReturn * ret)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2018-06-30 00:14:33 +00:00
|
|
|
gint res;
|
|
|
|
gboolean got_frame = FALSE;
|
2012-04-07 08:36:04 +00:00
|
|
|
gboolean mode_switch;
|
2012-04-18 10:37:53 +00:00
|
|
|
GstVideoCodecFrame *out_frame;
|
2012-06-15 13:18:47 +00:00
|
|
|
GstFFMpegVidDecVideoFrame *out_dframe;
|
2015-08-16 17:08:16 +00:00
|
|
|
GstBufferPool *pool;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
*ret = GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* in case we skip frames */
|
|
|
|
ffmpegdec->picture->pict_type = -1;
|
|
|
|
|
|
|
|
/* run QoS code, we don't stop decoding the frame when we are late because
|
|
|
|
* else we might skip a reference frame */
|
2014-05-13 18:17:17 +00:00
|
|
|
gst_ffmpegviddec_do_qos (ffmpegdec, frame, &mode_switch);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
res = avcodec_receive_frame (ffmpegdec->context, ffmpegdec->picture);
|
2012-06-15 13:18:47 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
/* No frames available at this time */
|
2022-03-08 14:05:17 +00:00
|
|
|
if (res == AVERROR (EAGAIN)) {
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "Need more data");
|
2018-06-30 00:14:33 +00:00
|
|
|
goto beach;
|
2022-03-08 14:05:17 +00:00
|
|
|
} else if (res == AVERROR_EOF) {
|
2018-06-30 00:14:33 +00:00
|
|
|
*ret = GST_FLOW_EOS;
|
2018-07-31 16:35:22 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "Context was entirely flushed");
|
2018-06-30 00:14:33 +00:00
|
|
|
goto beach;
|
|
|
|
} else if (res < 0) {
|
2022-03-08 14:05:17 +00:00
|
|
|
GST_VIDEO_DECODER_ERROR (ffmpegdec, 1, STREAM, DECODE, (NULL),
|
|
|
|
("Video decoding error"), *ret);
|
2018-06-30 00:14:33 +00:00
|
|
|
goto beach;
|
2012-12-12 08:48:53 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
got_frame = TRUE;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* get the output picture timing info again */
|
2012-06-15 13:18:47 +00:00
|
|
|
out_dframe = ffmpegdec->picture->opaque;
|
2012-07-03 15:05:17 +00:00
|
|
|
out_frame = gst_video_codec_frame_ref (out_dframe->frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2013-12-07 10:35:09 +00:00
|
|
|
/* also give back a buffer allocated by the frame, if any */
|
|
|
|
gst_buffer_replace (&out_frame->output_buffer, out_dframe->buffer);
|
|
|
|
gst_buffer_replace (&out_dframe->buffer, NULL);
|
|
|
|
|
2017-03-16 04:23:01 +00:00
|
|
|
/* Extract auxilliary info not stored in the main AVframe */
|
|
|
|
{
|
|
|
|
GstVideoInfo *in_info = &ffmpegdec->input_state->info;
|
|
|
|
/* Take multiview mode from upstream if present */
|
|
|
|
ffmpegdec->picture_multiview_mode = GST_VIDEO_INFO_MULTIVIEW_MODE (in_info);
|
|
|
|
ffmpegdec->picture_multiview_flags =
|
|
|
|
GST_VIDEO_INFO_MULTIVIEW_FLAGS (in_info);
|
|
|
|
|
|
|
|
/* Otherwise, see if there's info in the frame */
|
|
|
|
if (ffmpegdec->picture_multiview_mode == GST_VIDEO_MULTIVIEW_MODE_NONE) {
|
|
|
|
AVFrameSideData *side_data =
|
|
|
|
av_frame_get_side_data (ffmpegdec->picture, AV_FRAME_DATA_STEREO3D);
|
|
|
|
if (side_data) {
|
|
|
|
AVStereo3D *stereo = (AVStereo3D *) side_data->data;
|
|
|
|
ffmpegdec->picture_multiview_mode = stereo_av_to_gst (stereo->type);
|
|
|
|
if (stereo->flags & AV_STEREO3D_FLAG_INVERT) {
|
|
|
|
ffmpegdec->picture_multiview_flags =
|
|
|
|
GST_VIDEO_MULTIVIEW_FLAGS_RIGHT_VIEW_FIRST;
|
|
|
|
} else {
|
|
|
|
ffmpegdec->picture_multiview_flags = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec,
|
2012-04-18 10:37:53 +00:00
|
|
|
"pts %" G_GUINT64_FORMAT " duration %" G_GUINT64_FORMAT,
|
|
|
|
out_frame->pts, out_frame->duration);
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "picture: pts %" G_GUINT64_FORMAT,
|
|
|
|
(guint64) ffmpegdec->picture->pts);
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "picture: num %d",
|
|
|
|
ffmpegdec->picture->coded_picture_number);
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "picture: display %d",
|
|
|
|
ffmpegdec->picture->display_picture_number);
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "picture: opaque %p",
|
|
|
|
ffmpegdec->picture->opaque);
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "picture: reordered opaque %" G_GUINT64_FORMAT,
|
|
|
|
(guint64) ffmpegdec->picture->reordered_opaque);
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "repeat_pict:%d",
|
|
|
|
ffmpegdec->picture->repeat_pict);
|
2014-01-16 12:44:56 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "corrupted frame: %d",
|
|
|
|
!!(ffmpegdec->picture->flags & AV_FRAME_FLAG_CORRUPT));
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2015-06-26 13:34:30 +00:00
|
|
|
if (!gst_ffmpegviddec_negotiate (ffmpegdec, ffmpegdec->context,
|
2021-01-29 12:02:42 +00:00
|
|
|
ffmpegdec->picture, GST_BUFFER_FLAGS (out_frame->input_buffer)))
|
2015-06-26 13:34:30 +00:00
|
|
|
goto negotiation_error;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
pool = gst_video_decoder_get_buffer_pool (GST_VIDEO_DECODER (ffmpegdec));
|
|
|
|
if (G_UNLIKELY (out_frame->output_buffer == NULL)) {
|
|
|
|
*ret = get_output_buffer (ffmpegdec, out_frame);
|
|
|
|
} else if (G_UNLIKELY (out_frame->output_buffer->pool != pool)) {
|
|
|
|
GstBuffer *tmp = out_frame->output_buffer;
|
|
|
|
out_frame->output_buffer = NULL;
|
2012-04-18 10:37:53 +00:00
|
|
|
*ret = get_output_buffer (ffmpegdec, out_frame);
|
2015-08-16 17:08:16 +00:00
|
|
|
gst_buffer_unref (tmp);
|
|
|
|
}
|
2015-11-30 17:01:41 +00:00
|
|
|
#ifndef G_DISABLE_ASSERT
|
|
|
|
else {
|
|
|
|
GstVideoMeta *vmeta = gst_buffer_get_video_meta (out_frame->output_buffer);
|
|
|
|
if (vmeta) {
|
|
|
|
GstVideoInfo *info = &ffmpegdec->output_state->info;
|
2018-06-30 00:18:43 +00:00
|
|
|
g_assert ((gint) vmeta->width == GST_VIDEO_INFO_WIDTH (info));
|
|
|
|
g_assert ((gint) vmeta->height == GST_VIDEO_INFO_HEIGHT (info));
|
2015-11-30 17:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-08-16 17:08:16 +00:00
|
|
|
gst_object_unref (pool);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
if (G_UNLIKELY (*ret != GST_FLOW_OK))
|
|
|
|
goto no_output;
|
|
|
|
|
2014-01-16 12:44:56 +00:00
|
|
|
/* Mark corrupted frames as corrupted */
|
|
|
|
if (ffmpegdec->picture->flags & AV_FRAME_FLAG_CORRUPT)
|
|
|
|
GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_BUFFER_FLAG_CORRUPTED);
|
|
|
|
|
2015-06-26 13:34:30 +00:00
|
|
|
if (ffmpegdec->pic_interlaced) {
|
2012-07-23 09:37:57 +00:00
|
|
|
/* set interlaced flags */
|
|
|
|
if (ffmpegdec->picture->repeat_pict)
|
|
|
|
GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_VIDEO_BUFFER_FLAG_RFF);
|
|
|
|
if (ffmpegdec->picture->top_field_first)
|
|
|
|
GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_VIDEO_BUFFER_FLAG_TFF);
|
|
|
|
if (ffmpegdec->picture->interlaced_frame)
|
|
|
|
GST_BUFFER_FLAG_SET (out_frame->output_buffer,
|
|
|
|
GST_VIDEO_BUFFER_FLAG_INTERLACED);
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2018-02-22 14:57:24 +00:00
|
|
|
{
|
|
|
|
AVFrameSideData *side_data =
|
|
|
|
av_frame_get_side_data (ffmpegdec->picture, AV_FRAME_DATA_A53_CC);
|
|
|
|
if (side_data) {
|
2019-03-28 18:24:42 +00:00
|
|
|
GST_LOG_OBJECT (ffmpegdec,
|
|
|
|
"Found CC side data of type AV_FRAME_DATA_A53_CC, size %d",
|
2022-01-16 17:33:47 +00:00
|
|
|
(int) side_data->size);
|
2018-02-22 14:57:24 +00:00
|
|
|
GST_MEMDUMP ("A53 CC", side_data->data, side_data->size);
|
2019-03-28 18:24:42 +00:00
|
|
|
|
2020-07-02 09:28:34 +00:00
|
|
|
/* do not add closed caption meta if it already exists */
|
2020-07-06 21:33:22 +00:00
|
|
|
if (!gst_buffer_get_meta (out_frame->input_buffer,
|
2020-07-02 09:28:34 +00:00
|
|
|
GST_VIDEO_CAPTION_META_API_TYPE)) {
|
2019-03-28 18:24:42 +00:00
|
|
|
out_frame->output_buffer =
|
|
|
|
gst_buffer_make_writable (out_frame->output_buffer);
|
|
|
|
gst_buffer_add_video_caption_meta (out_frame->output_buffer,
|
|
|
|
GST_VIDEO_CAPTION_TYPE_CEA708_RAW, side_data->data,
|
|
|
|
side_data->size);
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (ffmpegdec,
|
2020-07-02 09:28:34 +00:00
|
|
|
"Closed caption meta already exists: will not add new caption meta");
|
2019-03-28 18:24:42 +00:00
|
|
|
}
|
2018-02-22 14:57:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-26 19:57:37 +00:00
|
|
|
/* cleaning time */
|
|
|
|
/* so we decoded this frame, frames preceding it in decoding order
|
|
|
|
* that still do not have a buffer allocated seem rather useless,
|
|
|
|
* and can be discarded, due to e.g. misparsed bogus frame
|
|
|
|
* or non-keyframe in skipped decoding, ...
|
|
|
|
* In any case, not likely to be seen again, so discard those,
|
|
|
|
* before they pile up and/or mess with timestamping */
|
|
|
|
{
|
|
|
|
GList *l, *ol;
|
|
|
|
GstVideoDecoder *dec = GST_VIDEO_DECODER (ffmpegdec);
|
|
|
|
gboolean old = TRUE;
|
|
|
|
|
|
|
|
ol = l = gst_video_decoder_get_frames (dec);
|
|
|
|
while (l) {
|
|
|
|
GstVideoCodecFrame *tmp = l->data;
|
|
|
|
|
|
|
|
if (tmp == frame)
|
|
|
|
old = FALSE;
|
|
|
|
|
|
|
|
if (old && GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY (tmp)) {
|
|
|
|
GST_LOG_OBJECT (dec,
|
|
|
|
"discarding ghost frame %p (#%d) PTS:%" GST_TIME_FORMAT " DTS:%"
|
|
|
|
GST_TIME_FORMAT, tmp, tmp->system_frame_number,
|
|
|
|
GST_TIME_ARGS (tmp->pts), GST_TIME_ARGS (tmp->dts));
|
|
|
|
/* drop extra ref and remove from frame list */
|
2020-01-22 17:39:47 +00:00
|
|
|
GST_VIDEO_CODEC_FRAME_FLAG_UNSET (tmp,
|
|
|
|
GST_FFMPEG_VIDEO_CODEC_FRAME_FLAG_ALLOCATED);
|
2013-11-26 19:57:37 +00:00
|
|
|
gst_video_decoder_release_frame (dec, tmp);
|
|
|
|
} else {
|
|
|
|
/* drop extra ref we got */
|
|
|
|
gst_video_codec_frame_unref (tmp);
|
|
|
|
}
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
g_list_free (ol);
|
|
|
|
}
|
|
|
|
|
2015-06-27 18:15:20 +00:00
|
|
|
av_frame_unref (ffmpegdec->picture);
|
|
|
|
|
2020-01-22 17:39:47 +00:00
|
|
|
if (frame)
|
|
|
|
GST_VIDEO_CODEC_FRAME_FLAG_UNSET (frame,
|
|
|
|
GST_FFMPEG_VIDEO_CODEC_FRAME_FLAG_ALLOCATED);
|
2020-01-22 17:41:27 +00:00
|
|
|
|
|
|
|
if (gst_video_decoder_get_subframe_mode (GST_VIDEO_DECODER (ffmpegdec)))
|
|
|
|
gst_video_decoder_have_last_subframe (GST_VIDEO_DECODER (ffmpegdec),
|
|
|
|
out_frame);
|
2020-01-22 17:39:47 +00:00
|
|
|
|
2015-06-26 18:38:01 +00:00
|
|
|
/* FIXME: Ideally we would remap the buffer read-only now before pushing but
|
|
|
|
* libav might still have a reference to it!
|
|
|
|
*/
|
2021-01-29 12:02:42 +00:00
|
|
|
if (GST_BUFFER_FLAG_IS_SET (out_frame->input_buffer,
|
|
|
|
GST_VIDEO_BUFFER_FLAG_ONEFIELD)) {
|
|
|
|
GST_BUFFER_FLAG_SET (out_frame->output_buffer,
|
|
|
|
GST_VIDEO_BUFFER_FLAG_ONEFIELD);
|
|
|
|
if (GST_BUFFER_FLAG_IS_SET (out_frame->input_buffer,
|
|
|
|
GST_VIDEO_BUFFER_FLAG_TFF)) {
|
|
|
|
GST_BUFFER_FLAG_SET (out_frame->output_buffer, GST_VIDEO_BUFFER_FLAG_TFF);
|
|
|
|
}
|
|
|
|
}
|
2012-04-18 10:37:53 +00:00
|
|
|
*ret =
|
|
|
|
gst_video_decoder_finish_frame (GST_VIDEO_DECODER (ffmpegdec), out_frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
beach:
|
2018-06-30 00:14:33 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "return flow %s, got frame: %d",
|
|
|
|
gst_flow_get_name (*ret), got_frame);
|
|
|
|
return got_frame;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* special cases */
|
|
|
|
no_output:
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "no output buffer");
|
2020-01-22 17:39:47 +00:00
|
|
|
GST_VIDEO_CODEC_FRAME_FLAG_UNSET (frame,
|
|
|
|
GST_FFMPEG_VIDEO_CODEC_FRAME_FLAG_ALLOCATED);
|
2012-04-18 10:37:53 +00:00
|
|
|
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (ffmpegdec), out_frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
goto beach;
|
|
|
|
}
|
2012-06-15 10:19:58 +00:00
|
|
|
|
|
|
|
negotiation_error:
|
|
|
|
{
|
2022-04-15 14:38:46 +00:00
|
|
|
gst_video_decoder_drop_frame (GST_VIDEO_DECODER (ffmpegdec), out_frame);
|
2015-07-23 23:15:43 +00:00
|
|
|
if (GST_PAD_IS_FLUSHING (GST_VIDEO_DECODER_SRC_PAD (ffmpegdec))) {
|
|
|
|
*ret = GST_FLOW_FLUSHING;
|
|
|
|
goto beach;
|
|
|
|
}
|
2012-06-15 10:19:58 +00:00
|
|
|
GST_WARNING_OBJECT (ffmpegdec, "Error negotiating format");
|
|
|
|
*ret = GST_FLOW_NOT_NEGOTIATED;
|
|
|
|
goto beach;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
/* Returns: Whether a frame was decoded */
|
|
|
|
static gboolean
|
|
|
|
gst_ffmpegviddec_frame (GstFFMpegVidDec * ffmpegdec, GstVideoCodecFrame * frame,
|
2012-04-07 08:36:04 +00:00
|
|
|
GstFlowReturn * ret)
|
|
|
|
{
|
2018-06-30 00:14:33 +00:00
|
|
|
gboolean got_frame = FALSE;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (ffmpegdec->context->codec == NULL))
|
|
|
|
goto no_codec;
|
|
|
|
|
|
|
|
*ret = GST_FLOW_OK;
|
|
|
|
ffmpegdec->context->frame_number++;
|
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
got_frame = gst_ffmpegviddec_video_frame (ffmpegdec, frame, ret);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
return got_frame;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
no_codec:
|
|
|
|
{
|
|
|
|
GST_ERROR_OBJECT (ffmpegdec, "no codec context");
|
2012-07-26 10:37:01 +00:00
|
|
|
*ret = GST_FLOW_NOT_NEGOTIATED;
|
2012-04-07 08:36:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 18:54:10 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_ffmpegviddec_drain (GstVideoDecoder * decoder)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec = GST_FFMPEGVIDDEC (decoder);
|
2020-09-14 11:24:51 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2019-04-29 06:02:06 +00:00
|
|
|
gboolean got_frame = FALSE;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2014-02-21 13:18:47 +00:00
|
|
|
if (!ffmpegdec->opened)
|
2015-10-26 18:54:10 +00:00
|
|
|
return GST_FLOW_OK;
|
2014-02-21 13:18:47 +00:00
|
|
|
|
2023-03-14 18:27:39 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (ffmpegdec);
|
|
|
|
if (avcodec_send_packet (ffmpegdec->context, NULL)) {
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (ffmpegdec);
|
2019-04-29 06:02:06 +00:00
|
|
|
goto send_packet_failed;
|
2023-03-14 18:27:39 +00:00
|
|
|
}
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (ffmpegdec);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2019-04-29 06:02:06 +00:00
|
|
|
do {
|
|
|
|
got_frame = gst_ffmpegviddec_frame (ffmpegdec, NULL, &ret);
|
|
|
|
} while (got_frame && ret == GST_FLOW_OK);
|
|
|
|
avcodec_flush_buffers (ffmpegdec->context);
|
2015-10-26 18:54:10 +00:00
|
|
|
|
2020-09-15 18:13:09 +00:00
|
|
|
/* FFMpeg will return AVERROR_EOF if it's internal was fully drained
|
|
|
|
* then we are translating it to GST_FLOW_EOS. However, because this behavior
|
2020-09-30 13:13:28 +00:00
|
|
|
* is fully internal stuff of this implementation and gstvideodecoder
|
2020-09-15 18:13:09 +00:00
|
|
|
* baseclass doesn't convert this GST_FLOW_EOS to GST_FLOW_OK,
|
2020-09-30 13:13:28 +00:00
|
|
|
* convert this flow returned here */
|
2020-09-15 18:13:09 +00:00
|
|
|
if (ret == GST_FLOW_EOS)
|
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
|
2018-07-31 16:35:22 +00:00
|
|
|
done:
|
2020-09-14 11:24:51 +00:00
|
|
|
return ret;
|
2018-07-31 16:35:22 +00:00
|
|
|
|
|
|
|
send_packet_failed:
|
|
|
|
GST_WARNING_OBJECT (ffmpegdec, "send packet failed, could not drain decoder");
|
|
|
|
goto done;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-04-18 10:37:53 +00:00
|
|
|
gst_ffmpegviddec_handle_frame (GstVideoDecoder * decoder,
|
|
|
|
GstVideoCodecFrame * frame)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec = GST_FFMPEGVIDDEC (decoder);
|
2018-06-30 00:14:33 +00:00
|
|
|
guint8 *data;
|
|
|
|
gint size;
|
|
|
|
gboolean got_frame;
|
2012-06-15 13:18:47 +00:00
|
|
|
GstMapInfo minfo;
|
2012-04-07 08:36:04 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2018-06-30 00:14:33 +00:00
|
|
|
AVPacket packet;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (ffmpegdec,
|
2012-12-21 10:03:27 +00:00
|
|
|
"Received new data of size %" G_GSIZE_FORMAT ", dts %" GST_TIME_FORMAT
|
|
|
|
", pts:%" GST_TIME_FORMAT ", dur:%" GST_TIME_FORMAT,
|
|
|
|
gst_buffer_get_size (frame->input_buffer), GST_TIME_ARGS (frame->dts),
|
2012-04-18 10:37:53 +00:00
|
|
|
GST_TIME_ARGS (frame->pts), GST_TIME_ARGS (frame->duration));
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-06-15 14:37:19 +00:00
|
|
|
if (!gst_buffer_map (frame->input_buffer, &minfo, GST_MAP_READ)) {
|
2015-06-03 00:48:33 +00:00
|
|
|
GST_ELEMENT_ERROR (ffmpegdec, STREAM, DECODE, ("Decoding problem"),
|
|
|
|
("Failed to map buffer for reading"));
|
2012-06-15 14:37:19 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2012-06-15 13:18:47 +00:00
|
|
|
}
|
|
|
|
|
2013-11-26 19:57:37 +00:00
|
|
|
/* treat frame as void until a buffer is requested for it */
|
2020-01-22 17:39:47 +00:00
|
|
|
if (!GST_VIDEO_CODEC_FRAME_FLAG_IS_SET (frame,
|
|
|
|
GST_FFMPEG_VIDEO_CODEC_FRAME_FLAG_ALLOCATED))
|
|
|
|
GST_VIDEO_CODEC_FRAME_FLAG_SET (frame,
|
|
|
|
GST_VIDEO_CODEC_FRAME_FLAG_DECODE_ONLY);
|
2013-11-26 19:57:37 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
data = minfo.data;
|
|
|
|
size = minfo.size;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
if (size > 0 && (!GST_MEMORY_IS_ZERO_PADDED (minfo.memory)
|
2018-04-30 19:41:40 +00:00
|
|
|
|| (minfo.maxsize - minfo.size) < AV_INPUT_BUFFER_PADDING_SIZE)) {
|
2012-04-07 08:36:04 +00:00
|
|
|
/* add padding */
|
2018-06-30 00:14:33 +00:00
|
|
|
if (ffmpegdec->padded_size < size + AV_INPUT_BUFFER_PADDING_SIZE) {
|
|
|
|
ffmpegdec->padded_size = size + AV_INPUT_BUFFER_PADDING_SIZE;
|
2012-04-07 08:36:04 +00:00
|
|
|
ffmpegdec->padded = g_realloc (ffmpegdec->padded, ffmpegdec->padded_size);
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "resized padding buffer to %d",
|
|
|
|
ffmpegdec->padded_size);
|
|
|
|
}
|
2018-07-18 10:41:50 +00:00
|
|
|
GST_CAT_TRACE_OBJECT (GST_CAT_PERFORMANCE, ffmpegdec,
|
2012-06-15 14:37:19 +00:00
|
|
|
"Copy input to add padding");
|
2018-06-30 00:14:33 +00:00
|
|
|
memcpy (ffmpegdec->padded, data, size);
|
|
|
|
memset (ffmpegdec->padded + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
data = ffmpegdec->padded;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
/* now decode the frame */
|
|
|
|
gst_avpacket_init (&packet, data, size);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2023-02-28 12:00:26 +00:00
|
|
|
if (!packet.size)
|
|
|
|
goto done;
|
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
if (ffmpegdec->palette) {
|
|
|
|
guint8 *pal;
|
2012-04-18 10:37:53 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
pal = av_packet_new_side_data (&packet, AV_PKT_DATA_PALETTE,
|
|
|
|
AVPALETTE_SIZE);
|
|
|
|
gst_buffer_extract (ffmpegdec->palette, 0, pal, AVPALETTE_SIZE);
|
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "copy pal %p %p", &packet, pal);
|
|
|
|
}
|
2015-03-09 21:02:38 +00:00
|
|
|
|
2018-09-21 14:01:53 +00:00
|
|
|
/* save reference to the timing info */
|
|
|
|
ffmpegdec->context->reordered_opaque = (gint64) frame->system_frame_number;
|
|
|
|
ffmpegdec->picture->reordered_opaque = (gint64) frame->system_frame_number;
|
2012-04-18 10:37:53 +00:00
|
|
|
|
2018-09-21 14:01:53 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "stored opaque values idx %d",
|
|
|
|
frame->system_frame_number);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
/* This might call into get_buffer() from another thread,
|
|
|
|
* which would cause a deadlock. Release the lock here
|
|
|
|
* and taking it again later seems safe
|
|
|
|
* See https://bugzilla.gnome.org/show_bug.cgi?id=726020
|
|
|
|
*/
|
|
|
|
GST_VIDEO_DECODER_STREAM_UNLOCK (ffmpegdec);
|
|
|
|
if (avcodec_send_packet (ffmpegdec->context, &packet) < 0) {
|
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (ffmpegdec);
|
2023-02-28 12:00:26 +00:00
|
|
|
av_packet_free_side_data (&packet);
|
2018-06-30 00:14:33 +00:00
|
|
|
goto send_packet_failed;
|
|
|
|
}
|
2023-02-28 12:00:26 +00:00
|
|
|
av_packet_free_side_data (&packet);
|
2018-06-30 00:14:33 +00:00
|
|
|
GST_VIDEO_DECODER_STREAM_LOCK (ffmpegdec);
|
2012-06-15 14:37:19 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
do {
|
|
|
|
/* decode a frame of audio/video now */
|
|
|
|
got_frame = gst_ffmpegviddec_frame (ffmpegdec, frame, &ret);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
GST_LOG_OBJECT (ffmpegdec, "breaking because of flow ret %s",
|
|
|
|
gst_flow_get_name (ret));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (got_frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2018-06-30 00:14:33 +00:00
|
|
|
done:
|
2012-06-20 01:41:14 +00:00
|
|
|
gst_buffer_unmap (frame->input_buffer, &minfo);
|
2012-07-03 15:05:17 +00:00
|
|
|
gst_video_codec_frame_unref (frame);
|
2012-06-20 01:41:14 +00:00
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
return ret;
|
2018-06-30 00:14:33 +00:00
|
|
|
|
|
|
|
send_packet_failed:
|
|
|
|
{
|
2022-11-24 17:39:50 +00:00
|
|
|
GST_VIDEO_DECODER_ERROR (decoder, 1, STREAM, DECODE,
|
|
|
|
("Failed to send data for decoding"), ("Invalid input packet"), ret);
|
2018-06-30 00:14:33 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 14:53:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ffmpegviddec_start (GstVideoDecoder * decoder)
|
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec = GST_FFMPEGVIDDEC (decoder);
|
2013-08-29 14:53:28 +00:00
|
|
|
GstFFMpegVidDecClass *oclass;
|
|
|
|
|
2022-11-01 15:13:23 +00:00
|
|
|
oclass = GST_FFMPEGVIDDEC_GET_CLASS (ffmpegdec);
|
2013-08-29 14:53:28 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (ffmpegdec);
|
2022-01-16 17:33:47 +00:00
|
|
|
avcodec_free_context (&ffmpegdec->context);
|
|
|
|
ffmpegdec->context = avcodec_alloc_context3 (oclass->in_plugin);
|
|
|
|
if (ffmpegdec->context == NULL) {
|
2013-08-29 14:53:28 +00:00
|
|
|
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
|
|
|
|
GST_OBJECT_UNLOCK (ffmpegdec);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ffmpegdec->context->opaque = ffmpegdec;
|
|
|
|
GST_OBJECT_UNLOCK (ffmpegdec);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ffmpegviddec_stop (GstVideoDecoder * decoder)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec = GST_FFMPEGVIDDEC (decoder);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
GST_OBJECT_LOCK (ffmpegdec);
|
2013-08-29 14:53:28 +00:00
|
|
|
gst_ffmpegviddec_close (ffmpegdec, FALSE);
|
2012-04-18 10:37:53 +00:00
|
|
|
GST_OBJECT_UNLOCK (ffmpegdec);
|
|
|
|
g_free (ffmpegdec->padded);
|
|
|
|
ffmpegdec->padded = NULL;
|
|
|
|
ffmpegdec->padded_size = 0;
|
|
|
|
if (ffmpegdec->input_state)
|
|
|
|
gst_video_codec_state_unref (ffmpegdec->input_state);
|
|
|
|
ffmpegdec->input_state = NULL;
|
|
|
|
if (ffmpegdec->output_state)
|
|
|
|
gst_video_codec_state_unref (ffmpegdec->output_state);
|
|
|
|
ffmpegdec->output_state = NULL;
|
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
if (ffmpegdec->internal_pool)
|
|
|
|
gst_object_unref (ffmpegdec->internal_pool);
|
|
|
|
ffmpegdec->internal_pool = NULL;
|
|
|
|
|
2015-06-26 13:34:30 +00:00
|
|
|
ffmpegdec->pic_pix_fmt = 0;
|
|
|
|
ffmpegdec->pic_width = 0;
|
|
|
|
ffmpegdec->pic_height = 0;
|
|
|
|
ffmpegdec->pic_par_n = 0;
|
|
|
|
ffmpegdec->pic_par_d = 0;
|
2016-09-29 12:35:01 +00:00
|
|
|
ffmpegdec->pic_interlaced = 0;
|
|
|
|
ffmpegdec->pic_field_order = 0;
|
|
|
|
ffmpegdec->pic_field_order_changed = FALSE;
|
2013-10-02 10:52:35 +00:00
|
|
|
ffmpegdec->ctx_ticks = 0;
|
|
|
|
ffmpegdec->ctx_time_n = 0;
|
|
|
|
ffmpegdec->ctx_time_d = 0;
|
|
|
|
|
2015-08-20 15:02:11 +00:00
|
|
|
ffmpegdec->pool_width = 0;
|
|
|
|
ffmpegdec->pool_height = 0;
|
|
|
|
ffmpegdec->pool_format = 0;
|
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-04-26 15:00:43 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_ffmpegviddec_finish (GstVideoDecoder * decoder)
|
|
|
|
{
|
2020-09-14 11:24:51 +00:00
|
|
|
GstFlowReturn flow_ret;
|
|
|
|
|
|
|
|
flow_ret = gst_ffmpegviddec_drain (decoder);
|
|
|
|
|
2015-10-26 18:54:10 +00:00
|
|
|
/* note that finish can and should clean up more drastically,
|
|
|
|
* but drain is also invoked on e.g. packet loss in GAP handling */
|
|
|
|
gst_ffmpegviddec_flush (decoder);
|
2012-04-26 15:00:43 +00:00
|
|
|
|
2020-09-14 11:24:51 +00:00
|
|
|
return flow_ret;
|
2012-04-26 15:00:43 +00:00
|
|
|
}
|
|
|
|
|
2012-04-18 10:37:53 +00:00
|
|
|
static gboolean
|
2013-08-15 13:51:52 +00:00
|
|
|
gst_ffmpegviddec_flush (GstVideoDecoder * decoder)
|
2012-04-18 10:37:53 +00:00
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec = GST_FFMPEGVIDDEC (decoder);
|
2012-04-18 10:37:53 +00:00
|
|
|
|
2015-10-26 18:54:10 +00:00
|
|
|
if (ffmpegdec->opened) {
|
|
|
|
GST_LOG_OBJECT (decoder, "flushing buffers");
|
2012-04-26 15:00:43 +00:00
|
|
|
avcodec_flush_buffers (ffmpegdec->context);
|
2015-10-26 18:54:10 +00:00
|
|
|
}
|
2012-04-18 10:37:53 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 14:37:19 +00:00
|
|
|
static gboolean
|
|
|
|
gst_ffmpegviddec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query)
|
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec = GST_FFMPEGVIDDEC (decoder);
|
2012-06-15 14:37:19 +00:00
|
|
|
GstVideoCodecState *state;
|
|
|
|
GstBufferPool *pool;
|
|
|
|
guint size, min, max;
|
|
|
|
GstStructure *config;
|
2015-08-16 17:08:16 +00:00
|
|
|
gboolean have_pool, have_videometa, have_alignment, update_pool = FALSE;
|
2012-08-08 13:59:59 +00:00
|
|
|
GstAllocator *allocator = NULL;
|
2015-08-16 17:08:16 +00:00
|
|
|
GstAllocationParams params = DEFAULT_ALLOC_PARAM;
|
|
|
|
|
|
|
|
have_pool = (gst_query_get_n_allocation_pools (query) != 0);
|
2012-06-15 14:37:19 +00:00
|
|
|
|
|
|
|
if (!GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation (decoder,
|
|
|
|
query))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
state = gst_video_decoder_get_output_state (decoder);
|
|
|
|
|
2012-08-08 13:59:59 +00:00
|
|
|
if (gst_query_get_n_allocation_params (query) > 0) {
|
|
|
|
gst_query_parse_nth_allocation_param (query, 0, &allocator, ¶ms);
|
2015-08-16 17:08:16 +00:00
|
|
|
params.align = MAX (params.align, DEFAULT_STRIDE_ALIGN);
|
2012-08-08 13:59:59 +00:00
|
|
|
} else {
|
|
|
|
gst_query_add_allocation_param (query, allocator, ¶ms);
|
|
|
|
}
|
|
|
|
|
2012-06-15 14:37:19 +00:00
|
|
|
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
|
|
|
|
2014-03-27 22:53:53 +00:00
|
|
|
/* Don't use pool that can't grow, as we don't know how many buffer we'll
|
|
|
|
* need, otherwise we may stall */
|
|
|
|
if (max != 0 && max < REQUIRED_POOL_MAX_BUFFERS) {
|
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = gst_video_buffer_pool_new ();
|
|
|
|
max = 0;
|
|
|
|
update_pool = TRUE;
|
2015-08-16 17:08:16 +00:00
|
|
|
have_pool = FALSE;
|
2014-03-27 22:53:53 +00:00
|
|
|
|
|
|
|
/* if there is an allocator, also drop it, as it might be the reason we
|
|
|
|
* have this limit. Default will be used */
|
|
|
|
if (allocator) {
|
|
|
|
gst_object_unref (allocator);
|
|
|
|
allocator = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 14:37:19 +00:00
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, state->caps, size, min, max);
|
2012-08-08 13:59:59 +00:00
|
|
|
gst_buffer_pool_config_set_allocator (config, allocator, ¶ms);
|
2012-06-15 14:37:19 +00:00
|
|
|
|
|
|
|
have_videometa =
|
2012-07-06 09:27:33 +00:00
|
|
|
gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
|
2015-08-16 17:08:16 +00:00
|
|
|
|
2012-06-15 14:37:19 +00:00
|
|
|
if (have_videometa)
|
|
|
|
gst_buffer_pool_config_add_option (config,
|
|
|
|
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
|
|
|
|
|
|
|
have_alignment =
|
|
|
|
gst_buffer_pool_has_option (pool, GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
|
|
|
|
|
2015-09-11 22:19:21 +00:00
|
|
|
/* If we have videometa, we never have to copy */
|
2015-08-16 17:08:16 +00:00
|
|
|
if (have_videometa && have_pool && have_alignment &&
|
|
|
|
gst_ffmpegviddec_can_direct_render (ffmpegdec)) {
|
2015-10-16 15:52:57 +00:00
|
|
|
GstStructure *config_copy = gst_structure_copy (config);
|
|
|
|
|
|
|
|
gst_ffmpegvideodec_prepare_dr_pool (ffmpegdec, pool, &state->info,
|
|
|
|
config_copy);
|
2015-08-16 17:08:16 +00:00
|
|
|
|
|
|
|
/* FIXME validate and retry */
|
2015-11-23 01:31:39 +00:00
|
|
|
if (gst_buffer_pool_set_config (pool, config_copy)) {
|
2015-08-16 17:08:16 +00:00
|
|
|
GstFlowReturn ret;
|
|
|
|
GstBuffer *tmp;
|
|
|
|
|
|
|
|
gst_buffer_pool_set_active (pool, TRUE);
|
|
|
|
ret = gst_buffer_pool_acquire_buffer (pool, &tmp, NULL);
|
|
|
|
if (ret == GST_FLOW_OK) {
|
|
|
|
GstVideoMeta *vmeta = gst_buffer_get_video_meta (tmp);
|
|
|
|
gboolean same_stride = TRUE;
|
2018-06-30 00:18:43 +00:00
|
|
|
guint i;
|
2015-08-16 17:08:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < vmeta->n_planes; i++) {
|
|
|
|
if (vmeta->stride[i] != ffmpegdec->stride[i]) {
|
|
|
|
same_stride = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-15 14:37:19 +00:00
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
gst_buffer_unref (tmp);
|
2012-06-15 14:37:19 +00:00
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
if (same_stride) {
|
|
|
|
if (ffmpegdec->internal_pool)
|
|
|
|
gst_object_unref (ffmpegdec->internal_pool);
|
|
|
|
ffmpegdec->internal_pool = gst_object_ref (pool);
|
2021-01-28 06:11:14 +00:00
|
|
|
ffmpegdec->pool_width = GST_VIDEO_INFO_WIDTH (&state->info);
|
2021-04-24 08:04:23 +00:00
|
|
|
ffmpegdec->pool_height =
|
|
|
|
MAX (GST_VIDEO_INFO_HEIGHT (&state->info),
|
|
|
|
ffmpegdec->context->coded_height);
|
2015-08-20 15:02:11 +00:00
|
|
|
ffmpegdec->pool_info = state->info;
|
2015-10-16 15:52:57 +00:00
|
|
|
gst_structure_free (config);
|
2015-08-16 17:08:16 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-15 14:37:19 +00:00
|
|
|
|
2015-11-30 17:01:41 +00:00
|
|
|
if (have_videometa && ffmpegdec->internal_pool
|
2021-01-28 06:11:14 +00:00
|
|
|
&& gst_ffmpeg_pixfmt_to_videoformat (ffmpegdec->pool_format) ==
|
|
|
|
GST_VIDEO_INFO_FORMAT (&state->info)
|
2015-11-30 17:01:41 +00:00
|
|
|
&& ffmpegdec->pool_width == state->info.width
|
|
|
|
&& ffmpegdec->pool_height == state->info.height) {
|
2015-08-16 17:08:16 +00:00
|
|
|
update_pool = TRUE;
|
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = gst_object_ref (ffmpegdec->internal_pool);
|
2015-10-16 15:52:57 +00:00
|
|
|
gst_structure_free (config);
|
2015-08-16 17:08:16 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2012-06-15 14:37:19 +00:00
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
/* configure */
|
|
|
|
if (!gst_buffer_pool_set_config (pool, config)) {
|
|
|
|
gboolean working_pool = FALSE;
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
2012-06-15 14:37:19 +00:00
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
if (gst_buffer_pool_config_validate_params (config, state->caps, size, min,
|
|
|
|
max)) {
|
|
|
|
working_pool = gst_buffer_pool_set_config (pool, config);
|
2015-10-02 10:49:35 +00:00
|
|
|
} else {
|
|
|
|
gst_structure_free (config);
|
2012-06-15 14:37:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
if (!working_pool) {
|
|
|
|
gst_object_unref (pool);
|
|
|
|
pool = gst_video_buffer_pool_new ();
|
|
|
|
config = gst_buffer_pool_get_config (pool);
|
|
|
|
gst_buffer_pool_config_set_params (config, state->caps, size, min, max);
|
|
|
|
gst_buffer_pool_config_set_allocator (config, NULL, ¶ms);
|
|
|
|
gst_buffer_pool_set_config (pool, config);
|
|
|
|
update_pool = TRUE;
|
|
|
|
}
|
2012-06-15 14:37:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 17:08:16 +00:00
|
|
|
done:
|
2012-06-15 14:37:19 +00:00
|
|
|
/* and store */
|
2014-03-27 22:53:53 +00:00
|
|
|
if (update_pool)
|
|
|
|
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
|
|
|
|
|
2012-06-15 14:37:19 +00:00
|
|
|
gst_object_unref (pool);
|
2012-08-08 13:59:59 +00:00
|
|
|
if (allocator)
|
|
|
|
gst_object_unref (allocator);
|
2012-06-15 14:37:19 +00:00
|
|
|
gst_video_codec_state_unref (state);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_ffmpegviddec_propose_allocation (GstVideoDecoder * decoder,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
GstAllocationParams params;
|
|
|
|
|
|
|
|
gst_allocation_params_init (¶ms);
|
|
|
|
params.flags = GST_MEMORY_FLAG_ZERO_PADDED;
|
2015-08-16 17:08:16 +00:00
|
|
|
params.align = DEFAULT_STRIDE_ALIGN;
|
2018-04-30 19:41:40 +00:00
|
|
|
params.padding = AV_INPUT_BUFFER_PADDING_SIZE;
|
2012-06-15 14:37:19 +00:00
|
|
|
/* we would like to have some padding so that we don't have to
|
|
|
|
* memcpy. We don't suggest an allocator. */
|
|
|
|
gst_query_add_allocation_param (query, NULL, ¶ms);
|
|
|
|
|
|
|
|
return GST_VIDEO_DECODER_CLASS (parent_class)->propose_allocation (decoder,
|
|
|
|
query);
|
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegviddec_set_property (GObject * object,
|
2012-04-07 08:36:04 +00:00
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec = GST_FFMPEGVIDDEC (object);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_LOWRES:
|
|
|
|
ffmpegdec->lowres = ffmpegdec->context->lowres = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_SKIPFRAME:
|
|
|
|
ffmpegdec->skip_frame = ffmpegdec->context->skip_frame =
|
|
|
|
g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_DIRECT_RENDERING:
|
|
|
|
ffmpegdec->direct_rendering = g_value_get_boolean (value);
|
|
|
|
break;
|
2021-04-12 23:45:41 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2012-04-07 08:36:04 +00:00
|
|
|
case PROP_DEBUG_MV:
|
2021-04-12 23:45:41 +00:00
|
|
|
/* non-functional */
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
2021-04-12 23:45:41 +00:00
|
|
|
#endif
|
2012-04-07 08:36:04 +00:00
|
|
|
case PROP_MAX_THREADS:
|
|
|
|
ffmpegdec->max_threads = g_value_get_int (value);
|
|
|
|
break;
|
2014-01-17 20:38:23 +00:00
|
|
|
case PROP_OUTPUT_CORRUPT:
|
|
|
|
ffmpegdec->output_corrupt = g_value_get_boolean (value);
|
|
|
|
break;
|
2018-10-06 09:51:58 +00:00
|
|
|
case PROP_THREAD_TYPE:
|
|
|
|
ffmpegdec->thread_type = g_value_get_flags (value);
|
|
|
|
break;
|
2022-11-01 13:35:11 +00:00
|
|
|
case PROP_STD_COMPLIANCE:
|
|
|
|
ffmpegdec->std_compliance = g_value_get_enum (value);
|
|
|
|
break;
|
2012-04-07 08:36:04 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegviddec_get_property (GObject * object,
|
2012-04-07 08:36:04 +00:00
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2022-11-01 15:13:23 +00:00
|
|
|
GstFFMpegVidDec *ffmpegdec = GST_FFMPEGVIDDEC (object);
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_LOWRES:
|
2022-01-16 17:33:47 +00:00
|
|
|
g_value_set_enum (value, ffmpegdec->lowres);
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_SKIPFRAME:
|
2022-01-16 17:33:47 +00:00
|
|
|
g_value_set_enum (value, ffmpegdec->skip_frame);
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_DIRECT_RENDERING:
|
|
|
|
g_value_set_boolean (value, ffmpegdec->direct_rendering);
|
|
|
|
break;
|
2021-04-12 23:45:41 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2012-04-07 08:36:04 +00:00
|
|
|
case PROP_DEBUG_MV:
|
2021-04-12 23:45:41 +00:00
|
|
|
g_value_set_boolean (value, FALSE);
|
2012-04-07 08:36:04 +00:00
|
|
|
break;
|
2021-04-12 23:45:41 +00:00
|
|
|
#endif
|
2012-04-07 08:36:04 +00:00
|
|
|
case PROP_MAX_THREADS:
|
|
|
|
g_value_set_int (value, ffmpegdec->max_threads);
|
|
|
|
break;
|
2014-01-17 20:38:23 +00:00
|
|
|
case PROP_OUTPUT_CORRUPT:
|
|
|
|
g_value_set_boolean (value, ffmpegdec->output_corrupt);
|
|
|
|
break;
|
2018-10-06 09:51:58 +00:00
|
|
|
case PROP_THREAD_TYPE:
|
|
|
|
g_value_set_flags (value, ffmpegdec->thread_type);
|
|
|
|
break;
|
2022-11-01 13:35:11 +00:00
|
|
|
case PROP_STD_COMPLIANCE:
|
|
|
|
g_value_set_enum (value, ffmpegdec->std_compliance);
|
|
|
|
break;
|
2012-04-07 08:36:04 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-04-07 09:14:45 +00:00
|
|
|
gst_ffmpegviddec_register (GstPlugin * plugin)
|
2012-04-07 08:36:04 +00:00
|
|
|
{
|
|
|
|
GTypeInfo typeinfo = {
|
2012-04-07 09:14:45 +00:00
|
|
|
sizeof (GstFFMpegVidDecClass),
|
2012-04-07 08:36:04 +00:00
|
|
|
NULL,
|
2022-11-01 15:13:23 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_ffmpegviddec_subclass_init,
|
2012-04-07 08:36:04 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2012-04-07 09:14:45 +00:00
|
|
|
sizeof (GstFFMpegVidDec),
|
2012-04-07 08:36:04 +00:00
|
|
|
0,
|
2022-11-01 15:13:23 +00:00
|
|
|
(GInstanceInitFunc) gst_ffmpegviddec_subinit,
|
2012-04-07 08:36:04 +00:00
|
|
|
};
|
|
|
|
GType type;
|
|
|
|
AVCodec *in_plugin;
|
|
|
|
gint rank;
|
2018-06-29 19:20:36 +00:00
|
|
|
void *i = 0;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
|
|
|
GST_LOG ("Registering decoders");
|
|
|
|
|
2018-06-29 19:20:36 +00:00
|
|
|
while ((in_plugin = (AVCodec *) av_codec_iterate (&i))) {
|
2012-04-07 08:36:04 +00:00
|
|
|
gchar *type_name;
|
|
|
|
gchar *plugin_name;
|
|
|
|
|
2012-09-29 23:27:10 +00:00
|
|
|
/* only video decoders */
|
2012-12-05 09:52:34 +00:00
|
|
|
if (!av_codec_is_decoder (in_plugin)
|
|
|
|
|| in_plugin->type != AVMEDIA_TYPE_VIDEO)
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2012-04-07 08:36:04 +00:00
|
|
|
|
2016-07-22 11:54:21 +00:00
|
|
|
/* no quasi codecs, please */
|
2013-05-06 22:56:22 +00:00
|
|
|
if (in_plugin->id == AV_CODEC_ID_RAWVIDEO ||
|
|
|
|
in_plugin->id == AV_CODEC_ID_V210 ||
|
|
|
|
in_plugin->id == AV_CODEC_ID_V210X ||
|
2016-07-22 11:54:21 +00:00
|
|
|
in_plugin->id == AV_CODEC_ID_V308 ||
|
|
|
|
in_plugin->id == AV_CODEC_ID_V408 ||
|
|
|
|
in_plugin->id == AV_CODEC_ID_V410 ||
|
|
|
|
in_plugin->id == AV_CODEC_ID_R210
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_AYUV
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_Y41P
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_012V
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_YUV4
|
2016-09-02 15:55:46 +00:00
|
|
|
#if AV_VERSION_INT (LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO) >= \
|
|
|
|
AV_VERSION_INT (57,4,0)
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_WRAPPED_AVFRAME
|
|
|
|
#endif
|
|
|
|
|| in_plugin->id == AV_CODEC_ID_ZLIB) {
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No decoders depending on external libraries (we don't build them, but
|
|
|
|
* people who build against an external ffmpeg might have them.
|
|
|
|
* We have native gstreamer plugins for all of those libraries anyway. */
|
|
|
|
if (!strncmp (in_plugin->name, "lib", 3)) {
|
|
|
|
GST_DEBUG
|
|
|
|
("Not using external library decoder %s. Use the gstreamer-native ones instead.",
|
|
|
|
in_plugin->name);
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 16:09:08 +00:00
|
|
|
/* Skip hardware or hybrid (hardware with software fallback) */
|
|
|
|
if ((in_plugin->capabilities & AV_CODEC_CAP_HARDWARE) ==
|
|
|
|
AV_CODEC_CAP_HARDWARE) {
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_DEBUG
|
2019-10-24 16:09:08 +00:00
|
|
|
("Ignoring hardware decoder %s. We can't handle this outside of ffmpeg",
|
2012-04-07 08:36:04 +00:00
|
|
|
in_plugin->name);
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 16:09:08 +00:00
|
|
|
if ((in_plugin->capabilities & AV_CODEC_CAP_HYBRID) == AV_CODEC_CAP_HYBRID) {
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_DEBUG
|
2019-10-24 16:09:08 +00:00
|
|
|
("Ignoring hybrid decoder %s. We can't handle this outside of ffmpeg",
|
2012-04-07 08:36:04 +00:00
|
|
|
in_plugin->name);
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 16:09:08 +00:00
|
|
|
/* No vdpau plugins until we can figure out how to properly use them
|
|
|
|
* outside of ffmpeg. */
|
|
|
|
if (g_str_has_suffix (in_plugin->name, "_vdpau")) {
|
2016-07-22 11:42:59 +00:00
|
|
|
GST_DEBUG
|
2019-10-24 16:09:08 +00:00
|
|
|
("Ignoring VDPAU decoder %s. We can't handle this outside of ffmpeg",
|
2016-07-22 11:42:59 +00:00
|
|
|
in_plugin->name);
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2016-07-22 11:42:59 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 16:09:08 +00:00
|
|
|
if (g_str_has_suffix (in_plugin->name, "_xvmc")) {
|
2016-11-11 16:03:00 +00:00
|
|
|
GST_DEBUG
|
2019-10-24 16:09:08 +00:00
|
|
|
("Ignoring XVMC decoder %s. We can't handle this outside of ffmpeg",
|
2016-11-11 16:03:00 +00:00
|
|
|
in_plugin->name);
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2016-11-11 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 16:09:08 +00:00
|
|
|
if (strstr (in_plugin->name, "vaapi")) {
|
2017-05-16 15:54:32 +00:00
|
|
|
GST_DEBUG
|
2019-10-24 16:09:08 +00:00
|
|
|
("Ignoring VAAPI decoder %s. We can't handle this outside of ffmpeg",
|
2017-05-16 15:54:32 +00:00
|
|
|
in_plugin->name);
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2017-05-16 15:54:32 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 16:09:08 +00:00
|
|
|
if (g_str_has_suffix (in_plugin->name, "_qsv")) {
|
2018-02-10 14:18:11 +00:00
|
|
|
GST_DEBUG
|
2019-10-24 16:09:08 +00:00
|
|
|
("Ignoring qsv decoder %s. We can't handle this outside of ffmpeg",
|
2018-02-10 14:18:11 +00:00
|
|
|
in_plugin->name);
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2018-02-10 14:18:11 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_DEBUG ("Trying plugin %s [%s]", in_plugin->name, in_plugin->long_name);
|
|
|
|
|
|
|
|
/* no codecs for which we're GUARANTEED to have better alternatives */
|
|
|
|
/* MPEG1VIDEO : the mpeg2video decoder is preferred */
|
|
|
|
/* MP1 : Use MP3 for decoding */
|
|
|
|
/* MP2 : Use MP3 for decoding */
|
|
|
|
/* Theora: Use libtheora based theoradec */
|
2019-05-29 06:19:38 +00:00
|
|
|
/* CDG: use cdgdec */
|
2022-12-20 12:10:01 +00:00
|
|
|
/* AV1: Use av1dec, dav1ddec or any of the hardware decoders.
|
|
|
|
* Also ffmpeg's decoder only works with hardware support!
|
|
|
|
*/
|
2017-06-13 16:50:50 +00:00
|
|
|
if (!strcmp (in_plugin->name, "theora") ||
|
2012-04-07 08:36:04 +00:00
|
|
|
!strcmp (in_plugin->name, "mpeg1video") ||
|
2012-09-07 16:56:43 +00:00
|
|
|
strstr (in_plugin->name, "crystalhd") != NULL ||
|
2012-04-07 08:36:04 +00:00
|
|
|
!strcmp (in_plugin->name, "ass") ||
|
|
|
|
!strcmp (in_plugin->name, "srt") ||
|
|
|
|
!strcmp (in_plugin->name, "pgssub") ||
|
|
|
|
!strcmp (in_plugin->name, "dvdsub") ||
|
2019-05-29 06:19:38 +00:00
|
|
|
!strcmp (in_plugin->name, "dvbsub") ||
|
2022-12-20 12:10:01 +00:00
|
|
|
!strcmp (in_plugin->name, "cdgraphics") ||
|
|
|
|
!strcmp (in_plugin->name, "av1")) {
|
2012-04-07 08:36:04 +00:00
|
|
|
GST_LOG ("Ignoring decoder %s", in_plugin->name);
|
2018-06-29 19:20:36 +00:00
|
|
|
continue;
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* construct the type */
|
2014-02-20 19:39:29 +00:00
|
|
|
if (!strcmp (in_plugin->name, "hevc")) {
|
|
|
|
plugin_name = g_strdup ("h265");
|
|
|
|
} else {
|
|
|
|
plugin_name = g_strdup ((gchar *) in_plugin->name);
|
|
|
|
}
|
2012-04-07 08:36:04 +00:00
|
|
|
g_strdelimit (plugin_name, NULL, '_');
|
2012-06-15 13:18:47 +00:00
|
|
|
type_name = g_strdup_printf ("avdec_%s", plugin_name);
|
2012-04-07 08:36:04 +00:00
|
|
|
g_free (plugin_name);
|
|
|
|
|
|
|
|
type = g_type_from_name (type_name);
|
|
|
|
|
|
|
|
if (!type) {
|
|
|
|
/* create the gtype now */
|
2022-11-01 15:13:23 +00:00
|
|
|
typeinfo.class_data = in_plugin;
|
2012-04-18 10:37:53 +00:00
|
|
|
type =
|
2022-11-01 15:13:23 +00:00
|
|
|
g_type_register_static (GST_TYPE_FFMPEGVIDDEC, type_name, &typeinfo,
|
2012-04-18 10:37:53 +00:00
|
|
|
0);
|
2012-04-07 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (Ronald) MPEG-4 gets a higher priority because it has been well-
|
|
|
|
* tested and by far outperforms divxdec/xviddec - so we prefer it.
|
2022-03-29 07:36:06 +00:00
|
|
|
* msmpeg4v3 same, as it outperforms divxdec for divx3 playback. */
|
2012-04-07 08:36:04 +00:00
|
|
|
switch (in_plugin->id) {
|
2016-01-21 16:35:51 +00:00
|
|
|
case AV_CODEC_ID_MPEG1VIDEO:
|
|
|
|
case AV_CODEC_ID_MPEG2VIDEO:
|
2013-05-06 22:56:22 +00:00
|
|
|
case AV_CODEC_ID_MPEG4:
|
|
|
|
case AV_CODEC_ID_MSMPEG4V3:
|
|
|
|
case AV_CODEC_ID_H264:
|
2014-01-06 12:36:39 +00:00
|
|
|
case AV_CODEC_ID_HEVC:
|
2013-05-06 22:56:22 +00:00
|
|
|
case AV_CODEC_ID_RV10:
|
|
|
|
case AV_CODEC_ID_RV20:
|
|
|
|
case AV_CODEC_ID_RV30:
|
|
|
|
case AV_CODEC_ID_RV40:
|
2012-04-07 08:36:04 +00:00
|
|
|
rank = GST_RANK_PRIMARY;
|
|
|
|
break;
|
|
|
|
/* DVVIDEO: we have a good dv decoder, fast on both ppc as well as x86.
|
|
|
|
* They say libdv's quality is better though. leave as secondary.
|
|
|
|
* note: if you change this, see the code in gstdv.c in good/ext/dv.
|
|
|
|
*/
|
2013-05-06 22:56:22 +00:00
|
|
|
case AV_CODEC_ID_DVVIDEO:
|
2012-04-07 08:36:04 +00:00
|
|
|
rank = GST_RANK_SECONDARY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rank = GST_RANK_MARGINAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!gst_element_register (plugin, type_name, rank, type)) {
|
|
|
|
g_warning ("Failed to register %s", type_name);
|
|
|
|
g_free (type_name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (type_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_LOG ("Finished Registering decoders");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|