Commit a3f03f3c authored by Max Kellermann's avatar Max Kellermann

removed playerData.c

Fetch the configuration variables buffered_chunks and buffered_before_play just when they are needed.
parent 90b34f8e
...@@ -90,7 +90,6 @@ mpd_headers = \ ...@@ -90,7 +90,6 @@ mpd_headers = \
permission.h \ permission.h \
player_thread.h \ player_thread.h \
player_control.h \ player_control.h \
playerData.h \
playlist.h \ playlist.h \
playlist_save.h \ playlist_save.h \
replay_gain.h \ replay_gain.h \
...@@ -172,7 +171,6 @@ mpd_SOURCES = \ ...@@ -172,7 +171,6 @@ mpd_SOURCES = \
permission.c \ permission.c \
player_thread.c \ player_thread.c \
player_control.c \ player_control.c \
playerData.c \
playlist.c \ playlist.c \
playlist_save.c \ playlist_save.c \
replay_gain.c \ replay_gain.c \
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "replay_gain.h" #include "replay_gain.h"
#include "tag.h" #include "tag.h"
#include "audio_format.h" #include "audio_format.h"
#include "playerData.h"
#include <stdbool.h> #include <stdbool.h>
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "conf.h" #include "conf.h"
#include "path.h" #include "path.h"
#include "mapper.h" #include "mapper.h"
#include "playerData.h"
#include "pipe.h" #include "pipe.h"
#include "decoder_thread.h" #include "decoder_thread.h"
#include "decoder_control.h" #include "decoder_control.h"
...@@ -70,6 +69,11 @@ ...@@ -70,6 +69,11 @@
#include <locale.h> #include <locale.h>
#endif #endif
enum {
DEFAULT_BUFFER_SIZE = 2048,
DEFAULT_BUFFER_BEFORE_PLAY = 10,
};
GThread *main_task; GThread *main_task;
GMainLoop *main_loop; GMainLoop *main_loop;
...@@ -111,6 +115,55 @@ static void openDB(Options * options, char *argv0) ...@@ -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 static gboolean
timer_save_state_file(G_GNUC_UNUSED gpointer data) timer_save_state_file(G_GNUC_UNUSED gpointer data)
{ {
...@@ -189,10 +242,7 @@ int main(int argc, char *argv[]) ...@@ -189,10 +242,7 @@ int main(int argc, char *argv[])
openDB(&options, argv[0]); openDB(&options, argv[0]);
command_init(); command_init();
initPlayerData(); initialize_decoder_and_player();
pc_init(buffered_before_play);
music_pipe_init(buffered_chunks, &pc.notify);
dc_init();
initAudioConfig(); initAudioConfig();
initAudioDriver(); initAudioDriver();
volume_init(); volume_init();
......
/* the Music Player Daemon (MPD)
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "playerData.h"
#include "pipe.h"
#include "conf.h"
#include "log.h"
#include <stdlib.h>
#define DEFAULT_BUFFER_SIZE 2048
#define DEFAULT_BUFFER_BEFORE_PLAY 10
unsigned int buffered_chunks;
unsigned int buffered_before_play;
void initPlayerData(void)
{
float perc = DEFAULT_BUFFER_BEFORE_PLAY;
char *test;
size_t bufferSize = DEFAULT_BUFFER_SIZE;
struct config_param *param;
param = config_get_param(CONF_AUDIO_BUFFER_SIZE);
if (param) {
bufferSize = strtol(param->value, &test, 10);
if (*test != '\0' || bufferSize <= 0) {
FATAL("buffer size \"%s\" is not a positive integer, "
"line %i\n", param->value, param->line);
}
}
bufferSize *= 1024;
buffered_chunks = bufferSize / CHUNK_SIZE;
if (buffered_chunks >= 1 << 15) {
FATAL("buffer size \"%li\" is too big\n", (long)bufferSize);
}
param = config_get_param(CONF_BUFFER_BEFORE_PLAY);
if (param) {
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);
}
}
buffered_before_play = (perc / 100) * buffered_chunks;
if (buffered_before_play > buffered_chunks) {
buffered_before_play = buffered_chunks;
}
}
/* the Music Player Daemon (MPD)
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MPD_PLAYER_DATA_H
#define MPD_PLAYER_DATA_H
extern unsigned int buffered_chunks;
extern unsigned int buffered_before_play;
void initPlayerData(void);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment