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..0711e18037f60aef432d4a9cc14a585779dcb107 100644 |
--- a/chrome/gpu/arc_gpu_video_decode_accelerator.cc |
+++ b/chrome/gpu/arc_gpu_video_decode_accelerator.cc |
@@ -14,6 +14,23 @@ |
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 codec. |
+// 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 kMaxArcCodecCount = 8; |
+ |
+} // anonymous namespace |
+ |
+// Since ArcGpuVideoDecodeAccelerator only works in the same thread, it's safe |
+// to access this variable without lock. |
+int ArcGpuVideoDecodeAccelerator::arc_codec_count_ = 0; |
+ |
ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord( |
int32_t bitstream_buffer_id, |
uint32_t buffer_index, |
@@ -42,17 +59,13 @@ 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() { |
+ if (vda_) { |
Pawel Osciak
2016/06/03 03:56:18
How do we guarantee this happens on the correct th
kcwu
2016/06/03 13:14:14
Done.
|
+ arc_codec_count_--; |
+ } |
+} |
-bool ArcGpuVideoDecodeAccelerator::Initialize( |
+ArcVideoAccelerator::Error ArcGpuVideoDecodeAccelerator::Initialize( |
const Config& config, |
ArcVideoAccelerator::Client* client) { |
DVLOG(5) << "Initialize(device=" << config.device_type |
@@ -60,19 +73,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 (arc_codec_count_ >= kMaxArcCodecCount) { |
+ LOG(WARNING) << "Reject to Initialize() due to too many ARC codec in use: " |
+ << arc_codec_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 +105,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 +115,13 @@ 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; |
+ |
+ arc_codec_count_++; |
+ DVLOG(5) << "Number of VDA in use: " << arc_codec_count_; |
+ |
+ return NO_ERROR; |
} |
void ArcGpuVideoDecodeAccelerator::SetNumberOfOutputBuffers(size_t number) { |