yes! rudimentary stream playing for mp3's!
be gentle git-svn-id: https://svn.musicpd.org/mpd/trunk@1051 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
aed844a67d
commit
746e7477e0
|
@ -98,8 +98,7 @@ int audiofile_decode(OutputBuffer * cb, DecoderControl * dc) {
|
|||
|
||||
while(!eof) {
|
||||
if(dc->seek) {
|
||||
cb->end = cb->begin;
|
||||
cb->wrap = 0;
|
||||
clearOutputBuffer(cb);
|
||||
current = dc->seekWhere *
|
||||
dc->audioFormat.sampleRate;
|
||||
afSeekFrame(af_fp, AF_DEFAULT_TRACK,current);
|
||||
|
|
|
@ -147,8 +147,7 @@ int flac_decode(OutputBuffer * cb, DecoderControl *dc) {
|
|||
if(dc->seek) {
|
||||
FLAC__uint64 sampleToSeek = dc->seekWhere*
|
||||
dc->audioFormat.sampleRate+0.5;
|
||||
cb->end = cb->begin;
|
||||
cb->wrap = 0;
|
||||
clearOutputBuffer(cb);
|
||||
if(FLAC__seekable_stream_decoder_seek_absolute(flacDec,
|
||||
sampleToSeek))
|
||||
{
|
||||
|
|
7
src/ls.c
7
src/ls.c
|
@ -44,7 +44,6 @@ char * dupAndStripPlaylistSuffix(char * file) {
|
|||
int isRemoteUrl(char * url) {
|
||||
char * prefixes[] = {
|
||||
"http://",
|
||||
"ftp://",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -53,12 +52,12 @@ int isRemoteUrl(char * url) {
|
|||
while(*urlPrefixes) {
|
||||
if(strncmp(*urlPrefixes,url,strlen(*urlPrefixes)) == 0) {
|
||||
#ifdef HAVE_MAD
|
||||
if(hasMp3Suffix(*urlPrefixes)) return 1;
|
||||
if(hasMp3Suffix(url)) return 1;
|
||||
#endif
|
||||
#ifdef HAVE_OGG
|
||||
if(hasOggSuffix(*urlPrefixes)) return 1;
|
||||
return 0;
|
||||
if(hasOggSuffix(url)) return 1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
urlPrefixes++;
|
||||
}
|
||||
|
|
|
@ -139,8 +139,8 @@ typedef struct _mp3DecodeData {
|
|||
int initMp3DecodeData(mp3DecodeData * data, char * file) {
|
||||
int ret;
|
||||
|
||||
while(((ret = openInputStream(&(data->inStream),file))<0)) /*&&
|
||||
data->inStream.error==EINTR);*/
|
||||
/*while(((*/ret = openInputStream(&(data->inStream),file)/*)<0)) &&
|
||||
data->inStream.error==EINTR)*/;
|
||||
if(ret<0) return -1;
|
||||
|
||||
data->outputPtr = data->outputBuffer;
|
||||
|
@ -165,10 +165,13 @@ int initMp3DecodeData(mp3DecodeData * data, char * file) {
|
|||
int fillMp3InputBuffer(mp3DecodeData * data, long offset) {
|
||||
size_t readSize;
|
||||
size_t remaining;
|
||||
size_t readed;
|
||||
unsigned char * readStart;
|
||||
|
||||
if(offset>=0) {
|
||||
seekInputStream(&(data->inStream),offset,SEEK_SET);
|
||||
if(seekInputStream(&(data->inStream),offset,SEEK_SET) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(offset==-1 && (data->stream).next_frame!=NULL) {
|
||||
|
@ -182,11 +185,15 @@ int fillMp3InputBuffer(mp3DecodeData * data, long offset) {
|
|||
readStart = data->readBuffer,
|
||||
remaining = 0;
|
||||
}
|
||||
|
||||
readSize = readFromInputStream(&(data->inStream),readStart,1,readSize);
|
||||
if(readSize<=0) return -1;
|
||||
|
||||
mad_stream_buffer(&data->stream,data->readBuffer,readSize+remaining);
|
||||
readed = 0;
|
||||
while(readed == 0 && !inputStreamAtEOF(&(data->inStream))) {
|
||||
readed = readFromInputStream(&(data->inStream), readStart, 1,
|
||||
readSize);
|
||||
}
|
||||
if(readed<=0) return -1;
|
||||
|
||||
mad_stream_buffer(&data->stream,data->readBuffer,readed+remaining);
|
||||
(data->stream).error = 0;
|
||||
|
||||
return 0;
|
||||
|
@ -441,6 +448,7 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) {
|
|||
if(data->muteFrame) {
|
||||
if(!dc->seek) data->muteFrame = 0;
|
||||
else if(dc->seekWhere<=data->elapsedTime) {
|
||||
clearOutputBuffer(cb);
|
||||
data->muteFrame = 0;
|
||||
dc->seek = 0;
|
||||
}
|
||||
|
@ -485,8 +493,6 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) {
|
|||
|
||||
if(dc->seek) {
|
||||
long i = 0;
|
||||
cb->wrap = 0;
|
||||
cb->end = cb->begin;
|
||||
data->muteFrame = 1;
|
||||
while(i<data->highestFrame && dc->seekWhere >
|
||||
((float)mad_timer_count(data->times[i],
|
||||
|
@ -495,9 +501,14 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) {
|
|||
i++;
|
||||
}
|
||||
if(i<data->highestFrame) {
|
||||
data->currentFrame = i;
|
||||
fillMp3InputBuffer(data,data->frameOffset[i]);
|
||||
data->muteFrame = 0;
|
||||
if(fillMp3InputBuffer(data,
|
||||
data->frameOffset[i]) == 0)
|
||||
{
|
||||
clearOutputBuffer(cb);
|
||||
data->currentFrame = i;
|
||||
data->muteFrame = 0;
|
||||
}
|
||||
else dc->seekError = 1;
|
||||
dc->seek = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,8 +220,7 @@ int mp4_decode(OutputBuffer * cb, DecoderControl * dc) {
|
|||
if(dc->seek && seekPositionFound) {
|
||||
seekPositionFound = 0;
|
||||
chunkLen = 0;
|
||||
cb->end = cb->begin;
|
||||
cb->wrap = 0;
|
||||
clearOutputBuffer(cb);
|
||||
dc->seek = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -191,8 +191,7 @@ int ogg_decode(OutputBuffer * cb, DecoderControl * dc)
|
|||
|
||||
while(!eof) {
|
||||
if(dc->seek) {
|
||||
cb->end = cb->begin;
|
||||
cb->wrap = 0;
|
||||
clearOutputBuffer(cb);
|
||||
chunkpos = 0;
|
||||
ov_time_seek_page(&vf,dc->seekWhere);
|
||||
dc->seek = 0;
|
||||
|
|
|
@ -26,6 +26,12 @@
|
|||
|
||||
static mpd_sint16 currentChunk = -1;
|
||||
|
||||
void clearOutputBuffer(OutputBuffer * cb) {
|
||||
currentChunk = -1;
|
||||
cb->end = cb->begin;
|
||||
cb->wrap = 0;
|
||||
}
|
||||
|
||||
void flushOutputBuffer(OutputBuffer * cb) {
|
||||
if(currentChunk == cb->end) {
|
||||
cb->end++;
|
||||
|
|
|
@ -38,6 +38,8 @@ typedef struct _OutputBuffer {
|
|||
AudioFormat audioFormat;
|
||||
} OutputBuffer;
|
||||
|
||||
void clearOutputBuffer(OutputBuffer * cb);
|
||||
|
||||
void flushOutputBuffer(OutputBuffer * cb);
|
||||
|
||||
int sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc,
|
||||
|
|
31
src/player.c
31
src/player.c
|
@ -161,22 +161,22 @@ int playerInit() {
|
|||
}
|
||||
|
||||
int playerGetDecodeType(char * utf8file) {
|
||||
if(!isFile(utf8file,NULL));
|
||||
if(!isRemoteUrl(utf8file) && !isFile(utf8file,NULL)) return -1;
|
||||
#ifdef HAVE_MAD
|
||||
else if(hasMp3Suffix(utf8file)) return DECODE_TYPE_MP3;
|
||||
if(hasMp3Suffix(utf8file)) return DECODE_TYPE_MP3;
|
||||
#endif
|
||||
#ifdef HAVE_OGG
|
||||
else if(hasOggSuffix(utf8file)) return DECODE_TYPE_OGG;
|
||||
if(hasOggSuffix(utf8file)) return DECODE_TYPE_OGG;
|
||||
#endif
|
||||
#ifdef HAVE_FLAC
|
||||
else if(hasFlacSuffix(utf8file)) return DECODE_TYPE_FLAC;
|
||||
if(hasFlacSuffix(utf8file)) return DECODE_TYPE_FLAC;
|
||||
#endif
|
||||
#ifdef HAVE_AUDIOFILE
|
||||
else if(hasWaveSuffix(utf8file)) return DECODE_TYPE_AUDIOFILE;
|
||||
if(hasWaveSuffix(utf8file)) return DECODE_TYPE_AUDIOFILE;
|
||||
#endif
|
||||
#ifdef HAVE_FAAD
|
||||
else if(hasAacSuffix(utf8file)) return DECODE_TYPE_AAC;
|
||||
else if(hasMp4Suffix(utf8file)) return DECODE_TYPE_MP4;
|
||||
if(hasAacSuffix(utf8file)) return DECODE_TYPE_AAC;
|
||||
if(hasMp4Suffix(utf8file)) return DECODE_TYPE_MP4;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ int playerPlay(FILE * fp, char * utf8file) {
|
|||
|
||||
if(playerStop(fp)<0) return -1;
|
||||
|
||||
{
|
||||
/*{
|
||||
struct stat st;
|
||||
if(stat(rmp2amp(utf8ToFsCharset(utf8file)),&st)<0) {
|
||||
strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
|
||||
|
@ -197,7 +197,7 @@ int playerPlay(FILE * fp, char * utf8file) {
|
|||
pc->error = PLAYER_ERROR_FILENOTFOUND;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
decodeType = playerGetDecodeType(utf8file);
|
||||
if(decodeType < 0) {
|
||||
|
@ -208,7 +208,10 @@ int playerPlay(FILE * fp, char * utf8file) {
|
|||
}
|
||||
pc->decodeType = decodeType;
|
||||
|
||||
strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN);
|
||||
if(isRemoteUrl(utf8file)) {
|
||||
strncpy(pc->file,utf8file,MAXPATHLEN);
|
||||
}
|
||||
else strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN);
|
||||
pc->file[MAXPATHLEN] = '\0';
|
||||
|
||||
pc->play = 1;
|
||||
|
@ -353,7 +356,10 @@ int queueSong(char * utf8file) {
|
|||
int decodeType;
|
||||
|
||||
if(pc->queueState==PLAYER_QUEUE_BLANK) {
|
||||
strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN);
|
||||
if(isRemoteUrl(utf8file)) {
|
||||
strncpy(pc->file,utf8file,MAXPATHLEN);
|
||||
}
|
||||
else strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN);
|
||||
pc->file[MAXPATHLEN] = '\0';
|
||||
|
||||
decodeType = playerGetDecodeType(utf8file);
|
||||
|
@ -410,7 +416,8 @@ int playerSeek(FILE * fp, char * utf8file, float time) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
file = rmp2amp(utf8ToFsCharset(utf8file));
|
||||
if(isRemoteUrl(utf8file)) file = utf8file;
|
||||
else file = rmp2amp(utf8ToFsCharset(utf8file));
|
||||
if(strcmp(pc->file,file)!=0) {
|
||||
decodeType = playerGetDecodeType(utf8file);
|
||||
if(decodeType < 0) {
|
||||
|
|
Loading…
Reference in New Issue