From 8ffcdb73e865ee6aff80db7cfcbdb44884b9ba95 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 28 Feb 2016 09:30:59 +0100 Subject: [PATCH] output/alsa: remove option "use_mmap" MPD does not really take advantage of memory-mapped I/O by generating data right into the ALSA buffer; using plain snd_pcm_mmap_writei() has no advantage compared to snd_pcm_writei(). Let's kill this non-feature. --- NEWS | 1 + doc/mpd.conf.5 | 5 --- doc/user.xml | 11 ------ src/output/plugins/AlsaOutputPlugin.cxx | 48 +++++-------------------- 4 files changed, 9 insertions(+), 56 deletions(-) diff --git a/NEWS b/NEWS index f201928f2..b5d5ccc22 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,7 @@ ver 0.20 (not yet released) - flac: new plugin which reads the "CUESHEET" metadata block * output - alsa: fix multi-channel order + - alsa: remove option "use_mmap" - jack: reduce CPU usage - pulse: set channel map to WAVE-EX - recorder: record tags diff --git a/doc/mpd.conf.5 b/doc/mpd.conf.5 index 23b319d8a..a3a366895 100644 --- a/doc/mpd.conf.5 +++ b/doc/mpd.conf.5 @@ -238,11 +238,6 @@ probably only useful if your alsa device has more than one identically\-named mixer control. The default is "0". Use "amixer scontrols" to see the list of controls with their indexes. .TP -.B use_mmap -Setting this allows you to use memory-mapped I/O. Certain hardware setups may -benefit from this, but most do not. Most users do not need to set this. The -default is to not use memory-mapped I/O. -.TP .B auto_resample Setting this to "no" disables ALSA's software resampling, if the hardware does not support a specific sample rate. This lets MPD do diff --git a/doc/user.xml b/doc/user.xml index 03dc1b41a..1e308c5d8 100644 --- a/doc/user.xml +++ b/doc/user.xml @@ -2482,17 +2482,6 @@ buffer_size: 16384 ...). - - - use_mmap - yes|no - - - If set to yes, then - libasound will try to use - memory mapped I/O. - - buffer_time diff --git a/src/output/plugins/AlsaOutputPlugin.cxx b/src/output/plugins/AlsaOutputPlugin.cxx index 461963df1..78d377eb6 100644 --- a/src/output/plugins/AlsaOutputPlugin.cxx +++ b/src/output/plugins/AlsaOutputPlugin.cxx @@ -50,9 +50,6 @@ static constexpr unsigned MPD_ALSA_BUFFER_TIME_US = 500000; static constexpr unsigned MPD_ALSA_RETRY_NR = 5; -typedef snd_pcm_sframes_t alsa_writei_t(snd_pcm_t * pcm, const void *buffer, - snd_pcm_uframes_t size); - struct AlsaOutput { AudioOutput base; @@ -64,9 +61,6 @@ struct AlsaOutput { */ std::string device; - /** use memory mapped I/O? */ - bool use_mmap; - #ifdef ENABLE_DSD /** * Enable DSD over PCM according to the DoP standard standard? @@ -88,13 +82,6 @@ struct AlsaOutput { /** the libasound PCM device handle */ snd_pcm_t *pcm; - /** - * a pointer to the libasound writei() function, which is - * snd_pcm_writei() or snd_pcm_mmap_writei(), depending on the - * use_mmap configuration - */ - alsa_writei_t *writei; - /** * The size of one audio frame passed to method play(). */ @@ -136,7 +123,7 @@ struct AlsaOutput { AlsaOutput() :base(alsa_output_plugin), - mode(0), writei(snd_pcm_writei) { + mode(0) { } ~AlsaOutput() { @@ -177,7 +164,7 @@ private: * Write silence to the ALSA device. */ void WriteSilence(snd_pcm_uframes_t nframes) { - writei(pcm, silence, nframes); + snd_pcm_writei(pcm, silence, nframes); } }; @@ -192,8 +179,6 @@ AlsaOutput::Configure(const ConfigBlock &block, Error &error) device = block.GetBlockValue("device", ""); - use_mmap = block.GetBlockValue("use_mmap", false); - #ifdef ENABLE_DSD dop = block.GetBlockValue("dop", false) || /* legacy name from MPD 0.18 and older: */ @@ -488,28 +473,11 @@ configure_hw: if (err < 0) goto error; - if (ad->use_mmap) { - err = snd_pcm_hw_params_set_access(ad->pcm, hwparams, - SND_PCM_ACCESS_MMAP_INTERLEAVED); - if (err < 0) { - FormatWarning(alsa_output_domain, - "Cannot set mmap'ed mode on ALSA device \"%s\": %s", - ad->GetDevice(), snd_strerror(-err)); - LogWarning(alsa_output_domain, - "Falling back to direct write mode"); - ad->use_mmap = false; - } else - ad->writei = snd_pcm_mmap_writei; - } - - if (!ad->use_mmap) { - cmd = "snd_pcm_hw_params_set_access"; - err = snd_pcm_hw_params_set_access(ad->pcm, hwparams, - SND_PCM_ACCESS_RW_INTERLEAVED); - if (err < 0) - goto error; - ad->writei = snd_pcm_writei; - } + cmd = "snd_pcm_hw_params_set_access"; + err = snd_pcm_hw_params_set_access(ad->pcm, hwparams, + SND_PCM_ACCESS_RW_INTERLEAVED); + if (err < 0) + goto error; err = alsa_output_setup_format(ad->pcm, hwparams, audio_format, params); @@ -890,7 +858,7 @@ AlsaOutput::Play(const void *chunk, size_t size, Error &error) assert(size > 0); while (true) { - snd_pcm_sframes_t ret = writei(pcm, chunk, size); + snd_pcm_sframes_t ret = snd_pcm_writei(pcm, chunk, size); if (ret > 0) { period_position = (period_position + ret) % period_frames;