[media] Use single ExportedSharedImage inside SharedImageBufferHandleSet
With multiplanar shared image for hardware decode launched, we can change the array<gpu::ExportedSharedImage> in SharedImageBufferHandleSet to take a single gpu::ExportedSharedImage. This change updates mojom and relevant callsites that use it. Bug: 332564976 Change-Id: I8cdf9626be1aa5a9a829d32f9712702e0c053a4c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5593229 Commit-Queue: Saifuddin Hitawala <hitawala@chromium.org> Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org> Reviewed-by: Guido Urdaneta <guidou@chromium.org> Reviewed-by: Brendon Tiszka <tiszka@chromium.org> Reviewed-by: Colin Blundell <blundell@chromium.org> Cr-Commit-Position: refs/heads/main@{#1310590}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
be2499efb1
commit
5340cdd605
content/browser/webrtc
media/capture
services
video_capture
video_effects
third_party/blink/renderer/platform/video_capture
@ -110,10 +110,10 @@ class TextureDeviceExerciser : public VirtualDeviceExerciser {
|
||||
|
||||
const SkColor4f kDarkFrameColor = SkColors::kBlack;
|
||||
const SkColor4f kLightFrameColor = SkColors::kGray;
|
||||
CreateDummyRgbFrame(ri, sii, kDarkFrameColor, dummy_frame_0_shared_images_,
|
||||
dummy_frame_0_sync_token_);
|
||||
CreateDummyRgbFrame(ri, sii, kLightFrameColor, dummy_frame_1_shared_images_,
|
||||
dummy_frame_1_sync_token_);
|
||||
dummy_frame_0_shared_image_ = CreateDummyRgbFrame(
|
||||
ri, sii, kDarkFrameColor, dummy_frame_0_sync_token_);
|
||||
dummy_frame_1_shared_image_ = CreateDummyRgbFrame(
|
||||
ri, sii, kLightFrameColor, dummy_frame_1_sync_token_);
|
||||
}
|
||||
|
||||
void RegisterVirtualDeviceAtVideoSourceProvider(
|
||||
@ -124,24 +124,18 @@ class TextureDeviceExerciser : public VirtualDeviceExerciser {
|
||||
->AddTextureVirtualDevice(info,
|
||||
virtual_device_.BindNewPipeAndPassReceiver());
|
||||
|
||||
std::vector<gpu::ExportedSharedImage> dummy_frame_0_exported_shared_images;
|
||||
std::vector<gpu::ExportedSharedImage> dummy_frame_1_exported_shared_images;
|
||||
|
||||
for (auto& shared_image : dummy_frame_0_shared_images_) {
|
||||
dummy_frame_0_exported_shared_images.push_back(shared_image->Export());
|
||||
}
|
||||
|
||||
for (auto& shared_image : dummy_frame_1_shared_images_) {
|
||||
dummy_frame_1_exported_shared_images.push_back(shared_image->Export());
|
||||
}
|
||||
gpu::ExportedSharedImage dummy_frame_0_exported_shared_image =
|
||||
dummy_frame_0_shared_image_->Export();
|
||||
gpu::ExportedSharedImage dummy_frame_1_exported_shared_image =
|
||||
dummy_frame_1_shared_image_->Export();
|
||||
|
||||
virtual_device_->OnNewSharedImageBufferHandle(
|
||||
0, media::mojom::SharedImageBufferHandleSet::New(
|
||||
std::move(dummy_frame_0_exported_shared_images),
|
||||
std::move(dummy_frame_0_exported_shared_image),
|
||||
dummy_frame_0_sync_token_, GL_TEXTURE_2D));
|
||||
virtual_device_->OnNewSharedImageBufferHandle(
|
||||
1, media::mojom::SharedImageBufferHandleSet::New(
|
||||
std::move(dummy_frame_1_exported_shared_images),
|
||||
std::move(dummy_frame_1_exported_shared_image),
|
||||
dummy_frame_1_sync_token_, GL_TEXTURE_2D));
|
||||
frame_being_consumed_[0] = false;
|
||||
frame_being_consumed_[1] = false;
|
||||
@ -195,11 +189,10 @@ class TextureDeviceExerciser : public VirtualDeviceExerciser {
|
||||
}
|
||||
|
||||
private:
|
||||
void CreateDummyRgbFrame(
|
||||
scoped_refptr<gpu::ClientSharedImage> CreateDummyRgbFrame(
|
||||
gpu::raster::RasterInterface* ri,
|
||||
gpu::SharedImageInterface* sii,
|
||||
SkColor4f frame_color,
|
||||
std::vector<scoped_refptr<gpu::ClientSharedImage>>& target,
|
||||
gpu::SyncToken& ri_token) {
|
||||
SkBitmap frame_bitmap;
|
||||
frame_bitmap.allocPixels(SkImageInfo::Make(
|
||||
@ -210,7 +203,7 @@ class TextureDeviceExerciser : public VirtualDeviceExerciser {
|
||||
// This SharedImage is populated via the raster interface below and may
|
||||
// be read via the raster interface in normal VideoFrame usage exercised
|
||||
// by the tests.
|
||||
scoped_refptr<gpu::ClientSharedImage> shared_image = sii->CreateSharedImage(
|
||||
auto shared_image = sii->CreateSharedImage(
|
||||
{viz::SinglePlaneFormat::kRGBA_8888, kDummyFrameCodedSize,
|
||||
gfx::ColorSpace::CreateSRGB(), kTopLeft_GrSurfaceOrigin,
|
||||
kOpaque_SkAlphaType,
|
||||
@ -225,13 +218,11 @@ class TextureDeviceExerciser : public VirtualDeviceExerciser {
|
||||
ri->WritePixels(shared_image->mailbox(), 0, 0, GL_TEXTURE_2D,
|
||||
frame_bitmap.pixmap());
|
||||
|
||||
// For RGB formats, only the first plane needs to be filled with an
|
||||
// actual texture.
|
||||
target.emplace_back(shared_image);
|
||||
|
||||
ri->GenSyncTokenCHROMIUM(ri_token.GetData());
|
||||
ri->ShallowFlushCHROMIUM();
|
||||
CHECK_EQ(ri->GetError(), static_cast<GLenum>(GL_NO_ERROR));
|
||||
|
||||
return shared_image;
|
||||
}
|
||||
|
||||
void OnFrameConsumptionFinished(int32_t frame_index) {
|
||||
@ -244,10 +235,8 @@ class TextureDeviceExerciser : public VirtualDeviceExerciser {
|
||||
mojo::Remote<video_capture::mojom::TextureVirtualDevice> virtual_device_;
|
||||
bool virtual_device_has_frame_access_handler_ = false;
|
||||
int dummy_frame_index_ = 0;
|
||||
std::vector<scoped_refptr<gpu::ClientSharedImage>>
|
||||
dummy_frame_0_shared_images_;
|
||||
std::vector<scoped_refptr<gpu::ClientSharedImage>>
|
||||
dummy_frame_1_shared_images_;
|
||||
scoped_refptr<gpu::ClientSharedImage> dummy_frame_0_shared_image_;
|
||||
scoped_refptr<gpu::ClientSharedImage> dummy_frame_1_shared_image_;
|
||||
gpu::SyncToken dummy_frame_0_sync_token_;
|
||||
gpu::SyncToken dummy_frame_1_sync_token_;
|
||||
std::array<bool, 2> frame_being_consumed_;
|
||||
|
@ -40,12 +40,10 @@ struct ReadyBuffer {
|
||||
VideoFrameInfo info;
|
||||
};
|
||||
|
||||
// Represents an ExportedSharedImage when used with GpuMemoryBufferHandle as
|
||||
// part of VideoBufferHandle.
|
||||
struct SharedImageBufferHandleSet {
|
||||
// The size of the |shared_images| array is always 1 when storing
|
||||
// MultiplanarSharedImage, and should otherwise match the plane number
|
||||
// of the corresponding pixel format listed in media::VideoPixelFormat.
|
||||
// In either case, the size should never exceed media::VideoFrame::kMaxPlanes.
|
||||
array<gpu.mojom.ExportedSharedImage> shared_images;
|
||||
gpu.mojom.ExportedSharedImage shared_image;
|
||||
gpu.mojom.SyncToken sync_token;
|
||||
uint32 texture_target;
|
||||
};
|
||||
|
@ -63,8 +63,7 @@ mojom::VideoBufferHandlePtr CreateBufferHandle(
|
||||
case VideoCaptureBufferType::kGpuMemoryBuffer: {
|
||||
auto [shared_image, sync_token] = CreateSharedImage(buffer, frame_info);
|
||||
auto shared_image_set = mojom::SharedImageBufferHandleSet::New(
|
||||
std::vector<gpu::ExportedSharedImage>{shared_image}, sync_token,
|
||||
GL_TEXTURE_2D);
|
||||
shared_image, sync_token, GL_TEXTURE_2D);
|
||||
|
||||
return mojom::VideoBufferHandle::NewSharedImageHandles(
|
||||
std::move(shared_image_set));
|
||||
|
@ -31,7 +31,10 @@ class TextureVirtualDeviceMojoAdapterTest : public ::testing::Test {
|
||||
|
||||
protected:
|
||||
void ProducerSharesBufferHandle(int32_t buffer_id) {
|
||||
auto dummy_buffer_handle = media::mojom::SharedImageBufferHandleSet::New();
|
||||
auto shared_image = gpu::ClientSharedImage::CreateForTesting();
|
||||
auto dummy_buffer_handle = media::mojom::SharedImageBufferHandleSet::New(
|
||||
shared_image->Export(), gpu::SyncToken(),
|
||||
shared_image->GetTextureTarget());
|
||||
adapter_->OnNewSharedImageBufferHandle(buffer_id,
|
||||
std::move(dummy_buffer_handle));
|
||||
}
|
||||
|
@ -36,9 +36,11 @@ namespace {
|
||||
|
||||
// Helper, returns dummy (but valid) VideoBufferHandlePtr.
|
||||
media::mojom::VideoBufferHandlePtr GetDummyVideoBufferHandle() {
|
||||
auto shared_image = gpu::ClientSharedImage::CreateForTesting();
|
||||
return media::mojom::VideoBufferHandle::NewSharedImageHandles(
|
||||
media::mojom::SharedImageBufferHandleSet::New(
|
||||
std::vector<gpu::ExportedSharedImage>(), gpu::SyncToken(), 0));
|
||||
shared_image->Export(), gpu::SyncToken(),
|
||||
shared_image->GetTextureTarget()));
|
||||
}
|
||||
|
||||
class VideoEffectsProcessorTest : public testing::Test {
|
||||
|
@ -124,8 +124,8 @@ struct VideoCaptureImpl::BufferContext
|
||||
const base::ReadOnlySharedMemoryRegion* read_only_shmem_region() const {
|
||||
return &read_only_shmem_region_;
|
||||
}
|
||||
const Vector<scoped_refptr<gpu::ClientSharedImage>>& shared_images() const {
|
||||
return shared_images_;
|
||||
const scoped_refptr<gpu::ClientSharedImage>& shared_image() const {
|
||||
return shared_image_;
|
||||
}
|
||||
const gpu::SyncToken& shared_image_sync_token() const {
|
||||
return shared_image_sync_token_;
|
||||
@ -216,18 +216,8 @@ struct VideoCaptureImpl::BufferContext
|
||||
|
||||
void InitializeFromSharedImage(
|
||||
media::mojom::blink::SharedImageBufferHandleSetPtr shared_image_handles) {
|
||||
DCHECK_GE(media::VideoFrame::kMaxPlanes,
|
||||
shared_image_handles->shared_images.size());
|
||||
for (wtf_size_t i = 0; i < media::VideoFrame::kMaxPlanes; ++i) {
|
||||
if (i < shared_image_handles->shared_images.size()) {
|
||||
scoped_refptr<gpu::ClientSharedImage> shared_image =
|
||||
gpu::ClientSharedImage::ImportUnowned(
|
||||
shared_image_handles->shared_images[i]);
|
||||
shared_images_.emplace_back(shared_image);
|
||||
} else {
|
||||
shared_images_.emplace_back(nullptr);
|
||||
}
|
||||
}
|
||||
shared_image_ = gpu::ClientSharedImage::ImportUnowned(
|
||||
shared_image_handles->shared_image);
|
||||
shared_image_sync_token_ = shared_image_handles->sync_token;
|
||||
shared_image_texture_target_ = shared_image_handles->texture_target;
|
||||
}
|
||||
@ -272,7 +262,7 @@ struct VideoCaptureImpl::BufferContext
|
||||
size_t data_size_ = 0;
|
||||
|
||||
// Only valid for |buffer_type_ == SHARED_IMAGE_HANDLES|.
|
||||
Vector<scoped_refptr<gpu::ClientSharedImage>> shared_images_;
|
||||
scoped_refptr<gpu::ClientSharedImage> shared_image_;
|
||||
gpu::SyncToken shared_image_sync_token_;
|
||||
uint32_t shared_image_texture_target_;
|
||||
|
||||
@ -383,17 +373,12 @@ VideoCaptureImpl::CreateVideoFrameInitData(
|
||||
break;
|
||||
}
|
||||
case VideoFrameBufferHandleType::kSharedImageHandles: {
|
||||
scoped_refptr<gpu::ClientSharedImage>
|
||||
shared_images[media::VideoFrame::kMaxPlanes];
|
||||
CHECK_GE(media::VideoFrame::kMaxPlanes,
|
||||
buffer_context->shared_images().size());
|
||||
for (wtf_size_t i = 0; i < buffer_context->shared_images().size(); i++) {
|
||||
shared_images[i] = buffer_context->shared_images()[i];
|
||||
}
|
||||
CHECK(buffer_context->shared_image());
|
||||
video_frame_init_data.frame_or_buffer =
|
||||
media::VideoFrame::WrapSharedImages(
|
||||
media::VideoFrame::WrapSharedImage(
|
||||
video_frame_init_data.ready_buffer->info->pixel_format,
|
||||
shared_images, buffer_context->shared_image_sync_token(),
|
||||
buffer_context->shared_image(),
|
||||
buffer_context->shared_image_sync_token(),
|
||||
buffer_context->shared_image_texture_target(),
|
||||
media::VideoFrame::ReleaseMailboxCB(),
|
||||
gfx::Size(video_frame_init_data.ready_buffer->info->coded_size),
|
||||
|
Reference in New Issue
Block a user