From b93f69a51a392f840def4bfffeb93e75082413c2 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Wed, 17 May 2023 13:52:47 +0200 Subject: [PATCH] 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 Reviewed-by: Ilya Nikolaevskiy Commit-Queue: Ilya Nikolaevskiy Cr-Commit-Position: refs/heads/main@{#40194} --- .../video_capture/linux/video_capture_v4l2.cc | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/video_capture/linux/video_capture_v4l2.cc b/modules/video_capture/linux/video_capture_v4l2.cc index 3521e7a21a..bb543a583f 100644 --- a/modules/video_capture/linux/video_capture_v4l2.cc +++ b/modules/video_capture/linux/video_capture_v4l2.cc @@ -268,6 +268,16 @@ int32_t VideoCaptureModuleV4L2::StartCapture( 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 @@ int32_t VideoCaptureModuleV4L2::StartCapture( "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; }