mp3 and ogg plugin stuff

git-svn-id: https://svn.musicpd.org/mpd/trunk@1245 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-05-31 01:21:17 +00:00
parent d7893a3e76
commit fd6aa25359
17 changed files with 231 additions and 498 deletions

View File

@ -1,21 +1,24 @@
bin_PROGRAMS = mpd bin_PROGRAMS = mpd
SUBDIRS = $(ID3_SUBDIR) $(MAD_SUBDIR) $(MP4FF_SUBDIR) SUBDIRS = $(ID3_SUBDIR) $(MAD_SUBDIR) $(MP4FF_SUBDIR)
mpd_inputPlugins = inputPlugins/mp3_plugin.c inputPlugins/ogg_plugin.c
mpd_headers = buffer2array.h interface.h command.h playlist.h ls.h \ mpd_headers = buffer2array.h interface.h command.h playlist.h ls.h \
song.h list.h directory.h tables.h utils.h path.h mp3_decode.h \ song.h list.h directory.h tables.h utils.h path.h \
tag.h player.h listen.h conf.h ogg_decode.h volume.h flac_decode.h \ tag.h player.h listen.h conf.h volume.h flac_decode.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 inputStream_file.h inputStream_http.h \ outputBuffer.h replayGain.h inputStream_file.h inputStream_http.h \
inputPlugin.h inputPlugin.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 \
tag.c player.c listen.c conf.c ogg_decode.c volume.c flac_decode.c \ tag.c player.c listen.c conf.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 inputStream_file.c inputStream_http.c inputPlugin.c \ replayGain.c inputStream_file.c inputStream_http.c inputPlugin.c \
$(mpd_headers) $(mpd_headers) $(mpd_inputPlugins)
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

