From patchwork Thu Jul 15 21:14:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13002 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 C9961C3228 for ; Thu, 15 Jul 2021 21:15:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7AC6868566; Thu, 15 Jul 2021 23:15:33 +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="psYBQ2Hl"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BF2AF68544 for ; Thu, 15 Jul 2021 23:15:14 +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 5BED6340 for ; Thu, 15 Jul 2021 23:15:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626383714; bh=deM3YgFU680f/nPIKkYwSskrp3IL9MmrKvZ1pCr8jPQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=psYBQ2HliEb+mWOOIpJs7YwfYAnE3x9oeAdHMSiHq/2K+Yz9hSnRTPsqxebDWCaa+ fCbnFJYMYkJWZz0sCuU2D68eDgnTtBCzuGa4E8j7xQCBemrOA9KhsD/DRnnA6h+zyR MtIFk+Xwf9L+sNkwHWcRyv/r33uu6tSC7gnl/FV4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Jul 2021 00:14:56 +0300 Message-Id: <20210715211459.19373-31-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715211459.19373-1-laurent.pinchart@ideasonboard.com> References: <20210715211459.19373-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 30/33] 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,