summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/moz-patch-stack/0100.patch
blob: e7fc0e79a8171f8255cf27903df3aa5e8edff408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
From: Andreas Pehrson <apehrson@mozilla.com>
Date: Wed, 26 Apr 2023 19:45:00 +0000
Subject: Bug 1694304 - cherry-pick libwebrtc 28ac56a415.
 r=webrtc-reviewers,jib

Upstream commit: https://webrtc.googlesource.com/src/+/28ac56a415a7513f1ebfb985659bf2012d84df3f
    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}

Differential Revision: https://phabricator.services.mozilla.com/D176507
Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/dabb9e2ec9d3b77e4cc19de0fb98cae4ce88293d
---
 .../test/video_capture_unittest.cc            | 33 +++++++++++++++++++
 .../video_capture/windows/video_capture_ds.cc | 18 +++++-----
 2 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/modules/video_capture/test/video_capture_unittest.cc b/modules/video_capture/test/video_capture_unittest.cc
index 4cf3d5931c..c8af222b57 100644
--- a/modules/video_capture/test/video_capture_unittest.cc
+++ b/modules/video_capture/test/video_capture_unittest.cc
@@ -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());
+}
diff --git a/modules/video_capture/windows/video_capture_ds.cc b/modules/video_capture/windows/video_capture_ds.cc
index 74b31d98be..8695f76245 100644
--- a/modules/video_capture/windows/video_capture_ds.cc
+++ b/modules/video_capture/windows/video_capture_ds.cc
@@ -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;
-- 
2.34.1