diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-05-04 19:49:29 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-05-04 19:49:29 +0000 |
commit | 659df586719c727204513c97c243c9f14dbfa5d9 (patch) | |
tree | 404a08b7c414feb0c1193fadd3ee146fa9bc8f95 /src/ogg_decode.c | |
parent | 638817fc5b2a537b21335d8f5e429559353602a5 (diff) | |
download | mpd-659df586719c727204513c97c243c9f14dbfa5d9.tar.gz mpd-659df586719c727204513c97c243c9f14dbfa5d9.tar.xz mpd-659df586719c727204513c97c243c9f14dbfa5d9.zip |
implement input abstraction for ogg and mp3
git-svn-id: https://svn.musicpd.org/mpd/trunk@904 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/ogg_decode.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/ogg_decode.c b/src/ogg_decode.c index 7d673d462..e37dae2a2 100644 --- a/src/ogg_decode.c +++ b/src/ogg_decode.c @@ -25,12 +25,14 @@ #include "audio.h" #include "log.h" #include "pcm_utils.h" +#include "inputStream.h" #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <vorbis/vorbisfile.h> +#include <errno.h> #ifdef WORDS_BIGENDIAN #define OGG_DECODE_USE_BIGENDIAN 1 @@ -38,6 +40,7 @@ #define OGG_DECODE_USE_BIGENDIAN 0 #endif +/* this is just for tag parsing for db import! */ int getOggTotalTime(char * file) { OggVorbis_File vf; FILE * oggfp; @@ -57,19 +60,47 @@ int getOggTotalTime(char * file) { return totalTime; } +size_t ogg_read_cb(void * ptr, size_t size, size_t nmemb, void * inStream) +{ + size_t ret; + ret = readFromInputStream((InputStream *)inStream,ptr,size,nmemb); + + if(ret<0) errno = ((InputStream *)inStream)->error; + + return ret; +} + +int ogg_seek_cb(void * inStream, ogg_int64_t offset, int whence) { + return seekInputStream((InputStream *)inStream,offset,whence); +} + +int ogg_close_cb(void * inStream) { + return closeInputStream((InputStream *)inStream); +} + +long ogg_tell_cb(void * inStream) { + return ((InputStream *)inStream)->offset; +} + int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) { OggVorbis_File vf; - FILE * oggfp; + ov_callbacks callbacks; + InputStream inStream; + + callbacks.read_func = ogg_read_cb; + callbacks.seek_func = ogg_seek_cb; + callbacks.close_func = ogg_close_cb; + callbacks.tell_func = ogg_tell_cb; - if(!(oggfp = fopen(dc->file,"r"))) { + if(openInputStreamFromFile(&inStream,dc->file)<0) { ERROR("failed to open ogg\n"); return -1; } - if(ov_open(oggfp, &vf, NULL, 0) < 0) { + if(ov_open_callbacks(&inStream, &vf, NULL, 0, callbacks) < 0) { ERROR("Input does not appear to be an Ogg bit stream.\n"); - fclose(oggfp); + closeInputStream(&inStream); return -1; } |