summaryrefslogtreecommitdiff
path: root/src/cam/main.cpp
diff options
context:
space:
mode:
authorNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-04-02 00:07:16 +0200
committerNiklas Söderlund <niklas.soderlund@ragnatech.se>2019-04-04 00:21:22 +0200
commit30fe5bde5f31272cdd10ca804a1fd3ce6078bc2f (patch)
tree722b7638849c6608f5c839a11fe316c5b15d9b5b /src/cam/main.cpp
parentd5ca33f6c7b0cd1ca20ec5dc7131aeedf1503080 (diff)
cam: Rework how streams configuration is prepared
In preparation of reworking how a default configuration is retrieved from a camera separate preparation of stream configuration and application into two different functions. Reason for this is that preparation of camera configuration will become more complex. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/cam/main.cpp')
-rw-r--r--src/cam/main.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index e7490c32..b5895fae 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -78,27 +78,27 @@ static int parseOptions(int argc, char *argv[])
return 0;
}
-static int configureStreams(Camera *camera, std::set<Stream *> &streams)
+static int prepareCameraConfig(std::map<Stream *, StreamConfiguration> *config)
{
- KeyValueParser::Options format = options[OptFormat];
- Stream *id = *streams.begin();
-
- std::map<Stream *, StreamConfiguration> config =
- camera->streamConfiguration(streams);
+ std::set<Stream *> streams = camera->streams();
+ *config = camera->streamConfiguration(streams);
+ Stream *stream = config->begin()->first;
if (options.isSet(OptFormat)) {
+ KeyValueParser::Options format = options[OptFormat];
+
if (format.isSet("width"))
- config[id].width = format["width"];
+ (*config)[stream].width = format["width"];
if (format.isSet("height"))
- config[id].height = format["height"];
+ (*config)[stream].height = format["height"];
/* TODO: Translate 4CC string to ID. */
if (format.isSet("pixelformat"))
- config[id].pixelFormat = format["pixelformat"];
+ (*config)[stream].pixelFormat = format["pixelformat"];
}
- return camera->configureStreams(config);
+ return 0;
}
static void requestComplete(Request *request, const std::map<Stream *, Buffer *> &buffers)
@@ -136,18 +136,23 @@ static void requestComplete(Request *request, const std::map<Stream *, Buffer *>
static int capture()
{
+ std::map<Stream *, StreamConfiguration> config;
+ std::vector<Request *> requests;
int ret;
- std::set<Stream *> streams = camera->streams();
- std::vector<Request *> requests;
+ ret = prepareCameraConfig(&config);
+ if (ret) {
+ std::cout << "Failed to prepare camera configuration" << std::endl;
+ return ret;
+ }
- ret = configureStreams(camera.get(), streams);
+ ret = camera->configureStreams(config);
if (ret < 0) {
std::cout << "Failed to configure camera" << std::endl;
return ret;
}
- Stream *stream = *streams.begin();
+ Stream *stream = config.begin()->first;
ret = camera->allocateBuffers();
if (ret) {