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

663 Коммитов

Автор SHA1 Сообщение Дата
Alex Chronopoulos 513727e5d9 Bug 1610527 - Update cubeb from upstream to d4b23d1. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D60518

--HG--
extra : moz-landing-system : lando
2020-01-22 13:59:51 +00:00
Alex Chronopoulos c75f44d0cb Bug 1610527 - Remove unnecessary patches from import script. r=padenot
`disable-assert.patch` is nor needed because the change has been merged upstream.
`revert-optimization.patch` is not needed because we want to undo the revert since this import attemptts to fix the crash.

Differential Revision: https://phabricator.services.mozilla.com/D60517

--HG--
extra : moz-landing-system : lando
2020-01-22 13:59:44 +00:00
Noemi Erli 6d247d8611 Backed out 2 changesets (bug 1610527) for causinf Linux debug and opt bustages in test_resampler.cpp a=backout
Backed out changeset 850bc97c56ab (bug 1610527)
Backed out changeset 71299532eee6 (bug 1610527)
2020-01-22 00:31:11 +02:00
Alex Chronopoulos cf314b852f Bug 1610527 - Update cubeb from upstream to 6cdf2fd. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D60518

--HG--
extra : moz-landing-system : lando
2020-01-21 15:32:54 +00:00
Alex Chronopoulos d46188be61 Bug 1610527 - Remove unnecessary patches from import script. r=padenot
`disable-assert.patch` is nor needed because the change has been merged upstream.
`revert-optimization.patch` is not needed because we want to undo the revert since this import attemptts to fix the crash.

Differential Revision: https://phabricator.services.mozilla.com/D60517

--HG--
extra : moz-landing-system : lando
2020-01-21 15:33:02 +00:00
Alex Chronopoulos 236f6c237f Bug 1604117 - Backout cubeb commit aa63601. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D59674

--HG--
extra : moz-landing-system : lando
2020-01-13 13:09:39 +00:00
Alex Chronopoulos c7942e4cd7 Bug 1603384 - Update cubeb from upstream to aa63601. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D56872

--HG--
extra : moz-landing-system : lando
2019-12-12 15:24:23 +00:00
Mike Hommey 7f4fff1db4 Bug 1601859 - Vendor cubeb-pulse-rs. r=kinetik
This technically breaks mach vendor rust because of the missing
licenses, but this will be fixed subsequently.

Differential Revision: https://phabricator.services.mozilla.com/D56161

--HG--
rename : media/libcubeb/cubeb-pulse-rs/AUTHORS => third_party/rust/cubeb-pulse/AUTHORS
rename : media/libcubeb/cubeb-pulse-rs/Cargo.toml => third_party/rust/cubeb-pulse/Cargo.toml
rename : media/libcubeb/cubeb-pulse-rs/LICENSE => third_party/rust/cubeb-pulse/LICENSE
rename : media/libcubeb/cubeb-pulse-rs/README.md => third_party/rust/cubeb-pulse/README.md
rename : media/libcubeb/cubeb-pulse-rs/src/backend/context.rs => third_party/rust/cubeb-pulse/src/backend/context.rs
rename : media/libcubeb/cubeb-pulse-rs/src/backend/cork_state.rs => third_party/rust/cubeb-pulse/src/backend/cork_state.rs
rename : media/libcubeb/cubeb-pulse-rs/src/backend/intern.rs => third_party/rust/cubeb-pulse/src/backend/intern.rs
rename : media/libcubeb/cubeb-pulse-rs/src/backend/mod.rs => third_party/rust/cubeb-pulse/src/backend/mod.rs
rename : media/libcubeb/cubeb-pulse-rs/src/backend/stream.rs => third_party/rust/cubeb-pulse/src/backend/stream.rs
rename : media/libcubeb/cubeb-pulse-rs/src/capi.rs => third_party/rust/cubeb-pulse/src/capi.rs
rename : media/libcubeb/cubeb-pulse-rs/src/lib.rs => third_party/rust/cubeb-pulse/src/lib.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-ffi/Cargo.toml => third_party/rust/pulse-ffi/Cargo.toml
rename : media/libcubeb/cubeb-pulse-rs/pulse-ffi/src/ffi_funcs.rs => third_party/rust/pulse-ffi/src/ffi_funcs.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-ffi/src/ffi_types.rs => third_party/rust/pulse-ffi/src/ffi_types.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-ffi/src/lib.rs => third_party/rust/pulse-ffi/src/lib.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/Cargo.toml => third_party/rust/pulse/Cargo.toml
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/src/context.rs => third_party/rust/pulse/src/context.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/src/error.rs => third_party/rust/pulse/src/error.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/src/lib.rs => third_party/rust/pulse/src/lib.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/src/mainloop_api.rs => third_party/rust/pulse/src/mainloop_api.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/src/operation.rs => third_party/rust/pulse/src/operation.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/src/proplist.rs => third_party/rust/pulse/src/proplist.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/src/stream.rs => third_party/rust/pulse/src/stream.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/src/threaded_mainloop.rs => third_party/rust/pulse/src/threaded_mainloop.rs
rename : media/libcubeb/cubeb-pulse-rs/pulse-rs/src/util.rs => third_party/rust/pulse/src/util.rs
extra : moz-landing-system : lando
2019-12-11 20:57:35 +00:00
Mike Hommey 1c4ef0191c Bug 1601859 - Vendor cubeb-coreaudio. r=padenot
This technically breaks mach vendor rust because of the missing
licenses, but this will be fixed subsequently.

Differential Revision: https://phabricator.services.mozilla.com/D56160

