Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPV crashes when sending DSD audio through PulseAudio #2654

Closed
JamesTheAwesomeDude opened this issue Dec 30, 2015 · 14 comments
Closed

MPV crashes when sending DSD audio through PulseAudio #2654

JamesTheAwesomeDude opened this issue Dec 30, 2015 · 14 comments

Comments

@JamesTheAwesomeDude
Copy link

When I play normal audio, MPV works fine and uses ao_pulse as the default.

But when I try to play a .dsf sound file, it uses ao_alsa. This is not a huge problem in itself, except when I try to change audio devices.

$ mpv 02\ -\ Pink\ Floyd\ -\ Welcome\ To\ The\ Machine.dsf --audio-device='pulse/alsa_output.pci-0000_04_02.0.analog-stereo' -v
[cplayer] Command line options: '02 - Pink Floyd - Welcome To The Machine.dsf' '--audio-device=pulse/alsa_output.pci-0000_04_02.0.analog-stereo' '-v'
[cplayer] mpv git-fc7212b (C) 2000-2015 mpv/MPlayer/mplayer2 projects
[cplayer]  built on Wed Dec 23 00:35:31 UTC 2015
[cplayer] ffmpeg library versions:
[cplayer]    libavutil       55.11.100
[cplayer]    libavcodec      57.18.100
[cplayer]    libavformat     57.20.100
[cplayer]    libswscale      4.0.100
[cplayer]    libavfilter     6.21.100
[cplayer]    libswresample   2.0.101
[cplayer] ffmpeg version: N-77406-gf6830cf
[cplayer] 
[cplayer] Configuration: ./waf configure --enable-pdf-build --prefix=/usr --confdir=/etc/mpv
[cplayer] List of enabled features: alsa asm atomic-builtins atomics audio-input av-avpacket-int64-duration av-new-pixdesc av-pix-fmt-mmal av-subtitle-nopict av-version-info avcodec-chroma-pos-api avframe-metadata avframe-skip-samples build-date cdda cplayer debug-build dlopen drm dvbin dvdnav dvdread encoding fchmod gl gl-x11 glibc-thread-name glob iconv jack jpeg lcms2 libass libass-osd libav libavdevice libavfilter libbluray libdl libguess libm librt libsmbclient libswresample libv4l2 linux-fstatfs lua nanosleep optimize oss-audio oss-audio-native posix posix-or-mingw posix-spawn pthreads pulse resampler rubberband shm sse4-intrinsics subprocess termios tv tv-v4l2 uchardet vaapi vaapi-glx vaapi-hwaccel vaapi-x11 vdpau vdpau-gl-x11 vdpau-hwaccel videodev vt.h x11 xext xinerama xrandr xss xv zlib
[global] config path: '' -> '/home/james/.config/mpv'
[global] config path: 'mpv.conf' -> '/home/james/.config/mpv/mpv.conf'
[global] config path: 'config' -/-> '/home/james/.config/mpv/config'
[global] config path: 'mpv.conf' -/-> '/home/james/.mpv/mpv.conf'
[global] config path: 'config' -/-> '/home/james/.mpv/config'
[global] config path: 'mpv.conf' -/-> '/etc/mpv/mpv.conf'
[global] config path: 'config' -/-> '/etc/mpv/config'
[cplayer] Reading config file /home/james/.config/mpv/mpv.conf
[cplayer] Setting option 'vo' = 'opengl-hq:dscale=mitchell,vdpau' (flags = 4)
[cplayer] Setting option 'framedrop' = 'decoder+vo' (flags = 4)
[cplayer] Setting option 'vd-lavc-skiploopfilter' = 'nonref' (flags = 4)
[cplayer] Setting option 'hwdec' = 'vdpau' (flags = 4)
[cplayer] Setting option 'vf' = 'vdpaupp' (flags = 4)
[cplayer] Setting option 'use-filedir-conf' = '' (flags = 4)
[cplayer] Setting option 'screenshot-format' = 'png' (flags = 4)
[cplayer] Setting option 'screenshot-template' = '~/Pictures/mpvshot-%tY-%tm-%td-%P' (flags = 4)
[cplayer] Setting option 'alang' = 'ja,jpn,en,eng' (flags = 4)
[cplayer] Setting option 'ad-lavc-downmix' = 'no' (flags = 4)
[cplayer] Setting option 'osd-fractions' = '' (flags = 4)
[cplayer] Setting option 'slang' = 'en,eng' (flags = 4)
[cplayer] Setting option 'audio-device' = 'pulse/alsa_output.pci-0000_04_02.0.analog-stereo' (flags = 8)
[cplayer] Setting option 'v' = '' (flags = 8)
[global] config path: 'input.conf' -> '/home/james/.config/mpv/input.conf'
[global] config path: 'input.conf' -/-> '/home/james/.mpv/input.conf'
[global] config path: 'input.conf' -/-> '/etc/mpv/input.conf'
[global] user path: '/home/james/.config/mpv/input.conf' -> '/home/james/.config/mpv/input.conf'
[ifo] Opening /home/james/.config/mpv/input.conf
[ifo/dvdnav] Opening /home/james/.config/mpv/input.conf
[bdmv/bluray] Opening /home/james/.config/mpv/input.conf
[file] Opening /home/james/.config/mpv/input.conf
[file] Stream opened successfully.
[input] Parsing input config file /home/james/.config/mpv/input.conf
[input] Input config file /home/james/.config/mpv/input.conf parsed: 2 binds
[osc] Loading script @osc.lua...
[global] config path: 'scripts' -/-> '/home/james/.config/mpv/scripts'
[global] config path: 'scripts' -/-> '/home/james/.mpv/scripts'
[global] config path: 'scripts' -/-> '/etc/mpv/scripts'
[osc] loading mp.defaults
[osc] loading @osc.lua
[global] config path: 'lua-settings/osc.conf' -> '/home/james/.config/mpv/lua-settings/osc.conf'
[cplayer] Run command: define-section, flags=0, args=[showhide, mouse_move script-binding osc/__keybinding1
[cplayer] mouse_leave script-binding osc/__keybinding2
[cplayer] , force]
[cplayer] Run command: enable-section, flags=0, args=[showhide, allow-hide-cursor+allow-vo-dragging]
[cplayer] Run command: define-section, flags=0, args=[input, mouse_btn0 script-binding osc/__keybinding3
[cplayer] shift+mouse_btn0 script-binding osc/__keybinding4
[cplayer] mouse_btn2 script-binding osc/__keybinding5
[cplayer] mouse_btn0_dbl ignore
[cplayer] shift+mouse_btn0_dbl ignore
[cplayer] mouse_btn2_dbl ignore
[cplayer] del script-binding osc/__keybinding6
[cplayer] , force]
[cplayer] Run command: enable-section, flags=0, args=[input, ]
[cplayer] Run command: disable-section, flags=0, args=[input]
[cplayer] Done loading @osc.lua.
[ytdl_hook] Loading script @ytdl_hook.lua...
[global] config path: 'scripts' -/-> '/home/james/.config/mpv/scripts'
[global] config path: 'scripts' -/-> '/home/james/.mpv/scripts'
[global] config path: 'scripts' -/-> '/etc/mpv/scripts'
[ytdl_hook] loading mp.defaults
[ytdl_hook] loading @ytdl_hook.lua
[cplayer] Run command: hook-add, flags=0, args=[on_load, 1, 10]
[cplayer] Done loading @ytdl_hook.lua.
[global] config path: 'scripts' -/-> '/home/james/.config/mpv/scripts'
[global] config path: 'scripts' -/-> '/home/james/.mpv/scripts'
[global] config path: 'scripts' -/-> '/etc/mpv/scripts'
[global] config path: 'watch_later' -> '/home/james/.config/mpv/watch_later'
[global] config path: '02 - Pink Floyd - Welcome To The Machine.dsf.conf' -/-> '/home/james/.config/mpv/02 - Pink Floyd - Welcome To The Machine.dsf.conf'
[global] config path: '02 - Pink Floyd - Welcome To The Machine.dsf.conf' -/-> '/home/james/.mpv/02 - Pink Floyd - Welcome To The Machine.dsf.conf'
[global] config path: '02 - Pink Floyd - Welcome To The Machine.dsf.conf' -/-> '/etc/mpv/02 - Pink Floyd - Welcome To The Machine.dsf.conf'
[cplayer] Playing: 02 - Pink Floyd - Welcome To The Machine.dsf
[cplayer] Running hook: ytdl_hook/on_load
[cplayer] Run command: hook-ack, flags=0, args=[on_load]
[ifo] Opening 02 - Pink Floyd - Welcome To The Machine.dsf
[ifo/dvdnav] Opening 02 - Pink Floyd - Welcome To The Machine.dsf
[bdmv/bluray] Opening 02 - Pink Floyd - Welcome To The Machine.dsf
[file] Opening 02 - Pink Floyd - Welcome To The Machine.dsf
[file] Stream opened successfully.
[demux] Trying demuxer: disc (force-level: normal)
[demux] Trying demuxer: edl (force-level: normal)
[demux] Trying demuxer: cue (force-level: normal)
[demux] Trying demuxer: rawaudio (force-level: normal)
[demux] Trying demuxer: rawvideo (force-level: normal)
[demux] Trying demuxer: tv (force-level: normal)
[demux] Trying demuxer: mkv (force-level: normal)
[demux] Trying demuxer: rar (force-level: normal)
[demux] Trying demuxer: lavf (force-level: normal)
[lavf] Found 'dsf' at score=100 size=2048.
[ffmpeg/demuxer] dsf: Estimating duration from bitrate, this may be inaccurate
[lavf] avformat_find_stream_info() finished after 426012 bytes.
[demux] Detected file format: dsf (libavformat)
[find_files] Loading external files in .
[global] config path: 'sub/' -/-> '/home/james/.config/mpv/sub/'
[global] config path: 'sub/' -/-> '/home/james/.mpv/sub/'
[global] config path: 'sub/' -/-> '/etc/mpv/sub/'
[cplayer]  (+) Audio --aid=1 (dsd_lsbf_planar)
[display-tags] File tags:
[display-tags]  Artist: Pink Floyd
[display-tags]  Album: Wish You Were Here
[display-tags]  Genre: Other
[display-tags]  Title: Welcome To The Machine
[display-tags]  Track: 2
[ad] Codec list:
[ad]     lavc:dsd_lsbf_planar - DSD (Direct Stream Digital), least significant bit first, planar
[ad] Opening audio decoder lavc:dsd_lsbf_planar
[ad] Requesting 1 threads for decoding.
[ad] Selected audio codec: DSD (Direct Stream Digital), least significant bit first, planar [lavc:dsd_lsbf_planar]
[cplayer] Starting playback...
[af] Audio filter chain:
[af]   [in] 352800Hz stereo 2ch floatp
[af]   [out] 352800Hz stereo 2ch floatp
[af]   [ao] 352800Hz stereo 2ch floatp
[ao] Trying audio driver 'pulse'
[ao] Using preferred device 'alsa_output.pci-0000_04_02.0.analog-stereo'
[ao/pulse] requested format: 352800 Hz, stereo channels, floatp
[ao/pulse] Library version: 4.0.0
[ao/pulse] Proto: 28
[ao/pulse] Server proto: 4294967295
[ao/pulse] Channel layouts:
[ao/pulse]  - #fl
[ao/pulse]  - #fr
[ao/pulse]  - #fc
[ao/pulse]  - #lfe
[ao/pulse]  - #bl
[ao/pulse]  - #br
[ao/pulse]  - #flc
[ao/pulse]  - #frc
[ao/pulse]  - #bc
[ao/pulse]  - #sl
[ao/pulse]  - #sr
[ao/pulse]  - #tc
[ao/pulse]  - #tfl
[ao/pulse]  - #tfc
[ao/pulse]  - #tfr
[ao/pulse]  - #tbl
[ao/pulse]  - #tbc
[ao/pulse]  - #tbr
[ao/pulse] result: stereo
[ao/pulse] Stream failed.
[ao] Failed to initialize audio driver 'pulse'
[ao] This audio driver/device was forced with the --audio-device option.
[ao] Try unsetting it.
[cplayer] Could not open/initialize audio device -> no sound.
[ad] Uninit audio filters...
[ad] Uninit audio decoder.
[cplayer] Audio: no audio
[cplayer] playback restart complete
[cplayer] EOF code: 7  
[cplayer] finished playback, audio output initialization failed (reason 4)
[cplayer] 
[cplayer] 
[cplayer] Exiting... (Errors when loading file)
[ytdl_hook] Exiting...
[osc] Exiting...
$ 

