MCPcopy Create free account
hub / github.com/TzuHuanTai/RaspberryPi-WebRTC / ParseDevice

Method ParseDevice

src/parser.cpp:397–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395}
396
397void Parser::ParseDevice(Args &args) {
398 size_t pos = args.camera.find(':');
399 if (pos == std::string::npos) {
400 throw std::runtime_error("Invalid camera string: " + args.camera +
401 ". Expected format: libcamera:<id> or v4l2:<id>");
402 }
403
404 std::string prefix = args.camera.substr(0, pos);
405 std::string id = args.camera.substr(pos + 1);
406
407 try {
408 args.camera_id = std::stoi(id);
409 } catch (const std::exception &e) {
410 throw std::runtime_error("Invalid camera ID: " + id);
411 }
412
413 if (prefix == "libcamera") {
414#if defined(USE_LIBCAMERA_CAPTURE)
415 args.use_libcamera = true;
416 args.format = V4L2_PIX_FMT_YUV420;
417 INFO_PRINT("Using libcamera, ID: %d", args.camera_id);
418#elif defined(JETSON_PLATFORM)
419 throw std::runtime_error("Jetson does not support libcamera. Use v4l2:<id> instead.");
420#else
421 throw std::runtime_error("libcamera is not supported on this platform.");
422#endif
423
424 } else if (prefix == "libargus") {
425#if defined(USE_LIBARGUS_CAPTURE)
426 args.use_libargus = true;
427 args.format = V4L2_PIX_FMT_YUV420;
428#elif defined(RPI_PLATFORM)
429 throw std::runtime_error("Raspberry Pi does not support libargus. Use v4l2:<id> instead.");
430#else
431 throw std::runtime_error("libargus is not supported on this platform.");
432#endif
433 } else if (prefix == "v4l2") {
434 args.format = ParseEnum(v4l2_fmt_table, args.v4l2_format);
435 INFO_PRINT("Using V4L2, ID: %d", args.camera_id);
436 INFO_PRINT("V4L2 format: %s", args.v4l2_format.c_str());
437
438 } else {
439 throw std::runtime_error("Unknown camera type: " + prefix +
440 ". Expected 'libcamera', 'libargus' or 'v4l2'");
441 }
442}

Callers

nothing calls this directly

Calls 1

ParseEnumFunction · 0.85

Tested by

no test coverage detected