OLD | NEW |
---|---|
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 codec. | |
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 kMaxArcCodecCount = 8; | |
27 | |
28 } // anonymous namespace | |
29 | |
30 // Since ArcGpuVideoDecodeAccelerator only works in the same thread, it's safe | |
31 // to access this variable without lock. | |
32 int ArcGpuVideoDecodeAccelerator::arc_codec_count_ = 0; | |
33 | |
17 ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord( | 34 ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord( |
18 int32_t bitstream_buffer_id, | 35 int32_t bitstream_buffer_id, |
19 uint32_t buffer_index, | 36 uint32_t buffer_index, |
20 int64_t timestamp) | 37 int64_t timestamp) |
21 : bitstream_buffer_id(bitstream_buffer_id), | 38 : bitstream_buffer_id(bitstream_buffer_id), |
22 buffer_index(buffer_index), | 39 buffer_index(buffer_index), |
23 timestamp(timestamp) {} | 40 timestamp(timestamp) {} |
24 | 41 |
25 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo() = default; | 42 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo() = default; |
26 | 43 |
27 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo( | 44 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo( |
28 InputBufferInfo&& other) = default; | 45 InputBufferInfo&& other) = default; |
29 | 46 |
30 ArcGpuVideoDecodeAccelerator::InputBufferInfo::~InputBufferInfo() = default; | 47 ArcGpuVideoDecodeAccelerator::InputBufferInfo::~InputBufferInfo() = default; |
31 | 48 |
32 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::OutputBufferInfo() = default; | 49 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::OutputBufferInfo() = default; |
33 | 50 |
34 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::OutputBufferInfo( | 51 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::OutputBufferInfo( |
35 OutputBufferInfo&& other) = default; | 52 OutputBufferInfo&& other) = default; |
36 | 53 |
37 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::~OutputBufferInfo() = default; | 54 ArcGpuVideoDecodeAccelerator::OutputBufferInfo::~OutputBufferInfo() = default; |
38 | 55 |
39 ArcGpuVideoDecodeAccelerator::ArcGpuVideoDecodeAccelerator() | 56 ArcGpuVideoDecodeAccelerator::ArcGpuVideoDecodeAccelerator() |
40 : arc_client_(nullptr), | 57 : arc_client_(nullptr), |
41 next_bitstream_buffer_id_(0), | 58 next_bitstream_buffer_id_(0), |
42 output_pixel_format_(media::PIXEL_FORMAT_UNKNOWN), | 59 output_pixel_format_(media::PIXEL_FORMAT_UNKNOWN), |
43 output_buffer_size_(0) {} | 60 output_buffer_size_(0) {} |
44 | 61 |
45 ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() {} | 62 ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() { |
63 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.
| |
64 arc_codec_count_--; | |
65 } | |
66 } | |
46 | 67 |
47 namespace { | 68 ArcVideoAccelerator::Error 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, | 69 const Config& config, |
57 ArcVideoAccelerator::Client* client) { | 70 ArcVideoAccelerator::Client* client) { |
58 DVLOG(5) << "Initialize(device=" << config.device_type | 71 DVLOG(5) << "Initialize(device=" << config.device_type |
59 << ", input_pixel_format=" << config.input_pixel_format | 72 << ", input_pixel_format=" << config.input_pixel_format |
60 << ", num_input_buffers=" << config.num_input_buffers << ")"; | 73 << ", num_input_buffers=" << config.num_input_buffers << ")"; |
61 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
62 if (config.device_type != Config::DEVICE_DECODER) | 75 if (config.device_type != Config::DEVICE_DECODER) |
63 return false; | 76 return INVALID_ARGUMENT; |
64 DCHECK(client); | 77 DCHECK(client); |
65 | 78 |
66 if (arc_client_) { | 79 if (arc_client_) { |
67 DLOG(ERROR) << "Re-Initialize() is not allowed"; | 80 DLOG(ERROR) << "Re-Initialize() is not allowed"; |
68 return false; | 81 return ILLEGAL_STATE; |
82 } | |
83 | |
84 if (arc_codec_count_ >= kMaxArcCodecCount) { | |
85 LOG(WARNING) << "Reject to Initialize() due to too many ARC codec in use: " | |
86 << arc_codec_count_; | |
87 return INSUFFICIENT_RESOURCES; | |
69 } | 88 } |
70 | 89 |
71 arc_client_ = client; | 90 arc_client_ = client; |
72 | 91 |
73 if (config.num_input_buffers > kMaxBufferCount) { | 92 if (config.num_input_buffers > kMaxBufferCount) { |
74 DLOG(ERROR) << "Request too many buffers: " << config.num_input_buffers; | 93 DLOG(ERROR) << "Request too many buffers: " << config.num_input_buffers; |
75 return false; | 94 return INVALID_ARGUMENT; |
76 } | 95 } |
77 input_buffer_info_.resize(config.num_input_buffers); | 96 input_buffer_info_.resize(config.num_input_buffers); |
78 | 97 |
79 media::VideoDecodeAccelerator::Config vda_config; | 98 media::VideoDecodeAccelerator::Config vda_config; |
80 switch (config.input_pixel_format) { | 99 switch (config.input_pixel_format) { |
81 case HAL_PIXEL_FORMAT_H264: | 100 case HAL_PIXEL_FORMAT_H264: |
82 vda_config.profile = media::H264PROFILE_MAIN; | 101 vda_config.profile = media::H264PROFILE_MAIN; |
83 break; | 102 break; |
84 case HAL_PIXEL_FORMAT_VP8: | 103 case HAL_PIXEL_FORMAT_VP8: |
85 vda_config.profile = media::VP8PROFILE_ANY; | 104 vda_config.profile = media::VP8PROFILE_ANY; |
86 break; | 105 break; |
87 default: | 106 default: |
88 DLOG(ERROR) << "Unsupported input format: " << config.input_pixel_format; | 107 DLOG(ERROR) << "Unsupported input format: " << config.input_pixel_format; |
89 return false; | 108 return INVALID_ARGUMENT; |
90 } | 109 } |
91 vda_config.output_mode = | 110 vda_config.output_mode = |
92 media::VideoDecodeAccelerator::Config::OutputMode::IMPORT; | 111 media::VideoDecodeAccelerator::Config::OutputMode::IMPORT; |
93 | 112 |
94 std::unique_ptr<content::GpuVideoDecodeAcceleratorFactory> vda_factory = | 113 std::unique_ptr<content::GpuVideoDecodeAcceleratorFactory> vda_factory = |
95 content::GpuVideoDecodeAcceleratorFactory::CreateWithNoGL(); | 114 content::GpuVideoDecodeAcceleratorFactory::CreateWithNoGL(); |
96 vda_ = vda_factory->CreateVDA(this, vda_config); | 115 vda_ = vda_factory->CreateVDA(this, vda_config); |
97 if (!vda_) { | 116 if (!vda_) { |
98 DLOG(ERROR) << "Failed to create VDA."; | 117 DLOG(ERROR) << "Failed to create VDA."; |
99 return false; | 118 return PLATFORM_FAILURE; |
100 } | 119 } |
101 return true; | 120 |
121 arc_codec_count_++; | |
122 DVLOG(5) << "Number of VDA in use: " << arc_codec_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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
OLD | NEW |