Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/gpu/arc_gpu_video_decode_accelerator.cc

Issue 2036723002: Limit the number of ARC codec (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed owenlin and posciak's comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/gpu/arc_gpu_video_decode_accelerator.h" 5 #include "chrome/gpu/arc_gpu_video_decode_accelerator.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/numerics/safe_math.h" 9 #include "base/numerics/safe_math.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "content/public/gpu/gpu_video_decode_accelerator_factory.h" 11 #include "content/public/gpu/gpu_video_decode_accelerator_factory.h"
12 #include "media/base/video_frame.h" 12 #include "media/base/video_frame.h"
13 13
14 namespace chromeos { 14 namespace chromeos {
15 namespace arc { 15 namespace arc {
16 16
17 namespace {
18
19 // An arbitrary chosen limit of the number of buffers. The number of
20 // buffers used is requested from the untrusted client side.
21 const size_t kMaxBufferCount = 128;
22
23 // 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.
24 // Currently we have no way to know the resources are not enough to create more
25 // VDA. Arbitrarily chosen a reasonable constant as the limit.
26 const int kMaxConcurrentClient = 8;
Pawel Osciak 2016/06/06 05:49:13 s/Client/Clients/
kcwu 2016/06/06 06:53:12 Done.
27
28 } // anonymous namespace
29
30 int ArcGpuVideoDecodeAccelerator::client_count_ = 0;
31
17 ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord( 32 ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord(
18 int32_t bitstream_buffer_id, 33 int32_t bitstream_buffer_id,
19 uint32_t buffer_index, 34 uint32_t buffer_index,
20 int64_t timestamp) 35 int64_t timestamp)
21 : bitstream_buffer_id(bitstream_buffer_id), 36 : bitstream_buffer_id(bitstream_buffer_id),
22 buffer_index(buffer_index), 37 buffer_index(buffer_index),
23 timestamp(timestamp) {} 38 timestamp(timestamp) {}
24 39
25 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo() = default; 40 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo() = default;
26 41
27 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo( 42 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo(
28 InputBufferInfo&& other) = default; 43 InputBufferInfo&& other) = default;
29 44
30 ArcGpuVideoDecodeAccelerator::InputBufferInfo::~InputBufferInfo() = default; 45 ArcGpuVideoDecodeAccelerator::InputBufferInfo::~InputBufferInfo() = default;
31 46
32 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::OutputBufferInfo() = default; 47 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::OutputBufferInfo() = default;
33 48
34 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::OutputBufferInfo( 49 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::OutputBufferInfo(
35 OutputBufferInfo&& other) = default; 50 OutputBufferInfo&& other) = default;
36 51
37 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::~OutputBufferInfo() = default; 52 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::~OutputBufferInfo() = default;
38 53
39 ArcGpuVideoDecodeAccelerator::ArcGpuVideoDecodeAccelerator() 54 ArcGpuVideoDecodeAccelerator::ArcGpuVideoDecodeAccelerator()
40 : arc_client_(nullptr), 55 : arc_client_(nullptr),
41 next_bitstream_buffer_id_(0), 56 next_bitstream_buffer_id_(0),
42 output_pixel_format_(media::PIXEL_FORMAT_UNKNOWN), 57 output_pixel_format_(media::PIXEL_FORMAT_UNKNOWN),
43 output_buffer_size_(0) {} 58 output_buffer_size_(0) {}
44 59
45 ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() {} 60 ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() {
61 DCHECK(thread_checker_.CalledOnValidThread());
62 if (vda_) {
63 client_count_--;
64 }
65 }
46 66
47 namespace { 67 ArcVideoAccelerator::Result ArcGpuVideoDecodeAccelerator::Initialize(
48
49 // An arbitrary chosen limit of the number of buffers. The number of
50 // buffers used is requested from the untrusted client side.
51 const size_t kMaxBufferCount = 128;
52
53 } // anonymous namespace
54
55 bool ArcGpuVideoDecodeAccelerator::Initialize(
56 const Config& config, 68 const Config& config,
57 ArcVideoAccelerator::Client* client) { 69 ArcVideoAccelerator::Client* client) {
58 DVLOG(5) << "Initialize(device=" << config.device_type 70 DVLOG(5) << "Initialize(device=" << config.device_type
59 << ", input_pixel_format=" << config.input_pixel_format 71 << ", input_pixel_format=" << config.input_pixel_format
60 << ", num_input_buffers=" << config.num_input_buffers << ")"; 72 << ", num_input_buffers=" << config.num_input_buffers << ")";
61 DCHECK(thread_checker_.CalledOnValidThread()); 73 DCHECK(thread_checker_.CalledOnValidThread());
62 if (config.device_type != Config::DEVICE_DECODER) 74 if (config.device_type != Config::DEVICE_DECODER)
63 return false; 75 return INVALID_ARGUMENT;
64 DCHECK(client); 76 DCHECK(client);
65 77
66 if (arc_client_) { 78 if (arc_client_) {
67 DLOG(ERROR) << "Re-Initialize() is not allowed"; 79 DLOG(ERROR) << "Re-Initialize() is not allowed";
68 return false; 80 return ILLEGAL_STATE;
81 }
82
83 if (client_count_ >= kMaxConcurrentClient) {
84 LOG(WARNING) << "Reject to Initialize() due to too many clients: "
85 << client_count_;
86 return INSUFFICIENT_RESOURCES;
69 } 87 }
70 88
71 arc_client_ = client; 89 arc_client_ = client;
72 90
73 if (config.num_input_buffers > kMaxBufferCount) { 91 if (config.num_input_buffers > kMaxBufferCount) {
74 DLOG(ERROR) << "Request too many buffers: " << config.num_input_buffers; 92 DLOG(ERROR) << "Request too many buffers: " << config.num_input_buffers;
75 return false; 93 return INVALID_ARGUMENT;
76 } 94 }
77 input_buffer_info_.resize(config.num_input_buffers); 95 input_buffer_info_.resize(config.num_input_buffers);
78 96
79 media::VideoDecodeAccelerator::Config vda_config; 97 media::VideoDecodeAccelerator::Config vda_config;
80 switch (config.input_pixel_format) { 98 switch (config.input_pixel_format) {
81 case HAL_PIXEL_FORMAT_H264: 99 case HAL_PIXEL_FORMAT_H264:
82 vda_config.profile = media::H264PROFILE_MAIN; 100 vda_config.profile = media::H264PROFILE_MAIN;
83 break; 101 break;
84 case HAL_PIXEL_FORMAT_VP8: 102 case HAL_PIXEL_FORMAT_VP8:
85 vda_config.profile = media::VP8PROFILE_ANY; 103 vda_config.profile = media::VP8PROFILE_ANY;
86 break; 104 break;
87 default: 105 default:
88 DLOG(ERROR) << "Unsupported input format: " << config.input_pixel_format; 106 DLOG(ERROR) << "Unsupported input format: " << config.input_pixel_format;
89 return false; 107 return INVALID_ARGUMENT;
90 } 108 }
91 vda_config.output_mode = 109 vda_config.output_mode =
92 media::VideoDecodeAccelerator::Config::OutputMode::IMPORT; 110 media::VideoDecodeAccelerator::Config::OutputMode::IMPORT;
93 111
94 std::unique_ptr<content::GpuVideoDecodeAcceleratorFactory> vda_factory = 112 std::unique_ptr<content::GpuVideoDecodeAcceleratorFactory> vda_factory =
95 content::GpuVideoDecodeAcceleratorFactory::CreateWithNoGL(); 113 content::GpuVideoDecodeAcceleratorFactory::CreateWithNoGL();
96 vda_ = vda_factory->CreateVDA(this, vda_config); 114 vda_ = vda_factory->CreateVDA(this, vda_config);
97 if (!vda_) { 115 if (!vda_) {
98 DLOG(ERROR) << "Failed to create VDA."; 116 DLOG(ERROR) << "Failed to create VDA.";
99 return false; 117 return PLATFORM_FAILURE;
100 } 118 }
101 return true; 119
120 client_count_++;
121 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.
122 << client_count_;
123
124 return NO_ERROR;
102 } 125 }
103 126
104 void ArcGpuVideoDecodeAccelerator::SetNumberOfOutputBuffers(size_t number) { 127 void ArcGpuVideoDecodeAccelerator::SetNumberOfOutputBuffers(size_t number) {
105 DVLOG(5) << "SetNumberOfOutputBuffers(" << number << ")"; 128 DVLOG(5) << "SetNumberOfOutputBuffers(" << number << ")";
106 DCHECK(thread_checker_.CalledOnValidThread()); 129 DCHECK(thread_checker_.CalledOnValidThread());
107 if (!vda_) { 130 if (!vda_) {
108 DLOG(ERROR) << "VDA not initialized"; 131 DLOG(ERROR) << "VDA not initialized";
109 return; 132 return;
110 } 133 }
111 134
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 void ArcGpuVideoDecodeAccelerator::NotifyFlushDone() { 410 void ArcGpuVideoDecodeAccelerator::NotifyFlushDone() {
388 DCHECK(thread_checker_.CalledOnValidThread()); 411 DCHECK(thread_checker_.CalledOnValidThread());
389 arc_client_->OnFlushDone(); 412 arc_client_->OnFlushDone();
390 } 413 }
391 414
392 void ArcGpuVideoDecodeAccelerator::NotifyResetDone() { 415 void ArcGpuVideoDecodeAccelerator::NotifyResetDone() {
393 DCHECK(thread_checker_.CalledOnValidThread()); 416 DCHECK(thread_checker_.CalledOnValidThread());
394 arc_client_->OnResetDone(); 417 arc_client_->OnResetDone();
395 } 418 }
396 419
397 static ArcVideoAccelerator::Error ConvertErrorCode( 420 static ArcVideoAccelerator::Result ConvertErrorCode(
398 media::VideoDecodeAccelerator::Error error) { 421 media::VideoDecodeAccelerator::Error error) {
399 switch (error) { 422 switch (error) {
400 case media::VideoDecodeAccelerator::ILLEGAL_STATE: 423 case media::VideoDecodeAccelerator::ILLEGAL_STATE:
401 return ArcVideoAccelerator::ILLEGAL_STATE; 424 return ArcVideoAccelerator::ILLEGAL_STATE;
402 case media::VideoDecodeAccelerator::INVALID_ARGUMENT: 425 case media::VideoDecodeAccelerator::INVALID_ARGUMENT:
403 return ArcVideoAccelerator::INVALID_ARGUMENT; 426 return ArcVideoAccelerator::INVALID_ARGUMENT;
404 case media::VideoDecodeAccelerator::UNREADABLE_INPUT: 427 case media::VideoDecodeAccelerator::UNREADABLE_INPUT:
405 return ArcVideoAccelerator::UNREADABLE_INPUT; 428 return ArcVideoAccelerator::UNREADABLE_INPUT;
406 case media::VideoDecodeAccelerator::PLATFORM_FAILURE: 429 case media::VideoDecodeAccelerator::PLATFORM_FAILURE:
407 return ArcVideoAccelerator::PLATFORM_FAILURE; 430 return ArcVideoAccelerator::PLATFORM_FAILURE;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 } 483 }
461 return true; 484 return true;
462 default: 485 default:
463 DLOG(ERROR) << "Invalid port: " << port; 486 DLOG(ERROR) << "Invalid port: " << port;
464 return false; 487 return false;
465 } 488 }
466 } 489 }
467 490
468 } // namespace arc 491 } // namespace arc
469 } // namespace chromeos 492 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698