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

Side by Side Diff: media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.cc

Issue 2905823002: Add Mojo interfaces for GpuJpegDecodeAccelerator and GpuJpegDecodeAcceleratorHost (Closed)
Patch Set: mojo interface Created 3 years, 7 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/client/gpu_jpeg_decode_accelerator_host.h" 5 #include "media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/shared_memory_handle.h" 12 #include "base/memory/shared_memory_handle.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "gpu/ipc/client/gpu_channel_host.h" 16 #include "gpu/ipc/client/gpu_channel_host.h"
17 #include "ipc/ipc_listener.h" 17 #include "ipc/ipc_listener.h"
18 #include "ipc/ipc_message_macros.h" 18 #include "ipc/ipc_message_macros.h"
19 #include "ipc/ipc_message_utils.h" 19 #include "ipc/ipc_message_utils.h"
20 #include "media/gpu/ipc/common/media_messages.h" 20 #include "media/gpu/ipc/common/media_messages.h"
21 21
22 namespace media { 22 namespace media {
23 23
24 // Class to receive AcceleratedJpegDecoderHostMsg_DecodeAck IPC message on IO 24 // Class to receive AcceleratedJpegDecoderHostMsg_DecodeAck IPC message on IO
25 // thread. This does very similar what MessageFilter usually does. It is not 25 // thread. This does very similar what MessageFilter usually does. It is not
26 // MessageFilter because GpuChannelHost doesn't support AddFilter. 26 // MessageFilter because GpuChannelHost doesn't support AddFilter.
27 class GpuJpegDecodeAcceleratorHost::Receiver : public IPC::Listener, 27 class GpuJpegDecodeAcceleratorHost::Receiver : public IPC::Listener {
28 public base::NonThreadSafe {
29 public: 28 public:
30 Receiver(Client* client, 29 Receiver(Client* client,
31 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) 30 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
32 : client_(client), 31 : client_(client),
33 io_task_runner_(io_task_runner), 32 io_task_runner_(io_task_runner),
34 weak_factory_for_io_( 33 weak_factory_for_io_(
35 base::MakeUnique<base::WeakPtrFactory<Receiver>>(this)), 34 base::MakeUnique<base::WeakPtrFactory<Receiver>>(this)),
36 weak_ptr_for_io_(weak_factory_for_io_->GetWeakPtr()) { 35 weak_ptr_for_io_(weak_factory_for_io_->GetWeakPtr()) {
37 DCHECK(CalledOnValidThread()); 36 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
38 } 37 }
39 38
40 ~Receiver() override { 39 ~Receiver() override {
41 DCHECK(CalledOnValidThread()); 40 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
42 // If |io_task_runner_| no longer accepts tasks, |weak_factory_for_io_| 41 // If |io_task_runner_| no longer accepts tasks, |weak_factory_for_io_|
43 // will leak. This is acceptable, because that should only happen on 42 // will leak. This is acceptable, because that should only happen on
44 // Browser shutdown. 43 // Browser shutdown.
45 io_task_runner_->DeleteSoon(FROM_HERE, weak_factory_for_io_.release()); 44 io_task_runner_->DeleteSoon(FROM_HERE, weak_factory_for_io_.release());
46 } 45 }
47 46
48 void InvalidateWeakPtrOnIOThread(base::WaitableEvent* event) { 47 void InvalidateWeakPtrOnIOThread(base::WaitableEvent* event) {
49 DCHECK(io_task_runner_->BelongsToCurrentThread()); 48 DCHECK(io_task_runner_->BelongsToCurrentThread());
50 weak_factory_for_io_->InvalidateWeakPtrs(); 49 weak_factory_for_io_->InvalidateWeakPtrs();
51 event->Signal(); 50 event->Signal();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 92
94 Client* client_; 93 Client* client_;
95 94
96 // GPU IO task runner. 95 // GPU IO task runner.
97 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 96 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
98 97
99 // Weak pointers will be invalidated on IO thread. 98 // Weak pointers will be invalidated on IO thread.
100 std::unique_ptr<base::WeakPtrFactory<Receiver>> weak_factory_for_io_; 99 std::unique_ptr<base::WeakPtrFactory<Receiver>> weak_factory_for_io_;
101 base::WeakPtr<Receiver> weak_ptr_for_io_; 100 base::WeakPtr<Receiver> weak_ptr_for_io_;
102 101
102 THREAD_CHECKER(thread_checker_);
103 DISALLOW_COPY_AND_ASSIGN(Receiver); 103 DISALLOW_COPY_AND_ASSIGN(Receiver);
104 }; 104 };
105 105
106 GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost( 106 GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost(
107 scoped_refptr<gpu::GpuChannelHost> channel, 107 scoped_refptr<gpu::GpuChannelHost> channel,
108 int32_t route_id, 108 int32_t route_id,
109 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) 109 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
110 : channel_(std::move(channel)), 110 : channel_(std::move(channel)),
111 decoder_route_id_(route_id), 111 decoder_route_id_(route_id),
112 io_task_runner_(io_task_runner) { 112 io_task_runner_(io_task_runner) {
113 DCHECK(channel_); 113 DCHECK(channel_);
114 DCHECK_NE(decoder_route_id_, MSG_ROUTING_NONE); 114 DCHECK_NE(decoder_route_id_, MSG_ROUTING_NONE);
115 } 115 }
116 116
117 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() { 117 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() {
118 DCHECK(CalledOnValidThread()); 118 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
119 Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_)); 119 Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_));
120 120
121 if (receiver_) { 121 if (receiver_) {
122 channel_->RemoveRoute(decoder_route_id_); 122 channel_->RemoveRoute(decoder_route_id_);
123 123
124 // Invalidate weak ptr of |receiver_|. After that, no more messages will be 124 // Invalidate weak ptr of |receiver_|. After that, no more messages will be
125 // routed to |receiver_| on IO thread. 125 // routed to |receiver_| on IO thread.
126 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, 126 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
127 base::WaitableEvent::InitialState::NOT_SIGNALED); 127 base::WaitableEvent::InitialState::NOT_SIGNALED);
128 // Use of Unretained() is safe, because if the task executes, we block 128 // Use of Unretained() is safe, because if the task executes, we block
129 // until it is finished by waiting on |event| below. 129 // until it is finished by waiting on |event| below.
130 bool task_expected_to_run = io_task_runner_->PostTask( 130 bool task_expected_to_run = io_task_runner_->PostTask(
131 FROM_HERE, base::Bind(&Receiver::InvalidateWeakPtrOnIOThread, 131 FROM_HERE, base::Bind(&Receiver::InvalidateWeakPtrOnIOThread,
132 base::Unretained(receiver_.get()), 132 base::Unretained(receiver_.get()),
133 base::Unretained(&event))); 133 base::Unretained(&event)));
134 // If the current call is happening during the browser shutdown, the 134 // If the current call is happening during the browser shutdown, the
135 // |io_task_runner_| may no longer be accepting tasks. 135 // |io_task_runner_| may no longer be accepting tasks.
136 if (task_expected_to_run) 136 if (task_expected_to_run)
137 event.Wait(); 137 event.Wait();
138 } 138 }
139 } 139 }
140 140
141 bool GpuJpegDecodeAcceleratorHost::Initialize( 141 bool GpuJpegDecodeAcceleratorHost::Initialize(
142 JpegDecodeAccelerator::Client* client) { 142 JpegDecodeAccelerator::Client* client) {
143 DCHECK(CalledOnValidThread()); 143 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
144 144
145 bool succeeded = false; 145 bool succeeded = false;
146 // This cannot be on IO thread because the msg is synchronous. 146 // This cannot be on IO thread because the msg is synchronous.
147 Send(new GpuChannelMsg_CreateJpegDecoder(decoder_route_id_, &succeeded)); 147 Send(new GpuChannelMsg_CreateJpegDecoder(decoder_route_id_, &succeeded));
148 148
149 if (!succeeded) { 149 if (!succeeded) {
150 DLOG(ERROR) << "Send(GpuChannelMsg_CreateJpegDecoder()) failed"; 150 DLOG(ERROR) << "Send(GpuChannelMsg_CreateJpegDecoder()) failed";
151 return false; 151 return false;
152 } 152 }
153 153
154 receiver_.reset(new Receiver(client, io_task_runner_)); 154 receiver_.reset(new Receiver(client, io_task_runner_));
155 155
156 return true; 156 return true;
157 } 157 }
158 158
159 void GpuJpegDecodeAcceleratorHost::Decode( 159 void GpuJpegDecodeAcceleratorHost::Decode(
160 const BitstreamBuffer& bitstream_buffer, 160 const BitstreamBuffer& bitstream_buffer,
161 const scoped_refptr<VideoFrame>& video_frame) { 161 const scoped_refptr<VideoFrame>& video_frame) {
162 DCHECK(CalledOnValidThread()); 162 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
163 163
164 DCHECK( 164 DCHECK(
165 base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle())); 165 base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle()));
166 166
167 AcceleratedJpegDecoderMsg_Decode_Params decode_params; 167 AcceleratedJpegDecoderMsg_Decode_Params decode_params;
168 decode_params.input_buffer = bitstream_buffer; 168 decode_params.input_buffer = bitstream_buffer;
169 base::SharedMemoryHandle input_handle = 169 base::SharedMemoryHandle input_handle =
170 channel_->ShareToGpuProcess(bitstream_buffer.handle()); 170 channel_->ShareToGpuProcess(bitstream_buffer.handle());
171 if (!base::SharedMemory::IsHandleValid(input_handle)) { 171 if (!base::SharedMemory::IsHandleValid(input_handle)) {
172 DLOG(ERROR) << "Failed to duplicate handle of BitstreamBuffer"; 172 DLOG(ERROR) << "Failed to duplicate handle of BitstreamBuffer";
(...skipping 22 matching lines...) Expand all
195 decode_params.output_buffer_size = 195 decode_params.output_buffer_size =
196 base::checked_cast<uint32_t>(output_buffer_size); 196 base::checked_cast<uint32_t>(output_buffer_size);
197 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params)); 197 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params));
198 } 198 }
199 199
200 bool GpuJpegDecodeAcceleratorHost::IsSupported() { 200 bool GpuJpegDecodeAcceleratorHost::IsSupported() {
201 return channel_->gpu_info().jpeg_decode_accelerator_supported; 201 return channel_->gpu_info().jpeg_decode_accelerator_supported;
202 } 202 }
203 203
204 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) { 204 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) {
205 DCHECK(CalledOnValidThread()); 205 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
206 206
207 if (!channel_->Send(message)) { 207 if (!channel_->Send(message)) {
208 DLOG(ERROR) << "Send(" << message->type() << ") failed"; 208 DLOG(ERROR) << "Send(" << message->type() << ") failed";
209 } 209 }
210 } 210 }
211 211
212 base::WeakPtr<IPC::Listener> GpuJpegDecodeAcceleratorHost::GetReceiver() { 212 base::WeakPtr<IPC::Listener> GpuJpegDecodeAcceleratorHost::GetReceiver() {
213 return receiver_->AsWeakPtrForIO(); 213 return receiver_->AsWeakPtrForIO();
214 } 214 }
215 215
216 void GpuJpegDecodeAcceleratorHost::OnDecodeAck(int32_t bitstream_buffer_id,
217 mojom::Error error) {}
218
216 } // namespace media 219 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698