summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2010-03-12 12:33:33 +0100
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2010-03-16 15:24:49 +0100
commit97d9c978334236f9ba190da342eb11f645ccde03 (patch)
tree2212e21160d364c31b7c9667c15f6944fa05de87
parent13bd3c8253a5c2998ce85a084a854f7a3d0ba7f5 (diff)
downloadpianobar-97d9c978334236f9ba190da342eb11f645ccde03.tar.gz
pianobar-97d9c978334236f9ba190da342eb11f645ccde03.tar.bz2
pianobar-97d9c978334236f9ba190da342eb11f645ccde03.zip
waitress: Replaced callback magic numbers
-rw-r--r--libwaitress/src/waitress.c14
-rw-r--r--libwaitress/src/waitress.h4
-rw-r--r--src/player.c27
3 files changed, 25 insertions, 20 deletions
diff --git a/libwaitress/src/waitress.c b/libwaitress/src/waitress.c
index 70a1547..72f5f0f 100644
--- a/libwaitress/src/waitress.c
+++ b/libwaitress/src/waitress.c
@@ -180,7 +180,7 @@ inline void WaitressSetHPP (WaitressHandle_t *waith, const char *host,
* @param data size
* @param buffer structure
*/
-static char WaitressFetchBufCb (void *recvData, size_t recvDataSize,
+static WaitressCbReturn_t WaitressFetchBufCb (void *recvData, size_t recvDataSize,
void *extraData) {
char *recvBytes = recvData;
WaitressFetchBufCbBuffer_t *buffer = extraData;
@@ -188,7 +188,7 @@ static char WaitressFetchBufCb (void *recvData, size_t recvDataSize,
if (buffer->buf == NULL) {
if ((buffer->buf = malloc (sizeof (*buffer->buf) *
(recvDataSize + 1))) == NULL) {
- return 0;
+ return WAITRESS_CB_RET_ERR;
}
} else {
char *newbuf;
@@ -196,7 +196,7 @@ static char WaitressFetchBufCb (void *recvData, size_t recvDataSize,
sizeof (*buffer->buf) *
(buffer->pos + recvDataSize + 1))) == NULL) {
free (buffer->buf);
- return 0;
+ return WAITRESS_CB_RET_ERR;
}
buffer->buf = newbuf;
}
@@ -204,7 +204,7 @@ static char WaitressFetchBufCb (void *recvData, size_t recvDataSize,
buffer->pos += recvDataSize;
*(buffer->buf+buffer->pos) = '\0';
- return 1;
+ return WAITRESS_CB_RET_OK;
}
/* Fetch string. Beware! This overwrites your waith->data pointer
@@ -457,7 +457,8 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) {
/* push remaining bytes */
if (bufFilled > 0) {
waith->contentReceived += bufFilled;
- if (!waith->callback (thisLine, bufFilled, waith->data)) {
+ if (waith->callback (thisLine, bufFilled, waith->data) ==
+ WAITRESS_CB_RET_ERR) {
CLOSE_RET (WAITRESS_RET_CB_ABORT);
}
}
@@ -467,7 +468,8 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) {
READ_RET (recvBuf, sizeof (recvBuf), &recvSize);
if (recvSize > 0) {
waith->contentReceived += recvSize;
- if (!waith->callback (recvBuf, recvSize, waith->data)) {
+ if (waith->callback (recvBuf, recvSize, waith->data) ==
+ WAITRESS_CB_RET_ERR) {
wRet = WAITRESS_RET_CB_ABORT;
break;
}
diff --git a/libwaitress/src/waitress.h b/libwaitress/src/waitress.h
index 5fa1874..ed5679f 100644
--- a/libwaitress/src/waitress.h
+++ b/libwaitress/src/waitress.h
@@ -34,6 +34,8 @@ THE SOFTWARE.
typedef enum {WAITRESS_METHOD_GET = 0, WAITRESS_METHOD_POST} WaitressMethod_t;
+typedef enum {WAITRESS_CB_RET_ERR, WAITRESS_CB_RET_OK} WaitressCbReturn_t;
+
typedef struct {
char host[WAITRESS_HOST_SIZE];
char port[WAITRESS_PORT_SIZE];
@@ -47,7 +49,7 @@ typedef struct {
char proxyPort[WAITRESS_PORT_SIZE];
/* extra data handed over to callback function */
void *data;
- char (*callback) (void *, size_t, void *);
+ WaitressCbReturn_t (*callback) (void *, size_t, void *);
int socktimeout;
} WaitressHandle_t;
diff --git a/src/player.c b/src/player.c
index af7ed22..2eb6e27 100644
--- a/src/player.c
+++ b/src/player.c
@@ -37,12 +37,13 @@ THE SOFTWARE.
((x << 8) & 0x00ff0000) | ((x << 24) & 0xff000000))
/* wait while locked, but don't slow down main thread by keeping
-* locks too long */
+ * locks too long */
#define QUIT_PAUSE_CHECK \
pthread_mutex_lock (&player->pauseMutex); \
pthread_mutex_unlock (&player->pauseMutex); \
if (player->doQuit) { \
- return 0; \
+ /* err => abort playback */ \
+ return WAITRESS_CB_RET_ERR; \
}
/* pandora uses float values with 2 digits precision. Scale them by 100 to get
@@ -117,14 +118,14 @@ static inline void BarPlayerBufferMove (struct audioPlayer *player) {
* @param extra data (player data)
* @return received bytes or less on error
*/
-static char BarPlayerAACCb (void *ptr, size_t size, void *stream) {
+static WaitressCbReturn_t BarPlayerAACCb (void *ptr, size_t size, void *stream) {
char *data = ptr;
struct audioPlayer *player = stream;
QUIT_PAUSE_CHECK;
if (!BarPlayerBufferFill (player, data, size)) {
- return 0;
+ return WAITRESS_CB_RET_ERR;
}
if (player->mode == PLAYER_RECV_DATA) {
@@ -191,7 +192,7 @@ static char BarPlayerAACCb (void *ptr, size_t size, void *stream) {
BarUiMsg (MSG_ERR, "Error while "
"initializing audio decoder"
"(%i)\n", err);
- return 0;
+ return WAITRESS_CB_RET_ERR;
}
audioOutDriver = ao_default_driver_id();
format.bits = 16;
@@ -203,7 +204,7 @@ static char BarPlayerAACCb (void *ptr, size_t size, void *stream) {
/* we're not interested in the errno */
player->aoError = 1;
BarUiMsg (MSG_ERR, "Cannot open audio device\n");
- return 0;
+ return WAITRESS_CB_RET_ERR;
}
player->mode = PLAYER_AUDIO_INITIALIZED;
break;
@@ -278,7 +279,7 @@ static char BarPlayerAACCb (void *ptr, size_t size, void *stream) {
BarPlayerBufferMove (player);
- return 1;
+ return WAITRESS_CB_RET_OK;
}
#endif /* ENABLE_FAAD */
@@ -301,7 +302,7 @@ static inline signed short int BarPlayerMadToShort (mad_fixed_t fixed) {
return (signed short int) (fixed >> (MAD_F_FRACBITS - 15));
}
-static char BarPlayerMp3Cb (void *ptr, size_t size, void *stream) {
+static WaitressCbReturn_t BarPlayerMp3Cb (void *ptr, size_t size, void *stream) {
char *data = ptr;
struct audioPlayer *player = stream;
size_t i;
@@ -309,13 +310,13 @@ static char BarPlayerMp3Cb (void *ptr, size_t size, void *stream) {
QUIT_PAUSE_CHECK;
if (!BarPlayerBufferFill (player, data, size)) {
- return 0;
+ return WAITRESS_CB_RET_ERR;
}
/* some "prebuffering" */
if (player->mode < PLAYER_RECV_DATA &&
player->bufferFilled < sizeof (player->buffer) / 2) {
- return 1;
+ return WAITRESS_CB_RET_OK;
}
mad_stream_buffer (&player->mp3Stream, player->buffer,
@@ -329,7 +330,7 @@ static char BarPlayerMp3Cb (void *ptr, size_t size, void *stream) {
if (player->mp3Stream.error != MAD_ERROR_BUFLEN) {
BarUiMsg (MSG_ERR, "mp3 decoding error: %s\n",
mad_stream_errorstr (&player->mp3Stream));
- return 0;
+ return WAITRESS_CB_RET_ERR;
} else {
/* rebuffering required => exit loop */
break;
@@ -360,7 +361,7 @@ static char BarPlayerMp3Cb (void *ptr, size_t size, void *stream) {
&format, NULL)) == NULL) {
player->aoError = 1;
BarUiMsg (MSG_ERR, "Cannot open audio device\n");
- return 0;
+ return WAITRESS_CB_RET_ERR;
}
/* calc song length using the framerate of the first decoded frame */
@@ -392,7 +393,7 @@ static char BarPlayerMp3Cb (void *ptr, size_t size, void *stream) {
BarPlayerBufferMove (player);
- return 1;
+ return WAITRESS_CB_RET_OK;
}
#endif /* ENABLE_MAD */