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

Side by Side Diff: content/browser/renderer_host/media/video_capture_device_impl.cc

Issue 130253002: Attempt to fixed crash on stop mirroring by stopping render thread on a worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed miu's comments Created 6 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/renderer_host/media/video_capture_device_impl.h" 5 #include "content/browser/renderer_host/media/video_capture_device_impl.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_forward.h" 9 #include "base/callback_forward.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 16 matching lines...) Expand all
27 #include "media/video/capture/video_capture_types.h" 27 #include "media/video/capture/video_capture_types.h"
28 #include "ui/gfx/rect.h" 28 #include "ui/gfx/rect.h"
29 29
30 namespace content { 30 namespace content {
31 31
32 namespace { 32 namespace {
33 33
34 void DeleteCaptureMachineOnUIThread( 34 void DeleteCaptureMachineOnUIThread(
35 scoped_ptr<VideoCaptureMachine> capture_machine) { 35 scoped_ptr<VideoCaptureMachine> capture_machine) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 if (capture_machine) { 37
38 capture_machine->Stop(); 38 capture_machine.reset();
39 capture_machine.reset();
40 }
41 } 39 }
42 40
43 } // namespace 41 } // namespace
44 42
45 ThreadSafeCaptureOracle::ThreadSafeCaptureOracle( 43 ThreadSafeCaptureOracle::ThreadSafeCaptureOracle(
46 scoped_ptr<media::VideoCaptureDevice::Client> client, 44 scoped_ptr<media::VideoCaptureDevice::Client> client,
47 scoped_ptr<VideoCaptureOracle> oracle, 45 scoped_ptr<VideoCaptureOracle> oracle,
48 const media::VideoCaptureParams& params) 46 const media::VideoCaptureParams& params)
49 : client_(client.Pass()), 47 : client_(client.Pass()),
50 oracle_(oracle.Pass()), 48 oracle_(oracle.Pass()),
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 238
241 oracle_proxy_->Stop(); 239 oracle_proxy_->Stop();
242 oracle_proxy_ = NULL; 240 oracle_proxy_ = NULL;
243 241
244 TransitionStateTo(kIdle); 242 TransitionStateTo(kIdle);
245 243
246 // Stops the capture machine asynchronously. 244 // Stops the capture machine asynchronously.
247 BrowserThread::PostTask( 245 BrowserThread::PostTask(
248 BrowserThread::UI, FROM_HERE, base::Bind( 246 BrowserThread::UI, FROM_HERE, base::Bind(
249 &VideoCaptureMachine::Stop, 247 &VideoCaptureMachine::Stop,
250 base::Unretained(capture_machine_.get()))); 248 base::Unretained(capture_machine_.get()),
249 base::Bind(&base::DoNothing)));
251 } 250 }
252 251
253 void VideoCaptureDeviceImpl::CaptureStarted(bool success) { 252 void VideoCaptureDeviceImpl::CaptureStarted(bool success) {
254 DCHECK(thread_checker_.CalledOnValidThread()); 253 DCHECK(thread_checker_.CalledOnValidThread());
255 if (!success) { 254 if (!success) {
256 DVLOG(1) << "Failed to start capture machine."; 255 DVLOG(1) << "Failed to start capture machine.";
257 Error(); 256 Error();
258 } 257 }
259 } 258 }
260 259
261 VideoCaptureDeviceImpl::VideoCaptureDeviceImpl( 260 VideoCaptureDeviceImpl::VideoCaptureDeviceImpl(
262 scoped_ptr<VideoCaptureMachine> capture_machine) 261 scoped_ptr<VideoCaptureMachine> capture_machine)
263 : state_(kIdle), 262 : state_(kIdle),
264 capture_machine_(capture_machine.Pass()) {} 263 capture_machine_(capture_machine.Pass()) {}
265 264
266 VideoCaptureDeviceImpl::~VideoCaptureDeviceImpl() { 265 VideoCaptureDeviceImpl::~VideoCaptureDeviceImpl() {
267 // If capture_machine is not NULL, then we need to return to the UI thread to 266 // If capture_machine is not NULL, then we need to return to the UI thread to
268 // safely stop the capture machine. 267 // safely stop the capture machine.
269 if (capture_machine_) { 268 if (capture_machine_) {
269 VideoCaptureMachine* capture_machine_ptr = capture_machine_.get();
270 BrowserThread::PostTask( 270 BrowserThread::PostTask(
271 BrowserThread::UI, FROM_HERE, base::Bind( 271 BrowserThread::UI, FROM_HERE,
272 &DeleteCaptureMachineOnUIThread, base::Passed(&capture_machine_))); 272 base::Bind(&VideoCaptureMachine::Stop,
273 base::Unretained(capture_machine_ptr),
274 base::Bind(&DeleteCaptureMachineOnUIThread,
275 base::Passed(&capture_machine_))));
273 } 276 }
274 DVLOG(1) << "VideoCaptureDeviceImpl@" << this << " destroying."; 277 DVLOG(1) << "VideoCaptureDeviceImpl@" << this << " destroying.";
275 } 278 }
276 279
277 void VideoCaptureDeviceImpl::TransitionStateTo(State next_state) { 280 void VideoCaptureDeviceImpl::TransitionStateTo(State next_state) {
278 DCHECK(thread_checker_.CalledOnValidThread()); 281 DCHECK(thread_checker_.CalledOnValidThread());
279 282
280 #ifndef NDEBUG 283 #ifndef NDEBUG
281 static const char* kStateNames[] = { 284 static const char* kStateNames[] = {
282 "Idle", "Allocated", "Capturing", "Error" 285 "Idle", "Allocated", "Capturing", "Error"
(...skipping 12 matching lines...) Expand all
295 return; 298 return;
296 299
297 if (oracle_proxy_) 300 if (oracle_proxy_)
298 oracle_proxy_->ReportError(); 301 oracle_proxy_->ReportError();
299 302
300 StopAndDeAllocate(); 303 StopAndDeAllocate();
301 TransitionStateTo(kError); 304 TransitionStateTo(kError);
302 } 305 }
303 306
304 } // namespace content 307 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698