Bug 1124491 - Add HTMLMediaElement.isEncrypted attribute - r=cpearce,bz
authorEdwin Flores <edwin@mozilla.com>
Tue, 27 Jan 2015 19:10:11 +1300
changeset 225966 c14c7a032bf70ec45f33c35054c04624cef6d0df
parent 225965 0eca2ce01266a27a6a324b53fa7415c2cea875a6
child 225967 7820fd1419980e83985329f060d6b8a50f2d6b8d
push id28179
push usercbook@mozilla.com
push dateTue, 27 Jan 2015 14:24:11 +0000
treeherdermozilla-central@232401a6d1cc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, bz
bugs1124491
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1124491 - Add HTMLMediaElement.isEncrypted attribute - r=cpearce,bz
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
dom/media/MediaInfo.h
dom/media/fmp4/MP4Reader.cpp
dom/media/mediasource/MediaSourceReader.cpp
dom/webidl/HTMLMediaElement.webidl
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2064,16 +2064,17 @@ HTMLMediaElement::HTMLMediaElement(alrea
     mHasPlayedOrSeeked(false),
     mHasSelfReference(false),
     mShuttingDown(false),
     mSuspendedForPreloadNone(false),
     mMediaSecurityVerified(false),
     mCORSMode(CORS_NONE),
     mHasAudio(false),
     mHasVideo(false),
+    mIsEncrypted(false),
     mDownloadSuspendedByCache(false),
     mAudioChannelFaded(false),
     mPlayingThroughTheAudioChannel(false),
     mDisableVideo(false),
     mWaitingFor(MediaWaitingFor::None),
     mElementInTreeState(ELEMENT_NOT_INTREE)
 {
 #ifdef PR_LOGGING
@@ -2998,16 +2999,17 @@ void HTMLMediaElement::ProcessMediaFragm
   }
 }
 
 void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo,
                                       nsAutoPtr<const MetadataTags> aTags)
 {
   mHasAudio = aInfo->HasAudio();
   mHasVideo = aInfo->HasVideo();
+  mIsEncrypted = aInfo->mIsEncrypted;
   mTags = aTags.forget();
   mLoadedDataFired = false;
   ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
   DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
   if (IsVideo() && mHasVideo) {
     mMediaSize = aInfo->mVideo.mDisplay;
     DispatchAsyncEvent(NS_LITERAL_STRING("resize"));
   }
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -406,16 +406,21 @@ public:
   double CurrentTime() const;
 
   void SetCurrentTime(double aCurrentTime, ErrorResult& aRv);
 
   void FastSeek(double aTime, ErrorResult& aRv);
 
   double Duration() const;
 
+  bool IsEncrypted() const
+  {
+    return mIsEncrypted;
+  }
+
   bool Paused() const
   {
     return mPaused;
   }
 
   double DefaultPlaybackRate() const
   {
     return mDefaultPlaybackRate;
@@ -1293,16 +1298,19 @@ protected:
   CORSMode mCORSMode;
 
   // True if the media has an audio track
   bool mHasAudio;
 
   // True if the media has a video track
   bool mHasVideo;
 
+  // True if the media has encryption information.
+  bool mIsEncrypted;
+
   // True if the media's channel's download has been suspended.
   bool mDownloadSuspendedByCache;
 
   // Audio Channel.
   AudioChannel mAudioChannel;
 
   // The audio channel has been faded.
   bool mAudioChannelFaded;
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -83,31 +83,35 @@ public:
   // True if we have an active audio bitstream.
   bool mHasAudio;
 
   TrackInfo mTrackInfo;
 };
 
 class MediaInfo {
 public:
+  MediaInfo() : mIsEncrypted(false) {}
+
   bool HasVideo() const
   {
     return mVideo.mHasVideo;
   }
 
   bool HasAudio() const
   {
     return mAudio.mHasAudio;
   }
 
   bool HasValidMedia() const
   {
     return HasVideo() || HasAudio();
   }
 
+  bool mIsEncrypted;
+
   // TODO: Store VideoInfo and AudioIndo in arrays to support multi-tracks.
   VideoInfo mVideo;
   AudioInfo mAudio;
 };
 
 } // namespace mozilla
 
 #endif // MediaInfo_h
