diff options
author | Eric Wong <normalperson@yhbt.net> | 2006-03-01 09:43:28 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2006-03-01 09:43:28 +0000 |
commit | 17d3ccbaa3f22c4c0f8a86515d71fc017a451bbd (patch) | |
tree | 5b7ff5d88f84effddf3a93cad6e79e690c5844c6 /src | |
parent | b08ab529940b9af125b9292e6866af10d7a8ae32 (diff) | |
download | mpd-17d3ccbaa3f22c4c0f8a86515d71fc017a451bbd.tar.gz mpd-17d3ccbaa3f22c4c0f8a86515d71fc017a451bbd.tar.xz mpd-17d3ccbaa3f22c4c0f8a86515d71fc017a451bbd.zip |
Merge trunk up to r3859 into oggflac
git-svn-id: https://svn.musicpd.org/mpd/branches/oggflac@3908 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r-- | src/charConv.c | 15 | ||||
-rw-r--r-- | src/command.c | 2 | ||||
-rw-r--r-- | src/inputPlugins/mp3_plugin.c | 85 |
3 files changed, 72 insertions, 30 deletions
diff --git a/src/charConv.c b/src/charConv.c index b12bfb751..2ca786668 100644 --- a/src/charConv.c +++ b/src/charConv.c @@ -42,17 +42,10 @@ mpd_sint8 char_conv_latin1ToUtf8 = 0; #define BUFFER_SIZE 1024 int setCharSetConversion(char * to, char * from) { - if(char_conv_to && char_conv_from) { - if (strcmp(from,char_conv_to)==0 && - strcmp(to,char_conv_from)==0) { - char * swap = char_conv_from; - char_conv_from = char_conv_to; - char_conv_to = swap; - return 0; - } else if (strcmp(to,char_conv_to)==0 && - strcmp(from,char_conv_from)==0) { - return 0; - } + if(char_conv_to && char_conv_from && + strcmp(to,char_conv_to)==0 && strcmp(from,char_conv_from)==0) + { + return 0; } closeCharSetConversion(); diff --git a/src/command.c b/src/command.c index 7963dc9de..0179f9865 100644 --- a/src/command.c +++ b/src/command.c @@ -921,7 +921,7 @@ void initCommands() { addCommand(COMMAND_KILL ,PERMISSION_ADMIN, -1,-1,handleKill,NULL); addCommand(COMMAND_CLOSE ,0, -1,-1,handleClose,NULL); addCommand(COMMAND_ADD ,PERMISSION_ADD, 1, 1,handleAdd,NULL); - addCommand(COMMAND_ADDID ,PERMISSION_ADD, 0, 1,handleAddId,NULL); + addCommand(COMMAND_ADDID ,PERMISSION_ADD, 1, 1,handleAddId,NULL); addCommand(COMMAND_DELETE ,PERMISSION_CONTROL, 1, 1,handleDelete,NULL); addCommand(COMMAND_DELETEID ,PERMISSION_CONTROL, 1, 1,handleDeleteId,NULL); addCommand(COMMAND_PLAYLIST ,PERMISSION_READ, 0, 0,handlePlaylist,NULL); diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c index dd7ceb767..8a73ed85d 100644 --- a/src/inputPlugins/mp3_plugin.c +++ b/src/inputPlugins/mp3_plugin.c @@ -35,9 +35,11 @@ #endif #include "../log.h" #include "../utils.h" +#include "../replayGain.h" #include "../tag.h" #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> @@ -207,13 +209,58 @@ int fillMp3InputBuffer(mp3DecodeData * data) { } #ifdef HAVE_ID3TAG -static MpdTag * mp3_parseId3Tag(mp3DecodeData * data, signed long tagsize) { - MpdTag * ret = NULL; +void mp3_getReplayGainInfo(struct id3_tag * tag, ReplayGainInfo ** infoPtr) { + int i; + char * key; + char * value; + struct id3_frame * frame; + int found = 0; + + if(*infoPtr) freeReplayGainInfo(*infoPtr); + *infoPtr = newReplayGainInfo(); + + for(i=0;(frame = id3_tag_findframe(tag, "TXXX", i));i++) { + if(frame->nfields < 3) continue; + + key = (char *) id3_ucs4_latin1duplicate(id3_field_getstring(&frame->fields[1])); + value = (char *) id3_ucs4_latin1duplicate(id3_field_getstring(&frame->fields[2])); + + if(strcmp(key, "replaygain_track_gain") == 0) { + (*infoPtr)->trackGain = atof(value); + found = 1; + } + else if(strcmp(key, "replaygain_album_gain") == 0) { + (*infoPtr)->albumGain = atof(value); + found = 1; + } + else if(strcmp(key, "replaygain_track_peak") == 0) { + (*infoPtr)->trackPeak = atof(value); + found = 1; + } + else if(strcmp(key, "replaygain_album_peak") == 0) { + (*infoPtr)->albumPeak = atof(value); + found = 1; + } + + free(key); + free(value); + + } + + if(!found) { + freeReplayGainInfo(*infoPtr); + *infoPtr = NULL; + } +} + +static void mp3_parseId3Tag(mp3DecodeData * data, signed long tagsize, MpdTag ** mpdTag, ReplayGainInfo ** replayGainInfo) { struct id3_tag * id3Tag = NULL; id3_length_t count; id3_byte_t const *id3_data; id3_byte_t * allocated = NULL; + if(mpdTag) *mpdTag = NULL; + count = data->stream.bufend - data->stream.this_frame; if(tagsize <= count) { @@ -251,17 +298,17 @@ static MpdTag * mp3_parseId3Tag(mp3DecodeData * data, signed long tagsize) { id3Tag = id3_tag_parse(id3_data, tagsize); if(id3Tag) { - ret = parseId3Tag(id3Tag); + if(mpdTag) *mpdTag = parseId3Tag(id3Tag); + if(replayGainInfo) mp3_getReplayGainInfo(id3Tag, replayGainInfo); id3_tag_delete(id3Tag); } fail: if(allocated) free(allocated); - return ret; } #endif -int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag) { +int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag, ReplayGainInfo ** replayGainInfo) { if((data->stream).buffer==NULL || (data->stream).error==MAD_ERROR_BUFLEN) { if(fillMp3InputBuffer(data) < 0) { return DECODE_BREAK; @@ -279,8 +326,7 @@ int decodeNextFrameHeader(mp3DecodeData * data, MpdTag ** tag) { if(tagsize>0) { if(tag && !(*tag)) { - *tag = mp3_parseId3Tag(data, tagsize); - + mp3_parseId3Tag(data, tagsize, tag, replayGainInfo); } else { mad_stream_skip(&(data->stream), @@ -408,7 +454,7 @@ fail: } int decodeFirstFrame(mp3DecodeData * data, DecoderControl * dc, - MpdTag ** tag) + MpdTag ** tag, ReplayGainInfo ** replayGainInfo) { struct xing xing; int ret; @@ -419,7 +465,7 @@ int decodeFirstFrame(mp3DecodeData * data, DecoderControl * dc, while(1) { skip = 0; - while((ret = decodeNextFrameHeader(data, tag))==DECODE_CONT && + while((ret = decodeNextFrameHeader(data, tag, replayGainInfo))==DECODE_CONT && (!dc || !dc->stop)); if(ret==DECODE_SKIP) skip = 1; else if(ret==DECODE_BREAK || (dc && dc->stop)) return -1; @@ -485,7 +531,7 @@ int getMp3TotalTime(char * file) { if(openInputStream(&inStream, file) < 0) return -1; initMp3DecodeData(&data,&inStream); - if(decodeFirstFrame(&data, NULL, NULL)<0) ret = -1; + if(decodeFirstFrame(&data, NULL, NULL,NULL)<0) ret = -1; else ret = data.totalTime+0.5; mp3DecodeDataFinalize(&data); closeInputStream(&inStream); @@ -494,11 +540,11 @@ int getMp3TotalTime(char * file) { } int openMp3FromInputStream(InputStream * inStream, mp3DecodeData * data, - DecoderControl * dc, MpdTag ** tag) + DecoderControl * dc, MpdTag ** tag, ReplayGainInfo ** replayGainInfo) { initMp3DecodeData(data, inStream); *tag = NULL; - if(decodeFirstFrame(data, dc, tag)<0) { + if(decodeFirstFrame(data, dc, tag, replayGainInfo)<0) { mp3DecodeDataFinalize(data); if(tag && *tag) freeMpdTag(*tag); return -1; @@ -507,7 +553,7 @@ int openMp3FromInputStream(InputStream * inStream, mp3DecodeData * data, return 0; } -int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) { +int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc, ReplayGainInfo ** replayGainInfo) { int i; int ret; int skip; @@ -593,7 +639,7 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) { data->outputBuffer, data->elapsedTime, data->bitRate/1000, - NULL); + (replayGainInfo != NULL) ? *replayGainInfo : NULL); if(ret == OUTPUT_BUFFER_DC_STOP) { data->flush = 0; return DECODE_BREAK; @@ -635,7 +681,7 @@ int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) { while(1) { skip = 0; - while((ret = decodeNextFrameHeader(data, NULL))==DECODE_CONT && + while((ret = decodeNextFrameHeader(data, NULL, replayGainInfo))==DECODE_CONT && !dc->stop && !dc->seek); if(ret==DECODE_BREAK || dc->stop || dc->seek) break; else if(ret==DECODE_SKIP) skip = 1; @@ -661,8 +707,9 @@ void initAudioFormatFromMp3DecodeData(mp3DecodeData * data, AudioFormat * af) { int mp3_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream) { mp3DecodeData data; MpdTag * tag = NULL; + ReplayGainInfo * replayGainInfo = NULL; - if(openMp3FromInputStream(inStream, &data, dc, &tag) < 0) { + if(openMp3FromInputStream(inStream, &data, dc, &tag, &replayGainInfo) < 0) { closeInputStream(inStream); if(!dc->stop) { ERROR("Input does not appear to be a mp3 bit stream.\n"); @@ -714,7 +761,7 @@ int mp3_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream) { dc->state = DECODE_STATE_DECODE; - while(mp3Read(&data,cb,dc)!=DECODE_BREAK); + while(mp3Read(&data,cb,dc, &replayGainInfo)!=DECODE_BREAK); /* send last little bit if not dc->stop */ if(!dc->stop && data.outputPtr!=data.outputBuffer && data.flush) { sendDataToOutputBuffer(cb, NULL, dc, @@ -722,9 +769,11 @@ int mp3_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream) { data.outputBuffer, data.outputPtr-data.outputBuffer, data.elapsedTime,data.bitRate/1000, - NULL); + replayGainInfo); } + if (replayGainInfo) freeReplayGainInfo(replayGainInfo); + closeInputStream(inStream); if(dc->seek && data.muteFrame == MUTEFRAME_SEEK) { |