From patchwork Wed Jul 7 02:19:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12840 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7D6F4C3226 for ; Wed, 7 Jul 2021 02:20:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3994D68520; Wed, 7 Jul 2021 04:20:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oQ+lm0a4"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B2B6A68537 for ; Wed, 7 Jul 2021 04:20:41 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 48515466 for ; Wed, 7 Jul 2021 04:20:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1625624441; bh=VKXcaqS+RJRLnr0tkYNAWdBApnloPBa17hKpCGpHNx4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oQ+lm0a4J9cJ00otOGYHtEqdwHp+oAAXUo2ysWauSSE5zGGouynKSEXMeFLwwDoUv oQZTgUB386HzHH+djK8kqOYKanEQLeBKPXxsHupUq97ubS5uw/yLA7IKzXxPhKFb8E OYyjmJC8R72qFWiEiXq04RAHHHHf7/QMOTWvUam0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Jul 2021 05:19:38 +0300 Message-Id: <20210707021941.20804-28-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210707021941.20804-1-laurent.pinchart@ideasonboard.com> References: <20210707021941.20804-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 27/30] cam: Allow specifying directories in the --file option X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The value of the --file option is the full name of the file to which captured frames are written. To write files to a specific directory with the default naming scheme, the "frame-#.bin" name has to appear at the end of the file name. Simplify usage of the option by allowing --file to specify a directory only. If the file name ends with a '/', the default "frame-#.bin" file name is automatically appended. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/buffer_writer.cpp | 7 ++++++- src/cam/buffer_writer.h | 2 +- src/cam/main.cpp | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cam/buffer_writer.cpp b/src/cam/buffer_writer.cpp index f2b21aef3362..a7648a92fc92 100644 --- a/src/cam/buffer_writer.cpp +++ b/src/cam/buffer_writer.cpp @@ -49,7 +49,12 @@ int BufferWriter::write(FrameBuffer *buffer, const std::string &streamName) size_t pos; int fd, ret = 0; - filename = pattern_; + if (!pattern_.empty()) + filename = pattern_; + + if (filename.empty() || filename.back() == '/') + filename += "frame-#.bin"; + 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 604ce8702ec7..7626de42d369 100644 --- a/src/cam/buffer_writer.h +++ b/src/cam/buffer_writer.h @@ -15,7 +15,7 @@ class BufferWriter { public: - BufferWriter(const std::string &pattern = "frame-#.bin"); + BufferWriter(const std::string &pattern = ""); ~BufferWriter(); void mapBuffer(libcamera::FrameBuffer *buffer); diff --git a/src/cam/main.cpp b/src/cam/main.cpp index a3f19d0fa61b..6d7d45e11499 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -118,7 +118,10 @@ int CamApp::parseOptions(int argc, char *argv[]) "capture", ArgumentOptional, "count"); parser.addOption(OptFile, OptionString, "Write captured frames to disk\n" - "The first '#' character in the file name is expanded to the stream name and frame sequence number.\n" + "If the file name ends with a '/', it sets the directory in which\n" + "to write files, using the default file name. Otherwise it sets the\n" + "full file path and name. The first '#' character in the file name\n" + "is expanded to the stream name and frame sequence number.\n" "The default file name is 'frame-#.bin'.", "file", ArgumentOptional, "filename"); parser.addOption(OptStream, &streamKeyValue,