@ -28,23 +28,6 @@
#include "sig_handlers.h" #include "sig_handlers.h"
#include "ls.h" #include "ls.h"
#ifdef HAVE_MAD
#include "mp3_decode.h"
#endif
#ifdef HAVE_OGG
#include "ogg_decode.h"
#endif
#ifdef HAVE_FLAC
#include "flac_decode.h"
#endif
#ifdef HAVE_AUDIOFILE
#include "audiofile_decode.h"
#endif
#ifdef HAVE_FAAD
#include "mp4_decode.h"
#include "aac_decode.h"
#endif
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
@ -255,8 +238,7 @@ int decodeSeek(PlayerControl * pc, DecoderControl * dc, OutputBuffer * cb,
void decodeStart(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) { void decodeStart(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) {
int ret; int ret;
InputStream inStream; InputStream inStream;
int suffix = pc->fileSuffix; InputPlugin * plugin;
int decodeType = pc->decodeType;
strncpy(dc->file,pc->file,MAXPATHLEN); strncpy(dc->file,pc->file,MAXPATHLEN);
dc->file[MAXPATHLEN] = '\0'; dc->file[MAXPATHLEN] = '\0';
@ -282,67 +264,33 @@ void decodeStart(PlayerControl * pc, OutputBuffer * cb, DecoderControl * dc) {
return; return;
} }
switch(decodeType) { ret = DECODE_ERROR_UNKTYPE;
case DECODE_TYPE_URL: if(isRemoteUrl(pc->file)) {
#ifdef HAVE_OGG plugin = getInputPluginFromMimeType(inStream.mime);
if(suffix == DECODE_SUFFIX_OGG || (inStream.mime && if(plugin == NULL) {
0 == strcmp(inStream.mime, "application/ogg"))) plugin = getInputPluginFromSuffix(getSuffix(dc->file));
}
if(plugin && (plugin->streamTypes & INPUT_PLUGIN_STREAM_URL) &&
plugin->streamDecodeFunc)
{ {
ret = ogg_decode(cb, dc, &inStream); ret = plugin->streamDecodeFunc(cb, dc, &inStream);
break;
} }
#endif
#ifdef HAVE_MAD
/*if(fileSuffix == DECODE_SUFFIX_MP3 || (inStream.mime &&
0 == strcmp(inStream.mime, "audio/mpeg")))*/
{
ret = mp3_decode(cb, dc, &inStream, 0);
break;
}
ret = DECODE_ERROR_UNKTYPE;
#endif
case DECODE_TYPE_FILE:
#ifdef HAVE_MAD
if(suffix == DECODE_SUFFIX_MP3) {
ret = mp3_decode(cb, dc, &inStream, 1);
break;
}
#endif
#ifdef HAVE_OGG
if(suffix == DECODE_SUFFIX_OGG) {
ret = ogg_decode(cb, dc, &inStream);
break;
}
#endif
#ifdef HAVE_FAAD
if(suffix == DECODE_SUFFIX_AAC) {
closeInputStream(&inStream);
ret = aac_decode(cb,dc);
break;
}
if(suffix == DECODE_SUFFIX_MP4) {
closeInputStream(&inStream);
ret = mp4_decode(cb,dc);
break;
}
#endif
#ifdef HAVE_FLAC
if(suffix == DECODE_SUFFIX_FLAC) {
closeInputStream(&inStream);
ret = flac_decode(cb,dc);
break;
}
#endif
#ifdef HAVE_AUDIOFILE
if(suffix == DECODE_SUFFIX_WAVE) {
closeInputStream(&inStream);
ret = audiofile_decode(cb,dc);
break;
}
#endif
default:
ret = DECODE_ERROR_UNKTYPE;
} }
else {
plugin = getInputPluginFromSuffix(getSuffix(dc->file));
if(plugin && (plugin->streamTypes && INPUT_PLUGIN_STREAM_FILE))
{
if(plugin->streamDecodeFunc) {
ret = plugin->streamDecodeFunc(cb, dc,
&inStream);
}
else if(plugin->fileDecodeFunc) {
closeInputStream(&inStream);
ret = plugin->fileDecodeFunc(cb, dc);
}
}
}
if(ret<0 || ret == DECODE_ERROR_UNKTYPE) { if(ret<0 || ret == DECODE_ERROR_UNKTYPE) {
strncpy(pc->erroredFile, dc->file, MAXPATHLEN); strncpy(pc->erroredFile, dc->file, MAXPATHLEN);
pc->erroredFile[MAXPATHLEN] = '\0'; pc->erroredFile[MAXPATHLEN] = '\0';

View File

@ -7,75 +7,10 @@
static List * inputPlugin_list = NULL; static List * inputPlugin_list = NULL;
InputPlugin * newInputPlugin(char * name, InputPlugin_streamDecodeFunc
streamDecodeFunc, InputPlugin_fileDecodeFunc fileDecodeFunc,
InputPlugin_tagDupFunc tagDupFunc, unsigned char streamTypes)
{
InputPlugin * ret = malloc(sizeof(InputPlugin));
memset(ret->name,0,INPUT_PLUGIN_NAME_LENGTH);
strncpy(ret->name, name, INPUT_PLUGIN_NAME_LENGTH-1);
ret->suffixes = NULL;
ret->mimeTypes = NULL;
ret->streamTypes = streamTypes;
ret->streamDecodeFunc = streamDecodeFunc;
ret->fileDecodeFunc = fileDecodeFunc;
ret->tagDupFunc = tagDupFunc;
return ret;
}
static void freeStringArray(char ** ptr) {
if(ptr) {
char ** tmp = ptr;
while(*tmp) {
if(*tmp) free(*tmp);
tmp++;
}
free (ptr);
}
}
void freeInputPlugin(InputPlugin * inPlugin) {
freeStringArray(inPlugin->suffixes);
freeStringArray(inPlugin->mimeTypes);
free(inPlugin);
}
static char ** AddStringToArray(char ** array, char * string) {
int arraySize = 1;
if(array) {
char ** tmp = array;
while(*tmp) {
arraySize++;
tmp++;
}
}
array = realloc(array, (arraySize+1)*sizeof(char *));
array[arraySize-1] = strdup(string);
array[arraySize] = NULL;
return array;
}
void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix) {
inPlugin->suffixes = AddStringToArray(inPlugin->suffixes, suffix);
}
void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * mimeType) {
inPlugin->mimeTypes = AddStringToArray(inPlugin->mimeTypes, mimeType);
}
void loadInputPlugin(InputPlugin * inputPlugin) { void loadInputPlugin(InputPlugin * inputPlugin) {
if(!inputPlugin) return;
if(!inputPlugin->name) return;
insertInList(inputPlugin_list, inputPlugin->name, (void *)inputPlugin); insertInList(inputPlugin_list, inputPlugin->name, (void *)inputPlugin);
} }
@ -96,11 +31,14 @@ InputPlugin * getInputPluginFromSuffix(char * suffix) {
ListNode * node = inputPlugin_list->firstNode; ListNode * node = inputPlugin_list->firstNode;
InputPlugin * plugin = NULL; InputPlugin * plugin = NULL;
if(suffix == NULL) return NULL;
while(node != NULL) { while(node != NULL) {
plugin = node->data; plugin = node->data;
if(stringFoundInStringArray(plugin->suffixes, suffix)) { if(stringFoundInStringArray(plugin->suffixes, suffix)) {
return plugin; return plugin;
} }
node = node->nextNode;
} }
return NULL; return NULL;
@ -115,6 +53,7 @@ InputPlugin * getInputPluginFromMimeType(char * mimeType) {
if(stringFoundInStringArray(plugin->mimeTypes, mimeType)) { if(stringFoundInStringArray(plugin->mimeTypes, mimeType)) {
return plugin; return plugin;
} }
node = node->nextNode;
} }
return NULL; return NULL;
@ -128,10 +67,15 @@ InputPlugin * getInputPluginFromName(char * name) {
return (InputPlugin *)plugin; return (InputPlugin *)plugin;
} }
extern InputPlugin mp3Plugin;
extern InputPlugin oggPlugin;
void initInputPlugins() { void initInputPlugins() {
inputPlugin_list = makeList((ListFreeDataFunc *)freeInputPlugin); inputPlugin_list = makeList(NULL);
/* load plugins here */ /* load plugins here */
loadInputPlugin(&mp3Plugin);
loadInputPlugin(&oggPlugin);
} }
void finishInputPlugins() { void finishInputPlugins() {

View File

@ -1,6 +1,7 @@
#ifndef INPUT_PLUGIN_H #ifndef INPUT_PLUGIN_H
#define INPUT_PLUGIN_H #define INPUT_PLUGIN_H
#include "../config.h"
#include "inputStream.h" #include "inputStream.h"
#include "decode.h" #include "decode.h"
#include "outputBuffer.h" #include "outputBuffer.h"
@ -9,8 +10,6 @@
#define INPUT_PLUGIN_STREAM_FILE 0x01 #define INPUT_PLUGIN_STREAM_FILE 0x01
#define INPUT_PLUGIN_STREAM_URL 0x02 #define INPUT_PLUGIN_STREAM_URL 0x02
#define INPUT_PLUGIN_NAME_LENGTH 64
typedef int (* InputPlugin_streamDecodeFunc) (OutputBuffer *, DecoderControl *, typedef int (* InputPlugin_streamDecodeFunc) (OutputBuffer *, DecoderControl *,
InputStream *); InputStream *);
@ -19,7 +18,7 @@ typedef int (* InputPlugin_fileDecodeFunc) (OutputBuffer *, DecoderControl *);
typedef MpdTag * (* InputPlugin_tagDupFunc) (char * utf8file); typedef MpdTag * (* InputPlugin_tagDupFunc) (char * utf8file);
typedef struct _InputPlugin { typedef struct _InputPlugin {
char name[INPUT_PLUGIN_NAME_LENGTH]; char * name;
InputPlugin_streamDecodeFunc streamDecodeFunc; InputPlugin_streamDecodeFunc streamDecodeFunc;
InputPlugin_fileDecodeFunc fileDecodeFunc; InputPlugin_fileDecodeFunc fileDecodeFunc;
InputPlugin_tagDupFunc tagDupFunc; InputPlugin_tagDupFunc tagDupFunc;
@ -28,25 +27,15 @@ typedef struct _InputPlugin {
char ** mimeTypes; char ** mimeTypes;
} InputPlugin; } InputPlugin;
/* interface for constructing a plugin */
InputPlugin * newInputPlugin(char * name, InputPlugin_streamDecodeFunc
streamDecodeFunc, InputPlugin_fileDecodeFunc fileDecodeFunc,
InputPlugin_tagDupFunc tagDupFunc, unsigned char streamTypes);
void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix);
void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * suffix);
void freeInputPlugin(InputPlugin * inputPlugin);
/* individual functions to load/unload plugins */ /* individual functions to load/unload plugins */
void loadInputPlugin(InputPlugin * inputPlugin); void loadInputPlugin(InputPlugin * inputPlugin);
/* this free's inputPlugin as well! */
void unloadInputPlugin(InputPlugin * inputPlugin); void unloadInputPlugin(InputPlugin * inputPlugin);
/* interface for using plugins */ /* interface for using plugins */
InputPlugin * getInputPluginFromSuffix(char * suffix); InputPlugin * getInputPluginFromSuffix(char * suffix);
InputPlugin * getInputPluginFromMimeTypes(char * mimeType); InputPlugin * getInputPluginFromMimeType(char * mimeType);
InputPlugin * getInputPluginFromName(char * name); InputPlugin * getInputPluginFromName(char * name);

View File

@ -16,28 +16,27 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "mp3_decode.h" #include "../inputPlugin.h"
#ifdef HAVE_MAD #ifdef HAVE_MAD
#include "pcm_utils.h" #include "../pcm_utils.h"
#ifdef USE_MPD_MAD #ifdef USE_MPD_MAD
#include "libmad/mad.h" #include "../libmad/mad.h"
#else #else
#include <mad.h> #include <mad.h>
#endif #endif
#ifdef HAVE_ID3TAG #ifdef HAVE_ID3TAG
#ifdef USE_MPD_ID3TAG #ifdef USE_MPD_ID3TAG
#include "libid3tag/id3tag.h" #include "../libid3tag/id3tag.h"
#else #else
#include <id3tag.h> #include <id3tag.h>
#endif #endif
#endif #endif
#include "playerData.h" #include "../log.h"
#include "log.h" #include "../utils.h"
#include "utils.h" #include "../tag.h"
#include "inputStream.h" #include "../path.h"
#include "outputBuffer.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -419,10 +418,10 @@ int getMp3TotalTime(char * file) {
} }
int openMp3FromInputStream(InputStream * inStream, mp3DecodeData * data, int openMp3FromInputStream(InputStream * inStream, mp3DecodeData * data,
DecoderControl * dc, int ignoreCrc) DecoderControl * dc)
{ {
initMp3DecodeData(data, inStream); initMp3DecodeData(data, inStream);
if(ignoreCrc) data->stream.options |= MAD_OPTION_IGNORECRC; data->stream.options |= MAD_OPTION_IGNORECRC;
if(decodeFirstFrame(data, dc)<0) { if(decodeFirstFrame(data, dc)<0) {
mp3DecodeDataFinalize(data); mp3DecodeDataFinalize(data);
return -1; return -1;
@ -565,12 +564,10 @@ void initAudioFormatFromMp3DecodeData(mp3DecodeData * data, AudioFormat * af) {
af->channels = MAD_NCHANNELS(&(data->frame).header); af->channels = MAD_NCHANNELS(&(data->frame).header);
} }
int mp3_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream, int mp3_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream) {
int ignoreCrc)
{
mp3DecodeData data; mp3DecodeData data;
if(openMp3FromInputStream(inStream, &data, dc, ignoreCrc) < 0) { if(openMp3FromInputStream(inStream, &data, dc) < 0) {
closeInputStream(inStream); closeInputStream(inStream);
if(!dc->stop) { if(!dc->stop) {
ERROR("Input does not appear to be a mp3 bit stream.\n"); ERROR("Input does not appear to be a mp3 bit stream.\n");
@ -616,5 +613,47 @@ int mp3_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream,
return 0; return 0;
} }
MpdTag * mp3_tagDup(char * utf8file) {
MpdTag * ret = NULL;
int time;
ret = id3Dup(utf8file);
time = getMp3TotalTime(rmp2amp(utf8ToFsCharset(utf8file)));
if(time>=0) {
if(!ret) ret = newMpdTag();
ret->time = time;
}
if(ret) validateUtf8Tag(ret);
return ret;
}
char * mp3_suffixes[] = {"mp3", NULL};
char * mp3_mimeTypes[] = {"audio/mpeg", NULL};
InputPlugin mp3Plugin =
{
"mp3",
mp3_decode,
NULL,
mp3_tagDup,
INPUT_PLUGIN_STREAM_FILE | INPUT_PLUGIN_STREAM_URL,
mp3_suffixes,
mp3_mimeTypes
};
#else
InputPlugin mp3Plugin =
{
NULL,
NULL,
NULL,
0,
NULL,
NULL
};
#endif #endif
/* vim:set shiftwidth=8 tabstop=8 expandtab: */

View File

@ -16,18 +16,18 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "ogg_decode.h" #include "../inputPlugin.h"
#ifdef HAVE_OGG #ifdef HAVE_OGG
#include "command.h" #include "../command.h"
#include "utils.h" #include "../utils.h"
#include "audio.h" #include "../audio.h"
#include "log.h" #include "../log.h"
#include "pcm_utils.h" #include "../pcm_utils.h"
#include "inputStream.h" #include "../inputStream.h"
#include "outputBuffer.h" #include "../outputBuffer.h"
#include "replayGain.h" #include "../replayGain.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
@ -274,5 +274,91 @@ int ogg_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream)
return 0; return 0;
} }
MpdTag * oggTagDup(char * utf8file) {
MpdTag * ret = NULL;
FILE * fp;
OggVorbis_File vf;
char ** comments;
char * temp;
char * s1;
char * s2;
fp = fopen(rmp2amp(utf8ToFsCharset(utf8file)),"r");
if(!fp) return NULL;
if(ov_open(fp,&vf,NULL,0)<0) {
fclose(fp);
return NULL;
}
ret = newMpdTag();
ret->time = (int)(ov_time_total(&vf,-1)+0.5);
comments = ov_comment(&vf,-1)->user_comments;
while(*comments) {
temp = strdup(*comments);
++comments;
if(!(s1 = strtok(temp,"="))) continue;
s2 = strtok(NULL,"");
if(!s1 || !s2);
else if(0==strcasecmp(s1,"artist")) {
if(!ret->artist) {
stripReturnChar(s2);
ret->artist = strdup(s2);
}
}
else if(0==strcasecmp(s1,"title")) {
if(!ret->title) {
stripReturnChar(s2);
ret->title = strdup(s2);
}
}
else if(0==strcasecmp(s1,"album")) {
if(!ret->album) {
stripReturnChar(s2);
ret->album = strdup(s2);
}
}
else if(0==strcasecmp(s1,"tracknumber")) {
if(!ret->track) {
stripReturnChar(s2);
ret->track = strdup(s2);
}
}
free(temp);
}
ov_clear(&vf);
if(ret) validateUtf8Tag(ret);
return ret;
}
char * oggSuffixes[] = {"ogg", NULL};
char * oggMimeTypes[] = {"application/ogg", NULL};
InputPlugin oggPlugin =
{
"ogg",
ogg_decode,
NULL,
oggTagDup,
INPUT_PLUGIN_STREAM_URL | INPUT_PLUGIN_STREAM_FILE,
oggSuffixes,
oggMimeTypes
};
#else
InputPlugin oggPlugin =
{
NULL,
NULL,
NULL,
0,
NULL,
NULL
};
#endif #endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -389,10 +389,12 @@ static int getHTTPHello(InputStream * inStream) {
DEBUG("stream audiocast-name: %s\n", data->icyName); DEBUG("stream audiocast-name: %s\n", data->icyName);
} }
else if(0 == strncmp(cur, "\r\nContent-Type:", 15)) { else if(0 == strncmp(cur, "\r\nContent-Type:", 15)) {
char * temp = strstr(cur+15,"\r\n"); int incr = 15;
char * temp = strstr(cur+incr,"\r\n");
if(!temp) break; if(!temp) break;
*temp = '\0'; *temp = '\0';
if(inStream->mime) free(inStream->mime); if(inStream->mime) free(inStream->mime);
while(*(incr+cur) == ' ') incr++;
inStream->mime = strdup(cur+15); inStream->mime = strdup(cur+15);
*temp = '\r'; *temp = '\r';
} }

