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

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

Powered by Google App Engine
This is Rietveld 408576698