Bug 1336431: P6. Handle change of resolution in RemoteDataDecoder. r?JamesCheng draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 13 Feb 2017 15:32:29 +0100
changeset 483577 02bfd674c98b2e63f6c23f3a1714852c9d84f16b
parent 483576 f1fbdc6929133049348faa1bc9dcd08d9850019e
child 483578 242a34c1d6ed95dc14dcd3ca0a80fdc5ffcb6b86
push id45346
push userbmo:jyavenard@mozilla.com
push dateTue, 14 Feb 2017 15:11:15 +0000
reviewersJamesCheng
bugs1336431
milestone54.0a1
Bug 1336431: P6. Handle change of resolution in RemoteDataDecoder. r?JamesCheng MozReview-Commit-ID: 8XOHESQiJ3t
dom/media/platforms/android/RemoteDataDecoder.cpp
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -8,16 +8,17 @@
 #include "FennecJNINatives.h"
 #include "GLImages.h"
 
 #include "MediaData.h"
 #include "MediaInfo.h"
 #include "VideoUtils.h"
 #include "VPXDecoder.h"
 
+#include "mozilla/Mutex.h"
 #include "nsThreadUtils.h"
 #include "nsPromiseFlatString.h"
 #include "nsIGfxInfo.h"
 
 #include "prlog.h"
 
 #include "DurationMap.h"
 #include <jni.h>
@@ -175,16 +176,18 @@ public:
 
       bool isEOS = !!(flags & MediaCodec::BUFFER_FLAG_END_OF_STREAM);
       int64_t durationUs = 0;
       if (!mDecoder->mInputDurations.Find(presentationTimeUs, durationUs) && !isEOS) {
         return;
       }
 
       if (size > 0) {
+        MutexAutoLock lock(mDecoder->mMutex);
+
         RefPtr<layers::Image> img = new SurfaceTextureImage(
           mDecoder->mSurfaceTexture.get(), mDecoder->mConfig.mDisplay,
           gl::OriginPos::BottomLeft);
 
         RefPtr<VideoData> v = VideoData::CreateFromImage(
           mDecoder->mConfig, offset, presentationTimeUs, durationUs,
           img, !!(flags & MediaCodec::BUFFER_FLAG_SYNC_FRAME),
           presentationTimeUs,
@@ -214,16 +217,17 @@ public:
 
   RemoteVideoDecoder(const VideoInfo& aConfig,
                      MediaFormat::Param aFormat,
                      layers::ImageContainer* aImageContainer,
                      const nsString& aDrmStubId, TaskQueue* aTaskQueue)
     : RemoteDataDecoder(MediaData::Type::VIDEO_DATA, aConfig.mMimeType,
                         aFormat, aDrmStubId, aTaskQueue)
     , mImageContainer(aImageContainer)
+    , mMutex("RemoteVideoDecoder Mutex")
     , mConfig(aConfig)
   {
   }
 
   RefPtr<InitPromise> Init() override
   {
     mSurfaceTexture = AndroidSurfaceTexture::Create();
     if (!mSurfaceTexture) {
@@ -270,23 +274,30 @@ public:
     mInputDurations.Insert(aSample->mDuration, aSample->mTime);
     return RemoteDataDecoder::Decode(aSample);
   }
 
   bool SupportDecoderRecycling() const override
   {
     return mIsCodecSupportAdaptivePlayback;
   }
+  void ConfigurationChanged(const TrackInfo& aConfig) override
+  {
+    MOZ_ASSERT(aConfig.GetAsVideoInfo());
+    MutexAutoLock lock(mMutex);
+    mConfig = *aConfig.GetAsVideoInfo();
+  }
 
 private:
   layers::ImageContainer* mImageContainer;
-  const VideoInfo mConfig;
   RefPtr<AndroidSurfaceTexture> mSurfaceTexture;
   DurationMap mInputDurations;
   bool mIsCodecSupportAdaptivePlayback = false;
+  Mutex mMutex; // Protects mConfig
+  VideoInfo mConfig;
 };
 
 class RemoteAudioDecoder : public RemoteDataDecoder
 {
 public:
   RemoteAudioDecoder(const AudioInfo& aConfig,
                      MediaFormat::Param aFormat,
                      const nsString& aDrmStubId, TaskQueue* aTaskQueue)