summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/qcam/main.cpp8
-rw-r--r--src/qcam/main_window.cpp30
-rw-r--r--src/qcam/main_window.h1
3 files changed, 38 insertions, 1 deletions
diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp
index 106b8a16..da942f3d 100644
--- a/src/qcam/main.cpp
+++ b/src/qcam/main.cpp
@@ -25,12 +25,20 @@ void signalHandler(int signal)
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;
parser.addOption(OptCamera, OptionString,
"Specify which camera to operate on", "camera",
ArgumentRequired, "camera");
parser.addOption(OptHelp, OptionNone, "Display this help message",
"help");
+ parser.addOption(OptSize, &sizeParser, "Set the stream size",
+ "size", true);
OptionsParser::Options options = parser.parse(argc, argv);
if (options.isSet(OptHelp))
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 5c26ab8e..dcb653e8 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -116,13 +116,41 @@ int MainWindow::startCapture()
int ret;
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());
if (ret < 0) {
std::cout << "Failed to configure camera" << std::endl;
return ret;
}
- const StreamConfiguration &cfg = config_->at(0);
Stream *stream = cfg.stream();
ret = viewfinder_->setFormat(cfg.pixelFormat, cfg.size.width,
cfg.size.height);
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
index f58cb6a6..b45cbca7 100644
--- a/src/qcam/main_window.h
+++ b/src/qcam/main_window.h
@@ -27,6 +27,7 @@ class ViewFinder;
enum {
OptCamera = 'c',
OptHelp = 'h',
+ OptSize = 's',
};
class MainWindow : public QMainWindow