Commit Graph

52 Commits

Author SHA1 Message Date
ejurgensen
2d84b0bab9 [alsa] Coverity fixups 2022-01-20 20:17:38 +01:00
ejurgensen
c5df688caf [alsa] Align commit bfe99e5 with coding style 2020-08-22 21:36:10 +02:00
whatdoineed2do/Ray
bfe99e56f7 [alsa] use alsamixer volume adjustment algorithm 2020-08-22 21:25:17 +02:00
whatdoineed2do/Ray
c6c1e8f9ee [alsa] dump_card() includes ALSA device name
Include ALSA's device name in the ALSA modules 'info' logging to help
identify sound devices as seen by the system for assisting config setup

Many configs use ALSA's hw ids to refer to device but ALSA can also use
device names:

    laudio: Available ALSA playback mixer(s) on hw:0 CARD=Intel (HDA Intel): 'Master' 'Headphone' 'Speaker' 'PCM' 'Mic' 'Beep'
    laudio: Available ALSA playback mixer(s) on hw:1 CARD=E30 (E30): 'E30 '

From the example above can use these ALSA names interchangably:
    'hw:0' and 'hw:Intel'
    'hw:1' and 'hw:E30'
2020-07-14 21:55:46 +01:00
ejurgensen
661289990c [player] Migrate a lot of speaker handling to outputs.c
Moves speaker selection, volume handling and startup to outputs.c, plus adds
the ability to "resurrect" a speaker that disconnects.

The purpose of moving the code is to concentrate device handling in one place.

