From patchwork Tue Apr 2 00:54:05 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: 839 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 40F24610BF for ; Tue, 2 Apr 2019 02:54:35 +0200 (CEST) X-Halon-ID: e1ca9d7d-54e1-11e9-846a-005056917a89 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA id e1ca9d7d-54e1-11e9-846a-005056917a89; Tue, 02 Apr 2019 02:54:34 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 2 Apr 2019 02:54:05 +0200 Message-Id: <20190402005406.25097-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402005406.25097-1-niklas.soderlund@ragnatech.se> References: <20190402005406.25097-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] cam: Extend request complete 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: Tue, 02 Apr 2019 00:54:35 -0000 The completion handler needs to handle all buffers in the request. Solve this by iterating over all buffers in the completed and assign each stream a name as we encounter them. The buffer writer needs to be extended to learn about stream names so it can prefix the files it writes with it. Signed-off-by: Niklas Söderlund --- src/cam/buffer_writer.cpp | 4 ++-- src/cam/buffer_writer.h | 2 +- src/cam/main.cpp | 41 +++++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/cam/buffer_writer.cpp b/src/cam/buffer_writer.cpp index 2d2258b4cd1cbbc2..02a9610b8b3caa31 100644 --- a/src/cam/buffer_writer.cpp +++ b/src/cam/buffer_writer.cpp @@ -19,13 +19,13 @@ BufferWriter::BufferWriter(const std::string &pattern) { } -int BufferWriter::write(libcamera::Buffer *buffer) +int BufferWriter::write(libcamera::Buffer *buffer, const std::string &prefix) { std::string filename; size_t pos; int fd, ret = 0; - filename = pattern_; + filename = prefix + "-" + pattern_; pos = filename.find_first_of('#'); if (pos != std::string::npos) { std::stringstream ss; diff --git a/src/cam/buffer_writer.h b/src/cam/buffer_writer.h index 9705773e0e397d45..ebc6c24cd8f8d43a 100644 --- a/src/cam/buffer_writer.h +++ b/src/cam/buffer_writer.h @@ -16,7 +16,7 @@ class BufferWriter public: BufferWriter(const std::string &pattern = "frame-#.bin"); - int write(libcamera::Buffer *buffer); + int write(libcamera::Buffer *buffer, const std::string &prefix); private: std::string pattern_; diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 1bf28ca8eb8c6da7..6aed4073f70d37a2 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -143,28 +143,45 @@ static int prepare_camera_config(std::map *config return 0; } +static std::string streamToName(const Stream *stream) +{ + static std::map names; + + if (names.find(stream) == names.end()) + names[stream] = std::string("stream") + std::to_string(names.size()); + + return names[stream]; +} + 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 const &it : buffers) { + Stream *stream = it.first; + Buffer *buffer = it.second; + std::string name = streamToName(stream); - double fps = buffer->timestamp() - last; - fps = last && fps ? 1000000000.0 / fps : 0.0; - last = buffer->timestamp(); + if (fps == 0.0) { + 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); + if (writer) + writer->write(buffer, name); + } request = camera->createRequest(); if (!request) {