Commit Graph

744 Commits

Author SHA1 Message Date
mitchmindtree 5e4f384992 Refactor `Host` and related traits into a new `traits` module
This is a draft implementation of #294. I'll leave this open for
feedback and potentially better trait naming suggestions or better
solutions in general!

cc @ishitatsuyuki
2019-06-29 14:45:15 +02:00
mitchmindtree 36dee482bd
Merge pull request #290 from mitchmindtree/macos_condvar
Remove macOS sleep loop in favour of using `Condvar`
2019-06-26 02:28:16 +02:00
mitchmindtree 3603cbaee7 Remove macOS sleep loop in favour of using `Condvar`
This solution was originally posted by @HybridEidolon in #185. Sorry it
took so long! I thought it might be easier to open a new PR as half of
your implementation here has already been implemented in a following PR
(namely, the change from an unnecessary `Vec` of callbacks to a single
user callback).

Closes #185.
2019-06-25 17:38:54 +02:00
mitchmindtree 7e413cb660
Merge pull request #289 from mitchmindtree/host
Introduce a `Host` API
2019-06-25 17:31:35 +02:00
mitchmindtree 51eba20c44 Remove DefaultHost type in favour of determining at runtime
Re-exports host-specific types so that they are available within the
platform module if necessary (e.g. host::asla::Host as AlsaHost).

Allows for converting platform-specific host types (e.g. AlsaHost) into
the dynamically dispatched type generated for the target platform
(`Host`).
2019-06-25 16:54:50 +02:00
mitchmindtree 283a73054e Address some nits highlighted by ishitatsuyuki 2019-06-25 16:26:27 +02:00
mitchmindtree e131979d22 Update README for addition of host enumeration API 2019-06-25 00:39:51 +02:00
mitchmindtree 6e9b40e225 Minimize compiler flags by using nested platform_impl mods
Also addresses some other CI errors:

- Add Host::new constructor for null backend
- Add missing DevicesError import to coreaudio backend
2019-06-24 23:22:37 +02:00
mitchmindtree f7cf0c65b8 Implement `Host` API for coreaudio backend 2019-06-24 22:44:57 +02:00
mitchmindtree 6b6830ab57 Implement `Host` API for emscripten backend 2019-06-24 22:38:48 +02:00
mitchmindtree 69cd058d28 Implement new `Host` API for WASAPI backend 2019-06-24 22:21:19 +02:00
mitchmindtree e8a05379c2 [WIP] Introduce a `Host` API
This is an implementation of the API described at #204. Please see that
issue for more details on the motivation.

-----

A **Host** provides access to the available audio devices on the system.
Some platforms have more than one host available, e.g.
wasapi/asio/dsound on windows, alsa/pulse/jack on linux and so on. As a
result, some audio devices are only available on certain hosts, while
others are only available on other hosts. Every platform supported by
CPAL has at least one **DefaultHost** that is guaranteed to be available
(alsa, wasapi and coreaudio). Currently, the default hosts are the only
hosts supported by CPAL, however this will change as of landing #221 (cc
@freesig). These changes should also accommodate support for other hosts
such as jack #250 (cc @derekdreery) and pulseaudio (cc @knappador) #259.

This introduces a suite of traits allowing for both compile time and
runtime dispatch of different hosts and their uniquely associated device
and event loop types.

A new private **host** module has been added containing the individual
host implementations, each in their own submodule gated to the platforms
on which they are available.

A new **platform** module has been added containing platform-specific
items, including a dynamically dispatched host type that allows for
easily switching between hosts at runtime.

The **ALL_HOSTS** slice contains a **HostId** for each host supported on
the current platform. The **available_hosts** function produces a
**HostId** for each host that is currently *available* on the platform.
The **host_from_id** function allows for initialising a host from its
associated ID, failing with a **HostUnavailable** error. The
**default_host** function returns the default host and should never
fail.

Please see the examples for a demonstration of the change in usage. For
the most part, things look the same at the surface level, however the
role of device enumeration and creating the event loop have been moved
from global functions to host methods. The enumerate.rs example has been
updated to enumerate all devices for each host, not just the default.

