In VideoCaptureV4L2 create the capture thread last in StartCapture
This makes it possible to add a SequenceChecker guard to _deviceFd that
ensures it is accessed only on the api thread while the capture thread
is not running, and only on the capture thread otherwise.
Bug: webrtc:15181
Change-Id: Ibc414ee973a3c4798e38e9b9a63e3053b95b9599
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/305645
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40194}
diff --git a/modules/video_capture/linux/video_capture_v4l2.cc b/modules/video_capture/linux/video_capture_v4l2.cc
index 3521e7a..bb543a5 100644
--- a/modules/video_capture/linux/video_capture_v4l2.cc
+++ b/modules/video_capture/linux/video_capture_v4l2.cc
@@ -268,6 +268,16 @@
return -1;
}
+ // Needed to start UVC camera - from the uvcview application
+ enum v4l2_buf_type type;
+ type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ if (ioctl(_deviceFd, VIDIOC_STREAMON, &type) == -1) {
+ RTC_LOG(LS_INFO) << "Failed to turn on stream";
+ return -1;
+ }
+
+ _captureStarted = true;
+
// start capture thread;
if (_captureThread.empty()) {
quit_ = false;
@@ -279,16 +289,6 @@
"CaptureThread",
rtc::ThreadAttributes().SetPriority(rtc::ThreadPriority::kHigh));
}
-
- // Needed to start UVC camera - from the uvcview application
- enum v4l2_buf_type type;
- type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- if (ioctl(_deviceFd, VIDIOC_STREAMON, &type) == -1) {
- RTC_LOG(LS_INFO) << "Failed to turn on stream";
- return -1;
- }
-
- _captureStarted = true;
return 0;
}