Bug 1637658 - P1. Only use ImageRect if explicitly set. r=mattwoodrow,pehrsons

The concept of ImageRect only exists with the WebM container. It defines a rectangle that will be used to crop the decoded image.

Initially (and as still indicated in the comment for VideoInfo.mImageRect) that field was only ever initialised by the WebMDemuxer.
So we now make this an optional value that needs to be explicitly initialised to be active, and only do so in the WebMDemuxer.

Differential Revision: https://phabricator.services.mozilla.com/D99601
This commit is contained in:
Jean-Yves Avenard 2020-12-14 08:16:23 +00:00
Родитель b49c538e2c
Коммит 945923fe99
3 изменённых файлов: 15 добавлений и 16 удалений

Просмотреть файл

@ -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<VideoInfo>;
// 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<gfx::IntRect> mImageRect;
// Indicates whether or not frames may contain alpha information.
bool mAlphaPresent = false;

Просмотреть файл

@ -27,7 +27,7 @@ struct ParamTraits<mozilla::VideoInfo> {
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<mozilla::VideoInfo> {
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<mozilla::VideoInfo> {
ReadParam(aMsg, aIter, &aResult->mColorSpace) &&
ReadParam(aMsg, aIter, &aResult->mColorRange) &&
ReadParam(aMsg, aIter, &alphaPresent)) {
aResult->SetImageRect(imageRect);
aResult->SetAlpha(alphaPresent);
return true;
}

Просмотреть файл

@ -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 "