summaryrefslogtreecommitdiff
path: root/src/Main.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-05-15 23:01:49 +0200
committerMax Kellermann <max@musicpd.org>2017-05-15 23:01:49 +0200
commit4faef28cc56c3ed72a22dbd1cb317cf756217400 (patch)
treef2a3e8168ce9efada0fd0afe9971f90f0dee12b4 /src/Main.cxx
parent89b900432e0bfb324356f6ae62a09241eb75d251 (diff)
parentb4c9d9c2a72fbf2c6c9090c73fe37fcc94dce1ca (diff)
Merge tag 'v0.20.7'
release v0.20.7
Diffstat (limited to 'src/Main.cxx')
-rw-r--r--src/Main.cxx33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/Main.cxx b/src/Main.cxx
index be6d0ea7f..7a5e8cc62 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -116,7 +116,13 @@
#include <limits.h>
-static constexpr unsigned DEFAULT_BUFFER_SIZE = 4096;
+static constexpr size_t KILOBYTE = 1024;
+static constexpr size_t MEGABYTE = 1024 * KILOBYTE;
+
+static constexpr size_t DEFAULT_BUFFER_SIZE = 4 * MEGABYTE;
+static constexpr size_t MIN_BUFFER_SIZE = std::max(CHUNK_SIZE * 32,
+ 64 * KILOBYTE);
+
static constexpr unsigned DEFAULT_BUFFER_BEFORE_PLAY = 10;
#ifdef ANDROID
@@ -129,7 +135,6 @@ struct Config {
ReplayGainConfig replay_gain;
};
-gcc_const
static Config
LoadConfig()
{
@@ -306,12 +311,17 @@ initialize_decoder_and_player(const ReplayGainConfig &replay_gain_config)
FormatFatalError("buffer size \"%s\" is not a "
"positive integer, line %i",
param->value.c_str(), param->line);
- buffer_size = tmp;
+ buffer_size = tmp * KILOBYTE;
+
+ if (buffer_size < MIN_BUFFER_SIZE) {
+ FormatWarning(config_domain, "buffer size %lu is too small, using %lu bytes instead",
+ (unsigned long)buffer_size,
+ (unsigned long)MIN_BUFFER_SIZE);
+ buffer_size = MIN_BUFFER_SIZE;
+ }
} else
buffer_size = DEFAULT_BUFFER_SIZE;
- buffer_size *= 1024;
-
const unsigned buffered_chunks = buffer_size / CHUNK_SIZE;
if (buffered_chunks >= 1 << 15)
@@ -329,6 +339,19 @@ initialize_decoder_and_player(const ReplayGainConfig &replay_gain_config)
"than 100 percent, line %i",
param->value.c_str(), param->line);
}
+
+ if (perc > 80) {
+ /* this upper limit should avoid deadlocks
+ which can occur because the DecoderThread
+ cannot ever fill the music buffer to
+ exactly 100%; a few chunks always need to
+ be available to generate silence in
+ Player::SendSilence() */
+ FormatError(config_domain,
+ "buffer_before_play is too large (%f%%), capping at 80%%; please fix your configuration",
+ perc);
+ perc = 80;
+ }
} else
perc = DEFAULT_BUFFER_BEFORE_PLAY;