Bug 1482059 - P2. Use new VPx frame parser to detect content change. r=padenot
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 14 Nov 2018 14:40:26 +0000
changeset 446204 6b87d74e97c91155e6023d154aab1786f3518101
parent 446203 76b88f20b0824ae7e24b4de15c2bec404faa30e2
child 446205 f1b7aa784d8caa8a4a68a66886eb63f24a860c5f
push id72957
push userjyavenard@mozilla.com
push dateWed, 14 Nov 2018 14:41:23 +0000
treeherderautoland@6b87d74e97c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1482059
milestone65.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 1482059 - P2. Use new VPx frame parser to detect content change. r=padenot We also set the TrackInfoSharedPtr to each decoded sample so that on decoder that can be recycled (android) the frames are displayed with the right size. Depends on D11588 Differential Revision: https://phabricator.services.mozilla.com/D11589
dom/media/platforms/wrappers/MediaChangeMonitor.cpp
--- a/dom/media/platforms/wrappers/MediaChangeMonitor.cpp
+++ b/dom/media/platforms/wrappers/MediaChangeMonitor.cpp
@@ -144,16 +144,17 @@ private:
 class VPXChangeMonitor : public MediaChangeMonitor::CodecChangeMonitor
 {
 public:
   explicit VPXChangeMonitor(const VideoInfo& aInfo)
     : mCurrentConfig(aInfo)
     , mCodec(VPXDecoder::IsVP8(aInfo.mMimeType) ? VPXDecoder::Codec::VP8
                                                 : VPXDecoder::Codec::VP9)
   {
+    mTrackInfo = new TrackInfoSharedPtr(mCurrentConfig, mStreamID++);
   }
 
   bool CanBeInstantiated() const override { return true; }
 
   MediaResult CheckForChange(MediaRawData* aSample) override
   {
     // Don't look at encrypted content.
     if (aSample->mCrypto.mValid) {
@@ -161,50 +162,56 @@ public:
     }
     // For both VP8 and VP9, we only look for resolution changes
     // on keyframes. Other resolution changes are invalid.
     if (!aSample->mKeyframe) {
       return NS_OK;
     }
 
     auto dataSpan = MakeSpan<const uint8_t>(aSample->Data(), aSample->Size());
-    auto dimensions = VPXDecoder::GetFrameSize(dataSpan, mCodec);
-    int profile = mCodec == VPXDecoder::Codec::VP9
-                    ? VPXDecoder::GetVP9Profile(dataSpan)
-                    : 0;
 
-    if (!mSize) {
-      mSize = Some(dimensions);
-      mProfile = Some(profile);
+    VPXDecoder::VPXStreamInfo info;
+    if (!VPXDecoder::GetStreamInfo(dataSpan, info, mCodec)) {
+      return NS_ERROR_DOM_MEDIA_DECODE_ERR;
+    }
+
+    if (!mInfo) {
+      mInfo = Some(info);
       return NS_OK;
     }
-    if (mSize.ref() == dimensions && mProfile.ref() == profile) {
+    if (mInfo.ref().IsCompatible(info)) {
       return NS_OK;
     }
-    mSize = Some(dimensions);
-    mProfile = Some(profile);
-    mCurrentConfig.mDisplay = dimensions;
+    mInfo = Some(info);
+    mCurrentConfig.mImage = info.mImage;
+    mCurrentConfig.mDisplay = info.mDisplay;
+    mCurrentConfig.SetImageRect(
+      gfx::IntRect(0, 0, info.mImage.width, info.mImage.height));
+    mTrackInfo = new TrackInfoSharedPtr(mCurrentConfig, mStreamID++);
 
     return NS_ERROR_DOM_MEDIA_NEED_NEW_DECODER;
   }
 
   const TrackInfo& Config() const override { return mCurrentConfig; }
 
   MediaResult PrepareSample(MediaDataDecoder::ConversionRequired aConversion,
                             MediaRawData* aSample,
                             bool aNeedKeyFrame) override
   {
+    aSample->mTrackInfo = mTrackInfo;
+
     return NS_OK;
   }
 
 private:
   VideoInfo mCurrentConfig;
   const VPXDecoder::Codec mCodec;
-  Maybe<gfx::IntSize> mSize;
-  Maybe<int> mProfile;
+  Maybe<VPXDecoder::VPXStreamInfo> mInfo;
+  uint32_t mStreamID = 0;
+  RefPtr<TrackInfoSharedPtr> mTrackInfo;
 };
 
 MediaChangeMonitor::MediaChangeMonitor(PlatformDecoderModule* aPDM,
                                        const CreateDecoderParams& aParams)
   : mPDM(aPDM)
   , mCurrentConfig(aParams.VideoConfig())
   , mKnowsCompositor(aParams.mKnowsCompositor)
   , mImageContainer(aParams.mImageContainer)