Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F102190076
D41942.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D41942.diff
View Options
diff --git a/sys/dev/sound/usb/uaudio.c b/sys/dev/sound/usb/uaudio.c
--- a/sys/dev/sound/usb/uaudio.c
+++ b/sys/dev/sound/usb/uaudio.c
@@ -96,7 +96,7 @@
static int uaudio_default_rate = 0; /* use rate list */
static int uaudio_default_bits = 32;
static int uaudio_default_channels = 0; /* use default */
-static int uaudio_buffer_ms = 2;
+static int uaudio_buffer_ms = 4;
static bool uaudio_handle_hid = true;
static SYSCTL_NODE(_hw_usb, OID_AUTO, uaudio, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
@@ -110,6 +110,9 @@
SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, default_channels, CTLFLAG_RWTUN,
&uaudio_default_channels, 0, "uaudio default sample channels");
+#define UAUDIO_BUFFER_MS_MIN 1
+#define UAUDIO_BUFFER_MS_MAX 8
+
static int
uaudio_buffer_ms_sysctl(SYSCTL_HANDLER_ARGS)
{
@@ -121,10 +124,10 @@
if (err != 0 || req->newptr == NULL || val == uaudio_buffer_ms)
return (err);
- if (val > 8)
- val = 8;
- else if (val < 2)
- val = 2;
+ if (val > UAUDIO_BUFFER_MS_MAX)
+ val = UAUDIO_BUFFER_MS_MAX;
+ else if (val < UAUDIO_BUFFER_MS_MIN)
+ val = UAUDIO_BUFFER_MS_MIN;
uaudio_buffer_ms = val;
@@ -133,7 +136,7 @@
SYSCTL_PROC(_hw_usb_uaudio, OID_AUTO, buffer_ms,
CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, 0, sizeof(int),
uaudio_buffer_ms_sysctl, "I",
- "uaudio buffering delay from 2ms to 8ms");
+ "uaudio buffering delay in milliseconds, from 1 to 8");
#ifdef USB_DEBUG
static int uaudio_debug;
@@ -1310,13 +1313,60 @@
return (0);
}
+static uint32_t
+uaudio_get_interval_frames(const usb_endpoint_descriptor_audio_t *ed)
+{
+ uint32_t frames = 1;
+ /* Isochronous transfer interval is 2^(bInterval - 1) frames. */
+ if (ed->bInterval >= 1 && ed->bInterval <= 16)
+ frames = (1 << (ed->bInterval - 1));
+ /* Limit transfer interval to maximum number of frames. */
+ if (frames > UAUDIO_NFRAMES)
+ frames = UAUDIO_NFRAMES;
+ return (frames);
+}
+
+static uint32_t
+uaudio_get_buffer_ms(struct uaudio_softc *sc, uint32_t int_frames)
+{
+ uint32_t ms = 1;
+ uint32_t fps = usbd_get_isoc_fps(sc->sc_udev);
+ /* Make sure a whole USB transfer interval fits into the buffer. */
+ if (fps >= 1000 && int_frames > 0 && int_frames <= UAUDIO_NFRAMES) {
+ /* Convert interval frames to milliseconds. */
+ ms = ((int_frames * 1000) / fps);
+ }
+ /* Respect minimum buffer length set through buffer_ms tunable. */
+ if (ms < uaudio_buffer_ms)
+ ms = uaudio_buffer_ms;
+ /* Limit buffer length to 8 milliseconds. */
+ if (ms > UAUDIO_BUFFER_MS_MAX)
+ ms = UAUDIO_BUFFER_MS_MAX;
+ return (ms);
+}
+
static uint32_t
uaudio_get_buffer_size(struct uaudio_chan *ch, uint8_t alt)
{
struct uaudio_chan_alt *chan_alt = &ch->usb_alt[alt];
- /* We use 2 times 8ms of buffer */
- uint32_t buf_size = chan_alt->sample_size *
- howmany(chan_alt->sample_rate * (UAUDIO_NFRAMES / 8), 1000);
+ uint32_t int_frames, ms, buf_size;
+ /* USB transfer interval in frames, from endpoint descriptor. */
+ int_frames = uaudio_get_interval_frames(chan_alt->p_ed1);
+ /* Buffer length in milliseconds, and in bytes of audio data. */
+ ms = uaudio_get_buffer_ms(ch->priv_sc, int_frames);
+ buf_size = chan_alt->sample_size *
+ howmany(chan_alt->sample_rate * ms, 1000);
+ return (buf_size);
+}
+
+static uint32_t
+uaudio_max_buffer_size(struct uaudio_chan *ch, uint8_t alt)
+{
+ struct uaudio_chan_alt *chan_alt = &ch->usb_alt[alt];
+ uint32_t buf_size;
+ /* Maximum buffer length is 8 milliseconds. */
+ buf_size = chan_alt->sample_size *
+ howmany(chan_alt->sample_rate * UAUDIO_BUFFER_MS_MAX, 1000);
return (buf_size);
}
@@ -2626,7 +2676,7 @@
buf_size = 0;
for (x = 0; x != ch->num_alt; x++) {
- uint32_t temp = uaudio_get_buffer_size(ch, x);
+ uint32_t temp = uaudio_max_buffer_size(ch, x);
if (temp > buf_size)
buf_size = temp;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 9, 5:39 PM (20 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
14563538
Default Alt Text
D41942.diff (3 KB)
Attached To
Mode
D41942: snd_uaudio(4): Adapt buffer length to buffer_ms tunable.
Attached
Detach File
Event Timeline
Log In to Comment