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;