aboutsummaryrefslogtreecommitdiffstats
path: root/src/decode.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-05-18 13:13:55 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-05-18 13:13:55 +0000
commitc51ad71efaa975c64f6ad31dce5578307a5cba7b (patch)
tree348881ea4c5b04bd17e04e881905dbacef296869 /src/decode.c
parent6c24180516f823985f564ba013607b47f70afa81 (diff)
downloadmpd-c51ad71efaa975c64f6ad31dce5578307a5cba7b.tar.gz
mpd-c51ad71efaa975c64f6ad31dce5578307a5cba7b.tar.xz
mpd-c51ad71efaa975c64f6ad31dce5578307a5cba7b.zip
rework stuff so that we can use mime-type of streams to detect type of file
git-svn-id: https://svn.musicpd.org/mpd/trunk@1062 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/decode.c129
1 files changed, 83 insertions, 46 deletions
diff --git a/src/decode.c b/src/decode.c
index 8ab215a4a..c990edc9e 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -26,6 +26,7 @@
#include "path.h"
#include "log.h"
#include "sig_handlers.h"
+#include "ls.h"
#ifdef HAVE_MAD
#include "mp3_decode.h"
@@ -213,65 +214,101 @@ void decodeSeek(PlayerControl * pc, DecoderControl * dc, OutputBuffer * cb) {
return; \
}
-int decoderInit(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) {
-
- int pid;
- int ret;
- decode_pid = &(pc->decode_pid);
+void decodeStart(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) {
+ int ret;
+ InputStream inStream;
- blockSignals();
- pid = fork();
+ strncpy(dc->file,pc->file,MAXPATHLEN);
+ dc->file[MAXPATHLEN] = '\0';
- if(pid==0) {
- /* CHILD */
- unblockSignals();
+ if(openInputStream(&inStream,dc->file) < 0) {
+ dc->error = DECODE_ERROR_FILE;
+ dc->start = 0;
+ dc->stop = 0;
+ dc->state = DECODE_STATE_STOP;
+ return;
+ }
- while(1) {
- if(dc->start) {
- strncpy(dc->file,pc->file,MAXPATHLEN);
- dc->file[MAXPATHLEN] = '\0';
- switch(pc->decodeType) {
+ while(!inputStreamAtEOF(&inStream) && bufferInputStream(&inStream) < 0);
+
+ switch(pc->decodeType) {
+ case DECODE_TYPE_URL:
#ifdef HAVE_MAD
- case DECODE_TYPE_MP3:
- ret = mp3_decode(cb,dc);
- break;
+ if(pc->fileSuffix == DECODE_SUFFIX_MP3 || (inStream.mime &&
+ 0 == strcmp(inStream.mime, "audio/mpeg")))
+ {
+ ret = mp3_decode(cb,dc,&inStream);
+ }
+ else ret = DECODE_ERROR_UNKTYPE;
+ break;
+#endif
+ case DECODE_TYPE_FILE:
+#ifdef HAVE_MAD
+ if(pc->fileSuffix == DECODE_SUFFIX_MP3) {
+ ret = mp3_decode(cb, dc, &inStream);
+ break;
+ }
#endif
#ifdef HAVE_FAAD
- case DECODE_TYPE_AAC:
- ret = aac_decode(cb,dc);
- break;
- case DECODE_TYPE_MP4:
- ret = mp4_decode(cb,dc);
- break;
+ if(pc->fileSuffix == DECODE_SUFFIX_AAC) {
+ closeInputStream(&inStream);
+ ret = aac_decode(cb,dc);
+ break;
+ }
+ if(pc->fileSuffix == DECODE_SUFFIX_MP4) {
+ closeInputStream(&inStream);
+ ret = mp4_decode(cb,dc);
+ break;
+ }
#endif
#ifdef HAVE_OGG
- case DECODE_TYPE_OGG:
- ret = ogg_decode(cb,dc);
- break;
+ if(pc->fileSuffix == DECODE_SUFFIX_OGG) {
+ closeInputStream(&inStream);
+ ret = ogg_decode(cb,dc);
+ break;
+ }
#endif
#ifdef HAVE_FLAC
- case DECODE_TYPE_FLAC:
- ret = flac_decode(cb,dc);
- break;
+ if(pc->fileSuffix == DECODE_SUFFIX_FLAC) {
+ closeInputStream(&inStream);
+ ret = flac_decode(cb,dc);
+ break;
+ }
#endif
#ifdef HAVE_AUDIOFILE
- case DECODE_TYPE_AUDIOFILE:
- ret = audiofile_decode(cb,dc);
- break;
+ if(pc->fileSuffix == DECODE_SUFFIX_WAVE) {
+ closeInputStream(&inStream);
+ ret = audiofile_decode(cb,dc);
+ break;
+ }
#endif
- default:
- ret = DECODE_ERROR_UNKTYPE;
- strncpy(pc->erroredFile,dc->file,
- MAXPATHLEN);
- pc->erroredFile[MAXPATHLEN] = '\0';
- }
- if(ret<0) {
- dc->error = DECODE_ERROR_FILE;
- dc->start = 0;
- dc->stop = 0;
- dc->state = DECODE_STATE_STOP;
- }
- }
+ default:
+ ret = DECODE_ERROR_UNKTYPE;
+ }
+ if(ret<0) {
+ strncpy(pc->erroredFile, dc->file, MAXPATHLEN);
+ pc->erroredFile[MAXPATHLEN] = '\0';
+ if(ret != DECODE_ERROR_UNKTYPE) dc->error = DECODE_ERROR_FILE;
+ dc->start = 0;
+ dc->stop = 0;
+ dc->state = DECODE_STATE_STOP;
+ }
+}
+
+int decoderInit(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) {
+
+ int pid;
+ decode_pid = &(pc->decode_pid);
+
+ blockSignals();
+ pid = fork();
+
+ if(pid==0) {
+ /* CHILD */
+ unblockSignals();
+
+ while(1) {
+ if(dc->start) decodeStart(pc, cb, dc);
else if(dc->stop) {
dc->state = DECODE_STATE_STOP;
dc->stop = 0;