View File

@ -216,27 +216,15 @@ int isDir(char * utf8name) {
return 0; return 0;
} }
int isMusic(char * utf8file, time_t * mtime) { InputPlugin * isMusic(char * utf8file, time_t * mtime) {
InputPlugin * ret = NULL;
if(isFile(utf8file,mtime)) { if(isFile(utf8file,mtime)) {
#ifdef HAVE_OGG char * s = getSuffix(utf8file);
if(hasOggSuffix(utf8file)) return 1; if(s) ret = getInputPluginFromSuffix(s);
#endif
#ifdef HAVE_FLAC
if(hasFlacSuffix(utf8file)) return 1;
#endif
#ifdef HAVE_MAD
if(hasMp3Suffix(utf8file)) return 1;
#endif
#ifdef HAVE_AUDIOFILE
if(hasWaveSuffix(utf8file)) return 1;
#endif
#ifdef HAVE_FAAD
if(hasMp4Suffix(utf8file)) return 1;
if(hasAacSuffix(utf8file)) return 1;
#endif
} }
return 0; return ret;
} }
/* vim:set shiftwidth=4 tabstop=8 expandtab: */ /* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -21,11 +21,15 @@
#include "../config.h" #include "../config.h"
#include "inputPlugin.h"
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
int lsPlaylists(FILE * fp, char * utf8path); int lsPlaylists(FILE * fp, char * utf8path);
char * getSuffix(char * utf8file);
int isRemoteUrl(char * url); int isRemoteUrl(char * url);
int isFile(char * utf8file, time_t * mtime); int isFile(char * utf8file, time_t * mtime);
@ -34,19 +38,7 @@ int isDir(char * utf8name);
int isPlaylist(char * utf8file); int isPlaylist(char * utf8file);
int isMusic(char * utf8file, time_t * mtime); InputPlugin * isMusic(char * utf8file, time_t * mtime);
int hasWaveSuffix(char * utf8file);
int hasMp3Suffix(char * utf8file);
int hasAacSuffix(char * utf8file);
int hasMp4Suffix(char * utf8file);
int hasOggSuffix(char * utf8file);
int hasFlacSuffix(char * utf8file);
char * dupAndStripPlaylistSuffix(char * file); char * dupAndStripPlaylistSuffix(char * file);

View File

@ -33,6 +33,7 @@
#include "log.h" #include "log.h"
#include "permission.h" #include "permission.h"
#include "replayGain.h" #include "replayGain.h"
#include "inputPlugin.h"
#include "../config.h" #include "../config.h"
#include <stdio.h> #include <stdio.h>
@ -327,6 +328,7 @@ int main(int argc, char * argv[]) {
initTables(); initTables();
initPlaylist(); initPlaylist();
initInputPlugins();
if(!options.dbFile) directory_db = strdup(rpp2app(".mpddb")); if(!options.dbFile) directory_db = strdup(rpp2app(".mpddb"));
else directory_db = strdup(options.dbFile); else directory_db = strdup(options.dbFile);
@ -448,6 +450,7 @@ int main(int argc, char * argv[]) {
finishPaths(); finishPaths();
finishPermissions(); finishPermissions();
finishCommands(); finishCommands();
finishInputPlugins();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,38 +0,0 @@
/* the Music Player Daemon (MPD)
* (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MP3_DECODE_H
#define MP3_DECODE_H
#include "../config.h"
#ifdef HAVE_MAD
#include "playerData.h"
#include "inputStream.h"
/* this is primarily used in tag.c */
int getMp3TotalTime(char * file);
int mp3_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream,
int ignoreCrc);
#endif
#endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -1,34 +0,0 @@
/* the Music Player Daemon (MPD)
* (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef OGG_DECODE_H
#define OGG_DECODE_H
#include "../config.h"
#include "playerData.h"
#include "inputStream.h"
#include <stdio.h>
int ogg_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream);
int getOggTotalTime(char * file);
#endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -117,7 +117,6 @@ int playerInit() {
closeMp3Directory(); closeMp3Directory();
finishPlaylist(); finishPlaylist();
closeTables(); closeTables();
finishPaths();
finishPermissions(); finishPermissions();
finishCommands(); finishCommands();
finishVolume(); finishVolume();
@ -160,35 +159,8 @@ int playerInit() {
return 0; return 0;
} }
int playerGetDecodeType(char * utf8file) {
if(isRemoteUrl(utf8file)) return DECODE_TYPE_URL;
if(isFile(utf8file,NULL)) return DECODE_TYPE_FILE;
return -1;
}
int playerGetSuffix(char * utf8file) {
#ifdef HAVE_MAD
if(hasMp3Suffix(utf8file)) return DECODE_SUFFIX_MP3;
#endif
#ifdef HAVE_OGG
if(hasOggSuffix(utf8file)) return DECODE_SUFFIX_OGG;
#endif
#ifdef HAVE_FAAD
if(hasAacSuffix(utf8file)) return DECODE_SUFFIX_AAC;
if(hasMp4Suffix(utf8file)) return DECODE_SUFFIX_MP4;
#endif
#ifdef HAVE_FLAC
if(hasFlacSuffix(utf8file)) return DECODE_SUFFIX_FLAC;
#endif
#ifdef HAVE_AUDIOFILE
if(hasWaveSuffix(utf8file)) return DECODE_SUFFIX_WAVE;
#endif
return -1;
}
int playerPlay(FILE * fp, Song * song) { int playerPlay(FILE * fp, Song * song) {
PlayerControl * pc = &(getPlayerData()->playerControl); PlayerControl * pc = &(getPlayerData()->playerControl);
int decodeType;
if(fp==NULL) fp = stderr; if(fp==NULL) fp = stderr;
@ -204,15 +176,6 @@ int playerPlay(FILE * fp, Song * song) {
} }
}*/ }*/
decodeType = playerGetDecodeType(song->utf8url);
if(decodeType < 0) {
strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
pc->erroredFile[MAXPATHLEN] = '\0';
pc->error = PLAYER_ERROR_UNKTYPE;
return 0;
}
pc->decodeType = decodeType;
pc->fileSuffix = playerGetSuffix(song->utf8url);
if(song->tag) pc->fileTime = song->tag->time; if(song->tag) pc->fileTime = song->tag->time;
else pc->fileTime = 0; else pc->fileTime = 0;
@ -362,7 +325,6 @@ void playerCloseAudio() {
int queueSong(Song * song) { int queueSong(Song * song) {
PlayerControl * pc = &(getPlayerData()->playerControl); PlayerControl * pc = &(getPlayerData()->playerControl);
int decodeType;
if(pc->queueState==PLAYER_QUEUE_BLANK) { if(pc->queueState==PLAYER_QUEUE_BLANK) {
if(isRemoteUrl(song->utf8url)) { if(isRemoteUrl(song->utf8url)) {
@ -372,10 +334,6 @@ int queueSong(Song * song) {
MAXPATHLEN); MAXPATHLEN);
pc->file[MAXPATHLEN] = '\0'; pc->file[MAXPATHLEN] = '\0';
decodeType = playerGetDecodeType(song->utf8url);
if(decodeType < 0) return -1;
pc->decodeType = decodeType;
pc->fileSuffix = playerGetSuffix(song->utf8url);
if(song->tag) pc->fileTime = song->tag->time; if(song->tag) pc->fileTime = song->tag->time;
else pc->fileTime = 0; else pc->fileTime = 0;
@ -421,7 +379,6 @@ void playerQueueUnlock() {
int playerSeek(FILE * fp, Song * song, float time) { int playerSeek(FILE * fp, Song * song, float time) {
PlayerControl * pc = &(getPlayerData()->playerControl); PlayerControl * pc = &(getPlayerData()->playerControl);
char * file; char * file;
int decodeType;
if(pc->state==PLAYER_STATE_STOP) { if(pc->state==PLAYER_STATE_STOP) {
myfprintf(fp,"%s player not currently playing\n", myfprintf(fp,"%s player not currently playing\n",
@ -432,16 +389,6 @@ int playerSeek(FILE * fp, Song * song, float time) {
if(isRemoteUrl(song->utf8url)) file = song->utf8url; if(isRemoteUrl(song->utf8url)) file = song->utf8url;
else file = rmp2amp(utf8ToFsCharset(song->utf8url)); else file = rmp2amp(utf8ToFsCharset(song->utf8url));
if(strcmp(pc->file,file)!=0) { if(strcmp(pc->file,file)!=0) {
decodeType = playerGetDecodeType(song->utf8url);
if(decodeType < 0) {
myfprintf(fp,"%s unknown file type: %s\n",
COMMAND_RESPOND_ERROR, song->utf8url);
ERROR("playerSeek: unknown file type: %s\n",
song->utf8url);
return -1;
}
pc->decodeType = decodeType;
pc->fileSuffix = playerGetSuffix(song->utf8url);
if(song->tag) pc->fileTime = song->tag->time; if(song->tag) pc->fileTime = song->tag->time;
else pc->fileTime = 0; else pc->fileTime = 0;

View File

@ -52,8 +52,6 @@
#define PLAYER_QUEUE_LOCKED 1 #define PLAYER_QUEUE_LOCKED 1
typedef struct _PlayerControl { typedef struct _PlayerControl {
volatile mpd_sint8 decodeType;
volatile mpd_sint8 fileSuffix;
volatile mpd_sint8 stop; volatile mpd_sint8 stop;
volatile mpd_sint8 play; volatile mpd_sint8 play;
volatile mpd_sint8 pause; volatile mpd_sint8 pause;

View File

@ -23,13 +23,10 @@
#include "utils.h" #include "utils.h"
#include "tag.h" #include "tag.h"
#include "log.h" #include "log.h"
#include "mp3_decode.h"
#include "audiofile_decode.h"
#include "ogg_decode.h"
#include "flac_decode.h"
#include "path.h" #include "path.h"
#include "playlist.h" #include "playlist.h"
#include "tables.h" #include "tables.h"
#include "inputPlugin.h"
#define SONG_KEY "key: " #define SONG_KEY "key: "
#define SONG_FILE "file: " #define SONG_FILE "file: "
@ -60,36 +57,10 @@ Song * newSong(char * utf8url, SONG_TYPE type) {
song->type = type; song->type = type;
if(song->type == SONG_TYPE_FILE) { if(song->type == SONG_TYPE_FILE) {
if(!isFile(utf8url,&(song->mtime))); InputPlugin * plugin;
#ifdef HAVE_OGG if((plugin = isMusic(utf8url,&(song->mtime)))) {
else if(hasOggSuffix(utf8url)) { song->tag = plugin->tagDupFunc(utf8url);
song->tag = oggTagDup(utf8url); }
}
#endif
#ifdef HAVE_FLAC
else if((hasFlacSuffix(utf8url))) {
song->tag = flacTagDup(utf8url);
}
#endif
#ifdef HAVE_MAD
else if(hasMp3Suffix(utf8url)) {
song->tag = mp3TagDup(utf8url);
}
#endif
#ifdef HAVE_AUDIOFILE
else if(hasWaveSuffix(utf8url)) {
song->tag = audiofileTagDup(utf8url);
}
#endif
#ifdef HAVE_FAAD
else if(hasAacSuffix(utf8url)) {
song->tag = aacTagDup(utf8url);
}
else if(hasMp4Suffix(utf8url)) {
song->tag = mp4TagDup(utf8url);
}
#endif
if(!song->tag || song->tag->time<0) { if(!song->tag || song->tag->time<0) {
freeSong(song); freeSong(song);
song = NULL; song = NULL;
@ -288,41 +259,16 @@ int updateSongInfo(Song * song) {
char * utf8url = song->utf8url; char * utf8url = song->utf8url;
if(song->type == SONG_TYPE_FILE) { if(song->type == SONG_TYPE_FILE) {
InputPlugin * plugin;
removeASongFromTables(song); removeASongFromTables(song);
if(song->tag) freeMpdTag(song->tag); if(song->tag) freeMpdTag(song->tag);
song->tag = NULL; song->tag = NULL;
if(!isFile(utf8url,&(song->mtime))); if((plugin = isMusic(utf8url,&(song->mtime)))) {
#ifdef HAVE_OGG song->tag = plugin->tagDupFunc(utf8url);
else if(hasOggSuffix(utf8url)) { }
song->tag = oggTagDup(utf8url);
}
#endif
#ifdef HAVE_FLAC
else if((hasFlacSuffix(utf8url))) {
song->tag = flacTagDup(utf8url);
}
#endif
#ifdef HAVE_MAD
else if(hasMp3Suffix(utf8url)) {
song->tag = mp3TagDup(utf8url);
}
#endif
#ifdef HAVE_AUDIOFILE
else if(hasWaveSuffix(utf8url)) {
song->tag = audiofileTagDup(utf8url);
}
#endif
#ifdef HAVE_FAAD
else if(hasAacSuffix(utf8url)) {
song->tag = aacTagDup(utf8url);
}
else if(hasMp4Suffix(utf8url)) {
song->tag = mp4TagDup(utf8url);
}
#endif
if(!song->tag || song->tag->time<0) return -1; if(!song->tag || song->tag->time<0) return -1;
else addSongToTables(song); else addSongToTables(song);
} }

View File

@ -19,7 +19,6 @@
#include "tag.h" #include "tag.h"
#include "path.h" #include "path.h"
#include "myfprintf.h" #include "myfprintf.h"
#include "mp3_decode.h"
#include "audiofile_decode.h" #include "audiofile_decode.h"
#include "mp4_decode.h" #include "mp4_decode.h"
#include "aac_decode.h" #include "aac_decode.h"
@ -171,26 +170,6 @@ MpdTag * audiofileTagDup(char * utf8file) {
} }
#endif #endif
#ifdef HAVE_MAD
MpdTag * mp3TagDup(char * utf8file) {
MpdTag * ret = NULL;
int time;
ret = id3Dup(utf8file);
time = getMp3TotalTime(rmp2amp(utf8ToFsCharset(utf8file)));
if(time>=0) {
if(!ret) ret = newMpdTag();
ret->time = time;
}
if(ret) validateUtf8Tag(ret);
return ret;
}
#endif
#ifdef HAVE_FAAD #ifdef HAVE_FAAD
MpdTag * aacTagDup(char * utf8file) { MpdTag * aacTagDup(char * utf8file) {
MpdTag * ret = NULL; MpdTag * ret = NULL;
@ -300,69 +279,6 @@ MpdTag * mp4TagDup(char * utf8file) {
} }
#endif #endif
#ifdef HAVE_OGG
MpdTag * oggTagDup(char * utf8file) {
MpdTag * ret = NULL;
FILE * fp;
OggVorbis_File vf;
char ** comments;
char * temp;
char * s1;
char * s2;
fp = fopen(rmp2amp(utf8ToFsCharset(utf8file)),"r");
if(!fp) return NULL;
if(ov_open(fp,&vf,NULL,0)<0) {
fclose(fp);
return NULL;
}
ret = newMpdTag();
ret->time = (int)(ov_time_total(&vf,-1)+0.5);
comments = ov_comment(&vf,-1)->user_comments;
while(*comments) {
temp = strdup(*comments);
++comments;
if(!(s1 = strtok(temp,"="))) continue;
s2 = strtok(NULL,"");
if(!s1 || !s2);
else if(0==strcasecmp(s1,"artist")) {
if(!ret->artist) {
stripReturnChar(s2);
ret->artist = strdup(s2);
}
}
else if(0==strcasecmp(s1,"title")) {
if(!ret->title) {
stripReturnChar(s2);
ret->title = strdup(s2);
}
}
else if(0==strcasecmp(s1,"album")) {
if(!ret->album) {
stripReturnChar(s2);
ret->album = strdup(s2);
}
}
else if(0==strcasecmp(s1,"tracknumber")) {
if(!ret->track) {
stripReturnChar(s2);
ret->track = strdup(s2);
}
}
free(temp);
}
ov_clear(&vf);
if(ret) validateUtf8Tag(ret);
return ret;
}
#endif
#ifdef HAVE_FLAC #ifdef HAVE_FLAC
MpdTag * flacMetadataDup(char * utf8file, int * vorbisCommentFound) { MpdTag * flacMetadataDup(char * utf8file, int * vorbisCommentFound) {
MpdTag * ret = NULL; MpdTag * ret = NULL;

View File

@ -31,6 +31,8 @@ typedef struct _MpdTag {
int time; int time;
} MpdTag; } MpdTag;
MpdTag * id3Dup(char * utf8filename);
MpdTag * newMpdTag(); MpdTag * newMpdTag();
void freeMpdTag(MpdTag * tag); void freeMpdTag(MpdTag * tag);
@ -61,5 +63,7 @@ void printMpdTag(FILE * fp, MpdTag * tag);
MpdTag * mpdTagDup(MpdTag * tag); MpdTag * mpdTagDup(MpdTag * tag);
void validateUtf8Tag(MpdTag * tag);
#endif #endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */ /* vim:set shiftwidth=4 tabstop=8 expandtab: */