0002-add-select-camera-options.patch 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From aec56c70bdc7f037a88deaa4cc84854ec2c961e9 Mon Sep 17 00:00:00 2001
  2. From: sw.multimedia <sw.multimedia@starfivetech.com>
  3. Date: Mon, 22 Nov 2021 10:16:15 +0800
  4. Subject: [PATCH] add select camera options
  5. ---
  6. core/libcamera_app.cpp | 29 +++++++++++++++++++++--------
  7. core/options.hpp | 5 +++++
  8. 2 files changed, 26 insertions(+), 8 deletions(-)
  9. diff --git a/core/libcamera_app.cpp b/core/libcamera_app.cpp
  10. index 3c4d862..22896a7 100644
  11. --- a/core/libcamera_app.cpp
  12. +++ b/core/libcamera_app.cpp
  13. @@ -58,17 +58,30 @@ void LibcameraApp::OpenCamera()
  14. if (camera_manager_->cameras().size() == 0)
  15. throw std::runtime_error("no cameras available");
  16. - std::string const &cam_id = camera_manager_->cameras()[0]->id();
  17. - camera_ = camera_manager_->get(cam_id);
  18. - if (!camera_)
  19. - throw std::runtime_error("failed to find camera " + cam_id);
  20. -
  21. - if (camera_->acquire())
  22. - throw std::runtime_error("failed to acquire camera " + cam_id);
  23. + if (options_->camera_name.length()) {
  24. + char *endptr;
  25. + unsigned long index = strtoul(options_->camera_name.c_str(), &endptr, 10);
  26. + std::cout << "Acquired camera name: " << options_->camera_name << std::endl;
  27. + if (*endptr == '\0' && index > 0 && index <= camera_manager_->cameras().size())
  28. + camera_ = camera_manager_->cameras()[index - 1];
  29. + else
  30. + camera_ = camera_manager_->get(options_->camera_name);
  31. + if (!camera_)
  32. + throw std::runtime_error("failed to find camera " + options_->camera_name);
  33. + if (camera_->acquire())
  34. + throw std::runtime_error("failed to acquire camera " + options_->camera_name);
  35. + } else {
  36. + std::string const &cam_id = camera_manager_->cameras()[0]->id();
  37. + camera_ = camera_manager_->get(cam_id);
  38. + if (!camera_)
  39. + throw std::runtime_error("failed to find camera " + cam_id);
  40. + if (camera_->acquire())
  41. + throw std::runtime_error("failed to acquire camera " + cam_id);
  42. + }
  43. camera_acquired_ = true;
  44. if (options_->verbose)
  45. - std::cout << "Acquired camera " << cam_id << std::endl;
  46. + std::cout << "Acquired camera " << camera_->id() << std::endl;
  47. if (!options_->post_process_file.empty())
  48. post_processor_.Read(options_->post_process_file);
  49. diff --git a/core/options.hpp b/core/options.hpp
  50. index 5c68088..de49beb 100644
  51. --- a/core/options.hpp
  52. +++ b/core/options.hpp
  53. @@ -30,6 +30,8 @@ struct Options
  54. "Displays the build version number")
  55. ("verbose,v", value<bool>(&verbose)->default_value(false)->implicit_value(true),
  56. "Output extra debug and diagnostics")
  57. + ("camera", value<std::string>(&camera_name),
  58. + "Specify which camera to operate on, by id or by index")
  59. ("config,c", value<std::string>(&config_file)->implicit_value("config.txt"),
  60. "Read the options from a file. If no filename is specified, default to config.txt. "
  61. "In case of duplicate options, the ones provided on the command line will be used. "
  62. @@ -115,6 +117,7 @@ struct Options
  63. bool help;
  64. bool version;
  65. bool verbose;
  66. + std::string camera_name;
  67. uint64_t timeout; // in ms
  68. std::string config_file;
  69. std::string output;
  70. @@ -259,12 +262,14 @@ struct Options
  71. {
  72. std::cout << "Options:" << std::endl;
  73. std::cout << " verbose: " << verbose << std::endl;
  74. + std::cout << " camera_name: " << camera_name << std::endl;
  75. if (!config_file.empty())
  76. std::cout << " config file: " << config_file << std::endl;
  77. std::cout << " info_text:" << info_text << std::endl;
  78. std::cout << " timeout: " << timeout << std::endl;
  79. std::cout << " width: " << width << std::endl;
  80. std::cout << " height: " << height << std::endl;
  81. + std::cout << " pixelformat: " << pixelformat << std::endl;
  82. std::cout << " output: " << output << std::endl;
  83. std::cout << " post_process_file: " << post_process_file << std::endl;
  84. std::cout << " rawfull: " << rawfull << std::endl;
  85. --
  86. 2.17.1