From c39201e0d2f5a19611ff020998e36765f95513af Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Mon, 9 Feb 2015 14:51:17 +0800 Subject: [PATCH] Bug 1129263 - Part 4. Use MediaInfo instead of mHasAudio/Video in media element. r=roc --- dom/html/HTMLMediaElement.cpp | 45 ++++++++++++++--------------------- dom/html/HTMLMediaElement.h | 17 +++++++++---- dom/html/HTMLVideoElement.cpp | 4 ++-- dom/media/MediaTrackList.h | 5 ++++ 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 26077f4575f4..beced9ed287d 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -685,8 +685,7 @@ void HTMLMediaElement::AbortExistingLoads() mHaveQueuedSelectResource = false; mSuspendedForPreloadNone = false; mDownloadSuspendedByCache = false; - mHasAudio = false; - mHasVideo = false; + mMediaInfo = MediaInfo(); mSourcePointer = nullptr; mLastNextFrameStatus = NEXT_FRAME_UNINITIALIZED; @@ -926,18 +925,13 @@ void HTMLMediaElement::NotifyMediaStreamTracksAvailable(DOMMediaStream* aStream) return; } - bool oldHasVideo = mHasVideo; + bool oldHasVideo = HasVideo(); - nsAutoTArray,1> audioTracks; - mSrcStream->GetAudioTracks(audioTracks); - nsAutoTArray,1> videoTracks; - mSrcStream->GetVideoTracks(videoTracks); + mMediaInfo.mAudio.mHasAudio = !AudioTracks()->IsEmpty(); + mMediaInfo.mVideo.mHasVideo = !VideoTracks()->IsEmpty(); - mHasAudio = !audioTracks.IsEmpty(); - mHasVideo = !videoTracks.IsEmpty(); - - if (IsVideo() && oldHasVideo != mHasVideo) { - // We are a video element and mHasVideo changed so update the screen wakelock + if (IsVideo() && oldHasVideo != HasVideo()) { + // We are a video element and HasVideo() changed so update the screen wakelock NotifyOwnerDocumentActivityChanged(); } @@ -1866,8 +1860,8 @@ HTMLMediaElement::CaptureStreamInternal(bool aFinishWhenEnded) OutputMediaStream* out = mOutputStreams.AppendElement(); uint8_t hints = 0; if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_METADATA) { - hints = (mHasAudio? DOMMediaStream::HINT_CONTENTS_AUDIO : 0) | - (mHasVideo? DOMMediaStream::HINT_CONTENTS_VIDEO : 0); + hints = (HasAudio()? DOMMediaStream::HINT_CONTENTS_AUDIO : 0) | + (HasVideo()? DOMMediaStream::HINT_CONTENTS_VIDEO : 0); } else { #ifdef DEBUG // Estimate hints based on the type of the media element @@ -2087,8 +2081,6 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed& aNo mSuspendedForPreloadNone(false), mMediaSecurityVerified(false), mCORSMode(CORS_NONE), - mHasAudio(false), - mHasVideo(false), mIsEncrypted(false), mDownloadSuspendedByCache(false), mAudioChannelFaded(false), @@ -3070,8 +3062,7 @@ void HTMLMediaElement::ProcessMediaFragmentURI() void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo, nsAutoPtr aTags) { - mHasAudio = aInfo->HasAudio(); - mHasVideo = aInfo->HasVideo(); + mMediaInfo = *aInfo; mIsEncrypted = aInfo->mIsEncrypted; mTags = aTags.forget(); mLoadedDataFired = false; @@ -3083,7 +3074,7 @@ void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo, } DispatchAsyncEvent(NS_LITERAL_STRING("durationchange")); - if (IsVideo() && mHasVideo) { + if (IsVideo() && HasVideo()) { mMediaSize = aInfo->mVideo.mDisplay; DispatchAsyncEvent(NS_LITERAL_STRING("resize")); } @@ -3094,8 +3085,8 @@ void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo, } // Tracks just got known, pass the info along to the output streams - uint8_t hints = (mHasAudio ? DOMMediaStream::HINT_CONTENTS_AUDIO : 0) | - (mHasVideo ? DOMMediaStream::HINT_CONTENTS_VIDEO : 0); + uint8_t hints = (HasAudio() ? DOMMediaStream::HINT_CONTENTS_AUDIO : 0) | + (HasVideo() ? DOMMediaStream::HINT_CONTENTS_VIDEO : 0); for (uint32_t i = 0; i < mOutputStreams.Length(); ++i) { OutputMediaStream* out = &mOutputStreams[i]; out->mStream->SetHintContents(hints); @@ -3401,17 +3392,17 @@ void HTMLMediaElement::UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatu } if (mSrcStream && mReadyState < nsIDOMHTMLMediaElement::HAVE_METADATA) { - if ((!mHasAudio && !mHasVideo) || - (IsVideo() && mHasVideo && mMediaSize == nsIntSize(-1, -1))) { + if ((!HasAudio() && !HasVideo()) || + (IsVideo() && HasVideo() && mMediaSize == nsIntSize(-1, -1))) { return; } // We are playing a stream that has video and a video frame is now set. // This means we have all metadata needed to change ready state. MediaInfo mediaInfo; - mediaInfo.mAudio.mHasAudio = mHasAudio; - mediaInfo.mVideo.mHasVideo = mHasVideo; - if (mHasVideo) { + mediaInfo.mAudio.mHasAudio = !AudioTracks()->IsEmpty(); + mediaInfo.mVideo.mHasVideo = !VideoTracks()->IsEmpty(); + if (mediaInfo.HasVideo()) { mediaInfo.mVideo.mDisplay = mMediaSize; } MetadataLoaded(&mediaInfo, nsAutoPtr(nullptr)); @@ -3422,7 +3413,7 @@ void HTMLMediaElement::UpdateReadyStateForData(MediaDecoderOwner::NextFrameStatu return; } - if (IsVideo() && mHasVideo && !IsPlaybackEnded() && + if (IsVideo() && HasVideo() && !IsPlaybackEnded() && GetImageContainer() && !GetImageContainer()->HasCurrentImage()) { // Don't advance if we are playing video, but don't have a video frame. // Also, if video became available after advancing to HAVE_CURRENT_DATA diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h index 8d583ef00fbb..1944dd1ebb49 100644 --- a/dom/html/HTMLMediaElement.h +++ b/dom/html/HTMLMediaElement.h @@ -408,6 +408,16 @@ public: double Duration() const; + bool HasAudio() const + { + return mMediaInfo.HasAudio(); + } + + bool HasVideo() const + { + return mMediaInfo.HasVideo(); + } + bool IsEncrypted() const { return mIsEncrypted; @@ -1300,11 +1310,8 @@ protected: // The CORS mode when loading the media element CORSMode mCORSMode; - // True if the media has an audio track - bool mHasAudio; - - // True if the media has a video track - bool mHasVideo; + // Info about the played media. + MediaInfo mMediaInfo; // True if the media has encryption information. bool mIsEncrypted; diff --git a/dom/html/HTMLVideoElement.cpp b/dom/html/HTMLVideoElement.cpp index 3ca0dddc3e55..8df0bf6024e5 100644 --- a/dom/html/HTMLVideoElement.cpp +++ b/dom/html/HTMLVideoElement.cpp @@ -179,7 +179,7 @@ double HTMLVideoElement::MozFrameDelay() bool HTMLVideoElement::MozHasAudio() const { MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread."); - return mHasAudio; + return HasAudio(); } JSObject* @@ -253,7 +253,7 @@ HTMLVideoElement::UpdateScreenWakeLock() return; } - if (!mScreenWakeLock && !mPaused && !hidden && mHasVideo) { + if (!mScreenWakeLock && !mPaused && !hidden && HasVideo()) { nsRefPtr pmService = power::PowerManagerService::GetInstance(); NS_ENSURE_TRUE_VOID(pmService); diff --git a/dom/media/MediaTrackList.h b/dom/media/MediaTrackList.h index ba2c2411567f..e7386f0b0941 100644 --- a/dom/media/MediaTrackList.h +++ b/dom/media/MediaTrackList.h @@ -106,6 +106,11 @@ public: MediaTrack* GetTrackById(const nsAString& aId); + bool IsEmpty() const + { + return mTracks.IsEmpty(); + } + uint32_t Length() const { return mTracks.Length();