From 915df4fc308489bddda94cbfe38abba1d3fa4736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Fri, 22 May 2015 09:43:26 +0200 Subject: [PATCH] CaptureManager: Don't stop a capturer at UnregisterVideoCapturer if it did not start in the first place. This fixes a bug where, if the VideoCapturer failed to start under certain circumstances, the capture manager would cause a callback saying that the capturer stopped even though it never started in the first place. A VERIFY check in VideoSource::SetState would then cause a crash since the state was set to kEnded when it was already in state kEnded (SetState only allows being called when the state changes). I only noticed this bug while doing a mistake in a separate CL. Not sure how to reliably reproduce said bug on a working build, but I have previously had camera hardware issues where it couldn't start the camera which resulted in the SetState kEnded -> kEnded crash. Hopefully this will fix that. R=tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/51039004 Cr-Commit-Position: refs/heads/master@{#9259} --- talk/media/base/capturemanager.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/talk/media/base/capturemanager.cc b/talk/media/base/capturemanager.cc index 95612187fa..d3b3f82b55 100644 --- a/talk/media/base/capturemanager.cc +++ b/talk/media/base/capturemanager.cc @@ -375,8 +375,10 @@ void CaptureManager::UnregisterVideoCapturer( // for the CaptureManager it doesn't matter as it will no longer receive any // frames from the VideoCapturer. SignalCapturerStateChange.stop(video_capturer->SignalStateChange); - video_capturer->Stop(); - SignalCapturerStateChange(video_capturer, CS_STOPPED); + if (video_capturer->IsRunning()) { + video_capturer->Stop(); + SignalCapturerStateChange(video_capturer, CS_STOPPED); + } } bool CaptureManager::StartWithBestCaptureFormat(