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

Side by Side Diff: media/gpu/ipc/client/gpu_video_encode_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_encode_accelerator_host.h" 5 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "gpu/ipc/client/gpu_channel_host.h" 10 #include "gpu/ipc/client/gpu_channel_host.h"
11 #include "media/base/bind_to_current_loop.h"
danakj 2017/01/13 19:32:04 same
emircan 2017/01/13 19:41:09 Done.
11 #include "media/base/video_frame.h" 12 #include "media/base/video_frame.h"
12 #include "media/gpu/gpu_video_accelerator_util.h" 13 #include "media/gpu/gpu_video_accelerator_util.h"
13 #include "media/gpu/ipc/common/media_messages.h" 14 #include "media/gpu/ipc/common/media_messages.h"
14 #include "media/video/video_encode_accelerator.h" 15 #include "media/video/video_encode_accelerator.h"
15 16
16 namespace media { 17 namespace media {
17 18
18 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( 19 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost(
19 gpu::CommandBufferProxyImpl* impl) 20 gpu::CommandBufferProxyImpl* impl)
20 : channel_(impl->channel()), 21 : channel_(impl->channel()),
21 encoder_route_id_(MSG_ROUTING_NONE), 22 encoder_route_id_(MSG_ROUTING_NONE),
22 client_(nullptr), 23 client_(nullptr),
23 impl_(impl), 24 impl_(impl),
24 next_frame_id_(0), 25 next_frame_id_(0),
26 task_runner_(base::ThreadTaskRunnerHandle::Get()),
danakj 2017/01/13 19:32:04 can you give these task runners a name that descri
emircan 2017/01/13 19:41:09 Done.
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 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { 33 GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() {
32 DCHECK(CalledOnValidThread()); 34 DCHECK(CalledOnValidThread());
33 if (channel_ && encoder_route_id_ != MSG_ROUTING_NONE) 35 if (channel_ && encoder_route_id_ != MSG_ROUTING_NONE)
34 channel_->RemoveRoute(encoder_route_id_); 36 channel_->RemoveRoute(encoder_route_id_);
37
38 base::AutoLock lock(impl_lock_);
35 if (impl_) 39 if (impl_)
36 impl_->RemoveDeletionObserver(this); 40 impl_->RemoveDeletionObserver(this);
37 } 41 }
38 42
39 bool GpuVideoEncodeAcceleratorHost::OnMessageReceived( 43 bool GpuVideoEncodeAcceleratorHost::OnMessageReceived(
40 const IPC::Message& message) { 44 const IPC::Message& message) {
41 bool handled = true; 45 bool handled = true;
42 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message) 46 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message)
43 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers, 47 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers,
44 OnRequireBitstreamBuffers) 48 OnRequireBitstreamBuffers)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 80 }
77 81
78 bool GpuVideoEncodeAcceleratorHost::Initialize( 82 bool GpuVideoEncodeAcceleratorHost::Initialize(
79 VideoPixelFormat input_format, 83 VideoPixelFormat input_format,
80 const gfx::Size& input_visible_size, 84 const gfx::Size& input_visible_size,
81 VideoCodecProfile output_profile, 85 VideoCodecProfile output_profile,
82 uint32_t initial_bitrate, 86 uint32_t initial_bitrate,
83 Client* client) { 87 Client* client) {
84 DCHECK(CalledOnValidThread()); 88 DCHECK(CalledOnValidThread());
85 client_ = client; 89 client_ = client;
90
91 base::AutoLock lock(impl_lock_);
86 if (!impl_) { 92 if (!impl_) {
87 DLOG(ERROR) << "impl_ destroyed"; 93 DLOG(ERROR) << "impl_ destroyed";
88 return false; 94 return false;
89 } 95 }
90 96
91 int32_t route_id = channel_->GenerateRouteID(); 97 int32_t route_id = channel_->GenerateRouteID();
92 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr()); 98 channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr());
93 99
94 CreateVideoEncoderParams params; 100 CreateVideoEncoderParams params;
95 params.input_format = input_format; 101 params.input_format = input_format;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 173
168 void GpuVideoEncodeAcceleratorHost::Destroy() { 174 void GpuVideoEncodeAcceleratorHost::Destroy() {
169 DCHECK(CalledOnValidThread()); 175 DCHECK(CalledOnValidThread());
170 if (channel_) 176 if (channel_)
171 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_)); 177 Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_));
172 client_ = nullptr; 178 client_ = nullptr;
173 delete this; 179 delete this;
174 } 180 }
175 181
176 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { 182 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() {
177 DCHECK(CalledOnValidThread()); 183 base::AutoLock lock(impl_lock_);
178 impl_ = nullptr; 184 impl_ = nullptr;
179 185
180 // The gpu::CommandBufferProxyImpl is going away; error out this VEA. 186 // The gpu::CommandBufferProxyImpl is going away; error out this VEA.
181 OnChannelError(); 187 channel_error_cb_.Run();
182 } 188 }
183 189
184 void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame( 190 void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame(
185 const scoped_refptr<VideoFrame>& frame, 191 const scoped_refptr<VideoFrame>& frame,
186 bool force_keyframe) { 192 bool force_keyframe) {
187 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { 193 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) {
188 PostNotifyError(FROM_HERE, kPlatformFailureError, 194 PostNotifyError(FROM_HERE, kPlatformFailureError,
189 "EncodeSharedMemory(): cannot encode frame with invalid " 195 "EncodeSharedMemory(): cannot encode frame with invalid "
190 "shared memory handle"); 196 "shared memory handle");
191 return; 197 return;
(...skipping 21 matching lines...) Expand all
213 219
214 void GpuVideoEncodeAcceleratorHost::PostNotifyError( 220 void GpuVideoEncodeAcceleratorHost::PostNotifyError(
215 const tracked_objects::Location& location, 221 const tracked_objects::Location& location,
216 Error error, 222 Error error,
217 const std::string& message) { 223 const std::string& message) {
218 DCHECK(CalledOnValidThread()); 224 DCHECK(CalledOnValidThread());
219 DLOG(ERROR) << "Error from " << location.function_name() << "(" 225 DLOG(ERROR) << "Error from " << location.function_name() << "("
220 << location.file_name() << ":" << location.line_number() << ") " 226 << location.file_name() << ":" << location.line_number() << ") "
221 << message << " (error = " << error << ")"; 227 << message << " (error = " << error << ")";
222 // Post the error notification back to this thread, to avoid re-entrancy. 228 // Post the error notification back to this thread, to avoid re-entrancy.
223 base::ThreadTaskRunnerHandle::Get()->PostTask( 229 task_runner_->PostTask(
224 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, 230 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError,
225 weak_this_factory_.GetWeakPtr(), error)); 231 weak_this_factory_.GetWeakPtr(), error));
226 } 232 }
227 233
228 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { 234 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) {
229 DCHECK(CalledOnValidThread()); 235 DCHECK(CalledOnValidThread());
230 uint32_t message_type = message->type(); 236 uint32_t message_type = message->type();
231 if (!channel_->Send(message)) { 237 if (!channel_->Send(message)) {
232 PostNotifyError(FROM_HERE, kPlatformFailureError, 238 PostNotifyError(FROM_HERE, kPlatformFailureError,
233 base::StringPrintf("Send(%d) failed", message_type)); 239 base::StringPrintf("Send(%d) failed", message_type));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 weak_this_factory_.InvalidateWeakPtrs(); 295 weak_this_factory_.InvalidateWeakPtrs();
290 296
291 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the 297 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the
292 // last thing done on this stack! 298 // last thing done on this stack!
293 VideoEncodeAccelerator::Client* client = nullptr; 299 VideoEncodeAccelerator::Client* client = nullptr;
294 std::swap(client_, client); 300 std::swap(client_, client);
295 client->NotifyError(error); 301 client->NotifyError(error);
296 } 302 }
297 303
298 } // namespace media 304 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698