will compile if you manually add "HAVE_MUSEPACK" to config.h and -lmusepack to

MPD_LIBS in Makefile

git-svn-id: https://svn.musicpd.org/mpd/trunk@2919 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2005-02-01 03:20:16 +00:00
parent 9c218e487d
commit e02659f6c0
3 changed files with 102 additions and 77 deletions

View File

@ -13,6 +13,7 @@ mpd_inputPlugins = \
inputPlugins/mod_plugin.c \ inputPlugins/mod_plugin.c \
inputPlugins/mp3_plugin.c \ inputPlugins/mp3_plugin.c \
inputPlugins/mp4_plugin.c \ inputPlugins/mp4_plugin.c \
inputPlugins/mpc_plugin.c \
inputPlugins/ogg_plugin.c inputPlugins/ogg_plugin.c

View File

@ -113,6 +113,7 @@ extern InputPlugin oggPlugin;
extern InputPlugin flacPlugin; extern InputPlugin flacPlugin;
extern InputPlugin audiofilePlugin; extern InputPlugin audiofilePlugin;
extern InputPlugin mp4Plugin; extern InputPlugin mp4Plugin;
extern InputPlugin mpcPlugin;
extern InputPlugin aacPlugin; extern InputPlugin aacPlugin;
extern InputPlugin modPlugin; extern InputPlugin modPlugin;
@ -125,6 +126,7 @@ void initInputPlugins() {
loadInputPlugin(&flacPlugin); loadInputPlugin(&flacPlugin);
loadInputPlugin(&audiofilePlugin); loadInputPlugin(&audiofilePlugin);
loadInputPlugin(&mp4Plugin); loadInputPlugin(&mp4Plugin);
loadInputPlugin(&mpcPlugin);
loadInputPlugin(&modPlugin); loadInputPlugin(&modPlugin);
} }

View File

