Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/args.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <string>
#include <unordered_map>

#include <linux/videodev2.h>

enum RecordMode {
Background = 0,
OnDemand = 1,
Expand All @@ -20,6 +18,12 @@ enum RecordType {
Snapshot = 1,
};

enum class CameraSource {
LibCamera,
LibArgus,
V4L2,
};

template <typename DEFAULT> struct TimeVal {
TimeVal()
: value(0) {}
Expand Down Expand Up @@ -60,16 +64,17 @@ template <typename DEFAULT> 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;
Expand Down
5 changes: 3 additions & 2 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -423,14 +423,15 @@ 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:<id> instead.");
#else
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());
Expand Down
17 changes: 8 additions & 9 deletions src/rtc/conductor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,18 @@ void Conductor::InitializeTracks() {

if (!video_track_ && !args.camera.empty()) {
video_capture_source_ = ([this]() -> std::shared_ptr<VideoCapturer> {
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
Expand Down Expand Up @@ -383,8 +382,8 @@ void Conductor::ControlCamera(std::shared_ptr<RtcChannel> 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);
Expand Down
Loading