Bug 1378304. P3 - store MediaResource in MediaDecoderReader and replace the use of GetResource() with mResource. r=jya

Note MediaDecoderReader::GetBuffered() accesses mResource which is null
when it is actually a MediaFormatReader. However, it is OK for MediaFormatReader
will override UpdateBuffered() and will never call GetBuffered().

MozReview-Commit-ID: 5qcH4PHDzin

--HG--
extra : rebase_source : acb3ef2d981509a397045110cbb7cbecba8d5bee
extra : source : 5f66ecf33bfaecceaab8d9020175e26c5ca5cd1b
This commit is contained in:
JW Wang 2017-07-05 14:53:31 +08:00
Родитель ab6f636e4a
Коммит f913f097ee
6 изменённых файлов: 19 добавлений и 11 удалений

Просмотреть файл

@ -373,7 +373,7 @@ DecoderTraits::CreateReader(const MediaContainerType& aType,
#ifdef MOZ_ANDROID_OMX
if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
decoderReader = new AndroidMediaReader(aDecoder, aType);
decoderReader = new AndroidMediaReader(aDecoder, aType, aResource);
} else
#endif
if (WebMDecoder::IsSupportedType(aType)) {

Просмотреть файл

@ -68,7 +68,8 @@ public:
size_t mSize;
};
MediaDecoderReader::MediaDecoderReader(AbstractMediaDecoder* aDecoder)
MediaDecoderReader::MediaDecoderReader(AbstractMediaDecoder* aDecoder,
MediaResource* aResource)
: mAudioCompactor(mAudioQueue)
, mDecoder(aDecoder)
, mTaskQueue(new TaskQueue(
@ -81,6 +82,7 @@ MediaDecoderReader::MediaDecoderReader(AbstractMediaDecoder* aDecoder)
, mIgnoreAudioOutputFormat(false)
, mHitAudioDecodeError(false)
, mShutdown(false)
, mResource(aResource)
{
MOZ_COUNT_CTOR(MediaDecoderReader);
MOZ_ASSERT(NS_IsMainThread());
@ -206,7 +208,7 @@ MediaDecoderReader::GetBuffered()
{
MOZ_ASSERT(OnTaskQueue());
AutoPinned<MediaResource> stream(mDecoder->GetResource());
AutoPinned<MediaResource> stream(mResource);
if (!mDuration.Ref().isSome()) {
return TimeIntervals();

Просмотреть файл

@ -97,7 +97,8 @@ public:
// The caller must ensure that Shutdown() is called before aDecoder is
// destroyed.
explicit MediaDecoderReader(AbstractMediaDecoder* aDecoder);
explicit MediaDecoderReader(AbstractMediaDecoder* aDecoder,
MediaResource* aResource = nullptr);
// Initializes the reader, returns NS_OK on success, or NS_ERROR_FAILURE
// on failure.
@ -321,6 +322,8 @@ protected:
// Notify if we are waiting for a decryption key.
MediaEventProducer<TrackInfo::TrackType> mOnTrackWaitingForKey;
RefPtr<MediaResource> mResource;
private:
virtual nsresult InitInternal() { return NS_OK; }

Просмотреть файл

@ -19,7 +19,8 @@ AndroidMediaDecoder::AndroidMediaDecoder(MediaDecoderInit& aInit,
MediaDecoderStateMachine* AndroidMediaDecoder::CreateStateMachine()
{
return new MediaDecoderStateMachine(this, new AndroidMediaReader(this, mType));
return new MediaDecoderStateMachine(
this, new AndroidMediaReader(this, mType, mResource));
}
} // namespace mozilla

Просмотреть файл

@ -26,8 +26,9 @@ typedef mozilla::layers::Image Image;
typedef mozilla::layers::PlanarYCbCrImage PlanarYCbCrImage;
AndroidMediaReader::AndroidMediaReader(AbstractMediaDecoder *aDecoder,
const MediaContainerType& aContainerType) :
MediaDecoderReader(aDecoder),
const MediaContainerType& aContainerType,
MediaResource* aResource) :
MediaDecoderReader(aDecoder, aResource),
mType(aContainerType),
mPlugin(nullptr),
mHasAudio(false),
@ -43,7 +44,7 @@ nsresult AndroidMediaReader::ReadMetadata(MediaInfo* aInfo,
MOZ_ASSERT(OnTaskQueue());
if (!mPlugin) {
mPlugin = GetAndroidMediaPluginHost()->CreateDecoder(mDecoder->GetResource(), mType);
mPlugin = GetAndroidMediaPluginHost()->CreateDecoder(mResource, mType);
if (!mPlugin) {
return NS_ERROR_FAILURE;
}
@ -169,7 +170,7 @@ bool AndroidMediaReader::DecodeVideoFrame(bool& aKeyframeSkip,
return true;
currentImage = bufferCallback.GetImage();
int64_t pos = mDecoder->GetResource()->Tell();
int64_t pos = mResource->Tell();
IntRect picture = mPicture;
RefPtr<VideoData> v;
@ -274,7 +275,7 @@ bool AndroidMediaReader::DecodeAudioData()
MOZ_ASSERT(OnTaskQueue());
// This is the approximate byte position in the stream.
int64_t pos = mDecoder->GetResource()->Tell();
int64_t pos = mResource->Tell();
// Read next frame
MPAPI::AudioFrame source;

Просмотреть файл

@ -38,7 +38,8 @@ class AndroidMediaReader : public MediaDecoderReader
MozPromiseRequestHolder<MediaDecoderReader::VideoDataPromise> mSeekRequest;
public:
AndroidMediaReader(AbstractMediaDecoder* aDecoder,
const MediaContainerType& aContainerType);
const MediaContainerType& aContainerType,
MediaResource* aResource);
nsresult ResetDecode(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack,
TrackInfo::kVideoTrack)) override;