Skip to content

Commit e8e2bb5

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 6ae593e commit e8e2bb5

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
@@ -548,6 +548,7 @@ struct unicam_device {
548548
/* subdevice async Notifier */
549549
struct v4l2_async_notifier notifier;
550550
unsigned int sequence;
551+
bool frame_started;
551552

552553
/* ptr to sub device */
553554
struct v4l2_subdev *sensor;
@@ -940,6 +941,8 @@ static irqreturn_t unicam_isr(int irq, void *dev)
940941
* buffer forever.
941942
*/
942943
if (fe) {
944+
bool inc_seq = unicam->frame_started;
945+
943946
/*
944947
* Ensure we have swapped buffers already as we can't
945948
* stop the peripheral. If no buffer is available, use a
@@ -975,11 +978,23 @@ static irqreturn_t unicam_isr(int irq, void *dev)
975978
unicam_process_buffer_complete(node, sequence);
976979
node->cur_frm = node->next_frm;
977980
node->next_frm = NULL;
981+
inc_seq = true;
978982
} else {
979983
node->cur_frm = node->next_frm;
980984
}
981985
}
982-
unicam->sequence++;
986+
987+
/*
988+
* Increment the sequence number conditionally on either a FS
989+
* having already occurred, or in the FE + FS condition as
990+
* caught in the FE handler above. This ensures the sequence
991+
* number corresponds to the frames generated by the sensor, not
992+
* the frames dequeued to userland.
993+
*/
994+
if (inc_seq) {
995+
unicam->sequence++;
996+
unicam->frame_started = false;
997+
}
983998
}
984999

9851000
if (ista & UNICAM_FSI) {
@@ -1022,6 +1037,7 @@ static irqreturn_t unicam_isr(int irq, void *dev)
10221037
}
10231038

10241039
unicam_queue_event_sof(unicam);
1040+
unicam->frame_started = true;
10251041
}
10261042

10271043
/*
@@ -2626,6 +2642,7 @@ static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count)
26262642
vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
26272643
}
26282644

2645+
dev->frame_started = false;
26292646
unicam_start_rx(dev, buffer_addr);
26302647

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

0 commit comments

Comments
 (0)