ソースを参照

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.
jp9000 11 年 前
コミット
d6b3230dbc
1 ファイル変更10 行追加0 行削除
  1. 10 0
      plugins/linux-v4l2/v4l2-input.c

+ 10 - 0
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) {