diff --git a/src/args.h b/src/args.h index ed0448b..e77ce32 100644 --- a/src/args.h +++ b/src/args.h @@ -8,8 +8,6 @@ #include #include -#include - enum RecordMode { Background = 0, OnDemand = 1, @@ -20,6 +18,12 @@ enum RecordType { Snapshot = 1, }; +enum class CameraSource { + LibCamera, + LibArgus, + V4L2, +}; + template struct TimeVal { TimeVal() : value(0) {} @@ -60,16 +64,17 @@ template struct TimeVal { struct Args { // video input int num_streams = 1; - int camera_id = 0; int fps = 30; int width = 640; int height = 480; int rotation = 0; - bool use_libargus = false; - bool use_libcamera = false; - uint32_t format = V4L2_PIX_FMT_MJPEG; + + CameraSource camera_source = CameraSource::LibCamera; + uint32_t format = 0; + uint32_t camera_id = 0; std::string camera = "libcamera:0"; - std::string v4l2_format = "mjpeg"; + std::string v4l2_format = "i420"; + std::string alias = ""; // per-camera alias for recording subdirectory prefix // sub stream for multiple resolution capture int sub_width = 0; diff --git a/src/parser.cpp b/src/parser.cpp index 5578c21..36fddc7 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -412,7 +412,7 @@ void Parser::ParseDevice(Args &args) { if (prefix == "libcamera") { #if defined(USE_LIBCAMERA_CAPTURE) - args.use_libcamera = true; + args.camera_source = CameraSource::LibCamera; args.format = V4L2_PIX_FMT_YUV420; INFO_PRINT("Using libcamera, ID: %d", args.camera_id); #elif defined(JETSON_PLATFORM) @@ -423,7 +423,7 @@ void Parser::ParseDevice(Args &args) { } else if (prefix == "libargus") { #if defined(USE_LIBARGUS_CAPTURE) - args.use_libargus = true; + args.camera_source = CameraSource::LibArgus; args.format = V4L2_PIX_FMT_YUV420; #elif defined(RPI_PLATFORM) throw std::runtime_error("Raspberry Pi does not support libargus. Use v4l2: instead."); @@ -431,6 +431,7 @@ void Parser::ParseDevice(Args &args) { throw std::runtime_error("libargus is not supported on this platform."); #endif } else if (prefix == "v4l2") { + args.camera_source = CameraSource::V4L2; args.format = ParseEnum(v4l2_fmt_table, args.v4l2_format); INFO_PRINT("Using V4L2, ID: %d", args.camera_id); INFO_PRINT("V4L2 format: %s", args.v4l2_format.c_str()); diff --git a/src/rtc/conductor.cpp b/src/rtc/conductor.cpp index 10593b8..9e486ee 100644 --- a/src/rtc/conductor.cpp +++ b/src/rtc/conductor.cpp @@ -91,19 +91,18 @@ void Conductor::InitializeTracks() { if (!video_track_ && !args.camera.empty()) { video_capture_source_ = ([this]() -> std::shared_ptr { - if (!args.use_libcamera && !args.use_libargus) { - INFO_PRINT("Use v4l2 capturer."); + if (args.camera_source == CameraSource::V4L2) { + INFO_PRINT("Camera: Use v4l2 capturer."); return V4L2Capturer::Create(args); } #if defined(USE_LIBCAMERA_CAPTURE) - else if (args.use_libcamera) { - INFO_PRINT("Use libcamera capturer."); + else if (args.camera_source == CameraSource::LibCamera) { + INFO_PRINT("Camera: Use libcamera capturer."); return LibcameraCapturer::Create(args); } #elif defined(USE_LIBARGUS_CAPTURE) - else if (args.use_libargus) { - INFO_PRINT("Use libargus capturer."); - // return LibargusBufferCapturer::Create(args); + else if (args.camera_source == CameraSource::LibArgus) { + INFO_PRINT("Camera: Use libargus capturer."); return LibargusEglCapturer::Create(args); } #endif @@ -383,8 +382,8 @@ void Conductor::ControlCamera(std::shared_ptr datachannel, DEBUG_PRINT("parse meta cmd message => %d, %d", key, value); try { - if (!args.use_libcamera) { - throw std::runtime_error("Setting camera options only valid with libcamera."); + if (!video_capture_source_) { + throw std::runtime_error("No camera available."); } if (!video_capture_source_->SetControls(key, value)) { ERROR_PRINT("Failed to set key: %d to value: %d", key, value);