**TODO**

- [x] Add the new **Host** API
- [x] Update examples for the new API.
- [x] ALSA host
- [ ] WASAPI host
- [ ] CoreAudio host
- [ ] Emscripten host **Follow-up PR**
- [ ] ASIO host #221

cc @ishitatsuyuki more to review for you if you're interested, but it
might be easier after #288 lands and this gets rebased.
2019-06-24 21:45:04 +02:00
mitchmindtree 2b9e2e0b2c
Merge pull request #288 from mitchmindtree/callback_event
User Callback API `StreamEvent` Overhaul
2019-06-24 21:33:32 +02:00
mitchmindtree c72bafd8ab Update examples eprintln to more accurately reflect error 2019-06-24 21:13:07 +02:00
mitchmindtree c05d2916b1 Remove `StreamEvent` in favour of `StreamDataResult` 2019-06-24 20:43:27 +02:00
mitchmindtree 26f7e99e9b Remove all `Pause`, `Play` and `Close` events
A follow up to [this comment](https://github.com/tomaka/cpal/pull/288#issuecomment-504712574).
2019-06-23 19:04:24 +02:00
mitchmindtree b1539c534f Add handling of `Play`, `Pause` and `Close` stream events to emscripten 2019-06-22 17:47:31 +02:00
mitchmindtree b2c1226b47 Update coreaudio backend for `StreamEvent` API addition. 2019-06-22 17:14:42 +02:00
mitchmindtree fddea2edd8 Update the null and emscripten backends for StreamEvent API 2019-06-22 03:53:51 +02:00
mitchmindtree 3e3cf26cde Update `wasapi` backend for `StreamEvent` API addition.
Refactors much of the `EventLoop::run` implementation in order to make
error handling a little easier.
2019-06-22 03:47:05 +02:00
mitchmindtree 39cd5d0084 Update examples for addition of new StreamEvent API 2019-06-22 00:10:40 +02:00
mitchmindtree e41baa248b Update alsa backend for addition of `StreamEvent` type
This commit significantly refactors the alsa backend's `EventLoop::run`
implementation in order to allow for better error handling throughout
the loop. This removes many cases that would previously `panic!` in
favour of calling the user callback with the necessary error and
removing the corrupt stream. Seeing as the method cannot return, a
catch-all `panic!` still exists at the end of the method, however this
refactor should make it much easier to remove this restriction in the
future.
2019-06-22 00:06:55 +02:00
mitchmindtree 59c789fbcd Add new `StreamEvent` type - enables more flexible user callback API
This adds the following types:

- `StreamEvent`
- `CloseStreamCause`
- `StreamError`

These allow for notifying the user of the following events:

- A stream has been played.
- A stream has been paused.
- A stream has been closed due to user destroying stream.
- A stream has been closed due to an error.
2019-06-22 00:02:57 +02:00
mitchmindtree 9cc5df8805
Merge pull request #286 from mitchmindtree/error_handling
Error Handling Overhaul
2019-06-21 16:30:18 +02:00
mitchmindtree e2ec0eace2 Remove gnu target to avoid need to install gcc for cc crate 2019-06-21 16:17:58 +02:00
mitchmindtree d1a4f456de Remove 32-bit appveyor targets. Only build nightly on MSVC.
As appveyor only does one job at a time, this should help to keep
appveyor builds under 5 minutes... Otherwise we're looking at 15+ min
build times.
2019-06-21 16:08:01 +02:00
mitchmindtree 2667547a9c Update lib docs to allow for testing on devices with no audio 2019-06-21 15:57:15 +02:00
mitchmindtree 61c3520d70 Try using a slightly more modern yml to address appveyor build bug
This uses the script from here with all comments stripped:

https://github.com/starkat99/appveyor-rust/

The beta targets have also been removed to keep build times low.
2019-06-21 15:53:27 +02:00
mitchmindtree 6164f83147 Fix compiler errors in wasapi backend after testing on windows 2019-06-21 23:32:00 +10:00
mitchmindtree 0b6e66d38e Update examples to use std Termination 2019-06-21 14:55:21 +02:00
mitchmindtree a733bdb4f9 Fix compile errors on macOS 2019-06-21 03:11:20 +02:00
mitchmindtree eae0e18714 Add `PlayStreamError` and `PauseStreamError`.
This allows for properly handling potential failure on macOS. We should
also consider propagating the mutex/channel poison errors through these
new types, especially considering the potential removal of the event
loop in favour of switching over to high-priority audio threads on
windows and linux.
2019-06-21 03:04:15 +02:00
mitchmindtree ba8d354e93 Improve handling of `BuildStreamError` throughout crate. 2019-06-21 02:38:59 +02:00
mitchmindtree f0e4e312c1 Improve handling of the `DefaultFormatError` 2019-06-21 01:38:21 +02:00
mitchmindtree fbb97f51ef Update examples for DeviceNameError 2019-06-21 01:37:55 +02:00
mitchmindtree 105086a108 Add new `DeviceNameError` type
The coreaudio and wasapi backends may both potentially fail to produce
the name associated with a device. This changes the API to allow for
returning the errors in these cases.
2019-06-21 00:58:15 +02:00
mitchmindtree 78a7cb9e79 Change `SupportedFormatsError::Unknown` variant to `BackendSpecific`
This allows for also passing through a description of the
unknown/platform-specific error.
2019-06-21 00:55:27 +02:00
mitchmindtree 42fc702f53 Add `BackendSpecificError`. Add new `DevicesError`.
See the documentation for both new errors for details.

The new `DevicesError` has been added to allow for returning errors when
enumerating devices. This has allowed to remove multiple potential
`panic!`s in each of the alsa, coreaudio and wasapi backends.
2019-06-20 22:37:36 +02:00
mitchmindtree cf84ab906f Rename `CreationError` to `BuildStreamError`
For clarity and to tie the name more closesly to the methods within from
which it may be returned.
2019-06-20 21:31:15 +02:00
mitchmindtree 0f27c1e0bb Rename `FormatsEnumerationError` to `SupportedFormatsError`
This more tightly associates the error with the device method on which
this might occur.
2019-06-20 21:16:39 +02:00
mitchmindtree 1275db805b Remove std `Error` implementations in favour of using `failure`
This will make adding new errors in the following commits towards better
error handling a lot easier.
2019-06-20 21:12:17 +02:00
mitchmindtree 9c04bf7400
Merge pull request #285 from mohanson/patch-1
Update feedback.rs
2019-06-20 18:31:21 +02:00
Mohanson 6ceb3a215f
Update feedback.rs 2019-06-19 10:34:12 +08:00
mitchmindtree e6f61b3a82
Merge pull request #283 from ishitatsuyuki/no-mutex
Use channels instead of mutex
2019-06-13 13:03:38 +02:00
Tatsuyuki Ishi 1d3754fa7d Use channels instead of mutex 2019-06-13 15:31:37 +09:00
mitchmindtree 755eefedff
Merge pull request #280 from mitchmindtree/deref_panic
Remove unnecessary panic! from OutputBuffer Deref impl
2019-06-08 00:13:53 +02:00
mitchmindtree 960b1d5a40 Remove unnecessary panic! from OutputBuffer Deref impl
Since #269 this `panic!` is certainly unnecessary as `InputBuffer` and
`OutputBuffer` are a thin wrapper around a slice. That said, I'm
struggling to understand exactly why this `panic!` was necessary in the
first place.

This closes #228.
2019-06-07 21:05:14 +02:00
mitchmindtree d0cafd68bf
Merge pull request #276 from AustinJ235/master
Release 0.9.0
2019-06-07 15:39:52 +02:00
mitchmindtree 7f7e50c96a
Merge pull request #211 from mitchmindtree/feedback_example
Add an example that demonstrates feeding input directly to output with some latency
2019-06-06 18:09:09 +02:00
Austin Johnson 49b2c42443 add changelog entries for #248 #254 & #269; update version to 0.9.0 2019-06-06 10:29:52 -05:00