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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 virtual void BindToLoop(int32 stream_id, | 25 virtual void BindToLoop(int32 stream_id, |
26 cc::VideoFrameProvider::Client* client, | 26 cc::VideoFrameProvider::Client* client, |
27 scoped_refptr<base::MessageLoopProxy> loop) OVERRIDE; | 27 scoped_refptr<base::MessageLoopProxy> loop) OVERRIDE; |
28 virtual void Release() OVERRIDE; | 28 virtual void Release() OVERRIDE; |
29 | 29 |
30 // StreamTextureHost::Listener implementation: | 30 // StreamTextureHost::Listener implementation: |
31 virtual void OnFrameAvailable() OVERRIDE; | 31 virtual void OnFrameAvailable() OVERRIDE; |
32 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; | 32 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; |
33 | 33 |
34 private: | 34 private: |
35 void SetClient(cc::VideoFrameProvider::Client* client); | 35 void BindOnThread(int32 stream_id); |
36 void BindOnThread(int32 stream_id, | |
37 scoped_refptr<base::MessageLoopProxy> loop); | |
38 | 36 |
39 const scoped_ptr<StreamTextureHost> host_; | 37 const scoped_ptr<StreamTextureHost> host_; |
| 38 |
| 39 // Protects access to |client_| and |loop_|. |
| 40 base::Lock lock_; |
| 41 cc::VideoFrameProvider::Client* client_; |
40 scoped_refptr<base::MessageLoopProxy> loop_; | 42 scoped_refptr<base::MessageLoopProxy> loop_; |
41 | 43 |
42 base::Lock client_lock_; | |
43 cc::VideoFrameProvider::Client* client_; | |
44 | |
45 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); | 44 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
46 }; | 45 }; |
47 | 46 |
48 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) | 47 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) |
49 : host_(host), client_(NULL) {} | 48 : host_(host), client_(NULL) {} |
50 | 49 |
51 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} | 50 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
52 | 51 |
53 void StreamTextureProxyImpl::Release() { | 52 void StreamTextureProxyImpl::Release() { |
54 // Assumes this is the last reference to this object. So no need to acquire | 53 { |
55 // lock. | 54 // Cannot call into |client_| anymore (from any thread) after returning |
56 SetClient(NULL); | 55 // from here. |
| 56 base::AutoLock lock(lock_); |
| 57 client_ = NULL; |
| 58 } |
| 59 // Release is analogous to the destructor, so there should be no more external |
| 60 // calls to this object in Release. Therefore there is no need to acquire the |
| 61 // lock to access |loop_|. |
57 if (!loop_.get() || loop_->BelongsToCurrentThread() || | 62 if (!loop_.get() || loop_->BelongsToCurrentThread() || |
58 !loop_->DeleteSoon(FROM_HERE, this)) { | 63 !loop_->DeleteSoon(FROM_HERE, this)) { |
59 delete this; | 64 delete this; |
60 } | 65 } |
61 } | 66 } |
62 | 67 |
63 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { | |
64 base::AutoLock lock(client_lock_); | |
65 client_ = client; | |
66 } | |
67 | |
68 void StreamTextureProxyImpl::BindToLoop( | 68 void StreamTextureProxyImpl::BindToLoop( |
69 int32 stream_id, | 69 int32 stream_id, |
70 cc::VideoFrameProvider::Client* client, | 70 cc::VideoFrameProvider::Client* client, |
71 scoped_refptr<base::MessageLoopProxy> loop) { | 71 scoped_refptr<base::MessageLoopProxy> loop) { |
72 DCHECK(loop); | 72 DCHECK(loop); |
73 SetClient(client); | 73 |
| 74 { |
| 75 base::AutoLock lock(lock_); |
| 76 DCHECK(!loop_ || (loop == loop_)); |
| 77 loop_ = loop; |
| 78 client_ = client; |
| 79 } |
| 80 |
74 if (loop->BelongsToCurrentThread()) { | 81 if (loop->BelongsToCurrentThread()) { |
75 BindOnThread(stream_id, loop); | 82 BindOnThread(stream_id); |
76 return; | 83 return; |
77 } | 84 } |
78 // Unretained is safe here only because the object is deleted on |loop_| | 85 // Unretained is safe here only because the object is deleted on |loop_| |
79 // thread. | 86 // thread. |
80 loop->PostTask(FROM_HERE, | 87 loop->PostTask(FROM_HERE, |
81 base::Bind(&StreamTextureProxyImpl::BindOnThread, | 88 base::Bind(&StreamTextureProxyImpl::BindOnThread, |
82 base::Unretained(this), | 89 base::Unretained(this), |
83 stream_id, | 90 stream_id)); |
84 loop)); | |
85 } | 91 } |
86 | 92 |
87 void StreamTextureProxyImpl::BindOnThread( | 93 void StreamTextureProxyImpl::BindOnThread(int32 stream_id) { |
88 int32 stream_id, | |
89 scoped_refptr<base::MessageLoopProxy> loop) { | |
90 DCHECK(!loop_ || (loop == loop_)); | |
91 loop_ = loop; | |
92 host_->BindToCurrentThread(stream_id, this); | 94 host_->BindToCurrentThread(stream_id, this); |
93 } | 95 } |
94 | 96 |
95 void StreamTextureProxyImpl::OnFrameAvailable() { | 97 void StreamTextureProxyImpl::OnFrameAvailable() { |
96 base::AutoLock lock(client_lock_); | 98 base::AutoLock lock(lock_); |
97 if (client_) | 99 if (client_) |
98 client_->DidReceiveFrame(); | 100 client_->DidReceiveFrame(); |
99 } | 101 } |
100 | 102 |
101 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 103 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
102 base::AutoLock lock(client_lock_); | 104 base::AutoLock lock(lock_); |
103 if (client_) | 105 if (client_) |
104 client_->DidUpdateMatrix(matrix); | 106 client_->DidUpdateMatrix(matrix); |
105 } | 107 } |
106 | 108 |
107 } // namespace | 109 } // namespace |
108 | 110 |
109 // static | 111 // static |
110 scoped_refptr<StreamTextureFactoryImpl> StreamTextureFactoryImpl::Create( | 112 scoped_refptr<StreamTextureFactoryImpl> StreamTextureFactoryImpl::Create( |
111 const scoped_refptr<cc::ContextProvider>& context_provider, | 113 const scoped_refptr<cc::ContextProvider>& context_provider, |
112 GpuChannelHost* channel, | 114 GpuChannelHost* channel, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 167 |
166 void StreamTextureFactoryImpl::AddObserver( | 168 void StreamTextureFactoryImpl::AddObserver( |
167 StreamTextureFactoryContextObserver* obs) { | 169 StreamTextureFactoryContextObserver* obs) { |
168 } | 170 } |
169 | 171 |
170 void StreamTextureFactoryImpl::RemoveObserver( | 172 void StreamTextureFactoryImpl::RemoveObserver( |
171 StreamTextureFactoryContextObserver* obs) { | 173 StreamTextureFactoryContextObserver* obs) { |
172 } | 174 } |
173 | 175 |
174 } // namespace content | 176 } // namespace content |
OLD | NEW |