aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-05-18 02:46:13 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-05-18 02:46:13 +0000
commit48a58073dd9bf781a8e2a127e832941332fc8a41 (patch)
tree8aeeb19951a63b43c8f054947539ae904b9f4558
parentee79a3a8fdd119444ff76d993678a56ed635df2b (diff)
downloadmpd-48a58073dd9bf781a8e2a127e832941332fc8a41.tar.gz
mpd-48a58073dd9bf781a8e2a127e832941332fc8a41.tar.xz
mpd-48a58073dd9bf781a8e2a127e832941332fc8a41.zip
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
-rw-r--r--src/Makefile.am4
-rw-r--r--src/aac_decode.c4
-rw-r--r--src/flac_decode.c2
-rw-r--r--src/inputStream.c50
-rw-r--r--src/inputStream.h24
-rw-r--r--src/mp3_decode.c4
-rw-r--r--src/mp4_decode.c2
-rw-r--r--src/ogg_decode.c2
-rw-r--r--src/tag.c3
9 files changed, 41 insertions, 54 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 08924e63c..9cfcf6647 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
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 \
- 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 \
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 \
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 \
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_LDADD = $(MPD_LIBS) $(ID3_LIB) $(MAD_LIB) $(MP4FF_LIB)
diff --git a/src/aac_decode.c b/src/aac_decode.c
index 7013502d4..ddc8b62d9 100644
--- a/src/aac_decode.c
+++ b/src/aac_decode.c
@@ -212,7 +212,7 @@ float getAacFloatTotalTime(char * file) {
InputStream inStream;
size_t bread;
- if(openInputStreamFromFile(&inStream,file) < 0) return -1;
+ if(openInputStream(&inStream,file) < 0) return -1;
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(openInputStreamFromFile(&inStream,dc->file) < 0) return -1;
+ if(openInputStream(&inStream,dc->file) < 0) return -1;
initAacBuffer(&inStream,&b,NULL,NULL,NULL);
diff --git a/src/flac_decode.c b/src/flac_decode.c
index c3780ef58..105a3ef6f 100644
--- a/src/flac_decode.c
+++ b/src/flac_decode.c
@@ -81,7 +81,7 @@ int flac_decode(OutputBuffer * cb, DecoderControl *dc) {
data.dc = dc;
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);
return -1;
}
diff --git a/src/inputStream.c b/src/inputStream.c
index 1dea4f271..578749e24 100644
--- a/src/inputStream.c
+++ b/src/inputStream.c
@@ -18,61 +18,35 @@
#include "inputStream.h"
+#include "inputStream_file.h"
+#include "inputStream_http.h"
+
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
-#include <errno.h>
-
-int openInputStreamFromFile(InputStream * inStream, char * filename) {
- inStream->fp = fopen(filename,"r");
- if(!inStream->fp) {
- inStream->error = errno;
- return -1;
- }
- inStream->offset = 0;
+int openInputStream(InputStream * inStream, char * url) {
+ if(inputStream_fileOpen(inStream,url) == 0) return 0;
+ if(inputStream_httpOpen(inStream,url) == 0) return 0;
- fseek(inStream->fp,0,SEEK_END);
- inStream->size = ftell(inStream->fp);
- fseek(inStream->fp,0,SEEK_SET);
-
- return 0;
+ return -1;
}
int seekInputStream(InputStream * inStream, long offset, int whence) {
- if(fseek(inStream->fp,offset,whence)==0) {
- inStream->offset = ftell(inStream->fp);
- }
- else {
- inStream->error = errno;
- return -1;
- }
-
- return 0;
+ return inStream->seekFunc(inStream,offset,whence);
}
size_t readFromInputStream(InputStream * inStream, void * ptr, size_t size,
size_t nmemb)
{
- size_t readSize;
-
- readSize = fread(ptr,size,nmemb,inStream->fp);
-
- if(readSize>0) inStream->offset+=readSize;
-
- return readSize;
+ return inStream->readFunc(inStream,ptr,size,nmemb);
}
int closeInputStream(InputStream * inStream) {
- if(fclose(inStream->fp)<0) {
- inStream->error = errno;
- }
- else return -1;
-
- return 0;
+ return inStream->closeFunc(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: */
diff --git a/src/inputStream.h b/src/inputStream.h
index 15eefe994..861232386 100644
--- a/src/inputStream.h
+++ b/src/inputStream.h
@@ -19,19 +19,33 @@
#ifndef INPUT_STREAM_H
#define INPUT_STREAM_H
-#include <stdio.h>
#include <stdlib.h>
-typedef struct _InputStream {
- FILE * fp;
+typedef struct _InputStream InputStream;
+
+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;
long offset;
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
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 closeInputStream(InputStream * inStream);
int inputStreamAtEOF(InputStream * inStream);
diff --git a/src/mp3_decode.c b/src/mp3_decode.c
index 9e19dbbda..a5a0d216c 100644
--- a/src/mp3_decode.c
+++ b/src/mp3_decode.c
@@ -139,8 +139,8 @@ typedef struct _mp3DecodeData {
int initMp3DecodeData(mp3DecodeData * data, char * file) {
int ret;
- while(((ret = openInputStreamFromFile(&(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;
diff --git a/src/mp4_decode.c b/src/mp4_decode.c
index b5c006f9e..4705a6ed6 100644
--- a/src/mp4_decode.c
+++ b/src/mp4_decode.c
@@ -113,7 +113,7 @@ int mp4_decode(OutputBuffer * cb, DecoderControl * dc) {
mpd_uint16 bitRate = 0;
InputStream inStream;
- if(openInputStreamFromFile(&inStream,dc->file) < 0) {
+ if(openInputStream(&inStream,dc->file) < 0) {
ERROR("failed to open %s\n",dc->file);
return -1;
}
diff --git a/src/ogg_decode.c b/src/ogg_decode.c
index cda00e6cb..4014644af 100644
--- a/src/ogg_decode.c
+++ b/src/ogg_decode.c
@@ -154,7 +154,7 @@ int ogg_decode(OutputBuffer * cb, DecoderControl * dc)
callbacks.close_func = ogg_close_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");
return -1;
}
diff --git a/src/tag.c b/src/tag.c
index dd1ea852c..1a9b03549 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -219,8 +219,7 @@ MpdTag * mp4DataDup(char * utf8file, int * mp4MetadataFound) {
*mp4MetadataFound = 0;
- if(openInputStreamFromFile(&inStream,rmp2amp(utf8ToFsCharset(utf8file)))
- < 0)
+ if(openInputStream(&inStream,rmp2amp(utf8ToFsCharset(utf8file))) < 0)
{
return NULL;
}