The above error occurs when these DSF files are output via PulseAudio at all. I tested it with various --ao and --audio-device settings, and found that the only constant was ao_pulse and the dsd_lsbf_planar, 352800 Hz, stereo, fltp, 5644 kb/s audio. (I did not have a large variety of DSF files on hands to test, so I only tested the one type.)

And the PulseAudio ALSA plugin ignores the client's requested audio device, outputting all ALSA clients’ sound via the default sink. So just using ao_alsa for DSF files always is not a perfect workaround.

@ghost
Copy link

ghost commented Dec 30, 2015

I see no crash, it just refuses to initialize.

Pulse probably returns an error, because the samplerate is somehow out of range. We could probably resample to a lower samplerate, but there doesn't appear to be a way to know the maximum sampelrate pulse accepts?

@JamesTheAwesomeDude
Copy link
Author

Is https://trac.ffmpeg.org/ticket/3509 of interest/use to this?

@ghost
Copy link

ghost commented Dec 30, 2015

Not really. It just shows they had the same problem with ffplay, and solved it by hardcoding the samplerates. (What kind of fix is this? Pulse hardcodes a limit, so ffplay duplicates the limit?)

@JamesTheAwesomeDude
Copy link
Author

…oh god, you're right. 😨 I can't believe they actually committed that.

