Bug 1166836: Part2. Only rescans MP4's moof when necessary. r=cpearce

This commit is contained in:
Jean-Yves Avenard 2015-05-25 15:09:16 +10:00
Родитель c0532dc0aa
Коммит 097193a76b
2 изменённых файлов: 23 добавлений и 16 удалений

Просмотреть файл

@ -151,6 +151,7 @@ MP4TrackDemuxer::MP4TrackDemuxer(MP4Demuxer* aParent,
uint32_t aTrackNumber)
: mParent(aParent)
, mStream(new mp4_demuxer::ResourceStream(mParent->mResource))
, mNeedReIndex(true)
, mMonitor("MP4TrackDemuxer")
{
mInfo = mParent->mMetadata->GetTrackInfo(aType, aTrackNumber);
@ -176,6 +177,23 @@ MP4TrackDemuxer::GetInfo() const
return mInfo->Clone();
}
void
MP4TrackDemuxer::EnsureUpToDateIndex()
{
if (!mNeedReIndex) {
return;
}
AutoPinned<MediaResource> resource(mParent->mResource);
nsTArray<MediaByteRange> byteRanges;
nsresult rv = resource->GetCachedRanges(byteRanges);
if (NS_FAILED(rv)) {
return;
}
MonitorAutoLock mon(mMonitor);
mIndex->UpdateMoofIndex(byteRanges);
mNeedReIndex = false;
}
nsRefPtr<MP4TrackDemuxer::SeekPromise>
MP4TrackDemuxer::Seek(media::TimeUnit aTime)
{
@ -305,6 +323,7 @@ MP4TrackDemuxer::GetEvictionOffset(media::TimeUnit aTime)
media::TimeIntervals
MP4TrackDemuxer::GetBuffered()
{
EnsureUpToDateIndex();
AutoPinned<MediaResource> resource(mParent->mResource);
nsTArray<MediaByteRange> byteRanges;
nsresult rv = resource->GetCachedRanges(byteRanges);
@ -315,16 +334,9 @@ MP4TrackDemuxer::GetBuffered()
nsTArray<mp4_demuxer::Interval<int64_t>> timeRanges;
MonitorAutoLock mon(mMonitor);
int64_t endComposition =
mIndex->GetEndCompositionIfBuffered(byteRanges);
mIndex->ConvertByteRangesToTimeRanges(byteRanges, &timeRanges);
if (endComposition) {
mp4_demuxer::Interval<int64_t>::SemiNormalAppend(
timeRanges, mp4_demuxer::Interval<int64_t>(endComposition, endComposition));
}
// convert timeRanges.
media::TimeIntervals ranges;
media::TimeIntervals ranges = media::TimeIntervals();
for (size_t i = 0; i < timeRanges.Length(); i++) {
ranges +=
media::TimeInterval(media::TimeUnit::FromMicroseconds(timeRanges[i].start),
@ -336,14 +348,7 @@ MP4TrackDemuxer::GetBuffered()
void
MP4TrackDemuxer::NotifyDataArrived()
{
AutoPinned<MediaResource> resource(mParent->mResource);
nsTArray<MediaByteRange> byteRanges;
nsresult rv = resource->GetCachedRanges(byteRanges);
if (NS_FAILED(rv)) {
return;
}
MonitorAutoLock mon(mMonitor);
mIndex->UpdateMoofIndex(byteRanges);
mNeedReIndex = true;
}
void

Просмотреть файл

@ -85,6 +85,7 @@ private:
friend class MP4Demuxer;
void NotifyDataArrived();
void UpdateSamples(nsTArray<nsRefPtr<MediaRawData>>& aSamples);
void EnsureUpToDateIndex();
nsRefPtr<MP4Demuxer> mParent;
nsRefPtr<mp4_demuxer::Index> mIndex;
UniquePtr<mp4_demuxer::SampleIterator> mIterator;
@ -93,6 +94,7 @@ private:
Maybe<media::TimeUnit> mNextKeyframeTime;
// Queued samples extracted by the demuxer, but not yet returned.
nsRefPtr<MediaRawData> mQueuedSample;
bool mNeedReIndex;
// We do not actually need a monitor, however MoofParser will assert
// if a monitor isn't held.