|
4 | 4 | *
|
5 | 5 | * options.cpp - common program options helpers
|
6 | 6 | */
|
| 7 | +#include <fcntl.h> |
| 8 | +#include <linux/v4l2-controls.h> |
| 9 | +#include <linux/videodev2.h> |
| 10 | +#include <sys/ioctl.h> |
7 | 11 | #include <algorithm>
|
8 | 12 | #include <iomanip>
|
9 | 13 | #include <iostream>
|
@@ -47,6 +51,16 @@ std::string Mode::ToString() const
|
47 | 51 | }
|
48 | 52 | }
|
49 | 53 |
|
| 54 | +static int xioctl(int fd, unsigned long ctl, void *arg) |
| 55 | +{ |
| 56 | + int ret, num_tries = 10; |
| 57 | + do |
| 58 | + { |
| 59 | + ret = ioctl(fd, ctl, arg); |
| 60 | + } while (ret == -1 && errno == EINTR && num_tries-- > 0); |
| 61 | + return ret; |
| 62 | +} |
| 63 | + |
50 | 64 | bool Options::Parse(int argc, char *argv[])
|
51 | 65 | {
|
52 | 66 | using namespace boost::program_options;
|
@@ -79,6 +93,27 @@ bool Options::Parse(int argc, char *argv[])
|
79 | 93 | else if (!lens_position_.empty())
|
80 | 94 | throw std::runtime_error("Invalid lens position: " + lens_position_);
|
81 | 95 |
|
| 96 | + // HDR control. Set this before opening or listing any cameras. |
| 97 | + // Currently this does not exist in libcamera, so go directly to V4L2 |
| 98 | + // XXX it's not obvious which v4l2-subdev to use for which camera! |
| 99 | + { |
| 100 | + bool ok = false; |
| 101 | + for (int i = 0; i < 4 && !ok; i++) |
| 102 | + { |
| 103 | + std::string dev("/dev/v4l-subdev"); |
| 104 | + dev += (char)('0' + i); |
| 105 | + int fd = open(dev.c_str(), O_RDWR, 0); |
| 106 | + if (fd < 0) |
| 107 | + continue; |
| 108 | + |
| 109 | + v4l2_control ctrl { V4L2_CID_WIDE_DYNAMIC_RANGE, hdr }; |
| 110 | + ok = !xioctl(fd, VIDIOC_S_CTRL, &ctrl); |
| 111 | + close(fd); |
| 112 | + } |
| 113 | + if (hdr && !ok) |
| 114 | + LOG_ERROR("WARNING: Unable to set HDR mode"); |
| 115 | + } |
| 116 | + |
82 | 117 | // Set the verbosity
|
83 | 118 | LibcameraApp::verbosity = verbose;
|
84 | 119 |
|
@@ -349,6 +384,8 @@ void Options::Print() const
|
349 | 384 | << afWindow_height << std::endl;
|
350 | 385 | if (!lens_position_.empty())
|
351 | 386 | std::cerr << " lens-position: " << lens_position_ << std::endl;
|
| 387 | + if (hdr) |
| 388 | + std::cerr << " hdr: enabled" << hdr << std::endl; |
352 | 389 | std::cerr << " mode: " << mode.ToString() << std::endl;
|
353 | 390 | std::cerr << " viewfinder-mode: " << viewfinder_mode.ToString() << std::endl;
|
354 | 391 | if (buffer_count > 0)
|
|
0 commit comments