You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.7 KiB
121 lines
4.7 KiB
1 year ago
|
From 2aef9000a1c8d76d3072365ffcb471ebffa20d3d Mon Sep 17 00:00:00 2001
|
||
|
From: Andreas Schneider <asn@cryptomilk.org>
|
||
|
Date: Tue, 15 Mar 2022 14:26:16 +0100
|
||
|
Subject: [PATCH] Track first_dts instead of using non-upstream functions
|
||
|
|
||
|
The function av_stream_get_first_dts() is not an upstream ffmpeg function and
|
||
|
is not available if you build with system ffmpeg. We can easily track the
|
||
|
first_dts on our own.
|
||
|
|
||
|
See also
|
||
|
https://ffmpeg.org/pipermail/ffmpeg-devel/2021-September/285401.html
|
||
|
|
||
|
Bug: 1306560
|
||
|
|
||
|
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
|
||
|
Change-Id: I90ba3cf2f2e16f56a0b405f26c67f911349fb71d
|
||
|
---
|
||
|
media/filters/ffmpeg_demuxer.cc | 18 ++++++++++++------
|
||
|
media/filters/ffmpeg_demuxer.h | 3 +++
|
||
|
3 files changed, 16 insertions(+), 6 deletions(-)
|
||
|
|
||
|
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
|
||
|
index 111899b661..799fc6e941 100644
|
||
|
--- a/media/filters/ffmpeg_demuxer.cc
|
||
|
+++ b/media/filters/ffmpeg_demuxer.cc
|
||
|
@@ -97,7 +97,7 @@ static base::TimeDelta FramesToTimeDelta(int frames, double sample_rate) {
|
||
|
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;
|
||
|
|
||
|
@@ -107,12 +107,12 @@ static base::TimeDelta ExtractStartTime(AVStream* stream) {
|
||
|
|
||
|
// 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;
|
||
|
}
|
||
|
@@ -283,6 +283,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_);
|
||
|
@@ -349,6 +350,10 @@ void FFmpegDemuxerStream::EnqueuePacket(ScopedAVPacket packet) {
|
||
|
int64_t packet_dts =
|
||
|
packet->dts == AV_NOPTS_VALUE ? packet->pts : packet->dts;
|
||
|
|
||
|
+ if (first_dts_ == AV_NOPTS_VALUE) {
|
||
|
+ first_dts_ = packet_dts;
|
||
|
+ }
|
||
|
+
|
||
|
// 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
|
||
|
@@ -1442,7 +1447,8 @@ void FFmpegDemuxer::OnFindStreamInfoDone(int result) {
|
||
|
|
||
|
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.
|
||
|
@@ -1599,7 +1605,7 @@ FFmpegDemuxerStream* FFmpegDemuxer::FindStreamWithLowestStartTimestamp(
|
||
|
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()) {
|
||
|
@@ -1620,7 +1626,7 @@ FFmpegDemuxerStream* FFmpegDemuxer::FindPreferredStreamForSeeking(
|
||
|
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())
|
||
|
diff --git a/media/filters/ffmpeg_demuxer.h b/media/filters/ffmpeg_demuxer.h
|
||
|
index c147309d6f..48a8f6ad8c 100644
|
||
|
--- a/media/filters/ffmpeg_demuxer.h
|
||
|
+++ b/media/filters/ffmpeg_demuxer.h
|
||
|
@@ -151,6 +151,8 @@ class MEDIA_EXPORT FFmpegDemuxerStream : public DemuxerStream {
|
||
|
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;
|
||
|
|
||
|
@@ -208,6 +210,7 @@ class MEDIA_EXPORT FFmpegDemuxerStream : public DemuxerStream {
|
||
|
bool fixup_chained_ogg_;
|
||
|
|
||
|
int num_discarded_packet_warnings_;
|
||
|
+ int64_t first_dts_;
|
||
|
int64_t last_packet_pos_;
|
||
|
int64_t last_packet_dts_;
|
||
|
};
|
||
|
--
|
||
|
2.35.1
|
||
|
|