Commit graph

382 commits

Author SHA1 Message Date
JasonLG1979
3be6990a13 Update dependencies 2022-04-19 17:29:37 -05:00
Roderick van Domburg
a7a260be16
Fix SDL deprecations 2022-04-07 23:20:49 +02:00
Roderick van Domburg
1290ee9925
Fix clippy warnings 2022-04-07 22:32:43 +02:00
JasonLG1979
d887d58251 Fix clippy warnings 2022-03-20 10:52:08 -05:00
JasonLG1979
dc9f822c80 Port #976 2022-03-19 21:15:46 -05:00
JasonLG1979
e0e23c9167 Use the librespot name arg for the app name in the PulseAudio backend
This sets the name displayed by PulseAudio to Librespot - Instance Name if a name is given otherwise Librespot (the default name).

This also sets the correct "role" as per the docs:

https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/Clients/ApplicationProperties/

PA_PROP_MEDIA_ROLE

"This is a property of the actual streamed data, not so much the application"

Roles are used for policies, things like automatically muting a music player when a call comes in and whatnot.

For bonus points this also sets PULSE_PROP_application.icon_name to audio-x-generic so that we get a nice icon in the PulseAudio settings by our name instead of a missing icon placeholder.
2022-03-19 15:09:26 -05:00
JasonLG1979
85d6c0c714 symphonia_decoder tweak
* Remove unwrap

