From 1de92303636815f0353ca2bd761f08ea38b8661b Mon Sep 17 00:00:00 2001 From: mglocker Date: Mon, 14 Jul 2008 19:57:36 +0000 Subject: [PATCH] Make VIDIOC_ENUM_FMT list all available formats for the attached device. --- sys/dev/usb/uvideo.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/sys/dev/usb/uvideo.c b/sys/dev/usb/uvideo.c index 86df7d34944..8179b921607 100644 --- a/sys/dev/usb/uvideo.c +++ b/sys/dev/usb/uvideo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvideo.c,v 1.52 2008/07/14 04:45:50 mglocker Exp $ */ +/* $OpenBSD: uvideo.c,v 1.53 2008/07/14 19:57:36 mglocker Exp $ */ /* * Copyright (c) 2008 Robert Nagy @@ -1990,25 +1990,50 @@ int uvideo_enum_fmt(void *v, struct v4l2_fmtdesc *fmtdesc) { struct uvideo_softc *sc = v; + int idx; - if (fmtdesc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || - fmtdesc->index > 0) + if (fmtdesc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + /* type not supported */ return (EINVAL); - /* - * XXX We need to create a sc->sc_desc_format pointer array - * which contains all available format descriptors. - */ - switch (sc->sc_fmtgrp_cur->format->bDescriptorSubtype) { + idx = fmtdesc->index + 1; + if (idx == UVIDEO_MAX_FORMAT || sc->sc_fmtgrp[idx].format == NULL) + /* no more formats left */ + return (EINVAL); + + switch (sc->sc_fmtgrp[idx].format->bDescriptorSubtype) { case UDESCSUB_VS_FORMAT_MJPEG: fmtdesc->flags = V4L2_FMT_FLAG_COMPRESSED; (void)strlcpy(fmtdesc->description, "MJPEG", sizeof(fmtdesc->description)); + fmtdesc->pixelformat = V4L2_PIX_FMT_MJPEG; + bzero(fmtdesc->reserved, sizeof(fmtdesc->reserved)); + break; + case UDESCSUB_VS_FORMAT_UNCOMPRESSED: + fmtdesc->flags = 0; + if (!strcmp(sc->sc_fmtgrp[idx].format->u.uc.guidFormat, + "YUY2")) { + (void)strlcpy(fmtdesc->description, "YUYV", + sizeof(fmtdesc->description)); + fmtdesc->pixelformat = V4L2_PIX_FMT_YUYV; + } else if (!strcmp(sc->sc_fmtgrp[idx].format->u.uc.guidFormat, + "NV12")) { + (void)strlcpy(fmtdesc->description, "NV12", + sizeof(fmtdesc->description)); + fmtdesc->pixelformat = V4L2_PIX_FMT_NV12; + } else { + (void)strlcpy(fmtdesc->description, "Unknown UC Format", + sizeof(fmtdesc->description)); + fmtdesc->pixelformat = 0; + } + bzero(fmtdesc->reserved, sizeof(fmtdesc->reserved)); break; default: fmtdesc->flags = 0; (void)strlcpy(fmtdesc->description, "Unknown Format", sizeof(fmtdesc->description)); + fmtdesc->pixelformat = 0; + bzero(fmtdesc->reserved, sizeof(fmtdesc->reserved)); break; } -- 2.20.1