Chromium Code Reviews| 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 base::Lock lock_; | |
| 40 cc::VideoFrameProvider::Client* client_; | |
| 40 scoped_refptr<base::MessageLoopProxy> loop_; | 41 scoped_refptr<base::MessageLoopProxy> loop_; |
| 41 | 42 |
| 42 base::Lock client_lock_; | |
| 43 cc::VideoFrameProvider::Client* client_; | |
| 44 | |
| 45 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); | 43 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxyImpl); |
| 46 }; | 44 }; |
| 47 | 45 |
| 48 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) | 46 StreamTextureProxyImpl::StreamTextureProxyImpl(StreamTextureHost* host) |
| 49 : host_(host), client_(NULL) {} | 47 : host_(host), client_(NULL) {} |
| 50 | 48 |
| 51 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} | 49 StreamTextureProxyImpl::~StreamTextureProxyImpl() {} |
| 52 | 50 |
| 53 void StreamTextureProxyImpl::Release() { | 51 void StreamTextureProxyImpl::Release() { |
| 54 // Assumes this is the last reference to this object. So no need to acquire | 52 scoped_refptr<base::MessageLoopProxy> loop; |
|
qinmin
2014/09/18 02:01:30
why do we need this, cannot we use loop_?
if bind
boliu
2014/09/18 02:04:23
I guess you can argue it both ways.
One side is "
| |
| 55 // lock. | 53 { |
| 56 SetClient(NULL); | 54 base::AutoLock lock(lock_); |
| 57 if (!loop_.get() || loop_->BelongsToCurrentThread() || | 55 loop = loop_; |
| 58 !loop_->DeleteSoon(FROM_HERE, this)) { | 56 client_ = NULL; |
| 57 } | |
| 58 if (!loop.get() || loop->BelongsToCurrentThread() || | |
| 59 !loop->DeleteSoon(FROM_HERE, this)) { | |
| 59 delete this; | 60 delete this; |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 void StreamTextureProxyImpl::SetClient(cc::VideoFrameProvider::Client* client) { | |
| 64 base::AutoLock lock(client_lock_); | |
| 65 client_ = client; | |
| 66 } | |
| 67 | |
| 68 void StreamTextureProxyImpl::BindToLoop( | 64 void StreamTextureProxyImpl::BindToLoop( |
| 69 int32 stream_id, | 65 int32 stream_id, |
| 70 cc::VideoFrameProvider::Client* client, | 66 cc::VideoFrameProvider::Client* client, |
| 71 scoped_refptr<base::MessageLoopProxy> loop) { | 67 scoped_refptr<base::MessageLoopProxy> loop) { |
| 72 DCHECK(loop); | 68 DCHECK(loop); |
| 73 SetClient(client); | 69 |
| 70 { | |
| 71 base::AutoLock lock(lock_); | |
| 72 DCHECK(!loop_ || (loop == loop_)); | |
| 73 loop_ = loop; | |
| 74 client_ = client; | |
| 75 } | |
| 76 | |
| 74 if (loop->BelongsToCurrentThread()) { | 77 if (loop->BelongsToCurrentThread()) { |
| 75 BindOnThread(stream_id, loop); | 78 BindOnThread(stream_id); |
| 76 return; | 79 return; |
| 77 } | 80 } |
| 78 // Unretained is safe here only because the object is deleted on |loop_| | 81 // Unretained is safe here only because the object is deleted on |loop_| |
| 79 // thread. | 82 // thread. |
| 80 loop->PostTask(FROM_HERE, | 83 loop->PostTask(FROM_HERE, |
| 81 base::Bind(&StreamTextureProxyImpl::BindOnThread, | 84 base::Bind(&StreamTextureProxyImpl::BindOnThread, |
| 82 base::Unretained(this), | 85 base::Unretained(this), |
| 83 stream_id, | 86 stream_id)); |
| 84 loop)); | |
| 85 } | 87 } |
| 86 | 88 |
| 87 void StreamTextureProxyImpl::BindOnThread( | 89 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); | 90 host_->BindToCurrentThread(stream_id, this); |
| 93 } | 91 } |
| 94 | 92 |
| 95 void StreamTextureProxyImpl::OnFrameAvailable() { | 93 void StreamTextureProxyImpl::OnFrameAvailable() { |
| 96 base::AutoLock lock(client_lock_); | 94 base::AutoLock lock(lock_); |
| 97 if (client_) | 95 if (client_) |
| 98 client_->DidReceiveFrame(); | 96 client_->DidReceiveFrame(); |
| 99 } | 97 } |
| 100 | 98 |
| 101 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { | 99 void StreamTextureProxyImpl::OnMatrixChanged(const float matrix[16]) { |
| 102 base::AutoLock lock(client_lock_); | 100 base::AutoLock lock(lock_); |
| 103 if (client_) | 101 if (client_) |
| 104 client_->DidUpdateMatrix(matrix); | 102 client_->DidUpdateMatrix(matrix); |
| 105 } | 103 } |
| 106 | 104 |
| 107 } // namespace | 105 } // namespace |
| 108 | 106 |
| 109 // static | 107 // static |
| 110 scoped_refptr<StreamTextureFactoryImpl> StreamTextureFactoryImpl::Create( | 108 scoped_refptr<StreamTextureFactoryImpl> StreamTextureFactoryImpl::Create( |
| 111 const scoped_refptr<cc::ContextProvider>& context_provider, | 109 const scoped_refptr<cc::ContextProvider>& context_provider, |
| 112 GpuChannelHost* channel, | 110 GpuChannelHost* channel, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 | 163 |
| 166 void StreamTextureFactoryImpl::AddObserver( | 164 void StreamTextureFactoryImpl::AddObserver( |
| 167 StreamTextureFactoryContextObserver* obs) { | 165 StreamTextureFactoryContextObserver* obs) { |
| 168 } | 166 } |
| 169 | 167 |
| 170 void StreamTextureFactoryImpl::RemoveObserver( | 168 void StreamTextureFactoryImpl::RemoveObserver( |
| 171 StreamTextureFactoryContextObserver* obs) { | 169 StreamTextureFactoryContextObserver* obs) { |
| 172 } | 170 } |
| 173 | 171 |
| 174 } // namespace content | 172 } // namespace content |
| OLD | NEW |