renamed buf_info to buf

This commit is contained in:
Maxim Devaev
2021-11-12 20:42:50 +03:00
parent 61ab2a81a5
commit dabaab4987
3 changed files with 42 additions and 42 deletions

View File

@@ -334,23 +334,23 @@ int device_select(device_s *dev, bool *has_read, bool *has_write, bool *has_erro
int device_grab_buffer(device_s *dev, hw_buffer_s **hw) {
*hw = NULL;
struct v4l2_buffer buf_info;
MEMSET_ZERO(buf_info);
buf_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf_info.memory = dev->io_method;
struct v4l2_buffer buf;
MEMSET_ZERO(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = dev->io_method;
LOG_DEBUG("Grabbing device buffer ...");
if (xioctl(RUN(fd), VIDIOC_DQBUF, &buf_info) < 0) {
if (xioctl(RUN(fd), VIDIOC_DQBUF, &buf) < 0) {
LOG_PERROR("Unable to grab device buffer");
return -1;
}
LOG_DEBUG("Grabbed new frame in device buffer: index=%u, bytesused=%u",
buf_info.index, buf_info.bytesused);
buf.index, buf.bytesused);
if (buf_info.index >= RUN(n_bufs)) {
if (buf.index >= RUN(n_bufs)) {
LOG_ERROR("V4L2 error: grabbed invalid device buffer: index=%u, n_bufs=%u",
buf_info.index, RUN(n_bufs));
buf.index, RUN(n_bufs));
return -1;
}
@@ -359,48 +359,48 @@ int device_grab_buffer(device_s *dev, hw_buffer_s **hw) {
// The good thing is such frames are quite small compared to the regular frames.
// For example a VGA (640x480) webcam frame is normally >= 8kByte large,
// corrupted frames are smaller.
if (buf_info.bytesused < dev->min_frame_size) {
LOG_DEBUG("Dropped too small frame sized %d bytes, assuming it was broken", buf_info.bytesused);
LOG_DEBUG("Releasing device buffer index=%u (broken frame) ...", buf_info.index);
if (xioctl(RUN(fd), VIDIOC_QBUF, &buf_info) < 0) {
LOG_PERROR("Unable to release device buffer index=%u (broken frame)", buf_info.index);
if (buf.bytesused < dev->min_frame_size) {
LOG_DEBUG("Dropped too small frame sized %d bytes, assuming it was broken", buf.bytesused);
LOG_DEBUG("Releasing device buffer index=%u (broken frame) ...", buf.index);
if (xioctl(RUN(fd), VIDIOC_QBUF, &buf) < 0) {
LOG_PERROR("Unable to release device buffer index=%u (broken frame)", buf.index);
return -1;
}
return -2;
}
# define HW(_next) RUN(hw_bufs)[buf_info.index]._next
# define HW(_next) RUN(hw_bufs)[buf.index]._next
A_MUTEX_LOCK(&HW(grabbed_mutex));
if (HW(grabbed)) {
LOG_ERROR("V4L2 error: grabbed device buffer is already used: index=%u, bytesused=%u",
buf_info.index, buf_info.bytesused);
buf.index, buf.bytesused);
A_MUTEX_UNLOCK(&HW(grabbed_mutex));
return -1;
}
HW(grabbed) = true;
A_MUTEX_UNLOCK(&HW(grabbed_mutex));
HW(raw.used) = buf_info.bytesused;
HW(raw.used) = buf.bytesused;
HW(raw.width) = RUN(width);
HW(raw.height) = RUN(height);
HW(raw.format) = RUN(format);
HW(raw.stride) = RUN(stride);
HW(raw.online) = true;
memcpy(&HW(buf_info), &buf_info, sizeof(struct v4l2_buffer));
memcpy(&HW(buf), &buf, sizeof(struct v4l2_buffer));
HW(raw.grab_ts) = get_now_monotonic();
# undef HW
*hw = &RUN(hw_bufs[buf_info.index]);
return buf_info.index;
*hw = &RUN(hw_bufs[buf.index]);
return buf.index;
}
int device_release_buffer(device_s *dev, hw_buffer_s *hw) {
const unsigned index = hw->buf_info.index;
const unsigned index = hw->buf.index;
LOG_DEBUG("Releasing device buffer index=%u ...", index);
A_MUTEX_LOCK(&hw->grabbed_mutex);
if (xioctl(RUN(fd), VIDIOC_QBUF, &hw->buf_info) < 0) {
if (xioctl(RUN(fd), VIDIOC_QBUF, &hw->buf) < 0) {
LOG_PERROR("Unable to release device buffer index=%u", index);
A_MUTEX_UNLOCK(&hw->grabbed_mutex);
return -1;
@@ -706,14 +706,14 @@ static int _device_open_io_method_mmap(device_s *dev) {
A_CALLOC(RUN(hw_bufs), req.count);
for (RUN(n_bufs) = 0; RUN(n_bufs) < req.count; ++RUN(n_bufs)) {
struct v4l2_buffer buf_info;
MEMSET_ZERO(buf_info);
buf_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf_info.memory = V4L2_MEMORY_MMAP;
buf_info.index = RUN(n_bufs);
struct v4l2_buffer buf;
MEMSET_ZERO(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = RUN(n_bufs);
LOG_DEBUG("Calling ioctl(VIDIOC_QUERYBUF) for device buffer %u ...", RUN(n_bufs));
if (xioctl(RUN(fd), VIDIOC_QUERYBUF, &buf_info) < 0) {
if (xioctl(RUN(fd), VIDIOC_QUERYBUF, &buf) < 0) {
LOG_PERROR("Can't VIDIOC_QUERYBUF");
return -1;
}
@@ -730,16 +730,16 @@ static int _device_open_io_method_mmap(device_s *dev) {
LOG_DEBUG("Mapping device buffer %u ...", RUN(n_bufs));
if ((HW(raw.data) = mmap(
NULL,
buf_info.length,
buf.length,
PROT_READ | PROT_WRITE,
MAP_SHARED,
RUN(fd),
buf_info.m.offset
buf.m.offset
)) == MAP_FAILED) {
LOG_PERROR("Can't map device buffer %u", RUN(n_bufs));
return -1;
}
HW(raw.allocated) = buf_info.length;
HW(raw.allocated) = buf.length;
# undef HW
}
@@ -785,18 +785,18 @@ static int _device_open_io_method_userptr(device_s *dev) {
static int _device_open_queue_buffers(device_s *dev) {
for (unsigned index = 0; index < RUN(n_bufs); ++index) {
struct v4l2_buffer buf_info;
MEMSET_ZERO(buf_info);
buf_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf_info.memory = dev->io_method;
buf_info.index = index;
struct v4l2_buffer buf;
MEMSET_ZERO(buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = dev->io_method;
buf.index = index;
if (dev->io_method == V4L2_MEMORY_USERPTR) {
buf_info.m.userptr = (unsigned long)RUN(hw_bufs)[index].raw.data;
buf_info.length = RUN(hw_bufs)[index].raw.allocated;
buf.m.userptr = (unsigned long)RUN(hw_bufs)[index].raw.data;
buf.length = RUN(hw_bufs)[index].raw.allocated;
}
LOG_DEBUG("Calling ioctl(VIDIOC_QBUF) for buffer %u ...", index);
if (xioctl(RUN(fd), VIDIOC_QBUF, &buf_info) < 0) {
if (xioctl(RUN(fd), VIDIOC_QBUF, &buf) < 0) {
LOG_PERROR("Can't VIDIOC_QBUF");
return -1;
}

View File

@@ -73,7 +73,7 @@
typedef struct {
frame_s raw;
struct v4l2_buffer buf_info;
struct v4l2_buffer buf;
# ifdef WITH_OMX
int dma_fd;

View File

@@ -235,7 +235,7 @@ static bool _worker_run_job(worker_s *wr) {
# define ER(_next) job->enc->run->_next
LOG_DEBUG("Worker %s compressing JPEG from buffer %u ...", wr->name, job->hw->buf_info.index);
LOG_DEBUG("Worker %s compressing JPEG from buffer %u ...", wr->name, job->hw->buf.index);
assert(ER(type) != ENCODER_TYPE_UNKNOWN);
assert(src->used > 0);
@@ -271,13 +271,13 @@ static bool _worker_run_job(worker_s *wr) {
job->dest->used,
job->dest->encode_end_ts - job->dest->encode_begin_ts,
wr->name,
job->hw->buf_info.index);
job->hw->buf.index);
return true;
# ifdef WITH_OMX
error:
LOG_ERROR("Compression failed: worker=%s, buffer=%u", wr->name, job->hw->buf_info.index);
LOG_ERROR("Compression failed: worker=%s, buffer=%u", wr->name, job->hw->buf.index);
LOG_ERROR("Error while compressing buffer, falling back to CPU");
A_MUTEX_LOCK(&ER(mutex));
ER(cpu_forced) = true;