From patchwork Sat Aug 22 13:40:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9359 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 25401BD87C for ; Sat, 22 Aug 2020 13:41:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AE01D61080; Sat, 22 Aug 2020 15:41:00 +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="AkpdbR/Z"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3AFF661080 for ; Sat, 22 Aug 2020 15:40:59 +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 BAD5529E for ; Sat, 22 Aug 2020 15:40:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1598103658; bh=U+RGkL2qOKp+EnB0NalhPLfO3gvk2MUHxfzQc8LlUCI=; h=From:To:Subject:Date:From; b=AkpdbR/ZYxTOE9Lt8Uzc6gJwhKnIkZC1zp/XmNMaHZm2pCcUG8mfsjld5GJpjxLF8 3bEjjhl1QW9tzvJ+1E+riZCA/afzN2YHuXEyJkNdiiFInxzqENueawssM27CWuNDHf YZ6k4N5IoJzvzfEYYa5YI3JokgfvX6/TV8i22BcM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 22 Aug 2020 16:40:36 +0300 Message-Id: <20200822134036.16209-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] cam: Limit file write to payload size 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 payload size in a captured framebuffer is usually equal to the buffer size. However, for compressed formats, the payload may be smaller Only write the payload when capturing to a file. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/buffer_writer.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cam/buffer_writer.cpp b/src/cam/buffer_writer.cpp index c5a5eb46224a..6305958924a4 100644 --- a/src/cam/buffer_writer.cpp +++ b/src/cam/buffer_writer.cpp @@ -64,9 +64,17 @@ int BufferWriter::write(FrameBuffer *buffer, const std::string &streamName) if (fd == -1) return -errno; - for (const FrameBuffer::Plane &plane : buffer->planes()) { + for (unsigned int i = 0; i < buffer->planes().size(); ++i) { + const FrameBuffer::Plane &plane = buffer->planes()[i]; + const FrameMetadata::Plane &meta = buffer->metadata().planes[i]; + void *data = mappedBuffers_[plane.fd.fd()].first; - unsigned int length = plane.length; + unsigned int length = std::min(meta.bytesused, plane.length); + + if (length < meta.bytesused) + std::cerr << "payload size " << meta.bytesused + << " smaller than plane size " << plane.length + << std::endl; ret = ::write(fd, data, length); if (ret < 0) {