--- a/dom/media/fmp4/MP4Reader.cpp
+++ b/dom/media/fmp4/MP4Reader.cpp
@@ -357,17 +357,17 @@ MP4Reader::ReadMetadata(MediaInfo* aInfo
     mInfo.mVideo.mHasVideo = mVideo.mActive = mDemuxer->HasValidVideo() &&
                                               mDecoder->GetImageContainer();
 
     mInfo.mAudio.mHasAudio = mAudio.mActive = mDemuxer->HasValidAudio();
 
     {
       MonitorAutoUnlock unlock(mDemuxerMonitor);
       ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
-      mIsEncrypted = mDemuxer->Crypto().valid;
+      mInfo.mIsEncrypted = mIsEncrypted = mDemuxer->Crypto().valid;
     }
 
     // Remember that we've initialized the demuxer, so that if we're decoding
     // an encrypted stream and we need to wait for a CDM to be set, we don't
     // need to reinit the demuxer.
     mDemuxerInitialized = true;
   } else if (mPlatform && !IsWaitingMediaResources()) {
     *aInfo = mInfo;
--- a/dom/media/mediasource/MediaSourceReader.cpp
+++ b/dom/media/mediasource/MediaSourceReader.cpp
@@ -876,28 +876,30 @@ MediaSourceReader::ReadMetadata(MediaInf
 
   if (mAudioTrack) {
     MOZ_ASSERT(mAudioTrack->IsReady());
     mAudioReader = mAudioTrack->Decoders()[0]->GetReader();
 
     const MediaInfo& info = mAudioReader->GetMediaInfo();
     MOZ_ASSERT(info.HasAudio());
     mInfo.mAudio = info.mAudio;
+    mInfo.mIsEncrypted = mInfo.mIsEncrypted || info.mIsEncrypted;
     maxDuration = std::max(maxDuration, mAudioReader->GetDecoder()->GetMediaDuration());
     MSE_DEBUG("MediaSourceReader(%p)::ReadMetadata audio reader=%p maxDuration=%lld",
               this, mAudioReader.get(), maxDuration);
   }
 
   if (mVideoTrack) {
     MOZ_ASSERT(mVideoTrack->IsReady());
     mVideoReader = mVideoTrack->Decoders()[0]->GetReader();
 
     const MediaInfo& info = mVideoReader->GetMediaInfo();
     MOZ_ASSERT(info.HasVideo());
     mInfo.mVideo = info.mVideo;
+    mInfo.mIsEncrypted = mInfo.mIsEncrypted || info.mIsEncrypted;
     maxDuration = std::max(maxDuration, mVideoReader->GetDecoder()->GetMediaDuration());
     MSE_DEBUG("MediaSourceReader(%p)::ReadMetadata video reader=%p maxDuration=%lld",
               this, mVideoReader.get(), maxDuration);
   }
 
   if (!maxDuration) {
     // Treat a duration of 0 as infinity
     maxDuration = -1;
--- a/dom/webidl/HTMLMediaElement.webidl
+++ b/dom/webidl/HTMLMediaElement.webidl
@@ -45,16 +45,18 @@ interface HTMLMediaElement : HTMLElement
   readonly attribute boolean seeking;
 
   // playback state
   [SetterThrows]
            attribute double currentTime;
   [Throws]
   void fastSeek(double time);
   readonly attribute unrestricted double duration;
+  [ChromeOnly]
+  readonly attribute boolean isEncrypted;
   // TODO: Bug 847376 - readonly attribute any startDate;
   readonly attribute boolean paused;
   [SetterThrows]
            attribute double defaultPlaybackRate;
   [SetterThrows]
            attribute double playbackRate;
   [NewObject]
   readonly attribute TimeRanges played;