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

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

Issue 2627173002: Adds locks for CommandBufferProxyImpl invalidation (Closed)
Patch Set: Created 3 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_video_decode_accelerator_host.h" 5 #include "media/gpu/ipc/client/gpu_video_decode_accelerator_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "gpu/ipc/client/gpu_channel_host.h" 12 #include "gpu/ipc/client/gpu_channel_host.h"
13 #include "ipc/ipc_message_macros.h" 13 #include "ipc/ipc_message_macros.h"
14 #include "ipc/ipc_message_utils.h" 14 #include "ipc/ipc_message_utils.h"
15 #include "media/base/bind_to_current_loop.h"
danakj 2017/01/13 19:32:04 unused then
emircan 2017/01/13 19:41:09 Sorry i missed out. Removing.
15 #include "media/gpu/ipc/common/media_messages.h" 16 #include "media/gpu/ipc/common/media_messages.h"
16 17
17 namespace media { 18 namespace media {
18 19
19 GpuVideoDecodeAcceleratorHost::GpuVideoDecodeAcceleratorHost( 20 GpuVideoDecodeAcceleratorHost::GpuVideoDecodeAcceleratorHost(
20 gpu::CommandBufferProxyImpl* impl) 21 gpu::CommandBufferProxyImpl* impl)
21 : channel_(impl->channel()), 22 : channel_(impl->channel()),
22 decoder_route_id_(MSG_ROUTING_NONE), 23 decoder_route_id_(MSG_ROUTING_NONE),
23 client_(NULL), 24 client_(nullptr),
24 impl_(impl), 25 impl_(impl),
26 task_runner_(base::ThreadTaskRunnerHandle::Get()),
25 weak_this_factory_(this) { 27 weak_this_factory_(this) {
26 DCHECK(channel_); 28 DCHECK(channel_);
27 DCHECK(impl_); 29 DCHECK(impl_);
28 impl_->AddDeletionObserver(this); 30 impl_->AddDeletionObserver(this);
29 } 31 }
30 32
31 GpuVideoDecodeAcceleratorHost::~GpuVideoDecodeAcceleratorHost() { 33 GpuVideoDecodeAcceleratorHost::~GpuVideoDecodeAcceleratorHost() {
32 DCHECK(CalledOnValidThread()); 34 DCHECK(CalledOnValidThread());
33 35
34 if (channel_ && decoder_route_id_ != MSG_ROUTING_NONE) 36 if (channel_ && decoder_route_id_ != MSG_ROUTING_NONE)
35 channel_->RemoveRoute(decoder_route_id_); 37 channel_->RemoveRoute(decoder_route_id_);
38
39 base::AutoLock lock(impl_lock_);
36 if (impl_) 40 if (impl_)
37 impl_->RemoveDeletionObserver(this); 41 impl_->RemoveDeletionObserver(this);
38 } 42 }
39 43
40 bool GpuVideoDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { 44 bool GpuVideoDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) {
41 DCHECK(CalledOnValidThread()); 45 DCHECK(CalledOnValidThread());
42 bool handled = true; 46 bool handled = true;
43 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAcceleratorHost, msg) 47 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAcceleratorHost, msg)
44 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_InitializationComplete, 48 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_InitializationComplete,
45 OnInitializationComplete) 49 OnInitializationComplete)
(...skipping 15 matching lines...) Expand all
61 // See OnNotifyError for why |this| mustn't be used after OnNotifyError might 65 // See OnNotifyError for why |this| mustn't be used after OnNotifyError might
62 // have been called above. 66 // have been called above.
63 return handled; 67 return handled;
64 } 68 }
65 69
66 void GpuVideoDecodeAcceleratorHost::OnChannelError() { 70 void GpuVideoDecodeAcceleratorHost::OnChannelError() {
67 DCHECK(CalledOnValidThread()); 71 DCHECK(CalledOnValidThread());
68 if (channel_) { 72 if (channel_) {
69 if (decoder_route_id_ != MSG_ROUTING_NONE) 73 if (decoder_route_id_ != MSG_ROUTING_NONE)
70 channel_->RemoveRoute(decoder_route_id_); 74 channel_->RemoveRoute(decoder_route_id_);
71 channel_ = NULL; 75 channel_ = nullptr;
72 } 76 }
73 DLOG(ERROR) << "OnChannelError()"; 77 DLOG(ERROR) << "OnChannelError()";
74 PostNotifyError(PLATFORM_FAILURE); 78 PostNotifyError(PLATFORM_FAILURE);
75 } 79 }
76 80
77 bool GpuVideoDecodeAcceleratorHost::Initialize(const Config& config, 81 bool GpuVideoDecodeAcceleratorHost::Initialize(const Config& config,
78 Client* client) { 82 Client* client) {
79 DCHECK(CalledOnValidThread()); 83 DCHECK(CalledOnValidThread());
80 client_ = client; 84 client_ = client;
81 85
86 base::AutoLock lock(impl_lock_);
82 if (!impl_) 87 if (!impl_)
83 return false; 88 return false;
84 89
85 int32_t route_id = channel_->GenerateRouteID(); 90 int32_t route_id = channel_->GenerateRouteID();
86 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr()); 91 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr());
87 92
88 bool succeeded = false; 93 bool succeeded = false;
89 Send(new GpuCommandBufferMsg_CreateVideoDecoder(impl_->route_id(), config, 94 Send(new GpuCommandBufferMsg_CreateVideoDecoder(impl_->route_id(), config,
90 route_id, &succeeded)); 95 route_id, &succeeded));
91 96
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 if (!channel_) 173 if (!channel_)
169 return; 174 return;
170 Send( 175 Send(
171 new AcceleratedVideoDecoderMsg_SetSurface(decoder_route_id_, surface_id)); 176 new AcceleratedVideoDecoderMsg_SetSurface(decoder_route_id_, surface_id));
172 } 177 }
173 178
174 void GpuVideoDecodeAcceleratorHost::Destroy() { 179 void GpuVideoDecodeAcceleratorHost::Destroy() {
175 DCHECK(CalledOnValidThread()); 180 DCHECK(CalledOnValidThread());
176 if (channel_) 181 if (channel_)
177 Send(new AcceleratedVideoDecoderMsg_Destroy(decoder_route_id_)); 182 Send(new AcceleratedVideoDecoderMsg_Destroy(decoder_route_id_));
178 client_ = NULL; 183 client_ = nullptr;
179 delete this; 184 delete this;
180 } 185 }
181 186
182 void GpuVideoDecodeAcceleratorHost::OnWillDeleteImpl() { 187 void GpuVideoDecodeAcceleratorHost::OnWillDeleteImpl() {
183 DCHECK(CalledOnValidThread()); 188 base::AutoLock lock(impl_lock_);
184 impl_ = NULL; 189 impl_ = nullptr;
185 190
186 // The gpu::CommandBufferProxyImpl is going away; error out this VDA. 191 // The gpu::CommandBufferProxyImpl is going away; error out this VDA.
187 OnChannelError(); 192 task_runner_->PostTask(
193 FROM_HERE, base::Bind(&GpuVideoDecodeAcceleratorHost::OnChannelError,
194 weak_this_factory_.GetWeakPtr()));
188 } 195 }
189 196
190 void GpuVideoDecodeAcceleratorHost::PostNotifyError(Error error) { 197 void GpuVideoDecodeAcceleratorHost::PostNotifyError(Error error) {
191 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
192 DVLOG(2) << "PostNotifyError(): error=" << error; 199 DVLOG(2) << "PostNotifyError(): error=" << error;
193 base::ThreadTaskRunnerHandle::Get()->PostTask( 200 task_runner_->PostTask(
194 FROM_HERE, base::Bind(&GpuVideoDecodeAcceleratorHost::OnNotifyError, 201 FROM_HERE, base::Bind(&GpuVideoDecodeAcceleratorHost::OnNotifyError,
195 weak_this_factory_.GetWeakPtr(), error)); 202 weak_this_factory_.GetWeakPtr(), error));
196 } 203 }
197 204
198 void GpuVideoDecodeAcceleratorHost::Send(IPC::Message* message) { 205 void GpuVideoDecodeAcceleratorHost::Send(IPC::Message* message) {
199 DCHECK(CalledOnValidThread()); 206 DCHECK(CalledOnValidThread());
200 uint32_t message_type = message->type(); 207 uint32_t message_type = message->type();
201 if (!channel_->Send(message)) { 208 if (!channel_->Send(message)) {
202 DLOG(ERROR) << "Send(" << message_type << ") failed"; 209 DLOG(ERROR) << "Send(" << message_type << ") failed";
203 PostNotifyError(PLATFORM_FAILURE); 210 PostNotifyError(PLATFORM_FAILURE);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } 280 }
274 281
275 void GpuVideoDecodeAcceleratorHost::OnNotifyError(uint32_t error) { 282 void GpuVideoDecodeAcceleratorHost::OnNotifyError(uint32_t error) {
276 DCHECK(CalledOnValidThread()); 283 DCHECK(CalledOnValidThread());
277 if (!client_) 284 if (!client_)
278 return; 285 return;
279 weak_this_factory_.InvalidateWeakPtrs(); 286 weak_this_factory_.InvalidateWeakPtrs();
280 287
281 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the 288 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the
282 // last thing done on this stack! 289 // last thing done on this stack!
283 VideoDecodeAccelerator::Client* client = NULL; 290 VideoDecodeAccelerator::Client* client = nullptr;
284 std::swap(client, client_); 291 std::swap(client, client_);
285 client->NotifyError(static_cast<VideoDecodeAccelerator::Error>(error)); 292 client->NotifyError(static_cast<VideoDecodeAccelerator::Error>(error));
286 } 293 }
287 294
288 } // namespace media 295 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698