archrelease: copy trunk to extra-x86_64
[arch-packages.git] / chromaprint / repos / extra-x86_64 / ffmpeg5.patch
blobd90767fd14cff5f08e5ed2953f1211ab2fd48012
1 From 6d938d70b1d52634f8b0d88cb29da87f8d5b35a2 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Bernhard=20Rosenkr=C3=A4nzer?= <bero@lindev.ch>
3 Date: Mon, 17 Jan 2022 04:41:33 +0100
4 Subject: [PATCH] Port to ffmpeg 5.0
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Replace removed functionality like accessing the codec context
10 from an AVStream and avcodec_decode_audio4()
12 Signed-off-by: Bernhard Rosenkränzer <bero@lindev.ch>
13 ---
14 src/audio/ffmpeg_audio_reader.h | 24 ++++++++++++++++++++++--
15 1 file changed, 22 insertions(+), 2 deletions(-)
17 diff --git a/src/audio/ffmpeg_audio_reader.h b/src/audio/ffmpeg_audio_reader.h
18 index 5550164..a3b8de7 100644
19 --- a/src/audio/ffmpeg_audio_reader.h
20 +++ b/src/audio/ffmpeg_audio_reader.h
21 @@ -74,7 +74,7 @@ class FFmpegAudioReader {
22 uint8_t *m_convert_buffer[1] = { nullptr };
23 int m_convert_buffer_nb_samples = 0;
25 - AVInputFormat *m_input_fmt = nullptr;
26 + const AVInputFormat *m_input_fmt = nullptr;
27 AVDictionary *m_input_opts = nullptr;
29 AVFormatContext *m_format_ctx = nullptr;
30 @@ -153,7 +153,7 @@ inline bool FFmpegAudioReader::Open(const std::string &file_name) {
31 return false;
34 - AVCodec *codec;
35 + const AVCodec *codec;
36 ret = av_find_best_stream(m_format_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, &codec, 0);
37 if (ret < 0) {
38 SetError("Could not find any audio stream in the file", ret);
39 @@ -161,7 +161,13 @@ inline bool FFmpegAudioReader::Open(const std::string &file_name) {
41 m_stream_index = ret;
43 +#if LIBAVCODEC_VERSION_MAJOR >= 59
44 + const AVCodec *streamcodec = avcodec_find_decoder(m_format_ctx->streams[m_stream_index]->codecpar->codec_id);
45 + m_codec_ctx = avcodec_alloc_context3(streamcodec);
46 + avcodec_parameters_to_context(m_codec_ctx, m_format_ctx->streams[m_stream_index]->codecpar);
47 +#else
48 m_codec_ctx = m_format_ctx->streams[m_stream_index]->codec;
49 +#endif
50 m_codec_ctx->request_sample_fmt = AV_SAMPLE_FMT_S16;
52 ret = avcodec_open2(m_codec_ctx, codec, nullptr);
53 @@ -278,7 +284,23 @@ inline bool FFmpegAudioReader::Read(const int16_t **data, size_t *size) {
57 +#if LIBAVCODEC_VERSION_MAJOR < 59
58 ret = avcodec_decode_audio4(m_codec_ctx, m_frame, &m_got_frame, &m_packet);
59 +#else
60 + m_got_frame = 0;
61 + ret = avcodec_send_packet(m_codec_ctx, &m_packet);
62 + if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
63 + ret = 0;
64 + if(ret >= 0) {
65 + ret = avcodec_receive_frame(m_codec_ctx, m_frame);
66 + if (ret == 0) {
67 + m_got_frame = 1;
68 + ret = m_packet.size;
69 + }
70 + }
71 + if(ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
72 + ret = 0;
73 +#endif
74 if (ret < 0) {
75 if (m_decode_error) {
76 SetError("Error decoding audio frame", m_decode_error);