OLD | NEW |
---|---|
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_impl.h" | 5 #include "content/renderer/media/android/stream_texture_factory_impl.h" |
6 | 6 |
7 #include "cc/output/context_provider.h" | 7 #include "cc/output/context_provider.h" |
8 #include "content/common/gpu/client/gpu_channel_host.h" | 8 #include "content/common/gpu/client/gpu_channel_host.h" |
9 #include "content/common/gpu/gpu_messages.h" | 9 #include "content/common/gpu/gpu_messages.h" |
10 #include "content/renderer/gpu/stream_texture_host_android.h" | 10 #include "content/renderer/gpu/stream_texture_host_android.h" |
11 #include "gpu/command_buffer/client/gles2_interface.h" | 11 #include "gpu/command_buffer/client/gles2_interface.h" |
12 #include "ui/gfx/size.h" | 12 #include "ui/gfx/size.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class StreamTextureProxyImpl : public StreamTextureProxy, | 18 class StreamTextureProxyImpl : public StreamTextureProxy, |
19 public StreamTextureHost::Listener { | 19 public StreamTextureHost::Listener { |
20 public: | 20 public: |
21 explicit StreamTextureProxyImpl(StreamTextureHost* host); | 21 explicit StreamTextureProxyImpl(StreamTextureHost* host); |
22 virtual ~StreamTextureProxyImpl(); | 22 virtual ~StreamTextureProxyImpl(); |
23 | 23 |
24 // StreamTextureProxy implementation: | 24 // StreamTextureProxy implementation: |
25 virtual void BindToCurrentThread(int32 stream_id) OVERRIDE; | 25 virtual void BindToLoop(int32 stream_id, |
26 virtual void SetClient(cc::VideoFrameProvider::Client* client) OVERRIDE; | 26 cc::VideoFrameProvider::Client* client, |
27 scoped_refptr<base::MessageLoopProxy> loop) OVERRIDE; | |
27 virtual void Release() OVERRIDE; | 28 virtual void Release() OVERRIDE; |
28 | 29 |
29 // StreamTextureHost::Listener implementation: | 30 // StreamTextureHost::Listener implementation: |
30 virtual void OnFrameAvailable() OVERRIDE; | 31 virtual void OnFrameAvailable() OVERRIDE; |
31 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; | 32 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; |
32 | 33 |
33 private: | 34 private: |
34 scoped_ptr<StreamTextureHost> host_; | 35 void SetClient(cc::VideoFrameProvider::Client* client); |
36 void BindOnThread(int32 stream_id, | |
37 cc::VideoFrameProvider::Client* client, | |
38 scoped_refptr<base::MessageLoopProxy> loop); | |
39 | |
40 const scoped_ptr<StreamTextureHost> host_; | |
35 scoped_refptr<base::MessageLoopProxy> loop_; | 41 scoped_refptr<base::MessageLoopProxy> loop_; |
36 | 42 |
37 base::Lock client_lock_; | 43 base::Lock client_lock_; |
38 cc::VideoFrameProvider::Client* client_; | 44 cc::VideoFrameProvider::Client* client_; |
39 | 45 |
40 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); | 46 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
41 }; | 47 }; |
42 | 48 |
43 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) | 49 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) |
44 : host_(host), client_(NULL) {} | 50 : host_(host), client_(NULL) {} |
45 | 51 |
46 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} | 52 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
47 | 53 |
48 void StreamTextureProxyImpl::Release() { | 54 void StreamTextureProxyImpl::Release() { |
55 // Assumes this is the last reference to this object. So no need to acquire | |
56 // lock. | |
49 SetClient(NULL); | 57 SetClient(NULL); |
50 if (loop_.get() && loop_.get() != base::MessageLoopProxy::current()) | 58 if (!loop_.get() || loop_->BelongsToCurrentThread() || |
51 loop_->DeleteSoon(FROM_HERE, this); | 59 !loop_->DeleteSoon(FROM_HERE, this)) { |
52 else | |
53 delete this; | 60 delete this; |
61 } | |
54 } | 62 } |
55 | 63 |
56 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { | 64 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { |
57 base::AutoLock lock(client_lock_); | 65 base::AutoLock lock(client_lock_); |
58 client_ = client; | 66 client_ = client; |
59 } | 67 } |
60 | 68 |
61 void StreamTextureProxyImpl::BindToCurrentThread(int stream_id) { | 69 void StreamTextureProxyImpl::BindToLoop( |
62 loop_ = base::MessageLoopProxy::current(); | 70 int32 stream_id, |
71 cc::VideoFrameProvider::Client* client, | |
72 scoped_refptr<base::MessageLoopProxy> loop) { | |
73 if (loop->BelongsToCurrentThread()) { | |
74 BindOnThread(stream_id, client, loop); | |
75 return; | |
76 } | |
77 // Unretained is safe here only because the object is deleted on |loop_| | |
78 // thread. | |
79 loop->PostTask(FROM_HERE, | |
80 base::Bind(&StreamTextureProxyImpl::BindOnThread, | |
81 base::Unretained(this), | |
82 stream_id, | |
83 client, | |
84 loop)); | |
85 } | |
86 | |
87 void StreamTextureProxyImpl::BindOnThread( | |
88 int32 stream_id, | |
89 cc::VideoFrameProvider::Client* client, | |
90 scoped_refptr<base::MessageLoopProxy> loop) { | |
no sievers
2014/09/15 19:00:39
DCHECK(!client || (client && loop));
DCHECK(!loop_
boliu
2014/09/15 20:41:53
Actually easier to just DCHECK(loop) in this case
| |
91 loop_ = loop; | |
92 SetClient(client); | |
no sievers
2014/09/15 19:00:40
move this to BindToLoop()
boliu
2014/09/15 20:41:53
Done.
| |
63 host_->BindToCurrentThread(stream_id, this); | 93 host_->BindToCurrentThread(stream_id, this); |
64 } | 94 } |
65 | 95 |
66 void StreamTextureProxyImpl::OnFrameAvailable() { | 96 void StreamTextureProxyImpl::OnFrameAvailable() { |
67 base::AutoLock lock(client_lock_); | 97 base::AutoLock lock(client_lock_); |
68 if (client_) | 98 if (client_) |
69 client_->DidReceiveFrame(); | 99 client_->DidReceiveFrame(); |
70 } | 100 } |
71 | 101 |
72 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 102 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 | 157 |
128 void StreamTextureFactoryImpl::SetStreamTextureSize(int32 stream_id, | 158 void StreamTextureFactoryImpl::SetStreamTextureSize(int32 stream_id, |
129 const gfx::Size& size) { | 159 const gfx::Size& size) { |
130 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); | 160 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); |
131 } | 161 } |
132 | 162 |
133 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { | 163 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { |
134 return context_provider_->ContextGL(); | 164 return context_provider_->ContextGL(); |
135 } | 165 } |
136 | 166 |
167 void StreamTextureFactoryImpl::AddObserver( | |
168 StreamTextureFactoryContextObserver* obs) { | |
169 } | |
170 | |
171 void StreamTextureFactoryImpl::RemoveObserver( | |
172 StreamTextureFactoryContextObserver* obs) { | |
173 } | |
174 | |
137 } // namespace content | 175 } // namespace content |
OLD | NEW |