qtwebengine-fix-building-with-system-ffmpeg.patch 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. From 6e554a30893150793c2638e3689cf208ffc8e375 Mon Sep 17 00:00:00 2001
  2. From: Dale Curtis <dalecurtis@chromium.org>
  3. Date: Sat, 2 Apr 2022 05:13:53 +0000
  4. Subject: [PATCH] Roll src/third_party/ffmpeg/ 574c39cce..32b2d1d526 (1125
  5. commits)
  6. https://chromium.googlesource.com/chromium/third_party/ffmpeg.git/+log/574c39cce323..32b2d1d526
  7. Created with:
  8. roll-dep src/third_party/ffmpeg
  9. Fixed: 1293918
  10. Cq-Include-Trybots: luci.chromium.try:mac_chromium_asan_rel_ng,linux_chromium_asan_rel_ng,linux_chromium_chromeos_asan_rel_ng
  11. Change-Id: I41945d0f963e3d1f65940067bac22f63b68e37d2
  12. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3565647
  13. Auto-Submit: Dale Curtis <dalecurtis@chromium.org>
  14. Reviewed-by: Dan Sanders <sandersd@chromium.org>
  15. Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
  16. Cr-Commit-Position: refs/heads/main@{#988253}
  17. ---
  18. .../clear_key_cdm/ffmpeg_cdm_audio_decoder.cc | 29 ++++++++++---------
  19. media/ffmpeg/ffmpeg_common.cc | 11 +++----
  20. media/filters/audio_file_reader.cc | 9 +++---
  21. media/filters/audio_file_reader_unittest.cc | 6 ++--
  22. .../filters/audio_video_metadata_extractor.cc | 11 +++++--
  23. .../filters/ffmpeg_aac_bitstream_converter.cc | 7 +++--
  24. ...ffmpeg_aac_bitstream_converter_unittest.cc | 2 +-
  25. media/filters/ffmpeg_audio_decoder.cc | 13 +++++----
  26. 8 files changed, 51 insertions(+), 37 deletions(-)
  27. diff --git a/src/3rdparty/chromium/media/cdm/library_cdm/clear_key_cdm/ffmpeg_cdm_audio_decoder.cc b/src/3rdparty/chromium/media/cdm/library_cdm/clear_key_cdm/ffmpeg_cdm_audio_decoder.cc
  28. index c535d2b..62ddbc8 100644
  29. --- a/src/3rdparty/chromium/media/cdm/library_cdm/clear_key_cdm/ffmpeg_cdm_audio_decoder.cc
  30. +++ b/src/3rdparty/chromium/media/cdm/library_cdm/clear_key_cdm/ffmpeg_cdm_audio_decoder.cc
  31. @@ -74,7 +74,7 @@ void CdmAudioDecoderConfigToAVCodecContext(
  32. codec_context->sample_fmt = AV_SAMPLE_FMT_NONE;
  33. }
  34. - codec_context->channels = config.channel_count;
  35. + codec_context->ch_layout.nb_channels = config.channel_count;
  36. codec_context->sample_rate = config.samples_per_second;
  37. if (config.extra_data) {
  38. @@ -124,8 +124,8 @@ void CopySamples(cdm::AudioFormat cdm_format,
  39. case cdm::kAudioFormatPlanarS16:
  40. case cdm::kAudioFormatPlanarF32: {
  41. const int decoded_size_per_channel =
  42. - decoded_audio_size / av_frame.channels;
  43. - for (int i = 0; i < av_frame.channels; ++i) {
  44. + decoded_audio_size / av_frame.ch_layout.nb_channels;
  45. + for (int i = 0; i < av_frame.ch_layout.nb_channels; ++i) {
  46. memcpy(output_buffer, av_frame.extended_data[i],
  47. decoded_size_per_channel);
  48. output_buffer += decoded_size_per_channel;
  49. @@ -185,13 +185,14 @@ bool FFmpegCdmAudioDecoder::Initialize(
  50. // Success!
  51. decoding_loop_ = std::make_unique<FFmpegDecodingLoop>(codec_context_.get());
  52. samples_per_second_ = config.samples_per_second;
  53. - bytes_per_frame_ = codec_context_->channels * config.bits_per_channel / 8;
  54. + bytes_per_frame_ =
  55. + codec_context_->ch_layout.nb_channels * config.bits_per_channel / 8;
  56. output_timestamp_helper_ =
  57. std::make_unique<AudioTimestampHelper>(config.samples_per_second);
  58. is_initialized_ = true;
  59. // Store initial values to guard against midstream configuration changes.
  60. - channels_ = codec_context_->channels;
  61. + channels_ = codec_context_->ch_layout.nb_channels;
  62. av_sample_format_ = codec_context_->sample_fmt;
  63. return true;
  64. @@ -291,7 +292,8 @@ cdm::Status FFmpegCdmAudioDecoder::DecodeBuffer(
  65. for (auto& frame : audio_frames) {
  66. int decoded_audio_size = 0;
  67. if (frame->sample_rate != samples_per_second_ ||
  68. - frame->channels != channels_ || frame->format != av_sample_format_) {
  69. + frame->ch_layout.nb_channels != channels_ ||
  70. + frame->format != av_sample_format_) {
  71. DLOG(ERROR) << "Unsupported midstream configuration change!"
  72. << " Sample Rate: " << frame->sample_rate << " vs "
  73. << samples_per_second_
  74. @@ -302,7 +304,7 @@ cdm::Status FFmpegCdmAudioDecoder::DecodeBuffer(
  75. }
  76. decoded_audio_size = av_samples_get_buffer_size(
  77. - nullptr, codec_context_->channels, frame->nb_samples,
  78. + nullptr, codec_context_->ch_layout.nb_channels, frame->nb_samples,
  79. codec_context_->sample_fmt, 1);
  80. if (!decoded_audio_size)
  81. continue;
  82. @@ -322,7 +324,7 @@ bool FFmpegCdmAudioDecoder::OnNewFrame(
  83. std::vector<std::unique_ptr<AVFrame, ScopedPtrAVFreeFrame>>* audio_frames,
  84. AVFrame* frame) {
  85. *total_size += av_samples_get_buffer_size(
  86. - nullptr, codec_context_->channels, frame->nb_samples,
  87. + nullptr, codec_context_->ch_layout.nb_channels, frame->nb_samples,
  88. codec_context_->sample_fmt, 1);
  89. audio_frames->emplace_back(av_frame_clone(frame));
  90. return true;
  91. diff --git a/src/3rdparty/chromium/media/ffmpeg/ffmpeg_common.cc b/src/3rdparty/chromium/media/ffmpeg/ffmpeg_common.cc
  92. index 2665355..910f9ad 100644
  93. --- a/src/3rdparty/chromium/media/ffmpeg/ffmpeg_common.cc
  94. +++ b/src/3rdparty/chromium/media/ffmpeg/ffmpeg_common.cc
  95. @@ -336,10 +336,11 @@ bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context,
  96. codec_context->sample_fmt, codec_context->codec_id);
  97. ChannelLayout channel_layout =
  98. - codec_context->channels > 8
  99. + codec_context->ch_layout.nb_channels > 8
  100. ? CHANNEL_LAYOUT_DISCRETE
  101. - : ChannelLayoutToChromeChannelLayout(codec_context->channel_layout,
  102. - codec_context->channels);
  103. + : ChannelLayoutToChromeChannelLayout(
  104. + codec_context->ch_layout.u.mask,
  105. + codec_context->ch_layout.nb_channels);
  106. switch (codec) {
  107. // For AC3/EAC3 we enable only demuxing, but not decoding, so FFmpeg does
  108. @@ -391,7 +392,7 @@ bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context,
  109. extra_data, encryption_scheme, seek_preroll,
  110. codec_context->delay);
  111. if (channel_layout == CHANNEL_LAYOUT_DISCRETE)
  112. - config->SetChannelsForDiscrete(codec_context->channels);
  113. + config->SetChannelsForDiscrete(codec_context->ch_layout.nb_channels);
  114. #if BUILDFLAG(ENABLE_PLATFORM_AC3_EAC3_AUDIO)
  115. // These are bitstream formats unknown to ffmpeg, so they don't have
  116. @@ -460,7 +461,7 @@ void AudioDecoderConfigToAVCodecContext(const AudioDecoderConfig& config,
  117. // TODO(scherkus): should we set |channel_layout|? I'm not sure if FFmpeg uses
  118. // said information to decode.
  119. - codec_context->channels = config.channels();
  120. + codec_context->ch_layout.nb_channels = config.channels();
  121. codec_context->sample_rate = config.samples_per_second();
  122. if (config.extra_data().empty()) {
  123. diff --git a/src/3rdparty/chromium/media/filters/audio_file_reader.cc b/src/3rdparty/chromium/media/filters/audio_file_reader.cc
  124. index 777eabc..2b58dd7 100644
  125. --- a/src/3rdparty/chromium/media/filters/audio_file_reader.cc
  126. +++ b/src/3rdparty/chromium/media/filters/audio_file_reader.cc
  127. @@ -113,14 +113,15 @@ bool AudioFileReader::OpenDecoder() {
  128. // Verify the channel layout is supported by Chrome. Acts as a sanity check
  129. // against invalid files. See http://crbug.com/171962
  130. - if (ChannelLayoutToChromeChannelLayout(codec_context_->channel_layout,
  131. - codec_context_->channels) ==
  132. + if (ChannelLayoutToChromeChannelLayout(
  133. + codec_context_->ch_layout.u.mask,
  134. + codec_context_->ch_layout.nb_channels) ==
  135. CHANNEL_LAYOUT_UNSUPPORTED) {
  136. return false;
  137. }
  138. // Store initial values to guard against midstream configuration changes.
  139. - channels_ = codec_context_->channels;
  140. + channels_ = codec_context_->ch_layout.nb_channels;
  141. audio_codec_ = CodecIDToAudioCodec(codec_context_->codec_id);
  142. sample_rate_ = codec_context_->sample_rate;
  143. av_sample_format_ = codec_context_->sample_fmt;
  144. @@ -223,7 +224,7 @@ bool AudioFileReader::OnNewFrame(
  145. if (frames_read < 0)
  146. return false;
  147. - const int channels = frame->channels;
  148. + const int channels = frame->ch_layout.nb_channels;
  149. if (frame->sample_rate != sample_rate_ || channels != channels_ ||
  150. frame->format != av_sample_format_) {
  151. DLOG(ERROR) << "Unsupported midstream configuration change!"
  152. diff --git a/src/3rdparty/chromium/media/filters/ffmpeg_aac_bitstream_converter.cc b/src/3rdparty/chromium/media/filters/ffmpeg_aac_bitstream_converter.cc
  153. index 76b41aa..e26b6cd 100644
  154. --- a/src/3rdparty/chromium/media/filters/ffmpeg_aac_bitstream_converter.cc
  155. +++ b/src/3rdparty/chromium/media/filters/ffmpeg_aac_bitstream_converter.cc
  156. @@ -195,14 +195,15 @@ bool FFmpegAACBitstreamConverter::ConvertPacket(AVPacket* packet) {
  157. if (!header_generated_ || codec_ != stream_codec_parameters_->codec_id ||
  158. audio_profile_ != stream_codec_parameters_->profile ||
  159. sample_rate_index_ != sample_rate_index ||
  160. - channel_configuration_ != stream_codec_parameters_->channels ||
  161. + channel_configuration_ !=
  162. + stream_codec_parameters_->ch_layout.nb_channels ||
  163. frame_length_ != header_plus_packet_size) {
  164. header_generated_ =
  165. GenerateAdtsHeader(stream_codec_parameters_->codec_id,
  166. 0, // layer
  167. stream_codec_parameters_->profile, sample_rate_index,
  168. 0, // private stream
  169. - stream_codec_parameters_->channels,
  170. + stream_codec_parameters_->ch_layout.nb_channels,
  171. 0, // originality
  172. 0, // home
  173. 0, // copyrighted_stream
  174. @@ -214,7 +215,7 @@ bool FFmpegAACBitstreamConverter::ConvertPacket(AVPacket* packet) {
  175. codec_ = stream_codec_parameters_->codec_id;
  176. audio_profile_ = stream_codec_parameters_->profile;
  177. sample_rate_index_ = sample_rate_index;
  178. - channel_configuration_ = stream_codec_parameters_->channels;
  179. + channel_configuration_ = stream_codec_parameters_->ch_layout.nb_channels;
  180. frame_length_ = header_plus_packet_size;
  181. }
  182. diff --git a/src/3rdparty/chromium/media/filters/ffmpeg_aac_bitstream_converter_unittest.cc b/src/3rdparty/chromium/media/filters/ffmpeg_aac_bitstream_converter_unittest.cc
  183. index 3b46f7f..1897eb0 100644
  184. --- a/src/3rdparty/chromium/media/filters/ffmpeg_aac_bitstream_converter_unittest.cc
  185. +++ b/src/3rdparty/chromium/media/filters/ffmpeg_aac_bitstream_converter_unittest.cc
  186. @@ -34,7 +34,7 @@ class FFmpegAACBitstreamConverterTest : public testing::Test {
  187. memset(&test_parameters_, 0, sizeof(AVCodecParameters));
  188. test_parameters_.codec_id = AV_CODEC_ID_AAC;
  189. test_parameters_.profile = FF_PROFILE_AAC_MAIN;
  190. - test_parameters_.channels = 2;
  191. + test_parameters_.ch_layout.nb_channels = 2;
  192. test_parameters_.extradata = extradata_header_;
  193. test_parameters_.extradata_size = sizeof(extradata_header_);
  194. }
  195. diff --git a/src/3rdparty/chromium/media/filters/ffmpeg_audio_decoder.cc b/src/3rdparty/chromium/media/filters/ffmpeg_audio_decoder.cc
  196. index bf3ed00..d564ee9 100644
  197. --- a/src/3rdparty/chromium/media/filters/ffmpeg_audio_decoder.cc
  198. +++ b/src/3rdparty/chromium/media/filters/ffmpeg_audio_decoder.cc
  199. @@ -29,7 +29,7 @@ namespace media {
  200. // Return the number of channels from the data in |frame|.
  201. static inline int DetermineChannels(AVFrame* frame) {
  202. - return frame->channels;
  203. + return frame->ch_layout.nb_channels;
  204. }
  205. // Called by FFmpeg's allocation routine to allocate a buffer. Uses
  206. @@ -243,7 +243,7 @@ bool FFmpegAudioDecoder::OnNewFrame(const DecoderBuffer& buffer,
  207. // Translate unsupported into discrete layouts for discrete configurations;
  208. // ffmpeg does not have a labeled discrete configuration internally.
  209. ChannelLayout channel_layout = ChannelLayoutToChromeChannelLayout(
  210. - codec_context_->channel_layout, codec_context_->channels);
  211. + codec_context_->ch_layout.u.mask, codec_context_->ch_layout.nb_channels);
  212. if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED &&
  213. config_.channel_layout() == CHANNEL_LAYOUT_DISCRETE) {
  214. channel_layout = CHANNEL_LAYOUT_DISCRETE;
  215. @@ -360,11 +360,11 @@ bool FFmpegAudioDecoder::ConfigureDecoder(const AudioDecoderConfig& config) {
  216. // Success!
  217. av_sample_format_ = codec_context_->sample_fmt;
  218. - if (codec_context_->channels != config.channels()) {
  219. + if (codec_context_->ch_layout.nb_channels != config.channels()) {
  220. MEDIA_LOG(ERROR, media_log_)
  221. << "Audio configuration specified " << config.channels()
  222. << " channels, but FFmpeg thinks the file contains "
  223. - << codec_context_->channels << " channels";
  224. + << codec_context_->ch_layout.nb_channels << " channels";
  225. ReleaseFFmpegResources();
  226. state_ = DecoderState::kUninitialized;
  227. return false;
  228. @@ -415,7 +415,7 @@ int FFmpegAudioDecoder::GetAudioBuffer(struct AVCodecContext* s,
  229. if (frame->nb_samples <= 0)
  230. return AVERROR(EINVAL);
  231. - if (s->channels != channels) {
  232. + if (s->ch_layout.nb_channels != channels) {
  233. DLOG(ERROR) << "AVCodecContext and AVFrame disagree on channel count.";
  234. return AVERROR(EINVAL);
  235. }
  236. @@ -448,7 +448,8 @@ int FFmpegAudioDecoder::GetAudioBuffer(struct AVCodecContext* s,
  237. ChannelLayout channel_layout =
  238. config_.channel_layout() == CHANNEL_LAYOUT_DISCRETE
  239. ? CHANNEL_LAYOUT_DISCRETE
  240. - : ChannelLayoutToChromeChannelLayout(s->channel_layout, s->channels);
  241. + : ChannelLayoutToChromeChannelLayout(s->ch_layout.u.mask,
  242. + s->ch_layout.nb_channels);
  243. if (channel_layout == CHANNEL_LAYOUT_UNSUPPORTED) {
  244. DLOG(ERROR) << "Unsupported channel layout.";
  245. commit 62274859104bd828373ae406aa9309e610449ac5
  246. Author: Ted Meyer <tmathmeyer@chromium.org>
  247. Date: Fri Mar 22 19:56:55 2024 +0000
  248. Replace deprecated use of AVCodecContext::reordered_opaque
  249. We can use the AV_CODEC_FLAG_COPY_OPAQUE flag on the codec context
  250. now to trigger timestamp propagation.
  251. Bug: 330573128
  252. Change-Id: I6bc57241a35ab5283742aad8d42acb4dc5e85858
  253. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5384308
  254. Commit-Queue: Ted (Chromium) Meyer <tmathmeyer@chromium.org>
  255. Reviewed-by: Dan Sanders <sandersd@chromium.org>
  256. Cr-Commit-Position: refs/heads/main@{#1277051}
  257. diff --git a/src/3rdparty/chromium/media/ffmpeg/ffmpeg_common.cc b/src/3rdparty/chromium/media/ffmpeg/ffmpeg_common.cc
  258. index 910f9ad..8be165c 100644
  259. --- a/src/3rdparty/chromium/media/ffmpeg/ffmpeg_common.cc
  260. +++ b/src/3rdparty/chromium/media/ffmpeg/ffmpeg_common.cc
  261. @@ -411,7 +411,9 @@ bool AVCodecContextToAudioDecoderConfig(const AVCodecContext* codec_context,
  262. // TODO(dalecurtis): Just use the profile from the codec context if ffmpeg
  263. // ever starts supporting xHE-AAC.
  264. - if (codec_context->profile == FF_PROFILE_UNKNOWN) {
  265. + constexpr uint8_t kXHEAAc = 41;
  266. + if (codec_context->profile == FF_PROFILE_UNKNOWN ||
  267. + codec_context->profile == kXHEAAc) {
  268. // Errors aren't fatal here, so just drop any MediaLog messages.
  269. NullMediaLog media_log;
  270. mp4::AAC aac_parser;
  271. diff --git a/src/3rdparty/chromium/media/ffmpeg/ffmpeg_regression_tests.cc b/src/3rdparty/chromium/media/ffmpeg/ffmpeg_regression_tests.cc
  272. index 05dcb1c..866f446 100644
  273. --- a/src/3rdparty/chromium/media/ffmpeg/ffmpeg_regression_tests.cc
  274. +++ b/src/3rdparty/chromium/media/ffmpeg/ffmpeg_regression_tests.cc
  275. @@ -90,16 +90,16 @@ FFMPEG_TEST_CASE(Cr62127,
  276. PIPELINE_ERROR_DECODE,
  277. PIPELINE_ERROR_DECODE);
  278. FFMPEG_TEST_CASE(Cr93620, "security/93620.ogg", PIPELINE_OK, PIPELINE_OK);
  279. -FFMPEG_TEST_CASE(Cr100492,
  280. - "security/100492.webm",
  281. - DECODER_ERROR_NOT_SUPPORTED,
  282. - DECODER_ERROR_NOT_SUPPORTED);
  283. +FFMPEG_TEST_CASE(Cr100492, "security/100492.webm", PIPELINE_OK, PIPELINE_OK);
  284. FFMPEG_TEST_CASE(Cr100543, "security/100543.webm", PIPELINE_OK, PIPELINE_OK);
  285. FFMPEG_TEST_CASE(Cr101458,
  286. "security/101458.webm",
  287. PIPELINE_ERROR_DECODE,
  288. PIPELINE_ERROR_DECODE);
  289. -FFMPEG_TEST_CASE(Cr108416, "security/108416.webm", PIPELINE_OK, PIPELINE_OK);
  290. +FFMPEG_TEST_CASE(Cr108416,
  291. + "security/108416.webm",
  292. + PIPELINE_ERROR_DECODE,
  293. + PIPELINE_ERROR_DECODE);
  294. FFMPEG_TEST_CASE(Cr110849,
  295. "security/110849.mkv",
  296. DEMUXER_ERROR_COULD_NOT_OPEN,
  297. @@ -154,7 +154,10 @@ FFMPEG_TEST_CASE(Cr234630b,
  298. "security/234630b.mov",
  299. DEMUXER_ERROR_NO_SUPPORTED_STREAMS,
  300. DEMUXER_ERROR_NO_SUPPORTED_STREAMS);
  301. -FFMPEG_TEST_CASE(Cr242786, "security/242786.webm", PIPELINE_OK, PIPELINE_OK);
  302. +FFMPEG_TEST_CASE(Cr242786,
  303. + "security/242786.webm",
  304. + PIPELINE_OK,
  305. + PIPELINE_ERROR_DECODE);
  306. // Test for out-of-bounds access with slightly corrupt file (detection logic
  307. // thinks it's a MONO file, but actually contains STEREO audio).
  308. FFMPEG_TEST_CASE(Cr275590,
  309. @@ -372,8 +375,8 @@ FFMPEG_TEST_CASE(WEBM_2,
  310. DEMUXER_ERROR_NO_SUPPORTED_STREAMS);
  311. FFMPEG_TEST_CASE(WEBM_4,
  312. "security/out.webm.68798.1929",
  313. - DECODER_ERROR_NOT_SUPPORTED,
  314. - DECODER_ERROR_NOT_SUPPORTED);
  315. + PIPELINE_OK,
  316. + PIPELINE_OK);
  317. FFMPEG_TEST_CASE(WEBM_5, "frame_size_change.webm", PIPELINE_OK, PIPELINE_OK);
  318. // General MKV test cases.
  319. diff --git a/src/3rdparty/chromium/media/filters/audio_decoder_unittest.cc b/src/3rdparty/chromium/media/filters/audio_decoder_unittest.cc
  320. index a7b2533..ba3c308 100644
  321. --- a/src/3rdparty/chromium/media/filters/audio_decoder_unittest.cc
  322. +++ b/src/3rdparty/chromium/media/filters/audio_decoder_unittest.cc
  323. @@ -484,7 +484,7 @@ constexpr TestParams kXheAacTestParams[] = {
  324. }},
  325. 0,
  326. 29400,
  327. - CHANNEL_LAYOUT_MONO,
  328. + CHANNEL_LAYOUT_UNSUPPORTED,
  329. AudioCodecProfile::kXHE_AAC},
  330. #endif
  331. {AudioCodec::kAAC,
  332. diff --git a/src/3rdparty/chromium/media/filters/audio_file_reader.cc b/src/3rdparty/chromium/media/filters/audio_file_reader.cc
  333. index 2b58dd7..9d37f32 100644
  334. --- a/src/3rdparty/chromium/media/filters/audio_file_reader.cc
  335. +++ b/src/3rdparty/chromium/media/filters/audio_file_reader.cc
  336. @@ -243,18 +243,10 @@ bool AudioFileReader::OnNewFrame(
  337. // silence from being output. In the case where we are also discarding some
  338. // portion of the packet (as indicated by a negative pts), we further want to
  339. // adjust the duration downward by however much exists before zero.
  340. -#if BUILDFLAG(USE_SYSTEM_FFMPEG)
  341. - if (audio_codec_ == AudioCodec::kAAC && frame->pkt_duration) {
  342. -#else
  343. if (audio_codec_ == AudioCodec::kAAC && frame->duration) {
  344. -#endif // BUILDFLAG(USE_SYSTEM_FFMPEG)
  345. const base::TimeDelta pkt_duration = ConvertFromTimeBase(
  346. glue_->format_context()->streams[stream_index_]->time_base,
  347. -#if BUILDFLAG(USE_SYSTEM_FFMPEG)
  348. - frame->pkt_duration + std::min(static_cast<int64_t>(0), frame->pts));
  349. -#else
  350. frame->duration + std::min(static_cast<int64_t>(0), frame->pts));
  351. -#endif // BUILDFLAG(USE_SYSTEM_FFMPEG)
  352. const base::TimeDelta frame_duration =
  353. base::Seconds(frames_read / static_cast<double>(sample_rate_));
  354. diff --git a/src/3rdparty/chromium/media/filters/audio_file_reader_unittest.cc b/src/3rdparty/chromium/media/filters/audio_file_reader_unittest.cc
  355. index a1c633d..5784fe1 100644
  356. --- a/src/3rdparty/chromium/media/filters/audio_file_reader_unittest.cc
  357. +++ b/src/3rdparty/chromium/media/filters/audio_file_reader_unittest.cc
  358. @@ -61,15 +61,14 @@ class AudioFileReaderTest : public testing::Test {
  359. // Verify packets are consistent across demuxer runs. Reads the first few
  360. // packets and then seeks back to the start timestamp and verifies that the
  361. // hashes match on the packets just read.
  362. - void VerifyPackets() {
  363. - const int kReads = 3;
  364. + void VerifyPackets(int packet_reads) {
  365. const int kTestPasses = 2;
  366. AVPacket packet;
  367. base::TimeDelta start_timestamp;
  368. std::vector<std::string> packet_md5_hashes_;
  369. for (int i = 0; i < kTestPasses; ++i) {
  370. - for (int j = 0; j < kReads; ++j) {
  371. + for (int j = 0; j < packet_reads; ++j) {
  372. ASSERT_TRUE(reader_->ReadPacketForTesting(&packet));
  373. // On the first pass save the MD5 hash of each packet, on subsequent
  374. @@ -98,7 +97,8 @@ class AudioFileReaderTest : public testing::Test {
  375. int sample_rate,
  376. base::TimeDelta duration,
  377. int frames,
  378. - int expected_frames) {
  379. + int expected_frames,
  380. + int packet_reads = 3) {
  381. Initialize(fn);
  382. ASSERT_TRUE(reader_->Open());
  383. EXPECT_EQ(channels, reader_->channels());
  384. @@ -112,7 +112,7 @@ class AudioFileReaderTest : public testing::Test {
  385. EXPECT_EQ(reader_->HasKnownDuration(), false);
  386. }
  387. if (!packet_verification_disabled_)
  388. - ASSERT_NO_FATAL_FAILURE(VerifyPackets());
  389. + ASSERT_NO_FATAL_FAILURE(VerifyPackets(packet_reads));
  390. ReadAndVerify(hash, expected_frames);
  391. }
  392. @@ -219,7 +219,7 @@ TEST_F(AudioFileReaderTest, AAC_ADTS) {
  393. }
  394. TEST_F(AudioFileReaderTest, MidStreamConfigChangesFail) {
  395. - RunTestFailingDecode("midstream_config_change.mp3", 42624);
  396. + RunTestFailingDecode("midstream_config_change.mp3", 0);
  397. }
  398. #endif
  399. @@ -229,7 +229,7 @@ TEST_F(AudioFileReaderTest, VorbisInvalidChannelLayout) {
  400. TEST_F(AudioFileReaderTest, WaveValidFourChannelLayout) {
  401. RunTest("4ch.wav", "131.71,38.02,130.31,44.89,135.98,42.52,", 4, 44100,
  402. - base::Microseconds(100001), 4411, 4410);
  403. + base::Microseconds(100001), 4411, 4410, /*packet_reads=*/2);
  404. }
  405. TEST_F(AudioFileReaderTest, ReadPartialMP3) {
  406. diff --git a/src/3rdparty/chromium/media/filters/ffmpeg_video_decoder.cc b/src/3rdparty/chromium/media/filters/ffmpeg_video_decoder.cc
  407. index e62b2af..ab39796 100644
  408. --- a/src/3rdparty/chromium/media/filters/ffmpeg_video_decoder.cc
  409. +++ b/src/3rdparty/chromium/media/filters/ffmpeg_video_decoder.cc
  410. @@ -125,7 +125,7 @@ bool FFmpegVideoDecoder::IsCodecSupported(VideoCodec codec) {
  411. }
  412. FFmpegVideoDecoder::FFmpegVideoDecoder(MediaLog* media_log)
  413. - : media_log_(media_log) {
  414. + : media_log_(media_log), timestamp_map_(128) {
  415. DVLOG(1) << __func__;
  416. DETACH_FROM_SEQUENCE(sequence_checker_);
  417. }
  418. @@ -204,10 +204,6 @@ int FFmpegVideoDecoder::GetVideoBuffer(struct AVCodecContext* codec_context,
  419. frame->linesize[plane] = layout->planes()[plane].stride;
  420. }
  421. - // This seems unsafe, given threaded decoding. However, `reordered_opaque` is
  422. - // also going away upstream, so we need a whole new mechanism either way.
  423. - frame->reordered_opaque = codec_context->reordered_opaque;
  424. -
  425. // This will be freed by `ReleaseVideoBufferImpl`.
  426. auto* opaque = new OpaqueData(fb_priv, frame_pool_, data, allocation_size,
  427. std::move(*layout));
  428. @@ -354,8 +350,10 @@ bool FFmpegVideoDecoder::FFmpegDecode(const DecoderBuffer& buffer) {
  429. DCHECK(packet->data);
  430. DCHECK_GT(packet->size, 0);
  431. - // Let FFmpeg handle presentation timestamp reordering.
  432. - codec_context_->reordered_opaque = buffer.timestamp().InMicroseconds();
  433. + const int64_t timestamp = buffer.timestamp().InMicroseconds();
  434. + const TimestampId timestamp_id = timestamp_id_generator_.GenerateNextId();
  435. + timestamp_map_.Put(std::make_pair(timestamp_id, timestamp));
  436. + packet->opaque = reinterpret_cast<void*>(timestamp_id.GetUnsafeValue());
  437. }
  438. FFmpegDecodingLoop::DecodeStatus decode_status = decoding_loop_->DecodePacket(
  439. packet, base::BindRepeating(&FFmpegVideoDecoder::OnNewFrame,
  440. @@ -414,7 +412,12 @@ bool FFmpegVideoDecoder::OnNewFrame(AVFrame* frame) {
  441. }
  442. gfx::Size natural_size = aspect_ratio.GetNaturalSize(visible_rect);
  443. - const auto pts = base::Microseconds(frame->reordered_opaque);
  444. + const auto ts_id = TimestampId(reinterpret_cast<size_t>(frame->opaque));
  445. + const auto ts_lookup = timestamp_map_.Get(ts_id);
  446. + if (ts_lookup == timestamp_map_.end()) {
  447. + return false;
  448. + }
  449. + const auto pts = base::Microseconds(std::get<1>(*ts_lookup));
  450. auto video_frame = VideoFrame::WrapExternalDataWithLayout(
  451. opaque->layout, visible_rect, natural_size, opaque->data, opaque->size,
  452. pts);
  453. @@ -489,8 +492,10 @@ bool FFmpegVideoDecoder::ConfigureDecoder(const VideoDecoderConfig& config,
  454. codec_context_->thread_count = GetFFmpegVideoDecoderThreadCount(config);
  455. codec_context_->thread_type =
  456. FF_THREAD_SLICE | (low_delay ? 0 : FF_THREAD_FRAME);
  457. +
  458. codec_context_->opaque = this;
  459. codec_context_->get_buffer2 = GetVideoBufferImpl;
  460. + codec_context_->flags |= AV_CODEC_FLAG_COPY_OPAQUE;
  461. if (decode_nalus_)
  462. codec_context_->flags2 |= AV_CODEC_FLAG2_CHUNKS;
  463. diff --git a/src/3rdparty/chromium/media/filters/ffmpeg_video_decoder.h b/src/3rdparty/chromium/media/filters/ffmpeg_video_decoder.h
  464. index 60cb9d5..4fa8628 100644
  465. --- a/src/3rdparty/chromium/media/filters/ffmpeg_video_decoder.h
  466. +++ b/src/3rdparty/chromium/media/filters/ffmpeg_video_decoder.h
  467. @@ -7,10 +7,12 @@
  468. #include <memory>
  469. +#include "base/containers/lru_cache.h"
  470. #include "base/functional/callback.h"
  471. #include "base/memory/raw_ptr.h"
  472. #include "base/memory/scoped_refptr.h"
  473. #include "base/sequence_checker.h"
  474. +#include "base/types/id_type.h"
  475. #include "media/base/supported_video_decoder_config.h"
  476. #include "media/base/video_decoder.h"
  477. #include "media/base/video_decoder_config.h"
  478. @@ -87,6 +89,20 @@ class MEDIA_EXPORT FFmpegVideoDecoder : public VideoDecoder {
  479. // FFmpeg structures owned by this object.
  480. std::unique_ptr<AVCodecContext, ScopedPtrAVFreeContext> codec_context_;
  481. + // The gist here is that timestamps need to be 64 bits to store microsecond
  482. + // precision. A 32 bit integer would overflow at ~35 minutes at this level of
  483. + // precision. We can't cast the timestamp to the void ptr object used by the
  484. + // opaque field in ffmpeg then, because it would lose data on a 32 bit build.
  485. + // However, we don't actually have 2^31 timestamped frames in a single
  486. + // playback, so it's fine to use the 32 bit value as a key in a map which
  487. + // contains the actual timestamps. Additionally, we've in the past set 128
  488. + // outstanding frames for re-ordering as a limit for cross-thread decoding
  489. + // tasks, so we'll do that here too with the LRU cache.
  490. + using TimestampId = base::IdType<int64_t, size_t, 0>;
  491. +
  492. + TimestampId::Generator timestamp_id_generator_;
  493. + base::LRUCache<TimestampId, int64_t> timestamp_map_;
  494. +
  495. VideoDecoderConfig config_;
  496. scoped_refptr<FrameBufferPool> frame_pool_;
  497. diff --git a/src/3rdparty/chromium/third_party/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc b/src/3rdparty/chromium/third_party/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc
  498. index f67718c..fe42aef 100644
  499. --- a/src/3rdparty/chromium/third_party/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc
  500. +++ b/src/3rdparty/chromium/third_party/webrtc/modules/video_coding/codecs/h264/h264_decoder_impl.cc
  501. @@ -229,7 +229,6 @@ int H264DecoderImpl::AVGetBuffer2(AVCodecContext* context,
  502. int total_size = y_size + 2 * uv_size;
  503. av_frame->format = context->pix_fmt;
  504. - av_frame->reordered_opaque = context->reordered_opaque;
  505. // Create a VideoFrame object, to keep a reference to the buffer.
  506. // TODO(nisse): The VideoFrame's timestamp and rotation info is not used.
  507. @@ -377,8 +376,6 @@ int32_t H264DecoderImpl::Decode(const EncodedImage& input_image,
  508. return WEBRTC_VIDEO_CODEC_ERROR;
  509. }
  510. packet->size = static_cast<int>(input_image.size());
  511. - int64_t frame_timestamp_us = input_image.ntp_time_ms_ * 1000; // ms -> μs
  512. - av_context_->reordered_opaque = frame_timestamp_us;
  513. int result = avcodec_send_packet(av_context_.get(), packet.get());
  514. @@ -395,10 +392,6 @@ int32_t H264DecoderImpl::Decode(const EncodedImage& input_image,
  515. return WEBRTC_VIDEO_CODEC_ERROR;
  516. }
  517. - // We don't expect reordering. Decoded frame timestamp should match
  518. - // the input one.
  519. - RTC_DCHECK_EQ(av_frame_->reordered_opaque, frame_timestamp_us);
  520. -
  521. // TODO(sakal): Maybe it is possible to get QP directly from FFmpeg.
  522. h264_bitstream_parser_.ParseBitstream(input_image);
  523. absl::optional<int> qp = h264_bitstream_parser_.GetLastSliceQp();