Would a "better" workaround be to find some way to "catch" the too-high-samplerate error and retry the audio, downsampling to 192kHz (or maybe even the destination audio device's maximum native rate) while spitting a warning to the terminal?
Or is this something best left not worked around (we'll just wait until PA gets its stuff together?)

@ghost
Copy link

ghost commented Dec 30, 2015

Well, I doubt pulse considers this a bug, but I don't know what the "correct" way to handle this. Actually, it might be possible that they just document a fixed limit in their API, but if they do, I can't see it. We also call a pa_format_info_valid() function, which seems to succeed.

In the best case, this is actually a PA bug. Maybe you could try to report it? Even if they close it as invalid, at least we'll know. Asking on the freenode IRC channel also might result in helpful comments.

@JamesTheAwesomeDude
Copy link
Author

When I first opened this issue, I asked about it and the 192kHz samplerate limit in #pulseaudio, but I didn't get any response. :/

I imagine the official stance on it is something along the lines of “If somebody tries to bring this up, don't make eye contact. If they pressure you about it, mumble something about CPU usage.”

That would be good if there were a max‐/card’s‐native‐samplerate API in Pulse, though.

@ghost
Copy link

ghost commented Dec 30, 2015

AFAIK you can ask pulse for a preferred samplerate.

@JamesTheAwesomeDude
Copy link
Author

Ooh, that gives me an idea for a least‐worst workaround: If PA dies because of too‐high‐samplerate, retry with the preferred one.

Does that hold any water? Or is it infeasible/unclean?

@ghost
Copy link

ghost commented Dec 30, 2015

Might be possible, but slightly messy, so I'd like to avoid it.

@ford-prefect
Copy link

We're looking at this in PulseAudio now:

http://lists.freedesktop.org/archives/pulseaudio-discuss/2015-December/025097.html

@ghost
Copy link

ghost commented Dec 31, 2015

Reading that thread, I actually found PA_RATE_MAX, and also a patch that fixes pa_format_info_valid().

I find it a bit strange that the maximum rate (which is really a rather arbitrary value) is part of the pulse client lib ABI - but fine, we can use that to limit the rate.

@JamesTheAwesomeDude
Copy link
Author

Something I was thinking: if we're going to be downsampling within the media player at all, why not downsample it to the target card's native rate? MPV resampling 352.8 > 192, only to have Pulse then resample it from 192 to the card's 48 or 44.1, seems like it would introduce more artifacts than is warranted, especially for playback of audio that was intended to be high quality.

On December 31, 2015 9:51:48 AM CST, "V. Lang" notifications@github.com wrote:

Reading that thread, I actually found PA_RATE_MAX, and also a patch
that fixes pa_format_info_valid().

I find it a bit strange that the maximum rate (which is really a rather
arbitrary value) is part of the pulse client lib ABI - but fine, we can
use that to limit the rate.


Reply to this email directly or view it on GitHub:
#2654 (comment)

@JamesTheAwesomeDude
Copy link
Author

Looking at that discussion thread, it looks like they're both fixing the bug in pa_format_info_valid() and bumping the maximum samplerate to 384kHz. Hopefully that should fix it.

One question: what will MPV resample the audio to if pa_format_info_valid() fails?

@ghost
Copy link

ghost commented Jan 5, 2016

One question: what will MPV resample the audio to if pa_format_info_valid() fails?

It will just fail initialization. But I was thinking it could try to set a default format. What that could be? No idea.

ghost pushed a commit that referenced this issue Jan 5, 2016
pa_format_info_valid() does not do this. (Although there is a proposed
patch on the PulseAudio mailing list.)

See #2654.
@ghost ghost closed this as completed in c1002f6 Jan 5, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants