Skip to content

Commit

Permalink
Move from sysmem.Allocator to sysmem2.Allocator.
Browse files Browse the repository at this point in the history
b/306258175
  • Loading branch information
dustingreen committed Aug 13, 2024
1 parent 20d2e12 commit 3d286b2
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 73 deletions.
21 changes: 10 additions & 11 deletions media/cdm/fuchsia/fuchsia_stream_decryptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,15 @@ void FuchsiaStreamDecryptor::OnStreamProcessorAllocateOutputBuffers(
base::BindOnce(&Sink::OnSysmemBufferStreamBufferCollectionToken,
base::Unretained(sink_)));

fuchsia::sysmem::BufferCollectionConstraints buffer_constraints;
buffer_constraints.usage.none = fuchsia::sysmem::noneUsage;
buffer_constraints.min_buffer_count = min_buffer_count_;
buffer_constraints.has_buffer_memory_constraints = true;
buffer_constraints.buffer_memory_constraints.min_size_bytes =
min_buffer_size_;
buffer_constraints.buffer_memory_constraints.ram_domain_supported = true;
buffer_constraints.buffer_memory_constraints.cpu_domain_supported = true;
buffer_constraints.buffer_memory_constraints.inaccessible_domain_supported =
true;
fuchsia::sysmem2::BufferCollectionConstraints buffer_constraints;
buffer_constraints.mutable_usage()->set_none(fuchsia::sysmem2::noneUsage);
buffer_constraints.set_min_buffer_count(min_buffer_count_);
auto& buffer_memory_constraints =
buffer_constraints.mutable_buffer_memory_constraints();
buffer_memory_constraints.set_min_size_bytes(min_buffer_size_);
buffer_memory_constraints.set_ram_domain_supported(true);
buffer_memory_constraints.set_cpu_domain_supported(true);
buffer_memory_constraints.set_inaccessible_domain_supported(true);

