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

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

Issue 2911113003: Replace deprecated base::NonThreadSafe in media/gpu in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 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_SEQUENCE(sequence_checker_);
38 } 37 }
39 38
40 ~Receiver() override { 39 ~Receiver() override {
41 DCHECK(CalledOnValidThread()); 40 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 std::swap(client, client_); 88 std::swap(client, client_);
90 client->NotifyError(bitstream_buffer_id, error); 89 client->NotifyError(bitstream_buffer_id, error);
91 } 90 }
92 } 91 }
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
98 SEQUENCE_CHECKER(sequence_checker_);
99
99 // Weak pointers will be invalidated on IO thread. 100 // Weak pointers will be invalidated on IO thread.
100 std::unique_ptr<base::WeakPtrFactory<Receiver>> weak_factory_for_io_; 101 std::unique_ptr<base::WeakPtrFactory<Receiver>> weak_factory_for_io_;
101 base::WeakPtr<Receiver> weak_ptr_for_io_; 102 base::WeakPtr<Receiver> weak_ptr_for_io_;
102 103
103 DISALLOW_COPY_AND_ASSIGN(Receiver); 104 DISALLOW_COPY_AND_ASSIGN(Receiver);
104 }; 105 };
105 106
106 GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost( 107 GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost(
107 scoped_refptr<gpu::GpuChannelHost> channel, 108 scoped_refptr<gpu::GpuChannelHost> channel,
108 int32_t route_id, 109 int32_t route_id,
109 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) 110 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
110 : channel_(std::move(channel)), 111 : channel_(std::move(channel)),
111 decoder_route_id_(route_id), 112 decoder_route_id_(route_id),
112 io_task_runner_(io_task_runner) { 113 io_task_runner_(io_task_runner) {
113 DCHECK(channel_); 114 DCHECK(channel_);
114 DCHECK_NE(decoder_route_id_, MSG_ROUTING_NONE); 115 DCHECK_NE(decoder_route_id_, MSG_ROUTING_NONE);
115 } 116 }
116 117
117 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() { 118 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() {
118 DCHECK(CalledOnValidThread()); 119 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
119 Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_)); 120 Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_));
120 121
121 if (receiver_) { 122 if (receiver_) {
122 channel_->RemoveRoute(decoder_route_id_); 123 channel_->RemoveRoute(decoder_route_id_);
123 124
124 // Invalidate weak ptr of |receiver_|. After that, no more messages will be 125 // Invalidate weak ptr of |receiver_|. After that, no more messages will be
125 // routed to |receiver_| on IO thread. 126 // routed to |receiver_| on IO thread.
126 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, 127 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
127 base::WaitableEvent::InitialState::NOT_SIGNALED); 128 base::WaitableEvent::InitialState::NOT_SIGNALED);
128 // Use of Unretained() is safe, because if the task executes, we block 129 // Use of Unretained() is safe, because if the task executes, we block
129 // until it is finished by waiting on |event| below. 130 // until it is finished by waiting on |event| below.
130 bool task_expected_to_run = io_task_runner_->PostTask( 131 bool task_expected_to_run = io_task_runner_->PostTask(
131 FROM_HERE, base::Bind(&Receiver::InvalidateWeakPtrOnIOThread, 132 FROM_HERE, base::Bind(&Receiver::InvalidateWeakPtrOnIOThread,
132 base::Unretained(receiver_.get()), 133 base::Unretained(receiver_.get()),
133 base::Unretained(&event))); 134 base::Unretained(&event)));
134 // If the current call is happening during the browser shutdown, the 135 // If the current call is happening during the browser shutdown, the
135 // |io_task_runner_| may no longer be accepting tasks. 136 // |io_task_runner_| may no longer be accepting tasks.
136 if (task_expected_to_run) 137 if (task_expected_to_run)
137 event.Wait(); 138 event.Wait();
138 } 139 }
139 } 140 }
140 141
141 bool GpuJpegDecodeAcceleratorHost::Initialize( 142 bool GpuJpegDecodeAcceleratorHost::Initialize(
142 JpegDecodeAccelerator::Client* client) { 143 JpegDecodeAccelerator::Client* client) {
143 DCHECK(CalledOnValidThread()); 144 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
144 145
145 bool succeeded = false; 146 bool succeeded = false;
146 // This cannot be on IO thread because the msg is synchronous. 147 // This cannot be on IO thread because the msg is synchronous.
147 Send(new GpuChannelMsg_CreateJpegDecoder(decoder_route_id_, &succeeded)); 148 Send(new GpuChannelMsg_CreateJpegDecoder(decoder_route_id_, &succeeded));
148 149
149 if (!succeeded) { 150 if (!succeeded) {
150 DLOG(ERROR) << "Send(GpuChannelMsg_CreateJpegDecoder()) failed"; 151 DLOG(ERROR) << "Send(GpuChannelMsg_CreateJpegDecoder()) failed";
151 return false; 152 return false;
152 } 153 }
153 154
154 receiver_.reset(new Receiver(client, io_task_runner_)); 155 receiver_.reset(new Receiver(client, io_task_runner_));
155 156
156 return true; 157 return true;
157 } 158 }
158 159
159 void GpuJpegDecodeAcceleratorHost::Decode( 160 void GpuJpegDecodeAcceleratorHost::Decode(
160 const BitstreamBuffer& bitstream_buffer, 161 const BitstreamBuffer& bitstream_buffer,
161 const scoped_refptr<VideoFrame>& video_frame) { 162 const scoped_refptr<VideoFrame>& video_frame) {
162 DCHECK(CalledOnValidThread()); 163 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
163 164
164 DCHECK( 165 DCHECK(
165 base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle())); 166 base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle()));
166 167
167 AcceleratedJpegDecoderMsg_Decode_Params decode_params; 168 AcceleratedJpegDecoderMsg_Decode_Params decode_params;
168 decode_params.input_buffer = bitstream_buffer; 169 decode_params.input_buffer = bitstream_buffer;
169 base::SharedMemoryHandle input_handle = 170 base::SharedMemoryHandle input_handle =
170 channel_->ShareToGpuProcess(bitstream_buffer.handle()); 171 channel_->ShareToGpuProcess(bitstream_buffer.handle());
171 if (!base::SharedMemory::IsHandleValid(input_handle)) { 172 if (!base::SharedMemory::IsHandleValid(input_handle)) {
172 DLOG(ERROR) << "Failed to duplicate handle of BitstreamBuffer"; 173 DLOG(ERROR) << "Failed to duplicate handle of BitstreamBuffer";
(...skipping 22 matching lines...) Expand all
195 decode_params.output_buffer_size = 196 decode_params.output_buffer_size =
196 base::checked_cast<uint32_t>(output_buffer_size); 197 base::checked_cast<uint32_t>(output_buffer_size);
197 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params)); 198 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params));
198 } 199 }
199 200
200 bool GpuJpegDecodeAcceleratorHost::IsSupported() { 201 bool GpuJpegDecodeAcceleratorHost::IsSupported() {
201 return channel_->gpu_info().jpeg_decode_accelerator_supported; 202 return channel_->gpu_info().jpeg_decode_accelerator_supported;
202 } 203 }
203 204
204 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) { 205 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) {
205 DCHECK(CalledOnValidThread()); 206 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
206 207
207 if (!channel_->Send(message)) { 208 if (!channel_->Send(message)) {
208 DLOG(ERROR) << "Send(" << message->type() << ") failed"; 209 DLOG(ERROR) << "Send(" << message->type() << ") failed";
209 } 210 }
210 } 211 }
211 212
212 base::WeakPtr<IPC::Listener> GpuJpegDecodeAcceleratorHost::GetReceiver() { 213 base::WeakPtr<IPC::Listener> GpuJpegDecodeAcceleratorHost::GetReceiver() {
213 return receiver_->AsWeakPtrForIO(); 214 return receiver_->AsWeakPtrForIO();
214 } 215 }
215 216
216 } // namespace media 217 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.h ('k') | media/gpu/ipc/client/gpu_video_decode_accelerator_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698