diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-08-20 01:31:51 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-08-20 01:31:51 -0700 |
commit | 1b197e65232e1a51b853db53985e8eda61f1b196 (patch) | |
tree | 2d85ff67ba79e32256a20d2d2bee7222352007fd /src/outputBuffer_config_init.h | |
parent | 5a0216af3dc7c9dedc4dacb708191f0fd380bb73 (diff) | |
parent | 508ae1c18d3bdc99a1bb06181762e5ec859cf072 (diff) | |
download | mpd-1b197e65232e1a51b853db53985e8eda61f1b196.tar.gz mpd-1b197e65232e1a51b853db53985e8eda61f1b196.tar.xz mpd-1b197e65232e1a51b853db53985e8eda61f1b196.zip |
Merge branch 'core-rewrite' of git://git.musicpd.org/normalperson/mpd
* 'core-rewrite' of git://git.musicpd.org/normalperson/mpd:
Remove ob_wait_sync and cleanup triggering in playlist
fix output buffer deadlock when daemonizing
log.c: thread-safety for warning log
core rewrite (decode,player,outputBuffer,playlist)
Diffstat (limited to '')
-rw-r--r-- | src/outputBuffer_config_init.h (renamed from src/playerData.c) | 81 |
1 files changed, 39 insertions, 42 deletions
diff --git a/src/playerData.c b/src/outputBuffer_config_init.h index 3934d0c6f..ba5b7f137 100644 --- a/src/playerData.c +++ b/src/outputBuffer_config_init.h @@ -16,7 +16,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "playerData.h" #include "conf.h" #include "log.h" #include "utils.h" @@ -24,67 +23,65 @@ #define DEFAULT_BUFFER_SIZE 2048 #define DEFAULT_BUFFER_BEFORE_PLAY 10 -unsigned int buffered_before_play; -PlayerControl pc; -DecoderControl dc; -OutputBuffer ob; -void initPlayerData(void) +void config_output_buffer(void) { float perc = DEFAULT_BUFFER_BEFORE_PLAY; char *test; - int crossfade = 0; - size_t bufferSize = DEFAULT_BUFFER_SIZE; - unsigned int buffered_chunks; + size_t buffer_size = DEFAULT_BUFFER_SIZE; ConfigParam *param; + unsigned int buffered_before_play; + unsigned int buffered_chunks; - param = getConfigParam(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, " + if ((param = getConfigParam(CONF_AUDIO_BUFFER_SIZE))) { + buffer_size = strtol(param->value, &test, 10); + if (*test != '\0' || buffer_size <= 0) + FATAL(CONF_AUDIO_BUFFER_SIZE + " \"%s\" is not a positive integer, " "line %i\n", param->value, param->line); - } } - bufferSize *= 1024; + buffer_size *= 1024; + buffered_chunks = buffer_size / CHUNK_SIZE; - buffered_chunks = bufferSize / CHUNK_SIZE; + if (buffered_chunks >= 1 << 15) + FATAL("buffer size \"%li\" is too big\n", (long)buffer_size); - if (buffered_chunks >= 1 << 15) { - FATAL("buffer size \"%li\" is too big\n", (long)bufferSize); - } - - param = getConfigParam(CONF_BUFFER_BEFORE_PLAY); - - if (param) { + if ((param = getConfigParam(CONF_BUFFER_BEFORE_PLAY))) { perc = strtod(param->value, &test); - if (*test != '%' || perc < 0 || perc > 100) { - FATAL("buffered before play \"%s\" is not a positive " + if (*test != '%' || perc < 0 || perc > 100) + FATAL(CONF_BUFFER_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) { + if (buffered_before_play > buffered_chunks) buffered_before_play = buffered_chunks; - } + ob.nr_bpp = buffered_before_play; - ob_init(buffered_chunks); - - notify_init(&pc.notify); - pc.error = PLAYER_ERROR_NOERROR; - pc.state = PLAYER_STATE_STOP; - pc.queueState = PLAYER_QUEUE_BLANK; - pc.queueLockState = PLAYER_QUEUE_UNLOCKED; - pc.crossFade = crossfade; - pc.softwareVolume = 1000; + assert(buffered_chunks > 0 && !ob.index && !ob.chunks); + ob.index = ringbuf_create(buffered_chunks); + ob.chunks = xcalloc(ob.index->size, sizeof(struct ob_chunk)); + ob.preseek_len = xmalloc(ob.index->size * sizeof(ob.chunks[0].len)); + ob.state = OB_STATE_STOP; +} - notify_init(&dc.notify); - dc.state = DECODE_STATE_STOP; - dc.error = DECODE_ERROR_NOERROR; +static void ob_free(void) +{ + free(ob.chunks); + ringbuf_free(ob.index); } +void init_output_buffer(void) +{ + pthread_attr_t attr; + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + if (pthread_create(&ob.thread, &attr, ob_task, NULL)) + FATAL("Failed to spawn player task: %s\n", strerror(errno)); + atexit(ob_free); +} |