From patchwork Fri Jan 25 15:33:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 386 X-Patchwork-Delegate: niklas.soderlund@ragnatech.se Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 218CF60C9D for ; Fri, 25 Jan 2019 16:33:55 +0100 (CET) X-Halon-ID: 9ee6f09a-20b6-11e9-874f-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id 9ee6f09a-20b6-11e9-874f-005056917f90; Fri, 25 Jan 2019 16:33:53 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 25 Jan 2019 16:33:40 +0100 Message-Id: <20190125153340.2744-8-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190125153340.2744-1-niklas.soderlund@ragnatech.se> References: <20190125153340.2744-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 7/7] cam: add option to statically configure a pipeline X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jan 2019 15:33:56 -0000 Add a option to statically configure the first stream of a camera to a fixed resolution. This should obviously be improved in the future but for now serves as a good exercise for the Camera API towards an application. Signed-off-by: Niklas Söderlund --- src/cam/main.cpp | 62 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index cb98d302dcf30331..b8c05d9079be3cb3 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -20,7 +20,8 @@ using namespace libcamera; OptionsParser::Options options; enum { - OptCamera = 'c', + OptCamera = 'C', + OptFormat = 'f', OptHelp = 'h', OptList = 'l', }; @@ -40,6 +41,7 @@ static int parseOptions(int argc, char *argv[]) parser.addOption(OptCamera, "Specify which camera to operate on", "camera", OptionsParser::ArgumentRequired, "camera"); + parser.addOption(OptFormat, "Configure the first stream to 640x480", "format"); parser.addOption(OptHelp, "Display this help message", "help"); parser.addOption(OptList, "List all cameras", "list"); @@ -64,6 +66,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; CameraManager *cm = CameraManager::instance(); + std::shared_ptr camera; + std::vector streams; ret = cm->start(); if (ret) { @@ -72,31 +76,65 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + loop = new EventLoop(cm->eventDispatcher()); + + struct sigaction sa = {}; + sa.sa_handler = &signalHandler; + sigaction(SIGINT, &sa, nullptr); + if (options.isSet(OptList)) { std::cout << "Available cameras:" << std::endl; - for (const std::shared_ptr &camera : cm->cameras()) - std::cout << "- " << camera->name() << std::endl; + for (const std::shared_ptr &cam : cm->cameras()) + std::cout << "- " << cam->name() << std::endl; } if (options.isSet(OptCamera)) { - std::shared_ptr cam = cm->get(options[OptCamera]); - - if (cam) { - std::cout << "Using camera " << cam->name() << std::endl; - } else { + camera = cm->get(options[OptCamera]); + if (!camera) { std::cout << "Camera " << options[OptCamera] << " not found" << std::endl; + goto out; + } + + streams = camera->streams(); + if (streams.size() != 1) { + std::cout << "Camera have " << streams.size() << + " streams, I only know how to work with 1" << std::endl; + goto out; + } + + if (camera->acquire()) { + std::cout << "Failed to acquire camera" << std::endl; + goto out; } + + std::cout << "Using camera " << camera->name() << std::endl; } - loop = new EventLoop(cm->eventDispatcher()); + if (options.isSet(OptFormat)) { + if (!camera) { + std::cout << "Can't configure stream, no camera selected" << std::endl; + goto out_camera; + } - struct sigaction sa = {}; - sa.sa_handler = &signalHandler; - sigaction(SIGINT, &sa, nullptr); + StreamConfiguration config = StreamConfiguration(streams.front()); + config.setDimension(640, 480); + + std::vector configs; + configs.push_back(&config); + + if (camera->configure(configs)) + std::cout << "Failed to configure camera" << std::endl; + } ret = loop->exec(); +out_camera: + if (camera) { + camera->release(); + camera.reset(); + } +out: delete loop; cm->stop();