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_synchronous_impl
.h" | 5 #include "content/renderer/media/android/stream_texture_factory_synchronous_impl
.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // Protects access to |client_| and |loop_|. | 47 // Protects access to |client_| and |loop_|. |
48 base::Lock lock_; | 48 base::Lock lock_; |
49 cc::VideoFrameProvider::Client* client_; | 49 cc::VideoFrameProvider::Client* client_; |
50 scoped_refptr<base::SingleThreadTaskRunner> loop_; | 50 scoped_refptr<base::SingleThreadTaskRunner> loop_; |
51 | 51 |
52 // Accessed on the |loop_| thread only. | 52 // Accessed on the |loop_| thread only. |
53 base::Closure callback_; | 53 base::Closure callback_; |
54 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> | 54 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> |
55 context_provider_; | 55 context_provider_; |
56 scoped_refptr<gfx::SurfaceTexture> surface_texture_; | 56 scoped_refptr<gfx::SurfaceTexture> surface_texture_; |
57 float current_matrix_[16]; | |
58 bool has_updated_; | |
59 | 57 |
60 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); | 58 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
61 }; | 59 }; |
62 | 60 |
63 StreamTextureProxyImpl::StreamTextureProxyImpl( | 61 StreamTextureProxyImpl::StreamTextureProxyImpl( |
64 StreamTextureFactorySynchronousImpl::ContextProvider* provider) | 62 StreamTextureFactorySynchronousImpl::ContextProvider* provider) |
65 : client_(NULL), context_provider_(provider), has_updated_(false) { | 63 : client_(NULL), context_provider_(provider) { |
66 std::fill(current_matrix_, current_matrix_ + 16, 0); | |
67 } | 64 } |
68 | 65 |
69 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} | 66 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
70 | 67 |
71 void StreamTextureProxyImpl::Release() { | 68 void StreamTextureProxyImpl::Release() { |
72 { | 69 { |
73 // Cannot call into |client_| anymore (from any thread) after returning | 70 // Cannot call into |client_| anymore (from any thread) after returning |
74 // from here. | 71 // from here. |
75 base::AutoLock lock(lock_); | 72 base::AutoLock lock(lock_); |
76 client_ = NULL; | 73 client_ = NULL; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 LOG(ERROR) << "Failed to get SurfaceTexture for stream."; | 112 LOG(ERROR) << "Failed to get SurfaceTexture for stream."; |
116 return; | 113 return; |
117 } | 114 } |
118 | 115 |
119 callback_ = | 116 callback_ = |
120 base::Bind(&StreamTextureProxyImpl::OnFrameAvailable, AsWeakPtr()); | 117 base::Bind(&StreamTextureProxyImpl::OnFrameAvailable, AsWeakPtr()); |
121 surface_texture_->SetFrameAvailableCallback(callback_); | 118 surface_texture_->SetFrameAvailableCallback(callback_); |
122 } | 119 } |
123 | 120 |
124 void StreamTextureProxyImpl::OnFrameAvailable() { | 121 void StreamTextureProxyImpl::OnFrameAvailable() { |
125 // GetTransformMatrix only returns something valid after both is true: | |
126 // - OnFrameAvailable was called | |
127 // - we called UpdateTexImage | |
128 if (has_updated_) { | |
129 float matrix[16]; | |
130 surface_texture_->GetTransformMatrix(matrix); | |
131 | |
132 if (memcmp(current_matrix_, matrix, sizeof(matrix)) != 0) { | |
133 memcpy(current_matrix_, matrix, sizeof(matrix)); | |
134 | |
135 base::AutoLock lock(lock_); | |
136 if (client_) | |
137 client_->DidUpdateMatrix(current_matrix_); | |
138 } | |
139 } | |
140 // OnFrameAvailable being called a second time implies that we called | |
141 // updateTexImage since after we received the first frame. | |
142 has_updated_ = true; | |
143 | |
144 base::AutoLock lock(lock_); | 122 base::AutoLock lock(lock_); |
145 if (client_) | 123 if (client_) |
146 client_->DidReceiveFrame(); | 124 client_->DidReceiveFrame(); |
147 } | 125 } |
148 | 126 |
149 } // namespace | 127 } // namespace |
150 | 128 |
151 // static | 129 // static |
152 scoped_refptr<StreamTextureFactorySynchronousImpl> | 130 scoped_refptr<StreamTextureFactorySynchronousImpl> |
153 StreamTextureFactorySynchronousImpl::Create( | 131 StreamTextureFactorySynchronousImpl::Create( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 201 |
224 void StreamTextureFactorySynchronousImpl::RemoveObserver( | 202 void StreamTextureFactorySynchronousImpl::RemoveObserver( |
225 StreamTextureFactoryContextObserver* obs) { | 203 StreamTextureFactoryContextObserver* obs) { |
226 DCHECK(observers_.find(obs) != observers_.end()); | 204 DCHECK(observers_.find(obs) != observers_.end()); |
227 observers_.erase(obs); | 205 observers_.erase(obs); |
228 if (context_provider_.get()) | 206 if (context_provider_.get()) |
229 context_provider_->RemoveObserver(obs); | 207 context_provider_->RemoveObserver(obs); |
230 } | 208 } |
231 | 209 |
232 } // namespace content | 210 } // namespace content |
OLD | NEW |