зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1336271 - ignore ftyp box when parsing mp4 metadata. r=jya
MozReview-Commit-ID: IarGzXtmGQ2 --HG-- extra : rebase_source : 0926bda331f491f9b14ab8da18be29d1a1b5e6da
This commit is contained in:
Родитель
8e811ce9b6
Коммит
9006749e49
|
@ -148,8 +148,7 @@ MoofParser::BlockingReadNextMoof()
|
|||
}
|
||||
|
||||
void
|
||||
MoofParser::ScanForMetadata(mozilla::MediaByteRange& aFtyp,
|
||||
mozilla::MediaByteRange& aMoov)
|
||||
MoofParser::ScanForMetadata(mozilla::MediaByteRange& aMoov)
|
||||
{
|
||||
int64_t length = std::numeric_limits<int64_t>::max();
|
||||
mSource->Length(&length);
|
||||
|
@ -157,49 +156,38 @@ MoofParser::ScanForMetadata(mozilla::MediaByteRange& aFtyp,
|
|||
byteRanges += MediaByteRange(0, length);
|
||||
RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
|
||||
|
||||
mozilla::MediaByteRange initRange;
|
||||
BoxContext context(stream, byteRanges);
|
||||
for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
|
||||
if (box.IsType("ftyp")) {
|
||||
aFtyp = box.Range();
|
||||
continue;
|
||||
}
|
||||
initRange = initRange.Span(box.Range());
|
||||
if (box.IsType("moov")) {
|
||||
aMoov = box.Range();
|
||||
break;
|
||||
// mInitRange is from stream start position to end of moov.
|
||||
mInitRange = aMoov = initRange;
|
||||
return;
|
||||
}
|
||||
}
|
||||
mInitRange = aFtyp.Span(aMoov);
|
||||
}
|
||||
|
||||
bool
|
||||
MoofParser::HasMetadata()
|
||||
{
|
||||
MediaByteRange ftyp;
|
||||
MediaByteRange moov;
|
||||
ScanForMetadata(ftyp, moov);
|
||||
return !!ftyp.Length() && !!moov.Length();
|
||||
ScanForMetadata(moov);
|
||||
return !!moov.Length();
|
||||
}
|
||||
|
||||
already_AddRefed<mozilla::MediaByteBuffer>
|
||||
MoofParser::Metadata()
|
||||
{
|
||||
MediaByteRange ftyp;
|
||||
MediaByteRange moov;
|
||||
ScanForMetadata(ftyp, moov);
|
||||
CheckedInt<MediaByteBuffer::size_type> ftypLength = ftyp.Length();
|
||||
ScanForMetadata(moov);
|
||||
CheckedInt<MediaByteBuffer::size_type> moovLength = moov.Length();
|
||||
if (!ftypLength.isValid() || !moovLength.isValid()
|
||||
|| !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.
|
||||
if (!moovLength.isValid() || !moovLength.value()) {
|
||||
// No moov, or they cannot be used as array size.
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
|
||||
if (!metadata->SetLength(totalLength.value(), fallible)) {
|
||||
if (!metadata->SetLength(moovLength.value(), fallible)) {
|
||||
// OOM
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -207,12 +195,7 @@ MoofParser::Metadata()
|
|||
RefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
|
||||
size_t read;
|
||||
bool rv =
|
||||
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);
|
||||
stream->ReadAt(moov.mStart, metadata->Elements(), moovLength.value(), &read);
|
||||
if (!rv || read != moovLength.value()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -299,8 +299,7 @@ public:
|
|||
|
||||
nsTArray<Moof>& Moofs() { return mMoofs; }
|
||||
private:
|
||||
void ScanForMetadata(mozilla::MediaByteRange& aFtyp,
|
||||
mozilla::MediaByteRange& aMoov);
|
||||
void ScanForMetadata(mozilla::MediaByteRange& aMoov);
|
||||
nsTArray<Moof> mMoofs;
|
||||
nsTArray<MediaByteRange> mMediaRanges;
|
||||
bool mIsAudio;
|
||||
|
|
Загрузка…
Ссылка в новой задаче