aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-04-12 04:12:01 +0000
committerEric Wong <normalperson@yhbt.net>2008-04-12 04:12:01 +0000
commitf6ed3eaeae593c65e577ef77822c2f60fe2af7a7 (patch)
tree93d4dd8b6ba4055d41d043565e56085d2624617f
parent82fbf1a24c8fa1048afcdde5235d58fbc5a8095d (diff)
downloadmpd-f6ed3eaeae593c65e577ef77822c2f60fe2af7a7.tar.gz
mpd-f6ed3eaeae593c65e577ef77822c2f60fe2af7a7.tar.xz
mpd-f6ed3eaeae593c65e577ef77822c2f60fe2af7a7.zip
converted macro processDecodeInput() to function
Macros are ugly, and multi-line macros are even more ugly. This patch converts processDecodeInput() to a C function. The disadvantage may be that the function does not have access to the caller's local variables, which might be regarded as an advantage on the other hand. For this reason, we have to pass variable references. This costs a tiny bit of performance, but it's worth eliminating this monster macro, and further patches will optimize this cost down. git-svn-id: https://svn.musicpd.org/mpd/trunk@7254 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/decode.c132
1 files changed, 80 insertions, 52 deletions
diff --git a/src/decode.c b/src/decode.c
index fe845f7be..6c0b9bfff 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -196,56 +196,59 @@ static int decodeSeek(PlayerControl * pc, DecoderControl * dc,
return ret;
}
-#define processDecodeInput() \
- if(pc->lockQueue) { \
- pc->queueLockState = PLAYER_QUEUE_LOCKED; \
- pc->lockQueue = 0; \
- wakeup_main_task(); \
- } \
- if(pc->unlockQueue) { \
- pc->queueLockState = PLAYER_QUEUE_UNLOCKED; \
- pc->unlockQueue = 0; \
- wakeup_main_task(); \
- } \
- if(pc->pause) { \
- pause = !pause; \
- if (pause) { \
- pc->state = PLAYER_STATE_PAUSE; \
- } else { \
- if (openAudioDevice(NULL) >= 0) { \
- pc->state = PLAYER_STATE_PLAY; \
- } else { \
- char tmp[MPD_PATH_MAX]; \
- pc->errored_song = pc->current_song; \
- pc->error = PLAYER_ERROR_AUDIO; \
- ERROR("problems opening audio device " \
- "while playing \"%s\"\n", \
- get_song_url(tmp, pc->current_song)); \
- pause = -1; \
- } \
- } \
- pc->pause = 0; \
- wakeup_main_task(); \
- if (pause == -1) { \
- pause = 1; \
- } else if (pause) { \
- dropBufferedAudio(); \
- closeAudioDevice(); \
- } \
- } \
- if(pc->seek) { \
- dropBufferedAudio(); \
- if(decodeSeek(pc,dc,cb,&decodeWaitedOn,&next) == 0) { \
- doCrossFade = 0; \
- nextChunk = -1; \
- bbp = 0; \
- } \
- } \
- if(pc->stop) { \
- dropBufferedAudio(); \
- quitDecode(pc,dc); \
- return; \
+static void processDecodeInput(PlayerControl * pc, DecoderControl * dc,
+ OutputBuffer * cb,
+ int *pause_r, unsigned int *bbp_r,
+ int *doCrossFade_r,
+ int *nextChunk_r,
+ int *decodeWaitedOn_r,
+ int *next_r)
+{
+ if(pc->lockQueue) {
+ pc->queueLockState = PLAYER_QUEUE_LOCKED;
+ pc->lockQueue = 0;
+ wakeup_main_task();
+ }
+ if(pc->unlockQueue) {
+ pc->queueLockState = PLAYER_QUEUE_UNLOCKED;
+ pc->unlockQueue = 0;
+ wakeup_main_task();
}
+ if(pc->pause) {
+ *pause_r = !*pause_r;
+ if (*pause_r) {
+ pc->state = PLAYER_STATE_PAUSE;
+ } else {
+ if (openAudioDevice(NULL) >= 0) {
+ pc->state = PLAYER_STATE_PLAY;
+ } else {
+ char tmp[MPD_PATH_MAX];
+ pc->errored_song = pc->current_song;
+ pc->error = PLAYER_ERROR_AUDIO;
+ ERROR("problems opening audio device "
+ "while playing \"%s\"\n",
+ get_song_url(tmp, pc->current_song));
+ *pause_r = -1;
+ }
+ }
+ pc->pause = 0;
+ wakeup_main_task();
+ if (*pause_r == -1) {
+ *pause_r = 1;
+ } else if (*pause_r) {
+ dropBufferedAudio();
+ closeAudioDevice();
+ }
+ }
+ if(pc->seek) {
+ dropBufferedAudio();
+ if(decodeSeek(pc,dc,cb,decodeWaitedOn_r,next_r) == 0) {
+ *doCrossFade_r = 0;
+ *nextChunk_r = -1;
+ *bbp_r = 0;
+ }
+ }
+}
static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
DecoderControl * dc)
@@ -427,12 +430,28 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
while (availableOutputBuffer(cb) < bbp &&
dc->state != DECODE_STATE_STOP) {
- processDecodeInput();
+ processDecodeInput(pc, dc, cb,
+ &pause, &bbp, &doCrossFade,
+ &nextChunk, &decodeWaitedOn, &next);
+ if (pc->stop) {
+ dropBufferedAudio();
+ quitDecode(pc,dc);
+ return;
+ }
+
player_sleep();
}
while (!quit) {
- processDecodeInput();
+ processDecodeInput(pc, dc, cb,
+ &pause, &bbp, &doCrossFade,
+ &nextChunk, &decodeWaitedOn, &next);
+ if (pc->stop) {
+ dropBufferedAudio();
+ quitDecode(pc,dc);
+ return;
+ }
+
handleDecodeStart();
if (dc->state == DECODE_STATE_STOP &&
pc->queueState == PLAYER_QUEUE_FULL &&
@@ -540,7 +559,16 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
}
while (pc->queueState == PLAYER_QUEUE_DECODE ||
pc->queueLockState == PLAYER_QUEUE_LOCKED) {
- processDecodeInput();
+ processDecodeInput(pc, dc, cb,
+ &pause, &bbp, &doCrossFade,
+ &nextChunk, &decodeWaitedOn,
+ &next);
+ if (pc->stop) {
+ dropBufferedAudio();
+ quitDecode(pc,dc);
+ return;
+ }
+
player_sleep();
}
if (pc->queueState != PLAYER_QUEUE_PLAY)