From c7b36f2e75c9fd5839e42bbf3627b4ae47bc0f24 Mon Sep 17 00:00:00 2001 From: Shelly Lin Date: Fri, 4 Jul 2014 11:54:54 +0800 Subject: [PATCH] Bug 744896 - Part 3: Pass MediaInfo to functions MetadataLoaded and QueueMetadata. r=roc. --- .../html/content/public/HTMLMediaElement.h | 5 +--- content/html/content/src/HTMLMediaElement.cpp | 9 ++---- content/media/AbstractMediaDecoder.h | 28 +++++++++---------- content/media/BufferDecoder.cpp | 4 +-- content/media/BufferDecoder.h | 4 +-- content/media/MediaDecoder.cpp | 11 +++----- content/media/MediaDecoder.h | 10 ++----- content/media/MediaDecoderOwner.h | 5 +--- content/media/MediaDecoderStateMachine.cpp | 19 ++++--------- content/media/MediaDecoderStateMachine.h | 2 +- content/media/MediaMetadataManager.h | 21 +++++--------- content/media/ogg/OggReader.cpp | 20 ++++++------- content/media/omx/MediaOmxDecoder.cpp | 7 ++--- content/media/omx/MediaOmxDecoder.h | 5 +--- 14 files changed, 53 insertions(+), 97 deletions(-) diff --git a/content/html/content/public/HTMLMediaElement.h b/content/html/content/public/HTMLMediaElement.h index 5f5031db316..b928cf75929 100644 --- a/content/html/content/public/HTMLMediaElement.h +++ b/content/html/content/public/HTMLMediaElement.h @@ -151,10 +151,7 @@ public: // Called by the video decoder object, on the main thread, // when it has read the metadata containing video dimensions, // etc. - virtual void MetadataLoaded(int aChannels, - int aRate, - bool aHasAudio, - bool aHasVideo, + virtual void MetadataLoaded(const MediaInfo* aInfo, const MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE; // Called by the video decoder object, on the main thread, diff --git a/content/html/content/src/HTMLMediaElement.cpp b/content/html/content/src/HTMLMediaElement.cpp index 1690250d87c..d76e1cdfe44 100644 --- a/content/html/content/src/HTMLMediaElement.cpp +++ b/content/html/content/src/HTMLMediaElement.cpp @@ -2876,13 +2876,10 @@ void HTMLMediaElement::ProcessMediaFragmentURI() } } -void HTMLMediaElement::MetadataLoaded(int aChannels, - int aRate, - bool aHasAudio, - bool aHasVideo, +void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo, const MetadataTags* aTags) { - mHasAudio = aHasAudio; + mHasAudio = aInfo->HasAudio(); mTags = aTags; ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA); DispatchAsyncEvent(NS_LITERAL_STRING("durationchange")); @@ -2895,7 +2892,7 @@ void HTMLMediaElement::MetadataLoaded(int aChannels, // If this element had a video track, but consists only of an audio track now, // delete the VideoFrameContainer. This happens when the src is changed to an // audio only file. - if (!aHasVideo && mVideoFrameContainer) { + if (!aInfo->HasVideo() && mVideoFrameContainer) { // call ForgetElement() such that callbacks from |mVideoFrameContainer| // won't reach us anymore. mVideoFrameContainer->ForgetElement(); diff --git a/content/media/AbstractMediaDecoder.h b/content/media/AbstractMediaDecoder.h index 7f0d14397c3..27ee1262669 100644 --- a/content/media/AbstractMediaDecoder.h +++ b/content/media/AbstractMediaDecoder.h @@ -8,6 +8,7 @@ #define AbstractMediaDecoder_h_ #include "mozilla/Attributes.h" +#include "MediaInfo.h" #include "nsISupports.h" #include "nsDataHashtable.h" #include "nsThreadUtils.h" @@ -89,8 +90,8 @@ public: // Return true if the transport layer supports seeking. virtual bool IsMediaSeekable() = 0; - virtual void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) = 0; - virtual void QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) = 0; + virtual void MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) = 0; + virtual void QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags) = 0; // Set the media end time in microseconds virtual void SetMediaEndTime(int64_t aTime) = 0; @@ -136,30 +137,27 @@ public: }; }; -class AudioMetadataEventRunner : public nsRunnable +class MetadataEventRunner : public nsRunnable { private: nsRefPtr mDecoder; public: - AudioMetadataEventRunner(AbstractMediaDecoder* aDecoder, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) - : mDecoder(aDecoder), - mChannels(aChannels), - mRate(aRate), - mHasAudio(aHasAudio), - mHasVideo(aHasVideo), - mTags(aTags) + MetadataEventRunner(AbstractMediaDecoder* aDecoder, MediaInfo* aInfo, MetadataTags* aTags) + : mDecoder(aDecoder), + mInfo(aInfo), + mTags(aTags) {} NS_IMETHOD Run() MOZ_OVERRIDE { - mDecoder->MetadataLoaded(mChannels, mRate, mHasAudio, mHasVideo, mTags); + mDecoder->MetadataLoaded(mInfo, mTags); return NS_OK; } - int mChannels; - int mRate; - bool mHasAudio; - bool mHasVideo; + // The ownership is transferred to MediaDecoder. + MediaInfo* mInfo; + + // The ownership is transferred to its owning element. MetadataTags* mTags; }; diff --git a/content/media/BufferDecoder.cpp b/content/media/BufferDecoder.cpp index 16c5494b780..d6ea8d8c7d8 100644 --- a/content/media/BufferDecoder.cpp +++ b/content/media/BufferDecoder.cpp @@ -147,13 +147,13 @@ BufferDecoder::IsMediaSeekable() } void -BufferDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) +BufferDecoder::MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) { // ignore } void -BufferDecoder::QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) +BufferDecoder::QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags) { // ignore } diff --git a/content/media/BufferDecoder.h b/content/media/BufferDecoder.h index c44c5d33fd8..d82b15a55de 100644 --- a/content/media/BufferDecoder.h +++ b/content/media/BufferDecoder.h @@ -60,8 +60,8 @@ public: virtual bool IsMediaSeekable() MOZ_OVERRIDE; - virtual void MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) MOZ_OVERRIDE; - virtual void QueueMetadata(int64_t aTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) MOZ_OVERRIDE; + virtual void MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) MOZ_OVERRIDE; + virtual void QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags) MOZ_OVERRIDE; virtual void SetMediaEndTime(int64_t aTime) MOZ_OVERRIDE; diff --git a/content/media/MediaDecoder.cpp b/content/media/MediaDecoder.cpp index c50428e9e79..6dbdb2a306e 100644 --- a/content/media/MediaDecoder.cpp +++ b/content/media/MediaDecoder.cpp @@ -653,15 +653,12 @@ already_AddRefed MediaDecoder::GetCurrentPrincipal() } void MediaDecoder::QueueMetadata(int64_t aPublishTime, - int aChannels, - int aRate, - bool aHasAudio, - bool aHasVideo, + MediaInfo* aInfo, MetadataTags* aTags) { NS_ASSERTION(OnDecodeThread(), "Should be on decode thread."); GetReentrantMonitor().AssertCurrentThreadIn(); - mDecoderStateMachine->QueueMetadata(aPublishTime, aChannels, aRate, aHasAudio, aHasVideo, aTags); + mDecoderStateMachine->QueueMetadata(aPublishTime, aInfo, aTags); } bool @@ -672,7 +669,7 @@ MediaDecoder::IsDataCachedToEndOfResource() mResource->IsDataCachedToEndOfResource(mDecoderPosition)); } -void MediaDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags) +void MediaDecoder::MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) { MOZ_ASSERT(NS_IsMainThread()); if (mShuttingDown) { @@ -700,7 +697,7 @@ void MediaDecoder::MetadataLoaded(int aChannels, int aRate, bool aHasAudio, bool // Make sure the element and the frame (if any) are told about // our new size. Invalidate(); - mOwner->MetadataLoaded(aChannels, aRate, aHasAudio, aHasVideo, aTags); + mOwner->MetadataLoaded(aInfo, aTags); } if (!mCalledResourceLoaded) { diff --git a/content/media/MediaDecoder.h b/content/media/MediaDecoder.h index 0e15826a5db..84f67de4c13 100755 --- a/content/media/MediaDecoder.h +++ b/content/media/MediaDecoder.h @@ -751,10 +751,7 @@ public: // main thread to be presented when the |currentTime| of the media is greater // or equal to aPublishTime. void QueueMetadata(int64_t aPublishTime, - int aChannels, - int aRate, - bool aHasAudio, - bool aHasVideo, + MediaInfo* aInfo, MetadataTags* aTags); /****** @@ -777,10 +774,7 @@ public: // Called when the metadata from the media file has been loaded by the // state machine. Call on the main thread only. - virtual void MetadataLoaded(int aChannels, - int aRate, - bool aHasAudio, - bool aHasVideo, + virtual void MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags); // Called when the first frame has been loaded. diff --git a/content/media/MediaDecoderOwner.h b/content/media/MediaDecoderOwner.h index ae65a838e86..21cd007c451 100644 --- a/content/media/MediaDecoderOwner.h +++ b/content/media/MediaDecoderOwner.h @@ -49,10 +49,7 @@ public: // Called by the video decoder object, on the main thread, // when it has read the metadata containing video dimensions, // etc. - virtual void MetadataLoaded(int aChannels, - int aRate, - bool aHasAudio, - bool aHasVideo, + virtual void MetadataLoaded(const MediaInfo* aInfo, const MetadataTags* aTags) = 0; // Called by the video decoder object, on the main thread, diff --git a/content/media/MediaDecoderStateMachine.cpp b/content/media/MediaDecoderStateMachine.cpp index 5db4955a8d3..ad741664903 100644 --- a/content/media/MediaDecoderStateMachine.cpp +++ b/content/media/MediaDecoderStateMachine.cpp @@ -1983,13 +1983,10 @@ MediaDecoderStateMachine::FinishDecodeMetadata() } // Inform the element that we've loaded the metadata and the first frame. + nsAutoPtr info(new MediaInfo()); + *info = mInfo; nsCOMPtr metadataLoadedEvent = - new AudioMetadataEventRunner(mDecoder, - mInfo.mAudio.mChannels, - mInfo.mAudio.mRate, - HasAudio(), - HasVideo(), - mMetadataTags.forget()); + new MetadataEventRunner(mDecoder, info.forget(), mMetadataTags.forget()); NS_DispatchToMainThread(metadataLoadedEvent, NS_DISPATCH_NORMAL); if (mState == DECODER_STATE_DECODING_METADATA) { @@ -3098,20 +3095,14 @@ bool MediaDecoderStateMachine::IsShutdown() } void MediaDecoderStateMachine::QueueMetadata(int64_t aPublishTime, - int aChannels, - int aRate, - bool aHasAudio, - bool aHasVideo, + MediaInfo* aInfo, MetadataTags* aTags) { NS_ASSERTION(OnDecodeThread(), "Should be on decode thread."); AssertCurrentThreadInMonitor(); TimedMetadata* metadata = new TimedMetadata; metadata->mPublishTime = aPublishTime; - metadata->mChannels = aChannels; - metadata->mRate = aRate; - metadata->mHasAudio = aHasAudio; - metadata->mHasVideo = aHasVideo; + metadata->mInfo = aInfo; metadata->mTags = aTags; mMetadataManager.QueueMetadata(metadata); } diff --git a/content/media/MediaDecoderStateMachine.h b/content/media/MediaDecoderStateMachine.h index 9fb34c29e12..e4861096eec 100644 --- a/content/media/MediaDecoderStateMachine.h +++ b/content/media/MediaDecoderStateMachine.h @@ -323,7 +323,7 @@ public: // shutting down. The decoder monitor must be held while calling this. bool IsShutdown(); - void QueueMetadata(int64_t aPublishTime, int aChannels, int aRate, bool aHasAudio, bool aHasVideo, MetadataTags* aTags); + void QueueMetadata(int64_t aPublishTime, MediaInfo* aInfo, MetadataTags* aTags); // Returns true if we're currently playing. The decoder monitor must // be held. diff --git a/content/media/MediaMetadataManager.h b/content/media/MediaMetadataManager.h index 20ce3b63850..278f691a787 100644 --- a/content/media/MediaMetadataManager.h +++ b/content/media/MediaMetadataManager.h @@ -22,14 +22,10 @@ namespace mozilla { // The metadata. The ownership is transfered to the element when dispatching to // the main threads. nsAutoPtr mTags; - // The sample rate of this media. - int mRate; - // The number of channel of this media. - int mChannels; - // True if this media has an audio track. - bool mHasAudio; - // True if this media has a video track. - bool mHasVideo; + // The media info, including the info of audio tracks and video tracks. + // The ownership is transfered to MediaDecoder when dispatching to the + // main thread. + nsAutoPtr mInfo; }; // This class encapsulate the logic to give the metadata from the reader to @@ -51,12 +47,9 @@ namespace mozilla { TimedMetadata* metadata = mMetadataQueue.getFirst(); while (metadata && aCurrentTime >= static_cast(metadata->mPublishTime) / USECS_PER_S) { nsCOMPtr metadataUpdatedEvent = - new AudioMetadataEventRunner(aDecoder, - metadata->mChannels, - metadata->mRate, - metadata->mHasAudio, - metadata->mHasVideo, - metadata->mTags.forget()); + new MetadataEventRunner(aDecoder, + metadata->mInfo.forget(), + metadata->mTags.forget()); NS_DispatchToMainThread(metadataUpdatedEvent); delete mMetadataQueue.popFirst(); metadata = mMetadataQueue.getFirst(); diff --git a/content/media/ogg/OggReader.cpp b/content/media/ogg/OggReader.cpp index 353f70eb492..89f8ca9faa9 100644 --- a/content/media/ogg/OggReader.cpp +++ b/content/media/ogg/OggReader.cpp @@ -627,8 +627,6 @@ bool OggReader::ReadOggChain() OpusState* newOpusState = nullptr; #endif /* MOZ_OPUS */ VorbisState* newVorbisState = nullptr; - int channels = 0; - long rate = 0; MetadataTags* tags = nullptr; if (HasVideo() || HasSkeleton() || !HasAudio()) { @@ -673,6 +671,7 @@ bool OggReader::ReadOggChain() return false; } + nsAutoPtr info(new MediaInfo()); if ((newVorbisState && ReadHeaders(newVorbisState)) && (mVorbisState->mInfo.rate == newVorbisState->mInfo.rate) && (mVorbisState->mInfo.channels == newVorbisState->mInfo.channels)) { @@ -681,8 +680,8 @@ bool OggReader::ReadOggChain() mVorbisSerial = mVorbisState->mSerial; LOG(PR_LOG_DEBUG, ("New vorbis ogg link, serial=%d\n", mVorbisSerial)); chained = true; - rate = mVorbisState->mInfo.rate; - channels = mVorbisState->mInfo.channels; + info->mAudio.mRate = mVorbisState->mInfo.rate; + info->mAudio.mChannels = mVorbisState->mInfo.channels; tags = mVorbisState->GetTags(); } @@ -694,8 +693,8 @@ bool OggReader::ReadOggChain() mOpusState = newOpusState; mOpusSerial = mOpusState->mSerial; chained = true; - rate = mOpusState->mRate; - channels = mOpusState->mChannels; + info->mAudio.mRate = mOpusState->mRate; + info->mAudio.mChannels = mOpusState->mChannels; tags = mOpusState->GetTags(); } #endif @@ -703,13 +702,12 @@ bool OggReader::ReadOggChain() if (chained) { SetChained(true); { + info->mAudio.mHasAudio = HasAudio(); + info->mVideo.mHasVideo = HasVideo(); + int rate = info->mAudio.mRate; ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); mDecoder->QueueMetadata((mDecodedAudioFrames * USECS_PER_S) / rate, - channels, - rate, - HasAudio(), - HasVideo(), - tags); + info.forget(), tags); } return true; } diff --git a/content/media/omx/MediaOmxDecoder.cpp b/content/media/omx/MediaOmxDecoder.cpp index d179bc756f9..d21440fc82b 100755 --- a/content/media/omx/MediaOmxDecoder.cpp +++ b/content/media/omx/MediaOmxDecoder.cpp @@ -55,14 +55,11 @@ void MediaOmxDecoder::SetCanOffloadAudio(bool aCanOffloadAudio) mCanOffloadAudio = aCanOffloadAudio; } -void MediaOmxDecoder::MetadataLoaded(int aChannels, - int aRate, - bool aHasAudio, - bool aHasVideo, +void MediaOmxDecoder::MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) { MOZ_ASSERT(NS_IsMainThread()); - MediaDecoder::MetadataLoaded(aChannels, aRate, aHasAudio, aHasVideo, aTags); + MediaDecoder::MetadataLoaded(aInfo, aTags); ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); if (!mCanOffloadAudio || mFallbackToStateMachine || mOutputStreams.Length() || diff --git a/content/media/omx/MediaOmxDecoder.h b/content/media/omx/MediaOmxDecoder.h index c25de052b42..5d185074509 100755 --- a/content/media/omx/MediaOmxDecoder.h +++ b/content/media/omx/MediaOmxDecoder.h @@ -21,10 +21,7 @@ public: virtual MediaDecoder* Clone(); virtual MediaDecoderStateMachine* CreateStateMachine(); - virtual void MetadataLoaded(int aChannels, - int aRate, - bool aHasAudio, - bool aHasVideo, + virtual void MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags); virtual void ChangeState(PlayState aState); virtual void ApplyStateToStateMachine(PlayState aState);