Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: media/gpu/ipc/service/gpu_jpeg_decode_accelerator.cc

Issue 2735083002: [Mojo Video Capture] Add test coverage for accelerated jpeg decoding (Closed)
Patch Set: Rebase to March 15th, Remove #include jpeg_parser Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "media/gpu/ipc/service/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/command_line.h"
13 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
16 #include "base/memory/shared_memory.h" 17 #include "base/memory/shared_memory.h"
17 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
18 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
19 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "gpu/ipc/service/gpu_channel.h" 22 #include "gpu/ipc/service/gpu_channel.h"
22 #include "ipc/ipc_message_macros.h" 23 #include "ipc/ipc_message_macros.h"
23 #include "ipc/message_filter.h" 24 #include "ipc/message_filter.h"
25 #include "media/base/media_switches.h"
24 #include "media/filters/jpeg_parser.h" 26 #include "media/filters/jpeg_parser.h"
27 #include "media/gpu/fake_jpeg_decode_accelerator.h"
25 #include "media/gpu/ipc/common/media_messages.h" 28 #include "media/gpu/ipc/common/media_messages.h"
26 #include "ui/gfx/geometry/size.h" 29 #include "ui/gfx/geometry/size.h"
27 30
28 #if defined(OS_CHROMEOS) 31 #if defined(OS_CHROMEOS)
29 #if defined(ARCH_CPU_X86_FAMILY) 32 #if defined(ARCH_CPU_X86_FAMILY)
30 #include "media/gpu/vaapi_jpeg_decode_accelerator.h" 33 #include "media/gpu/vaapi_jpeg_decode_accelerator.h"
31 #endif 34 #endif
32 #if defined(USE_V4L2_CODEC) 35 #if defined(USE_V4L2_CODEC)
33 #include "media/gpu/v4l2_device.h" 36 #include "media/gpu/v4l2_device.h"
34 #include "media/gpu/v4l2_jpeg_decode_accelerator.h" 37 #include "media/gpu/v4l2_jpeg_decode_accelerator.h"
(...skipping 17 matching lines...) Expand all
52 std::unique_ptr<media::JpegDecodeAccelerator> CreateVaapiJDA( 55 std::unique_ptr<media::JpegDecodeAccelerator> CreateVaapiJDA(
53 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) { 56 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
54 std::unique_ptr<media::JpegDecodeAccelerator> decoder; 57 std::unique_ptr<media::JpegDecodeAccelerator> decoder;
55 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 58 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
56 decoder.reset( 59 decoder.reset(
57 new media::VaapiJpegDecodeAccelerator(std::move(io_task_runner))); 60 new media::VaapiJpegDecodeAccelerator(std::move(io_task_runner)));
58 #endif 61 #endif
59 return decoder; 62 return decoder;
60 } 63 }
61 64
65 std::unique_ptr<media::JpegDecodeAccelerator> CreateFakeJDA(
66 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
67 return base::MakeUnique<media::FakeJpegDecodeAccelerator>(
68 std::move(io_task_runner));
69 }
70
62 void DecodeFinished(std::unique_ptr<base::SharedMemory> shm) { 71 void DecodeFinished(std::unique_ptr<base::SharedMemory> shm) {
63 // Do nothing. Because VideoFrame is backed by |shm|, the purpose of this 72 // Do nothing. Because VideoFrame is backed by |shm|, the purpose of this
64 // function is to just keep reference of |shm| to make sure it lives until 73 // function is to just keep reference of |shm| to make sure it lives until
65 // decode finishes. 74 // decode finishes.
66 } 75 }
67 76
68 bool VerifyDecodeParams(const AcceleratedJpegDecoderMsg_Decode_Params& params) { 77 bool VerifyDecodeParams(const AcceleratedJpegDecoderMsg_Decode_Params& params) {
69 const int kJpegMaxDimension = UINT16_MAX; 78 const int kJpegMaxDimension = UINT16_MAX;
70 if (params.coded_size.IsEmpty() || 79 if (params.coded_size.IsEmpty() ||
71 params.coded_size.width() > kJpegMaxDimension || 80 params.coded_size.width() > kJpegMaxDimension ||
(...skipping 15 matching lines...) Expand all
87 return false; 96 return false;
88 } 97 }
89 98
90 return true; 99 return true;
91 } 100 }
92 101
93 } // namespace 102 } // namespace
94 103
95 namespace media { 104 namespace media {
96 105
97 class GpuJpegDecodeAccelerator::Client : public JpegDecodeAccelerator::Client, 106 class GpuJpegDecodeAccelerator::Client : public JpegDecodeAccelerator::Client {
98 public base::NonThreadSafe {
99 public: 107 public:
100 Client(GpuJpegDecodeAccelerator* owner, int32_t route_id) 108 Client(base::WeakPtr<GpuJpegDecodeAccelerator> owner,
101 : owner_(owner->AsWeakPtr()), route_id_(route_id) {} 109 int32_t route_id,
110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
111 : owner_(std::move(owner)),
112 route_id_(route_id),
113 io_task_runner_(std::move(io_task_runner)) {
114 DCHECK(thread_checker_.CalledOnValidThread());
115 }
102 116
103 ~Client() override { DCHECK(CalledOnValidThread()); } 117 ~Client() override { DCHECK(thread_checker_.CalledOnValidThread()); }
104 118
105 // JpegDecodeAccelerator::Client implementation. 119 // JpegDecodeAccelerator::Client implementation.
106 void VideoFrameReady(int32_t bitstream_buffer_id) override { 120 void VideoFrameReady(int32_t bitstream_buffer_id) override {
107 DCHECK(CalledOnValidThread()); 121 DCHECK(thread_checker_.CalledOnValidThread());
108 if (owner_) 122 if (owner_)
109 owner_->NotifyDecodeStatus(route_id_, bitstream_buffer_id, 123 owner_->NotifyDecodeStatus(route_id_, bitstream_buffer_id,
110 JpegDecodeAccelerator::NO_ERRORS); 124 JpegDecodeAccelerator::NO_ERRORS);
111 } 125 }
112 126
113 void NotifyError(int32_t bitstream_buffer_id, 127 void NotifyError(int32_t bitstream_buffer_id,
114 JpegDecodeAccelerator::Error error) override { 128 JpegDecodeAccelerator::Error error) override {
115 DCHECK(CalledOnValidThread()); 129 DCHECK(thread_checker_.CalledOnValidThread());
116 if (owner_) 130 if (owner_)
117 owner_->NotifyDecodeStatus(route_id_, bitstream_buffer_id, error); 131 owner_->NotifyDecodeStatus(route_id_, bitstream_buffer_id, error);
118 } 132 }
119 133
120 void Decode(const BitstreamBuffer& bitstream_buffer, 134 void Decode(const BitstreamBuffer& bitstream_buffer,
121 const scoped_refptr<VideoFrame>& video_frame) { 135 const scoped_refptr<VideoFrame>& video_frame) {
122 DCHECK(CalledOnValidThread()); 136 DCHECK(io_task_runner_->BelongsToCurrentThread());
123 DCHECK(accelerator_); 137 DCHECK(accelerator_);
124 accelerator_->Decode(bitstream_buffer, video_frame); 138 accelerator_->Decode(bitstream_buffer, video_frame);
125 } 139 }
126 140
127 void set_accelerator(std::unique_ptr<JpegDecodeAccelerator> accelerator) { 141 void set_accelerator(std::unique_ptr<JpegDecodeAccelerator> accelerator) {
128 DCHECK(CalledOnValidThread()); 142 DCHECK(thread_checker_.CalledOnValidThread());
129 accelerator_ = std::move(accelerator); 143 accelerator_ = std::move(accelerator);
130 } 144 }
131 145
132 private: 146 private:
147 base::ThreadChecker thread_checker_;
133 base::WeakPtr<GpuJpegDecodeAccelerator> owner_; 148 base::WeakPtr<GpuJpegDecodeAccelerator> owner_;
134 int32_t route_id_; 149 const int32_t route_id_;
150 const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
135 std::unique_ptr<JpegDecodeAccelerator> accelerator_; 151 std::unique_ptr<JpegDecodeAccelerator> accelerator_;
136 }; 152 };
137 153
138 // Create, destroy, and RemoveClient run on child thread. All other methods run 154 // Create, destroy, and RemoveClient run on child thread. All other methods run
139 // on IO thread. 155 // on IO thread.
156 // TODO(chfremer): Migrate this to Mojo. See https://crbug.com/699255
140 class GpuJpegDecodeAccelerator::MessageFilter : public IPC::MessageFilter { 157 class GpuJpegDecodeAccelerator::MessageFilter : public IPC::MessageFilter {
141 public: 158 public:
142 explicit MessageFilter(GpuJpegDecodeAccelerator* owner) 159 explicit MessageFilter(GpuJpegDecodeAccelerator* owner)
143 : owner_(owner->AsWeakPtr()), 160 : owner_(owner->AsWeakPtr()),
144 child_task_runner_(owner_->child_task_runner_), 161 child_task_runner_(owner_->child_task_runner_),
145 io_task_runner_(owner_->io_task_runner_) {} 162 io_task_runner_(owner_->io_task_runner_) {}
146 163
147 void OnChannelError() override { sender_ = nullptr; } 164 void OnChannelError() override { sender_ = nullptr; }
148 165
149 void OnChannelClosing() override { sender_ = nullptr; } 166 void OnChannelClosing() override { sender_ = nullptr; }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 return true; 341 return true;
325 } 342 }
326 return false; 343 return false;
327 } 344 }
328 345
329 // static 346 // static
330 std::vector<GpuJpegDecodeAcceleratorFactoryProvider::CreateAcceleratorCB> 347 std::vector<GpuJpegDecodeAcceleratorFactoryProvider::CreateAcceleratorCB>
331 GpuJpegDecodeAcceleratorFactoryProvider::GetAcceleratorFactories() { 348 GpuJpegDecodeAcceleratorFactoryProvider::GetAcceleratorFactories() {
332 // This list is ordered by priority of use. 349 // This list is ordered by priority of use.
333 std::vector<CreateAcceleratorCB> result; 350 std::vector<CreateAcceleratorCB> result;
334 result.push_back(base::Bind(&CreateV4L2JDA)); 351 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
335 result.push_back(base::Bind(&CreateVaapiJDA)); 352 switches::kUseFakeJpegDecodeAccelerator)) {
353 result.push_back(base::Bind(&CreateFakeJDA));
354 } else {
355 result.push_back(base::Bind(&CreateV4L2JDA));
356 result.push_back(base::Bind(&CreateVaapiJDA));
357 }
336 return result; 358 return result;
337 } 359 }
338 360
339 GpuJpegDecodeAccelerator::GpuJpegDecodeAccelerator( 361 GpuJpegDecodeAccelerator::GpuJpegDecodeAccelerator(
340 gpu::FilteredSender* channel, 362 gpu::FilteredSender* channel,
341 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 363 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
342 : GpuJpegDecodeAccelerator( 364 : GpuJpegDecodeAccelerator(
343 channel, 365 channel,
344 std::move(io_task_runner), 366 std::move(io_task_runner),
345 GpuJpegDecodeAcceleratorFactoryProvider::GetAcceleratorFactories()) {} 367 GpuJpegDecodeAcceleratorFactoryProvider::GetAcceleratorFactories()) {}
(...skipping 16 matching lines...) Expand all
362 } 384 }
363 } 385 }
364 386
365 void GpuJpegDecodeAccelerator::AddClient(int32_t route_id, 387 void GpuJpegDecodeAccelerator::AddClient(int32_t route_id,
366 base::Callback<void(bool)> response) { 388 base::Callback<void(bool)> response) {
367 DCHECK(CalledOnValidThread()); 389 DCHECK(CalledOnValidThread());
368 390
369 // When adding non-chromeos platforms, VideoCaptureGpuJpegDecoder::Initialize 391 // When adding non-chromeos platforms, VideoCaptureGpuJpegDecoder::Initialize
370 // needs to be updated. 392 // needs to be updated.
371 393
372 std::unique_ptr<Client> client(new Client(this, route_id)); 394 std::unique_ptr<Client> client(
395 new Client(AsWeakPtr(), route_id, io_task_runner_));
373 std::unique_ptr<JpegDecodeAccelerator> accelerator; 396 std::unique_ptr<JpegDecodeAccelerator> accelerator;
374 for (const auto& create_jda_function : accelerator_factory_functions_) { 397 for (const auto& create_jda_function : accelerator_factory_functions_) {
375 std::unique_ptr<JpegDecodeAccelerator> tmp_accelerator = 398 std::unique_ptr<JpegDecodeAccelerator> tmp_accelerator =
376 create_jda_function.Run(io_task_runner_); 399 create_jda_function.Run(io_task_runner_);
377 if (tmp_accelerator && tmp_accelerator->Initialize(client.get())) { 400 if (tmp_accelerator && tmp_accelerator->Initialize(client.get())) {
378 accelerator = std::move(tmp_accelerator); 401 accelerator = std::move(tmp_accelerator);
379 break; 402 break;
380 } 403 }
381 } 404 }
382 405
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 filter_ = nullptr; 446 filter_ = nullptr;
424 } 447 }
425 } 448 }
426 449
427 bool GpuJpegDecodeAccelerator::Send(IPC::Message* message) { 450 bool GpuJpegDecodeAccelerator::Send(IPC::Message* message) {
428 DCHECK(CalledOnValidThread()); 451 DCHECK(CalledOnValidThread());
429 return channel_->Send(message); 452 return channel_->Send(message);
430 } 453 }
431 454
432 } // namespace media 455 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/fake_jpeg_decode_accelerator.cc ('k') | services/video_capture/receiver_mojo_to_media_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698