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

Side by Side Diff: content/renderer/media/renderer_gpu_video_accelerator_factories.cc

Issue 23440015: Fix webrtc HW encode deadlock scenarios. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 3 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 "content/renderer/media/renderer_gpu_video_accelerator_factories.h" 5 #include "content/renderer/media/renderer_gpu_video_accelerator_factories.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #include <GLES2/gl2ext.h> 8 #include <GLES2/gl2ext.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "content/child/child_thread.h" 11 #include "content/child/child_thread.h"
12 #include "content/common/gpu/client/gpu_channel_host.h" 12 #include "content/common/gpu/client/gpu_channel_host.h"
13 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 13 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
14 #include "gpu/command_buffer/client/gles2_implementation.h" 14 #include "gpu/command_buffer/client/gles2_implementation.h"
15 #include "gpu/ipc/command_buffer_proxy.h" 15 #include "gpu/ipc/command_buffer_proxy.h"
16 #include "third_party/skia/include/core/SkPixelRef.h" 16 #include "third_party/skia/include/core/SkPixelRef.h"
17 17
18 namespace content { 18 namespace content {
19 19
20 RendererGpuVideoAcceleratorFactories::~RendererGpuVideoAcceleratorFactories() {} 20 RendererGpuVideoAcceleratorFactories::~RendererGpuVideoAcceleratorFactories() {}
21 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories( 21 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories(
22 GpuChannelHost* gpu_channel_host, 22 GpuChannelHost* gpu_channel_host,
23 const scoped_refptr<base::MessageLoopProxy>& message_loop, 23 const scoped_refptr<base::MessageLoopProxy>& message_loop,
24 WebGraphicsContext3DCommandBufferImpl* context) 24 WebGraphicsContext3DCommandBufferImpl* context)
25 : message_loop_(message_loop), 25 : message_loop_(message_loop),
26 main_message_loop_(base::MessageLoopProxy::current()),
27 gpu_channel_host_(gpu_channel_host), 26 gpu_channel_host_(gpu_channel_host),
27 thread_safe_sender_(ChildThread::current()->thread_safe_sender()),
28 aborted_waiter_(true, false), 28 aborted_waiter_(true, false),
29 message_loop_async_waiter_(false, false), 29 message_loop_async_waiter_(false, false) {
30 render_thread_async_waiter_(false, false) {
31 // |context| is only required to support HW-accelerated decode. 30 // |context| is only required to support HW-accelerated decode.
32 if (!context) 31 if (!context)
33 return; 32 return;
34 33
35 if (message_loop_->BelongsToCurrentThread()) { 34 if (message_loop_->BelongsToCurrentThread()) {
36 AsyncGetContext(context); 35 AsyncGetContext(context);
37 message_loop_async_waiter_.Reset(); 36 message_loop_async_waiter_.Reset();
38 return; 37 return;
39 } 38 }
40 // Wait for the context to be acquired. 39 // Wait for the context to be acquired.
41 message_loop_->PostTask( 40 message_loop_->PostTask(
42 FROM_HERE, 41 FROM_HERE,
43 base::Bind(&RendererGpuVideoAcceleratorFactories::AsyncGetContext, 42 base::Bind(&RendererGpuVideoAcceleratorFactories::AsyncGetContext,
44 // Unretained to avoid ref/deref'ing |*this|, which is not yet 43 // Unretained to avoid ref/deref'ing |*this|, which is not yet
45 // stored in a scoped_refptr. Safe because the Wait() below 44 // stored in a scoped_refptr. Safe because the Wait() below
46 // keeps us alive until this task completes. 45 // keeps us alive until this task completes.
47 base::Unretained(this), 46 base::Unretained(this),
48 // OK to pass raw because the pointee is only deleted on the 47 // OK to pass raw because the pointee is only deleted on the
49 // compositor thread, and only as the result of a PostTask from 48 // compositor thread, and only as the result of a PostTask from
50 // the render thread which can only happen after this function 49 // the render thread which can only happen after this function
51 // returns, so our PostTask will run first. 50 // returns, so our PostTask will run first.
52 context)); 51 context));
53 message_loop_async_waiter_.Wait(); 52 message_loop_async_waiter_.Wait();
54 } 53 }
55 54
56 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories() 55 RendererGpuVideoAcceleratorFactories::RendererGpuVideoAcceleratorFactories()
57 : aborted_waiter_(true, false), 56 : aborted_waiter_(true, false),
58 message_loop_async_waiter_(false, false), 57 message_loop_async_waiter_(false, false) {}
59 render_thread_async_waiter_(false, false) {}
60 58
61 void RendererGpuVideoAcceleratorFactories::AsyncGetContext( 59 void RendererGpuVideoAcceleratorFactories::AsyncGetContext(
62 WebGraphicsContext3DCommandBufferImpl* context) { 60 WebGraphicsContext3DCommandBufferImpl* context) {
63 context_ = context->AsWeakPtr(); 61 context_ = context->AsWeakPtr();
64 if (context_.get()) { 62 if (context_.get()) {
65 if (context_->makeContextCurrent()) { 63 if (context_->makeContextCurrent()) {
66 // Called once per media player, but is a no-op after the first one in 64 // Called once per media player, but is a no-op after the first one in
67 // each renderer. 65 // each renderer.
68 context_->insertEventMarkerEXT("GpuVDAContext3D"); 66 context_->insertEventMarkerEXT("GpuVDAContext3D");
69 } 67 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 GL_UNSIGNED_BYTE, 354 GL_UNSIGNED_BYTE,
357 read_pixels_bitmap_.pixelRef()->pixels()); 355 read_pixels_bitmap_.pixelRef()->pixels());
358 gles2->DeleteFramebuffers(1, &fb); 356 gles2->DeleteFramebuffers(1, &fb);
359 gles2->DeleteTextures(1, &tmp_texture); 357 gles2->DeleteTextures(1, &tmp_texture);
360 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); 358 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR));
361 message_loop_async_waiter_.Signal(); 359 message_loop_async_waiter_.Signal();
362 } 360 }
363 361
364 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory( 362 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory(
365 size_t size) { 363 size_t size) {
366 if (main_message_loop_->BelongsToCurrentThread()) { 364 return ChildThread::AllocateSharedMemory(size, thread_safe_sender_.get());
367 return ChildThread::current()->AllocateSharedMemory(size);
368 }
369 main_message_loop_->PostTask(
370 FROM_HERE,
371 base::Bind(&RendererGpuVideoAcceleratorFactories::AsyncCreateSharedMemory,
372 this,
373 size));
374
375 base::WaitableEvent* objects[] = {&aborted_waiter_,
376 &render_thread_async_waiter_};
377 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0)
378 return NULL;
379 return shared_memory_segment_.release();
380 }
381
382 void RendererGpuVideoAcceleratorFactories::AsyncCreateSharedMemory(
383 size_t size) {
384 DCHECK_EQ(base::MessageLoop::current(),
385 ChildThread::current()->message_loop());
386
387 shared_memory_segment_.reset(
388 ChildThread::current()->AllocateSharedMemory(size));
389 render_thread_async_waiter_.Signal();
390 } 365 }
391 366
392 scoped_refptr<base::MessageLoopProxy> 367 scoped_refptr<base::MessageLoopProxy>
393 RendererGpuVideoAcceleratorFactories::GetMessageLoop() { 368 RendererGpuVideoAcceleratorFactories::GetMessageLoop() {
394 return message_loop_; 369 return message_loop_;
395 } 370 }
396 371
397 void RendererGpuVideoAcceleratorFactories::Abort() { aborted_waiter_.Signal(); } 372 void RendererGpuVideoAcceleratorFactories::Abort() { aborted_waiter_.Signal(); }
398 373
399 bool RendererGpuVideoAcceleratorFactories::IsAborted() { 374 bool RendererGpuVideoAcceleratorFactories::IsAborted() {
400 return aborted_waiter_.IsSignaled(); 375 return aborted_waiter_.IsSignaled();
401 } 376 }
402 377
403 scoped_refptr<RendererGpuVideoAcceleratorFactories> 378 scoped_refptr<RendererGpuVideoAcceleratorFactories>
404 RendererGpuVideoAcceleratorFactories::Clone() { 379 RendererGpuVideoAcceleratorFactories::Clone() {
405 scoped_refptr<RendererGpuVideoAcceleratorFactories> factories = 380 scoped_refptr<RendererGpuVideoAcceleratorFactories> factories =
406 new RendererGpuVideoAcceleratorFactories(); 381 new RendererGpuVideoAcceleratorFactories();
407 factories->message_loop_ = message_loop_; 382 factories->message_loop_ = message_loop_;
408 factories->main_message_loop_ = main_message_loop_;
409 factories->gpu_channel_host_ = gpu_channel_host_; 383 factories->gpu_channel_host_ = gpu_channel_host_;
410 factories->context_ = context_; 384 factories->context_ = context_;
385 factories->thread_safe_sender_ = thread_safe_sender_;
411 return factories; 386 return factories;
412 } 387 }
413 388
414 void 389 void
415 RendererGpuVideoAcceleratorFactories::AsyncDestroyVideoDecodeAccelerator() { 390 RendererGpuVideoAcceleratorFactories::AsyncDestroyVideoDecodeAccelerator() {
416 // OK to release because Destroy() will delete the VDA instance. 391 // OK to release because Destroy() will delete the VDA instance.
417 if (vda_) 392 if (vda_)
418 vda_.release()->Destroy(); 393 vda_.release()->Destroy();
419 } 394 }
420 395
421 void 396 void
422 RendererGpuVideoAcceleratorFactories::AsyncDestroyVideoEncodeAccelerator() { 397 RendererGpuVideoAcceleratorFactories::AsyncDestroyVideoEncodeAccelerator() {
423 // OK to release because Destroy() will delete the VDA instance. 398 // OK to release because Destroy() will delete the VDA instance.
424 if (vea_) 399 if (vea_)
425 vea_.release()->Destroy(); 400 vea_.release()->Destroy();
426 } 401 }
427 402
428 } // namespace content 403 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/renderer_gpu_video_accelerator_factories.h ('k') | content/renderer/media/rtc_video_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698