OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/common/gpu/media/gpu_jpeg_decode_accelerator.h" | 5 #include "content/common/gpu/media/gpu_jpeg_decode_accelerator.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 191 |
192 void OnDecodeOnIOThread( | 192 void OnDecodeOnIOThread( |
193 const int32_t* route_id, | 193 const int32_t* route_id, |
194 const AcceleratedJpegDecoderMsg_Decode_Params& params) { | 194 const AcceleratedJpegDecoderMsg_Decode_Params& params) { |
195 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 195 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
196 DCHECK(route_id); | 196 DCHECK(route_id); |
197 TRACE_EVENT0("jpeg", "GpuJpegDecodeAccelerator::MessageFilter::OnDecode"); | 197 TRACE_EVENT0("jpeg", "GpuJpegDecodeAccelerator::MessageFilter::OnDecode"); |
198 | 198 |
199 if (!VerifyDecodeParams(params)) { | 199 if (!VerifyDecodeParams(params)) { |
200 NotifyDecodeStatusOnIOThread( | 200 NotifyDecodeStatusOnIOThread( |
201 *route_id, params.input_buffer_id, | 201 *route_id, params.input_buffer.id(), |
202 media::JpegDecodeAccelerator::INVALID_ARGUMENT); | 202 media::JpegDecodeAccelerator::INVALID_ARGUMENT); |
203 if (base::SharedMemory::IsHandleValid(params.input_buffer_handle)) | |
204 base::SharedMemory::CloseHandle(params.input_buffer_handle); | |
205 if (base::SharedMemory::IsHandleValid(params.output_video_frame_handle)) | 203 if (base::SharedMemory::IsHandleValid(params.output_video_frame_handle)) |
206 base::SharedMemory::CloseHandle(params.output_video_frame_handle); | 204 base::SharedMemory::CloseHandle(params.output_video_frame_handle); |
207 return; | 205 return; |
208 } | 206 } |
209 | 207 |
210 // For handles in |params|, from now on, |params.output_video_frame_handle| | 208 // For handles in |params|, from now on, |params.output_video_frame_handle| |
211 // is taken cared by scoper. |params.input_buffer_handle| need to be closed | 209 // is taken cared by scoper. |params.input_buffer.handle()| need to be |
212 // manually for early exits. | 210 // closed manually for early exits. |
213 scoped_ptr<base::SharedMemory> output_shm( | 211 scoped_ptr<base::SharedMemory> output_shm( |
214 new base::SharedMemory(params.output_video_frame_handle, false)); | 212 new base::SharedMemory(params.output_video_frame_handle, false)); |
215 if (!output_shm->Map(params.output_buffer_size)) { | 213 if (!output_shm->Map(params.output_buffer_size)) { |
216 LOG(ERROR) << "Could not map output shared memory for input buffer id " | 214 LOG(ERROR) << "Could not map output shared memory for input buffer id " |
217 << params.input_buffer_id; | 215 << params.input_buffer.id(); |
218 NotifyDecodeStatusOnIOThread( | 216 NotifyDecodeStatusOnIOThread( |
219 *route_id, params.input_buffer_id, | 217 *route_id, params.input_buffer.id(), |
220 media::JpegDecodeAccelerator::PLATFORM_FAILURE); | 218 media::JpegDecodeAccelerator::PLATFORM_FAILURE); |
221 base::SharedMemory::CloseHandle(params.input_buffer_handle); | 219 base::SharedMemory::CloseHandle(params.input_buffer.handle()); |
222 return; | 220 return; |
223 } | 221 } |
224 | 222 |
225 media::BitstreamBuffer input_buffer(params.input_buffer_id, | |
226 params.input_buffer_handle, | |
227 params.input_buffer_size); | |
228 | |
229 uint8_t* shm_memory = static_cast<uint8_t*>(output_shm->memory()); | 223 uint8_t* shm_memory = static_cast<uint8_t*>(output_shm->memory()); |
230 scoped_refptr<media::VideoFrame> frame = | 224 scoped_refptr<media::VideoFrame> frame = |
231 media::VideoFrame::WrapExternalSharedMemory( | 225 media::VideoFrame::WrapExternalSharedMemory( |
232 media::PIXEL_FORMAT_I420, // format | 226 media::PIXEL_FORMAT_I420, // format |
233 params.coded_size, // coded_size | 227 params.coded_size, // coded_size |
234 gfx::Rect(params.coded_size), // visible_rect | 228 gfx::Rect(params.coded_size), // visible_rect |
235 params.coded_size, // natural_size | 229 params.coded_size, // natural_size |
236 shm_memory, // data | 230 shm_memory, // data |
237 params.output_buffer_size, // data_size | 231 params.output_buffer_size, // data_size |
238 params.output_video_frame_handle, // handle | 232 params.output_video_frame_handle, // handle |
239 0, // data_offset | 233 0, // data_offset |
240 base::TimeDelta()); // timestamp | 234 base::TimeDelta()); // timestamp |
241 if (!frame.get()) { | 235 if (!frame.get()) { |
242 LOG(ERROR) << "Could not create VideoFrame for input buffer id " | 236 LOG(ERROR) << "Could not create VideoFrame for input buffer id " |
243 << params.input_buffer_id; | 237 << params.input_buffer.id(); |
244 NotifyDecodeStatusOnIOThread( | 238 NotifyDecodeStatusOnIOThread( |
245 *route_id, params.input_buffer_id, | 239 *route_id, params.input_buffer.id(), |
246 media::JpegDecodeAccelerator::PLATFORM_FAILURE); | 240 media::JpegDecodeAccelerator::PLATFORM_FAILURE); |
247 base::SharedMemory::CloseHandle(params.input_buffer_handle); | 241 base::SharedMemory::CloseHandle(params.input_buffer.handle()); |
248 return; | 242 return; |
249 } | 243 } |
250 frame->AddDestructionObserver( | 244 frame->AddDestructionObserver( |
251 base::Bind(DecodeFinished, base::Passed(&output_shm))); | 245 base::Bind(DecodeFinished, base::Passed(&output_shm))); |
252 | 246 |
253 DCHECK_GT(client_map_.count(*route_id), 0u); | 247 DCHECK_GT(client_map_.count(*route_id), 0u); |
254 Client* client = client_map_[*route_id]; | 248 Client* client = client_map_[*route_id]; |
255 client->Decode(input_buffer, frame); | 249 client->Decode(params.input_buffer, frame); |
256 } | 250 } |
257 | 251 |
258 protected: | 252 protected: |
259 ~MessageFilter() override { | 253 ~MessageFilter() override { |
260 if (client_map_.empty()) | 254 if (client_map_.empty()) |
261 return; | 255 return; |
262 | 256 |
263 if (child_task_runner_->BelongsToCurrentThread()) { | 257 if (child_task_runner_->BelongsToCurrentThread()) { |
264 STLDeleteValues(&client_map_); | 258 STLDeleteValues(&client_map_); |
265 } else { | 259 } else { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 for (const auto& create_jda_function : create_jda_fps) { | 416 for (const auto& create_jda_function : create_jda_fps) { |
423 scoped_ptr<media::JpegDecodeAccelerator> accelerator = | 417 scoped_ptr<media::JpegDecodeAccelerator> accelerator = |
424 (*create_jda_function)(base::ThreadTaskRunnerHandle::Get()); | 418 (*create_jda_function)(base::ThreadTaskRunnerHandle::Get()); |
425 if (accelerator && accelerator->IsSupported()) | 419 if (accelerator && accelerator->IsSupported()) |
426 return true; | 420 return true; |
427 } | 421 } |
428 return false; | 422 return false; |
429 } | 423 } |
430 | 424 |
431 } // namespace content | 425 } // namespace content |
OLD | NEW |