| 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 "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 19 #include "base/trace_event/trace_event.h" | 19 #include "base/trace_event/trace_event.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "gpu/ipc/service/gpu_channel.h" | 21 #include "gpu/ipc/service/gpu_channel.h" |
| 22 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
| 23 #include "ipc/message_filter.h" | 23 #include "ipc/message_filter.h" |
| 24 #include "media/filters/jpeg_parser.h" | 24 #include "media/filters/jpeg_parser.h" |
| 25 #include "media/gpu/ipc/common/media_messages.h" | 25 #include "media/gpu/ipc/common/media_messages.h" |
| 26 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
| 27 | 27 |
| 28 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
| 29 #if defined(ARCH_CPU_X86_FAMILY) | 29 #if defined(ARCH_CPU_X86_FAMILY) |
| 30 #include "content/common/gpu/media/vaapi_jpeg_decode_accelerator.h" | 30 #include "media/gpu/vaapi_jpeg_decode_accelerator.h" |
| 31 #endif | 31 #endif |
| 32 #if defined(USE_V4L2_CODEC) | 32 #if defined(USE_V4L2_CODEC) |
| 33 #include "content/common/gpu/media/v4l2_device.h" | 33 #include "media/gpu/v4l2_device.h" |
| 34 #include "content/common/gpu/media/v4l2_jpeg_decode_accelerator.h" | 34 #include "media/gpu/v4l2_jpeg_decode_accelerator.h" |
| 35 #endif | 35 #endif |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 void DecodeFinished(std::unique_ptr<base::SharedMemory> shm) { | 40 void DecodeFinished(std::unique_ptr<base::SharedMemory> shm) { |
| 41 // Do nothing. Because VideoFrame is backed by |shm|, the purpose of this | 41 // Do nothing. Because VideoFrame is backed by |shm|, the purpose of this |
| 42 // function is to just keep reference of |shm| to make sure it lives util | 42 // function is to just keep reference of |shm| to make sure it lives util |
| 43 // decode finishes. | 43 // decode finishes. |
| 44 } | 44 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 63 LOG(ERROR) << "output_buffer_size is too small: " | 63 LOG(ERROR) << "output_buffer_size is too small: " |
| 64 << params.output_buffer_size; | 64 << params.output_buffer_size; |
| 65 return false; | 65 return false; |
| 66 } | 66 } |
| 67 | 67 |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 namespace content { | 73 namespace media { |
| 74 | 74 |
| 75 class GpuJpegDecodeAccelerator::Client | 75 class GpuJpegDecodeAccelerator::Client |
| 76 : public media::JpegDecodeAccelerator::Client, | 76 : public media::JpegDecodeAccelerator::Client, |
| 77 public base::NonThreadSafe { | 77 public base::NonThreadSafe { |
| 78 public: | 78 public: |
| 79 Client(content::GpuJpegDecodeAccelerator* owner, int32_t route_id) | 79 Client(media::GpuJpegDecodeAccelerator* owner, int32_t route_id) |
| 80 : owner_(owner->AsWeakPtr()), route_id_(route_id) {} | 80 : owner_(owner->AsWeakPtr()), route_id_(route_id) {} |
| 81 | 81 |
| 82 ~Client() override { DCHECK(CalledOnValidThread()); } | 82 ~Client() override { DCHECK(CalledOnValidThread()); } |
| 83 | 83 |
| 84 // media::JpegDecodeAccelerator::Client implementation. | 84 // media::JpegDecodeAccelerator::Client implementation. |
| 85 void VideoFrameReady(int32_t bitstream_buffer_id) override { | 85 void VideoFrameReady(int32_t bitstream_buffer_id) override { |
| 86 DCHECK(CalledOnValidThread()); | 86 DCHECK(CalledOnValidThread()); |
| 87 if (owner_) | 87 if (owner_) |
| 88 owner_->NotifyDecodeStatus(route_id_, bitstream_buffer_id, | 88 owner_->NotifyDecodeStatus(route_id_, bitstream_buffer_id, |
| 89 media::JpegDecodeAccelerator::NO_ERRORS); | 89 media::JpegDecodeAccelerator::NO_ERRORS); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 103 accelerator_->Decode(bitstream_buffer, video_frame); | 103 accelerator_->Decode(bitstream_buffer, video_frame); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void set_accelerator( | 106 void set_accelerator( |
| 107 std::unique_ptr<media::JpegDecodeAccelerator> accelerator) { | 107 std::unique_ptr<media::JpegDecodeAccelerator> accelerator) { |
| 108 DCHECK(CalledOnValidThread()); | 108 DCHECK(CalledOnValidThread()); |
| 109 accelerator_ = std::move(accelerator); | 109 accelerator_ = std::move(accelerator); |
| 110 } | 110 } |
| 111 | 111 |
| 112 private: | 112 private: |
| 113 base::WeakPtr<content::GpuJpegDecodeAccelerator> owner_; | 113 base::WeakPtr<media::GpuJpegDecodeAccelerator> owner_; |
| 114 int32_t route_id_; | 114 int32_t route_id_; |
| 115 std::unique_ptr<media::JpegDecodeAccelerator> accelerator_; | 115 std::unique_ptr<media::JpegDecodeAccelerator> accelerator_; |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 // Create, destroy, and RemoveClient run on child thread. All other methods run | 118 // Create, destroy, and RemoveClient run on child thread. All other methods run |
| 119 // on IO thread. | 119 // on IO thread. |
| 120 class GpuJpegDecodeAccelerator::MessageFilter : public IPC::MessageFilter { | 120 class GpuJpegDecodeAccelerator::MessageFilter : public IPC::MessageFilter { |
| 121 public: | 121 public: |
| 122 explicit MessageFilter(GpuJpegDecodeAccelerator* owner) | 122 explicit MessageFilter(GpuJpegDecodeAccelerator* owner) |
| 123 : owner_(owner->AsWeakPtr()), | 123 : owner_(owner->AsWeakPtr()), |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // only be accessed on IO thread. | 294 // only be accessed on IO thread. |
| 295 ClientMap client_map_; | 295 ClientMap client_map_; |
| 296 }; | 296 }; |
| 297 | 297 |
| 298 GpuJpegDecodeAccelerator::GpuJpegDecodeAccelerator( | 298 GpuJpegDecodeAccelerator::GpuJpegDecodeAccelerator( |
| 299 gpu::GpuChannel* channel, | 299 gpu::GpuChannel* channel, |
| 300 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 300 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
| 301 : channel_(channel), | 301 : channel_(channel), |
| 302 child_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 302 child_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 303 io_task_runner_(io_task_runner), | 303 io_task_runner_(io_task_runner), |
| 304 client_number_(0) { | 304 client_number_(0) {} |
| 305 } | |
| 306 | 305 |
| 307 GpuJpegDecodeAccelerator::~GpuJpegDecodeAccelerator() { | 306 GpuJpegDecodeAccelerator::~GpuJpegDecodeAccelerator() { |
| 308 DCHECK(CalledOnValidThread()); | 307 DCHECK(CalledOnValidThread()); |
| 309 if (filter_) { | 308 if (filter_) { |
| 310 channel_->RemoveFilter(filter_.get()); | 309 channel_->RemoveFilter(filter_.get()); |
| 311 } | 310 } |
| 312 } | 311 } |
| 313 | 312 |
| 314 void GpuJpegDecodeAccelerator::AddClient(int32_t route_id, | 313 void GpuJpegDecodeAccelerator::AddClient(int32_t route_id, |
| 315 base::Callback<void(bool)> response) { | 314 base::Callback<void(bool)> response) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 DCHECK(CalledOnValidThread()); | 382 DCHECK(CalledOnValidThread()); |
| 384 return channel_->Send(message); | 383 return channel_->Send(message); |
| 385 } | 384 } |
| 386 | 385 |
| 387 // static | 386 // static |
| 388 std::unique_ptr<media::JpegDecodeAccelerator> | 387 std::unique_ptr<media::JpegDecodeAccelerator> |
| 389 GpuJpegDecodeAccelerator::CreateV4L2JDA( | 388 GpuJpegDecodeAccelerator::CreateV4L2JDA( |
| 390 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) { | 389 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) { |
| 391 std::unique_ptr<media::JpegDecodeAccelerator> decoder; | 390 std::unique_ptr<media::JpegDecodeAccelerator> decoder; |
| 392 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | 391 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) |
| 393 scoped_refptr<V4L2Device> device = V4L2Device::Create( | 392 scoped_refptr<V4L2Device> device = |
| 394 V4L2Device::kJpegDecoder); | 393 V4L2Device::Create(V4L2Device::kJpegDecoder); |
| 395 if (device) | 394 if (device) |
| 396 decoder.reset(new V4L2JpegDecodeAccelerator(device, io_task_runner)); | 395 decoder.reset(new V4L2JpegDecodeAccelerator(device, io_task_runner)); |
| 397 #endif | 396 #endif |
| 398 return decoder; | 397 return decoder; |
| 399 } | 398 } |
| 400 | 399 |
| 401 // static | 400 // static |
| 402 std::unique_ptr<media::JpegDecodeAccelerator> | 401 std::unique_ptr<media::JpegDecodeAccelerator> |
| 403 GpuJpegDecodeAccelerator::CreateVaapiJDA( | 402 GpuJpegDecodeAccelerator::CreateVaapiJDA( |
| 404 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) { | 403 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 417 }; | 416 }; |
| 418 for (const auto& create_jda_function : create_jda_fps) { | 417 for (const auto& create_jda_function : create_jda_fps) { |
| 419 std::unique_ptr<media::JpegDecodeAccelerator> accelerator = | 418 std::unique_ptr<media::JpegDecodeAccelerator> accelerator = |
| 420 (*create_jda_function)(base::ThreadTaskRunnerHandle::Get()); | 419 (*create_jda_function)(base::ThreadTaskRunnerHandle::Get()); |
| 421 if (accelerator && accelerator->IsSupported()) | 420 if (accelerator && accelerator->IsSupported()) |
| 422 return true; | 421 return true; |
| 423 } | 422 } |
| 424 return false; | 423 return false; |
| 425 } | 424 } |
| 426 | 425 |
| 427 } // namespace content | 426 } // namespace media |
| OLD | NEW |