Skip to content

Commit 771f65c

Browse files
naushirpopcornmix
authored andcommitted
drivers: media: bcm2835_unicam: Improve frame sequence count handling
Ensure that the frame sequence counter is incremented only if a previous frame start interrupt has occurred, or a frame start + frame end has occurred simultaneously. This corresponds the sequence number with the actual number of frames produced by the sensor, not the number of frame buffers dequeued back to userland. Signed-off-by: Naushir Patuck <[email protected]>
1 parent 38557dc commit 771f65c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

drivers/media/platform/bcm2835/bcm2835-unicam.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ struct unicam_device {
537537
/* subdevice async Notifier */
538538
struct v4l2_async_notifier notifier;
539539
unsigned int sequence;
540+
bool frame_started;
540541

541542
/* ptr to sub device */
542543
struct v4l2_subdev *sensor;
@@ -929,6 +930,8 @@ static irqreturn_t unicam_isr(int irq, void *dev)
929930
* buffer forever.
930931
*/
931932
if (fe) {
933+
bool inc_seq = unicam->frame_started;
934+
932935
/*
933936
* Ensure we have swapped buffers already as we can't
934937
* stop the peripheral. If no buffer is available, use a
@@ -964,11 +967,23 @@ static irqreturn_t unicam_isr(int irq, void *dev)
964967
unicam_process_buffer_complete(node, sequence);
965968
node->cur_frm = node->next_frm;
966969
node->next_frm = NULL;
970+
inc_seq = true;
967971
} else {
968972
node->cur_frm = node->next_frm;
969973
}
970974
}
971-
unicam->sequence++;
975+
976+
/*
977+
* Increment the sequence number conditionally on either a FS
978+
* having already occurred, or in the FE + FS condition as
979+
* caught in the FE handler above. This ensures the sequence
980+
* number corresponds to the frames generated by the sensor, not
981+
* the frames dequeued to userland.
982+
*/
983+
if (inc_seq) {
984+
unicam->sequence++;
985+
unicam->frame_started = false;
986+
}
972987
}
973988

974989
if (ista & UNICAM_FSI) {
@@ -1011,6 +1026,7 @@ static irqreturn_t unicam_isr(int irq, void *dev)
10111026
}
10121027

10131028
unicam_queue_event_sof(unicam);
1029+
unicam->frame_started = true;
10141030
}
10151031

10161032
/*
@@ -2615,6 +2631,7 @@ static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count)
26152631
vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
26162632
}
26172633

2634+
dev->frame_started = false;
26182635
unicam_start_rx(dev, buffer_addr);
26192636

26202637
ret = v4l2_subdev_call(dev->sensor, video, s_stream, 1);

0 commit comments

Comments
 (0)