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>
This commit is contained in:
Laurent Pinchart
2020-08-16 17:52:50 +03:00
parent 3bd1985545
commit c671cbe622

View File

@@ -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) {