mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-21 03:15:06 +03:00
qcam: Make use of StreamKeyValueParser
Use the StreamKeyValueParser helper to parse stream configuration from the command line. This extends qcam to accept role hints and pixel format in addition to a size. Currently only one viewfinder stream is supported, add a check to keep this behavior. Going forward this restriction will be lifted to support more then one stream. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
18cfea19dc
commit
d29c321357
4 changed files with 28 additions and 27 deletions
|
@ -13,8 +13,9 @@
|
||||||
|
|
||||||
#include <libcamera/camera_manager.h>
|
#include <libcamera/camera_manager.h>
|
||||||
|
|
||||||
#include "main_window.h"
|
|
||||||
#include "../cam/options.h"
|
#include "../cam/options.h"
|
||||||
|
#include "../cam/stream_options.h"
|
||||||
|
#include "main_window.h"
|
||||||
|
|
||||||
void signalHandler(int signal)
|
void signalHandler(int signal)
|
||||||
{
|
{
|
||||||
|
@ -24,11 +25,7 @@ void signalHandler(int signal)
|
||||||
|
|
||||||
OptionsParser::Options parseOptions(int argc, char *argv[])
|
OptionsParser::Options parseOptions(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
KeyValueParser sizeParser;
|
StreamKeyValueParser streamKeyValue;
|
||||||
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,
|
||||||
|
@ -36,8 +33,8 @@ OptionsParser::Options parseOptions(int argc, char *argv[])
|
||||||
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",
|
parser.addOption(OptStream, &streamKeyValue,
|
||||||
"size", true);
|
"Set configuration of a camera stream", "stream", true);
|
||||||
|
|
||||||
OptionsParser::Options options = parser.parse(argc, argv);
|
OptionsParser::Options options = parser.parse(argc, argv);
|
||||||
if (options.isSet(OptHelp))
|
if (options.isSet(OptHelp))
|
||||||
|
|
|
@ -280,29 +280,25 @@ void MainWindow::toggleCapture(bool start)
|
||||||
*/
|
*/
|
||||||
int MainWindow::startCapture()
|
int MainWindow::startCapture()
|
||||||
{
|
{
|
||||||
|
StreamRoles roles = StreamKeyValueParser::roles(options_[OptStream]);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Verify roles are supported. */
|
||||||
|
if (roles.size() != 1) {
|
||||||
|
qCritical() << "Only one stream supported";
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (roles[0] != StreamRole::Viewfinder) {
|
||||||
|
qCritical() << "Only viewfinder supported";
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Configure the camera. */
|
/* Configure the camera. */
|
||||||
config_ = camera_->generateConfiguration({ StreamRole::Viewfinder });
|
config_ = camera_->generateConfiguration(roles);
|
||||||
|
|
||||||
StreamConfiguration &cfg = config_->at(0);
|
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"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Use a format supported by the viewfinder if available. */
|
/* Use a format supported by the viewfinder if available. */
|
||||||
std::vector<PixelFormat> formats = cfg.formats().pixelformats();
|
std::vector<PixelFormat> formats = cfg.formats().pixelformats();
|
||||||
for (const PixelFormat &format : viewfinder_->nativeFormats()) {
|
for (const PixelFormat &format : viewfinder_->nativeFormats()) {
|
||||||
|
@ -316,6 +312,13 @@ int MainWindow::startCapture()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allow user to override configuration. */
|
||||||
|
if (StreamKeyValueParser::updateConfiguration(config_.get(),
|
||||||
|
options_[OptStream])) {
|
||||||
|
qWarning() << "Failed to update configuration";
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
CameraConfiguration::Status validation = config_->validate();
|
CameraConfiguration::Status validation = config_->validate();
|
||||||
if (validation == CameraConfiguration::Invalid) {
|
if (validation == CameraConfiguration::Invalid) {
|
||||||
qWarning() << "Failed to create valid camera configuration";
|
qWarning() << "Failed to create valid camera configuration";
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include <libcamera/framebuffer_allocator.h>
|
#include <libcamera/framebuffer_allocator.h>
|
||||||
#include <libcamera/stream.h>
|
#include <libcamera/stream.h>
|
||||||
|
|
||||||
#include "../cam/options.h"
|
#include "../cam/stream_options.h"
|
||||||
#include "viewfinder.h"
|
#include "viewfinder.h"
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
@ -34,7 +34,7 @@ class QComboBox;
|
||||||
enum {
|
enum {
|
||||||
OptCamera = 'c',
|
OptCamera = 'c',
|
||||||
OptHelp = 'h',
|
OptHelp = 'h',
|
||||||
OptSize = 's',
|
OptStream = 's',
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
|
|
|
@ -3,6 +3,7 @@ qcam_sources = files([
|
||||||
'main.cpp',
|
'main.cpp',
|
||||||
'main_window.cpp',
|
'main_window.cpp',
|
||||||
'../cam/options.cpp',
|
'../cam/options.cpp',
|
||||||
|
'../cam/stream_options.cpp',
|
||||||
'viewfinder.cpp',
|
'viewfinder.cpp',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue