In VideoCaptureDS::Stop() fully stop the device

This makes the device light turn off when stopped.

Bug: webrtc:15109
Change-Id: I1deecbc2463e2e316e01ff1f061ab6b0313c1aa1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/302200
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39953}
This commit is contained in:
Andreas Pehrson 2023-04-20 16:21:36 +02:00 committed by WebRTC LUCI CQ
parent d6e6953ada
commit 28ac56a415
2 changed files with 41 additions and 10 deletions

View File

@ -341,3 +341,36 @@ TEST_F(VideoCaptureTest, DISABLED_TestTwoCameras) {
EXPECT_EQ(0, module2->StopCapture());
EXPECT_EQ(0, module1->StopCapture());
}
#ifdef WEBRTC_MAC
// No VideoCaptureImpl on Mac.
#define MAYBE_ConcurrentAccess DISABLED_ConcurrentAccess
#else
#define MAYBE_ConcurrentAccess ConcurrentAccess
#endif
TEST_F(VideoCaptureTest, MAYBE_ConcurrentAccess) {
TestVideoCaptureCallback capture_observer1;
rtc::scoped_refptr<VideoCaptureModule> module1(
OpenVideoCaptureDevice(0, &capture_observer1));
ASSERT_TRUE(module1.get() != NULL);
VideoCaptureCapability capability;
device_info_->GetCapability(module1->CurrentDeviceName(), 0, capability);
capture_observer1.SetExpectedCapability(capability);
TestVideoCaptureCallback capture_observer2;
rtc::scoped_refptr<VideoCaptureModule> module2(
OpenVideoCaptureDevice(0, &capture_observer2));
ASSERT_TRUE(module2.get() != NULL);
capture_observer2.SetExpectedCapability(capability);
// Starting module1 should work.
ASSERT_NO_FATAL_FAILURE(StartCapture(module1.get(), capability));
EXPECT_TRUE_WAIT(capture_observer1.incoming_frames() >= 5, kTimeOut);
// When module1 is stopped, starting module2 for the same device should work.
EXPECT_EQ(0, module1->StopCapture());
ASSERT_NO_FATAL_FAILURE(StartCapture(module2.get(), capability));
EXPECT_TRUE_WAIT(capture_observer2.incoming_frames() >= 5, kTimeOut);
EXPECT_EQ(0, module2->StopCapture());
}

View File

@ -113,17 +113,9 @@ int32_t VideoCaptureDS::Init(const char* deviceUniqueIdUTF8) {
return -1;
}
// Temporary connect here.
// This is done so that no one else can use the capture device.
if (SetCameraOutput(_requestedCapability) != 0) {
return -1;
}
hr = _mediaControl->Pause();
if (FAILED(hr)) {
RTC_LOG(LS_INFO)
<< "Failed to Pause the Capture device. Is it already occupied? " << hr;
return -1;
}
RTC_LOG(LS_INFO) << "Capture device '" << deviceUniqueIdUTF8
<< "' initialized.";
return 0;
@ -139,7 +131,13 @@ int32_t VideoCaptureDS::StartCapture(const VideoCaptureCapability& capability) {
return -1;
}
}
HRESULT hr = _mediaControl->Run();
HRESULT hr = _mediaControl->Pause();
if (FAILED(hr)) {
RTC_LOG(LS_INFO)
<< "Failed to Pause the Capture device. Is it already occupied? " << hr;
return -1;
}
hr = _mediaControl->Run();
if (FAILED(hr)) {
RTC_LOG(LS_INFO) << "Failed to start the Capture device.";
return -1;
@ -150,7 +148,7 @@ int32_t VideoCaptureDS::StartCapture(const VideoCaptureCapability& capability) {
int32_t VideoCaptureDS::StopCapture() {
MutexLock lock(&api_lock_);
HRESULT hr = _mediaControl->Pause();
HRESULT hr = _mediaControl->StopWhenReady();
if (FAILED(hr)) {
RTC_LOG(LS_INFO) << "Failed to stop the capture graph. " << hr;
return -1;