2004-02-24 00:41:20 +01:00
|
|
|
/* the Music Player Daemon (MPD)
|
|
|
|
* (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
|
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "decode.h"
|
2004-02-27 02:35:23 +01:00
|
|
|
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "player.h"
|
|
|
|
#include "playerData.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "pcm_utils.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "path.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_MAD
|
|
|
|
#include "mp3_decode.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_OGG
|
|
|
|
#include "ogg_decode.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FLAC
|
|
|
|
#include "flac_decode.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_AUDIOFILE
|
|
|
|
#include "audiofile_decode.h"
|
|
|
|
#endif
|
2004-03-18 17:31:29 +01:00
|
|
|
#ifdef HAVE_FAAD
|
|
|
|
#include "mp4_decode.h"
|
2004-03-22 03:44:22 +01:00
|
|
|
#include "aac_decode.h"
|
2004-03-18 17:31:29 +01:00
|
|
|
#endif
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2004-02-27 23:25:06 +01:00
|
|
|
int * decode_pid = NULL;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
void decodeSigHandler(int sig) {
|
|
|
|
if(sig==SIGCHLD) {
|
|
|
|
int status;
|
2004-02-27 23:25:06 +01:00
|
|
|
if(decode_pid && *decode_pid==wait3(&status,WNOHANG,NULL)) {
|
2004-02-24 00:41:20 +01:00
|
|
|
if(WIFSIGNALED(status) && WTERMSIG(status)!=SIGTERM) {
|
|
|
|
ERROR("decode process died from a "
|
|
|
|
"non-TERM signal: %i\n",
|
|
|
|
WTERMSIG(status));
|
|
|
|
}
|
2004-02-27 23:25:06 +01:00
|
|
|
*decode_pid = 0;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(sig==SIGTERM) {
|
2004-02-27 23:25:06 +01:00
|
|
|
if(decode_pid) {
|
|
|
|
int pid = *decode_pid;
|
|
|
|
if(pid>0) kill(pid,SIGTERM);
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void stopDecode(DecoderControl * dc) {
|
2004-02-27 23:25:06 +01:00
|
|
|
if(decode_pid && *decode_pid>0 &&
|
|
|
|
(dc->start || dc->state==DECODE_STATE_DECODE))
|
|
|
|
{
|
2004-02-24 00:41:20 +01:00
|
|
|
dc->stop = 1;
|
2004-03-18 19:35:23 +01:00
|
|
|
while(decode_pid && *decode_pid>0 && dc->stop) usleep(1000);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void quitDecode(PlayerControl * pc, DecoderControl * dc) {
|
|
|
|
stopDecode(dc);
|
|
|
|
pc->state = PLAYER_STATE_STOP;
|
|
|
|
pc->play = 0;
|
|
|
|
pc->stop = 0;
|
|
|
|
pc->pause = 0;
|
|
|
|
kill(getppid(),SIGUSR1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) {
|
2004-03-05 02:29:08 +01:00
|
|
|
long chunks;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
if(pc->crossFade<=0) return 0;
|
|
|
|
|
|
|
|
chunks = (af->sampleRate*af->bits*af->channels/8.0/CHUNK_SIZE);
|
|
|
|
chunks = (chunks*pc->crossFade+0.5);
|
|
|
|
|
2004-02-25 22:10:56 +01:00
|
|
|
if(chunks>(buffered_chunks-buffered_before_play)) {
|
|
|
|
chunks = buffered_chunks-buffered_before_play;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2004-02-25 18:53:48 +01:00
|
|
|
if(chunks<0) chunks = 0;
|
|
|
|
|
2004-03-05 02:29:08 +01:00
|
|
|
return (int)chunks;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
|
|
|
|
Buffer * cb)
|
|
|
|
{
|
2004-03-18 19:35:23 +01:00
|
|
|
while(decode_pid && *decode_pid>0 && dc->start) usleep(1000);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
if(dc->start || dc->error!=DECODE_ERROR_NOERROR) {
|
2004-02-25 19:46:41 +01:00
|
|
|
strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
|
2004-02-24 00:41:20 +01:00
|
|
|
pc->error = PLAYER_ERROR_FILE;
|
|
|
|
quitDecode(pc,dc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(initAudio(af)<0) {
|
2004-02-25 19:46:41 +01:00
|
|
|
strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
|
2004-02-24 00:41:20 +01:00
|
|
|
pc->error = PLAYER_ERROR_AUDIO;
|
|
|
|
quitDecode(pc,dc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pc->elapsedTime = 0;
|
|
|
|
pc->bitRate = 0;
|
2004-02-27 02:35:23 +01:00
|
|
|
pc->sampleRate = af->sampleRate;
|
|
|
|
pc->bits = af->bits;
|
|
|
|
pc->channels = af->channels;
|
2004-02-24 00:41:20 +01:00
|
|
|
pc->totalTime = cb->totalTime;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
|
|
|
|
Buffer * cb)
|
|
|
|
{
|
2004-02-27 23:25:06 +01:00
|
|
|
if(decode_pid && *decode_pid>0) {
|
2004-02-24 00:41:20 +01:00
|
|
|
cb->next = -1;
|
|
|
|
if(dc->state!=DECODE_STATE_DECODE || dc->error ||
|
|
|
|
strcmp(dc->file,pc->file)!=0)
|
|
|
|
{
|
|
|
|
stopDecode(dc);
|
|
|
|
cb->end = 0;
|
|
|
|
dc->error = 0;
|
|
|
|
dc->start = 1;
|
|
|
|
dc->error = 0;
|
|
|
|
waitOnDecode(pc,af,dc,cb);
|
|
|
|
}
|
2004-02-27 23:25:06 +01:00
|
|
|
if(*decode_pid>0 && dc->state==DECODE_STATE_DECODE) {
|
2004-03-18 23:20:26 +01:00
|
|
|
dc->seekWhere = pc->seekWhere > pc->totalTime-0.1 ?
|
|
|
|
pc->totalTime-0.1 :
|
|
|
|
pc->seekWhere;
|
|
|
|
dc->seekWhere = 0 > dc->seekWhere ? 0 : dc->seekWhere;
|
2004-03-22 03:44:22 +01:00
|
|
|
dc->seekError = 0;
|
2004-02-24 00:41:20 +01:00
|
|
|
dc->seek = 1;
|
|
|
|
pc->bitRate = 0;
|
2004-03-18 19:35:23 +01:00
|
|
|
while(*decode_pid>0 && dc->seek) usleep(1000);
|
2004-03-22 03:44:22 +01:00
|
|
|
if(dc->seekError) pc->elapsedTime = dc->seekWhere;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pc->seek = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define processDecodeInput() \
|
|
|
|
if(pc->lockQueue) { \
|
|
|
|
pc->queueLockState = PLAYER_QUEUE_LOCKED; \
|
|
|
|
pc->lockQueue = 0; \
|
|
|
|
} \
|
|
|
|
if(pc->unlockQueue) { \
|
|
|
|
pc->queueLockState = PLAYER_QUEUE_UNLOCKED; \
|
|
|
|
pc->unlockQueue = 0; \
|
|
|
|
} \
|
|
|
|
if(pc->pause) { \
|
|
|
|
pause = !pause; \
|
2004-03-20 20:47:05 +01:00
|
|
|
if(pause) { \
|
|
|
|
finishAudio(); \
|
|
|
|
pc->state = PLAYER_STATE_PAUSE; \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
if(initAudio(NULL)<0) { \
|
|
|
|
strncpy(pc->erroredFile,pc->file,MAXPATHLEN); \
|
|
|
|
pc->error = PLAYER_ERROR_AUDIO; \
|
|
|
|
quitDecode(pc,dc); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
pc->state = PLAYER_STATE_PLAY; \
|
|
|
|
} \
|
2004-02-24 00:41:20 +01:00
|
|
|
pc->pause = 0; \
|
|
|
|
kill(getppid(),SIGUSR1); \
|
|
|
|
} \
|
|
|
|
if(pc->seek) { \
|
|
|
|
pc->totalPlayTime+= pc->elapsedTime-pc->beginTime; \
|
|
|
|
decodeSeek(pc,af,dc,cb); \
|
|
|
|
pc->beginTime = pc->elapsedTime; \
|
|
|
|
doCrossFade = 0; \
|
|
|
|
nextChunk = -1; \
|
|
|
|
bbp = 0; \
|
|
|
|
} \
|
|
|
|
if(pc->stop) { \
|
|
|
|
pc->totalPlayTime+= pc->elapsedTime-pc->beginTime; \
|
|
|
|
quitDecode(pc,dc); \
|
|
|
|
return; \
|
|
|
|
}
|
|
|
|
|
|
|
|
int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
|
|
|
|
DecoderControl * dc) {
|
2004-03-03 01:01:43 +01:00
|
|
|
int pid;
|
2004-03-22 19:44:15 +01:00
|
|
|
int ret;
|
2004-02-27 23:25:06 +01:00
|
|
|
decode_pid = &(pc->decode_pid);
|
2004-03-03 01:01:43 +01:00
|
|
|
pid = fork();
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-02-29 09:10:52 +01:00
|
|
|
if(pid==0) {
|
2004-02-24 00:41:20 +01:00
|
|
|
/* CHILD */
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if(dc->start) {
|
2004-02-25 19:46:41 +01:00
|
|
|
strncpy(dc->file,pc->file,MAXPATHLEN);
|
2004-02-24 00:41:20 +01:00
|
|
|
switch(pc->decodeType) {
|
|
|
|
#ifdef HAVE_MAD
|
|
|
|
case DECODE_TYPE_MP3:
|
2004-03-22 19:44:15 +01:00
|
|
|
ret = mp3_decode(cb,af,dc);
|
2004-02-24 00:41:20 +01:00
|
|
|
break;
|
|
|
|
#endif
|
2004-03-18 17:31:29 +01:00
|
|
|
#ifdef HAVE_FAAD
|
2004-03-22 03:44:22 +01:00
|
|
|
case DECODE_TYPE_AAC:
|
2004-03-22 19:44:15 +01:00
|
|
|
ret = aac_decode(cb,af,dc);
|
2004-03-22 03:44:22 +01:00
|
|
|
break;
|
2004-03-18 17:31:29 +01:00
|
|
|
case DECODE_TYPE_MP4:
|
2004-03-22 19:44:15 +01:00
|
|
|
ret = mp4_decode(cb,af,dc);
|
2004-03-18 17:31:29 +01:00
|
|
|
break;
|
|
|
|
#endif
|
2004-02-24 00:41:20 +01:00
|
|
|
#ifdef HAVE_OGG
|
|
|
|
case DECODE_TYPE_OGG:
|
2004-03-22 19:44:15 +01:00
|
|
|
ret = ogg_decode(cb,af,dc);
|
2004-02-24 00:41:20 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_FLAC
|
|
|
|
case DECODE_TYPE_FLAC:
|
2004-03-22 19:44:15 +01:00
|
|
|
ret = flac_decode(cb,af,dc);
|
2004-02-24 00:41:20 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_AUDIOFILE
|
|
|
|
case DECODE_TYPE_AUDIOFILE:
|
2004-03-22 19:44:15 +01:00
|
|
|
ret = audiofile_decode(cb,af,dc);
|
2004-02-24 00:41:20 +01:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2004-03-22 19:44:15 +01:00
|
|
|
ret = DECODE_ERROR_UNKTYPE;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-03-22 19:44:15 +01:00
|
|
|
if(ret<0) {
|
|
|
|
dc->error = DECODE_ERROR_FILE;
|
2004-02-24 00:41:20 +01:00
|
|
|
dc->start = 0;
|
|
|
|
dc->stop = 0;
|
|
|
|
dc->state = DECODE_STATE_STOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(dc->stop) {
|
|
|
|
dc->state = DECODE_STATE_STOP;
|
|
|
|
dc->stop = 0;
|
|
|
|
}
|
|
|
|
else if(dc->seek) dc->start = 1;
|
2004-03-07 00:25:32 +01:00
|
|
|
else usleep(10000);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
/* END OF CHILD */
|
|
|
|
}
|
2004-02-29 09:10:52 +01:00
|
|
|
else if(pid<0) {
|
2004-02-25 19:46:41 +01:00
|
|
|
strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
|
2004-02-24 00:41:20 +01:00
|
|
|
pc->error = PLAYER_ERROR_SYSTEM;
|
|
|
|
return -1;
|
|
|
|
}
|
2004-02-29 09:10:52 +01:00
|
|
|
else *decode_pid = pid;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* decode w/ buffering
|
|
|
|
* this will fork another process
|
|
|
|
* child process does decoding
|
|
|
|
* parent process does playing audio
|
|
|
|
*/
|
|
|
|
void decode() {
|
|
|
|
Buffer * cb;
|
|
|
|
PlayerControl * pc;
|
|
|
|
AudioFormat * af;
|
|
|
|
DecoderControl * dc;
|
|
|
|
|
|
|
|
cb = &(getPlayerData()->buffer);
|
|
|
|
|
|
|
|
cb->begin = 0;
|
|
|
|
cb->end = 0;
|
|
|
|
cb->wrap = 0;
|
|
|
|
pc = &(getPlayerData()->playerControl);
|
|
|
|
dc = &(getPlayerData()->decoderControl);
|
|
|
|
af = &(getPlayerData()->audioFormat);
|
|
|
|
dc->error = 0;
|
|
|
|
dc->start = 1;
|
|
|
|
cb->next = -1;
|
|
|
|
|
2004-02-27 23:25:06 +01:00
|
|
|
if(decode_pid==NULL || *decode_pid<=0) {
|
2004-02-24 00:41:20 +01:00
|
|
|
if(decoderInit(pc,cb,af,dc)<0) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* PARENT */
|
|
|
|
int pause = 0;
|
|
|
|
int quit = 0;
|
|
|
|
int bbp = buffered_before_play;
|
|
|
|
int doCrossFade = 0;
|
|
|
|
int crossFadeChunks = 0;
|
|
|
|
int fadePosition;
|
|
|
|
int nextChunk = -1;
|
|
|
|
int test;
|
|
|
|
|
|
|
|
if(waitOnDecode(pc,af,dc,cb)<0) return;
|
|
|
|
|
|
|
|
pc->state = PLAYER_STATE_PLAY;
|
|
|
|
pc->play = 0;
|
|
|
|
pc->beginTime = pc->elapsedTime;
|
|
|
|
kill(getppid(),SIGUSR1);
|
|
|
|
|
2004-02-27 23:25:06 +01:00
|
|
|
while(*decode_pid>0 && !cb->wrap && cb->end-cb->begin<bbp &&
|
2004-02-24 00:41:20 +01:00
|
|
|
dc->state==DECODE_STATE_DECODE)
|
|
|
|
{
|
|
|
|
processDecodeInput();
|
|
|
|
if(quit) return;
|
2004-03-07 00:25:32 +01:00
|
|
|
usleep(1000);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while(!quit) {
|
|
|
|
processDecodeInput();
|
|
|
|
if(dc->state==DECODE_STATE_STOP &&
|
|
|
|
pc->queueState==PLAYER_QUEUE_FULL &&
|
|
|
|
pc->queueLockState==PLAYER_QUEUE_UNLOCKED)
|
|
|
|
{
|
|
|
|
cb->next = cb->end;
|
|
|
|
dc->start = 1;
|
|
|
|
pc->queueState = PLAYER_QUEUE_DECODE;
|
|
|
|
kill(getppid(),SIGUSR1);
|
|
|
|
}
|
|
|
|
if(cb->next>=0 && doCrossFade==0 && !dc->start) {
|
|
|
|
nextChunk = -1;
|
|
|
|
if(isCurrentAudioFormat(af)) {
|
|
|
|
doCrossFade = 1;
|
|
|
|
crossFadeChunks =
|
|
|
|
calculateCrossFadeChunks(pc,af);
|
|
|
|
if(!crossFadeChunks ||
|
|
|
|
pc->crossFade>=cb->totalTime)
|
|
|
|
{
|
|
|
|
doCrossFade = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else doCrossFade = -1;
|
|
|
|
}
|
2004-03-20 20:47:05 +01:00
|
|
|
if(pause) usleep(10000);
|
2004-02-24 00:41:20 +01:00
|
|
|
else if((cb->begin!=cb->end || cb->wrap) &&
|
|
|
|
cb->begin!=cb->next)
|
|
|
|
{
|
2004-03-05 17:02:47 +01:00
|
|
|
if(doCrossFade==1 && cb->next>=0 &&
|
2004-02-24 00:41:20 +01:00
|
|
|
((cb->next>cb->begin &&
|
|
|
|
(fadePosition=cb->next-cb->begin)
|
|
|
|
<=crossFadeChunks) ||
|
|
|
|
(cb->begin>cb->next &&
|
|
|
|
(fadePosition=cb->next-cb->begin+
|
2004-02-25 22:10:56 +01:00
|
|
|
buffered_chunks)<=crossFadeChunks)))
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
2004-02-25 18:53:48 +01:00
|
|
|
if(nextChunk<0) {
|
2004-02-24 00:41:20 +01:00
|
|
|
crossFadeChunks = fadePosition;
|
|
|
|
}
|
|
|
|
test = cb->end;
|
2004-02-25 22:10:56 +01:00
|
|
|
if(cb->wrap) test+=buffered_chunks;
|
2004-03-05 17:02:47 +01:00
|
|
|
nextChunk = cb->begin+crossFadeChunks;
|
2004-02-24 00:41:20 +01:00
|
|
|
if(nextChunk<test) {
|
2004-02-25 22:10:56 +01:00
|
|
|
if(nextChunk>=buffered_chunks)
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
|
|
|
nextChunk-=
|
2004-02-25 22:10:56 +01:00
|
|
|
buffered_chunks;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
pcm_mix(cb->chunks+cb->begin*
|
|
|
|
CHUNK_SIZE,
|
|
|
|
cb->chunks+nextChunk*
|
|
|
|
CHUNK_SIZE,
|
|
|
|
cb->chunkSize[
|
|
|
|
cb->begin],
|
|
|
|
cb->chunkSize[
|
|
|
|
nextChunk],
|
|
|
|
af,
|
|
|
|
((float)fadePosition)/
|
|
|
|
crossFadeChunks);
|
|
|
|
if(cb->chunkSize[nextChunk]>
|
|
|
|
cb->chunkSize[cb->begin]
|
|
|
|
)
|
|
|
|
{
|
|
|
|
cb->chunkSize[cb->begin]
|
|
|
|
= cb->chunkSize
|
|
|
|
[nextChunk];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(dc->state==DECODE_STATE_STOP)
|
|
|
|
{
|
|
|
|
doCrossFade = -1;
|
|
|
|
}
|
2004-03-05 17:02:47 +01:00
|
|
|
else continue;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pc->elapsedTime = cb->times[cb->begin];
|
|
|
|
pc->bitRate = cb->bitRate[cb->begin];
|
|
|
|
pcm_volumeChange(cb->chunks+cb->begin*
|
|
|
|
CHUNK_SIZE,
|
|
|
|
cb->chunkSize[cb->begin],
|
|
|
|
af,
|
|
|
|
pc->softwareVolume);
|
2004-02-28 00:13:26 +01:00
|
|
|
if(playAudio(cb->chunks+cb->begin*CHUNK_SIZE,
|
|
|
|
cb->chunkSize[cb->begin])<0)
|
|
|
|
{
|
|
|
|
quit = 1;
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
cb->begin++;
|
2004-02-25 22:10:56 +01:00
|
|
|
if(cb->begin>=buffered_chunks) {
|
2004-02-24 00:41:20 +01:00
|
|
|
cb->begin = 0;
|
|
|
|
cb->wrap = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(cb->next==cb->begin) {
|
|
|
|
pc->totalPlayTime+= pc->elapsedTime-
|
|
|
|
pc->beginTime;
|
|
|
|
if(doCrossFade==1 && nextChunk>=0) {
|
|
|
|
nextChunk = cb->begin+crossFadeChunks;
|
|
|
|
test = cb->end;
|
2004-02-25 22:10:56 +01:00
|
|
|
if(cb->wrap) test+=buffered_chunks;
|
2004-02-24 00:41:20 +01:00
|
|
|
if(nextChunk<test) {
|
2004-02-25 22:10:56 +01:00
|
|
|
if(nextChunk>=buffered_chunks)
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
|
|
|
nextChunk-=
|
2004-02-25 22:10:56 +01:00
|
|
|
buffered_chunks;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
cb->begin = nextChunk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(pc->queueState==PLAYER_QUEUE_DECODE ||
|
|
|
|
pc->queueLockState==PLAYER_QUEUE_LOCKED)
|
|
|
|
{
|
|
|
|
processDecodeInput();
|
|
|
|
if(quit) {
|
|
|
|
quitDecode(pc,dc);
|
|
|
|
return;
|
|
|
|
}
|
2004-03-18 19:35:23 +01:00
|
|
|
usleep(1000);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
if(pc->queueState!=PLAYER_QUEUE_PLAY) {
|
|
|
|
quit = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cb->next = -1;
|
|
|
|
if(waitOnDecode(pc,af,dc,cb)<0) return;
|
|
|
|
nextChunk = -1;
|
|
|
|
doCrossFade = 0;
|
|
|
|
crossFadeChunks = 0;
|
|
|
|
pc->queueState = PLAYER_QUEUE_EMPTY;
|
|
|
|
kill(getppid(),SIGUSR1);
|
|
|
|
}
|
|
|
|
pc->beginTime = cb->times[cb->begin];
|
|
|
|
}
|
2004-02-27 23:25:06 +01:00
|
|
|
else if(*decode_pid<=0 ||
|
2004-02-24 00:41:20 +01:00
|
|
|
(dc->state==DECODE_STATE_STOP && !dc->start))
|
|
|
|
{
|
|
|
|
quit = 1;
|
|
|
|
break;
|
|
|
|
}
|
2004-03-07 00:25:32 +01:00
|
|
|
else usleep(1000);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pc->totalPlayTime+= pc->elapsedTime-pc->beginTime; \
|
|
|
|
quitDecode(pc,dc);
|
|
|
|
|
|
|
|
/* END OF PARENT */
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|