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