Bug 1098126 - MoofParser fixes and disable for EME; r=mattwoodrow
--- a/dom/media/fmp4/MP4Reader.cpp
+++ b/dom/media/fmp4/MP4Reader.cpp
@@ -683,17 +683,19 @@ MP4Reader::PopSample(TrackType aTrack)
}
}
nsresult
MP4Reader::ResetDecode()
{
MOZ_ASSERT(GetTaskQueue()->IsCurrentThreadIn());
Flush(kVideo);
+ mDemuxer->SeekVideo(0);
Flush(kAudio);
+ mDemuxer->SeekAudio(0);
return MediaDecoderReader::ResetDecode();
}
void
MP4Reader::Output(TrackType aTrack, MediaData* aSample)
{
#ifdef LOG_SAMPLE_DECODE
VLOG("Decoded %s sample time=%lld dur=%lld",
--- a/media/libstagefright/binding/MoofParser.cpp
+++ b/media/libstagefright/binding/MoofParser.cpp
@@ -1,14 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mp4_demuxer/MoofParser.h"
#include "mp4_demuxer/Box.h"
+#include <limits>
namespace mp4_demuxer
{
using namespace stagefright;
using namespace mozilla;
void
@@ -67,20 +68,18 @@ public:
private:
nsRefPtr<Stream> mStream;
};
bool
MoofParser::BlockingReadNextMoof()
{
nsTArray<MediaByteRange> byteRanges;
- int64_t size;
- bool hasSize = mSource->Length(&size);
byteRanges.AppendElement(
- MediaByteRange(0,hasSize ? size : std::numeric_limits<int64_t>::max()));
+ MediaByteRange(0, std::numeric_limits<int64_t>::max()));
mp4_demuxer::BlockingStream* stream = new BlockingStream(mSource);
BoxContext context(stream, byteRanges);
for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
if (box.IsType("moof")) {
byteRanges.Clear();
byteRanges.AppendElement(MediaByteRange(mOffset, box.Range().mEnd));
RebuildFragmentedIndex(context);
@@ -329,17 +328,17 @@ Moof::ParseTrun(Box& aBox, Tfhd& aTfhd,
ctsOffset = reader->Read32();
}
}
Sample sample;
sample.mByteRange = MediaByteRange(offset, offset + sampleSize);
offset += sampleSize;
- sample.mDecodeTime = decodeTime;
+ sample.mDecodeTime = aMdhd.ToMicroseconds(decodeTime);
sample.mCompositionRange = Interval<Microseconds>(
aMdhd.ToMicroseconds((int64_t)decodeTime + ctsOffset - aEdts.mMediaStart),
aMdhd.ToMicroseconds((int64_t)decodeTime + ctsOffset + sampleDuration - aEdts.mMediaStart));
decodeTime += sampleDuration;
sample.mSync = !(sampleFlags & 0x1010000);
mIndex.AppendElement(sample);
--- a/media/libstagefright/binding/mp4_demuxer.cpp
+++ b/media/libstagefright/binding/mp4_demuxer.cpp
@@ -106,30 +106,30 @@ MP4Demuxer::Init()
if (track->start() != OK) {
return false;
}
mPrivate->mAudio = track;
mAudioConfig.Update(metaData, mimeType);
nsRefPtr<Index> index = new Index(mPrivate->mAudio->exportIndex(),
mSource, mAudioConfig.mTrackId);
mPrivate->mIndexes.AppendElement(index);
- if (index->IsFragmented()) {
+ if (index->IsFragmented() && !mAudioConfig.crypto.valid) {
mPrivate->mAudioIterator = new SampleIterator(index);
}
} else if (!mPrivate->mVideo.get() && !strncmp(mimeType, "video/", 6)) {
sp<MediaSource> track = e->getTrack(i);
if (track->start() != OK) {
return false;
}
mPrivate->mVideo = track;
mVideoConfig.Update(metaData, mimeType);
nsRefPtr<Index> index = new Index(mPrivate->mVideo->exportIndex(),
mSource, mVideoConfig.mTrackId);
mPrivate->mIndexes.AppendElement(index);
- if (index->IsFragmented()) {
+ if (index->IsFragmented() && !mVideoConfig.crypto.valid) {
mPrivate->mVideoIterator = new SampleIterator(index);
}
}
}
sp<MetaData> metaData = e->getMetaData();
mCrypto.Update(metaData);
return mPrivate->mAudio.get() || mPrivate->mVideo.get();