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.
chromium/chromium-119-ffmpeg-first_d...

95 lines
4.2 KiB

diff -up chromium-119.0.6045.105/media/filters/ffmpeg_demuxer.cc.first_dts chromium-119.0.6045.105/media/filters/ffmpeg_demuxer.cc
--- chromium-119.0.6045.105/media/filters/ffmpeg_demuxer.cc.first_dts 2023-11-01 19:10:31.000000000 +0100
+++ chromium-119.0.6045.105/media/filters/ffmpeg_demuxer.cc 2023-11-06 13:05:09.819011697 +0100
@@ -101,7 +101,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;
@@ -111,12 +111,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;
}
@@ -274,6 +274,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_);
@@ -336,6 +337,10 @@ void FFmpegDemuxerStream::EnqueuePacket(
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
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.
@@ -1604,7 +1610,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()) {
@@ -1625,7 +1631,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())
diff -up chromium-119.0.6045.105/media/filters/ffmpeg_demuxer.h.first_dts chromium-119.0.6045.105/media/filters/ffmpeg_demuxer.h
--- chromium-119.0.6045.105/media/filters/ffmpeg_demuxer.h.first_dts 2023-11-01 19:10:31.000000000 +0100
+++ chromium-119.0.6045.105/media/filters/ffmpeg_demuxer.h 2023-11-06 13:08:43.425784988 +0100
@@ -142,6 +142,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;
@@ -198,6 +200,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_;
// Requested buffer count. The actual returned buffer count could be less