From 5d2aa966ca732037aba345d7a60f3bbe600e22d3 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Tue, 6 Sep 2016 17:23:38 +1000 Subject: [PATCH] Bug 1300703: [webm] Use default duration if known. r=kinetik MozReview-Commit-ID: J18IdDGkL62 --HG-- extra : rebase_source : fa1e1fdba214f0a0f70656f0523bc76f2cfe5662 --- dom/media/webm/WebMDemuxer.cpp | 26 ++++++++++++++++++++++++-- dom/media/webm/WebMDemuxer.h | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dom/media/webm/WebMDemuxer.cpp b/dom/media/webm/WebMDemuxer.cpp index ae729ff541eb..375dd0466edd 100644 --- a/dom/media/webm/WebMDemuxer.cpp +++ b/dom/media/webm/WebMDemuxer.cpp @@ -355,6 +355,13 @@ WebMDemuxer::ReadMetadata() continue; } + uint64_t defaultDuration; + r = nestegg_track_default_duration(context, track, &defaultDuration); + if (r >= 0) { + mVideoDefaultDuration = + Some(uint64_t(media::TimeUnit::FromNanoseconds(defaultDuration).ToMicroseconds())); + } + mVideoTrack = track; mHasVideo = true; @@ -395,6 +402,13 @@ WebMDemuxer::ReadMetadata() return NS_ERROR_FAILURE; } + uint64_t defaultDuration; + r = nestegg_track_default_duration(context, track, &defaultDuration); + if (r >= 0) { + mAudioDefaultDuration = + Some(uint64_t(media::TimeUnit::FromNanoseconds(defaultDuration).ToMicroseconds())); + } + mAudioTrack = track; mHasAudio = true; mAudioCodec = nestegg_track_codec_id(context, track); @@ -587,7 +601,11 @@ WebMDemuxer::GetNextPacket(TrackInfo::TrackType aType, MediaRawDataQueue *aSampl } else if (!mIsMediaSource || (mIsMediaSource && mLastAudioFrameTime.isSome())) { next_tstamp = tstamp; - next_tstamp += tstamp - mLastAudioFrameTime.refOr(0); + if (mAudioDefaultDuration.isSome()) { + next_tstamp += mAudioDefaultDuration.ref(); + } else { + next_tstamp += tstamp - mLastAudioFrameTime.refOr(0); + } } else { PushAudioPacket(holder); } @@ -602,7 +620,11 @@ WebMDemuxer::GetNextPacket(TrackInfo::TrackType aType, MediaRawDataQueue *aSampl } else if (!mIsMediaSource || (mIsMediaSource && mLastVideoFrameTime.isSome())) { next_tstamp = tstamp; - next_tstamp += tstamp - mLastVideoFrameTime.refOr(0); + if (mVideoDefaultDuration.isSome()) { + next_tstamp += mVideoDefaultDuration.ref(); + } else { + next_tstamp += tstamp - mLastVideoFrameTime.refOr(0); + } } else { PushVideoPacket(holder); } diff --git a/dom/media/webm/WebMDemuxer.h b/dom/media/webm/WebMDemuxer.h index 6fff38e7dc35..4fa89cbb8f8a 100644 --- a/dom/media/webm/WebMDemuxer.h +++ b/dom/media/webm/WebMDemuxer.h @@ -220,6 +220,8 @@ private: // previous frame's timestamp. In NS. Maybe mLastAudioFrameTime; Maybe mLastVideoFrameTime; + Maybe mAudioDefaultDuration; + Maybe mVideoDefaultDuration; // Codec ID of audio track int mAudioCodec;