Chromium Code Reviews| Index: chrome/gpu/arc_gpu_video_decode_accelerator.cc |
| diff --git a/chrome/gpu/arc_gpu_video_decode_accelerator.cc b/chrome/gpu/arc_gpu_video_decode_accelerator.cc |
| index 52444a0c56843445e30be7d5fbbe5edf10e97127..c425eb0e0854e7ff040ccc63a4252cd1ac7c2707 100644 |
| --- a/chrome/gpu/arc_gpu_video_decode_accelerator.cc |
| +++ b/chrome/gpu/arc_gpu_video_decode_accelerator.cc |
| @@ -14,6 +14,21 @@ |
| namespace chromeos { |
| namespace arc { |
| +namespace { |
| + |
| +// An arbitrary chosen limit of the number of buffers. The number of |
| +// buffers used is requested from the untrusted client side. |
| +const size_t kMaxBufferCount = 128; |
| + |
| +// Maximum number of concurrent ARC video client. |
|
Pawel Osciak
2016/06/06 05:49:12
s/client/clients/
kcwu
2016/06/06 06:53:12
Done.
|
| +// Currently we have no way to know the resources are not enough to create more |
| +// VDA. Arbitrarily chosen a reasonable constant as the limit. |
| +const int kMaxConcurrentClient = 8; |
|
Pawel Osciak
2016/06/06 05:49:13
s/Client/Clients/
kcwu
2016/06/06 06:53:12
Done.
|
| + |
| +} // anonymous namespace |
| + |
| +int ArcGpuVideoDecodeAccelerator::client_count_ = 0; |
| + |
| ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord( |
| int32_t bitstream_buffer_id, |
| uint32_t buffer_index, |
| @@ -42,17 +57,14 @@ ArcGpuVideoDecodeAccelerator::ArcGpuVideoDecodeAccelerator() |
| output_pixel_format_(media::PIXEL_FORMAT_UNKNOWN), |
| output_buffer_size_(0) {} |
| -ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() {} |
| - |
| -namespace { |
| - |
| -// An arbitrary chosen limit of the number of buffers. The number of |
| -// buffers used is requested from the untrusted client side. |
| -const size_t kMaxBufferCount = 128; |
| - |
| -} // anonymous namespace |
| +ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (vda_) { |
| + client_count_--; |
| + } |
| +} |
| -bool ArcGpuVideoDecodeAccelerator::Initialize( |
| +ArcVideoAccelerator::Result ArcGpuVideoDecodeAccelerator::Initialize( |
| const Config& config, |
| ArcVideoAccelerator::Client* client) { |
| DVLOG(5) << "Initialize(device=" << config.device_type |
| @@ -60,19 +72,25 @@ bool ArcGpuVideoDecodeAccelerator::Initialize( |
| << ", num_input_buffers=" << config.num_input_buffers << ")"; |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| if (config.device_type != Config::DEVICE_DECODER) |
| - return false; |
| + return INVALID_ARGUMENT; |
| DCHECK(client); |
| if (arc_client_) { |
| DLOG(ERROR) << "Re-Initialize() is not allowed"; |
| - return false; |
| + return ILLEGAL_STATE; |
| + } |
| + |
| + if (client_count_ >= kMaxConcurrentClient) { |
| + LOG(WARNING) << "Reject to Initialize() due to too many clients: " |
| + << client_count_; |
| + return INSUFFICIENT_RESOURCES; |
| } |
| arc_client_ = client; |
| if (config.num_input_buffers > kMaxBufferCount) { |
| DLOG(ERROR) << "Request too many buffers: " << config.num_input_buffers; |
| - return false; |
| + return INVALID_ARGUMENT; |
| } |
| input_buffer_info_.resize(config.num_input_buffers); |
| @@ -86,7 +104,7 @@ bool ArcGpuVideoDecodeAccelerator::Initialize( |
| break; |
| default: |
| DLOG(ERROR) << "Unsupported input format: " << config.input_pixel_format; |
| - return false; |
| + return INVALID_ARGUMENT; |
| } |
| vda_config.output_mode = |
| media::VideoDecodeAccelerator::Config::OutputMode::IMPORT; |
| @@ -96,9 +114,14 @@ bool ArcGpuVideoDecodeAccelerator::Initialize( |
| vda_ = vda_factory->CreateVDA(this, vda_config); |
| if (!vda_) { |
| DLOG(ERROR) << "Failed to create VDA."; |
| - return false; |
| + return PLATFORM_FAILURE; |
| } |
| - return true; |
| + |
| + client_count_++; |
| + DVLOG(5) << "Number of concurrent ArcVideoAccelerator client: " |
|
Pawel Osciak
2016/06/06 05:49:12
s/client/clients/
kcwu
2016/06/06 06:53:12
Done.
|
| + << client_count_; |
| + |
| + return NO_ERROR; |
| } |
| void ArcGpuVideoDecodeAccelerator::SetNumberOfOutputBuffers(size_t number) { |
| @@ -394,7 +417,7 @@ void ArcGpuVideoDecodeAccelerator::NotifyResetDone() { |
| arc_client_->OnResetDone(); |
| } |
| -static ArcVideoAccelerator::Error ConvertErrorCode( |
| +static ArcVideoAccelerator::Result ConvertErrorCode( |
| media::VideoDecodeAccelerator::Error error) { |
| switch (error) { |
| case media::VideoDecodeAccelerator::ILLEGAL_STATE: |