Bug 1876414 - Let SetVideoDataToImage return MediaResult r=media-playback-reviewers,padenot

Differential Revision: https://phabricator.services.mozilla.com/D200568
This commit is contained in:
Chun-Min Chang 2024-02-13 00:18:13 +00:00
parent 9d206aa4a4
commit af045ec3b4
2 changed files with 21 additions and 16 deletions

View File

@ -299,18 +299,24 @@ PlanarYCbCrData ConstructPlanarYCbCrData(const VideoInfo& aInfo,
}
/* static */
bool VideoData::SetVideoDataToImage(PlanarYCbCrImage* aVideoImage,
const VideoInfo& aInfo,
const YCbCrBuffer& aBuffer,
const IntRect& aPicture, bool aCopyData) {
MediaResult VideoData::SetVideoDataToImage(PlanarYCbCrImage* aVideoImage,
const VideoInfo& aInfo,
const YCbCrBuffer& aBuffer,
const IntRect& aPicture,
bool aCopyData) {
MOZ_ASSERT(aVideoImage);
PlanarYCbCrData data = ConstructPlanarYCbCrData(aInfo, aBuffer, aPicture);
if (aCopyData) {
return aVideoImage->CopyData(data);
// TODO: PlanarYCbCrImage::CopyData may return false on non out-of-memory
// failures.
return MediaResult(
aVideoImage->CopyData(data) ? NS_OK : NS_ERROR_OUT_OF_MEMORY,
RESULT_DETAIL("Failed to copy image data"));
}
return aVideoImage->AdoptData(data);
return MediaResult(aVideoImage->AdoptData(data) ? NS_OK : NS_ERROR_UNEXPECTED,
RESULT_DETAIL("Failed to adopt image data"));
}
/* static */
@ -367,12 +373,10 @@ Result<already_AddRefed<VideoData>, MediaResult> VideoData::CreateAndCopyData(
PlanarYCbCrImage* videoImage = v->mImage->AsPlanarYCbCrImage();
MOZ_ASSERT(videoImage);
if (!VideoData::SetVideoDataToImage(videoImage, aInfo, aBuffer, aPicture,
true /* aCopyData */)) {
// TODO: VideoData::SetVideoDataToImage may return NULL on non out-of-memory
// failures.
return Err(MediaResult(NS_ERROR_OUT_OF_MEMORY,
"Failed to create a PlanarYCbCrImage"));
if (MediaResult r = VideoData::SetVideoDataToImage(
videoImage, aInfo, aBuffer, aPicture, true /* aCopyData */);
NS_FAILED(r)) {
return Err(r);
}
perfRecorder.Record();

View File

@ -520,10 +520,11 @@ class VideoData : public MediaData {
// Initialize PlanarYCbCrImage. Only When aCopyData is true,
// video data is copied to PlanarYCbCrImage.
static bool SetVideoDataToImage(PlanarYCbCrImage* aVideoImage,
const VideoInfo& aInfo,
const YCbCrBuffer& aBuffer,
const IntRect& aPicture, bool aCopyData);
static MediaResult SetVideoDataToImage(PlanarYCbCrImage* aVideoImage,
const VideoInfo& aInfo,
const YCbCrBuffer& aBuffer,
const IntRect& aPicture,
bool aCopyData);
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;