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:
parent
82fbf1a24c
commit
f6ed3eaeae
132
src/decode.c
132
src/decode.c
@ -196,55 +196,58 @@ 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) { \
|
if(pc->unlockQueue) {
|
||||||
pc->state = PLAYER_STATE_PAUSE; \
|
pc->queueLockState = PLAYER_QUEUE_UNLOCKED;
|
||||||
} else { \
|
pc->unlockQueue = 0;
|
||||||
if (openAudioDevice(NULL) >= 0) { \
|
wakeup_main_task();
|
||||||
pc->state = PLAYER_STATE_PLAY; \
|
}
|
||||||
} else { \
|
if(pc->pause) {
|
||||||
char tmp[MPD_PATH_MAX]; \
|
*pause_r = !*pause_r;
|
||||||
pc->errored_song = pc->current_song; \
|
if (*pause_r) {
|
||||||
pc->error = PLAYER_ERROR_AUDIO; \
|
pc->state = PLAYER_STATE_PAUSE;
|
||||||
ERROR("problems opening audio device " \
|
} else {
|
||||||
"while playing \"%s\"\n", \
|
if (openAudioDevice(NULL) >= 0) {
|
||||||
get_song_url(tmp, pc->current_song)); \
|
pc->state = PLAYER_STATE_PLAY;
|
||||||
pause = -1; \
|
} else {
|
||||||
} \
|
char tmp[MPD_PATH_MAX];
|
||||||
} \
|
pc->errored_song = pc->current_song;
|
||||||
pc->pause = 0; \
|
pc->error = PLAYER_ERROR_AUDIO;
|
||||||
wakeup_main_task(); \
|
ERROR("problems opening audio device "
|
||||||
if (pause == -1) { \
|
"while playing \"%s\"\n",
|
||||||
pause = 1; \
|
get_song_url(tmp, pc->current_song));
|
||||||
} else if (pause) { \
|
*pause_r = -1;
|
||||||
dropBufferedAudio(); \
|
}
|
||||||
closeAudioDevice(); \
|
}
|
||||||
} \
|
pc->pause = 0;
|
||||||
} \
|
wakeup_main_task();
|
||||||
if(pc->seek) { \
|
if (*pause_r == -1) {
|
||||||
dropBufferedAudio(); \
|
*pause_r = 1;
|
||||||
if(decodeSeek(pc,dc,cb,&decodeWaitedOn,&next) == 0) { \
|
} else if (*pause_r) {
|
||||||
doCrossFade = 0; \
|
dropBufferedAudio();
|
||||||
nextChunk = -1; \
|
closeAudioDevice();
|
||||||
bbp = 0; \
|
}
|
||||||
} \
|
}
|
||||||
} \
|
if(pc->seek) {
|
||||||
if(pc->stop) { \
|
dropBufferedAudio();
|
||||||
dropBufferedAudio(); \
|
if(decodeSeek(pc,dc,cb,decodeWaitedOn_r,next_r) == 0) {
|
||||||
quitDecode(pc,dc); \
|
*doCrossFade_r = 0;
|
||||||
return; \
|
*nextChunk_r = -1;
|
||||||
|
*bbp_r = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
|
static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
|
||||||
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user