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

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

Issue 2919193002: ArcBridge: Rename VideoAcceleratorService to VideoDecodeAccelerator. (Closed)
Patch Set: Address review comments Created 3 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
« no previous file with comments | « chrome/gpu/gpu_arc_video_service.h ('k') | components/arc/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/gpu/gpu_arc_video_service.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/gpu/arc_gpu_video_decode_accelerator.h"
14 #include "mojo/public/cpp/bindings/strong_binding.h"
15 #include "mojo/public/cpp/bindings/type_converter.h"
16 #include "mojo/public/cpp/system/platform_handle.h"
17
18 // Make sure arc::mojom::VideoAcceleratorService::Result and
19 // chromeos::arc::ArcVideoAccelerator::Result match.
20 static_assert(
21 static_cast<int>(arc::mojom::VideoAcceleratorService::Result::SUCCESS) ==
22 chromeos::arc::ArcVideoAccelerator::SUCCESS,
23 "enum mismatch");
24 static_assert(static_cast<int>(
25 arc::mojom::VideoAcceleratorService::Result::ILLEGAL_STATE) ==
26 chromeos::arc::ArcVideoAccelerator::ILLEGAL_STATE,
27 "enum mismatch");
28 static_assert(
29 static_cast<int>(
30 arc::mojom::VideoAcceleratorService::Result::INVALID_ARGUMENT) ==
31 chromeos::arc::ArcVideoAccelerator::INVALID_ARGUMENT,
32 "enum mismatch");
33 static_assert(
34 static_cast<int>(
35 arc::mojom::VideoAcceleratorService::Result::UNREADABLE_INPUT) ==
36 chromeos::arc::ArcVideoAccelerator::UNREADABLE_INPUT,
37 "enum mismatch");
38 static_assert(
39 static_cast<int>(
40 arc::mojom::VideoAcceleratorService::Result::PLATFORM_FAILURE) ==
41 chromeos::arc::ArcVideoAccelerator::PLATFORM_FAILURE,
42 "enum mismatch");
43 static_assert(
44 static_cast<int>(
45 arc::mojom::VideoAcceleratorService::Result::INSUFFICIENT_RESOURCES) ==
46 chromeos::arc::ArcVideoAccelerator::INSUFFICIENT_RESOURCES,
47 "enum mismatch");
48
49 namespace mojo {
50
51 template <>
52 struct TypeConverter<arc::mojom::BufferMetadataPtr,
53 chromeos::arc::BufferMetadata> {
54 static arc::mojom::BufferMetadataPtr Convert(
55 const chromeos::arc::BufferMetadata& input) {
56 arc::mojom::BufferMetadataPtr result = arc::mojom::BufferMetadata::New();
57 result->timestamp = input.timestamp;
58 result->bytes_used = input.bytes_used;
59 return result;
60 }
61 };
62
63 template <>
64 struct TypeConverter<chromeos::arc::BufferMetadata,
65 arc::mojom::BufferMetadataPtr> {
66 static chromeos::arc::BufferMetadata Convert(
67 const arc::mojom::BufferMetadataPtr& input) {
68 chromeos::arc::BufferMetadata result;
69 result.timestamp = input->timestamp;
70 result.bytes_used = input->bytes_used;
71 return result;
72 }
73 };
74
75 template <>
76 struct TypeConverter<arc::mojom::VideoFormatPtr, chromeos::arc::VideoFormat> {
77 static arc::mojom::VideoFormatPtr Convert(
78 const chromeos::arc::VideoFormat& input) {
79 arc::mojom::VideoFormatPtr result = arc::mojom::VideoFormat::New();
80 result->pixel_format = input.pixel_format;
81 result->buffer_size = input.buffer_size;
82 result->min_num_buffers = input.min_num_buffers;
83 result->coded_width = input.coded_width;
84 result->coded_height = input.coded_height;
85 result->crop_left = input.crop_left;
86 result->crop_width = input.crop_width;
87 result->crop_top = input.crop_top;
88 result->crop_height = input.crop_height;
89 return result;
90 }
91 };
92
93 template <>
94 struct TypeConverter<chromeos::arc::ArcVideoAccelerator::Config,
95 arc::mojom::ArcVideoAcceleratorConfigPtr> {
96 static chromeos::arc::ArcVideoAccelerator::Config Convert(
97 const arc::mojom::ArcVideoAcceleratorConfigPtr& input) {
98 chromeos::arc::ArcVideoAccelerator::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;
103 result.input_pixel_format = input->input_pixel_format;
104 return result;
105 }
106 };
107
108 } // namespace mojo
109
110 namespace chromeos {
111 namespace arc {
112
113 GpuArcVideoService::GpuArcVideoService(
114 const gpu::GpuPreferences& gpu_preferences)
115 : gpu_preferences_(gpu_preferences),
116 accelerator_(new ArcGpuVideoDecodeAccelerator(gpu_preferences_)) {}
117
118 GpuArcVideoService::~GpuArcVideoService() {
119 DCHECK(thread_checker_.CalledOnValidThread());
120 }
121
122 void GpuArcVideoService::OnError(ArcVideoAccelerator::Result error) {
123 DVLOG(2) << "OnError " << error;
124 DCHECK_NE(error, ArcVideoAccelerator::SUCCESS);
125 DCHECK(client_);
126 client_->OnError(
127 static_cast<::arc::mojom::VideoAcceleratorService::Result>(error));
128 }
129
130 void GpuArcVideoService::OnBufferDone(PortType port,
131 uint32_t index,
132 const BufferMetadata& metadata) {
133 DVLOG(2) << "OnBufferDone " << port << "," << index;
134 DCHECK(client_);
135 client_->OnBufferDone(static_cast<::arc::mojom::PortType>(port), index,
136 ::arc::mojom::BufferMetadata::From(metadata));
137 }
138
139 void GpuArcVideoService::OnFlushDone() {
140 DVLOG(2) << "OnFlushDone";
141 DCHECK(client_);
142 client_->OnFlushDone();
143 }
144
145 void GpuArcVideoService::OnResetDone() {
146 DVLOG(2) << "OnResetDone";
147 DCHECK(client_);
148 client_->OnResetDone();
149 }
150
151 void GpuArcVideoService::OnOutputFormatChanged(const VideoFormat& format) {
152 DVLOG(2) << "OnOutputFormatChanged";
153 DCHECK(client_);
154 client_->OnOutputFormatChanged(::arc::mojom::VideoFormat::From(format));
155 }
156
157 void GpuArcVideoService::Initialize(
158 ::arc::mojom::ArcVideoAcceleratorConfigPtr config,
159 ::arc::mojom::VideoAcceleratorServiceClientPtr client,
160 const InitializeCallback& callback) {
161 DVLOG(2) << "Initialize";
162 DCHECK(!client_);
163 client_ = std::move(client);
164 ArcVideoAccelerator::Result result =
165 accelerator_->Initialize(config.To<ArcVideoAccelerator::Config>(), this);
166 callback.Run(
167 static_cast<::arc::mojom::VideoAcceleratorService::Result>(result));
168 }
169
170 base::ScopedFD GpuArcVideoService::UnwrapFdFromMojoHandle(
171 mojo::ScopedHandle handle) {
172 DCHECK(client_);
173 if (!handle.is_valid()) {
174 LOG(ERROR) << "handle is invalid";
175 client_->OnError(
176 ::arc::mojom::VideoAcceleratorService::Result::INVALID_ARGUMENT);
177 return base::ScopedFD();
178 }
179
180 base::PlatformFile platform_file;
181 MojoResult mojo_result =
182 mojo::UnwrapPlatformFile(std::move(handle), &platform_file);
183 if (mojo_result != MOJO_RESULT_OK) {
184 LOG(ERROR) << "UnwrapPlatformFile failed: " << mojo_result;
185 client_->OnError(
186 ::arc::mojom::VideoAcceleratorService::Result::PLATFORM_FAILURE);
187 return base::ScopedFD();
188 }
189
190 return base::ScopedFD(platform_file);
191 }
192
193 void GpuArcVideoService::BindSharedMemory(::arc::mojom::PortType port,
194 uint32_t index,
195 mojo::ScopedHandle ashmem_handle,
196 uint32_t offset,
197 uint32_t length) {
198 DVLOG(2) << "BindSharedMemoryCallback port=" << port << ", index=" << index
199 << ", offset=" << offset << ", length=" << length;
200
201 base::ScopedFD fd = UnwrapFdFromMojoHandle(std::move(ashmem_handle));
202 if (!fd.is_valid())
203 return;
204 accelerator_->BindSharedMemory(static_cast<PortType>(port), index,
205 std::move(fd), offset, length);
206 }
207
208 void GpuArcVideoService::BindDmabuf(
209 ::arc::mojom::PortType port,
210 uint32_t index,
211 mojo::ScopedHandle dmabuf_handle,
212 std::vector<::arc::ArcVideoAcceleratorDmabufPlane> dmabuf_planes) {
213 DVLOG(2) << "BindDmabuf port=" << port << ", index=" << index;
214
215 base::ScopedFD fd = UnwrapFdFromMojoHandle(std::move(dmabuf_handle));
216 if (!fd.is_valid())
217 return;
218
219 accelerator_->BindDmabuf(static_cast<PortType>(port), index, std::move(fd),
220 std::move(dmabuf_planes));
221 }
222
223 void GpuArcVideoService::UseBuffer(::arc::mojom::PortType port,
224 uint32_t index,
225 ::arc::mojom::BufferMetadataPtr metadata) {
226 DVLOG(2) << "UseBuffer port=" << port << ", index=" << index;
227 accelerator_->UseBuffer(static_cast<PortType>(port), index,
228 metadata.To<BufferMetadata>());
229 }
230
231 void GpuArcVideoService::SetNumberOfOutputBuffers(uint32_t number) {
232 DVLOG(2) << "SetNumberOfOutputBuffers number=" << number;
233 accelerator_->SetNumberOfOutputBuffers(number);
234 }
235
236 void GpuArcVideoService::Reset() {
237 DVLOG(2) << "Reset";
238 accelerator_->Reset();
239 }
240
241 void GpuArcVideoService::Flush() {
242 DVLOG(2) << "Flush";
243 accelerator_->Flush();
244 }
245
246 } // namespace arc
247 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/gpu/gpu_arc_video_service.h ('k') | components/arc/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698