Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 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_(NULL), |
| 24 impl_(impl), | 25 impl_(impl), |
| 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); |
| 30 channel_error_cb_ = media::BindToCurrentLoop( | |
|
danakj
2017/01/13 18:27:50
Just store a task runner and bind/post to it from
emircan
2017/01/13 19:08:14
Done.
| |
| 31 base::Bind(&GpuVideoDecodeAcceleratorHost::OnChannelError, | |
| 32 weak_this_factory_.GetWeakPtr())); | |
| 29 } | 33 } |
| 30 | 34 |
| 31 GpuVideoDecodeAcceleratorHost::~GpuVideoDecodeAcceleratorHost() { | 35 GpuVideoDecodeAcceleratorHost::~GpuVideoDecodeAcceleratorHost() { |
| 32 DCHECK(CalledOnValidThread()); | 36 DCHECK(CalledOnValidThread()); |
| 33 | 37 |
| 34 if (channel_ && decoder_route_id_ != MSG_ROUTING_NONE) | 38 if (channel_ && decoder_route_id_ != MSG_ROUTING_NONE) |
| 35 channel_->RemoveRoute(decoder_route_id_); | 39 channel_->RemoveRoute(decoder_route_id_); |
| 40 | |
| 41 base::AutoLock lock(impl_lock_); | |
| 36 if (impl_) | 42 if (impl_) |
| 37 impl_->RemoveDeletionObserver(this); | 43 impl_->RemoveDeletionObserver(this); |
| 38 } | 44 } |
| 39 | 45 |
| 40 bool GpuVideoDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { | 46 bool GpuVideoDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { |
| 41 DCHECK(CalledOnValidThread()); | 47 DCHECK(CalledOnValidThread()); |
| 42 bool handled = true; | 48 bool handled = true; |
| 43 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAcceleratorHost, msg) | 49 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAcceleratorHost, msg) |
| 44 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_InitializationComplete, | 50 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_InitializationComplete, |
| 45 OnInitializationComplete) | 51 OnInitializationComplete) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 72 } | 78 } |
| 73 DLOG(ERROR) << "OnChannelError()"; | 79 DLOG(ERROR) << "OnChannelError()"; |
| 74 PostNotifyError(PLATFORM_FAILURE); | 80 PostNotifyError(PLATFORM_FAILURE); |
| 75 } | 81 } |
| 76 | 82 |
| 77 bool GpuVideoDecodeAcceleratorHost::Initialize(const Config& config, | 83 bool GpuVideoDecodeAcceleratorHost::Initialize(const Config& config, |
| 78 Client* client) { | 84 Client* client) { |
| 79 DCHECK(CalledOnValidThread()); | 85 DCHECK(CalledOnValidThread()); |
| 80 client_ = client; | 86 client_ = client; |
| 81 | 87 |
| 88 base::AutoLock lock(impl_lock_); | |
| 82 if (!impl_) | 89 if (!impl_) |
| 83 return false; | 90 return false; |
| 84 | 91 |
| 85 int32_t route_id = channel_->GenerateRouteID(); | 92 int32_t route_id = channel_->GenerateRouteID(); |
| 86 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr()); | 93 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr()); |
| 87 | 94 |
| 88 bool succeeded = false; | 95 bool succeeded = false; |
| 89 Send(new GpuCommandBufferMsg_CreateVideoDecoder(impl_->route_id(), config, | 96 Send(new GpuCommandBufferMsg_CreateVideoDecoder(impl_->route_id(), config, |
| 90 route_id, &succeeded)); | 97 route_id, &succeeded)); |
| 91 | 98 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 | 180 |
| 174 void GpuVideoDecodeAcceleratorHost::Destroy() { | 181 void GpuVideoDecodeAcceleratorHost::Destroy() { |
| 175 DCHECK(CalledOnValidThread()); | 182 DCHECK(CalledOnValidThread()); |
| 176 if (channel_) | 183 if (channel_) |
| 177 Send(new AcceleratedVideoDecoderMsg_Destroy(decoder_route_id_)); | 184 Send(new AcceleratedVideoDecoderMsg_Destroy(decoder_route_id_)); |
| 178 client_ = NULL; | 185 client_ = NULL; |
| 179 delete this; | 186 delete this; |
| 180 } | 187 } |
| 181 | 188 |
| 182 void GpuVideoDecodeAcceleratorHost::OnWillDeleteImpl() { | 189 void GpuVideoDecodeAcceleratorHost::OnWillDeleteImpl() { |
| 183 DCHECK(CalledOnValidThread()); | 190 base::AutoLock lock(impl_lock_); |
| 184 impl_ = NULL; | 191 impl_ = NULL; |
| 185 | 192 |
| 186 // The gpu::CommandBufferProxyImpl is going away; error out this VDA. | 193 // The gpu::CommandBufferProxyImpl is going away; error out this VDA. |
| 187 OnChannelError(); | 194 channel_error_cb_.Run(); |
| 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 base::ThreadTaskRunnerHandle::Get()->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 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 = NULL; |
| 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 |
| OLD | NEW |