blob: 022ff9af2909c79e0137aef330a13caaecdfd560 [file] [log] [blame]
From 38d10ee800e42afeacc6bee714216e4c974c11f5 Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@mengyan1223.wang>
Date: Mon, 17 Jan 2022 01:33:47 +0800
Subject: [PATCH] gst-libav: fix build with ffmpeg-5.0.0
Latest ffmpeg has removed avcodec_get_context_defaults(), and its
documentation says a new AVCodecContext should be allocated for this
purpose. The pointer returned by avcodec_find_decoder() is now
const-qualified so we also need to adjust for it. And, AVCOL_RANGE_MPEG
is now rejected with strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1531>
Upstream-Status: Backport
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
ext/libav/gstavauddec.c | 22 ++++++++-------------
ext/libav/gstavaudenc.c | 40 +++++++++++++++++++--------------------
ext/libav/gstavcodecmap.c | 7 ++++---
ext/libav/gstavutils.c | 2 +-
ext/libav/gstavviddec.c | 28 +++++++++++----------------
ext/libav/gstavvidenc.c | 21 ++++++++++----------
6 files changed, 54 insertions(+), 66 deletions(-)
diff --git a/ext/libav/gstavauddec.c b/ext/libav/gstavauddec.c
index baf7aa5..b03a724 100644
--- a/ext/libav/gstavauddec.c
+++ b/ext/libav/gstavauddec.c
@@ -168,12 +168,7 @@ gst_ffmpegauddec_finalize (GObject * object)
GstFFMpegAudDec *ffmpegdec = (GstFFMpegAudDec *) object;
av_frame_free (&ffmpegdec->frame);
-
- if (ffmpegdec->context != NULL) {
- gst_ffmpeg_avcodec_close (ffmpegdec->context);
- av_free (ffmpegdec->context);
- ffmpegdec->context = NULL;
- }
+ avcodec_free_context (&ffmpegdec->context);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -193,14 +188,12 @@ gst_ffmpegauddec_close (GstFFMpegAudDec * ffmpegdec, gboolean reset)
gst_ffmpeg_avcodec_close (ffmpegdec->context);
ffmpegdec->opened = FALSE;
- if (ffmpegdec->context->extradata) {
- av_free (ffmpegdec->context->extradata);
- ffmpegdec->context->extradata = NULL;
- }
+ av_freep (&ffmpegdec->context->extradata);
if (reset) {
- if (avcodec_get_context_defaults3 (ffmpegdec->context,
- oclass->in_plugin) < 0) {
+ avcodec_free_context (&ffmpegdec->context);
+ ffmpegdec->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegdec->context == NULL) {
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
return FALSE;
}
@@ -219,8 +212,9 @@ gst_ffmpegauddec_start (GstAudioDecoder * decoder)
oclass = (GstFFMpegAudDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
GST_OBJECT_LOCK (ffmpegdec);
- gst_ffmpeg_avcodec_close (ffmpegdec->context);
- if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) {
+ avcodec_free_context (&ffmpegdec->context);
+ ffmpegdec->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegdec->context == NULL) {
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
GST_OBJECT_UNLOCK (ffmpegdec);
return FALSE;
diff --git a/ext/libav/gstavaudenc.c b/ext/libav/gstavaudenc.c
index 3ff6432..689982f 100644
--- a/ext/libav/gstavaudenc.c
+++ b/ext/libav/gstavaudenc.c
@@ -175,10 +175,8 @@ gst_ffmpegaudenc_finalize (GObject * object)
/* clean up remaining allocated data */
av_frame_free (&ffmpegaudenc->frame);
- gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
- gst_ffmpeg_avcodec_close (ffmpegaudenc->refcontext);
- av_free (ffmpegaudenc->context);
- av_free (ffmpegaudenc->refcontext);
+ avcodec_free_context (&ffmpegaudenc->context);
+ avcodec_free_context (&ffmpegaudenc->refcontext);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -193,9 +191,9 @@ gst_ffmpegaudenc_start (GstAudioEncoder * encoder)
ffmpegaudenc->opened = FALSE;
ffmpegaudenc->need_reopen = FALSE;
- gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
- if (avcodec_get_context_defaults3 (ffmpegaudenc->context,
- oclass->in_plugin) < 0) {
+ avcodec_free_context (&ffmpegaudenc->context);
+ ffmpegaudenc->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegaudenc->context == NULL) {
GST_DEBUG_OBJECT (ffmpegaudenc, "Failed to set context defaults");
return FALSE;
}
@@ -241,10 +239,10 @@ gst_ffmpegaudenc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
/* close old session */
if (ffmpegaudenc->opened) {
- gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
+ avcodec_free_context (&ffmpegaudenc->context);
ffmpegaudenc->opened = FALSE;
- if (avcodec_get_context_defaults3 (ffmpegaudenc->context,
- oclass->in_plugin) < 0) {
+ ffmpegaudenc->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegaudenc->context == NULL) {
GST_DEBUG_OBJECT (ffmpegaudenc, "Failed to set context defaults");
return FALSE;
}
@@ -286,11 +284,11 @@ gst_ffmpegaudenc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
/* open codec */
if (gst_ffmpeg_avcodec_open (ffmpegaudenc->context, oclass->in_plugin) < 0) {
gst_caps_unref (allowed_caps);
- gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
+ avcodec_free_context (&ffmpegaudenc->context);
GST_DEBUG_OBJECT (ffmpegaudenc, "avenc_%s: Failed to open FFMPEG codec",
oclass->in_plugin->name);
- if (avcodec_get_context_defaults3 (ffmpegaudenc->context,
- oclass->in_plugin) < 0)
+ ffmpegaudenc->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegaudenc->context == NULL)
GST_DEBUG_OBJECT (ffmpegaudenc, "Failed to set context defaults");
if ((oclass->in_plugin->capabilities & AV_CODEC_CAP_EXPERIMENTAL) &&
@@ -312,10 +310,10 @@ gst_ffmpegaudenc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
if (!other_caps) {
gst_caps_unref (allowed_caps);
- gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
+ avcodec_free_context (&ffmpegaudenc->context);
GST_DEBUG ("Unsupported codec - no caps found");
- if (avcodec_get_context_defaults3 (ffmpegaudenc->context,
- oclass->in_plugin) < 0)
+ ffmpegaudenc->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegaudenc->context == NULL)
GST_DEBUG_OBJECT (ffmpegaudenc, "Failed to set context defaults");
return FALSE;
}
@@ -331,10 +329,10 @@ gst_ffmpegaudenc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
if (!gst_audio_encoder_set_output_format (GST_AUDIO_ENCODER (ffmpegaudenc),
icaps)) {
- gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
+ avcodec_free_context (&ffmpegaudenc->context);
gst_caps_unref (icaps);
- if (avcodec_get_context_defaults3 (ffmpegaudenc->context,
- oclass->in_plugin) < 0)
+ ffmpegaudenc->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegaudenc->context == NULL)
GST_DEBUG_OBJECT (ffmpegaudenc, "Failed to set context defaults");
return FALSE;
}
@@ -403,8 +401,8 @@ buffer_info_free (void *opaque, guint8 * data)
gst_buffer_unmap (info->buffer, &info->map);
gst_buffer_unref (info->buffer);
} else {
- av_free (info->ext_data);
- av_free (info->ext_data_array);
+ av_freep (&info->ext_data);
+ av_freep (&info->ext_data_array);
}
g_slice_free (BufferInfo, info);
}
diff --git a/ext/libav/gstavcodecmap.c b/ext/libav/gstavcodecmap.c
index f58633d..e2a3641 100644
--- a/ext/libav/gstavcodecmap.c
+++ b/ext/libav/gstavcodecmap.c
@@ -2331,7 +2331,7 @@ gst_ffmpeg_codecid_to_caps (enum AVCodecID codec_id,
}
if (buildcaps) {
- AVCodec *codec;
+ const AVCodec *codec;
if ((codec = avcodec_find_decoder (codec_id)) ||
(codec = avcodec_find_encoder (codec_id))) {
@@ -2975,6 +2975,7 @@ gst_ffmpeg_videoinfo_to_context (GstVideoInfo * info, AVCodecContext * context)
context->color_range = AVCOL_RANGE_JPEG;
} else {
context->color_range = AVCOL_RANGE_MPEG;
+ context->strict_std_compliance = FF_COMPLIANCE_UNOFFICIAL;
}
}
@@ -4330,7 +4331,7 @@ gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
audio = TRUE;
} else if (!strncmp (mimetype, "audio/x-gst-av-", 15)) {
gchar ext[16];
- AVCodec *codec;
+ const AVCodec *codec;
if (strlen (mimetype) <= 30 &&
sscanf (mimetype, "audio/x-gst-av-%s", ext) == 1) {
@@ -4342,7 +4343,7 @@ gst_ffmpeg_caps_to_codecid (const GstCaps * caps, AVCodecContext * context)
}
} else if (!strncmp (mimetype, "video/x-gst-av-", 15)) {
gchar ext[16];
- AVCodec *codec;
+ const AVCodec *codec;
if (strlen (mimetype) <= 30 &&
sscanf (mimetype, "video/x-gst-av-%s", ext) == 1) {
diff --git a/ext/libav/gstavutils.c b/ext/libav/gstavutils.c
index 3780cff..f3878c3 100644
--- a/ext/libav/gstavutils.c
+++ b/ext/libav/gstavutils.c
@@ -36,7 +36,7 @@
const gchar *
gst_ffmpeg_get_codecid_longname (enum AVCodecID codec_id)
{
- AVCodec *codec;
+ const AVCodec *codec;
/* Let's use what ffmpeg can provide us */
if ((codec = avcodec_find_decoder (codec_id)) ||
diff --git a/ext/libav/gstavviddec.c b/ext/libav/gstavviddec.c
index 7ec5766..5dd207e 100644
--- a/ext/libav/gstavviddec.c
+++ b/ext/libav/gstavviddec.c
@@ -320,12 +320,7 @@ gst_ffmpegviddec_finalize (GObject * object)
GstFFMpegVidDec *ffmpegdec = (GstFFMpegVidDec *) object;
av_frame_free (&ffmpegdec->picture);
-
- if (ffmpegdec->context != NULL) {
- gst_ffmpeg_avcodec_close (ffmpegdec->context);
- av_free (ffmpegdec->context);
- ffmpegdec->context = NULL;
- }
+ avcodec_free_context (&ffmpegdec->context);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -363,13 +358,11 @@ gst_ffmpegviddec_close (GstFFMpegVidDec * ffmpegdec, gboolean reset)
gst_buffer_replace (&ffmpegdec->palette, NULL);
- if (ffmpegdec->context->extradata) {
- av_free (ffmpegdec->context->extradata);
- ffmpegdec->context->extradata = NULL;
- }
+ av_freep (&ffmpegdec->context->extradata);
if (reset) {
- if (avcodec_get_context_defaults3 (ffmpegdec->context,
- oclass->in_plugin) < 0) {
+ avcodec_free_context (&ffmpegdec->context);
+ ffmpegdec->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegdec->context == NULL) {
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
return FALSE;
}
@@ -1704,7 +1697,7 @@ gst_ffmpegviddec_video_frame (GstFFMpegVidDec * ffmpegdec,
if (side_data) {
GST_LOG_OBJECT (ffmpegdec,
"Found CC side data of type AV_FRAME_DATA_A53_CC, size %d",
- side_data->size);
+ (int) side_data->size);
GST_MEMDUMP ("A53 CC", side_data->data, side_data->size);
/* do not add closed caption meta if it already exists */
@@ -1966,8 +1959,9 @@ gst_ffmpegviddec_start (GstVideoDecoder * decoder)
oclass = (GstFFMpegVidDecClass *) (G_OBJECT_GET_CLASS (ffmpegdec));
GST_OBJECT_LOCK (ffmpegdec);
- gst_ffmpeg_avcodec_close (ffmpegdec->context);
- if (avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin) < 0) {
+ avcodec_free_context (&ffmpegdec->context);
+ ffmpegdec->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegdec->context == NULL) {
GST_DEBUG_OBJECT (ffmpegdec, "Failed to set context defaults");
GST_OBJECT_UNLOCK (ffmpegdec);
return FALSE;
@@ -2261,10 +2255,10 @@ gst_ffmpegviddec_get_property (GObject * object,
switch (prop_id) {
case PROP_LOWRES:
- g_value_set_enum (value, ffmpegdec->context->lowres);
+ g_value_set_enum (value, ffmpegdec->lowres);
break;
case PROP_SKIPFRAME:
- g_value_set_enum (value, ffmpegdec->context->skip_frame);
+ g_value_set_enum (value, ffmpegdec->skip_frame);
break;
case PROP_DIRECT_RENDERING:
g_value_set_boolean (value, ffmpegdec->direct_rendering);
diff --git a/ext/libav/gstavvidenc.c b/ext/libav/gstavvidenc.c
index 0468d88..2ed9e5a 100644
--- a/ext/libav/gstavvidenc.c
+++ b/ext/libav/gstavvidenc.c
@@ -224,8 +224,8 @@ gst_ffmpegvidenc_finalize (GObject * object)
av_frame_free (&ffmpegenc->picture);
gst_ffmpeg_avcodec_close (ffmpegenc->context);
gst_ffmpeg_avcodec_close (ffmpegenc->refcontext);
- av_free (ffmpegenc->context);
- av_free (ffmpegenc->refcontext);
+ av_freep (&ffmpegenc->context);
+ av_freep (&ffmpegenc->refcontext);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -247,10 +247,10 @@ gst_ffmpegvidenc_set_format (GstVideoEncoder * encoder,
/* close old session */
if (ffmpegenc->opened) {
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
+ avcodec_free_context (&ffmpegenc->context);
ffmpegenc->opened = FALSE;
- if (avcodec_get_context_defaults3 (ffmpegenc->context,
- oclass->in_plugin) < 0) {
+ ffmpegenc->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegenc->context == NULL) {
GST_DEBUG_OBJECT (ffmpegenc, "Failed to set context defaults");
return FALSE;
}
@@ -454,9 +454,9 @@ bad_input_fmt:
}
close_codec:
{
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
- if (avcodec_get_context_defaults3 (ffmpegenc->context,
- oclass->in_plugin) < 0)
+ avcodec_free_context (&ffmpegenc->context);
+ ffmpegenc->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegenc->context == NULL)
GST_DEBUG_OBJECT (ffmpegenc, "Failed to set context defaults");
goto cleanup_stats_in;
}
@@ -896,8 +896,9 @@ gst_ffmpegvidenc_start (GstVideoEncoder * encoder)
ffmpegenc->need_reopen = FALSE;
/* close old session */
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
- if (avcodec_get_context_defaults3 (ffmpegenc->context, oclass->in_plugin) < 0) {
+ avcodec_free_context (&ffmpegenc->context);
+ ffmpegenc->context = avcodec_alloc_context3 (oclass->in_plugin);
+ if (ffmpegenc->context == NULL) {
GST_DEBUG_OBJECT (ffmpegenc, "Failed to set context defaults");
return FALSE;
}