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/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "content/public/gpu/gpu_video_decode_accelerator_factory.h" | 10 #include "content/public/gpu/gpu_video_decode_accelerator_factory.h" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
12 | 12 |
13 namespace chromeos { | 13 namespace chromeos { |
14 namespace arc { | 14 namespace arc { |
15 | 15 |
16 ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord( | 16 ArcGpuVideoDecodeAccelerator::InputRecord::InputRecord( |
17 int32_t bitstream_buffer_id, | 17 int32_t bitstream_buffer_id, |
18 uint32_t buffer_index, | 18 uint32_t buffer_index, |
19 int64_t timestamp) | 19 int64_t timestamp) |
20 : bitstream_buffer_id(bitstream_buffer_id), | 20 : bitstream_buffer_id(bitstream_buffer_id), |
21 buffer_index(buffer_index), | 21 buffer_index(buffer_index), |
22 timestamp(timestamp) {} | 22 timestamp(timestamp) {} |
23 | 23 |
24 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo() | |
25 : offset(0), length(0) {} | |
26 | |
27 ArcGpuVideoDecodeAccelerator::InputBufferInfo::InputBufferInfo( | |
28 InputBufferInfo&& other) | |
29 : handle(std::move(other.handle)), | |
30 offset(other.offset), | |
31 length(other.length) {} | |
32 | |
33 ArcGpuVideoDecodeAccelerator::InputBufferInfo::~InputBufferInfo() {} | |
34 | |
35 ArcGpuVideoDecodeAccelerator::ArcGpuVideoDecodeAccelerator() | 24 ArcGpuVideoDecodeAccelerator::ArcGpuVideoDecodeAccelerator() |
36 : pending_eos_output_buffer_(false), | 25 : pending_eos_output_buffer_(false), |
37 arc_client_(nullptr), | 26 arc_client_(nullptr), |
38 next_bitstream_buffer_id_(0), | 27 next_bitstream_buffer_id_(0), |
39 output_buffer_size_(0) {} | 28 output_buffer_size_(0) {} |
40 | 29 |
41 ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() {} | 30 ArcGpuVideoDecodeAccelerator::~ArcGpuVideoDecodeAccelerator() {} |
42 | 31 |
43 namespace { | 32 namespace { |
44 | 33 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return; | 138 return; |
150 } | 139 } |
151 InputBufferInfo* input_info = &input_buffer_info_[index]; | 140 InputBufferInfo* input_info = &input_buffer_info_[index]; |
152 input_info->handle = std::move(ashmem_fd); | 141 input_info->handle = std::move(ashmem_fd); |
153 input_info->offset = offset; | 142 input_info->offset = offset; |
154 input_info->length = length; | 143 input_info->length = length; |
155 } | 144 } |
156 | 145 |
157 void ArcGpuVideoDecodeAccelerator::BindDmabuf(PortType port, | 146 void ArcGpuVideoDecodeAccelerator::BindDmabuf(PortType port, |
158 uint32_t index, | 147 uint32_t index, |
159 base::ScopedFD dmabuf_fd) { | 148 base::ScopedFD dmabuf_fd, |
| 149 int32_t stride) { |
160 DCHECK(thread_checker_.CalledOnValidThread()); | 150 DCHECK(thread_checker_.CalledOnValidThread()); |
161 | 151 |
162 if (!vda_) { | 152 if (!vda_) { |
163 DLOG(ERROR) << "VDA not initialized"; | 153 DLOG(ERROR) << "VDA not initialized"; |
164 return; | 154 return; |
165 } | 155 } |
166 | 156 |
167 if (port != PORT_OUTPUT) { | 157 if (port != PORT_OUTPUT) { |
168 DLOG(ERROR) << "Dmabuf is only supported for input"; | 158 DLOG(ERROR) << "Dmabuf is only supported for input"; |
169 arc_client_->OnError(INVALID_ARGUMENT); | 159 arc_client_->OnError(INVALID_ARGUMENT); |
170 return; | 160 return; |
171 } | 161 } |
172 if (!ValidatePortAndIndex(port, index)) { | 162 if (!ValidatePortAndIndex(port, index)) { |
173 arc_client_->OnError(INVALID_ARGUMENT); | 163 arc_client_->OnError(INVALID_ARGUMENT); |
174 return; | 164 return; |
175 } | 165 } |
176 buffers_pending_import_[index] = std::move(dmabuf_fd); | 166 OutputBufferInfo& info = buffers_pending_import_[index]; |
| 167 info.handle = std::move(dmabuf_fd); |
| 168 info.stride = stride; |
177 } | 169 } |
178 | 170 |
179 void ArcGpuVideoDecodeAccelerator::UseBuffer(PortType port, | 171 void ArcGpuVideoDecodeAccelerator::UseBuffer(PortType port, |
180 uint32_t index, | 172 uint32_t index, |
181 const BufferMetadata& metadata) { | 173 const BufferMetadata& metadata) { |
182 DVLOG(5) << "UseBuffer(port=" << port << ", index=" << index | 174 DVLOG(5) << "UseBuffer(port=" << port << ", index=" << index |
183 << ", metadata=(bytes_used=" << metadata.bytes_used | 175 << ", metadata=(bytes_used=" << metadata.bytes_used |
184 << ", timestamp=" << metadata.timestamp << ")"; | 176 << ", timestamp=" << metadata.timestamp << ")"; |
185 DCHECK(thread_checker_.CalledOnValidThread()); | 177 DCHECK(thread_checker_.CalledOnValidThread()); |
186 if (!vda_) { | 178 if (!vda_) { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 } | 346 } |
355 | 347 |
356 void ArcGpuVideoDecodeAccelerator::SendEosIfNeededOrReusePicture( | 348 void ArcGpuVideoDecodeAccelerator::SendEosIfNeededOrReusePicture( |
357 uint32_t index) { | 349 uint32_t index) { |
358 if (pending_eos_output_buffer_) { | 350 if (pending_eos_output_buffer_) { |
359 BufferMetadata metadata; | 351 BufferMetadata metadata; |
360 metadata.flags = BUFFER_FLAG_EOS; | 352 metadata.flags = BUFFER_FLAG_EOS; |
361 arc_client_->OnBufferDone(PORT_OUTPUT, index, metadata); | 353 arc_client_->OnBufferDone(PORT_OUTPUT, index, metadata); |
362 pending_eos_output_buffer_ = false; | 354 pending_eos_output_buffer_ = false; |
363 } else { | 355 } else { |
364 if (buffers_pending_import_[index].is_valid()) { | 356 OutputBufferInfo& info = buffers_pending_import_[index]; |
| 357 if (info.handle.is_valid()) { |
| 358 gfx::GpuMemoryBufferHandle handle; |
| 359 #if defined(USE_OZONE) |
| 360 handle.native_pixmap_handle.fd = |
| 361 base::FileDescriptor(info.handle.release(), true); |
| 362 handle.native_pixmap_handle.stride = info.stride; |
| 363 #endif |
365 std::vector<gfx::GpuMemoryBufferHandle> buffers; | 364 std::vector<gfx::GpuMemoryBufferHandle> buffers; |
366 buffers.push_back(gfx::GpuMemoryBufferHandle()); | 365 buffers.push_back(handle); |
367 #if defined(USE_OZONE) | |
368 buffers.back().native_pixmap_handle.fd = | |
369 base::FileDescriptor(buffers_pending_import_[index].release(), true); | |
370 #endif | |
371 vda_->ImportBufferForPicture(index, buffers); | 366 vda_->ImportBufferForPicture(index, buffers); |
372 } else { | 367 } else { |
373 vda_->ReusePictureBuffer(index); | 368 vda_->ReusePictureBuffer(index); |
374 } | 369 } |
375 } | 370 } |
376 } | 371 } |
377 | 372 |
378 void ArcGpuVideoDecodeAccelerator::CreateInputRecord( | 373 void ArcGpuVideoDecodeAccelerator::CreateInputRecord( |
379 int32_t bitstream_buffer_id, | 374 int32_t bitstream_buffer_id, |
380 uint32_t buffer_index, | 375 uint32_t buffer_index, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 412 } |
418 return true; | 413 return true; |
419 default: | 414 default: |
420 DLOG(ERROR) << "Invalid port: " << port; | 415 DLOG(ERROR) << "Invalid port: " << port; |
421 return false; | 416 return false; |
422 } | 417 } |
423 } | 418 } |
424 | 419 |
425 } // namespace arc | 420 } // namespace arc |
426 } // namespace chromeos | 421 } // namespace chromeos |
OLD | NEW |