aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputPlugins/ogg_plugin.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-03-16 06:52:46 +0000
committerEric Wong <normalperson@yhbt.net>2006-03-16 06:52:46 +0000
commit69635022133488e6b19569fb59b16c4658a244eb (patch)
treea7149e6a5a82017ae3821c801433c8794f796aec /src/inputPlugins/ogg_plugin.c
parentd7e846bdc2d848525ebd4251c4c5d9c5fe0d2705 (diff)
downloadmpd-69635022133488e6b19569fb59b16c4658a244eb.tar.gz
mpd-69635022133488e6b19569fb59b16c4658a244eb.tar.xz
mpd-69635022133488e6b19569fb59b16c4658a244eb.zip
merge with mpd/trunk up to r3925
git-svn-id: https://svn.musicpd.org/mpd/trunk@3926 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/inputPlugins/oggvorbis_plugin.c (renamed from src/inputPlugins/ogg_plugin.c)126
1 files changed, 66 insertions, 60 deletions
diff --git a/src/inputPlugins/ogg_plugin.c b/src/inputPlugins/oggvorbis_plugin.c
index abadca388..63bac411e 100644
--- a/src/inputPlugins/ogg_plugin.c
+++ b/src/inputPlugins/oggvorbis_plugin.c
@@ -16,9 +16,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+/* TODO 'ogg' should probably be replaced with 'oggvorbis' in all instances */
+
#include "../inputPlugin.h"
-#ifdef HAVE_OGG
+#ifdef HAVE_OGGVORBIS
+
+#include "_ogg_common.h"
#include "../utils.h"
#include "../audio.h"
@@ -99,7 +103,7 @@ long ogg_tell_cb(void * vdata) {
return (long)(data->inStream->offset);
}
-char * ogg_parseComment(char * comment, char * needle) {
+static inline char * ogg_parseComment(char * comment, char * needle) {
int len = strlen(needle);
if(strncasecmp(comment, needle, len) == 0 && *(comment+len) == '=') {
@@ -150,48 +154,40 @@ void ogg_getReplayGainInfo(char ** comments, ReplayGainInfo ** infoPtr) {
}
}
-MpdTag * oggCommentsParse(char ** comments) {
- MpdTag * ret = NULL;
- char * temp;
+static const char * VORBIS_COMMENT_TRACK_KEY = "tracknumber";
+
+static inline unsigned int ogg_parseCommentAddToTag(char * comment,
+ unsigned int itemType, MpdTag ** tag)
+{
+ const char * needle = (itemType == TAG_ITEM_TRACK) ?
+ VORBIS_COMMENT_TRACK_KEY : mpdTagItemKeys[itemType];
+ unsigned int len = strlen(needle);
+
+ if(strncasecmp(comment, needle, len) == 0 && *(comment+len) == '=') {
+ if (!*tag)
+ *tag = newMpdTag();
+
+ addItemToMpdTag(*tag, itemType, comment+len+1);
+
+ return 1;
+ }
+
+ return 0;
+}
+static MpdTag * oggCommentsParse(char ** comments) {
+ MpdTag * tag = NULL;
+
while(*comments) {
- if((temp = ogg_parseComment(*comments,"artist"))) {
- if(!ret) ret = newMpdTag();
- addItemToMpdTag(ret, TAG_ITEM_ARTIST, temp);
- }
- else if((temp = ogg_parseComment(*comments,"title"))) {
- if(!ret) ret = newMpdTag();
- addItemToMpdTag(ret, TAG_ITEM_TITLE, temp);
- }
- else if((temp = ogg_parseComment(*comments,"album"))) {
- if(!ret) ret = newMpdTag();
- addItemToMpdTag(ret, TAG_ITEM_ALBUM, temp);
- }
- else if((temp = ogg_parseComment(*comments,"tracknumber"))) {
- if(!ret) ret = newMpdTag();
- addItemToMpdTag(ret, TAG_ITEM_TRACK, temp);
- }
- else if((temp = ogg_parseComment(*comments,"genre"))) {
- if(!ret) ret = newMpdTag();
- addItemToMpdTag(ret, TAG_ITEM_GENRE, temp);
- }
- else if((temp = ogg_parseComment(*comments,"date"))) {
- if(!ret) ret = newMpdTag();
- addItemToMpdTag(ret, TAG_ITEM_DATE, temp);
- }
- else if((temp = ogg_parseComment(*comments,"composer"))) {
- if(!ret) ret = newMpdTag();
- addItemToMpdTag(ret, TAG_ITEM_COMPOSER, temp);
- }
- else if((temp = ogg_parseComment(*comments,"performer"))) {
- if(!ret) ret = newMpdTag();
- addItemToMpdTag(ret, TAG_ITEM_PERFORMER, temp);
+ unsigned int j;
+ for (j = TAG_NUM_OF_ITEM_TYPES; j--; ) {
+ if (ogg_parseCommentAddToTag(*comments, j, &tag))
+ break;
}
-
comments++;
}
-
- return ret;
+
+ return tag;
}
void putOggCommentsIntoOutputBuffer(OutputBuffer * cb, char * streamName,
@@ -220,7 +216,9 @@ void putOggCommentsIntoOutputBuffer(OutputBuffer * cb, char * streamName,
freeMpdTag(tag);
}
-int ogg_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream)
+/* public */
+int oggvorbis_decode(OutputBuffer * cb, DecoderControl * dc,
+ InputStream * inStream)
{
OggVorbis_File vf;
ov_callbacks callbacks;
@@ -360,7 +358,7 @@ int ogg_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream)
return 0;
}
-MpdTag * oggTagDup(char * file) {
+MpdTag * oggvorbis_TagDup(char * file) {
MpdTag * ret = NULL;
FILE * fp;
OggVorbis_File vf;
@@ -386,35 +384,43 @@ MpdTag * oggTagDup(char * file) {
return ret;
}
-char * oggSuffixes[] = {"ogg", NULL};
-char * oggMimeTypes[] = {"application/ogg", NULL};
+static unsigned int oggvorbis_try_decode(InputStream * inStream)
+{
+ return (ogg_stream_type_detect(inStream) == VORBIS) ? 1 : 0;
+}
+
-InputPlugin oggPlugin =
+static char * oggvorbis_Suffixes[] = {"ogg", NULL};
+static char * oggvorbis_MimeTypes[] = {"application/ogg", NULL};
+
+InputPlugin oggvorbisPlugin =
{
- "ogg",
+ "oggvorbis",
+ NULL,
NULL,
+ oggvorbis_try_decode,
+ oggvorbis_decode,
NULL,
- ogg_decode,
- NULL,
- oggTagDup,
- INPUT_PLUGIN_STREAM_URL | INPUT_PLUGIN_STREAM_FILE,
- oggSuffixes,
- oggMimeTypes
+ oggvorbis_TagDup,
+ INPUT_PLUGIN_STREAM_URL | INPUT_PLUGIN_STREAM_FILE,
+ oggvorbis_Suffixes,
+ oggvorbis_MimeTypes
};
-#else
+#else /* !HAVE_OGGVORBIS */
-InputPlugin oggPlugin =
+InputPlugin oggvorbisPlugin =
{
NULL,
NULL,
NULL,
- NULL,
- NULL,
- NULL,
- 0,
- NULL,
- NULL
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ NULL,
+ NULL,
};
-#endif
+#endif /* HAVE_OGGVORBIS */