diff --git a/cmvr-es/devices/camera/uvc_camera/src/uvc_camera.cpp b/cmvr-es/devices/camera/uvc_camera/src/uvc_camera.cpp index 64463908..bad4499c 100644 --- a/cmvr-es/devices/camera/uvc_camera/src/uvc_camera.cpp +++ b/cmvr-es/devices/camera/uvc_camera/src/uvc_camera.cpp @@ -1178,10 +1178,22 @@ bool UVCCamera::startStreaming() stream_thread_.reset(); } } + + // A recording session may already own the encoder worker. The streaming + // state still has to reflect the new client lease so stopping recording + // does not terminate the worker while clients are consuming frames. + state_.is_streaming = true; //开启流采集线程 if (!stream_thread_) { - state_.is_streaming = true; - stream_thread_ = make_shared(&UVCCamera::streaming_worker_, this); + try { + stream_thread_ = make_shared(&UVCCamera::streaming_worker_, this); + } catch (const std::exception& e) { + state_.is_streaming = stream_count_ > 0; + state_.is_error = true; + state_.error_message = "failed to start streaming worker: " + std::string(e.what()); + CMVR_LOG(ERROR) << "[UVCCamera] (startStreaming): " << state_.error_message; + return false; + } //延时100ms,等待流线程获取图像 std::this_thread::sleep_for(std::chrono::milliseconds(100));