From d6b3230dbcfb2f49a6c42ea45b9d889a3e53f278 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 23 Oct 2014 10:37:43 -0700 Subject: [PATCH] linux-v4l2: Start timestamps from 0 per device When a new device starts up, make it so that the first timestamp that occurs starts from 0. This prevents the internal source timestamp handling from trying to buffer new frames to the new timestamp value in case the device changes. --- plugins/linux-v4l2/v4l2-input.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/linux-v4l2/v4l2-input.c b/plugins/linux-v4l2/v4l2-input.c index d9bc2f3cb..9618393f8 100644 --- a/plugins/linux-v4l2/v4l2-input.c +++ b/plugins/linux-v4l2/v4l2-input.c @@ -59,6 +59,8 @@ struct v4l2_data { int resolution; int framerate; bool sys_timing; + bool started; + uint64_t start_ts; /* internal data */ obs_source_t *source; @@ -182,6 +184,12 @@ static void *v4l2_thread(void *vptr) out.timestamp = data->sys_timing ? os_gettime_ns() : timeval2ns(buf.timestamp); + if (!data->started) { + data->start_ts = out.timestamp; + data->started = true; + } + out.timestamp -= data->start_ts; + start = (uint8_t *) data->buffers.info[buf.index].start; for (uint_fast32_t i = 0; i < MAX_AV_PLANES; ++i) out.data[i] = start + plane_offsets[i]; @@ -643,6 +651,8 @@ static void v4l2_init(struct v4l2_data *data) { int fps_num, fps_denom; + data->started = false; + blog(LOG_INFO, "Start capture from %s", data->device_id); data->dev = v4l2_open(data->device_id, O_RDWR | O_NONBLOCK); if (data->dev == -1) {