https://bugzilla.mozilla.org/show_bug.cgi?id=1825328 landed in Firefox
without going through upstream. It's necessary to build in an
environment where gtests are all compiled in the same executable.
Original patch by serge-sans-paille <sguelton@mozilla.com>.
Also clear out the memory used by the async logger when it's shut down.
This relies on the fact that enabling and disabling logging is performed
on the same thread, but I think this is a reasonnable thing to do. We
could assert it though.
audiounit-rust backend will return an error instead of hitting an
assertion when registering a callback by calling
`cubeb_stream_register_device_changed_callback` without unregistering
the registered callback. It's not possible to run a death test in gtest
for the Rust API[1]
[1] https://users.rust-lang.org/t/how-to-write-a-death-test-in-gtest-for-rust-apis/23575
* resampler: handle explicitly the case that input frames are less than output frames
* Review comments
* resampler: stop expecting input number of frames equal to output
* resampler: report correctly the input frames used
* resampler: add unit tests for passthrough_resampler::fill
* tests: check correctly the audio buffer values range (BMO 1484541).
* tests: create a comfortable way to enable logs in tests
* duplex test: check audio range correctly and change the input channel to stereo to avoid AD mixer (BMO 1484541).
* test_duplex: Revert back input channel to mono
* Add a test for cubeb_stream_get_current_device() and cubeb_stream_device_destroy()
* Reduce duplicates in audiounit_stream_get_current_device()
The audiounit_stream_get_current_device() will set the default device's name for input and output by the following steps:
1. Get default device's data, whose type is uint32
2. Convert the uint32 data into a string
3. Set the string into cubeb_device's name
Hence we can split it into functions to do the above steps:
i. audiounit_get_default_device_data(...)
Do the step 1
ii. allocate_and_convert_uint32_into_string(...)
Do the step 2 and 3. It will allocate memory for a string and put the converted string right there. (If we don't allocate and then set the values into the memory at the same time, we need to find a way to check the memory's boundary.)
They are called by a function named audiounit_get_default_device_name(...), with cubeb_device_type parameter to set the device name of input or output. And audiounit_get_default_device_name(...) will be used in audiounit_stream_get_current_device().
* Replace allocate_and_convert_uint32_into_string(...) by convert_uint32_into_string(...)
1. Rename allocate_and_convert_uint32_into_string(...) to convert_uint32_into_string(...)
2. Return a unique_ptr<char[]> from convert_uint32_into_string(...) pointing to an allocated memory
* Hard-coding the convertion from uint32 into string
This change is to make sure the conversion only ever needs to handle 4 bytes.
* Add more information to log when calling audiounit_stream_get_current_device(...)
We add a log with error message when we cannot get datasource data from the devices. However, we don't return an error code in this case since it's quite common when we try getting that data from USB devices. We will convert the datasource data into a string. If there is no data, the string is empty. Instead of logging when we cannot get the datasource data, it's better to log that the converted name is empty. It'll give more meaning (Users are more likely confused about what the empty datasource means.).
* Rename audiounit_get_default_device_data() to audiounit_get_default_device_datasource()
We should use an explicit name for this function since the same device will return different datasources. For example, the default input device on macbook pro will return "imic" if it uses the default internal microphone or "emic" when it uses an external microphone plugged in audio jack.
TODO: it's better to rename audiounit_stream_get_current_device to audiounit_stream_get_current_device_source. The reason is same as above.
This addresses the thread local COM initialization lifetime problem
discussed in issue #416 by moving the responsibility for COM
initialization from within cubeb to the caller.
* Add QUAD and QUAD_LFE layouts.
* Remove dual mono layout.
It makes no sense to have a case for those as the data structure
used (a bitmask) do not allow to represent this channel layout (a
channel can only be present once). As such it was a non-functional
layout
* Fix up cubeb_pulse compilation using C++ keyword.
* Remove the concept of preferred layout.
Channel layout is derived by the content being played. The concept of
preferred layout is meaningless. Either we have a layout defined, or
we don't. There's no in-between.
So we remove it.
* Remove CHANNEL_MONO concept.
* Add cubeb_sample_size convenience method.
* Rework cubeb_mixer.
This completely replace the existing remixer which had serious limitations:
1- Had no memory bound checks
2- Could only downmix 5.1 and 7.1 to stereo.
This mixer allows to convert from any sane layout to any other and work directly on interleaved samples.
This cubeb_mixer doesn't have an API compatible with the previous one.
This commit is non-fonctional, and was split for ease of review.
* Fix remixing on mac, windows and pulse backend.
* Make cubeb_mixer creation infallible.
Rather than ignore nonsensical layouts, we attempt to play it according to the stream channels count instead. The audio data will be played as-is, dropping the extra channels or inserting silence where needed.
* User proper sample size when calculating offsets.
Should the user data be of a different type to what the AudioUnit output is set to, we would have written outside the end of our allocated buffer.
* Fix input mixing and clarify frames vs samples terminology
* If a layout is unknown or invalid, always treat it as plain stereo or mono.
- For the silent loopback test we check that we don't get any sound above an
epsilon. The value of this epsilon has been increased to accommodate a wider
range of systems.
- The delay on all tests has been increased to allow for more time to capture
looped samples. The original 150ms delay was sufficient on the machine I tested
with, however, I've seen the tests fail due to not having enough looped input.
* Add an automated test to ensure creating a duplex stream with a device collection changed callback works.
* Fix a deadlock
When creating an aggregate device, and a device collection change callback was
installed, a deadlock occured, because the device collection change listener was
being called synchronously.
Use GCD to send a task to a serial queue, and carefuly unlock the mutex in
audiounit_stream_destroy to not deadlock on the queue.
* Don't call the device collection change callback when creating cubeb's own aggregate device.
* Remove std:: prefix, there is a using namespace std; now.
* Address review comments
* Address even more comments.
- Fix indentation in header
- Adjust spacing for casts and pointer + ref declarations
- Adjust comments in test about locking after stop
- Simplify default device selection when loopback is involved
Add a test file for loopback tests and add to build script. This file is
currently configured to be Windows only in build scripts, as the WASAPI backend
is currently the only backend supporting the new loopback interface.
Add a test for duplex streams using the default output device and a loopback
from the same device.