From f17c6eb49e556d803e9a7bcb2aade2fe77180521 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Tue, 7 Apr 2015 20:33:18 +1000 Subject: [PATCH] Bug 1151378: Part1. Remove of now unused code path. r=k17e libstagefright is now only used to read the metadata. --- media/libstagefright/binding/DecoderData.cpp | 71 ++------------- .../binding/include/mp4_demuxer/DecoderData.h | 4 - media/libstagefright/binding/mp4_demuxer.cpp | 86 ++++++------------- 3 files changed, 35 insertions(+), 126 deletions(-) diff --git a/media/libstagefright/binding/DecoderData.cpp b/media/libstagefright/binding/DecoderData.cpp index ee0d6ff7d5d6..05e409bb4ad2 100644 --- a/media/libstagefright/binding/DecoderData.cpp +++ b/media/libstagefright/binding/DecoderData.cpp @@ -8,7 +8,6 @@ #include "mp4_demuxer/DecoderData.h" #include #include "media/stagefright/MetaData.h" -#include "media/stagefright/MediaBuffer.h" #include "media/stagefright/MediaDefs.h" #include "media/stagefright/Utils.h" #include "mozilla/ArrayUtils.h" @@ -198,8 +197,7 @@ VideoDecoderConfig::IsValid() } MP4Sample::MP4Sample() - : mMediaBuffer(nullptr) - , decode_timestamp(0) + : decode_timestamp(0) , composition_timestamp(0) , duration(0) , byte_offset(0) @@ -232,26 +230,6 @@ MP4Sample::Clone() const MP4Sample::~MP4Sample() { - if (mMediaBuffer) { - mMediaBuffer->release(); - } -} - -void -MP4Sample::Update(int64_t& aMediaTime) -{ - sp m = mMediaBuffer->meta_data(); - // XXXbholley - Why don't we adjust decode_timestamp for aMediaTime? - // According to k17e, this code path is no longer used - we should probably remove it. - decode_timestamp = FindInt64(m, kKeyDecodingTime); - composition_timestamp = FindInt64(m, kKeyTime) - aMediaTime; - duration = FindInt64(m, kKeyDuration); - byte_offset = FindInt64(m, kKey64BitFileOffset); - is_sync_point = FindInt32(m, kKeyIsSyncFrame); - data = reinterpret_cast(mMediaBuffer->data()); - size = mMediaBuffer->range_length(); - - crypto.Update(m); } bool @@ -259,25 +237,14 @@ MP4Sample::Pad(size_t aPaddingBytes) { size_t newSize = size + aPaddingBytes; - // If the existing MediaBuffer has enough space then we just recycle it. If - // not then we copy to a new buffer. - uint8_t* newData = mMediaBuffer && newSize <= mMediaBuffer->size() - ? data - : new (fallible) uint8_t[newSize]; + uint8_t* newData = new (fallible) uint8_t[newSize]; if (!newData) { return false; } memset(newData + size, 0, aPaddingBytes); - - if (newData != data) { - memcpy(newData, data, size); - extra_buffer = data = newData; - if (mMediaBuffer) { - mMediaBuffer->release(); - mMediaBuffer = nullptr; - } - } + memcpy(newData, data, size); + extra_buffer = data = newData; return true; } @@ -287,11 +254,7 @@ MP4Sample::Prepend(const uint8_t* aData, size_t aSize) { size_t newSize = size + aSize; - // If the existing MediaBuffer has enough space then we just recycle it. If - // not then we copy to a new buffer. - uint8_t* newData = mMediaBuffer && newSize <= mMediaBuffer->size() - ? data - : new (fallible) uint8_t[newSize]; + uint8_t* newData = new (fallible) uint8_t[newSize]; if (!newData) { return false; } @@ -299,14 +262,7 @@ MP4Sample::Prepend(const uint8_t* aData, size_t aSize) memmove(newData + aSize, data, size); memmove(newData, aData, aSize); size = newSize; - - if (newData != data) { - extra_buffer = data = newData; - if (mMediaBuffer) { - mMediaBuffer->release(); - mMediaBuffer = nullptr; - } - } + extra_buffer = data = newData; return true; } @@ -314,25 +270,14 @@ MP4Sample::Prepend(const uint8_t* aData, size_t aSize) bool MP4Sample::Replace(const uint8_t* aData, size_t aSize) { - // If the existing MediaBuffer has enough space then we just recycle it. If - // not then we copy to a new buffer. - uint8_t* newData = mMediaBuffer && aSize <= mMediaBuffer->size() - ? data - : new (fallible) uint8_t[aSize]; + uint8_t* newData = new (fallible) uint8_t[aSize]; if (!newData) { return false; } memcpy(newData, aData, aSize); size = aSize; - - if (newData != data) { - extra_buffer = data = newData; - if (mMediaBuffer) { - mMediaBuffer->release(); - mMediaBuffer = nullptr; - } - } + extra_buffer = data = newData; return true; } diff --git a/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h b/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h index bb48a027e2ef..62b66657d32d 100644 --- a/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h +++ b/media/libstagefright/binding/include/mp4_demuxer/DecoderData.h @@ -17,7 +17,6 @@ namespace stagefright { template class sp; class MetaData; -class MediaBuffer; } namespace mp4_demuxer @@ -190,11 +189,8 @@ public: MP4Sample(); virtual ~MP4Sample(); MP4Sample* Clone() const; - void Update(int64_t& aMediaTime); bool Pad(size_t aPaddingBytes); - stagefright::MediaBuffer* mMediaBuffer; - Microseconds decode_timestamp; Microseconds composition_timestamp; Microseconds duration; diff --git a/media/libstagefright/binding/mp4_demuxer.cpp b/media/libstagefright/binding/mp4_demuxer.cpp index 316d95ac564c..c459b1b984ac 100644 --- a/media/libstagefright/binding/mp4_demuxer.cpp +++ b/media/libstagefright/binding/mp4_demuxer.cpp @@ -22,17 +22,16 @@ namespace mp4_demuxer struct StageFrightPrivate { - sp mExtractor; - + StageFrightPrivate() : mCanSeek(false) {} sp mAudio; - MediaSource::ReadOptions mAudioOptions; nsAutoPtr mAudioIterator; sp mVideo; - MediaSource::ReadOptions mVideoOptions; nsAutoPtr mVideoIterator; nsTArray> mIndexes; + + bool mCanSeek; }; class DataSourceAdapter : public DataSource @@ -79,7 +78,6 @@ MP4Demuxer::MP4Demuxer(Stream* source, Monitor* aMonitor) , mMonitor(aMonitor) , mNextKeyframeTime(-1) { - mPrivate->mExtractor = new MPEG4Extractor(new DataSourceAdapter(source)); } MP4Demuxer::~MP4Demuxer() @@ -96,7 +94,7 @@ bool MP4Demuxer::Init() { mMonitor->AssertCurrentThreadOwns(); - sp e = mPrivate->mExtractor; + sp e = new MPEG4Extractor(new DataSourceAdapter(mSource)); // Read the number of tracks. If we can't find any, make sure to bail now before // attempting any new reads to make the retry system work. @@ -148,6 +146,7 @@ MP4Demuxer::Init() // No duration were found in either tracks, use movie extend header box one. mVideoConfig.duration = mAudioConfig.duration = movieDuration; } + mPrivate->mCanSeek = e->flags() & MediaExtractor::CAN_SEEK; return mPrivate->mAudio.get() || mPrivate->mVideo.get(); } @@ -177,7 +176,7 @@ bool MP4Demuxer::CanSeek() { mMonitor->AssertCurrentThreadOwns(); - return mPrivate->mExtractor->flags() & MediaExtractor::CAN_SEEK; + return mPrivate->mCanSeek; } void @@ -186,9 +185,6 @@ MP4Demuxer::SeekAudio(Microseconds aTime) mMonitor->AssertCurrentThreadOwns(); if (mPrivate->mAudioIterator) { mPrivate->mAudioIterator->Seek(aTime); - } else { - mPrivate->mAudioOptions.setSeekTo( - aTime, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC); } } @@ -198,9 +194,6 @@ MP4Demuxer::SeekVideo(Microseconds aTime) mMonitor->AssertCurrentThreadOwns(); if (mPrivate->mVideoIterator) { mPrivate->mVideoIterator->Seek(aTime); - } else { - mPrivate->mVideoOptions.setSeekTo( - aTime, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC); } } @@ -208,29 +201,17 @@ MP4Sample* MP4Demuxer::DemuxAudioSample() { mMonitor->AssertCurrentThreadOwns(); - if (mPrivate->mAudioIterator) { - nsAutoPtr sample(mPrivate->mAudioIterator->GetNext()); - if (sample) { - if (sample->crypto.valid) { - sample->crypto.mode = mAudioConfig.crypto.mode; - sample->crypto.iv_size = mAudioConfig.crypto.iv_size; - sample->crypto.key.AppendElements(mAudioConfig.crypto.key); - } - } - return sample.forget(); - } - - nsAutoPtr sample(new MP4Sample()); - status_t status = - mPrivate->mAudio->read(&sample->mMediaBuffer, &mPrivate->mAudioOptions); - mPrivate->mAudioOptions.clearSeekTo(); - - if (status < 0) { + if (!mPrivate->mAudioIterator) { return nullptr; } - - sample->Update(mAudioConfig.media_time); - + nsAutoPtr sample(mPrivate->mAudioIterator->GetNext()); + if (sample) { + if (sample->crypto.valid) { + sample->crypto.mode = mAudioConfig.crypto.mode; + sample->crypto.iv_size = mAudioConfig.crypto.iv_size; + sample->crypto.key.AppendElements(mAudioConfig.crypto.key); + } + } return sample.forget(); } @@ -238,33 +219,20 @@ MP4Sample* MP4Demuxer::DemuxVideoSample() { mMonitor->AssertCurrentThreadOwns(); - if (mPrivate->mVideoIterator) { - nsAutoPtr sample(mPrivate->mVideoIterator->GetNext()); - if (sample) { - sample->extra_data = mVideoConfig.extra_data; - if (sample->crypto.valid) { - sample->crypto.mode = mVideoConfig.crypto.mode; - sample->crypto.key.AppendElements(mVideoConfig.crypto.key); - } - if (sample->composition_timestamp >= mNextKeyframeTime) { - mNextKeyframeTime = mPrivate->mVideoIterator->GetNextKeyframeTime(); - } - } - return sample.forget(); - } - - nsAutoPtr sample(new MP4Sample()); - status_t status = - mPrivate->mVideo->read(&sample->mMediaBuffer, &mPrivate->mVideoOptions); - mPrivate->mVideoOptions.clearSeekTo(); - - if (status < 0) { + if (!mPrivate->mVideoIterator) { return nullptr; } - - sample->Update(mVideoConfig.media_time); - sample->extra_data = mVideoConfig.extra_data; - + nsAutoPtr sample(mPrivate->mVideoIterator->GetNext()); + if (sample) { + sample->extra_data = mVideoConfig.extra_data; + if (sample->crypto.valid) { + sample->crypto.mode = mVideoConfig.crypto.mode; + sample->crypto.key.AppendElements(mVideoConfig.crypto.key); + } + if (sample->composition_timestamp >= mNextKeyframeTime) { + mNextKeyframeTime = mPrivate->mVideoIterator->GetNextKeyframeTime(); + } + } return sample.forget(); }