libcamera: qcam: Allow specifying sizes on command line
Add a '-s|--size' option to qcam to allow selecting the stream resolution using a command line option. If the sizes are not supported by the camera, they get automatically adjusted and the user notified via an output message. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
fae053307d
commit
a5ebcea8c0
3 changed files with 38 additions and 1 deletions
|
@ -25,12 +25,20 @@ void signalHandler(int signal)
|
||||||
|
|
||||||
OptionsParser::Options parseOptions(int argc, char *argv[])
|
OptionsParser::Options parseOptions(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
KeyValueParser sizeParser;
|
||||||
|
sizeParser.addOption("width", OptionInteger, "Width in pixels",
|
||||||
|
ArgumentRequired);
|
||||||
|
sizeParser.addOption("height", OptionInteger, "Height in pixels",
|
||||||
|
ArgumentRequired);
|
||||||
|
|
||||||
OptionsParser parser;
|
OptionsParser parser;
|
||||||
parser.addOption(OptCamera, OptionString,
|
parser.addOption(OptCamera, OptionString,
|
||||||
"Specify which camera to operate on", "camera",
|
"Specify which camera to operate on", "camera",
|
||||||
ArgumentRequired, "camera");
|
ArgumentRequired, "camera");
|
||||||
parser.addOption(OptHelp, OptionNone, "Display this help message",
|
parser.addOption(OptHelp, OptionNone, "Display this help message",
|
||||||
"help");
|
"help");
|
||||||
|
parser.addOption(OptSize, &sizeParser, "Set the stream size",
|
||||||
|
"size", true);
|
||||||
|
|
||||||
OptionsParser::Options options = parser.parse(argc, argv);
|
OptionsParser::Options options = parser.parse(argc, argv);
|
||||||
if (options.isSet(OptHelp))
|
if (options.isSet(OptHelp))
|
||||||
|
|
|
@ -116,13 +116,41 @@ int MainWindow::startCapture()
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
config_ = camera_->generateConfiguration({ StreamRole::VideoRecording });
|
config_ = camera_->generateConfiguration({ StreamRole::VideoRecording });
|
||||||
|
|
||||||
|
StreamConfiguration &cfg = config_->at(0);
|
||||||
|
if (options_.isSet(OptSize)) {
|
||||||
|
const std::vector<OptionValue> &sizeOptions =
|
||||||
|
options_[OptSize].toArray();
|
||||||
|
|
||||||
|
/* Set desired stream size if requested. */
|
||||||
|
for (const auto &value : sizeOptions) {
|
||||||
|
KeyValueParser::Options opt = value.toKeyValues();
|
||||||
|
|
||||||
|
if (opt.isSet("width"))
|
||||||
|
cfg.size.width = opt["width"];
|
||||||
|
|
||||||
|
if (opt.isSet("height"))
|
||||||
|
cfg.size.height = opt["height"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CameraConfiguration::Status validation = config_->validate();
|
||||||
|
if (validation == CameraConfiguration::Invalid) {
|
||||||
|
std::cerr << "Failed to create valid camera configuration";
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validation == CameraConfiguration::Adjusted) {
|
||||||
|
std::cout << "Stream size adjusted to "
|
||||||
|
<< cfg.size.toString() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
ret = camera_->configure(config_.get());
|
ret = camera_->configure(config_.get());
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
std::cout << "Failed to configure camera" << std::endl;
|
std::cout << "Failed to configure camera" << std::endl;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const StreamConfiguration &cfg = config_->at(0);
|
|
||||||
Stream *stream = cfg.stream();
|
Stream *stream = cfg.stream();
|
||||||
ret = viewfinder_->setFormat(cfg.pixelFormat, cfg.size.width,
|
ret = viewfinder_->setFormat(cfg.pixelFormat, cfg.size.width,
|
||||||
cfg.size.height);
|
cfg.size.height);
|
||||||
|
|
|
@ -27,6 +27,7 @@ class ViewFinder;
|
||||||
enum {
|
enum {
|
||||||
OptCamera = 'c',
|
OptCamera = 'c',
|
||||||
OptHelp = 'h',
|
OptHelp = 'h',
|
||||||
|
OptSize = 's',
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue