diff options
Diffstat (limited to '')
-rw-r--r-- | src/aac_decode.c | 29 | ||||
-rw-r--r-- | src/decode.c | 5 | ||||
-rw-r--r-- | src/player.c | 92 |
3 files changed, 61 insertions, 65 deletions
diff --git a/src/aac_decode.c b/src/aac_decode.c index fe8ede2fd..c4d8dcf4d 100644 --- a/src/aac_decode.c +++ b/src/aac_decode.c @@ -173,7 +173,7 @@ void initAacBuffer(FILE * fp, AacBuffer * b, float * length, if(retFileread) *retFileread = fileread; if(retTagsize) *retTagsize = tagsize; - if(!length) return; + if(length==NULL) return; if((b->buffer[0] == 0xFF) && ((b->buffer[1] & 0xF6) == 0xF0)) { adtsParse(b, length); @@ -308,14 +308,15 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) { time = 0.0; advanceAacBuffer(&b,bread); - fillAacBuffer(&b); - do { - if(dc->seek) { - dc->seekError = 1; - dc->seek = 0; + while(!eof) { + fillAacBuffer(&b); + + if(b.bytesIntoBuffer==0) { + eof = 1; + break; } - + sampleBuffer = faacDecDecode(decoder,&frameInfo,b.buffer, b.bytesIntoBuffer); @@ -348,7 +349,7 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) { sampleBufferLen = sampleCount*2; - while(sampleBufferLen>0 && !dc->seek) { + while(sampleBufferLen>0) { size_t size = sampleBufferLen>CHUNK_SIZE-chunkLen ? CHUNK_SIZE-chunkLen: sampleBufferLen; @@ -357,11 +358,15 @@ int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) { { usleep(10000); } - if(dc->stop) { + if(dc->seek) { + dc->seekError = 1; + dc->seek = 0; + } + else if(dc->stop) { eof = 1; break; } - else if(!dc->seek) { + else { sampleBufferLen-=size; memcpy(cb->chunks+cb->end*CHUNK_SIZE+chunkLen, 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); faacDecClose(decoder); diff --git a/src/decode.c b/src/decode.c index 5c1c05f25..6e3826951 100644 --- a/src/decode.c +++ b/src/decode.c @@ -128,12 +128,12 @@ int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc, return -1; } + pc->totalTime = cb->totalTime; pc->elapsedTime = 0; pc->bitRate = 0; pc->sampleRate = af->sampleRate; pc->bits = af->bits; pc->channels = af->channels; - pc->totalTime = cb->totalTime; return 0; } @@ -147,10 +147,11 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc, strcmp(dc->file,pc->file)!=0) { stopDecode(dc); + cb->begin = 0; cb->end = 0; + cb->wrap = 0; dc->error = 0; dc->start = 1; - dc->error = 0; waitOnDecode(pc,af,dc,cb); } if(*decode_pid>0 && dc->state==DECODE_STATE_DECODE) { diff --git a/src/player.c b/src/player.c index 81b78ca39..ea7d3723b 100644 --- a/src/player.c +++ b/src/player.c @@ -149,9 +149,31 @@ int playerInit() { 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) { PlayerControl * pc = &(getPlayerData()->playerControl); if(fp==NULL) fp = stderr; + int decodeType; if(playerStop(fp)<0) return -1; @@ -163,29 +185,14 @@ int playerPlay(FILE * fp, char * utf8file) { return 0; } } - - if(0); -#ifdef HAVE_MAD - 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 { + + decodeType = playerGetDecodeType(utf8file); + if(decodeType < 0) { strncpy(pc->erroredFile,pc->file,MAXPATHLEN); pc->error = PLAYER_ERROR_UNKTYPE; return 0; } + pc->decodeType = decodeType; strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN); @@ -315,36 +322,15 @@ void playerCloseAudio() { int queueSong(char * utf8file) { PlayerControl * pc = &(getPlayerData()->playerControl); + int decodeType; if(pc->queueState==PLAYER_QUEUE_BLANK) { strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN); - if(0); -#ifdef HAVE_MAD - 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_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; + decodeType = playerGetDecodeType(utf8file); + if(decodeType < 0) return -1; + pc->decodeType = decodeType; + pc->queueState = PLAYER_QUEUE_FULL; return 0; } @@ -387,6 +373,7 @@ void playerQueueUnlock() { int playerSeek(FILE * fp, char * utf8file, float time) { PlayerControl * pc = &(getPlayerData()->playerControl); char * file; + int decodeType; if(pc->state==PLAYER_STATE_STOP) { myfprintf(fp,"%s player not currently playing\n", @@ -395,10 +382,17 @@ int playerSeek(FILE * fp, char * utf8file, float time) { } file = rmp2amp(utf8ToFsCharset(utf8file)); - if(strcmp(pc->file,file)!=0) strncpy(pc->file,file,MAXPATHLEN); - /*if(playerStop(fp)<0) return -1; - if(playerPlay(stderr,file)<0) return -1;*/ - /*}*/ + if(strcmp(pc->file,file)!=0) { + decodeType = playerGetDecodeType(utf8file); + 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) { pc->seekWhere = time; |