forked from mirrors/gecko-dev
Backed out changeset 2c7d3f3cb9e8 (bug 1336271) on request for possible memory issues
This commit is contained in:
parent
c352d05b9b
commit
b5f09cc95b
2 changed files with 32 additions and 14 deletions
|
|
@ -148,7 +148,8 @@ MoofParser::BlockingReadNextMoof()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MoofParser::ScanForMetadata(mozilla::MediaByteRange& aMoov)
|
MoofParser::ScanForMetadata(mozilla::MediaByteRange& aFtyp,
|
||||||
|
mozilla::MediaByteRange& aMoov)
|
||||||
{
|
{
|
||||||
int64_t length = std::numeric_limits<int64_t>::max();
|
int64_t length = std::numeric_limits<int64_t>::max();
|
||||||
mSource->Length(&length);
|
mSource->Length(&length);
|
||||||
|
|
@ -156,38 +157,49 @@ MoofParser::ScanForMetadata(mozilla::MediaByteRange& aMoov)
|
||||||
byteRanges += MediaByteRange(0, length);
|
byteRanges += MediaByteRange(0, length);
|
||||||
RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
|
RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
|
||||||
|
|
||||||
mozilla::MediaByteRange initRange;
|
|
||||||
BoxContext context(stream, byteRanges);
|
BoxContext context(stream, byteRanges);
|
||||||
for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
|
for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
|
||||||
initRange = initRange.Span(box.Range());
|
if (box.IsType("ftyp")) {
|
||||||
|
aFtyp = box.Range();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (box.IsType("moov")) {
|
if (box.IsType("moov")) {
|
||||||
// mInitRange is from stream start position to end of moov.
|
aMoov = box.Range();
|
||||||
mInitRange = aMoov = initRange;
|
break;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mInitRange = aFtyp.Span(aMoov);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
MoofParser::HasMetadata()
|
MoofParser::HasMetadata()
|
||||||
{
|
{
|
||||||
|
MediaByteRange ftyp;
|
||||||
MediaByteRange moov;
|
MediaByteRange moov;
|
||||||
ScanForMetadata(moov);
|
ScanForMetadata(ftyp, moov);
|
||||||
return !!moov.Length();
|
return !!ftyp.Length() && !!moov.Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<mozilla::MediaByteBuffer>
|
already_AddRefed<mozilla::MediaByteBuffer>
|
||||||
MoofParser::Metadata()
|
MoofParser::Metadata()
|
||||||
{
|
{
|
||||||
|
MediaByteRange ftyp;
|
||||||
MediaByteRange moov;
|
MediaByteRange moov;
|
||||||
ScanForMetadata(moov);
|
ScanForMetadata(ftyp, moov);
|
||||||
|
CheckedInt<MediaByteBuffer::size_type> ftypLength = ftyp.Length();
|
||||||
CheckedInt<MediaByteBuffer::size_type> moovLength = moov.Length();
|
CheckedInt<MediaByteBuffer::size_type> moovLength = moov.Length();
|
||||||
if (!moovLength.isValid() || !moovLength.value()) {
|
if (!ftypLength.isValid() || !moovLength.isValid()
|
||||||
// No moov, or they cannot be used as array size.
|
|| !ftypLength.value() || !moovLength.value()) {
|
||||||
|
// No ftyp or moov, or they cannot be used as array size.
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
CheckedInt<MediaByteBuffer::size_type> totalLength = ftypLength + moovLength;
|
||||||
|
if (!totalLength.isValid()) {
|
||||||
|
// Addition overflow, or sum cannot be used as array size.
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
RefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
|
RefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
|
||||||
if (!metadata->SetLength(moovLength.value(), fallible)) {
|
if (!metadata->SetLength(totalLength.value(), fallible)) {
|
||||||
// OOM
|
// OOM
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +207,12 @@ MoofParser::Metadata()
|
||||||
RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
|
RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
|
||||||
size_t read;
|
size_t read;
|
||||||
bool rv =
|
bool rv =
|
||||||
stream->ReadAt(moov.mStart, metadata->Elements(), moovLength.value(), &read);
|
stream->ReadAt(ftyp.mStart, metadata->Elements(), ftypLength.value(), &read);
|
||||||
|
if (!rv || read != ftypLength.value()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
rv =
|
||||||
|
stream->ReadAt(moov.mStart, metadata->Elements() + ftypLength.value(), moovLength.value(), &read);
|
||||||
if (!rv || read != moovLength.value()) {
|
if (!rv || read != moovLength.value()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -299,7 +299,8 @@ public:
|
||||||
|
|
||||||
nsTArray<Moof>& Moofs() { return mMoofs; }
|
nsTArray<Moof>& Moofs() { return mMoofs; }
|
||||||
private:
|
private:
|
||||||
void ScanForMetadata(mozilla::MediaByteRange& aMoov);
|
void ScanForMetadata(mozilla::MediaByteRange& aFtyp,
|
||||||
|
mozilla::MediaByteRange& aMoov);
|
||||||
nsTArray<Moof> mMoofs;
|
nsTArray<Moof> mMoofs;
|
||||||
nsTArray<MediaByteRange> mMediaRanges;
|
nsTArray<MediaByteRange> mMediaRanges;
|
||||||
bool mIsAudio;
|
bool mIsAudio;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue