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

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

Issue 2556983002: Fix SetStreamTextureSize crash (Closed)
Patch Set: Style changes Created 4 years 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 void StreamTextureWrapperImpl::UpdateTextureSize(const gfx::Size& new_size) { 122 void StreamTextureWrapperImpl::UpdateTextureSize(const gfx::Size& new_size) {
123 DVLOG(2) << __func__; 123 DVLOG(2) << __func__;
124 124
125 if (!main_task_runner_->BelongsToCurrentThread()) { 125 if (!main_task_runner_->BelongsToCurrentThread()) {
126 main_task_runner_->PostTask( 126 main_task_runner_->PostTask(
127 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::UpdateTextureSize, 127 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::UpdateTextureSize,
128 weak_factory_.GetWeakPtr(), new_size)); 128 weak_factory_.GetWeakPtr(), new_size));
129 return; 129 return;
130 } 130 }
131 131
132 // InitializeOnMainThread() hasn't completed, or failed.
watk 2016/12/07 01:48:11 nit: "hasn't completed" makes it sounds like it ru
tguilbert 2016/12/07 19:23:55 Done.
133 if (!stream_texture_proxy_)
134 return;
135
132 if (natural_size_ == new_size) 136 if (natural_size_ == new_size)
133 return; 137 return;
134 138
135 natural_size_ = new_size; 139 natural_size_ = new_size;
136 140
137 ReallocateVideoFrame(new_size); 141 ReallocateVideoFrame(new_size);
138 stream_texture_proxy_->SetStreamTextureSize(new_size); 142 stream_texture_proxy_->SetStreamTextureSize(new_size);
139 } 143 }
140 144
141 void StreamTextureWrapperImpl::Initialize( 145 void StreamTextureWrapperImpl::Initialize(
142 const base::Closure& received_frame_cb, 146 const base::Closure& received_frame_cb,
143 const gfx::Size& natural_size, 147 const gfx::Size& natural_size,
144 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, 148 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
145 const base::Closure& init_cb) { 149 const StreamTextureWrapperInitCB& init_cb) {
146 DVLOG(2) << __func__; 150 DVLOG(2) << __func__;
147 151
148 compositor_task_runner_ = compositor_task_runner; 152 compositor_task_runner_ = compositor_task_runner;
149 natural_size_ = natural_size; 153 natural_size_ = natural_size;
150 154
151 main_task_runner_->PostTask( 155 main_task_runner_->PostTask(
152 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::InitializeOnMainThread, 156 FROM_HERE, base::Bind(&StreamTextureWrapperImpl::InitializeOnMainThread,
153 weak_factory_.GetWeakPtr(), received_frame_cb, 157 weak_factory_.GetWeakPtr(), received_frame_cb,
154 media::BindToCurrentLoop(init_cb))); 158 media::BindToCurrentLoop(init_cb)));
155 } 159 }
156 160
157 void StreamTextureWrapperImpl::InitializeOnMainThread( 161 void StreamTextureWrapperImpl::InitializeOnMainThread(
158 const base::Closure& received_frame_cb, 162 const base::Closure& received_frame_cb,
159 const base::Closure& init_cb) { 163 const StreamTextureWrapperInitCB& init_cb) {
160 DCHECK(main_task_runner_->BelongsToCurrentThread()); 164 DCHECK(main_task_runner_->BelongsToCurrentThread());
161 DVLOG(2) << __func__; 165 DVLOG(2) << __func__;
162 166
163 stream_texture_proxy_ = factory_->CreateProxy( 167 stream_texture_proxy_ = factory_->CreateProxy(
164 kGLTextureExternalOES, &texture_id_, &texture_mailbox_); 168 kGLTextureExternalOES, &texture_id_, &texture_mailbox_);
165 if (!stream_texture_proxy_) 169 if (!stream_texture_proxy_) {
170 init_cb.Run(false);
166 return; 171 return;
172 }
167 173
168 ReallocateVideoFrame(natural_size_); 174 ReallocateVideoFrame(natural_size_);
169 175
170 stream_texture_proxy_->BindToTaskRunner(received_frame_cb, 176 stream_texture_proxy_->BindToTaskRunner(received_frame_cb,
171 compositor_task_runner_); 177 compositor_task_runner_);
172 178
173 // TODO(tguilbert): Register the surface properly. See crbug.com/627658.
174
175 // |init_cb| is bound to the thread that originally called Initialize(). 179 // |init_cb| is bound to the thread that originally called Initialize().
watk 2016/12/07 01:48:11 nit: comment feels out of place now that you're ca
tguilbert 2016/12/07 19:23:55 Done.
176 init_cb.Run(); 180 init_cb.Run(true);
177 } 181 }
178 182
179 void StreamTextureWrapperImpl::Destroy() { 183 void StreamTextureWrapperImpl::Destroy() {
180 // Note: StreamTextureProxy stop calling back the provided frame received 184 // Note: StreamTextureProxy stop calling back the provided frame received
181 // callback immediately, and delete itself on the right thread. 185 // callback immediately, and delete itself on the right thread.
182 stream_texture_proxy_.reset(); 186 stream_texture_proxy_.reset();
183 187
184 if (!main_task_runner_->BelongsToCurrentThread()) { 188 if (!main_task_runner_->BelongsToCurrentThread()) {
185 // base::Unretained is safe here because this function is the only one that 189 // base::Unretained is safe here because this function is the only one that
186 // can can call delete. 190 // can can call delete.
187 main_task_runner_->PostTask( 191 main_task_runner_->PostTask(
188 FROM_HERE, 192 FROM_HERE,
189 base::Bind(&StreamTextureWrapperImpl::Destroy, base::Unretained(this))); 193 base::Bind(&StreamTextureWrapperImpl::Destroy, base::Unretained(this)));
190 return; 194 return;
191 } 195 }
192 196
193 delete this; 197 delete this;
194 } 198 }
195 199
196 } // namespace content 200 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698