Skip to content

Commit cb92836

Browse files
6by9popcornmix
authored andcommitted
staging: bcm2835-camera: Ensure H264 header bytes get a sensible timestamp
H264 header come from VC with 0 timestamps, which means they get a strange timestamp when processed with VC/kernel start times, particularly if used with the inline header option. Remember the last frame timestamp and use that if set, or otherwise use the kernel start time. raspberrypi#1836 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
1 parent 9cbb1ce commit cb92836

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,12 @@ static void buffer_cb(struct vchiq_mmal_instance *instance,
367367
return;
368368
}
369369

370-
if (dev->capture.vc_start_timestamp != -1 && pts) {
370+
if (dev->capture.vc_start_timestamp == -1) {
371+
buf->vb.vb2_buf.timestamp = ktime_get_ns();
372+
v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
373+
"Buffer time set as current time - %lld",
374+
buf->vb.vb2_buf.timestamp);
375+
} else if (mmal_buf->pts != 0) {
371376
ktime_t timestamp;
372377
s64 runtime_us = pts -
373378
dev->capture.vc_start_timestamp;
@@ -380,15 +385,33 @@ static void buffer_cb(struct vchiq_mmal_instance *instance,
380385
ktime_to_ns(timestamp));
381386
buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
382387
} else {
383-
buf->vb.vb2_buf.timestamp = ktime_get_ns();
388+
if (dev->capture.last_timestamp) {
389+
buf->vb.vb2_buf.timestamp =
390+
dev->capture.last_timestamp;
391+
v4l2_dbg(1, bcm2835_v4l2_debug,
392+
&dev->v4l2_dev,
393+
"Buffer time set as last timestamp - %lld",
394+
buf->vb.vb2_buf.timestamp);
395+
} else {
396+
buf->vb.vb2_buf.timestamp =
397+
ktime_to_ns(dev->capture.kernel_start_ts);
398+
v4l2_dbg(1, bcm2835_v4l2_debug,
399+
&dev->v4l2_dev,
400+
"Buffer time set as start timestamp - %lld",
401+
buf->vb.vb2_buf.timestamp);
402+
}
384403
}
404+
dev->capture.last_timestamp = buf->vb.vb2_buf.timestamp;
385405
buf->vb.sequence = dev->capture.sequence++;
386406
buf->vb.field = V4L2_FIELD_NONE;
387407

388408
vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
389409
if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME)
390410
buf->vb.flags |= V4L2_BUF_FLAG_KEYFRAME;
391411

412+
v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
413+
"Buffer has ts %llu",
414+
dev->capture.last_timestamp);
392415
vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
393416

394417
if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
@@ -552,6 +575,7 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
552575
}
553576

554577
dev->capture.kernel_start_ts = ktime_get();
578+
dev->capture.last_timestamp = 0;
555579

556580
/* enable the camera port */
557581
dev->capture.port->cb_ctx = dev;

‎drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ struct bm2835_mmal_dev {
9393
ktime_t kernel_start_ts;
9494
/* Sequence number of last buffer */
9595
u32 sequence;
96+
/* Timestamp of last frame */
97+
u64 last_timestamp;
9698

9799
struct vchiq_mmal_port *port; /* port being used for capture */
98100
/* camera port being used for capture */

0 commit comments

Comments
 (0)