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

Side by Side Diff: content/renderer/media/android/stream_texture_factory.cc

Issue 2192823004: Update StreamTextureProxy to accept a base::Closure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed include guards Created 4 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/android/stream_texture_factory.h" 5 #include "content/renderer/media/android/stream_texture_factory.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "cc/output/context_provider.h" 8 #include "cc/output/context_provider.h"
9 #include "content/common/gpu/client/context_provider_command_buffer.h" 9 #include "content/common/gpu/client/context_provider_command_buffer.h"
10 #include "gpu/command_buffer/client/gles2_interface.h" 10 #include "gpu/command_buffer/client/gles2_interface.h"
11 #include "gpu/ipc/client/command_buffer_proxy_impl.h" 11 #include "gpu/ipc/client/command_buffer_proxy_impl.h"
12 #include "gpu/ipc/client/gpu_channel_host.h" 12 #include "gpu/ipc/client/gpu_channel_host.h"
13 #include "gpu/ipc/common/gpu_messages.h" 13 #include "gpu/ipc/common/gpu_messages.h"
14 #include "ui/gfx/geometry/size.h" 14 #include "ui/gfx/geometry/size.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 StreamTextureProxy::StreamTextureProxy(StreamTextureHost* host) 18 StreamTextureProxy::StreamTextureProxy(StreamTextureHost* host) : host_(host) {}
19 : host_(host), client_(NULL) {}
20 19
21 StreamTextureProxy::~StreamTextureProxy() {} 20 StreamTextureProxy::~StreamTextureProxy() {}
22 21
23 void StreamTextureProxy::Release() { 22 void StreamTextureProxy::Release() {
24 { 23 {
25 // Cannot call into |client_| anymore (from any thread) after returning 24 // Cannot call into |client_| anymore (from any thread) after returning
watk 2016/07/29 19:03:16 |client_| is dead
tguilbert 2016/08/01 22:05:57 Done.
26 // from here. 25 // from here.
27 base::AutoLock lock(lock_); 26 base::AutoLock lock(lock_);
28 client_ = NULL; 27 received_frame_cb_.Reset();
29 } 28 }
30 // Release is analogous to the destructor, so there should be no more external 29 // Release is analogous to the destructor, so there should be no more external
31 // calls to this object in Release. Therefore there is no need to acquire the 30 // calls to this object in Release. Therefore there is no need to acquire the
32 // lock to access |loop_|. 31 // lock to access |loop_|.
33 if (!loop_.get() || loop_->BelongsToCurrentThread() || 32 if (!loop_.get() || loop_->BelongsToCurrentThread() ||
34 !loop_->DeleteSoon(FROM_HERE, this)) { 33 !loop_->DeleteSoon(FROM_HERE, this)) {
35 delete this; 34 delete this;
36 } 35 }
37 } 36 }
38 37
39 void StreamTextureProxy::BindToLoop( 38 void StreamTextureProxy::BindToLoop(
40 int32_t stream_id, 39 int32_t stream_id,
41 cc::VideoFrameProvider::Client* client, 40 const base::Closure& received_frame_cb,
42 scoped_refptr<base::SingleThreadTaskRunner> loop) { 41 scoped_refptr<base::SingleThreadTaskRunner> loop) {
43 DCHECK(loop.get()); 42 DCHECK(loop.get());
44 43
45 { 44 {
46 base::AutoLock lock(lock_); 45 base::AutoLock lock(lock_);
47 DCHECK(!loop_.get() || (loop.get() == loop_.get())); 46 DCHECK(!loop_.get() || (loop.get() == loop_.get()));
48 loop_ = loop; 47 loop_ = loop;
49 client_ = client; 48 received_frame_cb_ = received_frame_cb;
50 } 49 }
51 50
52 if (loop->BelongsToCurrentThread()) { 51 if (loop->BelongsToCurrentThread()) {
53 BindOnThread(stream_id); 52 BindOnThread(stream_id);
54 return; 53 return;
55 } 54 }
56 // Unretained is safe here only because the object is deleted on |loop_| 55 // Unretained is safe here only because the object is deleted on |loop_|
57 // thread. 56 // thread.
58 loop->PostTask(FROM_HERE, 57 loop->PostTask(FROM_HERE,
59 base::Bind(&StreamTextureProxy::BindOnThread, 58 base::Bind(&StreamTextureProxy::BindOnThread,
60 base::Unretained(this), 59 base::Unretained(this),
61 stream_id)); 60 stream_id));
62 } 61 }
63 62
64 void StreamTextureProxy::BindOnThread(int32_t stream_id) { 63 void StreamTextureProxy::BindOnThread(int32_t stream_id) {
65 host_->BindToCurrentThread(stream_id, this); 64 host_->BindToCurrentThread(stream_id, this);
66 } 65 }
67 66
68 void StreamTextureProxy::OnFrameAvailable() { 67 void StreamTextureProxy::OnFrameAvailable() {
69 base::AutoLock lock(lock_); 68 base::AutoLock lock(lock_);
70 if (client_) 69 if (!received_frame_cb_.is_null())
71 client_->DidReceiveFrame(); 70 received_frame_cb_.Run();
72 } 71 }
73 72
74 // static 73 // static
75 scoped_refptr<StreamTextureFactory> StreamTextureFactory::Create( 74 scoped_refptr<StreamTextureFactory> StreamTextureFactory::Create(
76 scoped_refptr<ContextProviderCommandBuffer> context_provider) { 75 scoped_refptr<ContextProviderCommandBuffer> context_provider) {
77 return new StreamTextureFactory(std::move(context_provider)); 76 return new StreamTextureFactory(std::move(context_provider));
78 } 77 }
79 78
80 StreamTextureFactory::StreamTextureFactory( 79 StreamTextureFactory::StreamTextureFactory(
81 scoped_refptr<ContextProviderCommandBuffer> context_provider) 80 scoped_refptr<ContextProviderCommandBuffer> context_provider)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 void StreamTextureFactory::SetStreamTextureSize(int32_t stream_id, 116 void StreamTextureFactory::SetStreamTextureSize(int32_t stream_id,
118 const gfx::Size& size) { 117 const gfx::Size& size) {
119 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); 118 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size));
120 } 119 }
121 120
122 gpu::gles2::GLES2Interface* StreamTextureFactory::ContextGL() { 121 gpu::gles2::GLES2Interface* StreamTextureFactory::ContextGL() {
123 return context_provider_->ContextGL(); 122 return context_provider_->ContextGL();
124 } 123 }
125 124
126 } // namespace content 125 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698