output_buffer_collection_->Initialize(std::move(buffer_constraints),
"CrFuchsiaStreamDecryptorOutput");
Expand Down Expand Up @@ -225,7 +224,7 @@ void FuchsiaStreamDecryptor::OnError() {

void FuchsiaStreamDecryptor::OnInputBuffersAcquired(
std::vector<VmoBuffer> buffers,
const fuchsia::sysmem::SingleBufferSettings&) {
const fuchsia::sysmem2::SingleBufferSettings&) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

if (buffers.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion media/cdm/fuchsia/fuchsia_stream_decryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MEDIA_EXPORT FuchsiaStreamDecryptor

void OnInputBuffersAcquired(
std::vector<VmoBuffer> buffers,
const fuchsia::sysmem::SingleBufferSettings& buffer_settings);
const fuchsia::sysmem2::SingleBufferSettings& buffer_settings);
void SendInputPacket(const DecoderBuffer* buffer,
StreamProcessorHelper::IoPacket packet);
void ProcessEndOfStream();
Expand Down
26 changes: 13 additions & 13 deletions media/fuchsia/common/sysmem_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
namespace media {

SysmemCollectionClient::SysmemCollectionClient(
fuchsia::sysmem::Allocator* allocator,
fuchsia::sysmem::BufferCollectionTokenPtr collection_token)
fuchsia::sysmem2::Allocator* allocator,
fuchsia::sysmem2::BufferCollectionTokenPtr collection_token)
: allocator_(allocator), collection_token_(std::move(collection_token)) {
DCHECK(allocator_);
DCHECK(collection_token_);
Expand All @@ -32,13 +32,13 @@ SysmemCollectionClient::~SysmemCollectionClient() {
}

void SysmemCollectionClient::Initialize(
fuchsia::sysmem::BufferCollectionConstraints constraints,
fuchsia::sysmem2::BufferCollectionConstraints constraints,
base::StringPiece name,
uint32_t name_priority) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);

writable_ = (constraints.usage.cpu & fuchsia::sysmem::cpuUsageWrite) ==
fuchsia::sysmem::cpuUsageWrite;
writable_ = (constraints.usage.cpu & fuchsia::sysmem2::cpuUsageWrite) ==
fuchsia::sysmem2::cpuUsageWrite;

allocator_->BindSharedCollection(std::move(collection_token_),
collection_.NewRequest());
Expand All @@ -55,7 +55,7 @@ void SysmemCollectionClient::Initialize(
}

sync_completion_closures_.push_back(
base::BindOnce(&fuchsia::sysmem::BufferCollection::SetConstraints,
base::BindOnce(&fuchsia::sysmem2::BufferCollection::SetConstraints,
base::Unretained(collection_.get()),
/*have_constraints=*/true, std::move(constraints)));
collection_->Sync(
Expand All @@ -69,7 +69,7 @@ void SysmemCollectionClient::CreateSharedToken(
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(collection_token_);

fuchsia::sysmem::BufferCollectionTokenPtr token;
fuchsia::sysmem2::BufferCollectionTokenPtr token;
collection_token_->Duplicate(ZX_RIGHT_SAME_RIGHTS, token.NewRequest());

if (!debug_client_name.empty()) {
Expand Down Expand Up @@ -106,7 +106,7 @@ void SysmemCollectionClient::OnSyncComplete() {

void SysmemCollectionClient::OnBuffersAllocated(
zx_status_t status,
fuchsia::sysmem::BufferCollectionInfo_2 buffer_collection_info) {
fuchsia::sysmem2::BufferCollectionInfo_2 buffer_collection_info) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);

if (status != ZX_OK) {
Expand Down Expand Up @@ -134,7 +134,7 @@ void SysmemCollectionClient::OnError(zx_status_t status) {
SysmemAllocatorClient::SysmemAllocatorClient(base::StringPiece client_name) {
allocator_ = base::ComponentContextForProcess()
->svc()
->Connect<fuchsia::sysmem::Allocator>();
->Connect<fuchsia::sysmem2::Allocator>();

allocator_->SetDebugClientInfo(std::string(client_name),
base::GetCurrentProcId());
Expand All @@ -143,15 +143,15 @@ SysmemAllocatorClient::SysmemAllocatorClient(base::StringPiece client_name) {
// Just log a warning. We will handle BufferCollection the failure when
// trying to create a new BufferCollection.
ZX_DLOG(WARNING, status)
<< "The fuchsia.sysmem.Allocator channel was disconnected.";
<< "The fuchsia.sysmem2.Allocator channel was disconnected.";
});
}

SysmemAllocatorClient::~SysmemAllocatorClient() = default;

fuchsia::sysmem::BufferCollectionTokenPtr
fuchsia::sysmem2::BufferCollectionTokenPtr
SysmemAllocatorClient::CreateNewToken() {
fuchsia::sysmem::BufferCollectionTokenPtr collection_token;
fuchsia::sysmem2::BufferCollectionTokenPtr collection_token;
allocator_->AllocateSharedCollection(collection_token.NewRequest());
return collection_token;
}
Expand All @@ -164,7 +164,7 @@ SysmemAllocatorClient::AllocateNewCollection() {

std::unique_ptr<SysmemCollectionClient>
SysmemAllocatorClient::BindSharedCollection(
fuchsia::sysmem::BufferCollectionTokenPtr token) {
fuchsia::sysmem2::BufferCollectionTokenPtr token) {
return std::make_unique<SysmemCollectionClient>(allocator_.get(),
std::move(token));
}
Expand Down
28 changes: 14 additions & 14 deletions media/fuchsia/common/sysmem_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define MEDIA_FUCHSIA_COMMON_SYSMEM_CLIENT_H_

#include <fuchsia/media/cpp/fidl.h>
#include <fuchsia/sysmem/cpp/fidl.h>
#include <fuchsia/sysmem2/cpp/fidl.h>

#include <vector>

Expand All @@ -18,7 +18,7 @@ namespace media {

class VmoBuffer;

// Wrapper for fuchsia.sysmem.BufferCollection . It provides the following two
// Wrapper for fuchsia.sysmem2.BufferCollection . It provides the following two
// features:
// 1. Calls Sync() and ensures that it completes before buffer constrains are
// set and shared tokens are passed to other participants.
Expand All @@ -30,17 +30,17 @@ class MEDIA_EXPORT SysmemCollectionClient {

// Callback for GetSharedToken().
using GetSharedTokenCB =
base::OnceCallback<void(fuchsia::sysmem::BufferCollectionTokenPtr token)>;
base::OnceCallback<void(fuchsia::sysmem2::BufferCollectionTokenPtr token)>;

// Callback for AcquireBuffers(). Called with an empty |buffers| if buffers
// allocation failed.
using AcquireBuffersCB = base::OnceCallback<void(
std::vector<VmoBuffer> buffers,
const fuchsia::sysmem::SingleBufferSettings& settings)>;
const fuchsia::sysmem2::SingleBufferSettings& settings)>;

SysmemCollectionClient(
fuchsia::sysmem::Allocator* allocator,
fuchsia::sysmem::BufferCollectionTokenPtr collection_token);
fuchsia::sysmem2::Allocator* allocator,
fuchsia::sysmem2::BufferCollectionTokenPtr collection_token);
~SysmemCollectionClient();

SysmemCollectionClient(const SysmemCollectionClient&) = delete;
Expand All @@ -55,7 +55,7 @@ class MEDIA_EXPORT SysmemCollectionClient {
uint64_t debug_client_id = 0);

// Initializes the collection with the given name and constraints.
void Initialize(fuchsia::sysmem::BufferCollectionConstraints constraints,
void Initialize(fuchsia::sysmem2::BufferCollectionConstraints constraints,
base::StringPiece name,
uint32_t name_priority = kDefaultNamePriority);

Expand All @@ -67,12 +67,12 @@ class MEDIA_EXPORT SysmemCollectionClient {
void OnSyncComplete();
void OnBuffersAllocated(
zx_status_t status,
fuchsia::sysmem::BufferCollectionInfo_2 buffer_collection_info);
fuchsia::sysmem2::BufferCollectionInfo buffer_collection_info);
void OnError(zx_status_t status);

fuchsia::sysmem::Allocator* const allocator_;
fuchsia::sysmem::BufferCollectionTokenPtr collection_token_;
fuchsia::sysmem::BufferCollectionPtr collection_;
fuchsia::sysmem2::Allocator* const allocator_;
fuchsia::sysmem2::BufferCollectionTokenPtr collection_token_;
fuchsia::sysmem2::BufferCollectionPtr collection_;

bool writable_ = false;
std::vector<base::OnceClosure> sync_completion_closures_;
Expand All @@ -90,19 +90,19 @@ class MEDIA_EXPORT SysmemAllocatorClient {
SysmemAllocatorClient(const SysmemAllocatorClient&) = delete;
SysmemAllocatorClient& operator=(const SysmemAllocatorClient&) = delete;

fuchsia::sysmem::BufferCollectionTokenPtr CreateNewToken();
fuchsia::sysmem2::BufferCollectionTokenPtr CreateNewToken();

// Creates new buffer collection.
std::unique_ptr<SysmemCollectionClient> AllocateNewCollection();

// Binds the specified token to a SysmemCollectionClient.
std::unique_ptr<SysmemCollectionClient> BindSharedCollection(
fuchsia::sysmem::BufferCollectionTokenPtr token);
fuchsia::sysmem2::BufferCollectionTokenPtr token);

private:
friend SysmemCollectionClient;

fuchsia::sysmem::AllocatorPtr allocator_;
fuchsia::sysmem2::AllocatorPtr allocator_;
};

} // namespace media
Expand Down
65 changes: 31 additions & 34 deletions media/fuchsia/video/fuchsia_video_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include "media/fuchsia/video/fuchsia_video_decoder.h"

#include <fuchsia/images2/cpp/fidl.h>
#include <fuchsia/sysmem/cpp/fidl.h>
#include <fuchsia/sysmem2/cpp/fidl.h>
#include <lib/zx/eventpair.h>
#include <vulkan/vulkan.h>

Expand Down Expand Up @@ -66,17 +68,17 @@ constexpr size_t kNumInputBuffers = 2;
// codecs, not just H264).
constexpr size_t kInputBufferSize = 1920 * 1080 * 3 / 2 / 2 + 128 * 1024;

const fuchsia::sysmem::PixelFormatType kSupportedPixelFormats[] = {
fuchsia::sysmem::PixelFormatType::NV12,
fuchsia::sysmem::PixelFormatType::I420,
fuchsia::sysmem::PixelFormatType::YV12,
const fuchsia::images2::PixelFormat kSupportedPixelFormats[] = {
fuchsia::images2::PixelFormat::NV12,
fuchsia::images2::PixelFormat::I420,
fuchsia::images2::PixelFormat::YV12,
};
const fuchsia::sysmem::ColorSpaceType kSupportedColorSpaces[] = {
fuchsia::sysmem::ColorSpaceType::REC601_NTSC,
fuchsia::sysmem::ColorSpaceType::REC601_NTSC_FULL_RANGE,
fuchsia::sysmem::ColorSpaceType::REC601_PAL,
fuchsia::sysmem::ColorSpaceType::REC601_PAL_FULL_RANGE,
fuchsia::sysmem::ColorSpaceType::REC709,
const fuchsia::images2::ColorSpace kSupportedColorSpaces[] = {
fuchsia::images2::ColorSpace::REC601_NTSC,
fuchsia::images2::ColorSpace::REC601_NTSC_FULL_RANGE,
fuchsia::images2::ColorSpace::REC601_PAL,
fuchsia::images2::ColorSpace::REC601_PAL_FULL_RANGE,
fuchsia::images2::ColorSpace::REC709,
};

absl::optional<gfx::Size> ParseMinBufferSize() {
Expand Down Expand Up @@ -438,7 +440,7 @@ DecoderStatus FuchsiaVideoDecoder::InitializeSysmemBufferStream(
}

void FuchsiaVideoDecoder::OnSysmemBufferStreamBufferCollectionToken(
fuchsia::sysmem::BufferCollectionTokenPtr token) {
fuchsia::sysmem2::BufferCollectionTokenPtr token) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(decoder_);
decoder_->SetInputBufferCollectionToken(std::move(token));
Expand Down Expand Up @@ -485,29 +487,25 @@ void FuchsiaVideoDecoder::OnStreamProcessorAllocateOutputBuffers(
base::Unretained(this)),
"gpu");

fuchsia::sysmem::BufferCollectionConstraints buffer_constraints;
buffer_constraints.usage.none = fuchsia::sysmem::noneUsage;
buffer_constraints.min_buffer_count_for_camping = kOutputBuffersForCamping;
buffer_constraints.min_buffer_count_for_shared_slack =
kMaxUsedOutputBuffers - kOutputBuffersForCamping;
fuchsia::sysmem2::BufferCollectionConstraints buffer_constraints;
buffer_constraints.mutable_usage()->set_none(fuchsia::sysmem2::noneUsage);
buffer_constraints.set_min_buffer_count_for_camping(kOutputBuffersForCamping);
buffer_constraints.set_min_buffer_count_for_shared_slack(
kMaxUsedOutputBuffers - kOutputBuffersForCamping);

buffer_constraints.image_format_constraints_count =
std::size(kSupportedPixelFormats);
auto& image_format_constraints_vector =
buffer_constraints.mutable_image_format_constraints();
for (size_t pixel_format_index = 0;
pixel_format_index < std::size(kSupportedPixelFormats);
++pixel_format_index) {
auto& image_format_constraints =
buffer_constraints.image_format_constraints[pixel_format_index];
image_format_constraints.pixel_format.type =
kSupportedPixelFormats[pixel_format_index];
image_format_constraints.pixel_format.has_format_modifier = true;
image_format_constraints.pixel_format.format_modifier.value =
fuchsia::sysmem::FORMAT_MODIFIER_LINEAR;

image_format_constraints.color_spaces_count =
std::size(kSupportedColorSpaces);
image_format_constraints_vector.emplace_back();
image_format_constraints.set_pixel_format(
kSupportedPixelFormats[pixel_format_index]);

auto& color_spaces = image_format_constraints.mutable_color_spaces();
for (size_t i = 0; i < std::size(kSupportedColorSpaces); ++i) {
image_format_constraints.color_space[i].type = kSupportedColorSpaces[i];
color_spaces.emplace_back(kSupportedColorSpaces[i]);
}
}

Expand All @@ -517,11 +515,10 @@ void FuchsiaVideoDecoder::OnStreamProcessorAllocateOutputBuffers(
pixel_format_index < std::size(kSupportedPixelFormats);
++pixel_format_index) {
auto& image_format_constraints =
buffer_constraints.image_format_constraints[pixel_format_index];
image_format_constraints.required_max_coded_width =
min_buffer_size->width();
image_format_constraints.required_max_coded_height =
min_buffer_size->height();
buffer_constraints.image_format_constraints()[pixel_format_index];
image_format_constraints.set_required_max_size(fuchsia::math::SizeU{
.width = min_buffer_size->width(),
.height = min_buffer_size->height()});
}
}

Expand Down Expand Up @@ -739,7 +736,7 @@ void FuchsiaVideoDecoder::OnError() {
}

void FuchsiaVideoDecoder::SetBufferCollectionTokenForGpu(
fuchsia::sysmem::BufferCollectionTokenPtr token) {
fuchsia::sysmem2::BufferCollectionTokenPtr token) {
// Register the new collection with the GPU process.
DCHECK(!output_buffer_collection_handle_);

Expand Down

0 comments on commit 3d286b2

Please sign in to comment.