Skip to content

Commit 9c0851f

Browse files
author
Alain Volmat
committed
samples: usb: uvc: add indirection for UVC source device
In preparation for the introduction of video encoder support add an indirection for handling of the buffers of the UVC source device. Currently this is only video_dev however it can also be an encoder device when encoder is introduced between video capture device and the UVC device. Signed-off-by: Alain Volmat <[email protected]>
1 parent 43309a2 commit 9c0851f

File tree

1 file changed

+15
-6
lines changed
  • samples/subsys/usb/uvc/src

1 file changed

+15
-6
lines changed

samples/subsys/usb/uvc/src/main.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ const static struct device *const video_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_cam
2323
/* Format capabilities of video_dev, used everywhere through the sample */
2424
static struct video_caps video_caps = {.type = VIDEO_BUF_TYPE_OUTPUT};
2525

26+
static const struct device *app_uvc_source_dev(void)
27+
{
28+
return video_dev;
29+
}
30+
2631
/* Pixel formats present in one of the UVC 1.5 standard */
2732
static bool app_is_supported_format(uint32_t pixfmt)
2833
{
@@ -46,6 +51,7 @@ static bool app_has_supported_format(void)
4651

4752
static void app_add_format(uint32_t pixfmt, uint32_t width, uint32_t height, bool has_sup_fmts)
4853
{
54+
const struct device *uvc_src_dev = app_uvc_source_dev();
4955
struct video_format fmt = {
5056
.pixelformat = pixfmt,
5157
.width = width,
@@ -60,7 +66,7 @@ static void app_add_format(uint32_t pixfmt, uint32_t width, uint32_t height, boo
6066
}
6167

6268
/* Set the format to get the size */
63-
ret = video_set_compose_format(video_dev, &fmt);
69+
ret = video_set_compose_format(uvc_src_dev, &fmt);
6470
if (ret != 0) {
6571
LOG_ERR("Could not set the format of %s to %s %ux%u (size %u)",
6672
video_dev->name, VIDEO_FOURCC_TO_STR(fmt.pixelformat),
@@ -141,6 +147,7 @@ static void app_add_filtered_formats(void)
141147

142148
int main(void)
143149
{
150+
const struct device *uvc_src_dev = app_uvc_source_dev();
144151
struct usbd_context *sample_usbd;
145152
struct video_buffer *vbuf;
146153
struct video_format fmt = {0};
@@ -162,7 +169,7 @@ int main(void)
162169
}
163170

164171
/* Must be called before usb_enable() */
165-
uvc_set_video_dev(uvc_dev, video_dev);
172+
uvc_set_video_dev(uvc_dev, uvc_src_dev);
166173

167174
/* Must be called before usb_enable() */
168175
app_add_filtered_formats();
@@ -269,17 +276,19 @@ int main(void)
269276
return ret;
270277
}
271278

272-
ret = video_transfer_buffer(video_dev, uvc_dev,
279+
ret = video_transfer_buffer(uvc_src_dev, uvc_dev,
273280
VIDEO_BUF_TYPE_OUTPUT, VIDEO_BUF_TYPE_INPUT, K_NO_WAIT);
274281
if (ret != 0 && ret != -EAGAIN) {
275-
LOG_ERR("Failed to transfer from %s to %s", video_dev->name, uvc_dev->name);
282+
LOG_ERR("Failed to transfer from %s to %s",
283+
uvc_src_dev->name, uvc_dev->name);
276284
return ret;
277285
}
278286

279-
ret = video_transfer_buffer(uvc_dev, video_dev,
287+
ret = video_transfer_buffer(uvc_dev, uvc_src_dev,
280288
VIDEO_BUF_TYPE_INPUT, VIDEO_BUF_TYPE_OUTPUT, K_NO_WAIT);
281289
if (ret != 0 && ret != -EAGAIN) {
282-
LOG_ERR("Failed to transfer from %s to %s", uvc_dev->name, video_dev->name);
290+
LOG_ERR("Failed to transfer from %s to %s",
291+
uvc_dev->name, uvc_src_dev->name);
283292
return ret;
284293
}
285294

0 commit comments

Comments
 (0)