aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-18 17:32:43 +0100
committerMax Kellermann <max@duempel.org>2009-01-18 17:32:43 +0100
commita3f03f3ccdefc8704d112405dca5db10a2f6cf94 (patch)
treee26e045a9694b32eb0292bde5407e1014ecdeac1 /src/main.c
parent90b34f8e6feb4dabc8da0d782cf5146318cfc02a (diff)
downloadmpd-a3f03f3ccdefc8704d112405dca5db10a2f6cf94.tar.gz
mpd-a3f03f3ccdefc8704d112405dca5db10a2f6cf94.tar.xz
mpd-a3f03f3ccdefc8704d112405dca5db10a2f6cf94.zip
removed playerData.c
Fetch the configuration variables buffered_chunks and buffered_before_play just when they are needed.
Diffstat (limited to '')
-rw-r--r--src/main.c60
1 files changed, 55 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index bfe89ae2a..9b1203a92 100644
--- a/src/main.c
+++ b/src/main.c
@@ -30,7 +30,6 @@
#include "conf.h"
#include "path.h"
#include "mapper.h"
-#include "playerData.h"
#include "pipe.h"
#include "decoder_thread.h"
#include "decoder_control.h"
@@ -70,6 +69,11 @@
#include <locale.h>
#endif
+enum {
+ DEFAULT_BUFFER_SIZE = 2048,
+ DEFAULT_BUFFER_BEFORE_PLAY = 10,
+};
+
GThread *main_task;
GMainLoop *main_loop;
@@ -111,6 +115,55 @@ static void openDB(Options * options, char *argv0)
}
}
+/**
+ * Initialize the decoder and player core, including the music pipe.
+ */
+static void
+initialize_decoder_and_player(void)
+{
+ struct config_param *param;
+ char *test;
+ size_t buffer_size;
+ float perc;
+ unsigned buffered_chunks;
+ unsigned buffered_before_play;
+
+ param = config_get_param(CONF_AUDIO_BUFFER_SIZE);
+ if (param != NULL) {
+ buffer_size = strtol(param->value, &test, 10);
+ if (*test != '\0' || buffer_size <= 0)
+ g_error("buffer size \"%s\" is not a positive integer, "
+ "line %i\n", param->value, param->line);
+ } else
+ buffer_size = DEFAULT_BUFFER_SIZE;
+
+ buffer_size *= 1024;
+
+ buffered_chunks = buffer_size / CHUNK_SIZE;
+
+ if (buffered_chunks >= 1 << 15)
+ g_error("buffer size \"%li\" is too big\n", (long)buffer_size);
+
+ param = config_get_param(CONF_BUFFER_BEFORE_PLAY);
+ if (param != NULL) {
+ perc = strtod(param->value, &test);
+ if (*test != '%' || perc < 0 || perc > 100) {
+ FATAL("buffered before play \"%s\" is not a positive "
+ "percentage and less than 100 percent, line %i"
+ "\n", param->value, param->line);
+ }
+ } else
+ perc = DEFAULT_BUFFER_BEFORE_PLAY;
+
+ buffered_before_play = (perc / 100) * buffered_chunks;
+ if (buffered_before_play > buffered_chunks)
+ buffered_before_play = buffered_chunks;
+
+ pc_init(buffered_before_play);
+ music_pipe_init(buffered_chunks, &pc.notify);
+ dc_init();
+}
+
static gboolean
timer_save_state_file(G_GNUC_UNUSED gpointer data)
{
@@ -189,10 +242,7 @@ int main(int argc, char *argv[])
openDB(&options, argv[0]);
command_init();
- initPlayerData();
- pc_init(buffered_before_play);
- music_pipe_init(buffered_chunks, &pc.notify);
- dc_init();
+ initialize_decoder_and_player();
initAudioConfig();
initAudioDriver();
volume_init();