@ -18,7 +18,7 @@
#include "../inputPlugin.h" #include "../inputPlugin.h"
#ifdef HAVE_MPC #ifdef HAVE_MUSEPACK
#include "../utils.h" #include "../utils.h"
#include "../audio.h" #include "../audio.h"
@ -41,14 +41,14 @@ typedef struct _MpcCallbackData {
/* this is just for tag parsing for db import! */ /* this is just for tag parsing for db import! */
int getMpcTotalTime(char * file) { int getMpcTotalTime(char * file) {
int totalTime = 0 int totalTime = 0;
return totalTime; return totalTime;
} }
mpc_int32_t mpc_read_cb(void * vdata, void * ptr, size_t size) { mpc_int32_t mpc_read_cb(void * vdata, void * ptr, mpc_int32_t size) {
mpc_int32_t ret = 0; mpc_int32_t ret = 0;
OggCallbackData * data = (OggCallbackData *)vdata; MpcCallbackData * data = (MpcCallbackData *)vdata;
while(1) { while(1) {
ret = readFromInputStream(data->inStream, ptr, size, 1); ret = readFromInputStream(data->inStream, ptr, size, 1);
@ -63,32 +63,59 @@ mpc_int32_t mpc_read_cb(void * vdata, void * ptr, size_t size) {
return ret; return ret;
} }
static mpc_bool_t ogg_seek_cb(void * vdata, ogg_int64_t offset) { static mpc_bool_t mpc_seek_cb(void * vdata, mpc_int32_t offset) {
OggCallbackData * data = (OggCallbackData *)vdata; MpcCallbackData * data = (MpcCallbackData *)vdata;
return data->inStream->seekable ? return !seekInputStream(data->inStream , offset, SEEK_SET);
!seekInputStream(data->inStream , offset, SEEK_SET) :
false;
} }
mpd_int32_t mpc_tell_cb(void * vdata) { mpc_int32_t mpc_tell_cb(void * vdata) {
OggCallbackData * data = (OggCallbackData *)vdata; MpcCallbackData * data = (MpcCallbackData *)vdata;
return (long)(data->inStream->offset); return (long)(data->inStream->offset);
} }
mpc_bool_t mpc_canseek_cb(void * vdata) { mpc_bool_t mpc_canseek_cb(void * vdata) {
OggCallbackData * data = (OggCallbackData *)vdata; MpcCallbackData * data = (MpcCallbackData *)vdata;
return data->inStream->seekable; return data->inStream->seekable;
} }
mpc_int32_t mpc_getsize_cb(void * vdata) { mpc_int32_t mpc_getsize_cb(void * vdata) {
OggCallbackData * data = (OggCallbackData *)vdata; MpcCallbackData * data = (MpcCallbackData *)vdata;
return data->inStream->size; return data->inStream->size;
} }
inline mpd_sint16 convertSample(MPC_SAMPLE_FORMAT sample) {
/* only doing 16-bit audio for now */
mpd_sint32 val;
const int clip_min = -1 << (16 - 1);
const int clip_max = (1 << (16 - 1)) - 1;
#ifdef MPC_FIXED_POINT
const int shift = 16 - MPC_FIXED_POINT_SCALE_SHIFT;
if( ssample > 0 ) {
sample <<= shift;
}
else if ( shift < 0 ) {
sample >>= -shift;
}
val = sample;
#else
const int float_scale = 1 << (16 - 1);
val = sample * float_scale;
#endif
if( val < clip_min) val = clip_min;
else if ( val > clip_max ) val = clip_max;
return val;
}
int mpc_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream) int mpc_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream)
{ {
mpc_decoder decoder; mpc_decoder decoder;
@ -96,8 +123,8 @@ int mpc_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream)
mpc_streaminfo info; mpc_streaminfo info;
MpcCallbackData data; MpcCallbackData data;
data.inStream = inStream;
data.dc = dc; MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH];
int eof = 0; int eof = 0;
long ret; long ret;
@ -105,7 +132,12 @@ int mpc_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream)
char chunk[MPC_CHUNK_SIZE]; char chunk[MPC_CHUNK_SIZE];
int chunkpos = 0; int chunkpos = 0;
long bitRate = 0; long bitRate = 0;
char ** comments; mpd_sint16 * s16 = (mpd_sint16 *) chunk;
unsigned long samplePos = 0;
mpc_uint32_t vbrUpdateAcc;
mpc_uint32_t vbrUpdateBits;
float time;
int i;
data.inStream = inStream; data.inStream = inStream;
data.dc = dc; data.dc = dc;
@ -143,75 +175,72 @@ int mpc_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream)
} }
} }
dc->totalTime = 0; dc->totalTime = mpc_streaminfo_get_length(&info);
dc->audioFormat.bits = 16; dc->audioFormat.bits = 16;
dc->audioFormat.sampleRate = info.sample_freq;
while(!eof) { while(!eof) {
if(dc->seek) { if(dc->seek) {
if(0 == ov_time_seek_page(&vf,dc->seekWhere)) { samplePos = dc->seekWhere * dc->audioFormat.sampleRate;
if(0 == mpc_decoder_seek_sample(&decoder, samplePos)) {
clearOutputBuffer(cb); clearOutputBuffer(cb);
chunkpos = 0; chunkpos = 0;
} }
else dc->seekError = 1; else dc->seekError = 1;
dc->seek = 0; dc->seek = 0;
} }
ret = ov_read(&vf, chunk+chunkpos, ret = mpc_decoder_decode(&decoder, sample_buffer,
OGG_CHUNK_SIZE-chunkpos, &vbrUpdateAcc, &vbrUpdateBits);
OGG_DECODE_USE_BIGENDIAN,
2, 1, &current_section);
if(current_section!=prev_section) { if(ret <= 0 ) {
/*printf("new song!\n");*/
vorbis_info *vi=ov_info(&vf,-1);
dc->audioFormat.channels = vi->channels;
dc->audioFormat.sampleRate = vi->rate;
if(dc->state == DECODE_STATE_START) {
getOutputAudioFormat(&(dc->audioFormat),
&(cb->audioFormat));
dc->state = DECODE_STATE_DECODE;
}
comments = ov_comment(&vf, -1)->user_comments;
putOggCommentsIntoOutputBuffer(cb, inStream->metaName,
comments);
ogg_getReplayGainInfo(comments, &replayGainInfo);
}
prev_section = current_section;
if(ret <= 0 && ret != OV_HOLE) {
eof = 1; eof = 1;
break; break;
} }
if(ret == OV_HOLE) ret = 0;
chunkpos+=ret; samplePos += ret;
if(chunkpos >= OGG_CHUNK_SIZE) { /* ret is in samples, and we have stereo */
if((test = ov_bitrate_instant(&vf))>0) { ret *= 2;
bitRate = test/1000;
} for(i = 0; i < ret; i++) {
sendDataToOutputBuffer(cb, inStream, dc, /* 16 bit audio again */
*s16 = convertSample(sample_buffer[i]);
chunkpos += 2;
s16++;
if(chunkpos >= MPC_CHUNK_SIZE) {
time = ((float)samplePos) /
dc->audioFormat.sampleRate;
bitRate = vbrUpdateBits *
dc->audioFormat.sampleRate /
(MPC_CHUNK_SIZE);
sendDataToOutputBuffer(cb, inStream, dc,
inStream->seekable, inStream->seekable,
chunk, chunkpos, chunk, chunkpos,
ov_pcm_tell(&vf)/ time,
dc->audioFormat.sampleRate,
bitRate, bitRate,
replayGainInfo); NULL);
chunkpos = 0; chunkpos = 0;
if(dc->stop) break; s16 = (mpd_sint16 *)chunk;
if(dc->stop) break;
}
} }
} }
if(!dc->stop && chunkpos > 0) { if(!dc->stop && chunkpos > 0) {
time = ((float)samplePos) / dc->audioFormat.sampleRate;
bitRate = vbrUpdateBits * dc->audioFormat.sampleRate /
chunkpos;
sendDataToOutputBuffer(cb, NULL, dc, inStream->seekable, sendDataToOutputBuffer(cb, NULL, dc, inStream->seekable,
chunk, chunkpos, chunk, chunkpos, time, bitRate, NULL);
ov_time_tell(&vf), bitRate, replayGainInfo);
} }
if(replayGainInfo) freeReplayGainInfo(replayGainInfo); closeInputStream(inStream);
ov_clear(&vf);
flushOutputBuffer(cb); flushOutputBuffer(cb);
@ -224,47 +253,40 @@ int mpc_decode(OutputBuffer * cb, DecoderControl * dc, InputStream * inStream)
return 0; return 0;
} }
MpdTag * oggTagDup(char * file) { MpdTag * mpcTagDup(char * file) {
MpdTag * ret = NULL; MpdTag * ret = NULL;
FILE * fp; FILE * fp;
OggVorbis_File vf;
fp = fopen(file,"r"); fp = fopen(file,"r");
if(!fp) return NULL; if(!fp) return NULL;
if(ov_open(fp,&vf,NULL,0)<0) {
fclose(fp);
return NULL;
}
ret = oggCommentsParse(ov_comment(&vf,-1)->user_comments); /* get tag info here */
if(!ret) ret = newMpdTag(); if(!ret) ret = newMpdTag();
ret->time = (int)(ov_time_total(&vf,-1)+0.5); ret->time = getMpcTotalTime(file);
ov_clear(&vf);
return ret; return ret;
} }
char * oggSuffixes[] = {"ogg", NULL}; char * mpcSuffixes[] = {"mpc", NULL};
char * oggMimeTypes[] = {"application/ogg", NULL}; char * mpcMimeTypes[] = {NULL};
InputPlugin oggPlugin = InputPlugin mpcPlugin =
{ {
"ogg", "mpc",
NULL, NULL,
NULL, NULL,
ogg_decode, mpc_decode,
NULL, NULL,
oggTagDup, mpcTagDup,
INPUT_PLUGIN_STREAM_URL | INPUT_PLUGIN_STREAM_FILE, INPUT_PLUGIN_STREAM_URL | INPUT_PLUGIN_STREAM_FILE,
oggSuffixes, mpcSuffixes,
oggMimeTypes mpcMimeTypes
}; };
#else #else
InputPlugin oggPlugin = InputPlugin mpcPlugin =
{ {
NULL, NULL,
NULL, NULL,