fix a bug, due to not resetting decodeType in playerSeek when the file to

seek isn't the same as the current playing file

git-svn-id: https://svn.musicpd.org/mpd/trunk@409 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-03-23 01:12:30 +00:00
parent 4b4438853c
commit 0783a2bde1
3 changed files with 61 additions and 65 deletions

View File

@ -173,7 +173,7 @@ void initAacBuffer(FILE * fp, AacBuffer * b, float * length,
if(retFileread) *retFileread = fileread; if(retFileread) *retFileread = fileread;
if(retTagsize) *retTagsize = tagsize; if(retTagsize) *retTagsize = tagsize;
if(!length) return; if(length==NULL) return;
if((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) { if((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) {
adtsParse(b, length); adtsParse(b, length);
@ -308,14 +308,15 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
time = 0.0; time = 0.0;
advanceAacBuffer(&b,bread); advanceAacBuffer(&b,bread);
fillAacBuffer(&b);
do { while(!eof) {
if(dc->seek) { fillAacBuffer(&b);
dc->seekError = 1;
dc->seek = 0; if(b.bytesIntoBuffer==0) {
eof = 1;
break;
} }
sampleBuffer = faacDecDecode(decoder,&frameInfo,b.buffer, sampleBuffer = faacDecDecode(decoder,&frameInfo,b.buffer,
b.bytesIntoBuffer); b.bytesIntoBuffer);
@ -348,7 +349,7 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
sampleBufferLen = sampleCount*2; sampleBufferLen = sampleCount*2;
while(sampleBufferLen>0 && !dc->seek) { while(sampleBufferLen>0) {
size_t size = sampleBufferLen>CHUNK_SIZE-chunkLen ? size_t size = sampleBufferLen>CHUNK_SIZE-chunkLen ?
CHUNK_SIZE-chunkLen: CHUNK_SIZE-chunkLen:
sampleBufferLen; sampleBufferLen;
@ -357,11 +358,15 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
{ {
usleep(10000); usleep(10000);
} }
if(dc->stop) { if(dc->seek) {
dc->seekError = 1;
dc->seek = 0;
}
else if(dc->stop) {
eof = 1; eof = 1;
break; break;
} }
else if(!dc->seek) { else {
sampleBufferLen-=size; sampleBufferLen-=size;
memcpy(cb->chunks+cb->end*CHUNK_SIZE+chunkLen, memcpy(cb->chunks+cb->end*CHUNK_SIZE+chunkLen,
sampleBuffer,size); sampleBuffer,size);
@ -381,10 +386,6 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
} }
} }
} }
fillAacBuffer(&b);
if(b.bytesIntoBuffer==0) eof = 1;
} while (!eof); } while (!eof);
faacDecClose(decoder); faacDecClose(decoder);

View File

@ -128,12 +128,12 @@ int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
return -1; return -1;
} }
pc->totalTime = cb->totalTime;
pc->elapsedTime = 0; pc->elapsedTime = 0;
pc->bitRate = 0; pc->bitRate = 0;
pc->sampleRate = af->sampleRate; pc->sampleRate = af->sampleRate;
pc->bits = af->bits; pc->bits = af->bits;
pc->channels = af->channels; pc->channels = af->channels;
pc->totalTime = cb->totalTime;
return 0; return 0;
} }
@ -147,10 +147,11 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
strcmp(dc->file,pc->file)!=0) strcmp(dc->file,pc->file)!=0)
{ {
stopDecode(dc); stopDecode(dc);
cb->begin = 0;
cb->end = 0; cb->end = 0;
cb->wrap = 0;
dc->error = 0; dc->error = 0;
dc->start = 1; dc->start = 1;
dc->error = 0;
waitOnDecode(pc,af,dc,cb); waitOnDecode(pc,af,dc,cb);
} }
if(*decode_pid>0 && dc->state==DECODE_STATE_DECODE) { if(*decode_pid>0 && dc->state==DECODE_STATE_DECODE) {

View File

@ -149,9 +149,31 @@ int playerInit() {
return 0; return 0;
} }
int playerGetDecodeType(char * utf8file) {
if(0);
#ifdef HAVE_MAD
if(isMp3(utf8file,NULL)) return DECODE_TYPE_MP3;
#endif
#ifdef HAVE_OGG
if(isOgg(utf8file,NULL)) return DECODE_TYPE_OGG;
#endif
#ifdef HAVE_FLAC
if(isFlac(utf8file,NULL)) return DECODE_TYPE_FLAC;
#endif
#ifdef HAVE_AUDIOFILE
if(isWave(utf8file,NULL)) return DECODE_TYPE_AUDIOFILE;
#endif
#ifdef HAVE_FAAD
if(isAac(utf8file,NULL)) return DECODE_TYPE_AAC;
if(isMp4(utf8file,NULL)) return DECODE_TYPE_MP4;
#endif
return -1;
}
int playerPlay(FILE * fp, char * utf8file) { int playerPlay(FILE * fp, char * utf8file) {
PlayerControl * pc = &(getPlayerData()->playerControl); PlayerControl * pc = &(getPlayerData()->playerControl);
if(fp==NULL) fp = stderr; if(fp==NULL) fp = stderr;
int decodeType;
if(playerStop(fp)<0) return -1; if(playerStop(fp)<0) return -1;
@ -163,29 +185,14 @@ int playerPlay(FILE * fp, char * utf8file) {
return 0; return 0;
} }
} }
if(0); decodeType = playerGetDecodeType(utf8file);
#ifdef HAVE_MAD if(decodeType < 0) {
else if(isMp3(utf8file,NULL)) pc->decodeType = DECODE_TYPE_MP3;
#endif
#ifdef HAVE_OGG
else if(isOgg(utf8file,NULL)) pc->decodeType = DECODE_TYPE_OGG;
#endif
#ifdef HAVE_FLAC
else if(isFlac(utf8file,NULL)) pc->decodeType = DECODE_TYPE_FLAC;
#endif
#ifdef HAVE_AUDIOFILE
else if(isWave(utf8file,NULL)) pc->decodeType = DECODE_TYPE_AUDIOFILE;
#endif
#ifdef HAVE_FAAD
else if(isAac(utf8file,NULL)) pc->decodeType = DECODE_TYPE_AAC;
else if(isMp4(utf8file,NULL)) pc->decodeType = DECODE_TYPE_MP4;
#endif
else {
strncpy(pc->erroredFile,pc->file,MAXPATHLEN); strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
pc->error = PLAYER_ERROR_UNKTYPE; pc->error = PLAYER_ERROR_UNKTYPE;
return 0; return 0;
} }
pc->decodeType = decodeType;
strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN); strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN);
@ -315,36 +322,15 @@ void playerCloseAudio() {
int queueSong(char * utf8file) { int queueSong(char * utf8file) {
PlayerControl * pc = &(getPlayerData()->playerControl); PlayerControl * pc = &(getPlayerData()->playerControl);
int decodeType;
if(pc->queueState==PLAYER_QUEUE_BLANK) { if(pc->queueState==PLAYER_QUEUE_BLANK) {
strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN); strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN);
if(0); decodeType = playerGetDecodeType(utf8file);
#ifdef HAVE_MAD if(decodeType < 0) return -1;
else if(isMp3(utf8file,NULL)) pc->decodeType = DECODE_TYPE_MP3; pc->decodeType = decodeType;
#endif
#ifdef HAVE_OGG
else if(isOgg(utf8file,NULL)) pc->decodeType = DECODE_TYPE_OGG;
#endif
#ifdef HAVE_FLAC
else if(isFlac(utf8file,NULL)) {
pc->decodeType = DECODE_TYPE_FLAC;
}
#endif
#ifdef HAVE_AUDIOFILE
else if(isWave(utf8file,NULL)) {
pc->decodeType = DECODE_TYPE_AUDIOFILE;
}
#endif
#ifdef HAVE_AUDIOFILE
else if(isAac(utf8file,NULL)) {
pc->decodeType = DECODE_TYPE_AAC;
}
else if(isMp4(utf8file,NULL)) {
pc->decodeType = DECODE_TYPE_MP4;
}
#endif
else return -1;
pc->queueState = PLAYER_QUEUE_FULL; pc->queueState = PLAYER_QUEUE_FULL;
return 0; return 0;
} }
@ -387,6 +373,7 @@ void playerQueueUnlock() {
int playerSeek(FILE * fp, char * utf8file, float time) { int playerSeek(FILE * fp, char * utf8file, float time) {
PlayerControl * pc = &(getPlayerData()->playerControl); PlayerControl * pc = &(getPlayerData()->playerControl);
char * file; char * file;
int decodeType;
if(pc->state==PLAYER_STATE_STOP) { if(pc->state==PLAYER_STATE_STOP) {
myfprintf(fp,"%s player not currently playing\n", myfprintf(fp,"%s player not currently playing\n",
@ -395,10 +382,17 @@ int playerSeek(FILE * fp, char * utf8file, float time) {
} }
file = rmp2amp(utf8ToFsCharset(utf8file)); file = rmp2amp(utf8ToFsCharset(utf8file));
if(strcmp(pc->file,file)!=0) strncpy(pc->file,file,MAXPATHLEN); if(strcmp(pc->file,file)!=0) {
/*if(playerStop(fp)<0) return -1; decodeType = playerGetDecodeType(utf8file);
if(playerPlay(stderr,file)<0) return -1;*/ if(decodeType < 0) {
/*}*/ printf("%s unknown file type: %s\n",
COMMAND_RESPOND_ERROR, utf8file);
return -1;
}
pc->decodeType = decodeType;
strncpy(pc->file,file,MAXPATHLEN);
}
if(pc->error==PLAYER_ERROR_NOERROR) { if(pc->error==PLAYER_ERROR_NOERROR) {
pc->seekWhere = time; pc->seekWhere = time;