--HG--
rename : media/libcubeb/cubeb-coreaudio-rs/coreaudio-sys-utils/Cargo.toml => third_party/rust/coreaudio-sys-utils/Cargo.toml
rename : media/libcubeb/cubeb-coreaudio-rs/coreaudio-sys-utils/src/aggregate_device.rs => third_party/rust/coreaudio-sys-utils/src/aggregate_device.rs
rename : media/libcubeb/cubeb-coreaudio-rs/coreaudio-sys-utils/src/audio_object.rs => third_party/rust/coreaudio-sys-utils/src/audio_object.rs
rename : media/libcubeb/cubeb-coreaudio-rs/coreaudio-sys-utils/src/audio_unit.rs => third_party/rust/coreaudio-sys-utils/src/audio_unit.rs
rename : media/libcubeb/cubeb-coreaudio-rs/coreaudio-sys-utils/src/cf_mutable_dict.rs => third_party/rust/coreaudio-sys-utils/src/cf_mutable_dict.rs
rename : media/libcubeb/cubeb-coreaudio-rs/coreaudio-sys-utils/src/dispatch.rs => third_party/rust/coreaudio-sys-utils/src/dispatch.rs
rename : media/libcubeb/cubeb-coreaudio-rs/coreaudio-sys-utils/src/lib.rs => third_party/rust/coreaudio-sys-utils/src/lib.rs
rename : media/libcubeb/cubeb-coreaudio-rs/coreaudio-sys-utils/src/string.rs => third_party/rust/coreaudio-sys-utils/src/string.rs
rename : media/libcubeb/cubeb-coreaudio-rs/Cargo.toml => third_party/rust/cubeb-coreaudio/Cargo.toml
rename : media/libcubeb/cubeb-coreaudio-rs/LICENSE => third_party/rust/cubeb-coreaudio/LICENSE
rename : media/libcubeb/cubeb-coreaudio-rs/src/backend/aggregate_device.rs => third_party/rust/cubeb-coreaudio/src/backend/aggregate_device.rs
rename : media/libcubeb/cubeb-coreaudio-rs/src/backend/auto_array.rs => third_party/rust/cubeb-coreaudio/src/backend/auto_array.rs
rename : media/libcubeb/cubeb-coreaudio-rs/src/backend/auto_release.rs => third_party/rust/cubeb-coreaudio/src/backend/auto_release.rs
rename : media/libcubeb/cubeb-coreaudio-rs/src/backend/device_property.rs => third_party/rust/cubeb-coreaudio/src/backend/device_property.rs
rename : media/libcubeb/cubeb-coreaudio-rs/src/backend/mixer.rs => third_party/rust/cubeb-coreaudio/src/backend/mixer.rs
rename : media/libcubeb/cubeb-coreaudio-rs/src/backend/mod.rs => third_party/rust/cubeb-coreaudio/src/backend/mod.rs
rename : media/libcubeb/cubeb-coreaudio-rs/src/backend/resampler.rs => third_party/rust/cubeb-coreaudio/src/backend/resampler.rs
rename : media/libcubeb/cubeb-coreaudio-rs/src/backend/utils.rs => third_party/rust/cubeb-coreaudio/src/backend/utils.rs
rename : media/libcubeb/cubeb-coreaudio-rs/src/capi.rs => third_party/rust/cubeb-coreaudio/src/capi.rs
rename : media/libcubeb/cubeb-coreaudio-rs/src/lib.rs => third_party/rust/cubeb-coreaudio/src/lib.rs
extra : moz-landing-system : lando
2019-12-10 15:43:17 +00:00
Landry Breuil 6cd8db12f6 Bug 1596546: disable sndio lazy loading on OpenBSD, and directly link with it r=kinetik
unveil() work in bug #1580271 broke sound playback

Differential Revision: https://phabricator.services.mozilla.com/D53079