* Refactor normalisation_data.
2022-02-20 01:27:12 -06:00
Jason Gray
47f1362453
Port remove unsafe code and catch up with dev (#956) 2022-02-14 12:15:19 +01:00
Jason Gray
616809b64c
Quantum-realm level normalisation optimization (#965)
This saves up to 1-2% CPU useage on a PI 4 depending on how much normalisation is actually being done.

* We don't need to test against EPSILON. The factor will never be over 1.0 in basic normalisation mode.
* Don't check the normalisation mode EVERY sample.
* Do as little math as possible by simplfiying all equations as much as possible (while still retaining the textbook equations in comments).
* Misc cleanup
2022-02-13 22:50:32 +01:00
Sebastian Dröge
ab562cc8d8
Update GStreamer to 0.18 and clean up (#964)
* Update GStreamer backend to 0.18
* Don't manually go through all intermediate states when shutting down the GStreamer backend; that happens automatically
* Don't initialize GStreamer twice
* Use less stringly-typed API for configuring the appsrc
* Create our own main context instead of stealing the default one; if the application somewhere else uses the default main context this would otherwise fail in interesting ways
* Create GStreamer pipeline more explicitly instead of going via strings for everything
* Add an audioresample element before the sink in case the sink doesn't support the sample rate
* Remove unnecessary `as_bytes()` call
* Use a GStreamer bus sync handler instead of spawning a new thread with a mainloop; it's only used for printing errors or when the end of the stream is reached, which can also be done as well when synchronously handling messages.
* Change `expect()` calls to proper error returns wherever possible in GStreamer backend
* Store asynchronously reported error in GStreamer backend and return them on next write
* Update MSRV to 1.56
2022-02-13 21:52:02 +01:00
Philip Deljanov
e64f09fd77 Upgrade to Symphonia v0.5. 2022-02-01 19:02:14 -05:00
Roderick van Domburg
c8971dce63
Fix Alsa softvol linear mapping (#950)
Use `--volume-range` overrides
2022-01-27 18:39:28 +01:00
Jason Gray
03e71f6e0a
simplify get_factor (#942)
Simplify `get_factor`
2022-01-27 07:40:59 +01:00
Roderick van Domburg
9b25669a08
Fix clippy lints 2022-01-26 23:05:40 +01:00
Roderick van Domburg
827b815da9
Update Rodio and neatly call play/pause 2022-01-26 22:54:04 +01:00
Roderick van Domburg
552d9145f4
Feature-gate passthrough decoder 2022-01-25 20:46:10 +01:00
Jason Gray
ceebb374f0
Remove unsafe code (#940)
Remove unsafe code
2022-01-23 19:02:04 +01:00
Jason Gray
c6e97a7f8a
Save some more CPU cycles in the limiter (#939)
Optimise limiter CPU usage
2022-01-17 22:57:30 +01:00
Roderick van Domburg
8851951f04
Change counting to spirc and player
They can be reinstantiated, unlike the `session` which is now
intended to be constructed once.
2022-01-16 21:29:59 +01:00
Roderick van Domburg
0de55c6183
Merge branch 'dev' into new-api 2022-01-14 23:42:18 +01:00
Roderick van Domburg
72af0d2014
New dynamic limiter for very wide dynamic ranges (#935)
New dynamic limiter for very wide dynamic ranges
2022-01-14 23:31:29 +01:00
Roderick van Domburg
1e54913523
Fix --device argument to various backends (#938)
Fix `--device` argument to various backends
2022-01-14 08:20:29 +01:00
Roderick van Domburg
e627cb4b35
Fix panic when retrying a track that already failed 2022-01-13 21:05:17 +01:00
Roderick van Domburg
78216eb6ee
Prevent seek before offset 2022-01-13 19:12:48 +01:00
Roderick van Domburg
c067c1524f
Only notify when we are >= 1 second ahead 2022-01-09 23:04:14 +01:00
Roderick van Domburg
a62c1fea8f
Fix rare panics on out-of-bounds stream position 2022-01-09 22:46:44 +01:00
Roderick van Domburg
75e6441db9
Downgrade for MSRV 1.53 2022-01-09 22:24:34 +01:00
Roderick van Domburg
e69d5a8e91
Fix GStreamer lagging audio on next track
Also: remove unnecessary thread and channel
2022-01-09 22:18:55 +01:00
Roderick van Domburg
d2c377d14b
Fix GStreamer cleanup on exit 2022-01-09 16:53:57 +01:00
Roderick van Domburg
59d00787c9
Update player crates and transitive dependencies 2022-01-09 16:04:53 +01:00
Roderick van Domburg
42455e0cdd
Merge branch 'new-api' of github.com:librespot-org/librespot into new-api 2022-01-08 23:29:57 +01:00
Roderick van Domburg
5cc3040bd8
Update futures 2022-01-08 21:21:31 +01:00
Roderick van Domburg
d380f1f040
Simplify AudioPacketPosition 2022-01-07 11:13:23 +01:00
Roderick van Domburg
a33014f9c5
Notify track position after skipping malformed packets 2022-01-06 22:46:50 +01:00
Roderick van Domburg
67ae0fcf8d
Fix gapless playback 2022-01-06 22:11:53 +01:00
Roderick van Domburg
8d74d48809
Audio file seeking improvements
- Ensure there is enough disk space for the write file
- Switch streaming mode only if necessary
- Return `Err` on seeking errors, instead of exiting
- Use the actual position after seeking
2022-01-06 21:55:08 +01:00
Roderick van Domburg
6c25fb79dc
Merge pull request #925 from pdeljanov/new-api-symphonia-fixes
Handle reset and decode errors
2022-01-06 11:10:02 +01:00
Philip Deljanov
5d44f910f3 Handle format reset and decode errors.
This change fixes two issues with the error handling of the
Symphonia decode loop.

1) `Error::ResetRequired` should always be propagated to jump
    to the next Spotify track.

2) On a decode error, get a new packet and try again instead of
   propagating the error and jumping to the next track.
2022-01-05 18:17:33 -05:00
JasonLG1979
cfde70f6f9 Fix clippy lint warning 2022-01-05 16:55:16 -06:00
Roderick van Domburg
1a7c440bd7
Improve lock ordering and contention 2022-01-05 20:44:08 +01:00
Roderick van Domburg
3e09eff906
Improve initial loading time
- Configure the decoder according to Spotify's metadata, don't probe

- Return from `AudioFile::open` as soon as possible, with the smallest
  possible block size suitable for opening the decoder, so the UI
  transitions from loading to playing/paused state. From there,
  the regular prefetching will take over.
2022-01-04 23:23:20 +01:00
Roderick van Domburg
eabdd79275
Seeking, buffer size and error handing improvements
- Set ideal sample buffer size after decoding first full packet
- Prevent audio glitches after seeking
- Reset decoder when the format reader requires it

Credits: @pdeljanov
2022-01-04 21:23:53 +01:00
Roderick van Domburg
a49bcb70a7
Fix clippy lints 2022-01-04 21:22:52 +01:00
Roderick van Domburg
8dbcda6bc2
Merge branch 'dev' into new-api 2022-01-04 01:13:48 +01:00
Roderick van Domburg
d5a4be4aa1
Optimize fallback sample buffer size 2022-01-04 00:50:45 +01:00
Roderick van Domburg
01448ccbe8
Seek in milliseconds and report the actual new position 2022-01-04 00:17:30 +01:00
Roderick van Domburg
f3a66d4b99
Remove lewton decoder 2022-01-03 22:41:54 +01:00
Roderick van Domburg
096269c1d0
Reintroduce offset for passthrough decoder 2022-01-03 22:20:29 +01:00
Roderick van Domburg
7921f23927
Improve format handling and support MP3
- Switch from `lewton` to `Symphonia`. This is a pure Rust demuxer
  and decoder in active development that supports a wide range of
  formats, including Ogg Vorbis, MP3, AAC and FLAC for future HiFi
  support. At the moment only Ogg Vorbis and MP3 are enabled; all
  AAC files are DRM-protected.

- Bump MSRV to 1.51, required for `Symphonia`.

- Filter out all files whose format is not specified.

- Not all episodes seem to be encrypted. If we can't get an audio
  key, try and see if we can play the file without decryption.

- After seeking, report the actual position instead of the target.

- Remove the 0xa7 bytes offset from `Subfile`, `Symphonia` does
  not balk at Spotify's custom Ogg packet before it. This also
  simplifies handling of formats other than Ogg Vorbis.

- When there is no next track to load, signal the UI that the
  player has stopped. Before, the player would get stuck in an
  infinite reloading loop when there was only one track in the
  queue and that track could not be loaded.
2022-01-03 00:13:28 +01:00
JasonLG1979
8dfa00d66f Clean up list_compatible_devices
Fix a typo and be a little more forgiving.
2022-01-01 17:19:12 -06:00
Guillaume Desmottes
f09be4850e Sink: pass ownership of the packet on write()
Prevent a copy if the implementation needs to keep the data around.
2021-12-31 13:46:35 +01:00
Roderick van Domburg
0fdff0d3fd
Follow client setting to filter explicit tracks
- Don't load explicit tracks when the client setting forbids them

 - When a client switches explicit filtering on *while* playing
   an explicit track, immediately skip to the next track
2021-12-30 23:50:28 +01:00
Roderick van Domburg
286a031d94
Always seek to starting position 2021-12-30 21:52:15 +01:00
Roderick van Domburg
e51f475a00
Further initial loading improvements
This should fix remaining cases of a client connecting, and failing
to start playback from *beyond* the beginning when `librespot` is
still loading that track.

This undoes the `suppress_loading_status` workaround from #430,
under the assumption that the race condition reported there has
since been fixed on Spotify's end.
2021-12-29 22:27:31 +01:00
Guillaume Desmottes
3ce9854df5 player: ensure load threads are done when dropping PlayerInternal
Fix a race where the load operation was trying to use a disposed tokio
context, resulting in panic.
2021-12-29 16:00:45 +01:00
Roderick van Domburg
332f9f04b1
Fix error hitting play when loading
Further changes:

 - Improve some debug and trace messages

 - Default to streaming download strategy

 - Synchronize mixer volume on loading play

 - Use default normalisation values when the file position isn't
   exactly what we need it to be

 - Update track position only when the decoder reports a
   successful seek
2021-12-28 23:46:37 +01:00
Roderick van Domburg
b7c047bca2
Fix alternative tracks 2021-12-27 09:35:11 +01:00
Roderick van Domburg
b4f7a9e35e
Change to parking_lot and remove remaining panics 2021-12-26 23:02:02 +01:00
Roderick van Domburg
62461be1fc
Change panics into Result<_, librespot_core::Error> 2021-12-26 21:18:42 +01:00
Roderick van Domburg
0d51fd43dc
Remove unwraps from librespot-audio 2021-12-18 23:44:13 +01:00
Roderick van Domburg
82b2653c5f
Merge remote-tracking branch 'librespot-org/dev' into new-api-wip 2021-12-16 23:01:56 +01:00
Roderick van Domburg
2f7b9863d9
Implement CDN for audio files 2021-12-16 22:42:37 +01:00
Roderick van Domburg
1736e7c52b
Merge pull request #905 from roderickvd/fix-exit-on-decoder-error
Skip track on decoding error
2021-12-15 19:01:15 +01:00
JasonLG1979
d5efb8a620 Dynamic failable buffer sizing alsa-backend
Dynamically set the alsa buffer and period based on the device's reported min/max buffer and period sizes. In the event of failure use the device's defaults.

This should have no effect on devices that allow for reasonable buffer and period sizes but would allow us to be more forgiving with less reasonable devices or configurations.

Closes: https://github.com/librespot-org/librespot/issues/895
2021-12-14 16:49:09 -06:00
Roderick van Domburg
8f23c3498f
Clean up warnings 2021-12-12 20:01:05 +01:00
Roderick van Domburg
79c4040a53
Skip track on decoding error 2021-12-12 12:56:02 +01:00
Roderick van Domburg
f03a7e95c1
Merge remote-tracking branch 'librespot-org/dev' into new-api-wip 2021-12-08 19:11:53 +01:00
Roderick van Domburg
0e2686863a
Major metadata refactoring and enhancement
* Expose all fields of recent protobufs

 * Add support for user-scoped playlists, user root playlists and
   playlist annotations

 * Convert messages with the Rust type system

 * Attempt to adhere to embargos (tracks and episodes scheduled for
   future release)

 * Return `Result`s with meaningful errors instead of panicking on
   `unwrap`s

 * Add foundation for future playlist editing

 * Up version in connection handshake to get all version-gated features
2021-12-07 23:22:24 +01:00
JasonLG1979
4370258716 Address clippy lint warnings for rust 1.57 2021-12-03 12:51:41 -06:00
Roderick van Domburg
47badd61e0
Update tokio and fix build 2021-11-27 14:26:13 +01:00
Roderick van Domburg
d19fd24074
Add spclient and HTTPS support
* Change metadata to use spclient
 * Add support for HTTPS proxies
 * Start purging unwraps and using Result instead
2021-11-26 23:28:37 +01:00
JasonLG1979
c006a23644 Improve --device ? functionality for the alsa backend
This makes `--device ?` only show compatible devices (ones that support 2 ch 44.1 Interleaved) and it shows what `librespot` format(s) they support.

This should be more useful to users as the info maps directly to `librespot`'s `--device` and `--format` options.
2021-11-20 13:51:24 -06:00
JasonLG1979
0e9fdbe6b4 Refactor main.rs
* Don't panic when parsing options. Instead list valid values and exit.
* Get rid of needless .expect in playback/src/audio_backend/mod.rs.
* Enforce reasonable ranges for option values (breaking).
* Don't evaluate options that would otherwise have no effect.
* Add pub const MIXERS to mixer/mod.rs very similar to the audio_backend's implementation. (non-breaking though)
* Use different option descriptions and error messages based on what backends are enabled at build time.
* Add a -q, --quiet option that changed the logging level to warn.
* Add a short name for every flag and option.
* Note removed options.
* Other misc cleanups.
2021-11-17 15:31:16 -06:00
Roderick van Domburg
0e6b1ba9dc
Update version numbers to 0.3.1 2021-10-24 20:12:33 +02:00
Roderick van Domburg
ff3648434b
Change hand-picked RNGs back to SmallRng
While `Xoshiro256+` is faster on 64-bit, it has low linear complexity in the
lower three bits, which *are* used when generating dither.

Also, while `Xoshiro128StarStar` access one less variable from the heap,
multiplication is generally slower than addition in hardware.
2021-10-21 19:31:58 +02:00
Roderick van Domburg
4c89a721ee
Improve dithering CPU usage (#866) 2021-10-19 22:33:04 +02:00
Sasha Hilton
6a3377402a Update version numbers to 0.3.0 2021-10-13 15:10:18 +01:00
JasonLG1979
9ef53f5ffb simplify buffer resizing
This way is less verbose, much more simple and less brittle.
2021-10-07 08:44:29 -05:00
Jason Gray
4c1b2278ab
Fix clippy comparison chain warning (#857) 2021-10-04 20:59:18 +02:00
Jason Gray
8d70fd910e
Implement common SinkError and SinkResult (#820)
* Make error messages more consistent and concise.

* `impl From<AlsaError> for io::Error` so `AlsaErrors` can be thrown to player as `io::Errors`. This little bit of boilerplate goes a long way to simplifying things further down in the code. And will make any needed future changes easier.

* Bonus: handle ALSA backend buffer sizing a little better.
2021-09-27 20:46:26 +02:00
Jason Gray
89577d1fc1
Improve player (#823)
* Improve error handling
* Harmonize `Seek`: Make the decoders and player use the same math for converting between samples and milliseconds
* Reduce duplicate calls: Make decoder seek in PCM, not ms
* Simplify decoder errors with `thiserror`
2021-09-20 19:29:12 +02:00
Roderick van Domburg
949ca4fded
Add and default to "auto" normalisation type (#844) 2021-09-20 19:22:02 +02:00
Roderick van Domburg
30717c3db7
Merge pull request #842 from roderickvd/2db-normalisation-threshold
Update default normalisation threshold
2021-09-03 21:48:42 +02:00
Roderick van Domburg
2fcd24164d
Merge pull request #840 from roderickvd/attenuate-last
Attenuate after normalisation
2021-09-02 22:09:30 +02:00
Roderick van Domburg
fe644bc0d7
Update default normalisation threshold 2021-09-02 22:04:30 +02:00
Roderick van Domburg
b016b69772
Fix clippy warnings 2021-09-01 21:25:32 +02:00
Roderick van Domburg
d8e35bf0c4
Remove clamping of float samples 2021-09-01 20:55:28 +02:00
Roderick van Domburg
7da4d0e473
Attenuate after normalisation 2021-09-01 20:54:47 +02:00
Roderick van Domburg
c67e268dc8
Improve Alsa mixer command-line options 2021-08-26 22:35:45 +02:00
Roderick van Domburg
43a8b91a3d
Revert name to softvol 2021-07-09 22:17:29 +02:00
Jason Gray
68bec41e08
Improve Alsa backend buffer (#811)
* Reuse the buffer for the life of the Alsa sink
* Don't depend on capacity being exact when sizing the buffer
* Always give the PCM a period's worth of audio even when draining the buffer
* Refactoring and code cleanup
2021-07-06 08:37:29 +02:00
Jason Gray
9ff33980d6
Better errors in PulseAudio backend (#801)
* More meaningful error messages
* Use F32 if a user requests F64 (F64 is not supported by PulseAudio)
* Move all code that can fail to `start` where errors can be returned to prevent panics
* Use drain in `stop`
2021-06-30 21:14:23 +02:00
Reinier Balt
751ccf63bb
Make convert and decoder public (#814) 2021-06-30 09:54:02 +02:00
Roderick van Domburg
7cd1b7a26a
Merge branch 'dev' into new-api-client 2021-06-26 00:14:20 +02:00
JasonLG1979
bb2477831b Don't explicitly set the number of periods
Doing so on configs that have less than the 4 periods we were asking for caused a crash. Instead ask for a buffer time of 500ms.
2021-06-25 17:10:50 -05:00
Roderick van Domburg
a7326815bd
Merge pull request #802 from JasonLG1979/fix_pipe_backend
Better errors in pipe backend
2021-06-19 22:38:47 +02:00
Roderick van Domburg
113ac94c07
Update protobufs (#796)
* Import Spotify 1.1.61.583 (Windows) protobufs
* Import Spotify 1.1.33.569 protobufs missing in 1.1.61.583
* Remove unused protobufs, no longer present in 1.1.61.583
2021-06-19 22:29:48 +02:00
JasonLG1979
336e714dba Fix clippy warning 2021-06-18 15:30:22 -05:00
JasonLG1979
5ffce0662a Fix clippy warnings
Fix the clippy warnings caused by https://github.com/librespot-org/librespot/pull/797
2021-06-18 15:11:07 -05:00
Jason Gray
2466e0b3c1
Merge branch 'librespot-org:dev' into fix_pipe_backend 2021-06-18 14:12:32 -05:00