From b3318288dc9806f278b129f7eafddd35868bfc71 Mon Sep 17 00:00:00 2001 From: Phil Ringnalda Date: Tue, 25 Nov 2014 21:57:42 -0800 Subject: [PATCH] Back out fe0fa358d7bc (bug 1102666) CLOSED TREE --- media/libstagefright/binding/DecoderData.cpp | 5 +- media/libstagefright/binding/MoofParser.cpp | 49 +++------------ .../binding/include/mp4_demuxer/ByteReader.h | 10 ---- .../binding/include/mp4_demuxer/DecoderData.h | 5 +- .../binding/include/mp4_demuxer/MoofParser.h | 16 +---- media/libstagefright/binding/mp4_demuxer.cpp | 4 +- .../av/include/media/stagefright/MetaData.h | 1 - .../media/libstagefright/MPEG4Extractor.cpp | 59 +++++++------------ .../libstagefright/include/MPEG4Extractor.h | 7 --- 9 files changed, 38 insertions(+), 118 deletions(-) diff --git a/media/libstagefright/binding/DecoderData.cpp b/media/libstagefright/binding/DecoderData.cpp index 2333d54beff..ae6ac214c96 100644 --- a/media/libstagefright/binding/DecoderData.cpp +++ b/media/libstagefright/binding/DecoderData.cpp @@ -131,7 +131,6 @@ TrackConfig::Update(sp& aMetaData, const char* aMimeType) // aMimeType points to a string from MediaDefs.cpp so we don't need to copy it mime_type = aMimeType; duration = FindInt64(aMetaData, kKeyDuration); - media_time = FindInt64(aMetaData, kKeyMediaTime); mTrackId = FindInt32(aMetaData, kKeyTrackID); crypto.Update(aMetaData); } @@ -216,11 +215,11 @@ MP4Sample::~MP4Sample() } void -MP4Sample::Update(int64_t& aMediaTime) +MP4Sample::Update() { sp m = mMediaBuffer->meta_data(); decode_timestamp = FindInt64(m, kKeyDecodingTime); - composition_timestamp = FindInt64(m, kKeyTime) - aMediaTime; + composition_timestamp = FindInt64(m, kKeyTime); duration = FindInt64(m, kKeyDuration); byte_offset = FindInt64(m, kKey64BitFileOffset); is_sync_point = FindInt32(m, kKeyIsSyncFrame); diff --git a/media/libstagefright/binding/MoofParser.cpp b/media/libstagefright/binding/MoofParser.cpp index 70ec122bcd0..f8243abd73f 100644 --- a/media/libstagefright/binding/MoofParser.cpp +++ b/media/libstagefright/binding/MoofParser.cpp @@ -22,7 +22,7 @@ MoofParser::RebuildFragmentedIndex(const nsTArray& aByteRanges) mInitRange = MediaByteRange(0, box.Range().mEnd); ParseMoov(box); } else if (box.IsType("moof")) { - Moof moof(box, mTrex, mMdhd, mEdts); + Moof moof(box, mTrex, mMdhd); if (!mMoofs.IsEmpty()) { // Stitch time ranges together in the case of a (hopefully small) time @@ -81,8 +81,6 @@ MoofParser::ParseTrak(Box& aBox) if (!mTrex.mTrackId || tkhd.mTrackId == mTrex.mTrackId) { ParseMdia(box, tkhd); } - } else if (box.IsType("edts")) { - mEdts = Edts(box); } } } @@ -110,18 +108,18 @@ MoofParser::ParseMvex(Box& aBox) } } -Moof::Moof(Box& aBox, Trex& aTrex, Mdhd& aMdhd, Edts& aEdts) : +Moof::Moof(Box& aBox, Trex& aTrex, Mdhd& aMdhd) : mRange(aBox.Range()), mMaxRoundingError(0) { for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) { if (box.IsType("traf")) { - ParseTraf(box, aTrex, aMdhd, aEdts); + ParseTraf(box, aTrex, aMdhd); } } } void -Moof::ParseTraf(Box& aBox, Trex& aTrex, Mdhd& aMdhd, Edts& aEdts) +Moof::ParseTraf(Box& aBox, Trex& aTrex, Mdhd& aMdhd) { Tfhd tfhd(aTrex); Tfdt tfdt; @@ -134,7 +132,7 @@ Moof::ParseTraf(Box& aBox, Trex& aTrex, Mdhd& aMdhd, Edts& aEdts) } } else if (box.IsType("trun")) { if (!aTrex.mTrackId || tfhd.mTrackId == aTrex.mTrackId) { - ParseTrun(box, tfhd, tfdt, aMdhd, aEdts); + ParseTrun(box, tfhd, tfdt, aMdhd); } } } @@ -163,7 +161,7 @@ public: }; void -Moof::ParseTrun(Box& aBox, Tfhd& aTfhd, Tfdt& aTfdt, Mdhd& aMdhd, Edts& aEdts) +Moof::ParseTrun(Box& aBox, Tfhd& aTfhd, Tfdt& aTfdt, Mdhd& aMdhd) { if (!aMdhd.mTimescale) { return; @@ -211,8 +209,8 @@ Moof::ParseTrun(Box& aBox, Tfhd& aTfhd, Tfdt& aTfdt, Mdhd& aMdhd, Edts& aEdts) offset += sampleSize; sample.mCompositionRange = Interval( - aMdhd.ToMicroseconds(decodeTime + ctsOffset - aEdts.mMediaStart), - aMdhd.ToMicroseconds(decodeTime + ctsOffset + sampleDuration - aEdts.mMediaStart)); + aMdhd.ToMicroseconds(decodeTime + ctsOffset), + aMdhd.ToMicroseconds(decodeTime + ctsOffset + sampleDuration)); decodeTime += sampleDuration; sample.mSync = !(sampleFlags & 0x1010000); @@ -330,35 +328,4 @@ Tfdt::Tfdt(Box& aBox) } reader->DiscardRemaining(); } - -Edts::Edts(Box& aBox) - : mMediaStart(0) -{ - Box child = aBox.FirstChild(); - if (!child.IsType("elst")) { - return; - } - - BoxReader reader(child); - uint32_t flags = reader->ReadU32(); - uint8_t version = flags >> 24; - - uint32_t entryCount = reader->ReadU32(); - NS_ASSERTION(entryCount == 1, "Can't handle videos with multiple edits"); - if (entryCount != 1) { - reader->DiscardRemaining(); - return; - } - - uint64_t segment_duration; - if (version == 1) { - segment_duration = reader->ReadU64(); - mMediaStart = reader->Read64(); - } else { - segment_duration = reader->ReadU32(); - mMediaStart = reader->Read32(); - } - NS_ASSERTION(segment_duration == 0, "Can't handle edits with fixed durations"); - reader->DiscardRemaining(); -} } diff --git a/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h b/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h index 51abd517dc1..297b379c607 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h +++ b/media/libstagefright/binding/include/mp4_demuxer/ByteReader.h @@ -96,16 +96,6 @@ public: return mozilla::BigEndian::readUint64(ptr); } - int64_t Read64() - { - auto ptr = Read(8); - if (!ptr) { - MOZ_ASSERT(false); - return 0; - } - return mozilla::BigEndian::readInt64(ptr); - } - const uint8_t* Read(size_t aCount) { if (aCount > mRemaining) { diff --git a/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h b/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h index 7ed3cf6d2a9..1c0823b473f 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h +++ b/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h @@ -78,11 +78,10 @@ public: class TrackConfig { public: - TrackConfig() : mime_type(nullptr), mTrackId(0), duration(0), media_time(0) {} + TrackConfig() : mime_type(nullptr), mTrackId(0), duration(0) {} const char* mime_type; uint32_t mTrackId; int64_t duration; - int64_t media_time; CryptoTrack crypto; void Update(stagefright::sp& aMetaData, @@ -145,7 +144,7 @@ class MP4Sample public: MP4Sample(); ~MP4Sample(); - void Update(int64_t& aMediaTime); + void Update(); void Pad(size_t aPaddingBytes); stagefright::MediaBuffer* mMediaBuffer; diff --git a/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h b/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h index f4f175762fc..629c0750ef6 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h +++ b/media/libstagefright/binding/include/mp4_demuxer/MoofParser.h @@ -96,15 +96,6 @@ public: uint64_t mBaseMediaDecodeTime; }; -class Edts -{ -public: - Edts() : mMediaStart(0) {} - explicit Edts(Box& aBox); - - int64_t mMediaStart; -}; - struct Sample { mozilla::MediaByteRange mByteRange; @@ -115,7 +106,7 @@ struct Sample class Moof { public: - Moof(Box& aBox, Trex& aTrex, Mdhd& aMdhd, Edts& aEdts); + Moof(Box& aBox, Trex& aTrex, Mdhd& aMdhd); void FixRounding(const Moof& aMoof); mozilla::MediaByteRange mRange; @@ -124,8 +115,8 @@ public: nsTArray mIndex; private: - void ParseTraf(Box& aBox, Trex& aTrex, Mdhd& aMdhd, Edts& aEdts); - void ParseTrun(Box& aBox, Tfhd& aTfhd, Tfdt& aTfdt, Mdhd& aMdhd, Edts& aEdts); + void ParseTraf(Box& aBox, Trex& aTrex, Mdhd& aMdhd); + void ParseTrun(Box& aBox, Tfhd& aTfhd, Tfdt& aTfdt, Mdhd& aMdhd); uint64_t mMaxRoundingError; }; @@ -155,7 +146,6 @@ public: Mdhd mMdhd; Trex mTrex; Tfdt mTfdt; - Edts mEdts; nsTArray mMoofs; }; } diff --git a/media/libstagefright/binding/mp4_demuxer.cpp b/media/libstagefright/binding/mp4_demuxer.cpp index 3a4e135673b..787509aed6d 100644 --- a/media/libstagefright/binding/mp4_demuxer.cpp +++ b/media/libstagefright/binding/mp4_demuxer.cpp @@ -173,7 +173,7 @@ MP4Demuxer::DemuxAudioSample() return nullptr; } - sample->Update(mAudioConfig.media_time); + sample->Update(); return sample.forget(); } @@ -190,7 +190,7 @@ MP4Demuxer::DemuxVideoSample() return nullptr; } - sample->Update(mVideoConfig.media_time); + sample->Update(); sample->prefix_data = mVideoConfig.annex_b; return sample.forget(); diff --git a/media/libstagefright/frameworks/av/include/media/stagefright/MetaData.h b/media/libstagefright/frameworks/av/include/media/stagefright/MetaData.h index 9c78a6948b3..30b40c8dfcd 100644 --- a/media/libstagefright/frameworks/av/include/media/stagefright/MetaData.h +++ b/media/libstagefright/frameworks/av/include/media/stagefright/MetaData.h @@ -77,7 +77,6 @@ enum { kKeyIsDRM = 'idrm', // int32_t (bool) kKeyEncoderDelay = 'encd', // int32_t (frames) kKeyEncoderPadding = 'encp', // int32_t (frames) - kKeyMediaTime = 'mtme', // int64_t (usecs) kKeyAlbum = 'albu', // cstring kKeyArtist = 'arti', // cstring diff --git a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp index a28bb6db4ca..a8417e8d554 100644 --- a/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp +++ b/media/libstagefright/frameworks/av/media/libstagefright/MPEG4Extractor.cpp @@ -838,8 +838,6 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) { track->includes_expensive_metadata = false; track->skipTrack = false; track->timescale = 0; - track->segment_duration = 0; - track->media_time = 0; track->meta->setCString(kKeyMIMEType, "application/octet-stream"); } @@ -912,10 +910,12 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) { ALOGW("ignoring edit list because timescale is 0"); } else { off64_t entriesoffset = data_offset + 8; + uint64_t segment_duration; + int64_t media_time; if (version == 1) { - if (!mDataSource->getUInt64(entriesoffset, &mLastTrack->segment_duration) || - !mDataSource->getUInt64(entriesoffset + 8, (uint64_t*)&mLastTrack->media_time)) { + if (!mDataSource->getUInt64(entriesoffset, &segment_duration) || + !mDataSource->getUInt64(entriesoffset + 8, (uint64_t*)&media_time)) { return ERROR_IO; } } else if (version == 0) { @@ -925,14 +925,28 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) { !mDataSource->getUInt32(entriesoffset + 4, (uint32_t*)&mt)) { return ERROR_IO; } - mLastTrack->segment_duration = sd; - mLastTrack->media_time = mt; + segment_duration = sd; + media_time = mt; } else { return ERROR_IO; } - storeEditList(); + uint64_t halfscale = mHeaderTimescale / 2; + segment_duration = (segment_duration * 1000000 + halfscale)/ mHeaderTimescale; + media_time = (media_time * 1000000 + halfscale) / mHeaderTimescale; + int64_t duration; + int32_t samplerate; + if (mLastTrack->meta->findInt64(kKeyDuration, &duration) && + mLastTrack->meta->findInt32(kKeySampleRate, &samplerate)) { + + int64_t delay = (media_time * samplerate + 500000) / 1000000; + mLastTrack->meta->setInt32(kKeyEncoderDelay, delay); + + int64_t paddingus = duration - (segment_duration + media_time); + int64_t paddingsamples = (paddingus * samplerate + 500000) / 1000000; + mLastTrack->meta->setInt32(kKeyEncoderPadding, paddingsamples); + } } *offset += chunk_size; break; @@ -1101,10 +1115,6 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) { mLastTrack->timescale = ntohl(timescale); - // Now that we've parsed the media timescale, we can interpret - // the edit list data. - storeEditList(); - int64_t duration = 0; if (version == 1) { if (mDataSource->readAt( @@ -1802,33 +1812,6 @@ status_t MPEG4Extractor::parseChunk(off64_t *offset, int depth) { return OK; } -void MPEG4Extractor::storeEditList() -{ - if (mHeaderTimescale == 0 || - mLastTrack->timescale == 0) { - return; - } - - uint64_t segment_duration = (mLastTrack->segment_duration * 1000000)/ mHeaderTimescale; - // media_time is measured in media time scale units. - int64_t media_time = (mLastTrack->media_time * 1000000) / mLastTrack->timescale; - - mLastTrack->meta->setInt64(kKeyMediaTime, media_time); - - int64_t duration; - int32_t samplerate; - if (mLastTrack->meta->findInt64(kKeyDuration, &duration) && - mLastTrack->meta->findInt32(kKeySampleRate, &samplerate)) { - - int64_t delay = (media_time * samplerate + 500000) / 1000000; - mLastTrack->meta->setInt32(kKeyEncoderDelay, delay); - - int64_t paddingus = duration - (segment_duration + media_time); - int64_t paddingsamples = (paddingus * samplerate + 500000) / 1000000; - mLastTrack->meta->setInt32(kKeyEncoderPadding, paddingsamples); - } -} - status_t MPEG4Extractor::parseSegmentIndex(off64_t offset, size_t size) { ALOGV("MPEG4Extractor::parseSegmentIndex"); diff --git a/media/libstagefright/frameworks/av/media/libstagefright/include/MPEG4Extractor.h b/media/libstagefright/frameworks/av/media/libstagefright/include/MPEG4Extractor.h index 9fcb99f2006..113152b1d8d 100644 --- a/media/libstagefright/frameworks/av/media/libstagefright/include/MPEG4Extractor.h +++ b/media/libstagefright/frameworks/av/media/libstagefright/include/MPEG4Extractor.h @@ -86,11 +86,6 @@ private: Track *next; sp meta; uint32_t timescale; - // Temporary storage for elst until we've - // parsed mdhd and can interpret them. - uint64_t segment_duration; - int64_t media_time; - sp sampleTable; bool includes_expensive_metadata; bool skipTrack; @@ -146,8 +141,6 @@ private: status_t parseSegmentIndex(off64_t data_offset, size_t data_size); - void storeEditList(); - Track *findTrackByMimePrefix(const char *mimePrefix); MPEG4Extractor(const MPEG4Extractor &);