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, cc::VideoFrameProvider::Client* client); | |
37 | |
38 const scoped_ptr<StreamTextureHost> host_; | |
39 | |
40 base::Lock lock_; | |
35 scoped_refptr<base::MessageLoopProxy> loop_; | 41 scoped_refptr<base::MessageLoopProxy> loop_; |
36 | |
37 base::Lock client_lock_; | |
38 cc::VideoFrameProvider::Client* client_; | 42 cc::VideoFrameProvider::Client* client_; |
39 | 43 |
40 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); | 44 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
41 }; | 45 }; |
42 | 46 |
43 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) | 47 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) |
44 : host_(host), client_(NULL) {} | 48 : host_(host), client_(NULL) {} |
45 | 49 |
46 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} | 50 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
47 | 51 |
48 void StreamTextureProxyImpl::Release() { | 52 void StreamTextureProxyImpl::Release() { |
49 SetClient(NULL); | 53 base::AutoLock lock(lock_); |
50 if (loop_.get() && loop_.get() != base::MessageLoopProxy::current()) | 54 client_ = NULL; |
51 loop_->DeleteSoon(FROM_HERE, this); | 55 if (!loop_.get() || loop_.get() != base::MessageLoopProxy::current() || |
qinmin
2014/09/15 17:16:26
so if loop_.get() != base::MessageLoopProxy::curre
boliu
2014/09/15 17:54:07
Done.
| |
52 else | 56 !loop_->DeleteSoon(FROM_HERE, this)) { |
53 delete this; | 57 delete this; |
58 } | |
54 } | 59 } |
55 | 60 |
56 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { | 61 void StreamTextureProxyImpl::BindToLoop( |
57 base::AutoLock lock(client_lock_); | 62 int32 stream_id, |
58 client_ = client; | 63 cc::VideoFrameProvider::Client* client, |
64 scoped_refptr<base::MessageLoopProxy> loop) { | |
65 base::AutoLock lock(lock_); | |
66 DCHECK(loop.get()); | |
67 loop_ = loop; | |
68 | |
69 if (loop.get() != base::MessageLoopProxy::current()) { | |
qinmin
2014/09/15 17:16:26
It doesn't seem to me that we will ever enter this
boliu
2014/09/15 17:54:07
Umm....webview will get here, but webview doesn't
| |
70 // Unretained is safe here only because the object is deleted on |loop_| | |
71 // thread. | |
72 loop->PostTask(FROM_HERE, | |
73 base::Bind(&StreamTextureProxyImpl::BindOnThread, | |
74 base::Unretained(this), | |
75 stream_id, | |
76 client)); | |
77 } else { | |
78 client_ = client; | |
79 host_->BindToCurrentThread(stream_id, this); | |
80 } | |
59 } | 81 } |
60 | 82 |
61 void StreamTextureProxyImpl::BindToCurrentThread(int stream_id) { | 83 void StreamTextureProxyImpl::BindOnThread( |
62 loop_ = base::MessageLoopProxy::current(); | 84 int32 stream_id, |
85 cc::VideoFrameProvider::Client* client) { | |
86 { | |
87 base::AutoLock lock(lock_); | |
88 client_ = client; | |
89 } | |
63 host_->BindToCurrentThread(stream_id, this); | 90 host_->BindToCurrentThread(stream_id, this); |
64 } | 91 } |
65 | 92 |
66 void StreamTextureProxyImpl::OnFrameAvailable() { | 93 void StreamTextureProxyImpl::OnFrameAvailable() { |
67 base::AutoLock lock(client_lock_); | 94 base::AutoLock lock(lock_); |
68 if (client_) | 95 if (client_) |
69 client_->DidReceiveFrame(); | 96 client_->DidReceiveFrame(); |
70 } | 97 } |
71 | 98 |
72 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 99 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
73 base::AutoLock lock(client_lock_); | 100 base::AutoLock lock(lock_); |
74 if (client_) | 101 if (client_) |
75 client_->DidUpdateMatrix(matrix); | 102 client_->DidUpdateMatrix(matrix); |
76 } | 103 } |
77 | 104 |
78 } // namespace | 105 } // namespace |
79 | 106 |
80 // static | 107 // static |
81 scoped_refptr<StreamTextureFactoryImpl> StreamTextureFactoryImpl::Create( | 108 scoped_refptr<StreamTextureFactoryImpl> StreamTextureFactoryImpl::Create( |
82 const scoped_refptr<cc::ContextProvider>& context_provider, | 109 const scoped_refptr<cc::ContextProvider>& context_provider, |
83 GpuChannelHost* channel, | 110 GpuChannelHost* channel, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 | 154 |
128 void StreamTextureFactoryImpl::SetStreamTextureSize(int32 stream_id, | 155 void StreamTextureFactoryImpl::SetStreamTextureSize(int32 stream_id, |
129 const gfx::Size& size) { | 156 const gfx::Size& size) { |
130 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); | 157 channel_->Send(new GpuStreamTextureMsg_SetSize(stream_id, size)); |
131 } | 158 } |
132 | 159 |
133 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { | 160 gpu::gles2::GLES2Interface* StreamTextureFactoryImpl::ContextGL() { |
134 return context_provider_->ContextGL(); | 161 return context_provider_->ContextGL(); |
135 } | 162 } |
136 | 163 |
164 void StreamTextureFactoryImpl::AddObserver( | |
165 StreamTextureFactoryContextObserver* obs) { | |
166 } | |
167 | |
168 void StreamTextureFactoryImpl::RemoveObserver( | |
169 StreamTextureFactoryContextObserver* obs) { | |
170 } | |
171 | |
137 } // namespace content | 172 } // namespace content |
OLD | NEW |