| 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_service.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/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "chrome/gpu/arc_gpu_video_decode_accelerator.h" | 12 #include "chrome/gpu/arc_gpu_video_decode_accelerator.h" |
| 13 #include "mojo/public/cpp/bindings/type_converter.h" | 13 #include "mojo/public/cpp/bindings/type_converter.h" |
| 14 #include "mojo/public/cpp/system/platform_handle.h" | 14 #include "mojo/public/cpp/system/platform_handle.h" |
| 15 | 15 |
| 16 // Make sure arc::mojom::VideoAcceleratorService::Result and |
| 17 // chromeos::arc::ArcVideoAccelerator::Result match. |
| 18 static_assert( |
| 19 static_cast<int>(arc::mojom::VideoAcceleratorService::Result::SUCCESS) == |
| 20 chromeos::arc::ArcVideoAccelerator::SUCCESS, |
| 21 "enum mismatch"); |
| 22 static_assert(static_cast<int>( |
| 23 arc::mojom::VideoAcceleratorService::Result::ILLEGAL_STATE) == |
| 24 chromeos::arc::ArcVideoAccelerator::ILLEGAL_STATE, |
| 25 "enum mismatch"); |
| 26 static_assert( |
| 27 static_cast<int>( |
| 28 arc::mojom::VideoAcceleratorService::Result::INVALID_ARGUMENT) == |
| 29 chromeos::arc::ArcVideoAccelerator::INVALID_ARGUMENT, |
| 30 "enum mismatch"); |
| 31 static_assert( |
| 32 static_cast<int>( |
| 33 arc::mojom::VideoAcceleratorService::Result::UNREADABLE_INPUT) == |
| 34 chromeos::arc::ArcVideoAccelerator::UNREADABLE_INPUT, |
| 35 "enum mismatch"); |
| 36 static_assert( |
| 37 static_cast<int>( |
| 38 arc::mojom::VideoAcceleratorService::Result::PLATFORM_FAILURE) == |
| 39 chromeos::arc::ArcVideoAccelerator::PLATFORM_FAILURE, |
| 40 "enum mismatch"); |
| 41 static_assert( |
| 42 static_cast<int>( |
| 43 arc::mojom::VideoAcceleratorService::Result::INSUFFICIENT_RESOURCES) == |
| 44 chromeos::arc::ArcVideoAccelerator::INSUFFICIENT_RESOURCES, |
| 45 "enum mismatch"); |
| 46 |
| 16 namespace { | 47 namespace { |
| 17 void OnConnectionError() { | 48 void OnConnectionError() { |
| 18 DVLOG(2) << "OnConnectionError"; | 49 DVLOG(2) << "OnConnectionError"; |
| 19 } | 50 } |
| 20 } // namespace | 51 } // namespace |
| 21 | 52 |
| 22 namespace mojo { | 53 namespace mojo { |
| 23 | 54 |
| 24 template <> | 55 template <> |
| 25 struct TypeConverter<arc::mojom::BufferMetadataPtr, | 56 struct TypeConverter<arc::mojom::BufferMetadataPtr, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 130 |
| 100 accelerator_.reset(new ArcGpuVideoDecodeAccelerator()); | 131 accelerator_.reset(new ArcGpuVideoDecodeAccelerator()); |
| 101 | 132 |
| 102 ::arc::mojom::VideoAcceleratorServicePtr service; | 133 ::arc::mojom::VideoAcceleratorServicePtr service; |
| 103 binding_.Bind(GetProxy(&service)); | 134 binding_.Bind(GetProxy(&service)); |
| 104 binding_.set_connection_error_handler(base::Bind(&OnConnectionError)); | 135 binding_.set_connection_error_handler(base::Bind(&OnConnectionError)); |
| 105 | 136 |
| 106 client_->Init(std::move(service)); | 137 client_->Init(std::move(service)); |
| 107 } | 138 } |
| 108 | 139 |
| 109 void GpuArcVideoService::OnError(ArcVideoAccelerator::Error error) { | 140 void GpuArcVideoService::OnError(ArcVideoAccelerator::Result error) { |
| 110 DVLOG(2) << "OnError " << error; | 141 DVLOG(2) << "OnError " << error; |
| 142 DCHECK_NE(error, ArcVideoAccelerator::SUCCESS); |
| 111 client_->OnError( | 143 client_->OnError( |
| 112 static_cast<::arc::mojom::VideoAcceleratorServiceClient::Error>(error)); | 144 static_cast<::arc::mojom::VideoAcceleratorService::Result>(error)); |
| 113 } | 145 } |
| 114 | 146 |
| 115 void GpuArcVideoService::OnBufferDone(PortType port, | 147 void GpuArcVideoService::OnBufferDone(PortType port, |
| 116 uint32_t index, | 148 uint32_t index, |
| 117 const BufferMetadata& metadata) { | 149 const BufferMetadata& metadata) { |
| 118 DVLOG(2) << "OnBufferDone " << port << "," << index; | 150 DVLOG(2) << "OnBufferDone " << port << "," << index; |
| 119 client_->OnBufferDone(static_cast<::arc::mojom::PortType>(port), index, | 151 client_->OnBufferDone(static_cast<::arc::mojom::PortType>(port), index, |
| 120 ::arc::mojom::BufferMetadata::From(metadata)); | 152 ::arc::mojom::BufferMetadata::From(metadata)); |
| 121 } | 153 } |
| 122 | 154 |
| 123 void GpuArcVideoService::OnFlushDone() { | 155 void GpuArcVideoService::OnFlushDone() { |
| 124 DVLOG(2) << "OnFlushDone"; | 156 DVLOG(2) << "OnFlushDone"; |
| 125 client_->OnFlushDone(); | 157 client_->OnFlushDone(); |
| 126 } | 158 } |
| 127 | 159 |
| 128 void GpuArcVideoService::OnResetDone() { | 160 void GpuArcVideoService::OnResetDone() { |
| 129 DVLOG(2) << "OnResetDone"; | 161 DVLOG(2) << "OnResetDone"; |
| 130 client_->OnResetDone(); | 162 client_->OnResetDone(); |
| 131 } | 163 } |
| 132 | 164 |
| 133 void GpuArcVideoService::OnOutputFormatChanged(const VideoFormat& format) { | 165 void GpuArcVideoService::OnOutputFormatChanged(const VideoFormat& format) { |
| 134 DVLOG(2) << "OnOutputFormatChanged"; | 166 DVLOG(2) << "OnOutputFormatChanged"; |
| 135 client_->OnOutputFormatChanged(::arc::mojom::VideoFormat::From(format)); | 167 client_->OnOutputFormatChanged(::arc::mojom::VideoFormat::From(format)); |
| 136 } | 168 } |
| 137 | 169 |
| 138 void GpuArcVideoService::Initialize( | 170 void GpuArcVideoService::Initialize( |
| 139 ::arc::mojom::ArcVideoAcceleratorConfigPtr config, | 171 ::arc::mojom::ArcVideoAcceleratorConfigPtr config, |
| 140 const InitializeCallback& callback) { | 172 const InitializeCallback& callback) { |
| 141 DVLOG(2) << "Initialize"; | 173 DVLOG(2) << "Initialize"; |
| 142 bool result = | 174 ArcVideoAccelerator::Result result = |
| 143 accelerator_->Initialize(config.To<ArcVideoAccelerator::Config>(), this); | 175 accelerator_->Initialize(config.To<ArcVideoAccelerator::Config>(), this); |
| 144 callback.Run(result); | 176 callback.Run( |
| 177 static_cast<::arc::mojom::VideoAcceleratorService::Result>(result)); |
| 178 } |
| 179 |
| 180 void GpuArcVideoService::DeprecatedInitialize( |
| 181 ::arc::mojom::ArcVideoAcceleratorConfigPtr config, |
| 182 const DeprecatedInitializeCallback& callback) { |
| 183 DVLOG(2) << "DeprecatedInitialize"; |
| 184 ArcVideoAccelerator::Result result = |
| 185 accelerator_->Initialize(config.To<ArcVideoAccelerator::Config>(), this); |
| 186 callback.Run(result == ArcVideoAccelerator::SUCCESS); |
| 145 } | 187 } |
| 146 | 188 |
| 147 base::ScopedFD GpuArcVideoService::UnwrapFdFromMojoHandle( | 189 base::ScopedFD GpuArcVideoService::UnwrapFdFromMojoHandle( |
| 148 mojo::ScopedHandle handle) { | 190 mojo::ScopedHandle handle) { |
| 149 if (!handle.is_valid()) { | 191 if (!handle.is_valid()) { |
| 150 LOG(ERROR) << "handle is invalid"; | 192 LOG(ERROR) << "handle is invalid"; |
| 151 client_->OnError( | 193 client_->OnError( |
| 152 ::arc::mojom::VideoAcceleratorServiceClient::Error::INVALID_ARGUMENT); | 194 ::arc::mojom::VideoAcceleratorService::Result::INVALID_ARGUMENT); |
| 153 return base::ScopedFD(); | 195 return base::ScopedFD(); |
| 154 } | 196 } |
| 155 | 197 |
| 156 base::PlatformFile platform_file; | 198 base::PlatformFile platform_file; |
| 157 MojoResult mojo_result = | 199 MojoResult mojo_result = |
| 158 mojo::UnwrapPlatformFile(std::move(handle), &platform_file); | 200 mojo::UnwrapPlatformFile(std::move(handle), &platform_file); |
| 159 if (mojo_result != MOJO_RESULT_OK) { | 201 if (mojo_result != MOJO_RESULT_OK) { |
| 160 LOG(ERROR) << "UnwrapPlatformFile failed: " << mojo_result; | 202 LOG(ERROR) << "UnwrapPlatformFile failed: " << mojo_result; |
| 161 client_->OnError( | 203 client_->OnError( |
| 162 ::arc::mojom::VideoAcceleratorServiceClient::Error::PLATFORM_FAILURE); | 204 ::arc::mojom::VideoAcceleratorService::Result::PLATFORM_FAILURE); |
| 163 return base::ScopedFD(); | 205 return base::ScopedFD(); |
| 164 } | 206 } |
| 165 | 207 |
| 166 return base::ScopedFD(platform_file); | 208 return base::ScopedFD(platform_file); |
| 167 } | 209 } |
| 168 | 210 |
| 169 void GpuArcVideoService::BindSharedMemory(::arc::mojom::PortType port, | 211 void GpuArcVideoService::BindSharedMemory(::arc::mojom::PortType port, |
| 170 uint32_t index, | 212 uint32_t index, |
| 171 mojo::ScopedHandle ashmem_handle, | 213 mojo::ScopedHandle ashmem_handle, |
| 172 uint32_t offset, | 214 uint32_t offset, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 accelerator_->Reset(); | 254 accelerator_->Reset(); |
| 213 } | 255 } |
| 214 | 256 |
| 215 void GpuArcVideoService::Flush() { | 257 void GpuArcVideoService::Flush() { |
| 216 DVLOG(2) << "Flush"; | 258 DVLOG(2) << "Flush"; |
| 217 accelerator_->Flush(); | 259 accelerator_->Flush(); |
| 218 } | 260 } |
| 219 | 261 |
| 220 } // namespace arc | 262 } // namespace arc |
| 221 } // namespace chromeos | 263 } // namespace chromeos |
| OLD | NEW |