зеркало из https://github.com/mozilla/gecko-dev.git
Revert "Bug 1196398: [mp4] Do not allocate memory spanning across ftyp and moov atom. r=kentuckyfriedtakahe"
This reverts commit 73156610be5f
This commit is contained in:
Родитель
600ae4f2bf
Коммит
af3e91f01a
|
@ -79,16 +79,22 @@ MP4Demuxer::Init()
|
|||
AutoPinned<mp4_demuxer::ResourceStream> stream(mStream);
|
||||
|
||||
// Check that we have enough data to read the metadata.
|
||||
if (!mp4_demuxer::MP4Metadata::HasCompleteMetadata(stream)) {
|
||||
MediaByteRange br = mp4_demuxer::MP4Metadata::MetadataRange(stream);
|
||||
if (br.IsNull()) {
|
||||
return InitPromise::CreateAndReject(DemuxerFailureReason::WAITING_FOR_DATA, __func__);
|
||||
}
|
||||
|
||||
mInitData = mp4_demuxer::MP4Metadata::Metadata(stream);
|
||||
if (!mInitData) {
|
||||
if (!mInitData->SetLength(br.Length(), fallible)) {
|
||||
// OOM
|
||||
return InitPromise::CreateAndReject(DemuxerFailureReason::DEMUXER_ERROR, __func__);
|
||||
}
|
||||
|
||||
size_t size;
|
||||
mStream->ReadAt(br.mStart, mInitData->Elements(), br.Length(), &size);
|
||||
if (size != size_t(br.Length())) {
|
||||
return InitPromise::CreateAndReject(DemuxerFailureReason::DEMUXER_ERROR, __func__);
|
||||
}
|
||||
|
||||
nsRefPtr<mp4_demuxer::BufferStream> bufferstream =
|
||||
new mp4_demuxer::BufferStream(mInitData);
|
||||
|
||||
|
|
|
@ -287,14 +287,17 @@ MP4Metadata::HasCompleteMetadata(Stream* aSource)
|
|||
return parser->HasMetadata();
|
||||
}
|
||||
|
||||
/*static*/ already_AddRefed<MediaByteBuffer>
|
||||
MP4Metadata::Metadata(Stream* aSource)
|
||||
/*static*/ mozilla::MediaByteRange
|
||||
MP4Metadata::MetadataRange(Stream* aSource)
|
||||
{
|
||||
// The MoofParser requires a monitor, but we don't need one here.
|
||||
mozilla::Monitor monitor("MP4Metadata::HasCompleteMetadata");
|
||||
mozilla::MonitorAutoLock mon(monitor);
|
||||
auto parser = mozilla::MakeUnique<MoofParser>(aSource, 0, false, &monitor);
|
||||
return parser->Metadata();
|
||||
if (parser->HasMetadata()) {
|
||||
return parser->mInitRange;
|
||||
}
|
||||
return mozilla::MediaByteRange();
|
||||
}
|
||||
|
||||
} // namespace mp4_demuxer
|
||||
|
|
|
@ -148,9 +148,8 @@ MoofParser::BlockingReadNextMoof()
|
|||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
MoofParser::ScanForMetadata(mozilla::MediaByteRange& aFtyp,
|
||||
mozilla::MediaByteRange& aMoov)
|
||||
bool
|
||||
MoofParser::HasMetadata()
|
||||
{
|
||||
int64_t length = std::numeric_limits<int64_t>::max();
|
||||
mSource->Length(&length);
|
||||
|
@ -158,57 +157,24 @@ MoofParser::ScanForMetadata(mozilla::MediaByteRange& aFtyp,
|
|||
byteRanges.AppendElement(MediaByteRange(0, length));
|
||||
nsRefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
|
||||
|
||||
MediaByteRange ftyp;
|
||||
MediaByteRange moov;
|
||||
BoxContext context(stream, byteRanges);
|
||||
for (Box box(&context, mOffset); box.IsAvailable(); box = box.Next()) {
|
||||
if (box.IsType("ftyp")) {
|
||||
aFtyp = box.Range();
|
||||
ftyp = box.Range();
|
||||
continue;
|
||||
}
|
||||
if (box.IsType("moov")) {
|
||||
aMoov = box.Range();
|
||||
moov = box.Range();
|
||||
break;
|
||||
}
|
||||
}
|
||||
mInitRange = aFtyp.Extents(aMoov);
|
||||
}
|
||||
|
||||
bool
|
||||
MoofParser::HasMetadata()
|
||||
{
|
||||
MediaByteRange ftyp;
|
||||
MediaByteRange moov;
|
||||
ScanForMetadata(ftyp, moov);
|
||||
return !!ftyp.Length() && !!moov.Length();
|
||||
}
|
||||
|
||||
already_AddRefed<MediaByteBuffer>
|
||||
MoofParser::Metadata()
|
||||
{
|
||||
MediaByteRange ftyp;
|
||||
MediaByteRange moov;
|
||||
ScanForMetadata(ftyp, moov);
|
||||
if (!ftyp.Length() || !moov.Length()) {
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
nsRefPtr<MediaByteBuffer> metadata = new MediaByteBuffer();
|
||||
if (!metadata->SetLength(ftyp.Length() + moov.Length(), fallible)) {
|
||||
// OOM
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<mp4_demuxer::BlockingStream> stream = new BlockingStream(mSource);
|
||||
size_t read;
|
||||
bool rv =
|
||||
stream->ReadAt(ftyp.mStart, metadata->Elements(), ftyp.Length(), &read);
|
||||
if (!rv || read != ftyp.Length()) {
|
||||
return nullptr;
|
||||
}
|
||||
rv =
|
||||
stream->ReadAt(moov.mStart, metadata->Elements() + ftyp.Length(), moov.Length(), &read);
|
||||
if (!rv || read != moov.Length()) {
|
||||
return nullptr;
|
||||
}
|
||||
return metadata.forget();
|
||||
mInitRange = ftyp.Extents(moov);
|
||||
return true;
|
||||
}
|
||||
|
||||
Interval<Microseconds>
|
||||
|
|
|
@ -30,7 +30,7 @@ public:
|
|||
~MP4Metadata();
|
||||
|
||||
static bool HasCompleteMetadata(Stream* aSource);
|
||||
static already_AddRefed<MediaByteBuffer> Metadata(Stream* aSource);
|
||||
static mozilla::MediaByteRange MetadataRange(Stream* aSource);
|
||||
uint32_t GetNumberTracks(mozilla::TrackInfo::TrackType aType) const;
|
||||
mozilla::UniquePtr<mozilla::TrackInfo> GetTrackInfo(mozilla::TrackInfo::TrackType aType,
|
||||
size_t aTrackNumber) const;
|
||||
|
|
|
@ -228,7 +228,6 @@ public:
|
|||
|
||||
bool BlockingReadNextMoof();
|
||||
bool HasMetadata();
|
||||
already_AddRefed<MediaByteBuffer> Metadata();
|
||||
MediaByteRange FirstCompleteMediaSegment();
|
||||
MediaByteRange FirstCompleteMediaHeader();
|
||||
|
||||
|
@ -245,8 +244,6 @@ public:
|
|||
Monitor* mMonitor;
|
||||
nsTArray<Moof>& Moofs() { mMonitor->AssertCurrentThreadOwns(); return mMoofs; }
|
||||
private:
|
||||
void ScanForMetadata(mozilla::MediaByteRange& aFtyp,
|
||||
mozilla::MediaByteRange& aMoov);
|
||||
nsTArray<Moof> mMoofs;
|
||||
nsTArray<MediaByteRange> mMediaRanges;
|
||||
bool mIsAudio;
|
||||
|
|
Загрузка…
Ссылка в новой задаче