]> git.pld-linux.org Git - packages/qt5-qtwebengine.git/blob - chromium-112-ffmpeg-first_dts.patch
relup
[packages/qt5-qtwebengine.git] / chromium-112-ffmpeg-first_dts.patch
1 From 2aef9000a1c8d76d3072365ffcb471ebffa20d3d Mon Sep 17 00:00:00 2001
2 From: Andreas Schneider <asn@cryptomilk.org>
3 Date: Tue, 15 Mar 2022 14:26:16 +0100
4 Subject: [PATCH] Track first_dts instead of using non-upstream functions
5
6 The function av_stream_get_first_dts() is not an upstream ffmpeg function and
7 is not available if you build with system ffmpeg. We can easily track the
8 first_dts on our own.
9
10 See also
11 https://ffmpeg.org/pipermail/ffmpeg-devel/2021-September/285401.html
12
13 Bug: 1306560
14
15 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
16 Change-Id: I90ba3cf2f2e16f56a0b405f26c67f911349fb71d
17 ---
18  media/filters/ffmpeg_demuxer.cc | 18 ++++++++++++------
19  media/filters/ffmpeg_demuxer.h  |  3 +++
20  3 files changed, 16 insertions(+), 6 deletions(-)
21
22 diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
23 index 111899b661..799fc6e941 100644
24 --- a/media/filters/ffmpeg_demuxer.cc
25 +++ b/media/filters/ffmpeg_demuxer.cc
26 @@ -97,7 +97,7 @@ static base::TimeDelta FramesToTimeDelta(int frames, double sample_rate) {
27        frames * base::Time::kMicrosecondsPerSecond / sample_rate);
28  }
29  
30 -static base::TimeDelta ExtractStartTime(AVStream* stream) {
31 +static base::TimeDelta ExtractStartTime(AVStream* stream, int64_t first_dts) {
32    // The default start time is zero.
33    base::TimeDelta start_time;
34  
35 @@ -107,12 +107,12 @@ static base::TimeDelta ExtractStartTime(AVStream* stream) {
36  
37    // Next try to use the first DTS value, for codecs where we know PTS == DTS
38    // (excludes all H26x codecs). The start time must be returned in PTS.
39 -  if (av_stream_get_first_dts(stream) != kNoFFmpegTimestamp &&
40 +  if (first_dts != AV_NOPTS_VALUE &&
41        stream->codecpar->codec_id != AV_CODEC_ID_HEVC &&
42        stream->codecpar->codec_id != AV_CODEC_ID_H264 &&
43        stream->codecpar->codec_id != AV_CODEC_ID_MPEG4) {
44      const base::TimeDelta first_pts =
45 -        ConvertFromTimeBase(stream->time_base, av_stream_get_first_dts(stream));
46 +        ConvertFromTimeBase(stream->time_base, first_dts);
47      if (first_pts < start_time)
48        start_time = first_pts;
49    }
50 @@ -283,6 +283,7 @@ FFmpegDemuxerStream::FFmpegDemuxerStream(
51        fixup_negative_timestamps_(false),
52        fixup_chained_ogg_(false),
53        num_discarded_packet_warnings_(0),
54 +      first_dts_(AV_NOPTS_VALUE),
55        last_packet_pos_(AV_NOPTS_VALUE),
56        last_packet_dts_(AV_NOPTS_VALUE) {
57    DCHECK(demuxer_);
58 @@ -349,6 +350,10 @@ void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) {
59    int64_t packet_dts =
60        packet->dts == AV_NOPTS_VALUE ? packet->pts : packet->dts;
61  
62 +  if (first_dts_ == AV_NOPTS_VALUE) {
63 +    first_dts_ = packet_dts;
64 +  }
65 +
66    // Chained ogg files have non-monotonically increasing position and time stamp
67    // values, which prevents us from using them to determine if a packet should
68    // be dropped. Since chained ogg is only allowed on single track audio only
69 @@ -1442,7 +1447,8 @@ void FFmpegDemuxer::OnFindStreamInfoDone(int result) {
70  
71      max_duration = std::max(max_duration, streams_[i]->duration());
72  
73 -    base::TimeDelta start_time = ExtractStartTime(stream);
74 +    base::TimeDelta start_time =
75 +        ExtractStartTime(stream, streams_[i]->first_dts());
76  
77      // Note: This value is used for seeking, so we must take the true value and
78      // not the one possibly clamped to zero below.
79 diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h
80 index c147309d6f..48a8f6ad8c 100644
81 --- a/media/filters/ffmpeg_demuxer.h
82 +++ b/media/filters/ffmpeg_demuxer.h
83 @@ -151,6 +151,8 @@ class MEDIA_EXPORT FFmpegDemuxerStream : public DemuxerStream {
84    base::TimeDelta start_time() const { return start_time_; }
85    void set_start_time(base::TimeDelta time) { start_time_ = time; }
86  
87 +  int64_t first_dts() const { return first_dts_; }
88 +
89   private:
90    friend class FFmpegDemuxerTest;
91  
92 @@ -208,6 +210,7 @@ class MEDIA_EXPORT FFmpegDemuxerStream : public DemuxerStream {
93    bool fixup_chained_ogg_;
94  
95    int num_discarded_packet_warnings_;
96 +  int64_t first_dts_;
97    int64_t last_packet_pos_;
98    int64_t last_packet_dts_;
99  
100 -- 
101 2.35.1
102
This page took 0.126605 seconds and 3 git commands to generate.