diff --git a/packages/usb/usb-host-audio/usb/host/audio.py b/packages/usb/usb-host-audio/usb/host/audio.py index 7228c944..3c7cd641 100644 --- a/packages/usb/usb-host-audio/usb/host/audio.py +++ b/packages/usb/usb-host-audio/usb/host/audio.py @@ -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) @@ -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() diff --git a/tests/test_usb_host_streams.py b/tests/test_usb_host_streams.py index 73585826..2bcd64d0 100644 --- a/tests/test_usb_host_streams.py +++ b/tests/test_usb_host_streams.py @@ -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)) @@ -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)