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

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

Issue 2390783003: Make stream_id internal to StreamTextureHost. (Closed)
Patch Set: Rebasing to TOT. Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_wrapper_impl.h" 5 #include "content/renderer/media/android/stream_texture_wrapper_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "cc/layers/video_frame_provider.h" 8 #include "cc/layers/video_frame_provider.h"
9 #include "gpu/GLES2/gl2extchromium.h" 9 #include "gpu/GLES2/gl2extchromium.h"
10 #include "gpu/command_buffer/client/gles2_interface.h" 10 #include "gpu/command_buffer/client/gles2_interface.h"
(...skipping 15 matching lines...) Expand all
26 gl->ShallowFlushCHROMIUM(); 26 gl->ShallowFlushCHROMIUM();
27 } 27 }
28 } 28 }
29 29
30 namespace content { 30 namespace content {
31 31
32 StreamTextureWrapperImpl::StreamTextureWrapperImpl( 32 StreamTextureWrapperImpl::StreamTextureWrapperImpl(
33 scoped_refptr<StreamTextureFactory> factory, 33 scoped_refptr<StreamTextureFactory> factory,
34 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) 34 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner)
35 : texture_id_(0), 35 : texture_id_(0),
36 stream_id_(0),
37 factory_(factory), 36 factory_(factory),
38 main_task_runner_(main_task_runner), 37 main_task_runner_(main_task_runner),
39 weak_factory_(this) {} 38 weak_factory_(this) {}
40 39
41 StreamTextureWrapperImpl::~StreamTextureWrapperImpl() { 40 StreamTextureWrapperImpl::~StreamTextureWrapperImpl() {
42 DCHECK(main_task_runner_->BelongsToCurrentThread()); 41 DCHECK(main_task_runner_->BelongsToCurrentThread());
43 42
44 if (stream_id_) { 43 if (texture_id_) {
45 GLES2Interface* gl = factory_->ContextGL(); 44 GLES2Interface* gl = factory_->ContextGL();
46 gl->DeleteTextures(1, &texture_id_); 45 gl->DeleteTextures(1, &texture_id_);
47 // Flush to ensure that the stream texture gets deleted in a timely fashion. 46 // Flush to ensure that the stream texture gets deleted in a timely fashion.
48 gl->ShallowFlushCHROMIUM(); 47 gl->ShallowFlushCHROMIUM();
48 texture_id_ = 0;
liberato (no reviews please) 2016/10/07 20:01:26 why? (i have a habit of doing this too -- but i ha
sivag 2016/10/10 11:06:52 There is no reason to do it in the destructor. I w
49 } 49 }
50 50
51 SetCurrentFrameInternal(nullptr); 51 SetCurrentFrameInternal(nullptr);
52 } 52 }
53 53
54 media::ScopedStreamTextureWrapper StreamTextureWrapperImpl::Create( 54 media::ScopedStreamTextureWrapper StreamTextureWrapperImpl::Create(
55 scoped_refptr<StreamTextureFactory> factory, 55 scoped_refptr<StreamTextureFactory> factory,
56 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) { 56 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) {
57 return media::ScopedStreamTextureWrapper( 57 return media::ScopedStreamTextureWrapper(
58 new StreamTextureWrapperImpl(factory, main_task_runner)); 58 new StreamTextureWrapperImpl(factory, main_task_runner));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 base::TimeDelta()); 99 base::TimeDelta());
100 100
101 // TODO(tguilbert): Create and pipe the enable_texture_copy_ flag for Webview 101 // TODO(tguilbert): Create and pipe the enable_texture_copy_ flag for Webview
102 // scenarios. See crbug.com/628066. 102 // scenarios. See crbug.com/628066.
103 103
104 SetCurrentFrameInternal(new_frame); 104 SetCurrentFrameInternal(new_frame);
105 } 105 }
106 106
107 void StreamTextureWrapperImpl::ForwardStreamTextureForSurfaceRequest( 107 void StreamTextureWrapperImpl::ForwardStreamTextureForSurfaceRequest(
108 const base::UnguessableToken& request_token) { 108 const base::UnguessableToken& request_token) {
109 return factory_->ForwardStreamTextureForSurfaceRequest(stream_id_, 109 stream_texture_proxy_->ForwardStreamTextureForSurfaceRequest(request_token);
110 request_token);
111 } 110 }
112 111
113 void StreamTextureWrapperImpl::SetCurrentFrameInternal( 112 void StreamTextureWrapperImpl::SetCurrentFrameInternal(
114 const scoped_refptr<media::VideoFrame>& video_frame) { 113 const scoped_refptr<media::VideoFrame>& video_frame) {
115 base::AutoLock auto_lock(current_frame_lock_); 114 base::AutoLock auto_lock(current_frame_lock_);
116 current_frame_ = video_frame; 115 current_frame_ = video_frame;
117 } 116 }
118 117
119 void StreamTextureWrapperImpl::UpdateTextureSize(const gfx::Size& new_size) { 118 void StreamTextureWrapperImpl::UpdateTextureSize(const gfx::Size& new_size) {
120 DVLOG(2) << __FUNCTION__; 119 DVLOG(2) << __FUNCTION__;
121 120
122 if (!main_task_runner_->BelongsToCurrentThread()) { 121 if (!main_task_runner_->BelongsToCurrentThread()) {
123 main_task_runner_->PostTask( 122 main_task_runner_->PostTask(
124 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::UpdateTextureSize, 123 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::UpdateTextureSize,
125 weak_factory_.GetWeakPtr(), new_size)); 124 weak_factory_.GetWeakPtr(), new_size));
126 return; 125 return;
127 } 126 }
128 127
129 if (natural_size_ == new_size) 128 if (natural_size_ == new_size)
130 return; 129 return;
131 130
132 natural_size_ = new_size; 131 natural_size_ = new_size;
133 132
134 ReallocateVideoFrame(new_size); 133 ReallocateVideoFrame(new_size);
135 factory_->SetStreamTextureSize(stream_id_, new_size); 134 stream_texture_proxy_->SetStreamTextureSize(new_size);
136 } 135 }
137 136
138 void StreamTextureWrapperImpl::Initialize( 137 void StreamTextureWrapperImpl::Initialize(
139 const base::Closure& received_frame_cb, 138 const base::Closure& received_frame_cb,
140 const gfx::Size& natural_size, 139 const gfx::Size& natural_size,
141 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, 140 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
142 const base::Closure& init_cb) { 141 const base::Closure& init_cb) {
143 DVLOG(2) << __FUNCTION__; 142 DVLOG(2) << __FUNCTION__;
144 143
145 compositor_task_runner_ = compositor_task_runner; 144 compositor_task_runner_ = compositor_task_runner;
146 natural_size_ = natural_size; 145 natural_size_ = natural_size;
147 146
148 main_task_runner_->PostTask( 147 main_task_runner_->PostTask(
149 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::InitializeOnMainThread, 148 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::InitializeOnMainThread,
150 weak_factory_.GetWeakPtr(), received_frame_cb, 149 weak_factory_.GetWeakPtr(), received_frame_cb,
151 media::BindToCurrentLoop(init_cb))); 150 media::BindToCurrentLoop(init_cb)));
152 } 151 }
153 152
154 void StreamTextureWrapperImpl::InitializeOnMainThread( 153 void StreamTextureWrapperImpl::InitializeOnMainThread(
155 const base::Closure& received_frame_cb, 154 const base::Closure& received_frame_cb,
156 const base::Closure& init_cb) { 155 const base::Closure& init_cb) {
157 DCHECK(main_task_runner_->BelongsToCurrentThread()); 156 DCHECK(main_task_runner_->BelongsToCurrentThread());
158 DVLOG(2) << __FUNCTION__; 157 DVLOG(2) << __FUNCTION__;
159 158
160 stream_texture_proxy_.reset(factory_->CreateProxy()); 159 int32_t route_id = factory_->CreateStreamTexture(
160 kGLTextureExternalOES, &texture_id_, &texture_mailbox_);
161 stream_texture_proxy_.reset(factory_->CreateProxy(route_id));
161 162
162 stream_id_ = factory_->CreateStreamTexture(kGLTextureExternalOES,
163 &texture_id_, &texture_mailbox_);
164 ReallocateVideoFrame(natural_size_); 163 ReallocateVideoFrame(natural_size_);
165 164
166 stream_texture_proxy_->BindToTaskRunner(stream_id_, received_frame_cb, 165 stream_texture_proxy_->BindToTaskRunner(received_frame_cb,
167 compositor_task_runner_); 166 compositor_task_runner_);
168 167
169 // TODO(tguilbert): Register the surface properly. See crbug.com/627658. 168 // TODO(tguilbert): Register the surface properly. See crbug.com/627658.
170 169
171 // |init_cb| is bound to the thread that originally called Initialize(). 170 // |init_cb| is bound to the thread that originally called Initialize().
172 init_cb.Run(); 171 init_cb.Run();
173 } 172 }
174 173
175 void StreamTextureWrapperImpl::Destroy() { 174 void StreamTextureWrapperImpl::Destroy() {
176 // Note: StreamTextureProxy stop calling back the provided frame received 175 // Note: StreamTextureProxy stop calling back the provided frame received
177 // callback immediately, and delete itself on the right thread. 176 // callback immediately, and delete itself on the right thread.
178 stream_texture_proxy_.reset(); 177 stream_texture_proxy_.reset();
179 178
180 if (!main_task_runner_->BelongsToCurrentThread()) { 179 if (!main_task_runner_->BelongsToCurrentThread()) {
181 // base::Unretained is safe here because this function is the only one that 180 // base::Unretained is safe here because this function is the only one that
182 // can can call delete. 181 // can can call delete.
183 main_task_runner_->PostTask( 182 main_task_runner_->PostTask(
184 FROM_HERE, 183 FROM_HERE,
185 base::Bind(&StreamTextureWrapperImpl::Destroy, base::Unretained(this))); 184 base::Bind(&StreamTextureWrapperImpl::Destroy, base::Unretained(this)));
186 return; 185 return;
187 } 186 }
188 187
189 delete this; 188 delete this;
190 } 189 }
191 190
192 } // namespace content 191 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698