Skip to content

Commit 0ce73c8

Browse files
committed
Fixup: Fix building with system ffmpeg
System FFmpeg contains multiple codecs for mp3 and uses whatever it finds first. Chromium only supports one, and not aware of others. Force the supported codec for mp3 decoding. Fixes: QTBUG-130273 Change-Id: Ic25ae719ee0490426ddac8df7544dff04fc0b255 Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/599610 Reviewed-by: Allan Sandfeld Jensen <[email protected]> (cherry picked from commit 3b9f0ed) Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/600431 Reviewed-by: Qt Cherry-pick Bot <[email protected]>
1 parent 287cf99 commit 0ce73c8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

chromium/media/filters/ffmpeg_audio_decoder.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ bool FFmpegAudioDecoder::ConfigureDecoder(const AudioDecoderConfig& config) {
368368
const AVCodec* codec = [&config, this]() {
369369
if (config.codec() == AudioCodec::kOpus)
370370
return avcodec_find_decoder_by_name("libopus");
371+
if (config.codec() == AudioCodec::kMP3) {
372+
return avcodec_find_decoder_by_name("mp3");
373+
}
371374
return avcodec_find_decoder(codec_context_->codec_id);
372375
}();
373376
#else

chromium/media/filters/ffmpeg_glue.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,24 @@ bool FFmpegGlue::OpenContext(bool is_local_file) {
246246
CHECK_NE(container_, container_names::MediaContainerName::kContainerUnknown);
247247
LogContainer(is_local_file, container_);
248248

249+
#if BUILDFLAG(IS_QTWEBENGINE) && BUILDFLAG(USE_SYSTEM_FFMPEG)
250+
// Sometimes FFmpeg is not aware of the whitelisted codecs and
251+
// configures streams and demuxers with unsupported codecs/params.
252+
// Force the correct codecs to avoid problems later.
253+
// https://ffmpeg.org/doxygen/7.0/structAVFormatContext.html#a52f39351b15890ef57cc6ff0ec9ab42d
254+
// https://ffmpeg.org/doxygen/7.0/structAVFormatContext.html#ae5e087f4623b907517c0f7dd8327387d
255+
256+
// Note: don't forget to update FFmpeg[Audio|Video]Decoder::ConfigureDecoder
257+
258+
if (strcmp(format_context_->iformat->name, "mp3") == 0) {
259+
const AVCodec* mp3_codec = avcodec_find_decoder_by_name("mp3");
260+
if (mp3_codec) {
261+
format_context_->audio_codec = mp3_codec;
262+
} else {
263+
LOG(ERROR) << "No supported codec for mp3";
264+
}
265+
}
266+
#endif
249267
return true;
250268
}
251269

0 commit comments

Comments
 (0)