-
Notifications
You must be signed in to change notification settings - Fork 4
/
chromium-108-ffmpeg-first_dts.patch
130 lines (113 loc) · 5.47 KB
/
chromium-108-ffmpeg-first_dts.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
diff -up chromium-108.0.5359.124/AUTHORS.first_dts chromium-108.0.5359.124/AUTHORS
--- chromium-108.0.5359.124/AUTHORS.first_dts 2022-12-31 15:30:52.923006393 +0100
+++ chromium-108.0.5359.124/AUTHORS 2022-12-31 15:32:50.431215836 +0100
@@ -97,6 +97,7 @@ Andra Paraschiv <[email protected]
Andras Tokodi <[email protected]>
Andreas Nazlidis <[email protected]>
Andreas Papacharalampous <[email protected]>
+Andreas Schneider <[email protected]>
Andrei Borza <[email protected]>
Andrei Parvu <[email protected]>
Andrei Parvu <[email protected]>
diff -up chromium-108.0.5359.124/media/filters/ffmpeg_demuxer.cc.first_dts chromium-108.0.5359.124/media/filters/ffmpeg_demuxer.cc
--- chromium-108.0.5359.124/media/filters/ffmpeg_demuxer.cc.first_dts 2022-12-14 01:39:52.000000000 +0100
+++ chromium-108.0.5359.124/media/filters/ffmpeg_demuxer.cc 2022-12-31 15:30:52.923006393 +0100
@@ -58,7 +58,7 @@ namespace media {
namespace {
-constexpr int64_t kInvalidPTSMarker = static_cast<int64_t>(0x8000000000000000);
+constexpr int64_t kRelativeTsBase = static_cast<int64_t>(0x7ffeffffffffffff);
void SetAVStreamDiscard(AVStream* stream, AVDiscard discard) {
DCHECK(stream);
@@ -91,7 +91,7 @@ static base::TimeDelta FramesToTimeDelta
sample_rate);
}
-static base::TimeDelta ExtractStartTime(AVStream* stream) {
+static base::TimeDelta ExtractStartTime(AVStream* stream, int64_t first_dts) {
// The default start time is zero.
base::TimeDelta start_time;
@@ -101,12 +101,12 @@ static base::TimeDelta ExtractStartTime(
// Next try to use the first DTS value, for codecs where we know PTS == DTS
// (excludes all H26x codecs). The start time must be returned in PTS.
- if (av_stream_get_first_dts(stream) != kNoFFmpegTimestamp &&
+ if (first_dts != AV_NOPTS_VALUE &&
stream->codecpar->codec_id != AV_CODEC_ID_HEVC &&
stream->codecpar->codec_id != AV_CODEC_ID_H264 &&
stream->codecpar->codec_id != AV_CODEC_ID_MPEG4) {
const base::TimeDelta first_pts =
- ConvertFromTimeBase(stream->time_base, av_stream_get_first_dts(stream));
+ ConvertFromTimeBase(stream->time_base, first_dts);
if (first_pts < start_time)
start_time = first_pts;
}
@@ -275,6 +275,7 @@ FFmpegDemuxerStream::FFmpegDemuxerStream
fixup_negative_timestamps_(false),
fixup_chained_ogg_(false),
num_discarded_packet_warnings_(0),
+ first_dts_(AV_NOPTS_VALUE),
last_packet_pos_(AV_NOPTS_VALUE),
last_packet_dts_(AV_NOPTS_VALUE) {
DCHECK(demuxer_);
@@ -341,6 +342,11 @@ void FFmpegDemuxerStream::EnqueuePacket(
int64_t packet_dts =
packet->dts == AV_NOPTS_VALUE ? packet->pts : packet->dts;
+ if (first_dts_ == AV_NOPTS_VALUE && packet->dts != AV_NOPTS_VALUE &&
+ last_packet_dts_ != AV_NOPTS_VALUE) {
+ first_dts_ = packet->dts - (last_packet_dts_ + kRelativeTsBase);
+ }
+
// Chained ogg files have non-monotonically increasing position and time stamp
// values, which prevents us from using them to determine if a packet should
// be dropped. Since chained ogg is only allowed on single track audio only
@@ -683,6 +689,7 @@ void FFmpegDemuxerStream::FlushBuffers(b
ResetBitstreamConverter();
if (!preserve_packet_position) {
+ first_dts_ = AV_NOPTS_VALUE;
last_packet_pos_ = AV_NOPTS_VALUE;
last_packet_dts_ = AV_NOPTS_VALUE;
}
@@ -1434,7 +1441,8 @@ void FFmpegDemuxer::OnFindStreamInfoDone
max_duration = std::max(max_duration, streams_[i]->duration());
- base::TimeDelta start_time = ExtractStartTime(stream);
+ base::TimeDelta start_time =
+ ExtractStartTime(stream, streams_[i]->first_dts());
// Note: This value is used for seeking, so we must take the true value and
// not the one possibly clamped to zero below.
@@ -1591,7 +1599,7 @@ FFmpegDemuxerStream* FFmpegDemuxer::Find
for (const auto& stream : streams_) {
if (!stream || stream->IsEnabled() != enabled)
continue;
- if (av_stream_get_first_dts(stream->av_stream()) == kInvalidPTSMarker)
+ if (stream->first_dts() == AV_NOPTS_VALUE)
continue;
if (!lowest_start_time_stream ||
stream->start_time() < lowest_start_time_stream->start_time()) {
@@ -1612,7 +1620,7 @@ FFmpegDemuxerStream* FFmpegDemuxer::Find
if (stream->type() != DemuxerStream::VIDEO)
continue;
- if (av_stream_get_first_dts(stream->av_stream()) == kInvalidPTSMarker)
+ if (stream->first_dts() == AV_NOPTS_VALUE)
continue;
if (!stream->IsEnabled())
@@ -1926,4 +1934,4 @@ void FFmpegDemuxer::RunPendingSeekCB(Pip
std::move(pending_seek_cb_).Run(status);
}
-} // namespace media
+} // namespace media
\ Kein Zeilenumbruch am Dateiende.
diff -up chromium-108.0.5359.124/media/filters/ffmpeg_demuxer.h.first_dts chromium-108.0.5359.124/media/filters/ffmpeg_demuxer.h
--- chromium-108.0.5359.124/media/filters/ffmpeg_demuxer.h.first_dts 2022-12-14 01:39:52.000000000 +0100
+++ chromium-108.0.5359.124/media/filters/ffmpeg_demuxer.h 2022-12-31 15:30:52.924006403 +0100
@@ -145,6 +145,8 @@ class MEDIA_EXPORT FFmpegDemuxerStream :
base::TimeDelta start_time() const { return start_time_; }
void set_start_time(base::TimeDelta time) { start_time_ = time; }
+ int64_t first_dts() const { return first_dts_; }
+
private:
friend class FFmpegDemuxerTest;
@@ -202,6 +204,7 @@ class MEDIA_EXPORT FFmpegDemuxerStream :
bool fixup_chained_ogg_;
int num_discarded_packet_warnings_;
+ int64_t first_dts_;
int64_t last_packet_pos_;
int64_t last_packet_dts_;
};