diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-04-12 04:08:29 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-04-12 04:08:29 +0000 |
commit | efa464235613c6f3bfd40179d3676dd913feeafe (patch) | |
tree | dd1399ff950fff7be918a0487da95896c2819868 /src | |
parent | b3230404892539192be974e632c63a5d5548f735 (diff) | |
download | mpd-efa464235613c6f3bfd40179d3676dd913feeafe.tar.gz mpd-efa464235613c6f3bfd40179d3676dd913feeafe.tar.xz mpd-efa464235613c6f3bfd40179d3676dd913feeafe.zip |
Start using song pointers in core data structures
Instead of copying URLs everywhere...
[merged r7186 from branches/ew]
git-svn-id: https://svn.musicpd.org/mpd/trunk@7244 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/decode.c | 66 | ||||
-rw-r--r-- | src/decode.h | 3 | ||||
-rw-r--r-- | src/player.c | 38 | ||||
-rw-r--r-- | src/player.h | 5 | ||||
-rw-r--r-- | src/playerData.c | 7 |
5 files changed, 53 insertions, 66 deletions
diff --git a/src/decode.c b/src/decode.c index b1cce7fac..1b60b95d2 100644 --- a/src/decode.c +++ b/src/decode.c @@ -103,9 +103,12 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) { \ decodeWaitedOn = 0; \ if(openAudioDevice(&(cb->audioFormat))<0) { \ - pathcpy_trunc(pc->erroredUrl, pc->utf8url); \ + char tmp[MPD_PATH_MAX]; \ + pc->errored_song = pc->current_song; \ pc->error = PLAYER_ERROR_AUDIO; \ - ERROR("problems opening audio device while playing \"%s\"\n", pc->utf8url); \ + ERROR("problems opening audio device " \ + "while playing \"%s\"\n", \ + get_song_url(tmp, pc->current_song)); \ quitDecode(pc,dc); \ return; \ } else { \ @@ -124,7 +127,7 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) cb->audioFormat.sampleRate; \ } \ else if(dc->state!=DECODE_STATE_START) { \ - pathcpy_trunc(pc->erroredUrl, pc->utf8url); \ + pc->errored_song = pc->current_song; \ pc->error = PLAYER_ERROR_FILE; \ quitDecode(pc,dc); \ return; \ @@ -138,13 +141,11 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) static int waitOnDecode(PlayerControl * pc, DecoderControl * dc, OutputBuffer * cb, int *decodeWaitedOn) { - pathcpy_trunc(pc->currentUrl, pc->utf8url); - while (dc->start) player_wakeup_decoder(); if (dc->start || dc->error != DECODE_ERROR_NOERROR) { - pathcpy_trunc(pc->erroredUrl, pc->utf8url); + pc->errored_song = pc->current_song; pc->error = PLAYER_ERROR_FILE; quitDecode(pc, dc); return -1; @@ -165,8 +166,9 @@ static int decodeSeek(PlayerControl * pc, DecoderControl * dc, { int ret = -1; - if (dc->state == DECODE_STATE_STOP || dc->error || - strcmp(dc->utf8url, pc->utf8url) != 0) { + if (dc->state == DECODE_STATE_STOP || + dc->error || + dc->current_song != pc->current_song) { stopDecode(dc); *next = -1; cb->begin = 0; @@ -213,9 +215,12 @@ static int decodeSeek(PlayerControl * pc, DecoderControl * dc, if (openAudioDevice(NULL) >= 0) { \ pc->state = PLAYER_STATE_PLAY; \ } else { \ - pathcpy_trunc(pc->erroredUrl, pc->utf8url); \ + char tmp[MPD_PATH_MAX]; \ + pc->errored_song = pc->current_song; \ pc->error = PLAYER_ERROR_AUDIO; \ - ERROR("problems opening audio device while playing \"%s\"\n", pc->utf8url); \ + ERROR("problems opening audio device " \ + "while playing \"%s\"\n", \ + get_song_url(tmp, pc->current_song)); \ pause = -1; \ } \ } \ @@ -249,21 +254,20 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, int close_instream = 1; InputStream inStream; InputPlugin *plugin = NULL; - char path_max_tmp[MPD_PATH_MAX]; + char path_max_fs[MPD_PATH_MAX]; + char path_max_utf8[MPD_PATH_MAX]; - /* not actually sure why we convert between latin/UTF8 for URLs */ - if (isRemoteUrl(pc->utf8url)) { - if (!utf8_to_latin1(path_max_tmp, pc->utf8url)) { - dc->error = DECODE_ERROR_FILE; - goto stop_no_close; - } - } else - rmp2amp_r(path_max_tmp, - utf8_to_fs_charset(path_max_tmp, pc->utf8url)); - - pathcpy_trunc(dc->utf8url, pc->utf8url); + if (!get_song_url(path_max_utf8, pc->current_song)) { + dc->error = DECODE_ERROR_FILE; + goto stop_no_close; + } + if (!isRemoteUrl(path_max_utf8)) { + rmp2amp_r(path_max_fs, + utf8_to_fs_charset(path_max_fs, path_max_utf8)); + } - if (openInputStream(&inStream, path_max_tmp) < 0) { + dc->current_song = pc->current_song; /* NEED LOCK */ + if (openInputStream(&inStream, path_max_fs) < 0) { dc->error = DECODE_ERROR_FILE; goto stop_no_close; } @@ -271,12 +275,6 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, dc->state = DECODE_STATE_START; dc->start = 0; - while (!inputStreamAtEOF(&inStream) && bufferInputStream(&inStream) < 0 - && !dc->stop) { - /* sleep so we don't consume 100% of the cpu */ - my_usleep(10000); - } - /* for http streams, seekable is determined in bufferInputStream */ dc->seekable = inStream.seekable; @@ -284,7 +282,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, goto stop; ret = DECODE_ERROR_UNKTYPE; - if (isRemoteUrl(dc->utf8url)) { + if (isRemoteUrl(path_max_utf8)) { unsigned int next = 0; /* first we try mime types: */ @@ -302,7 +300,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, /* if that fails, try suffix matching the URL: */ if (plugin == NULL) { - const char *s = getSuffix(dc->utf8url); + const char *s = getSuffix(path_max_utf8); next = 0; while (ret && (plugin = getInputPluginFromSuffix(s, next++))) { if (!plugin->streamDecodeFunc) @@ -330,7 +328,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, } } else { unsigned int next = 0; - const char *s = getSuffix(dc->utf8url); + const char *s = getSuffix(path_max_utf8); while (ret && (plugin = getInputPluginFromSuffix(s, next++))) { if (!plugin->streamTypes & INPUT_PLUGIN_STREAM_FILE) continue; @@ -343,7 +341,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, closeInputStream(&inStream); close_instream = 0; ret = plugin->fileDecodeFunc(cb, dc, - path_max_tmp); + path_max_fs); break; } else if (plugin->streamDecodeFunc) { ret = plugin->streamDecodeFunc(cb, dc, &inStream); @@ -353,7 +351,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, } if (ret < 0 || ret == DECODE_ERROR_UNKTYPE) { - pathcpy_trunc(pc->erroredUrl, dc->utf8url); + pc->errored_song = pc->current_song; if (ret != DECODE_ERROR_UNKTYPE) dc->error = DECODE_ERROR_FILE; else diff --git a/src/decode.h b/src/decode.h index 1d90dced4..704caf990 100644 --- a/src/decode.h +++ b/src/decode.h @@ -22,6 +22,7 @@ #include "../config.h" #include "path.h" #include "tag.h" +#include "song.h" #include "mpd_types.h" #include "audio.h" @@ -49,7 +50,7 @@ typedef struct _DecoderControl { volatile mpd_sint8 seekable; volatile double seekWhere; AudioFormat audioFormat; - char utf8url[MPD_PATH_MAX]; + Song *current_song; volatile float totalTime; } DecoderControl; diff --git a/src/player.c b/src/player.c index 109cbe936..f9aedcd20 100644 --- a/src/player.c +++ b/src/player.c @@ -121,7 +121,7 @@ static void set_current_song(Song *song) PlayerControl *pc = &(getPlayerData()->playerControl); pc->fileTime = song->tag ? song->tag->time : 0; - get_song_url(pc->utf8url, song); + pc->current_song = song; } int playerPlay(int fd, Song * song) @@ -222,43 +222,34 @@ int getPlayerError(void) char *getPlayerErrorStr(void) { - static char *error; - int errorlen = MPD_PATH_MAX + 1024; + /* static OK here, only one user in main task */ + static char error[MPD_PATH_MAX + 64]; /* still too much */ + static const size_t errorlen = sizeof(error); + char path_max_tmp[MPD_PATH_MAX]; PlayerControl *pc = &(getPlayerData()->playerControl); - - error = xrealloc(error, errorlen); - error[0] = '\0'; + *error = '\0'; /* likely */ switch (pc->error) { case PLAYER_ERROR_FILENOTFOUND: snprintf(error, errorlen, "file \"%s\" does not exist or is inaccessible", - pc->erroredUrl); + get_song_url(path_max_tmp, pc->errored_song)); break; case PLAYER_ERROR_FILE: snprintf(error, errorlen, "problems decoding \"%s\"", - pc->erroredUrl); + get_song_url(path_max_tmp, pc->errored_song)); break; case PLAYER_ERROR_AUDIO: - snprintf(error, errorlen, "problems opening audio device"); + strcpy(error, "problems opening audio device"); break; case PLAYER_ERROR_SYSTEM: - snprintf(error, errorlen, "system error occured"); + strcpy(error, "system error occured"); break; case PLAYER_ERROR_UNKTYPE: - snprintf(error, errorlen, "file type of \"%s\" is unknown", - pc->erroredUrl); - default: - break; + snprintf(error, errorlen, "file type of \"%s\" is unknown", + get_song_url(path_max_tmp, pc->errored_song)); } - - errorlen = strlen(error); - error = xrealloc(error, errorlen + 1); - - if (errorlen) - return error; - - return NULL; + return *error ? error : NULL; } static void playerCloseAudio(void) @@ -321,7 +312,6 @@ void playerQueueUnlock(void) int playerSeek(int fd, Song * song, float seek_time) { PlayerControl *pc = &(getPlayerData()->playerControl); - char path_max_tmp[MPD_PATH_MAX]; assert(song != NULL); @@ -331,7 +321,7 @@ int playerSeek(int fd, Song * song, float seek_time) return -1; } - if (strcmp(pc->utf8url, get_song_url(path_max_tmp, song)) != 0) + if (pc->current_song != song) set_current_song(song); if (pc->error == PLAYER_ERROR_NOERROR) { diff --git a/src/player.h b/src/player.h index 605a25a80..c819a90c6 100644 --- a/src/player.h +++ b/src/player.h @@ -64,9 +64,8 @@ typedef struct _PlayerControl { volatile float totalTime; volatile float elapsedTime; volatile float fileTime; - char utf8url[MPD_PATH_MAX]; - char currentUrl[MPD_PATH_MAX]; - char erroredUrl[MPD_PATH_MAX]; + Song *current_song; + Song *errored_song; volatile mpd_sint8 queueState; volatile mpd_sint8 queueLockState; volatile mpd_sint8 lockQueue; diff --git a/src/playerData.c b/src/playerData.c index 43852a4c6..718b28771 100644 --- a/src/playerData.c +++ b/src/playerData.c @@ -107,9 +107,8 @@ void initPlayerData(void) playerData_pd->playerControl.queueLockState = PLAYER_QUEUE_UNLOCKED; playerData_pd->playerControl.seek = 0; playerData_pd->playerControl.closeAudio = 0; - memset(playerData_pd->playerControl.utf8url, 0, MPD_PATH_MAX); - memset(playerData_pd->playerControl.erroredUrl, 0, MPD_PATH_MAX); - memset(playerData_pd->playerControl.currentUrl, 0, MPD_PATH_MAX); + playerData_pd->playerControl.current_song = NULL; + playerData_pd->playerControl.errored_song = NULL; playerData_pd->playerControl.crossFade = crossfade; playerData_pd->playerControl.softwareVolume = 1000; playerData_pd->playerControl.totalPlayTime = 0; @@ -119,7 +118,7 @@ void initPlayerData(void) playerData_pd->decoderControl.state = DECODE_STATE_STOP; playerData_pd->decoderControl.seek = 0; playerData_pd->decoderControl.error = DECODE_ERROR_NOERROR; - memset(playerData_pd->decoderControl.utf8url, 0, MPD_PATH_MAX); + playerData_pd->decoderControl.current_song = NULL; } PlayerData *getPlayerData(void) |