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.
master
jp9000 2014-10-23 10:37:43 -07:00
parent 40b1cc180d
commit d6b3230dbc
1 changed files with 10 additions and 0 deletions

View File

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