| 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" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/shared_memory.h" | 13 #include "base/memory/shared_memory.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "content/common/gpu/gpu_channel.h" | 18 #include "content/common/gpu/gpu_channel.h" |
| 19 #include "content/common/gpu/gpu_messages.h" | 19 #include "content/common/gpu/gpu_messages.h" |
| 20 #include "content/common/gpu/jpeg_decode_params.h" |
| 20 #include "ipc/ipc_message_macros.h" | 21 #include "ipc/ipc_message_macros.h" |
| 21 #include "ipc/message_filter.h" | 22 #include "ipc/message_filter.h" |
| 22 #include "media/filters/jpeg_parser.h" | 23 #include "media/filters/jpeg_parser.h" |
| 23 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
| 24 | 25 |
| 25 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
| 26 #if defined(ARCH_CPU_X86_FAMILY) | 27 #if defined(ARCH_CPU_X86_FAMILY) |
| 27 #include "content/common/gpu/media/vaapi_jpeg_decode_accelerator.h" | 28 #include "content/common/gpu/media/vaapi_jpeg_decode_accelerator.h" |
| 28 #endif | 29 #endif |
| 29 #if defined(USE_V4L2_CODEC) | 30 #if defined(USE_V4L2_CODEC) |
| 30 #include "content/common/gpu/media/v4l2_device.h" | 31 #include "content/common/gpu/media/v4l2_device.h" |
| 31 #include "content/common/gpu/media/v4l2_jpeg_decode_accelerator.h" | 32 #include "content/common/gpu/media/v4l2_jpeg_decode_accelerator.h" |
| 32 #endif | 33 #endif |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 void DecodeFinished(scoped_ptr<base::SharedMemory> shm) { | 38 void DecodeFinished(scoped_ptr<base::SharedMemory> shm) { |
| 38 // Do nothing. Because VideoFrame is backed by |shm|, the purpose of this | 39 // Do nothing. Because VideoFrame is backed by |shm|, the purpose of this |
| 39 // function is to just keep reference of |shm| to make sure it lives util | 40 // function is to just keep reference of |shm| to make sure it lives util |
| 40 // decode finishes. | 41 // decode finishes. |
| 41 } | 42 } |
| 42 | 43 |
| 43 bool VerifyDecodeParams(const AcceleratedJpegDecoderMsg_Decode_Params& params) { | 44 bool VerifyDecodeParams(const content::JpegDecodeParams& params) { |
| 44 if (params.input_buffer_id < 0) { | 45 if (params.input_buffer_id < 0) { |
| 45 LOG(ERROR) << "BitstreamBuffer id " << params.input_buffer_id | 46 LOG(ERROR) << "BitstreamBuffer id " << params.input_buffer_id |
| 46 << " out of range"; | 47 << " out of range"; |
| 47 return false; | 48 return false; |
| 48 } | 49 } |
| 49 | 50 |
| 50 const int kJpegMaxDimension = UINT16_MAX; | 51 const int kJpegMaxDimension = UINT16_MAX; |
| 51 if (params.coded_size.IsEmpty() || | 52 if (params.coded_size.IsEmpty() || |
| 52 params.coded_size.width() > kJpegMaxDimension || | 53 params.coded_size.width() > kJpegMaxDimension || |
| 53 params.coded_size.height() > kJpegMaxDimension) { | 54 params.coded_size.height() > kJpegMaxDimension) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 193 } |
| 193 | 194 |
| 194 void NotifyDecodeStatusOnIOThread(int32_t route_id, | 195 void NotifyDecodeStatusOnIOThread(int32_t route_id, |
| 195 int32_t buffer_id, | 196 int32_t buffer_id, |
| 196 media::JpegDecodeAccelerator::Error error) { | 197 media::JpegDecodeAccelerator::Error error) { |
| 197 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 198 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 198 SendOnIOThread(new AcceleratedJpegDecoderHostMsg_DecodeAck( | 199 SendOnIOThread(new AcceleratedJpegDecoderHostMsg_DecodeAck( |
| 199 route_id, buffer_id, error)); | 200 route_id, buffer_id, error)); |
| 200 } | 201 } |
| 201 | 202 |
| 202 void OnDecodeOnIOThread( | 203 void OnDecodeOnIOThread(const int32_t* route_id, |
| 203 const int32_t* route_id, | 204 const JpegDecodeParams& params) { |
| 204 const AcceleratedJpegDecoderMsg_Decode_Params& params) { | |
| 205 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 205 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 206 DCHECK(route_id); | 206 DCHECK(route_id); |
| 207 TRACE_EVENT0("jpeg", "GpuJpegDecodeAccelerator::MessageFilter::OnDecode"); | 207 TRACE_EVENT0("jpeg", "GpuJpegDecodeAccelerator::MessageFilter::OnDecode"); |
| 208 | 208 |
| 209 if (!VerifyDecodeParams(params)) { | 209 if (!VerifyDecodeParams(params)) { |
| 210 NotifyDecodeStatusOnIOThread( | 210 NotifyDecodeStatusOnIOThread( |
| 211 *route_id, params.input_buffer_id, | 211 *route_id, params.input_buffer_id, |
| 212 media::JpegDecodeAccelerator::INVALID_ARGUMENT); | 212 media::JpegDecodeAccelerator::INVALID_ARGUMENT); |
| 213 if (base::SharedMemory::IsHandleValid(params.input_buffer_handle)) | 213 if (base::SharedMemory::IsHandleValid(params.input_buffer_handle)) |
| 214 base::SharedMemory::CloseHandle(params.input_buffer_handle); | 214 base::SharedMemory::CloseHandle(params.input_buffer_handle); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 for (const auto& create_jda_function : create_jda_fps) { | 432 for (const auto& create_jda_function : create_jda_fps) { |
| 433 scoped_ptr<media::JpegDecodeAccelerator> accelerator = | 433 scoped_ptr<media::JpegDecodeAccelerator> accelerator = |
| 434 (*create_jda_function)(base::ThreadTaskRunnerHandle::Get()); | 434 (*create_jda_function)(base::ThreadTaskRunnerHandle::Get()); |
| 435 if (accelerator && accelerator->IsSupported()) | 435 if (accelerator && accelerator->IsSupported()) |
| 436 return true; | 436 return true; |
| 437 } | 437 } |
| 438 return false; | 438 return false; |
| 439 } | 439 } |
| 440 | 440 |
| 441 } // namespace content | 441 } // namespace content |
| OLD | NEW |