From patchwork Fri Apr 5 23:59:28 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: 937 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 90261611A7 for ; Sat, 6 Apr 2019 01:59:39 +0200 (CEST) X-Halon-ID: ddff9235-57fe-11e9-8144-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id ddff9235-57fe-11e9-8144-0050569116f7; Sat, 06 Apr 2019 01:59:37 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sat, 6 Apr 2019 01:59:28 +0200 Message-Id: <20190405235929.27987-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190405235929.27987-1-niklas.soderlund@ragnatech.se> References: <20190405235929.27987-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/5] cam: Extend request completion handler to deal with multiple streams 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, 05 Apr 2019 23:59:40 -0000 The completion handler needs to handle all buffers in the request. Solve this by iterating over all buffers in the completed request. The streams are named automatically streamX, where X is the order of how the stream was passed to configureStream(). Signed-off-by: Niklas Söderlund --- src/cam/main.cpp | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index da05612b1c347b31..da5ca3402ce1a823 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -23,6 +23,7 @@ using namespace libcamera; OptionsParser::Options options; std::shared_ptr camera; +std::map streamInfo; EventLoop *loop; BufferWriter *writer; @@ -87,9 +88,12 @@ static int prepareCameraConfig(CameraConfiguration *config) { std::vector roles; + streamInfo.clear(); + /* If no configuration is provided assume a single video stream. */ if (!options.isSet(OptStream)) { *config = camera->streamConfiguration({ Stream::VideoRecording() }); + streamInfo[config->front()] = "stream0"; return 0; } @@ -142,31 +146,42 @@ static int prepareCameraConfig(CameraConfiguration *config) (*config)[stream].pixelFormat = conf["pixelformat"]; } + for (unsigned int i = 0; i < config->size(); i++) + streamInfo[(*config)[i]] = "stream" + std::to_string(i); + return 0; } static void requestComplete(Request *request, const std::map &buffers) { static uint64_t last = 0; + double fps = 0.0; if (request->status() == Request::RequestCancelled) return; - Buffer *buffer = buffers.begin()->second; + for (auto it = buffers.begin(); it != buffers.end(); ++it) { + Stream *stream = it->first; + Buffer *buffer = it->second; + std::string name = streamInfo[stream]; - double fps = buffer->timestamp() - last; - fps = last && fps ? 1000000000.0 / fps : 0.0; - last = buffer->timestamp(); + if (it == buffers.begin()) { + fps = buffer->timestamp() - last; + fps = last && fps ? 1000000000.0 / fps : 0.0; + last = buffer->timestamp(); + } - std::cout << "seq: " << std::setw(6) << std::setfill('0') << buffer->sequence() - << " buf: " << buffer->index() - << " bytesused: " << buffer->bytesused() - << " timestamp: " << buffer->timestamp() - << " fps: " << std::fixed << std::setprecision(2) << fps - << std::endl; + std::cout << name << " seq: " << std::setw(6) + << std::setfill('0') << buffer->sequence() + << " buf: " << buffer->index() + << " bytesused: " << buffer->bytesused() + << " timestamp: " << buffer->timestamp() + << " fps: " << std::fixed << std::setprecision(2) << fps + << std::endl; - if (writer) - writer->write(buffer, "stream0"); + if (writer) + writer->write(buffer, name); + } request = camera->createRequest(); if (!request) {