| 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/gpu_arc_video_service.h" | 5 #include "chrome/gpu/gpu_arc_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "chrome/gpu/arc_gpu_video_decode_accelerator.h" | 13 #include "chrome/gpu/chrome_arc_video_decode_accelerator.h" |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" | 14 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 15 #include "mojo/public/cpp/bindings/type_converter.h" | 15 #include "mojo/public/cpp/bindings/type_converter.h" |
| 16 #include "mojo/public/cpp/system/platform_handle.h" | 16 #include "mojo/public/cpp/system/platform_handle.h" |
| 17 | 17 |
| 18 // Make sure arc::mojom::VideoAcceleratorService::Result and | 18 // Make sure arc::mojom::VideoDecodeAccelerator::Result and |
| 19 // chromeos::arc::ArcVideoAccelerator::Result match. | 19 // chromeos::arc::ArcVideoDecodeAccelerator::Result match. |
| 20 static_assert( | 20 static_assert( |
| 21 static_cast<int>(arc::mojom::VideoAcceleratorService::Result::SUCCESS) == | 21 static_cast<int>(arc::mojom::VideoDecodeAccelerator::Result::SUCCESS) == |
| 22 chromeos::arc::ArcVideoAccelerator::SUCCESS, | 22 chromeos::arc::ArcVideoDecodeAccelerator::SUCCESS, |
| 23 "enum mismatch"); | 23 "enum mismatch"); |
| 24 static_assert(static_cast<int>( | 24 static_assert(static_cast<int>( |
| 25 arc::mojom::VideoAcceleratorService::Result::ILLEGAL_STATE) == | 25 arc::mojom::VideoDecodeAccelerator::Result::ILLEGAL_STATE) == |
| 26 chromeos::arc::ArcVideoAccelerator::ILLEGAL_STATE, | 26 chromeos::arc::ArcVideoDecodeAccelerator::ILLEGAL_STATE, |
| 27 "enum mismatch"); | 27 "enum mismatch"); |
| 28 static_assert( | 28 static_assert( |
| 29 static_cast<int>( | 29 static_cast<int>( |
| 30 arc::mojom::VideoAcceleratorService::Result::INVALID_ARGUMENT) == | 30 arc::mojom::VideoDecodeAccelerator::Result::INVALID_ARGUMENT) == |
| 31 chromeos::arc::ArcVideoAccelerator::INVALID_ARGUMENT, | 31 chromeos::arc::ArcVideoDecodeAccelerator::INVALID_ARGUMENT, |
| 32 "enum mismatch"); | 32 "enum mismatch"); |
| 33 static_assert( | 33 static_assert( |
| 34 static_cast<int>( | 34 static_cast<int>( |
| 35 arc::mojom::VideoAcceleratorService::Result::UNREADABLE_INPUT) == | 35 arc::mojom::VideoDecodeAccelerator::Result::UNREADABLE_INPUT) == |
| 36 chromeos::arc::ArcVideoAccelerator::UNREADABLE_INPUT, | 36 chromeos::arc::ArcVideoDecodeAccelerator::UNREADABLE_INPUT, |
| 37 "enum mismatch"); | 37 "enum mismatch"); |
| 38 static_assert( | 38 static_assert( |
| 39 static_cast<int>( | 39 static_cast<int>( |
| 40 arc::mojom::VideoAcceleratorService::Result::PLATFORM_FAILURE) == | 40 arc::mojom::VideoDecodeAccelerator::Result::PLATFORM_FAILURE) == |
| 41 chromeos::arc::ArcVideoAccelerator::PLATFORM_FAILURE, | 41 chromeos::arc::ArcVideoDecodeAccelerator::PLATFORM_FAILURE, |
| 42 "enum mismatch"); | 42 "enum mismatch"); |
| 43 static_assert( | 43 static_assert( |
| 44 static_cast<int>( | 44 static_cast<int>( |
| 45 arc::mojom::VideoAcceleratorService::Result::INSUFFICIENT_RESOURCES) == | 45 arc::mojom::VideoDecodeAccelerator::Result::INSUFFICIENT_RESOURCES) == |
| 46 chromeos::arc::ArcVideoAccelerator::INSUFFICIENT_RESOURCES, | 46 chromeos::arc::ArcVideoDecodeAccelerator::INSUFFICIENT_RESOURCES, |
| 47 "enum mismatch"); | 47 "enum mismatch"); |
| 48 | 48 |
| 49 namespace mojo { | 49 namespace mojo { |
| 50 | 50 |
| 51 template <> | 51 template <> |
| 52 struct TypeConverter<arc::mojom::BufferMetadataPtr, | 52 struct TypeConverter<arc::mojom::BufferMetadataPtr, |
| 53 chromeos::arc::BufferMetadata> { | 53 chromeos::arc::BufferMetadata> { |
| 54 static arc::mojom::BufferMetadataPtr Convert( | 54 static arc::mojom::BufferMetadataPtr Convert( |
| 55 const chromeos::arc::BufferMetadata& input) { | 55 const chromeos::arc::BufferMetadata& input) { |
| 56 arc::mojom::BufferMetadataPtr result = arc::mojom::BufferMetadata::New(); | 56 arc::mojom::BufferMetadataPtr result = arc::mojom::BufferMetadata::New(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 84 result->coded_height = input.coded_height; | 84 result->coded_height = input.coded_height; |
| 85 result->crop_left = input.crop_left; | 85 result->crop_left = input.crop_left; |
| 86 result->crop_width = input.crop_width; | 86 result->crop_width = input.crop_width; |
| 87 result->crop_top = input.crop_top; | 87 result->crop_top = input.crop_top; |
| 88 result->crop_height = input.crop_height; | 88 result->crop_height = input.crop_height; |
| 89 return result; | 89 return result; |
| 90 } | 90 } |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 template <> | 93 template <> |
| 94 struct TypeConverter<chromeos::arc::ArcVideoAccelerator::Config, | 94 struct TypeConverter<chromeos::arc::ArcVideoDecodeAccelerator::Config, |
| 95 arc::mojom::ArcVideoAcceleratorConfigPtr> { | 95 arc::mojom::VideoDecodeAcceleratorConfigPtr> { |
| 96 static chromeos::arc::ArcVideoAccelerator::Config Convert( | 96 static chromeos::arc::ArcVideoDecodeAccelerator::Config Convert( |
| 97 const arc::mojom::ArcVideoAcceleratorConfigPtr& input) { | 97 const arc::mojom::VideoDecodeAcceleratorConfigPtr& input) { |
| 98 chromeos::arc::ArcVideoAccelerator::Config result; | 98 chromeos::arc::ArcVideoDecodeAccelerator::Config result; |
| 99 result.device_type = | |
| 100 static_cast<chromeos::arc::ArcVideoAccelerator::Config::DeviceType>( | |
| 101 input->device_type); | |
| 102 result.num_input_buffers = input->num_input_buffers; | 99 result.num_input_buffers = input->num_input_buffers; |
| 103 result.input_pixel_format = input->input_pixel_format; | 100 result.input_pixel_format = input->input_pixel_format; |
| 104 return result; | 101 return result; |
| 105 } | 102 } |
| 106 }; | 103 }; |
| 107 | 104 |
| 108 } // namespace mojo | 105 } // namespace mojo |
| 109 | 106 |
| 110 namespace chromeos { | 107 namespace chromeos { |
| 111 namespace arc { | 108 namespace arc { |
| 112 | 109 |
| 113 GpuArcVideoService::GpuArcVideoService( | 110 GpuArcVideoDecodeAccelerator::GpuArcVideoDecodeAccelerator( |
| 114 const gpu::GpuPreferences& gpu_preferences) | 111 const gpu::GpuPreferences& gpu_preferences) |
| 115 : gpu_preferences_(gpu_preferences), | 112 : gpu_preferences_(gpu_preferences), |
| 116 accelerator_(new ArcGpuVideoDecodeAccelerator(gpu_preferences_)) {} | 113 accelerator_(new ChromeArcVideoDecodeAccelerator(gpu_preferences_)) {} |
| 117 | 114 |
| 118 GpuArcVideoService::~GpuArcVideoService() { | 115 GpuArcVideoDecodeAccelerator::~GpuArcVideoDecodeAccelerator() { |
| 119 DCHECK(thread_checker_.CalledOnValidThread()); | 116 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 120 } | 117 } |
| 121 | 118 |
| 122 void GpuArcVideoService::OnError(ArcVideoAccelerator::Result error) { | 119 void GpuArcVideoDecodeAccelerator::OnError( |
| 120 ArcVideoDecodeAccelerator::Result error) { |
| 123 DVLOG(2) << "OnError " << error; | 121 DVLOG(2) << "OnError " << error; |
| 124 DCHECK_NE(error, ArcVideoAccelerator::SUCCESS); | 122 DCHECK_NE(error, ArcVideoDecodeAccelerator::SUCCESS); |
| 125 DCHECK(client_); | 123 DCHECK(client_); |
| 126 client_->OnError( | 124 client_->OnError( |
| 127 static_cast<::arc::mojom::VideoAcceleratorService::Result>(error)); | 125 static_cast<::arc::mojom::VideoDecodeAccelerator::Result>(error)); |
| 128 } | 126 } |
| 129 | 127 |
| 130 void GpuArcVideoService::OnBufferDone(PortType port, | 128 void GpuArcVideoDecodeAccelerator::OnBufferDone( |
| 131 uint32_t index, | 129 PortType port, |
| 132 const BufferMetadata& metadata) { | 130 uint32_t index, |
| 131 const BufferMetadata& metadata) { |
| 133 DVLOG(2) << "OnBufferDone " << port << "," << index; | 132 DVLOG(2) << "OnBufferDone " << port << "," << index; |
| 134 DCHECK(client_); | 133 DCHECK(client_); |
| 135 client_->OnBufferDone(static_cast<::arc::mojom::PortType>(port), index, | 134 client_->OnBufferDone(static_cast<::arc::mojom::PortType>(port), index, |
| 136 ::arc::mojom::BufferMetadata::From(metadata)); | 135 ::arc::mojom::BufferMetadata::From(metadata)); |
| 137 } | 136 } |
| 138 | 137 |
| 139 void GpuArcVideoService::OnFlushDone() { | 138 void GpuArcVideoDecodeAccelerator::OnFlushDone() { |
| 140 DVLOG(2) << "OnFlushDone"; | 139 DVLOG(2) << "OnFlushDone"; |
| 141 DCHECK(client_); | 140 DCHECK(client_); |
| 142 client_->OnFlushDone(); | 141 client_->OnFlushDone(); |
| 143 } | 142 } |
| 144 | 143 |
| 145 void GpuArcVideoService::OnResetDone() { | 144 void GpuArcVideoDecodeAccelerator::OnResetDone() { |
| 146 DVLOG(2) << "OnResetDone"; | 145 DVLOG(2) << "OnResetDone"; |
| 147 DCHECK(client_); | 146 DCHECK(client_); |
| 148 client_->OnResetDone(); | 147 client_->OnResetDone(); |
| 149 } | 148 } |
| 150 | 149 |
| 151 void GpuArcVideoService::OnOutputFormatChanged(const VideoFormat& format) { | 150 void GpuArcVideoDecodeAccelerator::OnOutputFormatChanged( |
| 151 const VideoFormat& format) { |
| 152 DVLOG(2) << "OnOutputFormatChanged"; | 152 DVLOG(2) << "OnOutputFormatChanged"; |
| 153 DCHECK(client_); | 153 DCHECK(client_); |
| 154 client_->OnOutputFormatChanged(::arc::mojom::VideoFormat::From(format)); | 154 client_->OnOutputFormatChanged(::arc::mojom::VideoFormat::From(format)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void GpuArcVideoService::Initialize( | 157 void GpuArcVideoDecodeAccelerator::Initialize( |
| 158 ::arc::mojom::ArcVideoAcceleratorConfigPtr config, | 158 ::arc::mojom::VideoDecodeAcceleratorConfigPtr config, |
| 159 ::arc::mojom::VideoAcceleratorServiceClientPtr client, | 159 ::arc::mojom::VideoDecodeClientPtr client, |
| 160 const InitializeCallback& callback) { | 160 const InitializeCallback& callback) { |
| 161 DVLOG(2) << "Initialize"; | 161 DVLOG(2) << "Initialize"; |
| 162 DCHECK(!client_); | 162 DCHECK(!client_); |
| 163 if (config->device_type_deprecated != |
| 164 ::arc::mojom::VideoDecodeAcceleratorConfig::DeviceTypeDeprecated:: |
| 165 DEVICE_DECODER) { |
| 166 LOG(ERROR) << "only decoder is supported"; |
| 167 callback.Run( |
| 168 ::arc::mojom::VideoDecodeAccelerator::Result::INVALID_ARGUMENT); |
| 169 } |
| 163 client_ = std::move(client); | 170 client_ = std::move(client); |
| 164 ArcVideoAccelerator::Result result = | 171 ArcVideoDecodeAccelerator::Result result = accelerator_->Initialize( |
| 165 accelerator_->Initialize(config.To<ArcVideoAccelerator::Config>(), this); | 172 config.To<ArcVideoDecodeAccelerator::Config>(), this); |
| 166 callback.Run( | 173 callback.Run( |
| 167 static_cast<::arc::mojom::VideoAcceleratorService::Result>(result)); | 174 static_cast<::arc::mojom::VideoDecodeAccelerator::Result>(result)); |
| 168 } | 175 } |
| 169 | 176 |
| 170 base::ScopedFD GpuArcVideoService::UnwrapFdFromMojoHandle( | 177 base::ScopedFD GpuArcVideoDecodeAccelerator::UnwrapFdFromMojoHandle( |
| 171 mojo::ScopedHandle handle) { | 178 mojo::ScopedHandle handle) { |
| 172 DCHECK(client_); | 179 DCHECK(client_); |
| 173 if (!handle.is_valid()) { | 180 if (!handle.is_valid()) { |
| 174 LOG(ERROR) << "handle is invalid"; | 181 LOG(ERROR) << "handle is invalid"; |
| 175 client_->OnError( | 182 client_->OnError( |
| 176 ::arc::mojom::VideoAcceleratorService::Result::INVALID_ARGUMENT); | 183 ::arc::mojom::VideoDecodeAccelerator::Result::INVALID_ARGUMENT); |
| 177 return base::ScopedFD(); | 184 return base::ScopedFD(); |
| 178 } | 185 } |
| 179 | 186 |
| 180 base::PlatformFile platform_file; | 187 base::PlatformFile platform_file; |
| 181 MojoResult mojo_result = | 188 MojoResult mojo_result = |
| 182 mojo::UnwrapPlatformFile(std::move(handle), &platform_file); | 189 mojo::UnwrapPlatformFile(std::move(handle), &platform_file); |
| 183 if (mojo_result != MOJO_RESULT_OK) { | 190 if (mojo_result != MOJO_RESULT_OK) { |
| 184 LOG(ERROR) << "UnwrapPlatformFile failed: " << mojo_result; | 191 LOG(ERROR) << "UnwrapPlatformFile failed: " << mojo_result; |
| 185 client_->OnError( | 192 client_->OnError( |
| 186 ::arc::mojom::VideoAcceleratorService::Result::PLATFORM_FAILURE); | 193 ::arc::mojom::VideoDecodeAccelerator::Result::PLATFORM_FAILURE); |
| 187 return base::ScopedFD(); | 194 return base::ScopedFD(); |
| 188 } | 195 } |
| 189 | 196 |
| 190 return base::ScopedFD(platform_file); | 197 return base::ScopedFD(platform_file); |
| 191 } | 198 } |
| 192 | 199 |
| 193 void GpuArcVideoService::BindSharedMemory(::arc::mojom::PortType port, | 200 void GpuArcVideoDecodeAccelerator::BindSharedMemory( |
| 194 uint32_t index, | 201 ::arc::mojom::PortType port, |
| 195 mojo::ScopedHandle ashmem_handle, | 202 uint32_t index, |
| 196 uint32_t offset, | 203 mojo::ScopedHandle ashmem_handle, |
| 197 uint32_t length) { | 204 uint32_t offset, |
| 205 uint32_t length) { |
| 198 DVLOG(2) << "BindSharedMemoryCallback port=" << port << ", index=" << index | 206 DVLOG(2) << "BindSharedMemoryCallback port=" << port << ", index=" << index |
| 199 << ", offset=" << offset << ", length=" << length; | 207 << ", offset=" << offset << ", length=" << length; |
| 200 | 208 |
| 201 base::ScopedFD fd = UnwrapFdFromMojoHandle(std::move(ashmem_handle)); | 209 base::ScopedFD fd = UnwrapFdFromMojoHandle(std::move(ashmem_handle)); |
| 202 if (!fd.is_valid()) | 210 if (!fd.is_valid()) |
| 203 return; | 211 return; |
| 204 accelerator_->BindSharedMemory(static_cast<PortType>(port), index, | 212 accelerator_->BindSharedMemory(static_cast<PortType>(port), index, |
| 205 std::move(fd), offset, length); | 213 std::move(fd), offset, length); |
| 206 } | 214 } |
| 207 | 215 |
| 208 void GpuArcVideoService::BindDmabuf( | 216 void GpuArcVideoDecodeAccelerator::BindDmabuf( |
| 209 ::arc::mojom::PortType port, | 217 ::arc::mojom::PortType port, |
| 210 uint32_t index, | 218 uint32_t index, |
| 211 mojo::ScopedHandle dmabuf_handle, | 219 mojo::ScopedHandle dmabuf_handle, |
| 212 std::vector<::arc::ArcVideoAcceleratorDmabufPlane> dmabuf_planes) { | 220 std::vector<::arc::ArcVideoAcceleratorDmabufPlane> dmabuf_planes) { |
| 213 DVLOG(2) << "BindDmabuf port=" << port << ", index=" << index; | 221 DVLOG(2) << "BindDmabuf port=" << port << ", index=" << index; |
| 214 | 222 |
| 215 base::ScopedFD fd = UnwrapFdFromMojoHandle(std::move(dmabuf_handle)); | 223 base::ScopedFD fd = UnwrapFdFromMojoHandle(std::move(dmabuf_handle)); |
| 216 if (!fd.is_valid()) | 224 if (!fd.is_valid()) |
| 217 return; | 225 return; |
| 218 | 226 |
| 219 accelerator_->BindDmabuf(static_cast<PortType>(port), index, std::move(fd), | 227 accelerator_->BindDmabuf(static_cast<PortType>(port), index, std::move(fd), |
| 220 std::move(dmabuf_planes)); | 228 std::move(dmabuf_planes)); |
| 221 } | 229 } |
| 222 | 230 |
| 223 void GpuArcVideoService::UseBuffer(::arc::mojom::PortType port, | 231 void GpuArcVideoDecodeAccelerator::UseBuffer( |
| 224 uint32_t index, | 232 ::arc::mojom::PortType port, |
| 225 ::arc::mojom::BufferMetadataPtr metadata) { | 233 uint32_t index, |
| 234 ::arc::mojom::BufferMetadataPtr metadata) { |
| 226 DVLOG(2) << "UseBuffer port=" << port << ", index=" << index; | 235 DVLOG(2) << "UseBuffer port=" << port << ", index=" << index; |
| 227 accelerator_->UseBuffer(static_cast<PortType>(port), index, | 236 accelerator_->UseBuffer(static_cast<PortType>(port), index, |
| 228 metadata.To<BufferMetadata>()); | 237 metadata.To<BufferMetadata>()); |
| 229 } | 238 } |
| 230 | 239 |
| 231 void GpuArcVideoService::SetNumberOfOutputBuffers(uint32_t number) { | 240 void GpuArcVideoDecodeAccelerator::SetNumberOfOutputBuffers(uint32_t number) { |
| 232 DVLOG(2) << "SetNumberOfOutputBuffers number=" << number; | 241 DVLOG(2) << "SetNumberOfOutputBuffers number=" << number; |
| 233 accelerator_->SetNumberOfOutputBuffers(number); | 242 accelerator_->SetNumberOfOutputBuffers(number); |
| 234 } | 243 } |
| 235 | 244 |
| 236 void GpuArcVideoService::Reset() { | 245 void GpuArcVideoDecodeAccelerator::Reset() { |
| 237 DVLOG(2) << "Reset"; | 246 DVLOG(2) << "Reset"; |
| 238 accelerator_->Reset(); | 247 accelerator_->Reset(); |
| 239 } | 248 } |
| 240 | 249 |
| 241 void GpuArcVideoService::Flush() { | 250 void GpuArcVideoDecodeAccelerator::Flush() { |
| 242 DVLOG(2) << "Flush"; | 251 DVLOG(2) << "Flush"; |
| 243 accelerator_->Flush(); | 252 accelerator_->Flush(); |
| 244 } | 253 } |
| 245 | 254 |
| 246 } // namespace arc | 255 } // namespace arc |
| 247 } // namespace chromeos | 256 } // namespace chromeos |
| OLD | NEW |