Also changes how we deal with speaker selection. The player will now generally
not alter a user selection, even if the device fails. The purpose of this is to
maintain selection both if the device briefly fails, and if the user switches
off the device (we stop playback) and later turns it on + starts new playback.
2020-05-03 00:00:18 +02:00
ejurgensen
aa9a08aedb [alsa] Improvements to commit 0a08b93 2020-04-18 21:35:47 +02:00
whatdoineed2do/Ray
0a08b93c24 [alsa] list alsa devices/mixers suitable for playback 2020-04-18 11:36:41 +01:00
Justin Wong
938a19ff15 Update volume on device reconnect 2020-04-14 23:49:34 +08:00
whatdoineed2do/Ray
609cba5f04 [alsa] multi alsa cfg section SEGV with no nickname - use 'card' when not specified 2020-01-06 15:38:32 +00:00
whatdoineed2do/Ray
7ea8eeae05 [alsa] cfg section typo using 'mixer_device_name' 2020-01-03 19:37:07 +00:00
ejurgensen
4e1e5efedc [alsa] Changes to commit 0cb4e0b: multiple devices 2020-01-03 19:02:39 +01:00
whatdoineed2do/Ray
0cb4e0b862 [outputs/conf] New multiple 'alsa' sections split from 'audio' 2020-01-02 23:51:59 +01:00
ejurgensen
251080344e [alsa] Fix missing unsubscription when closing session (ref. #866) 2019-12-27 11:29:36 +01:00
ejurgensen
85ab7c3057 [alsa] Fix playback of 24 bit audio (issue #830)
The player will write 24 bit samples using 3 bytes, not 4, so the appropriate
sample format is SND_PCM_FORMAT_S24_3LE, not SND_PCM_FORMAT_S24_LE.

For extra protection we also use snd_pcm_bytes_to_frames() instead of BTOS(),
because that way we can be more certain that the buffer is not too short for
snd_pcm_writei().
2019-10-22 19:51:51 +02:00
whatdoineed2do/Ray
554799ebc3 [streaming/xcode] configurable MP3 streaming bitrate 2019-09-22 22:58:32 +02:00
ejurgensen
e654276262 [alsa] Fix incorrect use of abs() for float, use fabs() instead 2019-09-18 21:28:15 +02:00
ejurgensen
51d85d0975 [alsa] Fix for ALSA issues when source quality changes (issue #722, issue #744 and issue #754)
* Fix "clicks" during playback, especially on low buffer size devices
  Bug had two causes: Trying to write to the prebuf ringbuffer when it was full
  and writing new audio to the device without first having drained the prebuf,
  thus writing out of order.

* Use snd_pcm_drain() so alsa doesn't report underrun on playback session end
  Removes SNDRV_PCM_IOCTL_SYNC_PTR errors

* Fix missing error check of the return value from snd_pcm_avail (now use snd_pcm_avail_delay)
2019-06-22 21:53:09 +02:00
Scott Shambarger
20f5118f75 [alsa] asoundlib.h should be alsa/asoundlib.h 2019-06-11 20:10:04 -07:00
ejurgensen
cd7bf45749
[alsa] Return ALSA the error code from buffer_write, not -1 2019-05-15 11:53:13 +02:00
ejurgensen
c7b8b94163 [alsa] Set quality in device_open() (possible fix for issue #720) 2019-04-12 22:24:48 +02:00
ejurgensen
ce2be1a724 [-] A bit of cleaning up 2019-04-10 22:38:48 +02:00
ejurgensen
dc65cb5b76 [alsa] Make sync and sync evaluation period configurable 2019-04-09 21:45:16 +02:00
ejurgensen
02cd65a992 [alsa] New resample-based sync correction 2019-04-08 00:50:20 +02:00
ejurgensen
6930fdb28d [alsa] Fix memleak: Missing free 2019-03-26 22:08:15 +01:00
ejurgensen
95deef9c06 A bit of scan-build fixup 2019-03-22 22:15:13 +01:00
ejurgensen
b8e0280567 [outputs] Add a 10 sec stop timer + drop playback_stop()
In the output implementations playback_stop() was somewhat redundant,
since device_stop() does the same.

The timer should make sure that we always close outputs (previously
they were in some cases kept open).

The commit also includes some renaming.
2019-03-18 23:06:08 +01:00
ejurgensen
143708368c [alsa] Fix sync check
Sync correction still not implemented
2019-03-18 23:06:08 +01:00
ejurgensen
cfaceab9fe [outputs] Misc fixup 2019-03-18 23:06:08 +01:00
ejurgensen
9d5555152c [alsa] Implement new output interface + some refactoring
Sync still missing
2019-03-18 23:06:08 +01:00
ejurgensen
d008e241cf [outputs] Make outputs_device_flush (per device flushing)
Works better with the callback mechanism
2019-03-18 23:06:08 +01:00
ejurgensen
936103f462 [outputs] Move device_add/rm to outputs and get rid of advertised flag 2019-03-18 23:06:08 +01:00
ejurgensen
a7e8476996 [outputs] Refactor outputs some more, eg change callback system 2019-03-18 23:06:08 +01:00
ejurgensen
e99f20992e [player/outputs] Implement changed output interfaces in most backends
Still missing cast, alsa and pulseaudio, but these can so far just be
disabled with configure.

Otherwise still mostly untested.
2019-03-18 23:06:08 +01:00
ejurgensen
fcc91ecd86 [player/outputs] Handle multiple quality levels + use rtp_common (WIP!)
* Untie Airtunes stuff further from player and non-Airplay outputs
* Change raop.c to use rtp_common.c (step 1)
* Change heartbeat of player to 100 ticks/sec, since we have untied from
  Airtunes 352 samples per packet (which equals 126 ticks/sec at 44100)

Still a lot to be done in the player, since the rtptime's in it don't
are probably broken.
2019-03-18 23:06:08 +01:00
ejurgensen
a37fc0916f [alsa] Fix scan-build issue: Argument with 'nonnull' attribute passed null 2018-12-29 16:34:56 +01:00
Don Cross
07e46d75c8 [alsa] Made resync period configurable 1..20 seconds, with default=10. (#604)
The unconfigurable resync period of 10 seconds was not frequent
enough to keep my own ALSA device in sync with the AirPlay stream.
Now the period is configurable.  The default is still at 10
seconds, to prevent any change in behavior unless opted in by
the user.

Currently the adjustment causes a tiny "click" distortion in the
ALSA output, so it is better to make the check as infrequent as
possible, while still being frequent enough to stay in sync
over lengthy sessions of playback.

Added source_sample_rate, target_sample_rate to alsa_session.
This is a first step toward rendering ALSA at a different
sampling rate than the AirPlay stream, so that (a) we will
be able to dynamically adjust the ALSA sampling rate for an
improved sync algorithm, and (b) later, a more generalized
resampling algorithm can accommodate very different hardware
sampling rates like 22050 Hz or 48000 Hz.

Reworked alsa_session_free() so that it can be used to
tear down a partially initialized alsa_session if an
error occurs in the middle of alsa_session_make().
This simplifies the error handling logic in alsa_session_make().
This refactoring will be helpful later when resampling is added,
because more data structures will be dynamically allocated
during initialization.

Signed-off-by: Don Cross <cosinekitty@gmail.com>
2018-10-14 20:40:36 +02:00
ejurgensen
0c2773039b [-] Fix alsa.c null pointer deref + some minor bugs and do some housekeeping
Thanks to Denis Denisov and cppcheck for notifying about the below. The leaks
are edge cases, but the warning of dereference of avail in alsa.c points at
a bug that could probably cause actual crashes.

[src/evrtsp/rtsp.c:1352]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?
[src/httpd_daap.c:228]: (error) Memory leak: s
[src/library.c:280]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[src/library.c:284]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[src/library/filescanner_playlist.c:251]: (error) Resource leak: fp
[src/library/filescanner_playlist.c:273]: (error) Resource leak: fp
[src/outputs/alsa.c:143]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?
[src/outputs/alsa.c:657]: (warning) Possible null pointer dereference: avail
[src/outputs/dummy.c:75]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?
[src/outputs/fifo.c:245]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?
[src/outputs/raop.c:1806]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?
[src/outputs/raop.c:1371]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
[src/outputs/raop.c:1471]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
[src/outputs/raop_verification.c:705] -> [src/outputs/raop_verification.c:667]: (warning) Either the condition 'if(len_M)' is redundant or there is possible null pointer dereference: len_M.
2017-10-05 22:13:01 +02:00
ejurgensen
3f2ad41094 [alsa] Fix missing cleanup of failed ALSA sessions 2017-07-14 23:20:53 +02:00
ejurgensen
26c22144fc [-] Misc housekeeping (minor memleaks, invalid free's) 2017-02-12 01:19:56 +01:00
ejurgensen
c50b038397 [misc] Move STOB and BTOS macros to misc.h 2017-01-27 22:01:24 +01:00
ejurgensen
bdd6bab982 [-] Lots of housekeeping thanks to scan-build and input from @acmay 2016-11-19 23:08:50 +01:00
Pat Coulthard
ae79800493 Add mixer_device configuration file option for ALSA
Support a separate mixer_device configuration file option for
advanced ALSA configurations. Previously, ALSA local output
happened to work becasue "default" is valid as both a PCM and a
mixer. Now you can separately specify the device name for PCM
output and mixer operations.

In my setup, I am using the following setup:
card = "default:CARD=NVidia"
mixer = "Front"
mixer_device = "hw:CARD=NVidia"
2016-09-25 15:52:15 -05:00
ejurgensen
7af9c25964 Merge branch 'pulseaudio1' 2016-08-28 22:37:41 +02:00
ejurgensen
8a9d8c31da [alsa] Remove risky negative enum (risky when AND'ing with ALSA_F_STARTED) 2016-08-13 17:08:14 +02:00
ejurgensen
4399466f21 [pulseaudio] Friendly naming of sinks in speaker list 2016-07-21 23:15:06 +02:00
ejurgensen
ad01d65047 [alsa] Let the user configure an offset to sync audio if required 2016-04-14 09:48:48 +02:00
ejurgensen
e23fed4ac4 [alsa] Avoid call to snd_pcm_prepare if already in the right state 2016-04-14 09:48:48 +02:00
ejurgensen
19181007f4 [alsa] Increase max latency variance
Latency on the RPi varies quite a bit
2016-04-14 09:48:48 +02:00
ejurgensen
632bfd9a33 [alsa] Add low-tech sync with the player (and AirPlay) 2016-04-14 09:48:48 +02:00
ejurgensen
eca41e306e [alsa] Try to measure latency 2016-04-14 09:48:48 +02:00