Граф коммитов

1003 Коммитов

Автор SHA1 Сообщение Дата
Paul Adenot 369c45504c Use cubeb-backend 0.10.3 2022-10-10 13:55:20 +02:00
Paul Adenot 3ba2ca6ef5 Don't log from other threads than the output thread, in duplex mode
This uses an spsc ring buffer to proxy the audio input callback
parameters to the output thread, for logging purposes.

Without this, multiple threads can attempt writing in the spsc ring
buffer that's used for logging, which make an assertion blow up.
2022-10-05 18:19:47 +02:00
Chun-Min Chang c33e609569 Fix clippy::bool-to-int-with-if
For further information: https://rust-lang.github.io/rust-clippy/master/index.html#bool_to_int_with_if
2022-09-14 09:52:58 -07:00
Paul Adenot ab933e7cbd Use the new async logging macros, fix various log messages 2022-08-17 11:11:24 -07:00
Chun-Min Chang fe6a7282a8 Allow failure of current_device
`AudioUnitStream::current_device` can fail when the default device has
no `kAudioDevicePropertyDataSource` value.
2022-07-26 16:14:14 -07:00
Paul Adenot 44eca95823 Querying kAudioUnitProperty_StreamFormat can return a channel count of 0 2022-04-20 11:00:23 -07:00
Chun-Min Chang a5a21ccbcc Always use frame count to read and write BufferManager 2022-04-13 16:02:42 +02:00
Chun-Min Chang 6b29728958 Correct the input frame calculation 2022-04-13 16:02:42 +02:00
Paul Adenot 214400933b
Fix device reinit when no input/output device are present (#173)
* Revert 8c1c57a, keeping the changes in 8b7d464

* Really attempt to create a device_info when reiniting to ensure a valid device is availble.

* Let the OS error out and propagate the error instead of asserting

* Revert "Let the OS error out and propagate the error instead of asserting"

This reverts commit a5fe4208cc.

* Revert "Really attempt to create a device_info when reiniting to ensure a valid device is availble."

This reverts commit 38896988d7.

* Revert "Revert 8c1c57a, keeping the changes in 8b7d464"

This reverts commit 0a82ab619f.

* Fix device reinit when no input/output device are present

Co-authored-by: Chun-Min Chang <chun.m.chang@gmail.com>
2022-04-12 18:35:15 -07:00
Matthew Gregan 39f7e696c1
Handle data_callback errors and signal to user via state_callback. (#169) 2022-03-29 11:11:26 -07:00
Chun-Min Chang 8b7d46422d
Use `get_channel_count` for `max_channel_count` (#168)
* Use get_channel_count for max_channel_count

We use `get_channel_count` for the max channel count in
`enumerate_devices` but we use `get_device_stream_format`'s channel info
for `max_channel_count`. We should use `get_channel_count` instead.

* Return OSStatus as error in get_channel_count

No need to return cubeb-error in non top-level API.
2022-03-29 11:00:37 -07:00
Chun-Min Chang 8c1c57a772
Return error for default device if it's `kAudioObjectUnknown` (#167)
* Shorten the function name

Rename `audiounit_get_default_device_id` to `get_default_device_id`.

* Return error for default device if it's kAudioObjectUnknown

The default output device on CircleCI server is `kAudioObjectUnknown`.
We should return error if we get this kind of device since all its
operations will be invalid.

* Add todo
2022-03-29 09:55:07 -07:00
Chun-Min Chang f1bf9c6089
Some cleanup (#165)
* Fix typo

* Change returned value of audiounit_get_default_device_id and its friends
2022-03-28 11:54:17 -07:00
Chun-Min Chang 0dbb6ef2b6
Correct the master device of the aggregate device (#166)
We should set the master device of the aggregate device to the output
device of the aggregate device, instead of the default output device.
2022-03-28 10:59:14 -07:00
Paul Adenot e012b2151f Don't multiply by zero when getting the input latency with different hw vs. user rates 2022-03-25 17:34:31 +01:00
Paul Adenot c13f579bc9 When the default output or input are selected, and the device disappears, the new defaults should be used 2022-03-25 17:34:20 +01:00
Paul Adenot 14a712c4f5 Use the user-provided rate to open the output device, and not the hardware rate 2022-03-25 12:17:05 +01:00
Paul Adenot b313a83c0a Restore the ability to open a stream with more channels than the output device has channels
The mixer handles it. This allows playing e.g. a 5.1 file correctly on
2.0 hardware.
2022-03-22 15:28:54 +01:00
Paul Adenot 84a7515bd8 Use kAudioDeviceTransportTypeBuiltIn from coreaudio-sys 2022-03-22 11:31:30 +01:00
Paul Adenot 4d017ee7ed Don't use an aggregate device if either device is already an aggregate device 2022-03-22 11:31:30 +01:00
Chun-Min Chang 8cbeb55265 review changes 2022-03-22 11:31:30 +01:00
Paul Adenot 0921daf037 Refactor various audio input parameter.
Remove input_channels_to_ignore from CoreStreamData, and pass it
directly to the BufferManager.

Refactor input_desc so that it's always what we set the input audiounit
to, and subsequently remove input_hw_rate, because it's redundant with
input_desc.mSamplerate.
2022-03-22 11:31:30 +01:00
Paul Adenot d9240043e0 Remove is_device_a_type_of and its test 2022-03-22 11:31:30 +01:00
Paul Adenot d85a02ab65 Extract a function to fill the audio-channel related part of a AudioStreamBasicDescription 2022-03-22 11:31:30 +01:00
Paul Adenot 71b6c53f6c Mark function test-only 2022-03-22 11:31:30 +01:00
Paul Adenot d820ca152f Always use aggregate devices 2022-03-22 11:31:30 +01:00
Paul Adenot 8ad4d4d672 Write a specialized input remixer that can move channels around and mix down in a very small set of circumstances
We don't want to use the regular mixer here, we can do everything in
place, always, and make it very efficient. Also it's specialized and
only handles very few cases.

When using an aggregate device, it can be that the output device has
input channels. Those input channels are delivered in the input callback
as usual, in the same buffer as the input channels of the input device
we care about. The channels for the output device are _always_ first in
the buffer, followed by the channels for the inpuut device, because of
the way the aggregate device is setup (see aggregate_device.rs).

This patch allows remixing the data, dropping the channels we don't want
and putting the frames for the channels the user wants at the right
location in the buffer.
2022-03-22 11:31:30 +01:00
Paul Adenot 9588fc78f4 When using an aggregate device, and the device used as an output device has input channels, determine how many channels it has 2022-03-22 11:31:30 +01:00
Paul Adenot 3071ba936b Error out when attempting to open an input stream with more channel than the device has 2022-03-22 11:31:30 +01:00
Paul Adenot 79ae42d59b Reclock if not in the same clock domain, or if not using an aggregate device 2022-03-22 11:31:30 +01:00
Paul Adenot f99b842a39 Make aggregate_device an Option 2022-03-22 11:31:30 +01:00
Paul Adenot d82f5e78ff Update ABI for cubeb_resampler_create changes, allow selecting the quality at the call site 2022-03-22 11:31:30 +01:00
Paul Adenot 916d5017c5 Bump cubeb to 0.10 2022-03-22 11:31:30 +01:00
Paul Adenot 82d7f134c9 Increase the ring buffer size: multiple input callback can fire in a row 2022-03-22 11:31:30 +01:00
Paul Adenot 65c0fe3d73 Fix comment. 2022-03-21 15:41:01 +01:00
Chun-Min Chang a813e3282d Close the stream before entering error state 2022-03-21 15:41:01 +01:00
Chun-Min Chang d345869ec1 Show default device before running tests 2022-03-21 15:37:07 +01:00
Chun-Min Chang ec3709f396 Show device list in scope before running tests 2022-03-21 15:37:07 +01:00
Chun-Min Chang b2b5d423b2 Monitor default-input change only when following default input device
We always monitor the default input changed event even if we don't use
the default input device. As a result, one audio stream has an input can
be re-initialized even if its device has no change at all (e.g., When
default input device is X and the input stream S uses device Y as its
input device, the S will be re-initialized if the system default device
is changed from X to Z, where X, Y, Z are all different devices.).

To avoid the above problem, and not to reinitialize the stream, when it
has input, we should monitor the default-input change only when the user
requests to follow the system default input.
2022-03-16 17:32:45 -07:00
Chun-Min Chang f1d599efb2 Reword comments for the event listeners 2022-03-16 17:32:45 -07:00
Chun-Min Chang 9ae1359cfa Remoe DEV_SYSTEM_DEFAULT 2022-03-16 16:58:32 -07:00
Chun-Min Chang fc85d97f57 No need to use kAudioUnitSubType_DefaultOutput 2022-03-16 16:58:32 -07:00
Chun-Min Chang acf8aca4cf Correct typo 2022-03-16 16:58:32 -07:00
Chun-Min Chang 99568f4ff2 Remove outdated comment
The reinit behavior is changed in #154.  This comment is incorrect now.
2022-03-16 16:58:32 -07:00
Chun-Min Chang ca183a83c7 Avoid firing multiple device_changed_callback
In the current code, theoretically we can fire multiple
device_changed_callbacks at one event handler, but we will at most
re-initialize stream once. There is no need to fire multiple callbacks
if we only reinitialize stream once.
2022-03-14 09:35:44 -07:00
Chun-Min Chang 21cea9ceb3 Don't switch input when using non-default device
By the comments [1,2] in the BMO 1735201, we should not switch the input
device behind the scenes when users specify what devices they want. That
is, we should not automatically re-initialize the input or duplex stream
when the input device is gone. We will get a device-collection changed
event as well when this happen and Gecko/Firefox will stop the paired
MediaStreamTrack soon in this case.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1735201#c0
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1735201#c11
2022-03-14 09:35:44 -07:00
Chun-Min Chang 1607f2f0d3 Only ignore DeviceIsAlive event if no other events
From the callback API pattern, theoretically it's possible to get
multiple events at the same time. We used to ignore
`kAudioDevicePropertyDeviceIsAlive` event and do nothing when the device
is system input without checking if we have other events at that moment
or not. If we do have other events, we should run other event handler
rather than do nothing in this case.
2022-03-14 09:35:44 -07:00
Chun-Min Chang a616bf062f Simplify the event logs 2022-03-14 09:35:44 -07:00
Chun-Min Chang 720c797d12 Make PropertySelector enum 2022-03-14 09:35:44 -07:00
Chun-Min Chang cde02a7627 Assert we won't get unexpected events 2022-03-14 09:35:44 -07:00