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
This commit is contained in:
Max Kellermann 2008-04-12 04:12:01 +00:00 committed by Eric Wong
parent 82fbf1a24c
commit f6ed3eaeae

View File

@ -196,56 +196,59 @@ static int decodeSeek(PlayerControl * pc, DecoderControl * dc,
return ret; return ret;
} }
#define processDecodeInput() \ static void processDecodeInput(PlayerControl * pc, DecoderControl * dc,
if(pc->lockQueue) { \ OutputBuffer * cb,
pc->queueLockState = PLAYER_QUEUE_LOCKED; \ int *pause_r, unsigned int *bbp_r,
pc->lockQueue = 0; \ int *doCrossFade_r,
wakeup_main_task(); \ int *nextChunk_r,
} \ int *decodeWaitedOn_r,
if(pc->unlockQueue) { \ int *next_r)
pc->queueLockState = PLAYER_QUEUE_UNLOCKED; \ {
pc->unlockQueue = 0; \ if(pc->lockQueue) {
wakeup_main_task(); \ pc->queueLockState = PLAYER_QUEUE_LOCKED;
} \ pc->lockQueue = 0;
if(pc->pause) { \ wakeup_main_task();
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; \
} }
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, static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
DecoderControl * dc) DecoderControl * dc)
@ -427,12 +430,28 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
while (availableOutputBuffer(cb) < bbp && while (availableOutputBuffer(cb) < bbp &&
dc->state != DECODE_STATE_STOP) { 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(); player_sleep();
} }
while (!quit) { while (!quit) {
processDecodeInput(); processDecodeInput(pc, dc, cb,
&pause, &bbp, &doCrossFade,
&nextChunk, &decodeWaitedOn, &next);
if (pc->stop) {
dropBufferedAudio();
quitDecode(pc,dc);
return;
}
handleDecodeStart(); handleDecodeStart();
if (dc->state == DECODE_STATE_STOP && if (dc->state == DECODE_STATE_STOP &&
pc->queueState == PLAYER_QUEUE_FULL && pc->queueState == PLAYER_QUEUE_FULL &&
@ -540,7 +559,16 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
} }
while (pc->queueState == PLAYER_QUEUE_DECODE || while (pc->queueState == PLAYER_QUEUE_DECODE ||
pc->queueLockState == PLAYER_QUEUE_LOCKED) { 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(); player_sleep();
} }
if (pc->queueState != PLAYER_QUEUE_PLAY) if (pc->queueState != PLAYER_QUEUE_PLAY)