- if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
- is_capturing(dev)) {
- v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
- "Grab another frame as buffer has EOS");
- vchiq_mmal_port_parameter_set(
- instance,
- dev->capture.camera_port,
- MMAL_PARAMETER_CAPTURE,
- &dev->capture.frame_count,
- sizeof(dev->capture.frame_count));
- }
+ if (dev->capture.vc_start_timestamp == -1) {
+ /*
+ * VPU doesn't support MMAL_PARAMETER_SYSTEM_TIME, rely on
+ * kernel time, and have no latency compensation.
+ */
+ buf->vb.vb2_buf.timestamp = ktime_get_ns();
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "Buffer time set as current time - %lld",
+ buf->vb.vb2_buf.timestamp);
+ } else if (mmal_buf->pts != 0) {
+ ktime_t timestamp;
+ s64 runtime_us = mmal_buf->pts -
+ dev->capture.vc_start_timestamp;
+ timestamp = ktime_add_us(dev->capture.kernel_start_ts,
+ runtime_us);
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "Convert start time %llu and %llu with offset %llu to %llu\n",
+ ktime_to_ns(dev->capture.kernel_start_ts),
+ dev->capture.vc_start_timestamp, mmal_buf->pts,
+ ktime_to_ns(timestamp));
+ if (timestamp < dev->capture.last_timestamp) {
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "Negative delta - using last time\n");
+ timestamp = dev->capture.last_timestamp;
+ }
+ buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
+ } else {
+ if (dev->capture.last_timestamp) {
+ buf->vb.vb2_buf.timestamp = dev->capture.last_timestamp;
+ v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
+ "Buffer time set as last timestamp - %lld",
+ buf->vb.vb2_buf.timestamp);