Video: Correct the bit depth return value for PIXEL_FROMAT_P{0|2|4}10
These formats previously being named with PIXEL_FROMAT_P{0|2|4}16,
while only P010 actually uses this format store data. Historically, because P016 always returns 16 bit depth, we have written some of the workarounds for this.
The previous CL (https://crrev.com/c/5633141) just
completed the renaming, this CL intends to keep correct
the incorrect bit depth.
Bug: 347597908
Change-Id: I301f2ef39a9d3136231841b39b7d0a5854b99f53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5641797
Reviewed-by: ccameron chromium <ccameron@chromium.org>
Reviewed-by: Dan Sanders <sandersd@chromium.org>
Commit-Queue: Sida Zhu <zhusida@bytedance.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Cr-Commit-Position: refs/heads/main@{#1320011}
diff --git a/media/base/video_types.cc b/media/base/video_types.cc
index ca264f40..6a7b7443 100644
--- a/media/base/video_types.cc
+++ b/media/base/video_types.cc
@@ -372,15 +372,15 @@
case PIXEL_FORMAT_YUV420AP10:
case PIXEL_FORMAT_YUV422AP10:
case PIXEL_FORMAT_YUV444AP10:
+ case PIXEL_FORMAT_P010LE:
+ case PIXEL_FORMAT_P210LE:
+ case PIXEL_FORMAT_P410LE:
return 10;
case PIXEL_FORMAT_YUV420P12:
case PIXEL_FORMAT_YUV422P12:
case PIXEL_FORMAT_YUV444P12:
return 12;
case PIXEL_FORMAT_Y16:
- case PIXEL_FORMAT_P010LE:
- case PIXEL_FORMAT_P210LE:
- case PIXEL_FORMAT_P410LE:
case PIXEL_FORMAT_RGBAF16:
return 16;
}
diff --git a/media/base/video_types.h b/media/base/video_types.h
index 469eea9..530f38c 100644
--- a/media/base/video_types.h
+++ b/media/base/video_types.h
@@ -64,7 +64,7 @@
PIXEL_FORMAT_ABGR = 27, // 32bpp RGBA (byte-order), 1 plane.
PIXEL_FORMAT_XBGR = 28, // 24bpp RGBX (byte-order), 1 plane.
- // 24bpp YUV planar 1x1 Y, 2x2 interleaved UV, 10 bits per channel.
+ // 15bpp YUV planar 1x1 Y, 2x2 interleaved UV, 10 bits per channel.
// data in the high bits, zeros in the low bits, little-endian.
PIXEL_FORMAT_P010LE = 29,
@@ -95,11 +95,11 @@
// 24bpp YUV planar 1x1 Y, 1x1 interleaved UV, 8 bits per channel.
PIXEL_FORMAT_NV24 = 41,
- // 32bpp YUV planar 1x1 Y, 2x1 interleaved UV, 10 bits per channel.
+ // 20bpp YUV planar 1x1 Y, 2x1 interleaved UV, 10 bits per channel.
// data in the high bits, zeros in the low bits, little-endian.
PIXEL_FORMAT_P210LE = 42,
- // 48bpp YUV planar 1x1 Y, 1x1 interleaved UV, 10 bits per channel.
+ // 30bpp YUV planar 1x1 Y, 1x1 interleaved UV, 10 bits per channel.
// data in the high bits, zeros in the low bits, little-endian.
PIXEL_FORMAT_P410LE = 43,
diff --git a/media/gpu/chromeos/oop_video_decoder.cc b/media/gpu/chromeos/oop_video_decoder.cc
index 6ea4c211..0b5dec64 100644
--- a/media/gpu/chromeos/oop_video_decoder.cc
+++ b/media/gpu/chromeos/oop_video_decoder.cc
@@ -100,7 +100,7 @@
mojo_frame->metadata.needs_detiling &&
mojo_frame->format == PIXEL_FORMAT_P010LE) {
// This is a tiled, protected MTK format that is true 10bpp so it will
- // not pass the tests in VerifyGpuMemoryBufferHandle for P016. Instead just
+ // not pass the tests in VerifyGpuMemoryBufferHandle for P010. Instead just
// do the basic tests that would be done in that call here. This is safe to
// do because the buffers for this will only go into the secure video
// decoder which will fail on invalid buffer parameters.
@@ -114,8 +114,8 @@
<< mojo_frame->coded_size.ToString();
return nullptr;
}
- constexpr size_t kNumP016Planes = 2;
- if (kNumP016Planes != mojo_frame->gpu_memory_buffer_handle
+ constexpr size_t kNumP010Planes = 2;
+ if (kNumP010Planes != mojo_frame->gpu_memory_buffer_handle
.native_pixmap_handle.planes.size()) {
VLOGF(1) << "Invalid number of dmabuf planes passed: "
<< mojo_frame->gpu_memory_buffer_handle.native_pixmap_handle
diff --git a/media/gpu/test/image_quality_metrics.cc b/media/gpu/test/image_quality_metrics.cc
index e502e41..19b4e97 100644
--- a/media/gpu/test/image_quality_metrics.cc
+++ b/media/gpu/test/image_quality_metrics.cc
@@ -144,14 +144,8 @@
ASSERT_TRUE_OR_RETURN(
frame1->visible_rect().size() == frame2->visible_rect().size(),
static_cast<double>(std::numeric_limits<std::size_t>::max()));
- // Ideally, frame1->BitDepth() should be the same as frame2->BitDepth()
- // always. But in the 10 bit case, the 10 bit frame can be carried with P010LE
- // whose bit depth is regarded to be 16. This is due to a lack of NV12 10-bit
- // buffer format in media::VideoPixelFormat. As a workaround for this, we
- // determine the common bit depth as the smaller one.
ASSERT_TRUE_OR_RETURN(
- (frame1->BitDepth() == 8 && frame1->BitDepth() == frame2->BitDepth()) ||
- std::min(frame1->BitDepth(), frame2->BitDepth()) == 10,
+ frame1->BitDepth() == frame2->BitDepth(),
static_cast<double>(std::numeric_limits<std::size_t>::max()));
const size_t bit_depth = std::min(frame1->BitDepth(), frame2->BitDepth());
const VideoPixelFormat common_format =
diff --git a/media/gpu/v4l2/v4l2_video_decoder.cc b/media/gpu/v4l2/v4l2_video_decoder.cc
index afa0598..8eb634f 100644
--- a/media/gpu/v4l2/v4l2_video_decoder.cc
+++ b/media/gpu/v4l2/v4l2_video_decoder.cc
@@ -674,10 +674,7 @@
// P010 and NV12, and then down sample to NV12 if it is selected. This is
// not desired, so drop the candidates that don't match the bit depth of the
// stream.
- size_t candidate_bit_depth =
- (candidate == Fourcc(Fourcc::MT2T))
- ? 10u
- : BitDepth(candidate->ToVideoPixelFormat());
+ size_t candidate_bit_depth = BitDepth(candidate->ToVideoPixelFormat());
if (candidate_bit_depth != bit_depth) {
DVLOGF(1) << "Enumerated format " << candidate->ToString()
<< " with a bit depth of " << candidate_bit_depth
diff --git a/media/mojo/mojom/stable/stable_video_decoder_types.mojom b/media/mojo/mojom/stable/stable_video_decoder_types.mojom
index 5ade637..8781fce 100644
--- a/media/mojo/mojom/stable/stable_video_decoder_types.mojom
+++ b/media/mojo/mojom/stable/stable_video_decoder_types.mojom
@@ -413,7 +413,7 @@
kPixelFormatABGR = 27, // 32bpp RGBA (byte-order), 1 plane.
kPixelFormatXBGR = 28, // 24bpp RGBX (byte-order), 1 plane.
- // 24bpp YUV planar 1x1 Y, 2x2 interleaved UV, 10 bits per channel.
+ // 15bpp YUV planar 1x1 Y, 2x2 interleaved UV, 10 bits per channel.
// data in the high bits, zeros in the low bits, little-endian.
kPixelFormatP010LE = 29,
@@ -446,11 +446,11 @@
// 24bpp YUV planar 1x1 Y, 1x1 interleaved UV, 8 bits per channel.
[MinVersion=3] kPixelFormatNV24 = 41,
- // 32bpp YUV planar 1x1 Y, 2x1 interleaved UV, 16 bits per channel.
+ // 20bpp YUV planar 1x1 Y, 2x1 interleaved UV, 16 bits per channel.
// data in the high bits, zeros in the low bits, little-endian.
[MinVersion=3] kPixelFormatP210LE = 42,
- // 48bpp YUV planar 1x1 Y, 1x1 interleaved UV, 16 bits per channel.
+ // 30bpp YUV planar 1x1 Y, 1x1 interleaved UV, 16 bits per channel.
// data in the high bits, zeros in the low bits, little-endian.
[MinVersion=3] kPixelFormatP410LE = 43,
};
diff --git a/media/renderers/paint_canvas_video_renderer.cc b/media/renderers/paint_canvas_video_renderer.cc
index c36d107..f0c36899d 100644
--- a/media/renderers/paint_canvas_video_renderer.cc
+++ b/media/renderers/paint_canvas_video_renderer.cc
@@ -307,10 +307,12 @@
case kBT2020_8bit_Full_SkYUVColorSpace:
case kBT2020_10bit_Full_SkYUVColorSpace:
case kBT2020_12bit_Full_SkYUVColorSpace:
+ case kBT2020_16bit_Full_SkYUVColorSpace:
return &YUV_MATRIX(libyuv::kYuvV2020Constants);
case kBT2020_8bit_Limited_SkYUVColorSpace:
case kBT2020_10bit_Limited_SkYUVColorSpace:
case kBT2020_12bit_Limited_SkYUVColorSpace:
+ case kBT2020_16bit_Limited_SkYUVColorSpace:
return &YUV_MATRIX(libyuv::kYuv2020Constants);
case kFCC_Full_SkYUVColorSpace:
case kFCC_Limited_SkYUVColorSpace:
@@ -326,12 +328,13 @@
case kYCgCo_10bit_Limited_SkYUVColorSpace:
case kYCgCo_12bit_Full_SkYUVColorSpace:
case kYCgCo_12bit_Limited_SkYUVColorSpace:
+ case kYCgCo_16bit_Full_SkYUVColorSpace:
+ case kYCgCo_16bit_Limited_SkYUVColorSpace:
// TODO(crbug.com/41486014): Return color space for default
// kRec601_SkYUVColorSpace as libyuv does not have FCC, SMPTE240M, YDZDX,
// GBR, YCgCo equivalent support.
return &YUV_MATRIX(libyuv::kYuvI601Constants);
case kIdentity_SkYUVColorSpace:
- default:
NOTREACHED_NORETURN();
};
}
diff --git a/media/renderers/video_resource_updater_unittest.cc b/media/renderers/video_resource_updater_unittest.cc
index 076c8a5..3efeaf3 100644
--- a/media/renderers/video_resource_updater_unittest.cc
+++ b/media/renderers/video_resource_updater_unittest.cc
@@ -298,7 +298,7 @@
return video_frame;
}
- scoped_refptr<VideoFrame> CreateP016TestFrame() {
+ scoped_refptr<VideoFrame> CreateP010TestFrame() {
const int kDimension = 10;
gfx::Size size(kDimension, kDimension);
@@ -601,9 +601,9 @@
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resources.type);
}
-TEST_F(VideoResourceUpdaterTest, P016FrameSoftwareCompositor) {
+TEST_F(VideoResourceUpdaterTest, P010FrameSoftwareCompositor) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
- scoped_refptr<VideoFrame> video_frame = CreateP016TestFrame();
+ scoped_refptr<VideoFrame> video_frame = CreateP010TestFrame();
VideoFrameExternalResources resources =
updater->CreateExternalResourcesFromVideoFrame(video_frame);
@@ -1119,7 +1119,7 @@
EXPECT_EQ(0u, GetSharedImageCount());
}
-TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleP016HDR) {
+TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleP010HDR) {
constexpr auto kHDR10ColorSpace = gfx::ColorSpace::CreateHDR10();
gfx::HDRMetadata hdr_metadata{};
hdr_metadata.smpte_st_2086 =
diff --git a/skia/ext/cicp.cc b/skia/ext/cicp.cc
index c15cd8d..b15da28 100644
--- a/skia/ext/cicp.cc
+++ b/skia/ext/cicp.cc
@@ -208,6 +208,11 @@
? kBT2020_12bit_Full_SkYUVColorSpace
: kBT2020_12bit_Limited_SkYUVColorSpace;
return true;
+ case 16:
+ yuv_color_space = full_range_flag
+ ? kBT2020_16bit_Full_SkYUVColorSpace
+ : kBT2020_16bit_Limited_SkYUVColorSpace;
+ return true;
default:
break;
}
diff --git a/third_party/blink/renderer/modules/webcodecs/image_decoder_core.cc b/third_party/blink/renderer/modules/webcodecs/image_decoder_core.cc
index 2097961e..5b5d718a 100644
--- a/third_party/blink/renderer/modules/webcodecs/image_decoder_core.cc
+++ b/third_party/blink/renderer/modules/webcodecs/image_decoder_core.cc
@@ -67,12 +67,14 @@
case kBT2020_8bit_Full_SkYUVColorSpace:
case kBT2020_10bit_Full_SkYUVColorSpace:
case kBT2020_12bit_Full_SkYUVColorSpace:
+ case kBT2020_16bit_Full_SkYUVColorSpace:
return gfx::ColorSpace(primary_id, transfer_id,
gfx::ColorSpace::MatrixID::BT2020_NCL,
gfx::ColorSpace::RangeID::FULL);
case kBT2020_8bit_Limited_SkYUVColorSpace:
case kBT2020_10bit_Limited_SkYUVColorSpace:
case kBT2020_12bit_Limited_SkYUVColorSpace:
+ case kBT2020_16bit_Limited_SkYUVColorSpace:
return gfx::ColorSpace(primary_id, transfer_id,
gfx::ColorSpace::MatrixID::BT2020_NCL,
gfx::ColorSpace::RangeID::LIMITED);
@@ -111,17 +113,18 @@
case kYCgCo_8bit_Full_SkYUVColorSpace:
case kYCgCo_10bit_Full_SkYUVColorSpace:
case kYCgCo_12bit_Full_SkYUVColorSpace:
+ case kYCgCo_16bit_Full_SkYUVColorSpace:
return gfx::ColorSpace(primary_id, transfer_id,
gfx::ColorSpace::MatrixID::YCOCG,
gfx::ColorSpace::RangeID::FULL);
case kYCgCo_8bit_Limited_SkYUVColorSpace:
case kYCgCo_10bit_Limited_SkYUVColorSpace:
case kYCgCo_12bit_Limited_SkYUVColorSpace:
+ case kYCgCo_16bit_Limited_SkYUVColorSpace:
return gfx::ColorSpace(primary_id, transfer_id,
gfx::ColorSpace::MatrixID::YCOCG,
gfx::ColorSpace::RangeID::LIMITED);
case kIdentity_SkYUVColorSpace:
- default:
NOTREACHED_IN_MIGRATION();
return gfx::ColorSpace();
};
@@ -469,7 +472,9 @@
skyuv_cs == kBT2020_10bit_Full_SkYUVColorSpace ||
skyuv_cs == kBT2020_10bit_Limited_SkYUVColorSpace ||
skyuv_cs == kBT2020_12bit_Full_SkYUVColorSpace ||
- skyuv_cs == kBT2020_12bit_Limited_SkYUVColorSpace)
+ skyuv_cs == kBT2020_12bit_Limited_SkYUVColorSpace ||
+ skyuv_cs == kBT2020_16bit_Full_SkYUVColorSpace ||
+ skyuv_cs == kBT2020_16bit_Limited_SkYUVColorSpace)
<< "Unexpected SkYUVColorSpace: " << skyuv_cs;
auto transfer_id = gfx::ColorSpace::TransferID::BT709;
@@ -477,7 +482,9 @@
skyuv_cs == kBT2020_10bit_Limited_SkYUVColorSpace) {
transfer_id = gfx::ColorSpace::TransferID::BT2020_10;
} else if (skyuv_cs == kBT2020_12bit_Full_SkYUVColorSpace ||
- skyuv_cs == kBT2020_12bit_Limited_SkYUVColorSpace) {
+ skyuv_cs == kBT2020_12bit_Limited_SkYUVColorSpace ||
+ skyuv_cs == kBT2020_16bit_Full_SkYUVColorSpace ||
+ skyuv_cs == kBT2020_16bit_Limited_SkYUVColorSpace) {
transfer_id = gfx::ColorSpace::TransferID::BT2020_12;
}
diff --git a/ui/gfx/color_space.cc b/ui/gfx/color_space.cc
index 148c760..615ab58 100644
--- a/ui/gfx/color_space.cc
+++ b/ui/gfx/color_space.cc
@@ -30,14 +30,6 @@
namespace {
-// Videos that are from a 10 or 12 bit source, but are stored in a 16-bit
-// format (e.g, PIXEL_FORMAT_P016LE) will report having 16 bits per pixel.
-// Assume they have 10 bits per pixel.
-// https://crbug.com/1381100
-int BitDepthWithWorkaroundApplied(int bit_depth) {
- return bit_depth == 16 ? 10 : bit_depth;
-}
-
static bool FloatsEqualWithinTolerance(const float* a,
const float* b,
int n,
@@ -1024,7 +1016,6 @@
}
SkM44 ColorSpace::GetTransferMatrix(int bit_depth) const {
- bit_depth = BitDepthWithWorkaroundApplied(bit_depth);
DCHECK_GE(bit_depth, 8);
// If chroma samples are real numbers in the range of −0.5 to 0.5, an offset
// of 0.5 is added to get real numbers in the range of 0 to 1. When
@@ -1111,7 +1102,6 @@
}
SkM44 ColorSpace::GetRangeAdjustMatrix(int bit_depth) const {
- bit_depth = BitDepthWithWorkaroundApplied(bit_depth);
DCHECK_GE(bit_depth, 8);
switch (range_) {
case RangeID::FULL:
@@ -1156,7 +1146,6 @@
}
bool ColorSpace::ToSkYUVColorSpace(int bit_depth, SkYUVColorSpace* out) const {
- bit_depth = BitDepthWithWorkaroundApplied(bit_depth);
switch (matrix_) {
case MatrixID::BT709:
*out = range_ == RangeID::FULL ? kRec709_Full_SkYUVColorSpace
@@ -1185,6 +1174,11 @@
: kBT2020_12bit_Limited_SkYUVColorSpace;
return true;
}
+ if (bit_depth == 16) {
+ *out = range_ == RangeID::FULL ? kBT2020_16bit_Full_SkYUVColorSpace
+ : kBT2020_16bit_Limited_SkYUVColorSpace;
+ return true;
+ }
return false;
case MatrixID::FCC:
@@ -1223,6 +1217,11 @@
: kYCgCo_12bit_Limited_SkYUVColorSpace;
return true;
}
+ if (bit_depth == 16) {
+ *out = range_ == RangeID::FULL ? kYCgCo_16bit_Full_SkYUVColorSpace
+ : kYCgCo_16bit_Limited_SkYUVColorSpace;
+ return true;
+ }
return false;
default:
break;