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

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

Issue 532993002: work-in-progress patch to fix context lost black video (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more threading fix Created 6 years, 3 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_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 16 matching lines...) Expand all
27 27
28 class StreamTextureProxyImpl 28 class StreamTextureProxyImpl
29 : public StreamTextureProxy, 29 : public StreamTextureProxy,
30 public base::SupportsWeakPtr<StreamTextureProxyImpl> { 30 public base::SupportsWeakPtr<StreamTextureProxyImpl> {
31 public: 31 public:
32 explicit StreamTextureProxyImpl( 32 explicit StreamTextureProxyImpl(
33 StreamTextureFactorySynchronousImpl::ContextProvider* provider); 33 StreamTextureFactorySynchronousImpl::ContextProvider* provider);
34 virtual ~StreamTextureProxyImpl(); 34 virtual ~StreamTextureProxyImpl();
35 35
36 // StreamTextureProxy implementation: 36 // StreamTextureProxy implementation:
37 virtual void BindToCurrentThread(int32 stream_id) OVERRIDE; 37 virtual void BindToLoop(int32 stream_id,
38 virtual void SetClient(cc::VideoFrameProvider::Client* client) OVERRIDE; 38 cc::VideoFrameProvider::Client* client,
39 scoped_refptr<base::MessageLoopProxy> loop) OVERRIDE;
39 virtual void Release() OVERRIDE; 40 virtual void Release() OVERRIDE;
40 41
41 private: 42 private:
43 void SetClient(cc::VideoFrameProvider::Client* client);
44 void BindOnThread(int32 stream_id,
45 cc::VideoFrameProvider::Client* client,
46 scoped_refptr<base::MessageLoopProxy> loop);
42 void OnFrameAvailable(); 47 void OnFrameAvailable();
43 48
44 scoped_refptr<base::MessageLoopProxy> loop_;
45 base::Lock client_lock_; 49 base::Lock client_lock_;
46 cc::VideoFrameProvider::Client* client_; 50 cc::VideoFrameProvider::Client* client_;
51
52 // Accessed on the |loop_| thread only.
53 scoped_refptr<base::MessageLoopProxy> loop_;
47 base::Closure callback_; 54 base::Closure callback_;
48
49 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider> 55 scoped_refptr<StreamTextureFactorySynchronousImpl::ContextProvider>
50 context_provider_; 56 context_provider_;
51 scoped_refptr<gfx::SurfaceTexture> surface_texture_; 57 scoped_refptr<gfx::SurfaceTexture> surface_texture_;
52
53 float current_matrix_[16]; 58 float current_matrix_[16];
54 bool has_updated_; 59 bool has_updated_;
55 60
56 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); 61 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl);
57 }; 62 };
58 63
59 StreamTextureProxyImpl::StreamTextureProxyImpl( 64 StreamTextureProxyImpl::StreamTextureProxyImpl(
60 StreamTextureFactorySynchronousImpl::ContextProvider* provider) 65 StreamTextureFactorySynchronousImpl::ContextProvider* provider)
61 : context_provider_(provider), has_updated_(false) { 66 : client_(NULL), context_provider_(provider), has_updated_(false) {
62 std::fill(current_matrix_, current_matrix_ + 16, 0); 67 std::fill(current_matrix_, current_matrix_ + 16, 0);
63 } 68 }
64 69
65 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} 70 StreamTextureProxyImpl::~StreamTextureProxyImpl() {}
66 71
67 void StreamTextureProxyImpl::Release() { 72 void StreamTextureProxyImpl::Release() {
73 // Assumes this is the last reference to this object. So no need to acquire
74 // lock.
68 SetClient(NULL); 75 SetClient(NULL);
69 if (loop_.get() && !loop_->BelongsToCurrentThread()) 76 if (!loop_.get() || loop_->BelongsToCurrentThread() ||
70 loop_->DeleteSoon(FROM_HERE, this); 77 !loop_->DeleteSoon(FROM_HERE, this)) {
71 else
72 delete this; 78 delete this;
79 }
73 } 80 }
74 81
75 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { 82 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) {
76 base::AutoLock lock(client_lock_); 83 base::AutoLock lock(client_lock_);
77 client_ = client; 84 client_ = client;
78 } 85 }
79 86
80 void StreamTextureProxyImpl::BindToCurrentThread(int stream_id) { 87 void StreamTextureProxyImpl::BindToLoop(
81 loop_ = base::MessageLoopProxy::current(); 88 int32 stream_id,
89 cc::VideoFrameProvider::Client* client,
90 scoped_refptr<base::MessageLoopProxy> loop) {
91
92 if (loop->BelongsToCurrentThread()) {
93 BindOnThread(stream_id, client, loop);
94 return;
95 }
96 // Unretained is safe here only because the object is deleted on |loop_|
97 // thread.
98 loop->PostTask(FROM_HERE,
99 base::Bind(&StreamTextureProxyImpl::BindOnThread,
100 base::Unretained(this),
101 stream_id,
102 client,
103 loop));
104 }
105
106 void StreamTextureProxyImpl::BindOnThread(
107 int32 stream_id,
108 cc::VideoFrameProvider::Client* client,
109 scoped_refptr<base::MessageLoopProxy> loop) {
110 SetClient(client);
111 loop_ = loop;
112
82 surface_texture_ = context_provider_->GetSurfaceTexture(stream_id); 113 surface_texture_ = context_provider_->GetSurfaceTexture(stream_id);
83 if (!surface_texture_) { 114 if (!surface_texture_) {
84 LOG(ERROR) << "Failed to get SurfaceTexture for stream."; 115 LOG(ERROR) << "Failed to get SurfaceTexture for stream.";
85 return; 116 return;
86 } 117 }
87 118
88 callback_ = 119 callback_ =
89 base::Bind(&StreamTextureProxyImpl::OnFrameAvailable, AsWeakPtr()); 120 base::Bind(&StreamTextureProxyImpl::OnFrameAvailable, AsWeakPtr());
90 surface_texture_->SetFrameAvailableCallback(callback_); 121 surface_texture_->SetFrameAvailableCallback(callback_);
91 } 122 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 206
176 void StreamTextureFactorySynchronousImpl::SetStreamTextureSize( 207 void StreamTextureFactorySynchronousImpl::SetStreamTextureSize(
177 int32 stream_id, 208 int32 stream_id,
178 const gfx::Size& size) {} 209 const gfx::Size& size) {}
179 210
180 gpu::gles2::GLES2Interface* StreamTextureFactorySynchronousImpl::ContextGL() { 211 gpu::gles2::GLES2Interface* StreamTextureFactorySynchronousImpl::ContextGL() {
181 DCHECK(context_provider_); 212 DCHECK(context_provider_);
182 return context_provider_->ContextGL(); 213 return context_provider_->ContextGL();
183 } 214 }
184 215
216 void StreamTextureFactorySynchronousImpl::AddObserver(
217 StreamTextureFactoryContextObserver* obs) {
218 context_provider_->AddObserver(obs);
219 }
220
221 void StreamTextureFactorySynchronousImpl::RemoveObserver(
222 StreamTextureFactoryContextObserver* obs) {
223 context_provider_->RemoveObserver(obs);
224 }
225
185 } // namespace content 226 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698