add new inputStream stuff, hopefully something major isn't foobar'd

git-svn-id: https://svn.musicpd.org/mpd/trunk@1049 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-05-18 02:46:13 +00:00
parent ee79a3a8fd
commit 48a58073dd
9 changed files with 41 additions and 54 deletions

View File

@ -6,14 +6,14 @@ mpd_headers = buffer2array.h interface.h command.h playlist.h ls.h \
audio.h playerData.h stats.h myfprintf.h sig_handlers.h decode.h log.h \ audio.h playerData.h stats.h myfprintf.h sig_handlers.h decode.h log.h \
audiofile_decode.h charConv.h permission.h mpd_types.h pcm_utils.h \ audiofile_decode.h charConv.h permission.h mpd_types.h pcm_utils.h \
mp4_decode.h aac_decode.h signal_check.h utf8.h inputStream.h \ mp4_decode.h aac_decode.h signal_check.h utf8.h inputStream.h \
outputBuffer.h replayGain.h outputBuffer.h replayGain.h inputStream_file.h inputStream_http.h
mpd_SOURCES = main.c buffer2array.c interface.c command.c playlist.c ls.c \ mpd_SOURCES = main.c buffer2array.c interface.c command.c playlist.c ls.c \
song.c list.c directory.c tables.c utils.c path.c mp3_decode.c \ song.c list.c directory.c tables.c utils.c path.c mp3_decode.c \
tag.c player.c listen.c conf.c ogg_decode.c volume.c flac_decode.c \ tag.c player.c listen.c conf.c ogg_decode.c volume.c flac_decode.c \
audio.c playerData.c stats.c myfprintf.c sig_handlers.c decode.c log.c \ audio.c playerData.c stats.c myfprintf.c sig_handlers.c decode.c log.c \
audiofile_decode.c charConv.c permission.c pcm_utils.c mp4_decode.c \ audiofile_decode.c charConv.c permission.c pcm_utils.c mp4_decode.c \
aac_decode.c signal_check.c utf8.c inputStream.c outputBuffer.c \ aac_decode.c signal_check.c utf8.c inputStream.c outputBuffer.c \
replayGain.c $(mpd_headers) replayGain.c inputStream_file.c inputStream_http.c $(mpd_headers)
mpd_CFLAGS = $(MPD_CFLAGS) mpd_CFLAGS = $(MPD_CFLAGS)
mpd_LDADD = $(MPD_LIBS) $(ID3_LIB) $(MAD_LIB) $(MP4FF_LIB) mpd_LDADD = $(MPD_LIBS) $(ID3_LIB) $(MAD_LIB) $(MP4FF_LIB)

View File

