linux-v4l2: Improve error and debug logging

The capture loop errors are now logged as such.
Increased the amount of information logged in debug mode, including
state of all buffers on timeout.
Add device name to all capture loop debug output, especially useful when
debugging issues with multiple v4l2 video streams.
This commit is contained in:
Piotr Esden-Tempski
2021-01-12 09:33:11 -08:00
committed by Jim
parent f1c389c365
commit bb264b2b33
3 changed files with 75 additions and 6 deletions
+33 -6
View File
@@ -162,13 +162,19 @@ static void *v4l2_thread(void *vptr)
struct obs_source_frame out;
size_t plane_offsets[MAX_AV_PLANES];
blog(LOG_DEBUG, "%s: new capture thread", data->device_id);
if (v4l2_start_capture(data->dev, &data->buffers) < 0)
goto exit;
blog(LOG_DEBUG, "%s: new capture started", data->device_id);
frames = 0;
first_ts = 0;
v4l2_prep_obs_frame(data, &out, plane_offsets);
blog(LOG_DEBUG, "%s: obs frame prepared", data->device_id);
while (os_event_try(data->event) == EAGAIN) {
FD_ZERO(&fds);
FD_SET(data->dev, &fds);
@@ -179,10 +185,20 @@ static void *v4l2_thread(void *vptr)
if (r < 0) {
if (errno == EINTR)
continue;
blog(LOG_DEBUG, "select failed");
blog(LOG_ERROR, "%s: select failed", data->device_id);
break;
} else if (r == 0) {
blog(LOG_DEBUG, "select timeout");
blog(LOG_ERROR, "%s: select timed out",
data->device_id);
#ifdef _DEBUG
v4l2_query_all_buffers(data->dev, &data->buffers);
#endif
if (v4l2_ioctl(data->dev, VIDIOC_LOG_STATUS) < 0) {
blog(LOG_ERROR, "%s: failed to log status",
data->device_id);
}
continue;
}
@@ -190,12 +206,21 @@ static void *v4l2_thread(void *vptr)
buf.memory = V4L2_MEMORY_MMAP;
if (v4l2_ioctl(data->dev, VIDIOC_DQBUF, &buf) < 0) {
if (errno == EAGAIN)
if (errno == EAGAIN) {
blog(LOG_DEBUG, "%s: ioctl dqbuf eagain",
data->device_id);
continue;
blog(LOG_DEBUG, "failed to dequeue buffer");
}
blog(LOG_ERROR, "%s: failed to dequeue buffer",
data->device_id);
break;
}
blog(LOG_DEBUG,
"%s: ts: %06ld buf id #%d, flags 0x%08X, seq #%d, len %d, used %d",
data->device_id, buf.timestamp.tv_usec, buf.index,
buf.flags, buf.sequence, buf.length, buf.bytesused);
out.timestamp = timeval2ns(buf.timestamp);
if (!frames)
first_ts = out.timestamp;
@@ -207,14 +232,16 @@ static void *v4l2_thread(void *vptr)
obs_source_output_video(data->source, &out);
if (v4l2_ioctl(data->dev, VIDIOC_QBUF, &buf) < 0) {
blog(LOG_DEBUG, "failed to enqueue buffer");
blog(LOG_ERROR, "%s: failed to enqueue buffer",
data->device_id);
break;
}
frames++;
}
blog(LOG_INFO, "Stopped capture after %" PRIu64 " frames", frames);
blog(LOG_INFO, "%s: Stopped capture after %" PRIu64 " frames",
data->device_id, frames);
exit:
v4l2_stop_capture(data->dev);