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:
parent
ee79a3a8fd
commit
48a58073dd
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
int openInputStream(InputStream * inStream, char * url) {
|
||||
if(inputStream_fileOpen(inStream,url) == 0) return 0;
|
||||
if(inputStream_httpOpen(inStream,url) == 0) return 0;
|
||||
|
||||
inStream->offset = 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: */
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user