diff --git a/dom/media/MediaInfo.h b/dom/media/MediaInfo.h index 362def3bba08..8120cf12427c 100644 --- a/dom/media/MediaInfo.h +++ b/dom/media/MediaInfo.h @@ -141,7 +141,7 @@ class VideoInfo : public TrackInfo { }; VideoInfo() : VideoInfo(-1, -1) {} - explicit VideoInfo(int32_t aWidth, int32_t aHeight) + VideoInfo(int32_t aWidth, int32_t aHeight) : VideoInfo(gfx::IntSize(aWidth, aHeight)) {} explicit VideoInfo(const gfx::IntSize& aSize) @@ -151,8 +151,7 @@ class VideoInfo : public TrackInfo { mImage(aSize), mCodecSpecificConfig(new MediaByteBuffer), mExtraData(new MediaByteBuffer), - mRotation(kDegree_0), - mImageRect(gfx::IntRect(gfx::IntPoint(), aSize)) {} + mRotation(kDegree_0) {} VideoInfo(const VideoInfo& aOther) = default; @@ -175,13 +174,14 @@ class VideoInfo : public TrackInfo { bool HasAlpha() const { return mAlphaPresent; } gfx::IntRect ImageRect() const { - if (mImageRect.Width() < 0 || mImageRect.Height() < 0) { + if (!mImageRect) { return gfx::IntRect(0, 0, mImage.width, mImage.height); } - return mImageRect; + return *mImageRect; } - void SetImageRect(const gfx::IntRect& aRect) { mImageRect = aRect; } + void SetImageRect(const gfx::IntRect& aRect) { mImageRect = Some(aRect); } + void ResetImageRect() { mImageRect.reset(); } // Returned the crop rectangle scaled to aWidth/aHeight size relative to // mImage size. @@ -254,9 +254,11 @@ class VideoInfo : public TrackInfo { void SetFrameRate(int32_t aRate) { mFrameRate = Some(aRate); } private: + friend struct IPC::ParamTraits; + // mImage may be cropped; currently only used with the WebM container. - // A negative width or height indicate that no cropping is to occur. - gfx::IntRect mImageRect; + // If unset, no cropping is to occur. + Maybe mImageRect; // Indicates whether or not frames may contain alpha information. bool mAlphaPresent = false; diff --git a/dom/media/ipc/MediaIPCUtils.h b/dom/media/ipc/MediaIPCUtils.h index cdbab6640b9e..b940a3af8ba4 100644 --- a/dom/media/ipc/MediaIPCUtils.h +++ b/dom/media/ipc/MediaIPCUtils.h @@ -27,7 +27,7 @@ struct ParamTraits { WriteParam(aMsg, aParam.mDisplay); WriteParam(aMsg, aParam.mStereoMode); WriteParam(aMsg, aParam.mImage); - WriteParam(aMsg, aParam.ImageRect()); + WriteParam(aMsg, aParam.mImageRect); WriteParam(aMsg, *aParam.mCodecSpecificConfig); WriteParam(aMsg, *aParam.mExtraData); WriteParam(aMsg, aParam.mRotation); @@ -45,7 +45,7 @@ struct ParamTraits { ReadParam(aMsg, aIter, &aResult->mDisplay) && ReadParam(aMsg, aIter, &aResult->mStereoMode) && ReadParam(aMsg, aIter, &aResult->mImage) && - ReadParam(aMsg, aIter, &imageRect) && + ReadParam(aMsg, aIter, &aResult->mImageRect) && ReadParam(aMsg, aIter, aResult->mCodecSpecificConfig.get()) && ReadParam(aMsg, aIter, aResult->mExtraData.get()) && ReadParam(aMsg, aIter, &aResult->mRotation) && @@ -53,7 +53,6 @@ struct ParamTraits { ReadParam(aMsg, aIter, &aResult->mColorSpace) && ReadParam(aMsg, aIter, &aResult->mColorRange) && ReadParam(aMsg, aIter, &alphaPresent)) { - aResult->SetImageRect(imageRect); aResult->SetAlpha(alphaPresent); return true; } diff --git a/dom/media/platforms/wrappers/MediaChangeMonitor.cpp b/dom/media/platforms/wrappers/MediaChangeMonitor.cpp index 61e166910a9a..7eba198a7bde 100644 --- a/dom/media/platforms/wrappers/MediaChangeMonitor.cpp +++ b/dom/media/platforms/wrappers/MediaChangeMonitor.cpp @@ -131,8 +131,6 @@ class H264ChangeMonitor : public MediaChangeMonitor::CodecChangeMonitor { mCurrentConfig.mImage.height = spsdata.pic_height; mCurrentConfig.mDisplay.width = spsdata.display_width; mCurrentConfig.mDisplay.height = spsdata.display_height; - mCurrentConfig.SetImageRect( - gfx::IntRect(0, 0, spsdata.pic_width, spsdata.pic_height)); mCurrentConfig.mColorDepth = spsdata.ColorDepth(); mCurrentConfig.mColorSpace = spsdata.ColorSpace(); mCurrentConfig.mColorRange = spsdata.video_full_range_flag @@ -192,9 +190,9 @@ class VPXChangeMonitor : public MediaChangeMonitor::CodecChangeMonitor { } mCurrentConfig.mImage = info.mImage; mCurrentConfig.mDisplay = info.mDisplay; - mCurrentConfig.SetImageRect( - gfx::IntRect(0, 0, info.mImage.width, info.mImage.height)); - + // We can't properly determine the image rect once we've had a resolution + // change. + mCurrentConfig.ResetImageRect(); PROFILER_MARKER_TEXT( "VPX Stream Change", MEDIA_PLAYBACK, {}, "VPXChangeMonitor::CheckForChange has detected a change in the "