summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Meuser <jakemsr@cvs.openbsd.org>2010-10-18 23:12:41 +0000
committerJacob Meuser <jakemsr@cvs.openbsd.org>2010-10-18 23:12:41 +0000
commitfb66b24925bc93c7cd7cffe25d6eeb0fd7d8a783 (patch)
tree791bb4cd358cf0cfa2e90cfc3dfa621f7aa8b71e
parent1572f19ae4bd0f3a7cad5c89d6d4a27801b6a078 (diff)
use setting with closest matching bandwidth for the current configuration
instead of the first one that has enough bandwidth as it may be too much
-rw-r--r--sys/dev/usb/uvideo.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/sys/dev/usb/uvideo.c b/sys/dev/usb/uvideo.c
index 91d40e1b765..8d97b9a5e12 100644
--- a/sys/dev/usb/uvideo.c
+++ b/sys/dev/usb/uvideo.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvideo.c,v 1.142 2010/10/09 09:48:03 jakemsr Exp $ */
+/* $OpenBSD: uvideo.c,v 1.143 2010/10/18 23:12:40 jakemsr Exp $ */
/*
* Copyright (c) 2008 Robert Nagy <robert@openbsd.org>
@@ -1226,7 +1226,7 @@ uvideo_vs_set_alt(struct uvideo_softc *sc, usbd_interface_handle ifaceh,
const usb_descriptor_t *desc;
usb_interface_descriptor_t *id;
usb_endpoint_descriptor_t *ed;
- int i;
+ int i, diff, best_diff = INT_MAX;
usbd_status error;
uint32_t psize;
@@ -1253,19 +1253,26 @@ uvideo_vs_set_alt(struct uvideo_softc *sc, usbd_interface_handle ifaceh,
/* save endpoint with requested bandwidth */
psize = UGETW(ed->wMaxPacketSize);
psize = UE_GET_SIZE(psize) * (1 + UE_GET_TRANS(psize));
- if (psize >= max_packet_size) {
+ if (psize >= max_packet_size)
+ diff = psize - max_packet_size;
+ else
+ goto next;
+ if (diff < best_diff) {
+ best_diff = diff;
sc->sc_vs_cur->endpoint = ed->bEndpointAddress;
sc->sc_vs_cur->curalt = id->bAlternateSetting;
sc->sc_vs_cur->psize = psize;
- DPRINTF(1, "%s: set alternate iface to ", DEVNAME(sc));
- DPRINTF(1, "bAlternateSetting=0x%02x\n",
- id->bAlternateSetting);
- break;
+ if (diff == 0)
+ break;
}
next:
desc = usb_desc_iter_next(&iter);
}
+ DPRINTF(1, "%s: set alternate iface to ", DEVNAME(sc));
+ DPRINTF(1, "bAlternateSetting=0x%02x psize=%d max_packet_size=%d\n",
+ sc->sc_vs_cur->curalt, sc->sc_vs_cur->psize, max_packet_size);
+
/* set alternate video stream interface */
error = usbd_set_interface(ifaceh, i);
if (error) {