@ -212,7 +212,7 @@ float getAacFloatTotalTime(char * file) {
InputStream inStream; InputStream inStream;
size_t bread; size_t bread;
if(openInputStreamFromFile(&inStream,file) < 0) return -1; if(openInputStream(&inStream,file) < 0) return -1;
initAacBuffer(&inStream,&b,&length,&fileread,&tagsize); initAacBuffer(&inStream,&b,&length,&fileread,&tagsize);
@ -274,7 +274,7 @@ int aac_decode(OutputBuffer * cb, DecoderControl * dc) {
if((totalTime = getAacFloatTotalTime(dc->file)) < 0) return -1; if((totalTime = getAacFloatTotalTime(dc->file)) < 0) return -1;
if(openInputStreamFromFile(&inStream,dc->file) < 0) return -1; if(openInputStream(&inStream,dc->file) < 0) return -1;
initAacBuffer(&inStream,&b,NULL,NULL,NULL); initAacBuffer(&inStream,&b,NULL,NULL,NULL);

View File

@ -81,7 +81,7 @@ int flac_decode(OutputBuffer * cb, DecoderControl *dc) {
data.dc = dc; data.dc = dc;
data.replayGainScale = 1.0; data.replayGainScale = 1.0;
if(openInputStreamFromFile(&(data.inStream),dc->file)<0) { if(openInputStream(&(data.inStream),dc->file)<0) {
ERROR("unable to open flac: %s\n",dc->file); ERROR("unable to open flac: %s\n",dc->file);
return -1; return -1;
} }

View File

@ -18,61 +18,35 @@
#include "inputStream.h" #include "inputStream.h"
#include "inputStream_file.h"
#include "inputStream_http.h"
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
int openInputStreamFromFile(InputStream * inStream, char * filename) { int openInputStream(InputStream * inStream, char * url) {
inStream->fp = fopen(filename,"r"); if(inputStream_fileOpen(inStream,url) == 0) return 0;
if(!inStream->fp) { if(inputStream_httpOpen(inStream,url) == 0) return 0;
inStream->error = errno;
return -1; return -1;
} }
inStream->offset = 0;
fseek(inStream->fp,0,SEEK_END);
inStream->size = ftell(inStream->fp);
fseek(inStream->fp,0,SEEK_SET);
return 0;
}
int seekInputStream(InputStream * inStream, long offset, int whence) { int seekInputStream(InputStream * inStream, long offset, int whence) {
if(fseek(inStream->fp,offset,whence)==0) { return inStream->seekFunc(inStream,offset,whence);
inStream->offset = ftell(inStream->fp);
}
else {
inStream->error = errno;
return -1;
}
return 0;
} }
size_t readFromInputStream(InputStream * inStream, void * ptr, size_t size, size_t readFromInputStream(InputStream * inStream, void * ptr, size_t size,
size_t nmemb) size_t nmemb)
{ {
size_t readSize; return inStream->readFunc(inStream,ptr,size,nmemb);
readSize = fread(ptr,size,nmemb,inStream->fp);
if(readSize>0) inStream->offset+=readSize;
return readSize;
} }
int closeInputStream(InputStream * inStream) { int closeInputStream(InputStream * inStream) {
if(fclose(inStream->fp)<0) { return inStream->closeFunc(inStream);
inStream->error = errno;
}
else return -1;
return 0;
} }
int inputStreamAtEOF(InputStream * inStream) { int inputStreamAtEOF(InputStream * inStream) {
return feof(inStream->fp); return inStream->atEOFFunc(inStream);
} }
/* vim:set shiftwidth=4 tabstop=8 expandtab: */ /* vim:set shiftwidth=8 tabstop=8 expandtab: */

View File

@ -19,19 +19,33 @@
#ifndef INPUT_STREAM_H #ifndef INPUT_STREAM_H
#define INPUT_STREAM_H #define INPUT_STREAM_H
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
typedef struct _InputStream { typedef struct _InputStream InputStream;
FILE * fp;
typedef int (* InputStreamSeekFunc) (InputStream * inStream, long offset,
int whence);
typedef size_t (* InputStreamReadFunc) (InputStream * inStream, void * ptr, size_t size,
size_t nmemb);
typedef int (* InputStreamCloseFunc) (InputStream * inStream);
typedef int (* InputStreamAtEOFFunc) (InputStream * inStream);
struct _InputStream {
int error; int error;
long offset; long offset;
size_t size; size_t size;
} InputStream;
/* don't touc this stuff */
InputStreamSeekFunc seekFunc;
InputStreamReadFunc readFunc;
InputStreamCloseFunc closeFunc;
InputStreamAtEOFFunc atEOFFunc;
void * data;
};
/* if an error occurs for these 3 functions, then -1 is returned and errno /* if an error occurs for these 3 functions, then -1 is returned and errno
for the input stream is set */ for the input stream is set */
int openInputStreamFromFile(InputStream * inStream, char * filename); int openInputStream(InputStream * inStream, char * url);
int seekInputStream(InputStream * inStream, long offset, int whence); int seekInputStream(InputStream * inStream, long offset, int whence);
int closeInputStream(InputStream * inStream); int closeInputStream(InputStream * inStream);
int inputStreamAtEOF(InputStream * inStream); int inputStreamAtEOF(InputStream * inStream);

View File

@ -139,8 +139,8 @@ typedef struct _mp3DecodeData {
int initMp3DecodeData(mp3DecodeData * data, char * file) { int initMp3DecodeData(mp3DecodeData * data, char * file) {
int ret; int ret;
while(((ret = openInputStreamFromFile(&(data->inStream),file))<0) && while(((ret = openInputStream(&(data->inStream),file))<0)) /*&&
data->inStream.error==EINTR); data->inStream.error==EINTR);*/
if(ret<0) return -1; if(ret<0) return -1;
data->outputPtr = data->outputBuffer; data->outputPtr = data->outputBuffer;

View File

@ -113,7 +113,7 @@ int mp4_decode(OutputBuffer * cb, DecoderControl * dc) {
mpd_uint16 bitRate = 0; mpd_uint16 bitRate = 0;
InputStream inStream; InputStream inStream;
if(openInputStreamFromFile(&inStream,dc->file) < 0) { if(openInputStream(&inStream,dc->file) < 0) {
ERROR("failed to open %s\n",dc->file); ERROR("failed to open %s\n",dc->file);
return -1; return -1;
} }

View File

@ -154,7 +154,7 @@ int ogg_decode(OutputBuffer * cb, DecoderControl * dc)
callbacks.close_func = ogg_close_cb; callbacks.close_func = ogg_close_cb;
callbacks.tell_func = ogg_tell_cb; callbacks.tell_func = ogg_tell_cb;
if(openInputStreamFromFile(&inStream,dc->file)<0) { if(openInputStream(&inStream,dc->file)<0) {
ERROR("failed to open ogg\n"); ERROR("failed to open ogg\n");
return -1; return -1;
} }

View File

@ -219,8 +219,7 @@ MpdTag * mp4DataDup(char * utf8file, int * mp4MetadataFound) {
*mp4MetadataFound = 0; *mp4MetadataFound = 0;
if(openInputStreamFromFile(&inStream,rmp2amp(utf8ToFsCharset(utf8file))) if(openInputStream(&inStream,rmp2amp(utf8ToFsCharset(utf8file))) < 0)
< 0)
{ {
return NULL; return NULL;
} }