--HG--
extra : moz-landing-system : lando
2019-11-15 06:33:19 +00:00
Chun-Min Chang b98337f5cd Bug 1589931 - P2: Update cubeb-audiounit-rs to 0920240. r=padenot
Pick commits:
0920240 - Always return null-terminated strings from current_device (#25)

Differential Revision: https://phabricator.services.mozilla.com/D52880

--HG--
extra : moz-landing-system : lando
2019-11-14 21:00:16 +00:00
Chun-Min Chang bb5b523cb0 Bug 1590151 - Update cubeb-coreaudio-rs to cd954ca. r=padenot
Pick commits:
cd954ca - Update dependencies (#22)
7043a0c - Make audiounit_get_devices_of_type infallible (#21)

Differential Revision: https://phabricator.services.mozilla.com/D51725

--HG--
extra : moz-landing-system : lando
2019-11-07 16:41:44 +00:00
Chun-Min Chang 7f26e8dfa4 Bug 1591249 - Bump coreaudio-sys to 0.2.3. r=glandium
The current coreaudio-sys in gecko is a custom 0.2.2 version that used
to avoid the cross-compiling issue mentioned in bug 1569003. The issue
has been fixed in the coreaudio-sys 0.2.3, so we should follow the
upstream instead of using a custom version. As a result, the
coreaudio-sys would generate API bindings based on the MacOS SDK defined
in the build settings.

Differential Revision: https://phabricator.services.mozilla.com/D50531

--HG--
extra : moz-landing-system : lando
2019-10-31 20:14:00 +00:00
Chun-Min Chang 97ec12425c Bug 1590890 - Disable bindgen when building coreaudio-sys. r=glandium
Revert the coreaudio-sys dependency changed in bug 1589514, which causes
a trouble when compiling with sccache

Differential Revision: https://phabricator.services.mozilla.com/D50529

--HG--
extra : moz-landing-system : lando
2019-10-28 22:04:16 +00:00
Paul Adenot 12cabe50dd Bug 1590652 - Temporarily revert to using IAudioClient on Windows 10. r=kinetik
Differential Revision: https://phabricator.services.mozilla.com/D50242

--HG--
extra : moz-landing-system : lando
2019-10-23 21:19:36 +00:00
Chun-Min Chang d7aacc3bc4 Bug 1589514 - P2: Update cubeb-coreaudio-rs to 92e2e11. r=padenot
Depends on D50002

Differential Revision: https://phabricator.services.mozilla.com/D50003

--HG--
extra : moz-landing-system : lando
2019-10-22 11:46:55 +00:00
Chun-Min Chang d8668b05bc Bug 1589514 - P1: Update script importing cubeb-coreaudio-rs. r=padenot
Pick commits:
92e2e11 - minor style fix
5163960 - Update authors
fdb0b1d - Make utf8_from_cfstringref work with empty CFStringRef (#20)
a39bf5f - Remove a fixed issue

Differential Revision: https://phabricator.services.mozilla.com/D50002

--HG--
extra : moz-landing-system : lando
2019-10-22 11:46:32 +00:00
Jan Beich d354b5e3a2 Bug 1588669 - Allow ALSA/SNDIO lazy bindings after 81926b0c0d8c. r=kinetik
Differential Revision: https://phabricator.services.mozilla.com/D49258

--HG--
extra : moz-landing-system : lando
2019-10-15 09:33:33 +00:00
Paul Adenot c9cbd16860 Bug 1575883 - Update cubeb-pulse-rs to f9eb50b8. r=kinetik
Differential Revision: https://phabricator.services.mozilla.com/D47281

--HG--
extra : moz-landing-system : lando
2019-10-11 16:00:41 +00:00
Paul Adenot 1f614d2cd1 Bug 1575883 - Update cubeb-coreaudio-rs to fd242ea. r=kinetik
Differential Revision: https://phabricator.services.mozilla.com/D47278

--HG--
extra : moz-landing-system : lando
2019-10-11 15:44:18 +00:00
Paul Adenot 8088048155 Bug 1575883 - Update cubeb to a1200c34. r=kinetik
Differential Revision: https://phabricator.services.mozilla.com/D47277

--HG--
extra : moz-landing-system : lando
2019-10-11 16:05:55 +00:00
Paul Adenot 6571cd8b7b Bug 1575883 - Remove cubeb_panner.{cpp,h} from the cubeb update script. r=kinetik
Those files have been removed upstream.

Differential Revision: https://phabricator.services.mozilla.com/D47276

--HG--
extra : moz-landing-system : lando
2019-10-11 15:50:18 +00:00
Matthew Gregan 25b3f4cfbc Bug 1575131 - Update libcubeb for IAudioClient3 support on Win10. r=padenot
This picks up the work contributed by @ligfx in https://github.com/kinetiknz/cubeb/pull/530.

Differential Revision: https://phabricator.services.mozilla.com/D42590

--HG--
extra : moz-landing-system : lando
2019-08-26 07:52:25 +00:00
Chun-Min Chang 4c2709e357 Bug 1574644 - Update cubeb-coreaudio-rs to version 71faddb. r=kinetik
Differential Revision: https://phabricator.services.mozilla.com/D42382

--HG--
extra : moz-landing-system : lando
2019-08-16 22:20:30 +00:00
Chun-Min Chang 817f6f88f6 Bug 1570446 - P2: Update cubeb-coreaudio-rs to version ee0f981. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D39979

--HG--
extra : moz-landing-system : lando
2019-08-02 18:29:37 +00:00
Chun-Min Chang f29bfc124d Bug 1570446 - P1: Update script importing cubeb-coreaudio-rs to gecko. r=padenot
- Don't import the build settings since the settings in gecko is more
complicated.
- Print out the picked commits when running the scripts

Differential Revision: https://phabricator.services.mozilla.com/D40097

--HG--
extra : moz-landing-system : lando
2019-08-02 18:29:25 +00:00
Mike Hommey 7acef03e16 Bug 1569331 - Use the more traditional way to override dependencies for coreaudio-sys. r=froydnj
Differential Revision: https://phabricator.services.mozilla.com/D39579

--HG--
extra : moz-landing-system : lando
2019-07-27 00:35:09 +00:00
Mike Hommey 2919ab6ba3 Bug 1569003 - Disable bindgen when building coreaudio-sys. r=nalexander
This is the most immediate solution to the problem. This is how
automation ends up building things because it's cross-compiling and
cross-compiling falls back to the code path of that feature, and this
solves the immediate problem of builds not working out of the box.

The more long term fix would be to fix the coreaudio-sys crate to do the
right thing.

Differential Revision: https://phabricator.services.mozilla.com/D39447

--HG--
extra : moz-landing-system : lando
2019-07-26 03:54:13 +00:00
Paul Adenot 86d1623bc3 Bug 1567457 - Update cubeb-pulse-rs to version ee6666. r=kinetik
Reviewed upstream by :achronop, :kinetik, :chunmin in:
https://github.com/djg/cubeb-pulse-rs/pull/41
https://github.com/djg/cubeb-pulse-rs/pull/42
https://github.com/djg/cubeb-pulse-rs/pull/43
https://github.com/djg/cubeb-pulse-rs/pull/44
https://github.com/djg/cubeb-pulse-rs/pull/45

Differential Revision: https://phabricator.services.mozilla.com/D38661

--HG--
extra : moz-landing-system : lando
2019-07-23 12:03:23 +00:00
Paul Adenot b2b7b7837d Bug 1567480 - Update libcubeb to 0b5b52d. r=kinetik
Differential Revision: https://phabricator.services.mozilla.com/D38674

--HG--
extra : moz-landing-system : lando
2019-07-19 22:56:19 +00:00
Gurzau Raul 8517586551 Backed out 2 changesets (bug 1567457) for failures at test_getUserMedia_basicAudio_loopback.html on a CLOSED TREE.
Backed out changeset ce5d76c8be1b (bug 1567457)
Backed out changeset 35503df3d3e8 (bug 1567457)
2019-07-19 18:24:05 +03:00
Paul Adenot be57df7942 Bug 1567457 - Update cubeb-pulse-rs to version 3a748a2. r=kinetik
Reviewed upstream by :achronop, :kinetik, :chunmin in:
https://github.com/djg/cubeb-pulse-rs/pull/41
https://github.com/djg/cubeb-pulse-rs/pull/42

Differential Revision: https://phabricator.services.mozilla.com/D38661

--HG--
extra : moz-landing-system : lando
2019-07-19 13:36:44 +00:00
Chun-Min Chang ec036851de Bug 1530715 - P42: Remove unnecessary mutex. r=padenot
There are three potential data-race operations that may run at the same
time:
1. Data callback and stream reinitialization
2. Data callback and stream destroying
3. Stream reinitialization and stream destroying

The case 1 and 2 won't happen as long as the AudioOutputUnitStop is
called at the beginning of stream reinitialization and stream
destorying. The AudioOutputUnitStop requires to lock a mutex inside
CoreAudio framework that is also used by the data callback. Thus, if
there is a running callback, which holds the mutex inside CoreAudio
framework, when AudioOutputUnitStop is called, then the calling will
block the current thread until the data callback ends since it is
waiting for the mutex. By calling AudioOutputUnitStop at the beginning
of the stream reinitialization and stream destroying, the data race of
case 1 and 2 can be avoided.

On the other hand, the case 3 won't happen since the stream
initialization and destroying is run on the same task queue. The two
tasks on the same serial task queue are impossible to be run at the same
time. The mutex in AudioUnitStream is unnecessary because it's used for
the case 3.

Differential Revision: https://phabricator.services.mozilla.com/D34076

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:56 +00:00
Chun-Min Chang c4f1202ebd Bug 1530715 - P41: Remove OwnedCriticalSection in cubeb stream. r=padenot
The custom mutex, OwnedCriticalSection, in the current code comes with
the C-to-Rust translation work of cubeb_audiouniut.cpp. Its design is in
C style and not fitted well in the Rust. Rust has a better mutex design.

In the previous patches, all the data that may be touched on the
different threads are moved into a struct wrapped by a Rust mutex. Those
data will be touched in the critical sections created by the Rust mutex.
Therefore, this custom mutex becomes redundant. It's time to say goodbye
to it.

Differential Revision: https://phabricator.services.mozilla.com/D34074

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:58 +00:00
Chun-Min Chang 2c4a12e3b6 Bug 1530715 - P40: Move stream setup and close into a struct within a mutex. r=padenot
The core stream data that will be touched on the different threads when
the stream is created, reinitialized, destoryed should be used in the
critical section. Those core data are initialized in stream-setup and
destroyed in stream-close. The stream-setup and stream-close is run in
the critical section so they won't be executed at the same time.
Currently, the critical section is created by our custom mutex. However,
this custom mutex will be removed in the later mutex replacement.

Instead of running these two operations in the critical sections created
by the custom mutex, they should be moved into a struct wrapped by a
standard Rust mutex. As a result, at the end when the custom mutex is
removed, these two operations are still in the critical sections that
are created by the Rust mutex.

Differential Revision: https://phabricator.services.mozilla.com/D34073

--HG--
extra : moz-landing-system : lando
2019-07-10 08:07:00 +00:00
Chun-Min Chang 05ca07cf2a Bug 1530715 - P39: Move listeners (un)registrations into a strcut within a mutex. r=padenot
The listeners will be registered and unregistered on the different threads,
so the listeners should be used in the critical sections. We do create
critical sections by our own mutex. However, this custom mutex will be
gradually replaced by the standard Rust mutex in the following patches.

To replace the custom mutex, we put the listeners to the struct wrapped
by a Rust mutex and register or unregister the listeners in the critical
section created by this struct. At the end when the custom mutex is
removed, those operations are still in the critical sections.

Differential Revision: https://phabricator.services.mozilla.com/D34072

--HG--
extra : moz-landing-system : lando
2019-07-10 08:07:02 +00:00
Chun-Min Chang 36d0185bd8 Bug 1530715 - P38: Merge configure_input into setup. r=padenot
Calling configure_input requires borrowing AudioUnitStream as a
mutable. Merging configure_input into setup will help to avoid a
potential borrowing-twice issue in the later mutex replacement. There
will be a critical section created by a Rust mutex in the setup, which
will borrow the AudioUnitStream as an immutable.

Differential Revision: https://phabricator.services.mozilla.com/D34071

--HG--
extra : moz-landing-system : lando
2019-07-10 08:07:04 +00:00
Chun-Min Chang 49581ca4dc Bug 1530715 - P37: Merge configure_output into setup. r=padenot
Calling configure_output requires borrowing AudioUnitStream as a
mutable. Merging configure_output into setup will help to avoid a
potential borrowing-twice issue in the later mutex replacement. There
will be a critical section created by a Rust mutex in the setup, which
will borrow the AudioUnitStream as an immutable.

Differential Revision: https://phabricator.services.mozilla.com/D34070

--HG--
extra : moz-landing-system : lando
2019-07-10 08:07:06 +00:00
Chun-Min Chang c02d11403d Bug 1530715 - P36: Move out minimum_resampling_input_frames of output callback. r=padenot
Avoid calling minimum_resampling_input_frames by a borrowing from
AudioUnitStream

Differential Revision: https://phabricator.services.mozilla.com/D34069

--HG--
extra : moz-landing-system : lando
2019-07-10 08:07:08 +00:00
Chun-Min Chang 4f393e66ea Bug 1530715 - P35: Store layout in the stream instead of context. r=padenot
We store global layout info and channels info in the cubeb context.
However, the streams might output to different devices. We should store
the layout info of the output device in the stream directly instead of
in the context. On the other hand, the `channels` value is a duplicate
of `output_desc.mChannelsPerFrame` or `mixer.out_channels` so we don't
need to store this value.

Differential Revision: https://phabricator.services.mozilla.com/D34068

--HG--
extra : moz-landing-system : lando
2019-07-10 08:07:10 +00:00
Chun-Min Chang 6c5d3ff715 Bug 1530715 - P34: Merge layout_init into configure_output. r=padenot
1. Avoid calling layout_init by wrong AudioUnit value

2. Avoid calling layout getting/setting APIs by borrowing the
AudioUnitStream as a mutable. It will help to avoid the potential
borrowing-twice issues in the later mutex replacement.

Differential Revision: https://phabricator.services.mozilla.com/D34067

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:35 +00:00
Chun-Min Chang 93932acf07 Bug 1530715 - P33: Register and unregister the device-changed callbacks when stream setup and close. r=padenot
1. The code readability is slightly better if we can register and
unregister the callbacks in the same places. The device-chaned callbacks
are registered when stream setup and unregistered when stream close.

2. In the later mutex replacement, the core stream variables that may be
touched by different threads when reinitializing or destroying the
stream, including {in, out}_unit, will be wrapped in a Rust mutex.
Moving these callbacks (un)registration into the same places makes it
easier to find where the critical sections are.

Differential Revision: https://phabricator.services.mozilla.com/D34066

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:37 +00:00
Chun-Min Chang 56e7631637 Bug 1530715 - P32: Close the stream if failing in stream reinitialization. r=padenot
Before reporting the error by the state callback, closing the stream to
make sure the data callback and device-changed callback are
unregistered.

Differential Revision: https://phabricator.services.mozilla.com/D34065

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:39 +00:00
Chun-Min Chang f06595279a Bug 1530715 - P31: Merge render_input into audiounit_input_callback. r=padenot
1. If AudioUnitRender return kAudioUnitErr_CannotDoInCurrentContext
within a input-only stream, the input-only stream will keep feed silence
data into the buffer instead of reporting the error. With this change,
the error will be rendered as the returned value of the data callback to
the underlying CoreAudio framework.

2. By merging the render_input into audiounit_input_callback and adjust
the timing to call reinit_async, now the reinit_async is called at the
line that is out of the main logic for feeding buffer data. In the scope
of the main logic, there will be a critical section created by locking a
Rust mutex within AudioUnitStream in the later mutex replacement.
Without moving the reinit_async, which borrows AudioUnitStream as a
mutable, out of the critical section, there will be a borrowing-twice
issue.

Differential Revision: https://phabricator.services.mozilla.com/D34064

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:41 +00:00
Chun-Min Chang 7a27f19d14 Bug 1530715 - P30: Some clean-up in audiounit_output_callback. r=padenot
- Remove unnecessary mutabilities
- Remove duplicate API calls

Differential Revision: https://phabricator.services.mozilla.com/D34063

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:43 +00:00
Chun-Min Chang d637d53858 Bug 1530715 - P29: Move mixer to a struct within a mutex. r=padenot
The mixer of the stream will be created, reinitialized, used or
destroyed on different threads, so its operations should be in the
critical sections. We do create critical sections by our custom mutex.
However, this custom mutex will be gradually replaced by the standard
Rust mutex in the following patches.

To replace the custom mutex, we put the mixer to the struct wrapped by a
Rust mutex and do all the mixer operations in the critical section
created by this struct. At the end when the custom mutex is removed,
those operations are still in critical sections.

Calling notify_state_changed needs to borrow AudioUnitStream as a
mutuable. To avoid the borrowing-twice issue, the notify_state_changed
calling is moved out the scope of the critical section created in the
output data callback.

Differential Revision: https://phabricator.services.mozilla.com/D34062

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:45 +00:00
Chun-Min Chang 7efd386b4d Bug 1530715 - P28: Create a Mixer module. r=padenot
Using an Mixer struct to operate all the mixing APIs is a way to make
the code clearer. In addition, we can avoid calling mix function by
borrowing the AudioUnitStream as a mutable. It will help to avoid
potential borrowing-twice issues in the later mutex replacement.

Differential Revision: https://phabricator.services.mozilla.com/D34061

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:47 +00:00
Chun-Min Chang 2ac1419990 Bug 1530715 - P27: Move resampler to a struct within a mutex. r=padenot
The resampler of the stream will be created, reinitialized, used or
destroyed on different threads, so its operations should be in the
critical sections. We do create critical sections by our custom mutex.
However, this custom mutex will be gradually replaced by the standard
mutex in the following patches. To replace the custom mutex, we put the
resampler to the struct wrapped by a Rust mutex and do all the resampler
operations in the critical section created by this struct. At the end
when the custom mutex is removed, those operations are still in critical
sections.

Differential Revision: https://phabricator.services.mozilla.com/D34060

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:48 +00:00
Chun-Min Chang e8c9106144 Bug 1530715 - P26: Create a Resampler module. r=padenot
Using a resample struct to operate all its related operations will make
the code clearer.

Differential Revision: https://phabricator.services.mozilla.com/D34059

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:50 +00:00
Chun-Min Chang 43dfd443a9 Bug 1530715 - P25: Move aggregate_device to a struct within a mutex. r=padenot
The aggregate device of the stream may be created, reinitialized, or
destroyed on different threads, so its operations should be in the
critical sections. We do create critical sections by our custom mutex.
However, this custom mutex will be gradually replaced by the standard
Rust mutex in the following patches.

To replace the custom mutex, we create a struct wrapped by a Rust mutex
and create critical sections by this Rust mutex to do operations for
aggregate-device settings. At the end, not only aggregate-device
calls, but also other operations that needs to be locked will be
operated in the critical section created by this struct.

This is the beginning patch to replace the custom mutex in
AudioUnitStream.

Differential Revision: https://phabricator.services.mozilla.com/D34058

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:52 +00:00
Chun-Min Chang 3aa1456189 Bug 1530715 - P24: Create an AggregateDevice module. r=padenot
Using an aggregate-device struct to operate all the settings for the
aggregate device is a way to make the code clearer. In addition, we can
avoid calling some aggregate-device APIs by borrowing the
AudioUnitStream as a mutable. It will help to avoid potential
borrowing-twice issues in the later mutex replacement.

Differential Revision: https://phabricator.services.mozilla.com/D34057

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:54 +00:00
Chun-Min Chang 4c2db1a9e9 Bug 1530715 - P23: Avoid poisoning the mutex for device_changed_callback. r=padenot
The mutex is considered poisoned whenever a thread panics while holding
the mutex. Registering a second device changed callback without unregistering
the original callback makes the thread panics while holding the mutex
for the device_changed_callback. This mutex will be used when device
property changed callback. If the mutex is poisoned then a device
property is changed, we will get another panic when firing the callback
because of using a poisoned mutex.

Differential Revision: https://phabricator.services.mozilla.com/D34056

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:14 +00:00
Chun-Min Chang c53fb628bb Bug 1530715 - P22: Replace device_changed_callback_lock by standard Rust mutex. r=padenot
The registration, unregistration, and notification for the device
property changed is done in a critical section created by locking our
own custom mutex. To replace our own custom mutex by standard Rust
mutex, the critical section should be created by locking a standard Rust
mutex. This can be done by simply merging device_changed_callback and
device_changed_callback_lock into a Rust mutex variable.

Differential Revision: https://phabricator.services.mozilla.com/D34055

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:16 +00:00
Chun-Min Chang 74e3dce58a Bug 1530715 - P21: Replace set_buffer_size by set_buffer_size_sync and its friends. r=padenot
By moving out this API from the AudioUnitStream, we can avoid calling
it by borrowing the AudioUnitStream variable as a mutable. This will
help to avoid the potential borrowing-twice issues in the later mutex
replacement

In addition, the change applies an idiomatic way to wait for the system
callback event without consuming CPU time.

Differential Revision: https://phabricator.services.mozilla.com/D34054

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:18 +00:00
Chun-Min Chang 1edd33e172 Bug 1530715 - P20: Replace init_input_linear_buffer by create_auto_array. r=padenot
This change provides two benefits:

1. Setting variable by the Result value directly is rustier than setting
the variable by a mutual reference with a dummy Result that only
contains an error.

2. By moving out this API from the AudioUnitStream, we can avoid calling
it by borrowing the AudioUnitStream variable as a mutable. This will
help to avoid the potential borrowing-twice issues in the later mutex
replacement.

Differential Revision: https://phabricator.services.mozilla.com/D34053

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:20 +00:00
Chun-Min Chang 9e1bc8c79c Bug 1530715 - P19: Replace audio_stream_desc_init by create_stream_description. r=padenot
Setting variable by the Result value directly is rustier than setting
the variable by a mutual reference with a dummy Result that only
contains an error.

Differential Revision: https://phabricator.services.mozilla.com/D34052

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:22 +00:00
Chun-Min Chang 8c75b216bd Bug 1530715 - P18: Replace audiounit_create_unit by create_audiounit and its friends. r=padenot
Setting variable by the Result value directly is rustier than setting
the variable by a mutual reference with a dummy Result that only
contains an error.

Differential Revision: https://phabricator.services.mozilla.com/D34051

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:23 +00:00
Chun-Min Chang 907cf01736 Bug 1530715 - P17: Move get_volume out of AudioUnitStream. r=padenot
By moving get_volume out of AudioUnitStream, we can avoid unnecessary
borrowing from the AudioUnitStream variable. This change will make the
get_volume become symmetric to the set_volume.

Differential Revision: https://phabricator.services.mozilla.com/D34050

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:25 +00:00
Chun-Min Chang bd24fd4b75 Bug 1530715 - P16: Implement an internal set_volume API. r=padenot
By narrowing down the parameters that set_volume API needs, we can avoid
the unnecessary mutual borrowing from the AudioUnitStream variable. This
will help to avoid potential borrowing-twice issues in the later mutex
replacement.

Differential Revision: https://phabricator.services.mozilla.com/D34049

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:27 +00:00
Chun-Min Chang 37853f682b Bug 1530715 - P15: Replace set_device_info by create_device_info. r=padenot
Setting variable by the Result value directly is rustier than setting
the variable by a mutual reference with a dummy Result that only
contains the error.

Differential Revision: https://phabricator.services.mozilla.com/D34048

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:29 +00:00
Chun-Min Chang b2fb383839 Bug 1530715 - P14: Wrap state-callback code into a function. r=padenot
The code will be clearer if we can wrap the state-callback that notify
the state changed into a function. It will hide some details about
rendering the callback to C interface.

Differential Revision: https://phabricator.services.mozilla.com/D34047

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:31 +00:00
Chun-Min Chang c11a02e48f Bug 1530715 - P13: Remove unnecessary parameter in reinit. r=padenot
When the stream is re-initialized, the input unit and/or output unit
should be reset if they are currently used, no matter what scope (input
or output or in-output) the parameter requests.

Differential Revision: https://phabricator.services.mozilla.com/D34046

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:33 +00:00
Chun-Min Chang 7d493b1809 Bug 1530715 - P12: Remove the unused variable in AudioUnitStream. r=padenot
Removing expected_output_callbacks_in_a_row since it is not being used.

Differential Revision: https://phabricator.services.mozilla.com/D34045

--HG--
extra : moz-landing-system : lando
2019-07-10 08:05:55 +00:00
Chun-Min Chang 05f6e81727 Bug 1530715 - P11: Remove OwnedCriticalSection in cubeb context. r=padenot
The OwnedCriticalSection is a custom mutex directly translated from the
C code of the Cubeb library. Replacing the custom mutex by standard Rust
mutex make the code fit in the Rust design better and make debugging the
code easier. The variables protected by the custom mutex in the cubeb
context is moved to the Rust standard mutex in previous patches. The
custom mutex in the cubeb context is able to be removed since we no
longer rely on it.

Differential Revision: https://phabricator.services.mozilla.com/D29983

--HG--
extra : moz-landing-system : lando
2019-07-10 08:05:57 +00:00
Chun-Min Chang 1fe7bb3763 Bug 1530715 - P10: Avoid poisoning the mutex for device-collection-changed. r=padenot
The mutex is considered poisoned whenever a thread panics while holding
the mutex. Registering a second device-collection-changed callback
without unregistering the original callback makes the thread panics while
holding the mutex for the device-collection-changed variables. This
mutex will be used when the cubeb context is dropped. If the mutex is
poisoned, we will get another panic when dropping the cubeb context
because of using a poisoned mutex.

Differential Revision: https://phabricator.services.mozilla.com/D29982

--HG--
extra : moz-landing-system : lando
2019-07-10 08:05:59 +00:00
Chun-Min Chang 26cd170591 Bug 1530715 - P9: Move device-collection-changed variables to a struct within a mutex. r=padenot
The registration, unregistration, and notification for the device
collection changed is done in a critical section created by locking our
own custom mutex. To replace our own custom mutex by standard Rust
mutex, the critical section should be created by locking a standard Rust
mutex. This can be done by simply putting those varaibles for
device-collection-changed to a struct within a Rust mutex.

Differential Revision: https://phabricator.services.mozilla.com/D29981

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:00 +00:00
Chun-Min Chang b5c9d13587 Bug 1530715 - P8: Always use global latency frames to initialize the cubeb stream. r=padenot
The global latency frames in the cubeb context is the latency frames of
the first cubeb stream created in that cubeb context. The reason is
because latency frames cannot be changed when there is an active stream
operating in parallel. To make sure the latency won't be changed, the
latency frames of the streams after the first stream will be overwritten
by the global latency frames. Since we always use the global latency
frames, instead of overwritting latency frames of the later streams, we
could, we could simply initialize all the streams with the global
latency frames.

Differential Revision: https://phabricator.services.mozilla.com/D29980

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:02 +00:00
Chun-Min Chang 8fb9376269 Bug 1530715 - P7: Move active_streams to a struct within a mutex. r=padenot
The counting of the active streams in a cubeb context is calculated in a
critical section created by locking our own custom mutex. To replace our
own mutex by standard Rust mutex, the critical section calculating the
active streams should be created by locking a standard Rust mutex. This
can be done by simply putting the active_streams to a struct with a Rust
mutex.

Differential Revision: https://phabricator.services.mozilla.com/D29979

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:04 +00:00
Chun-Min Chang 9099a8f1b1 Bug 1530715 - P6: Fully initialize the aggregate device before using it. r=padenot
In the current implementation, we assume the aggregate device is created
immediately after calling the system API to create it, and we also
assume the sub-devices of the aggregate device are added immediately
upon we call the system API to set the sub-devices. Unfortunately, these
assumptions are not correct. Occasionally these settings are not
executed immediately, especially when they are not called on the main
thread (e.g., we may create an aggregate device off the main thread when
switching devices). Using the listeners monitoring the devices-changed
events can make sure those settings are done.

Differential Revision: https://phabricator.services.mozilla.com/D29978

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:08 +00:00
Chun-Min Chang f608e7a6f9 Bug 1530715 - P5: Remove the unused code when clamping latency frames. r=padenot
The clamp_latency function is only called when the cubeb context has one
stream only. In that case, clamp_latency will clamp the stream latency
frames in a safe range and then return the clamped value directly. The
code in clamp_latency for more than one streams doesn't be executed
since clamp_latency isn't called when there are more than one streams
within cubeb context. It's easier to read the code if the unused code is
removed.

Differential Revision: https://phabricator.services.mozilla.com/D29011

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:06 +00:00
Chun-Min Chang 0561641171 Bug 1530715 - P3: Build cubeb-coreaudio-rs in libcubeb. r=kinetik
Differential Revision: https://phabricator.services.mozilla.com/D23432

--HG--
extra : moz-landing-system : lando
2019-07-10 08:06:12 +00:00
Chun-Min Chang f6d72027f3 Bug 1530715 - P2: Import oxidized cubeb_audiounit.cpp. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D23431

--HG--
extra : moz-landing-system : lando
2019-07-17 04:48:25 +00:00
Chun-Min Chang 487c109761 Bug 1530715 - P1: Create an empty cubeb-coreaudio-rs crate in libcubeb. r=kinetik
To import cubeb-coreaudio-rs crate later, creating a dummy folder in
advance in libcubeb. It should be the mirrow of cubeb-coreaudio-rs crate
on github. The information of cubeb-coreaudio-rs is in README_MOZILLA.

Differential Revision: https://phabricator.services.mozilla.com/D23429

--HG--
extra : moz-landing-system : lando
2019-07-10 08:05:53 +00:00
Andreea Pavel 7853764e9d Backed out 42 changesets (bug 1530715) for SM build bustages on a CLOSED TREE
Backed out changeset 88ba94506737 (bug 1530715)
Backed out changeset 586d1b42a31b (bug 1530715)
Backed out changeset 7e7f5b9f2bf6 (bug 1530715)
Backed out changeset 7506b654e92f (bug 1530715)
Backed out changeset 518f85cf84a9 (bug 1530715)
Backed out changeset aca1e6806fc9 (bug 1530715)
Backed out changeset 70e97244daa8 (bug 1530715)
Backed out changeset 7c1e970c84a0 (bug 1530715)
Backed out changeset 9e10aa50ca0e (bug 1530715)
Backed out changeset 2a8d1c6faa33 (bug 1530715)
Backed out changeset bdc3110a40e9 (bug 1530715)
Backed out changeset bd809d3c5fd8 (bug 1530715)
Backed out changeset fe28daa92fc4 (bug 1530715)
Backed out changeset a964627f40c6 (bug 1530715)
Backed out changeset 3f3677f2980f (bug 1530715)
Backed out changeset e527edaabd65 (bug 1530715)
Backed out changeset 421e51bf612b (bug 1530715)
Backed out changeset 8f10a1790557 (bug 1530715)
Backed out changeset 0c5a0ed7203a (bug 1530715)
Backed out changeset 7fe0263794d3 (bug 1530715)
Backed out changeset ecd20933073e (bug 1530715)
Backed out changeset de4e23af5054 (bug 1530715)
Backed out changeset dcd65347e392 (bug 1530715)
Backed out changeset cd0e483df6be (bug 1530715)
Backed out changeset 9acd782f9450 (bug 1530715)
Backed out changeset b4809ada60dd (bug 1530715)
Backed out changeset 3742faad3806 (bug 1530715)
Backed out changeset bf15184c3c63 (bug 1530715)
Backed out changeset b6139a17a5fd (bug 1530715)
Backed out changeset dda297f7755a (bug 1530715)
Backed out changeset e98c1c0d561d (bug 1530715)
Backed out changeset 72c18b15e767 (bug 1530715)
Backed out changeset a8d7741d9134 (bug 1530715)
Backed out changeset 7562f780b687 (bug 1530715)
Backed out changeset 0cec8139038c (bug 1530715)
Backed out changeset 5ebf9b275f10 (bug 1530715)
Backed out changeset 7042c5c9c764 (bug 1530715)
Backed out changeset 4cd64e4037fa (bug 1530715)
Backed out changeset 48719d342b6f (bug 1530715)
Backed out changeset 0500179d3bbf (bug 1530715)
Backed out changeset 4bed62b601c6 (bug 1530715)
Backed out changeset 30f0b9853b0f (bug 1530715)
2019-07-10 10:56:00 +03:00
Chun-Min Chang 97c91ba03d Bug 1530715 - P42: Remove unnecessary mutex. r=padenot
There are three potential data-race operations that may run at the same
time:
1. Data callback and stream reinitialization
2. Data callback and stream destroying
3. Stream reinitialization and stream destroying

The case 1 and 2 won't happen as long as the AudioOutputUnitStop is
called at the beginning of stream reinitialization and stream
destorying. The AudioOutputUnitStop requires to lock a mutex inside
CoreAudio framework that is also used by the data callback. Thus, if
there is a running callback, which holds the mutex inside CoreAudio
framework, when AudioOutputUnitStop is called, then the calling will
block the current thread until the data callback ends since it is
waiting for the mutex. By calling AudioOutputUnitStop at the beginning
of the stream reinitialization and stream destroying, the data race of
case 1 and 2 can be avoided.

On the other hand, the case 3 won't happen since the stream
initialization and destroying is run on the same task queue. The two
tasks on the same serial task queue are impossible to be run at the same
time. The mutex in AudioUnitStream is unnecessary because it's used for
the case 3.

Differential Revision: https://phabricator.services.mozilla.com/D34076

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:07 +00:00
Chun-Min Chang a97f2bb079 Bug 1530715 - P41: Remove OwnedCriticalSection in cubeb stream. r=padenot
The custom mutex, OwnedCriticalSection, in the current code comes with
the C-to-Rust translation work of cubeb_audiouniut.cpp. Its design is in
C style and not fitted well in the Rust. Rust has a better mutex design.

In the previous patches, all the data that may be touched on the
different threads are moved into a struct wrapped by a Rust mutex. Those
data will be touched in the critical sections created by the Rust mutex.
Therefore, this custom mutex becomes redundant. It's time to say goodbye
to it.

Differential Revision: https://phabricator.services.mozilla.com/D34074

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:07 +00:00
Chun-Min Chang 381a586aed Bug 1530715 - P40: Move stream setup and close into a struct within a mutex. r=padenot
The core stream data that will be touched on the different threads when
the stream is created, reinitialized, destoryed should be used in the
critical section. Those core data are initialized in stream-setup and
destroyed in stream-close. The stream-setup and stream-close is run in
the critical section so they won't be executed at the same time.
Currently, the critical section is created by our custom mutex. However,
this custom mutex will be removed in the later mutex replacement.

Instead of running these two operations in the critical sections created
by the custom mutex, they should be moved into a struct wrapped by a
standard Rust mutex. As a result, at the end when the custom mutex is
removed, these two operations are still in the critical sections that
are created by the Rust mutex.

Differential Revision: https://phabricator.services.mozilla.com/D34073

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:07 +00:00
Chun-Min Chang 12e982f4e9 Bug 1530715 - P39: Move listeners (un)registrations into a strcut within a mutex. r=padenot
The listeners will be registered and unregistered on the different threads,
so the listeners should be used in the critical sections. We do create
critical sections by our own mutex. However, this custom mutex will be
gradually replaced by the standard Rust mutex in the following patches.

To replace the custom mutex, we put the listeners to the struct wrapped
by a Rust mutex and register or unregister the listeners in the critical
section created by this struct. At the end when the custom mutex is
removed, those operations are still in the critical sections.

Differential Revision: https://phabricator.services.mozilla.com/D34072

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:07 +00:00
Chun-Min Chang 59a0d37fb0 Bug 1530715 - P38: Merge configure_input into setup. r=padenot
Calling configure_input requires borrowing AudioUnitStream as a
mutable. Merging configure_input into setup will help to avoid a
potential borrowing-twice issue in the later mutex replacement. There
will be a critical section created by a Rust mutex in the setup, which
will borrow the AudioUnitStream as an immutable.

Differential Revision: https://phabricator.services.mozilla.com/D34071

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:06 +00:00
Chun-Min Chang ad3d63d477 Bug 1530715 - P37: Merge configure_output into setup. r=padenot
Calling configure_output requires borrowing AudioUnitStream as a
mutable. Merging configure_output into setup will help to avoid a
potential borrowing-twice issue in the later mutex replacement. There
will be a critical section created by a Rust mutex in the setup, which
will borrow the AudioUnitStream as an immutable.

Differential Revision: https://phabricator.services.mozilla.com/D34070

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:06 +00:00
Chun-Min Chang 03fce17902 Bug 1530715 - P36: Move out minimum_resampling_input_frames of output callback. r=padenot
Avoid calling minimum_resampling_input_frames by a borrowing from
AudioUnitStream

Differential Revision: https://phabricator.services.mozilla.com/D34069

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:06 +00:00
Chun-Min Chang fcb7b1184a Bug 1530715 - P35: Store layout in the stream instead of context. r=padenot
We store global layout info and channels info in the cubeb context.
However, the streams might output to different devices. We should store
the layout info of the output device in the stream directly instead of
in the context. On the other hand, the `channels` value is a duplicate
of `output_desc.mChannelsPerFrame` or `mixer.out_channels` so we don't
need to store this value.

Differential Revision: https://phabricator.services.mozilla.com/D34068

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:06 +00:00
Chun-Min Chang e20280cfce Bug 1530715 - P34: Merge layout_init into configure_output. r=padenot
1. Avoid calling layout_init by wrong AudioUnit value

2. Avoid calling layout getting/setting APIs by borrowing the
AudioUnitStream as a mutable. It will help to avoid the potential
borrowing-twice issues in the later mutex replacement.

Differential Revision: https://phabricator.services.mozilla.com/D34067

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:06 +00:00
Chun-Min Chang 7392d55799 Bug 1530715 - P33: Register and unregister the device-changed callbacks when stream setup and close. r=padenot
1. The code readability is slightly better if we can register and
unregister the callbacks in the same places. The device-chaned callbacks
are registered when stream setup and unregistered when stream close.

2. In the later mutex replacement, the core stream variables that may be
touched by different threads when reinitializing or destroying the
stream, including {in, out}_unit, will be wrapped in a Rust mutex.
Moving these callbacks (un)registration into the same places makes it
easier to find where the critical sections are.

Differential Revision: https://phabricator.services.mozilla.com/D34066

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:05 +00:00
Chun-Min Chang 142f9296b2 Bug 1530715 - P32: Close the stream if failing in stream reinitialization. r=padenot
Before reporting the error by the state callback, closing the stream to
make sure the data callback and device-changed callback are
unregistered.

Differential Revision: https://phabricator.services.mozilla.com/D34065

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:05 +00:00
Chun-Min Chang 661d951af8 Bug 1530715 - P31: Merge render_input into audiounit_input_callback. r=padenot
1. If AudioUnitRender return kAudioUnitErr_CannotDoInCurrentContext
within a input-only stream, the input-only stream will keep feed silence
data into the buffer instead of reporting the error. With this change,
the error will be rendered as the returned value of the data callback to
the underlying CoreAudio framework.

2. By merging the render_input into audiounit_input_callback and adjust
the timing to call reinit_async, now the reinit_async is called at the
line that is out of the main logic for feeding buffer data. In the scope
of the main logic, there will be a critical section created by locking a
Rust mutex within AudioUnitStream in the later mutex replacement.
Without moving the reinit_async, which borrows AudioUnitStream as a
mutable, out of the critical section, there will be a borrowing-twice
issue.

Differential Revision: https://phabricator.services.mozilla.com/D34064

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:05 +00:00
Chun-Min Chang 7c005b7f90 Bug 1530715 - P30: Some clean-up in audiounit_output_callback. r=padenot
- Remove unnecessary mutabilities
- Remove duplicate API calls

Differential Revision: https://phabricator.services.mozilla.com/D34063

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:05 +00:00
Chun-Min Chang c47370ecc1 Bug 1530715 - P29: Move mixer to a struct within a mutex. r=padenot
The mixer of the stream will be created, reinitialized, used or
destroyed on different threads, so its operations should be in the
critical sections. We do create critical sections by our custom mutex.
However, this custom mutex will be gradually replaced by the standard
Rust mutex in the following patches.

To replace the custom mutex, we put the mixer to the struct wrapped by a
Rust mutex and do all the mixer operations in the critical section
created by this struct. At the end when the custom mutex is removed,
those operations are still in critical sections.

Calling notify_state_changed needs to borrow AudioUnitStream as a
mutuable. To avoid the borrowing-twice issue, the notify_state_changed
calling is moved out the scope of the critical section created in the
output data callback.

Differential Revision: https://phabricator.services.mozilla.com/D34062

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:04 +00:00
Chun-Min Chang c7c35b3626 Bug 1530715 - P28: Create a Mixer module. r=padenot
Using an Mixer struct to operate all the mixing APIs is a way to make
the code clearer. In addition, we can avoid calling mix function by
borrowing the AudioUnitStream as a mutable. It will help to avoid
potential borrowing-twice issues in the later mutex replacement.

Differential Revision: https://phabricator.services.mozilla.com/D34061

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:04 +00:00
Chun-Min Chang aa39343ea4 Bug 1530715 - P27: Move resampler to a struct within a mutex. r=padenot
The resampler of the stream will be created, reinitialized, used or
destroyed on different threads, so its operations should be in the
critical sections. We do create critical sections by our custom mutex.
However, this custom mutex will be gradually replaced by the standard
mutex in the following patches. To replace the custom mutex, we put the
resampler to the struct wrapped by a Rust mutex and do all the resampler
operations in the critical section created by this struct. At the end
when the custom mutex is removed, those operations are still in critical
sections.

Differential Revision: https://phabricator.services.mozilla.com/D34060

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:04 +00:00
Chun-Min Chang 96aee8cca3 Bug 1530715 - P26: Create a Resampler module. r=padenot
Using a resample struct to operate all its related operations will make
the code clearer.

Differential Revision: https://phabricator.services.mozilla.com/D34059

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:04 +00:00
Chun-Min Chang 3481c83d49 Bug 1530715 - P25: Move aggregate_device to a struct within a mutex. r=padenot
The aggregate device of the stream may be created, reinitialized, or
destroyed on different threads, so its operations should be in the
critical sections. We do create critical sections by our custom mutex.
However, this custom mutex will be gradually replaced by the standard
Rust mutex in the following patches.

To replace the custom mutex, we create a struct wrapped by a Rust mutex
and create critical sections by this Rust mutex to do operations for
aggregate-device settings. At the end, not only aggregate-device
calls, but also other operations that needs to be locked will be
operated in the critical section created by this struct.

This is the beginning patch to replace the custom mutex in
AudioUnitStream.

Differential Revision: https://phabricator.services.mozilla.com/D34058

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:03 +00:00
Chun-Min Chang 7eed9af4a2 Bug 1530715 - P24: Create an AggregateDevice module. r=padenot
Using an aggregate-device struct to operate all the settings for the
aggregate device is a way to make the code clearer. In addition, we can
avoid calling some aggregate-device APIs by borrowing the
AudioUnitStream as a mutable. It will help to avoid potential
borrowing-twice issues in the later mutex replacement.

Differential Revision: https://phabricator.services.mozilla.com/D34057

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:03 +00:00
Chun-Min Chang 9cbaedd2cd Bug 1530715 - P23: Avoid poisoning the mutex for device_changed_callback. r=padenot
The mutex is considered poisoned whenever a thread panics while holding
the mutex. Registering a second device changed callback without unregistering
the original callback makes the thread panics while holding the mutex
for the device_changed_callback. This mutex will be used when device
property changed callback. If the mutex is poisoned then a device
property is changed, we will get another panic when firing the callback
because of using a poisoned mutex.

Differential Revision: https://phabricator.services.mozilla.com/D34056

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:03 +00:00
Chun-Min Chang b7048aa82e Bug 1530715 - P22: Replace device_changed_callback_lock by standard Rust mutex. r=padenot
The registration, unregistration, and notification for the device
property changed is done in a critical section created by locking our
own custom mutex. To replace our own custom mutex by standard Rust
mutex, the critical section should be created by locking a standard Rust
mutex. This can be done by simply merging device_changed_callback and
device_changed_callback_lock into a Rust mutex variable.

Differential Revision: https://phabricator.services.mozilla.com/D34055

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:03 +00:00
Chun-Min Chang b7dc2b7dae Bug 1530715 - P21: Replace set_buffer_size by set_buffer_size_sync and its friends. r=padenot
By moving out this API from the AudioUnitStream, we can avoid calling
it by borrowing the AudioUnitStream variable as a mutable. This will
help to avoid the potential borrowing-twice issues in the later mutex
replacement

In addition, the change applies an idiomatic way to wait for the system
callback event without consuming CPU time.

Differential Revision: https://phabricator.services.mozilla.com/D34054

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:02 +00:00
Chun-Min Chang 9b1165df4e Bug 1530715 - P20: Replace init_input_linear_buffer by create_auto_array. r=padenot
This change provides two benefits:

1. Setting variable by the Result value directly is rustier than setting
the variable by a mutual reference with a dummy Result that only
contains an error.

2. By moving out this API from the AudioUnitStream, we can avoid calling
it by borrowing the AudioUnitStream variable as a mutable. This will
help to avoid the potential borrowing-twice issues in the later mutex
replacement.

Differential Revision: https://phabricator.services.mozilla.com/D34053

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:02 +00:00
Chun-Min Chang 144d1b88b0 Bug 1530715 - P19: Replace audio_stream_desc_init by create_stream_description. r=padenot
Setting variable by the Result value directly is rustier than setting
the variable by a mutual reference with a dummy Result that only
contains an error.

Differential Revision: https://phabricator.services.mozilla.com/D34052

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:02 +00:00
Chun-Min Chang 0bcfbedb5a Bug 1530715 - P18: Replace audiounit_create_unit by create_audiounit and its friends. r=padenot
Setting variable by the Result value directly is rustier than setting
the variable by a mutual reference with a dummy Result that only
contains an error.

Differential Revision: https://phabricator.services.mozilla.com/D34051

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:02 +00:00
Chun-Min Chang ef2cf3df24 Bug 1530715 - P17: Move get_volume out of AudioUnitStream. r=padenot
By moving get_volume out of AudioUnitStream, we can avoid unnecessary
borrowing from the AudioUnitStream variable. This change will make the
get_volume become symmetric to the set_volume.

Differential Revision: https://phabricator.services.mozilla.com/D34050

--HG--
extra : moz-landing-system : lando
2019-07-09 19:57:01 +00:00