summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2009-02-04 18:52:10 +0100
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2009-02-04 18:52:10 +0100
commit9bf820b044e846bb2b17dfb2b78a1d9a8d3c59f1 (patch)
tree02b3c4a2afc6c398b8a670de454b5b6efe3b04f6
parentf94f57e565abde0a4645c2e66f378c39f082bf0e (diff)
downloadpianobar-windows-9bf820b044e846bb2b17dfb2b78a1d9a8d3c59f1.tar.gz
pianobar-windows-9bf820b044e846bb2b17dfb2b78a1d9a8d3c59f1.tar.bz2
pianobar-windows-9bf820b044e846bb2b17dfb2b78a1d9a8d3c59f1.zip
Buffer abstraction
Replace copy&waste by inline functions
-rw-r--r--src/player.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/player.c b/src/player.c
index da4f60a..4266e44 100644
--- a/src/player.c
+++ b/src/player.c
@@ -75,6 +75,27 @@ inline signed short int applyReplayGain (signed short int value,
}
}
+inline int BarPlayerBufferFill (struct audioPlayer *player, char *data,
+ size_t dataSize) {
+ /* fill buffer */
+ if (player->bufferFilled + dataSize > sizeof (player->buffer)) {
+ printf (PACKAGE ": Buffer overflow!\n");
+ return 0;
+ }
+ memcpy (player->buffer+player->bufferFilled, data, dataSize);
+ player->bufferFilled += dataSize;
+ player->bufferRead = 0;
+ player->bytesReceived += dataSize;
+ return 1;
+}
+
+inline void BarPlayerBufferMove (struct audioPlayer *player) {
+ /* move remaining bytes to buffer beginning */
+ memmove (player->buffer, player->buffer + player->bufferRead,
+ (player->bufferFilled - player->bufferRead));
+ player->bufferFilled -= player->bufferRead;
+}
+
#ifdef ENABLE_FAAD
/* play aac stream
@@ -90,15 +111,9 @@ size_t BarPlayerAACCurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
QUIT_PAUSE_CHECK;
- /* fill buffer */
- if (player->bufferFilled + size*nmemb > sizeof (player->buffer)) {
- printf (PACKAGE ": Buffer overflow!\n");
+ if (!BarPlayerBufferFill (player, data, size*nmemb)) {
return 0;
}
- memcpy (player->buffer+player->bufferFilled, data, size*nmemb);
- player->bufferFilled += size*nmemb;
- player->bufferRead = 0;
- player->bytesReceived += size*nmemb;
if (player->mode == PLAYER_RECV_DATA) {
short int *aacDecoded;
@@ -229,10 +244,7 @@ size_t BarPlayerAACCurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
}
}
- /* move remaining bytes to buffer beginning */
- memmove (player->buffer, player->buffer + player->bufferRead,
- (player->bufferFilled - player->bufferRead));
- player->bufferFilled -= player->bufferRead;
+ BarPlayerBufferMove (player);
return size*nmemb;
}
@@ -264,15 +276,9 @@ size_t BarPlayerMp3CurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
QUIT_PAUSE_CHECK;
- /* fill buffer */
- if (player->bufferFilled + size*nmemb > sizeof (player->buffer)) {
- printf (PACKAGE ": Buffer overflow!\n");
+ if (!BarPlayerBufferFill (player, data, size*nmemb)) {
return 0;
}
- memcpy (player->buffer+player->bufferFilled, data, size*nmemb);
- player->bufferFilled += size*nmemb;
- player->bufferRead = 0;
- player->bytesReceived += size*nmemb;
mad_stream_buffer (&player->mp3Stream, player->buffer,
player->bufferFilled);
@@ -326,10 +332,7 @@ size_t BarPlayerMp3CurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
player->bufferRead += player->mp3Stream.next_frame - player->buffer;
- /* move remaining bytes to buffer beginning */
- memmove (player->buffer, player->buffer + player->bufferRead,
- (player->bufferFilled - player->bufferRead));
- player->bufferFilled -= player->bufferRead;
+ BarPlayerBufferMove (player);
return size*nmemb;
}