Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/usb/usb-host-audio/usb/host/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
_MAX_SUBRANGES = 8
_DEFAULT_RING = 8192 # about 43 ms of 48 kHz stereo
_E2BIG = 7 # the host refused an endpoint too big for its FIFO
_ENOSPC = 28 # the hub in front of a full-speed device has no bus time left
# What the host answers for a stream whose device has gone: ENOENT once the
# stream is torn down, ENODEV while it is going.
_GONE = (2, 19)
Expand Down Expand Up @@ -179,6 +180,10 @@ def _start(self, ring, rate):
raise OSError(_E2BIG, "endpoint 0x%02x declares %d-byte packets, more than this board's "
"USB host can buffer (its sizes are printed above)"
% (s.endpoint, s.max_packet & 0x7FF))
if e.errno == _ENOSPC:
raise OSError(_ENOSPC, "the high-speed hub in front of this full-speed device has no bus "
"time left for this stream; stop another audio stream on that hub, or "
"choose a lower rate or fewer channels")
raise OSError("the interface claim was refused (%s); for a speaker, start the host with "
"usb.core.start(classes=(\"uac\",))" % e)
self._set_rate()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_usb_host_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def _host_poll(self, dev_id, ep, buf):
def host_claim(self, dev_id, itf, alt=0):
if self.refuse_claim == "too big":
raise OSError(7, "E2BIG")
if self.refuse_claim == "no room":
raise OSError(28, "ENOSPC")
if self.refuse_claim:
raise OSError(16, "EBUSY")
self.calls.append(("claim", itf, alt))
Expand Down Expand Up @@ -336,6 +338,16 @@ def test_an_endpoint_too_big_for_the_fifo_says_its_size(self):
self.assertNotIn("classes=", str(e.exception))


def test_a_hub_with_no_bus_time_left_says_so(self):
host.reset(_uac2_blob(), refuse_claim="no room")
spk = Speaker(device(), rate=48000)
with self.assertRaises(OSError) as e:
spk.start()
self.assertEqual(28, e.exception.errno)
self.assertIn("no bus time left", str(e.exception))
self.assertNotIn("classes=", str(e.exception))


class TestMicrophone(unittest.TestCase):
def test_reads_whole_frames_from_the_ring(self):
host.reset(_CODEC)
Expand Down