Blame qtwebengine-ffmpeg-first_dts.patch

78415c7
diff --git a/configure.cmake b/configure.cmake
78415c7
index b20ab3b65..c41f66301 100644
78415c7
--- a/configure.cmake
78415c7
+++ b/configure.cmake
78415c7
@@ -203,25 +203,6 @@ int main(void){
78415c7
 }"
78415c7
 )
78415c7
78415c7
-qt_config_compile_test(libavformat
78415c7
-    LABEL "libavformat"
78415c7
-    LIBRARIES
78415c7
-        PkgConfig::FFMPEG
78415c7
-    CODE
78415c7
-"
78415c7
-#include \"libavformat/version.h\"
78415c7
-extern \"C\" {
78415c7
-#include \"libavformat/avformat.h\"
78415c7
-}
78415c7
-int main(void) {
78415c7
-#if LIBAVFORMAT_VERSION_MAJOR >= 59
78415c7
-    AVStream stream;
78415c7
-    auto first_dts = av_stream_get_first_dts(&stream);
78415c7
-#endif
78415c7
-    return 0;
78415c7
-}"
78415c7
-)
78415c7
-
78415c7
 #### Features
78415c7
78415c7
 qt_feature("qtwebengine-build" PUBLIC
78415c7
@@ -542,11 +523,6 @@ add_check_for_support(
78415c7
    CONDITION NOT LINUX OR DBUS_FOUND
78415c7
    MESSAGE "Build requires dbus."
78415c7
 )
78415c7
-add_check_for_support(
78415c7
-    MODULES QtWebEngine
78415c7
-    CONDITION NOT LINUX OR NOT QT_FEATURE_webengine_system_ffmpeg OR TEST_libavformat
78415c7
-    MESSAGE "Unmodified ffmpeg >= 5.0 is not supported."
78415c7
-)
78415c7
 # FIXME: This prevents non XCB Linux builds from building:
78415c7
 set(xcbSupport X11 LIBDRM XCOMPOSITE XCURSOR XRANDR XI XPROTO XSHMFENCE XTST)
78415c7
 foreach(xs ${xcbSupport})
78415c7
diff --git a/src/3rdparty/chromium/AUTHORS b/src/3rdparty/chromium/AUTHORS
78415c7
index 8d638184b..80e4a9b35 100644
78415c7
--- a/src/3rdparty/chromium/AUTHORS
78415c7
+++ b/src/3rdparty/chromium/AUTHORS
78415c7
@@ -94,6 +94,7 @@ Andra Paraschiv <andra.paraschiv@intel.com>
78415c7
 Andras Tokodi <a.tokodi@eyeo.com>
78415c7
 Andreas Nazlidis <andreas221b@gmail.com>
78415c7
 Andreas Papacharalampous <andreas@apap04.com>
78415c7
+Andreas Schneider <asn@cryptomilk.org>
78415c7
 Andrei Borza <andrei.borza@gmail.com>
78415c7
 Andrei Parvu <andrei.prv@gmail.com>
78415c7
 Andrei Parvu <parvu@adobe.com>
78415c7
diff --git a/src/3rdparty/chromium/media/filters/ffmpeg_demuxer.cc b/src/3rdparty/chromium/media/filters/ffmpeg_demuxer.cc
78415c7
index 7b709d70d..d97b6b4d0 100644
78415c7
--- a/src/3rdparty/chromium/media/filters/ffmpeg_demuxer.cc
78415c7
+++ b/src/3rdparty/chromium/media/filters/ffmpeg_demuxer.cc
78415c7
@@ -58,7 +58,7 @@ namespace media {
78415c7
78415c7
 namespace {
78415c7
78415c7
-constexpr int64_t kInvalidPTSMarker = static_cast<int64_t>(0x8000000000000000);
78415c7
+constexpr int64_t kRelativeTsBase = static_cast<int64_t>(0x7ffeffffffffffff);
78415c7
78415c7
 void SetAVStreamDiscard(AVStream* stream, AVDiscard discard) {
78415c7
   DCHECK(stream);
78415c7
@@ -101,7 +101,7 @@ static base::TimeDelta FramesToTimeDelta(int frames, double sample_rate) {
78415c7
                             sample_rate);
78415c7
 }
78415c7
78415c7
-static base::TimeDelta ExtractStartTime(AVStream* stream) {
78415c7
+static base::TimeDelta ExtractStartTime(AVStream* stream, int64_t first_dts) {
78415c7
   // The default start time is zero.
78415c7
   base::TimeDelta start_time;
78415c7
78415c7
@@ -111,12 +111,12 @@ static base::TimeDelta ExtractStartTime(AVStream* stream) {
78415c7
78415c7
   // Next try to use the first DTS value, for codecs where we know PTS == DTS
78415c7
   // (excludes all H26x codecs). The start time must be returned in PTS.
78415c7
-  if (av_stream_get_first_dts(stream) != kInvalidPTSMarker &&
78415c7
+  if (first_dts != AV_NOPTS_VALUE &&
78415c7
       stream->codecpar->codec_id != AV_CODEC_ID_HEVC &&
78415c7
       stream->codecpar->codec_id != AV_CODEC_ID_H264 &&
78415c7
       stream->codecpar->codec_id != AV_CODEC_ID_MPEG4) {
78415c7
     const base::TimeDelta first_pts =
78415c7
-        ConvertFromTimeBase(stream->time_base, av_stream_get_first_dts(stream));
78415c7
+        ConvertFromTimeBase(stream->time_base, first_dts);
78415c7
     if (first_pts < start_time)
78415c7
       start_time = first_pts;
78415c7
   }
78415c7
@@ -285,6 +285,7 @@ FFmpegDemuxerStream::FFmpegDemuxerStream(
78415c7
       fixup_negative_timestamps_(false),
78415c7
       fixup_chained_ogg_(false),
78415c7
       num_discarded_packet_warnings_(0),
78415c7
+      first_dts_(AV_NOPTS_VALUE),
78415c7
       last_packet_pos_(AV_NOPTS_VALUE),
78415c7
       last_packet_dts_(AV_NOPTS_VALUE) {
78415c7
   DCHECK(demuxer_);
78415c7
@@ -351,6 +352,11 @@ void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) {
78415c7
   int64_t packet_dts =
78415c7
       packet->dts == AV_NOPTS_VALUE ? packet->pts : packet->dts;
78415c7
78415c7
+  if (first_dts_ == AV_NOPTS_VALUE && packet->dts != AV_NOPTS_VALUE &&
78415c7
+      last_packet_dts_ != AV_NOPTS_VALUE) {
78415c7
+    first_dts_ = packet->dts - (last_packet_dts_ + kRelativeTsBase);
78415c7
+  }
78415c7
+
78415c7
   // Chained ogg files have non-monotonically increasing position and time stamp
78415c7
   // values, which prevents us from using them to determine if a packet should
78415c7
   // be dropped. Since chained ogg is only allowed on single track audio only
78415c7
@@ -698,6 +704,7 @@ void FFmpegDemuxerStream::FlushBuffers(bool preserve_packet_position) {
78415c7
   ResetBitstreamConverter();
78415c7
78415c7
   if (!preserve_packet_position) {
78415c7
+    first_dts_ = AV_NOPTS_VALUE;
78415c7
     last_packet_pos_ = AV_NOPTS_VALUE;
78415c7
     last_packet_dts_ = AV_NOPTS_VALUE;
78415c7
   }
78415c7
@@ -1449,7 +1456,8 @@ void FFmpegDemuxer::OnFindStreamInfoDone(int result) {
78415c7
78415c7
     max_duration = std::max(max_duration, streams_[i]->duration());
78415c7
78415c7
-    base::TimeDelta start_time = ExtractStartTime(stream);
78415c7
+    base::TimeDelta start_time =
78415c7
+        ExtractStartTime(stream, streams_[i]->first_dts());
78415c7
78415c7
     // Note: This value is used for seeking, so we must take the true value and
78415c7
     // not the one possibly clamped to zero below.
78415c7
@@ -1606,7 +1614,7 @@ FFmpegDemuxerStream* FFmpegDemuxer::FindStreamWithLowestStartTimestamp(
78415c7
   for (const auto& stream : streams_) {
78415c7
     if (!stream || stream->IsEnabled() != enabled)
78415c7
       continue;
78415c7
-    if (av_stream_get_first_dts(stream->av_stream()) == kInvalidPTSMarker)
78415c7
+    if (stream->first_dts() == AV_NOPTS_VALUE)
78415c7
       continue;
78415c7
     if (!lowest_start_time_stream ||
78415c7
         stream->start_time() < lowest_start_time_stream->start_time()) {
78415c7
@@ -1627,7 +1635,7 @@ FFmpegDemuxerStream* FFmpegDemuxer::FindPreferredStreamForSeeking(
78415c7
     if (stream->type() != DemuxerStream::VIDEO)
78415c7
       continue;
78415c7
78415c7
-    if (av_stream_get_first_dts(stream->av_stream()) == kInvalidPTSMarker)
78415c7
+    if (stream->first_dts() == AV_NOPTS_VALUE)
78415c7
       continue;
78415c7
78415c7
     if (!stream->IsEnabled())
78415c7
diff --git a/src/3rdparty/chromium/media/filters/ffmpeg_demuxer.h b/src/3rdparty/chromium/media/filters/ffmpeg_demuxer.h
78415c7
index 45ab0f348..6b093318f 100644
78415c7
--- a/src/3rdparty/chromium/media/filters/ffmpeg_demuxer.h
78415c7
+++ b/src/3rdparty/chromium/media/filters/ffmpeg_demuxer.h
78415c7
@@ -152,6 +152,8 @@ class MEDIA_EXPORT FFmpegDemuxerStream : public DemuxerStream {
78415c7
   base::TimeDelta start_time() const { return start_time_; }
78415c7
   void set_start_time(base::TimeDelta time) { start_time_ = time; }
78415c7
78415c7
+  int64_t first_dts() const { return first_dts_; }
78415c7
+
78415c7
  private:
78415c7
   friend class FFmpegDemuxerTest;
78415c7
78415c7
@@ -209,6 +211,7 @@ class MEDIA_EXPORT FFmpegDemuxerStream : public DemuxerStream {
78415c7
   bool fixup_chained_ogg_;
78415c7
78415c7
   int num_discarded_packet_warnings_;
78415c7
+  int64_t first_dts_;
78415c7
   int64_t last_packet_pos_;
78415c7
   int64_t last_packet_dts_;
78415c7
 };