Skip to content

Commit f7ebe31

Browse files
committed
refactoring
1 parent 3a83181 commit f7ebe31

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/libs/capture.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,25 +569,28 @@ bool _capture_is_buffer_valid(const us_capture_s *cap, const struct v4l2_buffer
569569
if (us_is_jpeg(cap->run->format)) {
570570
if (buf->bytesused < 125) {
571571
// https://stackoverflow.com/questions/2253404/what-is-the-smallest-valid-jpeg-file-size-in-bytes
572-
_LOG_DEBUG("Discarding invalid frame, too small to be a valid JPEG: bytesused=%u", buf->bytesused);
572+
_LOG_DEBUG("Discarding invalid frame, too small to be a valid JPEG: bytesused=%u",
573+
buf->bytesused);
573574
return false;
574575
}
575576

576577
const u16 begin_marker = (((u16)(data[0]) << 8) | data[1]);
577578
if (begin_marker != 0xFFD8) {
578-
_LOG_DEBUG("Discarding JPEG frame with invalid header: begin_marker=0x%04x, bytesused=%u", begin_marker, buf->bytesused);
579+
_LOG_DEBUG("Discarding JPEG frame with invalid header: begin_marker=0x%04x, bytesused=%u",
580+
begin_marker, buf->bytesused);
579581
return false;
580582
}
581583

582-
const u8 *const end_ptr = data + buf->bytesused;
583-
const u8 *const eoi_ptr = end_ptr - 2;
584-
const u16 eoi_marker = (((u16)(eoi_ptr[0]) << 8) | eoi_ptr[1]);
585-
if (eoi_marker != 0xFFD9 && eoi_marker != 0xD900 && eoi_marker != 0x0000) {
584+
const u8 *const end_ptr = data + buf->bytesused - 2;
585+
const u16 end_marker = (((u16)(end_ptr[0]) << 8) | end_ptr[1]);
586+
if (end_marker != 0xFFD9 && end_marker != 0xD900 && end_marker != 0x0000) {
586587
if (!cap->allow_truncated_frames) {
587-
_LOG_DEBUG("Discarding truncated JPEG frame: eoi_marker=0x%04x, bytesused=%u", eoi_marker, buf->bytesused);
588+
_LOG_DEBUG("Discarding truncated JPEG frame: end_marker=0x%04x, bytesused=%u",
589+
end_marker, buf->bytesused);
588590
return false;
589591
}
590-
_LOG_DEBUG("Got truncated JPEG frame: eoi_marker=0x%04x, bytesused=%u", eoi_marker, buf->bytesused);
592+
_LOG_DEBUG("Got truncated JPEG frame: end_marker=0x%04x, bytesused=%u",
593+
end_marker, buf->bytesused);
591594
}
592595
}
593596

0 commit comments

Comments
 (0)