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

909 Коммитов

Автор SHA1 Сообщение Дата
Andreas Pehrson 5752eb7bba Shut down audio dump streams on destroy 2023-10-11 11:21:18 +02:00
Paul Adenot ebd5fac8b1 WIP: Log audio directly from input/output callbacks 2023-09-25 17:28:53 +02:00
Paul Adenot 5370bb98ab
Bump bitflags to version 2 (#184)
* Bump bitflags to version 2

* clippy --fix

* fmt

* Remove unnecessary cast

* Remove unnecessary mut ref

---------

Co-authored-by: Chun-Min Chang <chun.m.chang@gmail.com>
2023-07-25 16:16:06 -07:00
Matthew Gregan 93b5c01a13 Remove `also_mutexed_stm` pattern when making serial queue calls.
The lifetime of the stream is guaranteed to outlive any items running on the
serial queue.  This is ensured by stream destroy flushing the serial queue
before freeing stream resources.
2022-10-25 08:53:59 +13:00
Matthew Gregan 12580cad8b Use serial queue to stop AudioUnits when handling errors in a render callback.
Avoids a possible deadlock inside CoreAudio if another thread calls
AudioOutputUnitStop concurrently.  The thread running the render callback holds
the HALB_Mutex and blocks acquiring the CAMutex inside AudioOutputUnitStop.
The racing thread calling AudioOutputUnitStop holds the CAMutex and blocks
acquiring the HALB_Mutex.
2022-10-25 08:51:11 +13:00
Paul Adenot 1cba37c0c1 Fix new errors reported by clippy on Nightly 2022-10-10 14:16:37 -07:00
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