Skip to content

Commit 230538e

Browse files
committed
samples: video: capture: Get and enumerate frame rate
Add code to get the current frame rate and enumerate all supported frame rates (frame intervals) of the current format. Signed-off-by: Phi Bang Nguyen <[email protected]>
1 parent e0197b6 commit 230538e

File tree

1 file changed

+22
-0
lines changed
  • samples/drivers/video/capture/src

1 file changed

+22
-0
lines changed

samples/drivers/video/capture/src/main.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ int main(void)
7878
struct video_buffer *buffers[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX], *vbuf;
7979
struct video_format fmt;
8080
struct video_caps caps;
81+
struct video_frmival frmival;
82+
struct video_frmival_enum fie;
8183
unsigned int frame = 0;
8284
size_t bsize;
8385
int i = 0;
@@ -129,6 +131,26 @@ int main(void)
129131
(char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16),
130132
(char)(fmt.pixelformat >> 24), fmt.width, fmt.height);
131133

134+
if (!video_get_frmival(video_dev, VIDEO_EP_OUT, &frmival)) {
135+
printk("- Default frame rate : %f fps\n",
136+
1.0 * frmival.denominator / frmival.numerator);
137+
}
138+
139+
printk("- Supported frame intervals for the default format:\n");
140+
memset(&fie, 0, sizeof(fie));
141+
fie.format = &fmt;
142+
while (video_enum_frmival(video_dev, VIDEO_EP_OUT, &fie) == 0) {
143+
if (fie.type == VIDEO_FRMIVAL_TYPE_DISCRETE) {
144+
printk(" %u/%u ", fie.discrete.numerator, fie.discrete.denominator);
145+
} else {
146+
printk(" [min = %u/%u; max = %u/%u; step = %u/%u]\n",
147+
fie.stepwise.min.numerator, fie.stepwise.min.denominator,
148+
fie.stepwise.max.numerator, fie.stepwise.max.denominator,
149+
fie.stepwise.step.numerator, fie.stepwise.step.denominator);
150+
}
151+
fie.index++;
152+
}
153+
132154
#if DT_HAS_CHOSEN(zephyr_display)
133155
const struct device *const display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
134156

0 commit comments

Comments
 (0)