Debian Codegraph @

third_party/rust/cubeb-coreaudio/README.md

raw
1 # cubeb-coreaudio-rs
2
3 [![CircleCI](https://circleci.com/gh/mozilla/cubeb-coreaudio-rs.svg?style=svg)](https://circleci.com/gh/mozilla/cubeb-coreaudio-rs)
4 [![Build & Test](https://github.com/mozilla/cubeb-coreaudio-rs/actions/workflows/test.yml/badge.svg)](https://github.com/mozilla/cubeb-coreaudio-rs/actions/workflows/test.yml)
5
6 *Rust* implementation of [Cubeb][cubeb] on [the MacOS platform][cubeb-au].
7
8 ## Current Goals
9
10 - Keep refactoring the implementation until it looks rusty! (it's translated from C at first.)
11 - Check the [todo list][todo]
12
13 ## Status
14
15 This is now the _Firefox_'s default audio backend on *Mac OS*.
16
17 ## Install
18
19 ### Install cubeb-coreaudio within cubeb
20
21 Run the following command:
22 ```sh
23 curl https://raw.githubusercontent.com/mozilla/cubeb-coreaudio-rs/trailblazer/build-audiounit-rust-in-cubeb.sh | sh
24 ```
25
26 ### Other
27
28 Just clone this repo
29
30 ## Test
31
32 Please run `sh run_tests.sh`.
33
34 Some tests cannot be run in parallel.
35 They may operate the same device at the same time,
36 or indirectly fire some system events that are listened by some tests.
37
38 The tests that may affect others are marked `#[ignore]`.
39 They will be run by `cargo test ... -- --ignored ...`
40 after finishing normal tests.
41 Most of the tests are executed in `run_tests.sh`.
42 Only those tests commented with *FIXME* are left.
43
44 ### Git Hooks
45
46 You can install _git hooks_ by running `install_git_hook.sh`.
47 Then _pre-push_ script will be run and do the `cargo fmt` and `cargo clippy` check
48 before the commits are pushed to remote.
49
50 ### Run Sanitizers
51
52 Run _AddressSanitizer (ASan), LeakSanitizer (LSan), MemorySanitizer (MSan), ThreadSanitizer (TSan)_
53 by `sh run_sanitizers.sh`.
54
55 The above command will run all the test suits in *run_tests.sh* by all the available _sanitizers_.
56 However, it takes a long time for finshing the tests.
57
58 ### Device Tests
59
60 Run `run_device_tests.sh`.
61
62 If you'd like to run all the device tests with sanitizers,
63 use `RUSTFLAGS="-Z sanitizer=<SAN>" sh run_device_tests.sh`
64 with valid `<SAN>` such as `address` or `thread`.
65
66 #### Device Switching
67
68 The system default device will be changed during our tests.
69 All the available devices will take turns being the system default device.
70 However, after finishing the tests, the default device will be set to the original one.
71 The sounds in the tests should be able to continue whatever the system default device is.
72
73 #### Device Plugging/Unplugging
74
75 We implement APIs simulating plugging or unplugging a device
76 by adding or removing an aggregate device programmatically.
77 It's used to verify our callbacks for minitoring the system devices work.
78
79 ### Manual Test
80
81 - Output devices switching
82 - `$ cargo test test_switch_output_device -- --ignored --nocapture`
83 - Enter `s` to switch output devices
84 - Enter `q` to finish test
85 - Device collection change
86 - `cargo test test_device_collection_change -- --ignored --nocapture`
87 - Plug/Unplug devices to see events log.
88 - Manual Stream Tester
89 - `cargo test test_stream_tester -- --ignored --nocapture`
90 - `c` to create a stream
91 - `d` to destroy a stream
92 - `s` to start the created stream
93 - `t` to stop the created stream
94 - `r` to register a device changed callback to the created stream
95 - `v` to set volume to the created stream
96 - `q` to quit the test
97 - It's useful to simulate the stream bahavior to reproduce the bug we found,
98 with some modified code.
99
100 ## TODO
101
102 See [todo list][todo]
103
104 ## Issues
105
106 - Atomic:
107 - We need atomic type around `f32` but there is no this type in the stardard Rust
108 - Using [atomic-rs](https://github.com/Amanieu/atomic-rs) to do this.
109 - `kAudioDevicePropertyBufferFrameSize` cannot be set when another stream using the same device with smaller buffer size is active. See [here][chg-buf-sz] for details.
110
111 ### Test issues
112
113 - Fail to run tests that depend on `AggregateDevice::create_blank_device` with the tests that work with the device event listeners
114 - The `AggregateDevice::create_blank_device` will add an aggregate device to the system and fire the device-change events indirectly.
115 - `TestDeviceSwitcher` cannot work when there is an alive full-duplex stream
116 - An aggregate device will be created for a duplex stream when its input and output devices are different.
117 - `TestDeviceSwitcher` will cached the available devices, upon it's created, as the candidates for default device
118 - Hence the created aggregate device may be cached in `TestDeviceSwitcher`
119 - If the aggregate device is destroyed (when the destroying the duplex stream created it) but the `TestDeviceSwitcher` is still working,
120 it will set a destroyed device as the default device
121 - See details in [device_change.rs](src/backend/tests/device_change.rs)
122
123 ## Branches
124
125 - [trailblazer][trailblazer]: Main branch
126 - [plain-translation-from-c][from-c]: The code is rewritten from C code on a line-by-line basis
127 - [ocs-disposal][ocs-disposal]: The first version that replace our custom mutex by Rust Mutex
128
129 [cubeb]: https://github.com/mozilla/cubeb "Cross platform audio library"
130 [cubeb-au]: https://github.com/mozilla/cubeb/blob/master/src/cubeb_audiounit.cpp "Cubeb AudioUnit"
131
132 [chg-buf-sz]: https://cs.chromium.org/chromium/src/media/audio/mac/audio_manager_mac.cc?l=982-989&rcl=0207eefb445f9855c2ed46280cb835b6f08bdb30 "issue on changing buffer size"
133
134 [todo]: todo.md
135
136 [bmo1572273]: https://bugzilla.mozilla.org/show_bug.cgi?id=1572273
137 [bmo1572273-c13]: https://bugzilla.mozilla.org/show_bug.cgi?id=1572273#c13
138
139 [from-c]: https://github.com/mozilla/cubeb-coreaudio-rs/tree/plain-translation-from-c
140 [ocs-disposal]: https://github.com/mozilla/cubeb-coreaudio-rs/tree/ocs-disposal
141 [trailblazer]: https://github.com/mozilla/cubeb-coreaudio-rs/tree/trailblazer