diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-08-16 17:52:50 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-08-25 21:57:53 +0300 |
commit | c671cbe622469185311fafce4b32b6b995a04445 (patch) | |
tree | b0035607b2a1d47a3b00d8cd8e3165453bab8e6c /src/cam | |
parent | 3bd19855459f6b58360197bc67c545a698812899 (diff) |
cam: Limit file write to payload size
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 <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/cam')
-rw-r--r-- | src/cam/buffer_writer.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/cam/buffer_writer.cpp b/src/cam/buffer_writer.cpp index c5a5eb46..f2b21aef 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 (meta.bytesused > plane.length) + std::cerr << "payload size " << meta.bytesused + << " larger than plane size " << plane.length + << std::endl; ret = ::write(fd, data, length); if (ret < 0) { |