zed: update to 0.172.9
[aosc-os-abbs.git] / app-i18n / goldendict / autobuild / patches / 0003-add-support-for-ffmpeg-7.0.patch
blob3f1018dcfcd34719b39e5ee60cc4438a72cb1b8e
1 From 381e2a59815cbd54a4544189e522f6731036b6dd Mon Sep 17 00:00:00 2001
2 From: Liao Junxuan <mikeljx@126.com>
3 Date: Fri, 28 Jun 2024 18:06:13 +0800
4 Subject: [PATCH 3/3] add support for ffmpeg 7.0
6 FF_API_OLD_CHANNEL_LAYOUT is removed in libavcodec 61.
7 See https://patchwork.ffmpeg.org/project/ffmpeg/cover/20240125134425.374-1-jamrial@gmail.com/ .
8 ---
9 ffmpegaudio.cc | 33 ++++++++++++++++++++++++++++-----
10 1 file changed, 28 insertions(+), 5 deletions(-)
12 diff --git a/ffmpegaudio.cc b/ffmpegaudio.cc
13 index a97d6dca..5ef602ad 100644
14 --- a/ffmpegaudio.cc
15 +++ b/ffmpegaudio.cc
16 @@ -118,6 +118,13 @@ struct DecoderContext
17 bool play( QString & errorString );
18 bool normalizeAudio( AVFrame * frame, vector<char> & samples );
19 void playFrame( AVFrame * frame );
20 + int nbChannels() {
21 +#if LIBAVCODEC_VERSION_MAJOR >= 61
22 + return codecContext_->ch_layout.nb_channels;
23 +#else
24 + return codecContext_->channels;
25 +#endif
26 + }
29 DecoderContext::DecoderContext( QByteArray const & audioData, QAtomicInt & isCancelled ):
30 @@ -261,7 +268,7 @@ bool DecoderContext::openCodec( QString & errorString )
33 gdDebug( "Codec open: %s: channels: %d, rate: %d, format: %s\n", codec_->long_name,
34 - codecContext_->channels, codecContext_->sample_rate, av_get_sample_fmt_name( codecContext_->sample_fmt ) );
35 + nbChannels(), codecContext_->sample_rate, av_get_sample_fmt_name( codecContext_->sample_fmt ) );
37 if ( codecContext_->sample_fmt == AV_SAMPLE_FMT_S32 ||
38 codecContext_->sample_fmt == AV_SAMPLE_FMT_S32P ||
39 @@ -270,6 +277,21 @@ bool DecoderContext::openCodec( QString & errorString )
40 codecContext_->sample_fmt == AV_SAMPLE_FMT_DBL ||
41 codecContext_->sample_fmt == AV_SAMPLE_FMT_DBLP )
43 +#if LIBAVCODEC_VERSION_MAJOR >= 61
44 + int ret = swr_alloc_set_opts2( &swr_,
45 + &codecContext_->ch_layout,
46 + AV_SAMPLE_FMT_S16,
47 + codecContext_->sample_rate,
48 + &codecContext_->ch_layout,
49 + codecContext_->sample_fmt,
50 + codecContext_->sample_rate,
51 + 0,
52 + NULL );
53 + if ( ret < 0 ) {
54 + errorString = QObject::tr( "swr_alloc_set_opts2() failed: %1." ).arg( avErrorString( ret ) );
55 + return false;
56 + }
57 +#else
58 swr_ = swr_alloc_set_opts( NULL,
59 codecContext_->channel_layout,
60 AV_SAMPLE_FMT_S16,
61 @@ -279,6 +301,7 @@ bool DecoderContext::openCodec( QString & errorString )
62 codecContext_->sample_rate,
64 NULL );
65 +#endif
66 swr_init( swr_ );
69 @@ -351,7 +374,7 @@ bool DecoderContext::openOutputDevice( QString & errorString )
71 ao_sample_format aoSampleFormat;
72 memset (&aoSampleFormat, 0, sizeof(aoSampleFormat) );
73 - aoSampleFormat.channels = codecContext_->channels;
74 + aoSampleFormat.channels = nbChannels();
75 aoSampleFormat.rate = codecContext_->sample_rate;
76 aoSampleFormat.byte_format = AO_FMT_NATIVE;
77 aoSampleFormat.matrix = 0;
78 @@ -520,7 +543,7 @@ static inline int32_t toInt32( double v )
79 bool DecoderContext::normalizeAudio( AVFrame * frame, vector<char> & samples )
81 int lineSize = 0;
82 - int dataSize = av_samples_get_buffer_size( &lineSize, codecContext_->channels,
83 + int dataSize = av_samples_get_buffer_size( &lineSize, nbChannels(),
84 frame->nb_samples, codecContext_->sample_fmt, 1 );
86 // Portions from: https://code.google.com/p/lavfilters/source/browse/decoder/LAVAudio/LAVAudio.cpp
87 @@ -542,7 +565,7 @@ bool DecoderContext::normalizeAudio( AVFrame * frame, vector<char> & samples )
88 uint8_t * out = ( uint8_t * )&samples.front();
89 for ( int i = 0; i < frame->nb_samples; i++ )
91 - for ( int ch = 0; ch < codecContext_->channels; ch++ )
92 + for ( int ch = 0; ch < nbChannels(); ch++ )
94 *out++ = ( ( uint8_t * )frame->extended_data[ch] )[i];
96 @@ -556,7 +579,7 @@ bool DecoderContext::normalizeAudio( AVFrame * frame, vector<char> & samples )
97 int16_t * out = ( int16_t * )&samples.front();
98 for ( int i = 0; i < frame->nb_samples; i++ )
100 - for ( int ch = 0; ch < codecContext_->channels; ch++ )
101 + for ( int ch = 0; ch < nbChannels(); ch++ )
103 *out++ = ( ( int16_t * )frame->extended_data[ch] )[i];
106 2.46.0