some more cleanups

git-svn-id: https://svn.musicpd.org/mpd/trunk@60 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-02-25 21:10:56 +00:00
parent e1c839cd56
commit 8edc416344
11 changed files with 36 additions and 33 deletions

View File

@ -115,7 +115,7 @@ int audiofile_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
++cb->end; ++cb->end;
if(cb->end>=BUFFERED_CHUNKS) { if(cb->end>=buffered_chunks) {
cb->end = 0; cb->end = 0;
cb->wrap = 1; cb->wrap = 1;
} }

View File

@ -216,13 +216,16 @@ char ** readConf(char * file) {
conf_params[conf_absolutePaths[i]]); conf_params[conf_absolutePaths[i]]);
exit(-1); exit(-1);
} }
/* Parse ~ in path */
else if(conf_params[conf_absolutePaths[i]] && else if(conf_params[conf_absolutePaths[i]] &&
conf_params[conf_absolutePaths[i]][0]=='~') conf_params[conf_absolutePaths[i]][0]=='~')
{ {
struct passwd * pwd = NULL; struct passwd * pwd = NULL;
char * path; char * path;
int pos = 1; int pos = 1;
if(conf_params[conf_absolutePaths[i]][1]=='/') { if(conf_params[conf_absolutePaths[i]][1]=='/' ||
conf_params[conf_absolutePaths[i]][1]=='\0')
{
uid_t uid = geteuid(); uid_t uid = geteuid();
if((pwd = getpwuid(uid)) == NULL) { if((pwd = getpwuid(uid)) == NULL) {
ERROR("problems getting passwd entry " ERROR("problems getting passwd entry "
@ -251,7 +254,7 @@ char ** readConf(char * file) {
if(foundSlash) *ch = '/'; if(foundSlash) *ch = '/';
} }
path = malloc(strlen(pwd->pw_dir)+strlen( path = malloc(strlen(pwd->pw_dir)+strlen(
&(conf_params[conf_absolutePaths[i]][pos]))); &(conf_params[conf_absolutePaths[i]][pos]))+1);
strcpy(path,pwd->pw_dir); strcpy(path,pwd->pw_dir);
strcat(path,&(conf_params[conf_absolutePaths[i]][pos])); strcat(path,&(conf_params[conf_absolutePaths[i]][pos]));
free(conf_params[conf_absolutePaths[i]]); free(conf_params[conf_absolutePaths[i]]);

View File

@ -93,8 +93,8 @@ int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) {
chunks = (af->sampleRate*af->bits*af->channels/8.0/CHUNK_SIZE); chunks = (af->sampleRate*af->bits*af->channels/8.0/CHUNK_SIZE);
chunks = (chunks*pc->crossFade+0.5); chunks = (chunks*pc->crossFade+0.5);
if(chunks>(BUFFERED_CHUNKS-buffered_before_play)) { if(chunks>(buffered_chunks-buffered_before_play)) {
chunks = BUFFERED_CHUNKS-buffered_before_play; chunks = buffered_chunks-buffered_before_play;
} }
if(chunks<0) chunks = 0; if(chunks<0) chunks = 0;
@ -338,19 +338,19 @@ void decode() {
<=crossFadeChunks) || <=crossFadeChunks) ||
(cb->begin>cb->next && (cb->begin>cb->next &&
(fadePosition=cb->next-cb->begin+ (fadePosition=cb->next-cb->begin+
BUFFERED_CHUNKS)<=crossFadeChunks))) buffered_chunks)<=crossFadeChunks)))
{ {
if(nextChunk<0) { if(nextChunk<0) {
crossFadeChunks = fadePosition; crossFadeChunks = fadePosition;
} }
nextChunk = cb->begin+crossFadeChunks; nextChunk = cb->begin+crossFadeChunks;
test = cb->end; test = cb->end;
if(cb->wrap) test+=BUFFERED_CHUNKS; if(cb->wrap) test+=buffered_chunks;
if(nextChunk<test) { if(nextChunk<test) {
if(nextChunk>=BUFFERED_CHUNKS) if(nextChunk>=buffered_chunks)
{ {
nextChunk-= nextChunk-=
BUFFERED_CHUNKS; buffered_chunks;
} }
pcm_mix(cb->chunks+cb->begin* pcm_mix(cb->chunks+cb->begin*
CHUNK_SIZE, CHUNK_SIZE,
@ -393,7 +393,7 @@ void decode() {
playAudio(cb->chunks+cb->begin*CHUNK_SIZE, playAudio(cb->chunks+cb->begin*CHUNK_SIZE,
cb->chunkSize[cb->begin]); cb->chunkSize[cb->begin]);
cb->begin++; cb->begin++;
if(cb->begin>=BUFFERED_CHUNKS) { if(cb->begin>=buffered_chunks) {
cb->begin = 0; cb->begin = 0;
cb->wrap = 0; cb->wrap = 0;
} }
@ -404,12 +404,12 @@ void decode() {
if(doCrossFade==1 && nextChunk>=0) { if(doCrossFade==1 && nextChunk>=0) {
nextChunk = cb->begin+crossFadeChunks; nextChunk = cb->begin+crossFadeChunks;
test = cb->end; test = cb->end;
if(cb->wrap) test+=BUFFERED_CHUNKS; if(cb->wrap) test+=buffered_chunks;
if(nextChunk<test) { if(nextChunk<test) {
if(nextChunk>=BUFFERED_CHUNKS) if(nextChunk>=buffered_chunks)
{ {
nextChunk-= nextChunk-=
BUFFERED_CHUNKS; buffered_chunks;
} }
cb->begin = nextChunk; cb->begin = nextChunk;
} }

View File

@ -192,7 +192,7 @@ int flacSendChunk(FlacData * data) {
data->cb->bitRate[data->cb->end] = 0; data->cb->bitRate[data->cb->end] = 0;
data->cb->end++; data->cb->end++;
if(data->cb->end>=BUFFERED_CHUNKS) { if(data->cb->end>=buffered_chunks) {
data->cb->end = 0; data->cb->end = 0;
data->cb->wrap = 1; data->cb->wrap = 1;
} }

View File

@ -32,7 +32,7 @@
#include <stdlib.h> #include <stdlib.h>
char * dupAndStripPlaylistSuffix(char * file) { char * dupAndStripPlaylistSuffix(char * file) {
int size = strlen(file)-strlen(PLAYLIST_FILE_SUFFIX)-1; size_t size = strlen(file)-strlen(PLAYLIST_FILE_SUFFIX)-1;
char * ret = malloc(size+1); char * ret = malloc(size+1);
strncpy(ret,file,size); strncpy(ret,file,size);

View File

@ -374,7 +374,7 @@ int mp3ChildSendData(mp3DecodeData * data, Buffer * cb, DecoderControl * dc) {
cb->times[cb->end] = data->elapsedTime; cb->times[cb->end] = data->elapsedTime;
cb->end++; cb->end++;
if(cb->end>=BUFFERED_CHUNKS) { if(cb->end>=buffered_chunks) {
cb->end = 0; cb->end = 0;
cb->wrap = 1; cb->wrap = 1;
} }

View File

@ -97,7 +97,7 @@ int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
} }
cb->bitRate[cb->end] = bitRate; cb->bitRate[cb->end] = bitRate;
cb->end++; cb->end++;
if(cb->end>=BUFFERED_CHUNKS) { if(cb->end>=buffered_chunks) {
cb->end = 0; cb->end = 0;
cb->wrap = 1; cb->wrap = 1;
} }

View File

@ -134,7 +134,7 @@ char * rmp2amp(char * relativePath) {
memset(absolutePath,0,MAXPATHLEN+1); memset(absolutePath,0,MAXPATHLEN+1);
strcpy(absolutePath,musicDir); strncpy(absolutePath,musicDir,MAXPATHLEN);
strncat(absolutePath,relativePath,MAXPATHLEN-strlen(musicDir)); strncat(absolutePath,relativePath,MAXPATHLEN-strlen(musicDir));
return absolutePath; return absolutePath;
@ -145,7 +145,7 @@ char * rpp2app(char * relativePath) {
memset(absolutePath,0,MAXPATHLEN+1); memset(absolutePath,0,MAXPATHLEN+1);
strcpy(absolutePath,playlistDir); strncpy(absolutePath,playlistDir,MAXPATHLEN);
strncat(absolutePath,relativePath,MAXPATHLEN-strlen(musicDir)); strncat(absolutePath,relativePath,MAXPATHLEN-strlen(musicDir));
return absolutePath; return absolutePath;

View File

@ -28,7 +28,7 @@
#include <string.h> #include <string.h>
int buffered_before_play; int buffered_before_play;
int BUFFERED_CHUNKS; int buffered_chunks;
PlayerData * playerData_pd; PlayerData * playerData_pd;
@ -49,7 +49,7 @@ void initPlayerData() {
} }
bufferSize*=1024; bufferSize*=1024;
BUFFERED_CHUNKS = bufferSize/CHUNK_SIZE; buffered_chunks = bufferSize/CHUNK_SIZE;
perc = strtod((getConf())[CONF_BUFFER_BEFORE_PLAY],&test); perc = strtod((getConf())[CONF_BUFFER_BEFORE_PLAY],&test);
if(*test!='%' || perc<0 || perc>100) { if(*test!='%' || perc<0 || perc>100) {
@ -58,16 +58,16 @@ void initPlayerData() {
(getConf())[CONF_BUFFER_BEFORE_PLAY]); (getConf())[CONF_BUFFER_BEFORE_PLAY]);
exit(-1); exit(-1);
} }
buffered_before_play = (perc/100)*BUFFERED_CHUNKS; buffered_before_play = (perc/100)*buffered_chunks;
if(buffered_before_play>BUFFERED_CHUNKS) { if(buffered_before_play>buffered_chunks) {
buffered_before_play = BUFFERED_CHUNKS; buffered_before_play = buffered_chunks;
} }
else if(buffered_before_play<0) buffered_before_play = 0; else if(buffered_before_play<0) buffered_before_play = 0;
allocationSize = BUFFERED_CHUNKS*CHUNK_SIZE; /*actual buffer*/ allocationSize = buffered_chunks*CHUNK_SIZE; /*actual buffer*/
allocationSize+= BUFFERED_CHUNKS*sizeof(float); /*for times*/ allocationSize+= buffered_chunks*sizeof(float); /*for times*/
allocationSize+= BUFFERED_CHUNKS*sizeof(mpd_sint16); /*for chunkSize*/ allocationSize+= buffered_chunks*sizeof(mpd_sint16); /*for chunkSize*/
allocationSize+= BUFFERED_CHUNKS*sizeof(mpd_sint16); /*for bitRate*/ allocationSize+= buffered_chunks*sizeof(mpd_sint16); /*for bitRate*/
allocationSize+= sizeof(PlayerData); /*for playerData struct*/ allocationSize+= sizeof(PlayerData); /*for playerData struct*/
if((shmid = shmget(IPC_PRIVATE,allocationSize,IPC_CREAT|0600))<0) { if((shmid = shmget(IPC_PRIVATE,allocationSize,IPC_CREAT|0600))<0) {
@ -87,11 +87,11 @@ void initPlayerData() {
buffer->chunks = ((char *)playerData_pd)+sizeof(PlayerData); buffer->chunks = ((char *)playerData_pd)+sizeof(PlayerData);
buffer->chunkSize = (mpd_sint16 *)(((char *)buffer->chunks)+ buffer->chunkSize = (mpd_sint16 *)(((char *)buffer->chunks)+
BUFFERED_CHUNKS*CHUNK_SIZE); buffered_chunks*CHUNK_SIZE);
buffer->bitRate = (mpd_sint16 *)(((char *)buffer->chunkSize)+ buffer->bitRate = (mpd_sint16 *)(((char *)buffer->chunkSize)+
BUFFERED_CHUNKS*sizeof(mpd_sint16)); buffered_chunks*sizeof(mpd_sint16));
buffer->times = (float *)(((char *)buffer->bitRate)+ buffer->times = (float *)(((char *)buffer->bitRate)+
BUFFERED_CHUNKS*sizeof(mpd_sint16)); buffered_chunks*sizeof(mpd_sint16));
playerData_pd->playerControl.stop = 0; playerData_pd->playerControl.stop = 0;
playerData_pd->playerControl.pause = 0; playerData_pd->playerControl.pause = 0;

View File

@ -27,7 +27,7 @@
#define CHUNK_SIZE 1024 #define CHUNK_SIZE 1024
extern int buffered_before_play; extern int buffered_before_play;
extern int BUFFERED_CHUNKS; extern int buffered_chunks;
typedef struct _Buffer { typedef struct _Buffer {
char * chunks; char * chunks;

View File

@ -130,7 +130,7 @@ void initPlaylist() {
playlist.songs = malloc(sizeof(Song *)*playlist_max_length); playlist.songs = malloc(sizeof(Song *)*playlist_max_length);
playlist.order = malloc(sizeof(Song *)*playlist_max_length); playlist.order = malloc(sizeof(Song *)*playlist_max_length);
memset(playlist.songs,(int)NULL,sizeof(char *)*playlist_max_length); memset(playlist.songs,0,sizeof(char *)*playlist_max_length);
srand(time(NULL)); srand(time(NULL));