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
This commit is contained in:
		
							
								
								
									
										60
									
								
								src/decode.c
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								src/decode.c
									
									
									
									
									
								
							| @@ -103,9 +103,12 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) | |||||||
| 		{ \ | 		{ \ | ||||||
| 			decodeWaitedOn = 0; \ | 			decodeWaitedOn = 0; \ | ||||||
| 			if(openAudioDevice(&(cb->audioFormat))<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; \ | 				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); \ | 				quitDecode(pc,dc); \ | ||||||
| 				return; \ | 				return; \ | ||||||
| 			} else { \ | 			} else { \ | ||||||
| @@ -124,7 +127,7 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) | |||||||
| 					cb->audioFormat.sampleRate; \ | 					cb->audioFormat.sampleRate; \ | ||||||
|                 } \ |                 } \ | ||||||
|                 else if(dc->state!=DECODE_STATE_START) { \ |                 else if(dc->state!=DECODE_STATE_START) { \ | ||||||
| 			pathcpy_trunc(pc->erroredUrl, pc->utf8url); \ | 			pc->errored_song = pc->current_song; \ | ||||||
| 		        pc->error = PLAYER_ERROR_FILE; \ | 		        pc->error = PLAYER_ERROR_FILE; \ | ||||||
| 		        quitDecode(pc,dc); \ | 		        quitDecode(pc,dc); \ | ||||||
| 		        return; \ | 		        return; \ | ||||||
| @@ -138,13 +141,11 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) | |||||||
| static int waitOnDecode(PlayerControl * pc, DecoderControl * dc, | static int waitOnDecode(PlayerControl * pc, DecoderControl * dc, | ||||||
| 			OutputBuffer * cb, int *decodeWaitedOn) | 			OutputBuffer * cb, int *decodeWaitedOn) | ||||||
| { | { | ||||||
| 	pathcpy_trunc(pc->currentUrl, pc->utf8url); |  | ||||||
|  |  | ||||||
| 	while (dc->start) | 	while (dc->start) | ||||||
| 		player_wakeup_decoder(); | 		player_wakeup_decoder(); | ||||||
|  |  | ||||||
| 	if (dc->start || dc->error != DECODE_ERROR_NOERROR) { | 	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; | 		pc->error = PLAYER_ERROR_FILE; | ||||||
| 		quitDecode(pc, dc); | 		quitDecode(pc, dc); | ||||||
| 		return -1; | 		return -1; | ||||||
| @@ -165,8 +166,9 @@ static int decodeSeek(PlayerControl * pc, DecoderControl * dc, | |||||||
| { | { | ||||||
| 	int ret = -1; | 	int ret = -1; | ||||||
|  |  | ||||||
| 	if (dc->state == DECODE_STATE_STOP || dc->error || | 	if (dc->state == DECODE_STATE_STOP || | ||||||
| 	    strcmp(dc->utf8url, pc->utf8url) != 0) { | 	    dc->error || | ||||||
|  | 	    dc->current_song != pc->current_song) { | ||||||
| 		stopDecode(dc); | 		stopDecode(dc); | ||||||
| 		*next = -1; | 		*next = -1; | ||||||
| 		cb->begin = 0; | 		cb->begin = 0; | ||||||
| @@ -213,9 +215,12 @@ static int decodeSeek(PlayerControl * pc, DecoderControl * dc, | |||||||
| 			if (openAudioDevice(NULL) >= 0) { \ | 			if (openAudioDevice(NULL) >= 0) { \ | ||||||
| 				pc->state = PLAYER_STATE_PLAY; \ | 				pc->state = PLAYER_STATE_PLAY; \ | ||||||
| 			} else { \ | 			} else { \ | ||||||
| 				pathcpy_trunc(pc->erroredUrl, pc->utf8url); \ | 				char tmp[MPD_PATH_MAX]; \ | ||||||
|  | 				pc->errored_song = pc->current_song; \ | ||||||
| 				pc->error = PLAYER_ERROR_AUDIO; \ | 				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; \ | 				pause = -1; \ | ||||||
| 			} \ | 			} \ | ||||||
| 		} \ | 		} \ | ||||||
| @@ -249,21 +254,20 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, | |||||||
| 	int close_instream = 1; | 	int close_instream = 1; | ||||||
| 	InputStream inStream; | 	InputStream inStream; | ||||||
| 	InputPlugin *plugin = NULL; | 	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 (!get_song_url(path_max_utf8, pc->current_song)) { | ||||||
| 	if (isRemoteUrl(pc->utf8url)) { |  | ||||||
| 		if (!utf8_to_latin1(path_max_tmp, pc->utf8url)) { |  | ||||||
| 		dc->error = DECODE_ERROR_FILE; | 		dc->error = DECODE_ERROR_FILE; | ||||||
| 		goto stop_no_close; | 		goto stop_no_close; | ||||||
| 	} | 	} | ||||||
| 	} else | 	if (!isRemoteUrl(path_max_utf8)) { | ||||||
| 		rmp2amp_r(path_max_tmp, | 		rmp2amp_r(path_max_fs, | ||||||
| 		          utf8_to_fs_charset(path_max_tmp, pc->utf8url)); | 		          utf8_to_fs_charset(path_max_fs, path_max_utf8)); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	pathcpy_trunc(dc->utf8url, pc->utf8url); | 	dc->current_song = pc->current_song; /* NEED LOCK */ | ||||||
|  | 	if (openInputStream(&inStream, path_max_fs) < 0) { | ||||||
| 	if (openInputStream(&inStream, path_max_tmp) < 0) { |  | ||||||
| 		dc->error = DECODE_ERROR_FILE; | 		dc->error = DECODE_ERROR_FILE; | ||||||
| 		goto stop_no_close; | 		goto stop_no_close; | ||||||
| 	} | 	} | ||||||
| @@ -271,12 +275,6 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, | |||||||
| 	dc->state = DECODE_STATE_START; | 	dc->state = DECODE_STATE_START; | ||||||
| 	dc->start = 0; | 	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 */ | 	/* for http streams, seekable is determined in bufferInputStream */ | ||||||
| 	dc->seekable = inStream.seekable; | 	dc->seekable = inStream.seekable; | ||||||
|  |  | ||||||
| @@ -284,7 +282,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, | |||||||
| 		goto stop; | 		goto stop; | ||||||
|  |  | ||||||
| 	ret = DECODE_ERROR_UNKTYPE; | 	ret = DECODE_ERROR_UNKTYPE; | ||||||
| 	if (isRemoteUrl(dc->utf8url)) { | 	if (isRemoteUrl(path_max_utf8)) { | ||||||
| 		unsigned int next = 0; | 		unsigned int next = 0; | ||||||
|  |  | ||||||
| 		/* first we try mime types: */ | 		/* 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 that fails, try suffix matching the URL: */ | ||||||
| 		if (plugin == NULL) { | 		if (plugin == NULL) { | ||||||
| 			const char *s = getSuffix(dc->utf8url); | 			const char *s = getSuffix(path_max_utf8); | ||||||
| 			next = 0; | 			next = 0; | ||||||
| 			while (ret && (plugin = getInputPluginFromSuffix(s, next++))) { | 			while (ret && (plugin = getInputPluginFromSuffix(s, next++))) { | ||||||
| 				if (!plugin->streamDecodeFunc) | 				if (!plugin->streamDecodeFunc) | ||||||
| @@ -330,7 +328,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, | |||||||
| 		} | 		} | ||||||
| 	} else { | 	} else { | ||||||
| 		unsigned int next = 0; | 		unsigned int next = 0; | ||||||
| 		const char *s = getSuffix(dc->utf8url); | 		const char *s = getSuffix(path_max_utf8); | ||||||
| 		while (ret && (plugin = getInputPluginFromSuffix(s, next++))) { | 		while (ret && (plugin = getInputPluginFromSuffix(s, next++))) { | ||||||
| 			if (!plugin->streamTypes & INPUT_PLUGIN_STREAM_FILE) | 			if (!plugin->streamTypes & INPUT_PLUGIN_STREAM_FILE) | ||||||
| 				continue; | 				continue; | ||||||
| @@ -343,7 +341,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, | |||||||
| 				closeInputStream(&inStream); | 				closeInputStream(&inStream); | ||||||
| 				close_instream = 0; | 				close_instream = 0; | ||||||
| 				ret = plugin->fileDecodeFunc(cb, dc, | 				ret = plugin->fileDecodeFunc(cb, dc, | ||||||
| 				                             path_max_tmp); | 				                             path_max_fs); | ||||||
| 				break; | 				break; | ||||||
| 			} else if (plugin->streamDecodeFunc) { | 			} else if (plugin->streamDecodeFunc) { | ||||||
| 				ret = plugin->streamDecodeFunc(cb, dc, &inStream); | 				ret = plugin->streamDecodeFunc(cb, dc, &inStream); | ||||||
| @@ -353,7 +351,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (ret < 0 || ret == DECODE_ERROR_UNKTYPE) { | 	if (ret < 0 || ret == DECODE_ERROR_UNKTYPE) { | ||||||
| 		pathcpy_trunc(pc->erroredUrl, dc->utf8url); | 		pc->errored_song = pc->current_song; | ||||||
| 		if (ret != DECODE_ERROR_UNKTYPE) | 		if (ret != DECODE_ERROR_UNKTYPE) | ||||||
| 			dc->error = DECODE_ERROR_FILE; | 			dc->error = DECODE_ERROR_FILE; | ||||||
| 		else | 		else | ||||||
|   | |||||||
| @@ -22,6 +22,7 @@ | |||||||
| #include "../config.h" | #include "../config.h" | ||||||
| #include "path.h" | #include "path.h" | ||||||
| #include "tag.h" | #include "tag.h" | ||||||
|  | #include "song.h" | ||||||
|  |  | ||||||
| #include "mpd_types.h" | #include "mpd_types.h" | ||||||
| #include "audio.h" | #include "audio.h" | ||||||
| @@ -49,7 +50,7 @@ typedef struct _DecoderControl { | |||||||
| 	volatile mpd_sint8 seekable; | 	volatile mpd_sint8 seekable; | ||||||
| 	volatile double seekWhere; | 	volatile double seekWhere; | ||||||
| 	AudioFormat audioFormat; | 	AudioFormat audioFormat; | ||||||
| 	char utf8url[MPD_PATH_MAX]; | 	Song *current_song; | ||||||
| 	volatile float totalTime; | 	volatile float totalTime; | ||||||
| } DecoderControl; | } DecoderControl; | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										36
									
								
								src/player.c
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								src/player.c
									
									
									
									
									
								
							| @@ -121,7 +121,7 @@ static void set_current_song(Song *song) | |||||||
| 	PlayerControl *pc = &(getPlayerData()->playerControl); | 	PlayerControl *pc = &(getPlayerData()->playerControl); | ||||||
|  |  | ||||||
| 	pc->fileTime = song->tag ? song->tag->time : 0; | 	pc->fileTime = song->tag ? song->tag->time : 0; | ||||||
| 	get_song_url(pc->utf8url, song); | 	pc->current_song = song; | ||||||
| } | } | ||||||
|  |  | ||||||
| int playerPlay(int fd, Song * song) | int playerPlay(int fd, Song * song) | ||||||
| @@ -222,43 +222,34 @@ int getPlayerError(void) | |||||||
|  |  | ||||||
| char *getPlayerErrorStr(void) | char *getPlayerErrorStr(void) | ||||||
| { | { | ||||||
| 	static char *error; | 	/* static OK here, only one user in main task */ | ||||||
| 	int errorlen = MPD_PATH_MAX + 1024; | 	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); | 	PlayerControl *pc = &(getPlayerData()->playerControl); | ||||||
|  | 	*error = '\0'; /* likely */ | ||||||
| 	error = xrealloc(error, errorlen); |  | ||||||
| 	error[0] = '\0'; |  | ||||||
|  |  | ||||||
| 	switch (pc->error) { | 	switch (pc->error) { | ||||||
| 	case PLAYER_ERROR_FILENOTFOUND: | 	case PLAYER_ERROR_FILENOTFOUND: | ||||||
| 		snprintf(error, errorlen, | 		snprintf(error, errorlen, | ||||||
| 			 "file \"%s\" does not exist or is inaccessible", | 			 "file \"%s\" does not exist or is inaccessible", | ||||||
| 			 pc->erroredUrl); | 			 get_song_url(path_max_tmp, pc->errored_song)); | ||||||
| 		break; | 		break; | ||||||
| 	case PLAYER_ERROR_FILE: | 	case PLAYER_ERROR_FILE: | ||||||
| 		snprintf(error, errorlen, "problems decoding \"%s\"", | 		snprintf(error, errorlen, "problems decoding \"%s\"", | ||||||
| 			 pc->erroredUrl); | 			 get_song_url(path_max_tmp, pc->errored_song)); | ||||||
| 		break; | 		break; | ||||||
| 	case PLAYER_ERROR_AUDIO: | 	case PLAYER_ERROR_AUDIO: | ||||||
| 		snprintf(error, errorlen, "problems opening audio device"); | 		strcpy(error, "problems opening audio device"); | ||||||
| 		break; | 		break; | ||||||
| 	case PLAYER_ERROR_SYSTEM: | 	case PLAYER_ERROR_SYSTEM: | ||||||
| 		snprintf(error, errorlen, "system error occured"); | 		strcpy(error, "system error occured"); | ||||||
| 		break; | 		break; | ||||||
| 	case PLAYER_ERROR_UNKTYPE: | 	case PLAYER_ERROR_UNKTYPE: | ||||||
| 		snprintf(error, errorlen, "file type of \"%s\" is unknown", | 		snprintf(error, errorlen, "file type of \"%s\" is unknown", | ||||||
| 			 pc->erroredUrl); | 			 get_song_url(path_max_tmp, pc->errored_song)); | ||||||
| 	default: |  | ||||||
| 		break; |  | ||||||
| 	} | 	} | ||||||
|  | 	return *error ? error : NULL; | ||||||
| 	errorlen = strlen(error); |  | ||||||
| 	error = xrealloc(error, errorlen + 1); |  | ||||||
|  |  | ||||||
| 	if (errorlen) |  | ||||||
| 		return error; |  | ||||||
|  |  | ||||||
| 	return NULL; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| static void playerCloseAudio(void) | static void playerCloseAudio(void) | ||||||
| @@ -321,7 +312,6 @@ void playerQueueUnlock(void) | |||||||
| int playerSeek(int fd, Song * song, float seek_time) | int playerSeek(int fd, Song * song, float seek_time) | ||||||
| { | { | ||||||
| 	PlayerControl *pc = &(getPlayerData()->playerControl); | 	PlayerControl *pc = &(getPlayerData()->playerControl); | ||||||
| 	char path_max_tmp[MPD_PATH_MAX]; |  | ||||||
|  |  | ||||||
| 	assert(song != NULL); | 	assert(song != NULL); | ||||||
|  |  | ||||||
| @@ -331,7 +321,7 @@ int playerSeek(int fd, Song * song, float seek_time) | |||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (strcmp(pc->utf8url, get_song_url(path_max_tmp, song)) != 0) | 	if (pc->current_song != song) | ||||||
| 		set_current_song(song); | 		set_current_song(song); | ||||||
|  |  | ||||||
| 	if (pc->error == PLAYER_ERROR_NOERROR) { | 	if (pc->error == PLAYER_ERROR_NOERROR) { | ||||||
|   | |||||||
| @@ -64,9 +64,8 @@ typedef struct _PlayerControl { | |||||||
| 	volatile float totalTime; | 	volatile float totalTime; | ||||||
| 	volatile float elapsedTime; | 	volatile float elapsedTime; | ||||||
| 	volatile float fileTime; | 	volatile float fileTime; | ||||||
| 	char utf8url[MPD_PATH_MAX]; | 	Song *current_song; | ||||||
| 	char currentUrl[MPD_PATH_MAX]; | 	Song *errored_song; | ||||||
| 	char erroredUrl[MPD_PATH_MAX]; |  | ||||||
| 	volatile mpd_sint8 queueState; | 	volatile mpd_sint8 queueState; | ||||||
| 	volatile mpd_sint8 queueLockState; | 	volatile mpd_sint8 queueLockState; | ||||||
| 	volatile mpd_sint8 lockQueue; | 	volatile mpd_sint8 lockQueue; | ||||||
|   | |||||||
| @@ -107,9 +107,8 @@ void initPlayerData(void) | |||||||
| 	playerData_pd->playerControl.queueLockState = PLAYER_QUEUE_UNLOCKED; | 	playerData_pd->playerControl.queueLockState = PLAYER_QUEUE_UNLOCKED; | ||||||
| 	playerData_pd->playerControl.seek = 0; | 	playerData_pd->playerControl.seek = 0; | ||||||
| 	playerData_pd->playerControl.closeAudio = 0; | 	playerData_pd->playerControl.closeAudio = 0; | ||||||
| 	memset(playerData_pd->playerControl.utf8url, 0, MPD_PATH_MAX); | 	playerData_pd->playerControl.current_song = NULL; | ||||||
| 	memset(playerData_pd->playerControl.erroredUrl, 0, MPD_PATH_MAX); | 	playerData_pd->playerControl.errored_song = NULL; | ||||||
| 	memset(playerData_pd->playerControl.currentUrl, 0, MPD_PATH_MAX); |  | ||||||
| 	playerData_pd->playerControl.crossFade = crossfade; | 	playerData_pd->playerControl.crossFade = crossfade; | ||||||
| 	playerData_pd->playerControl.softwareVolume = 1000; | 	playerData_pd->playerControl.softwareVolume = 1000; | ||||||
| 	playerData_pd->playerControl.totalPlayTime = 0; | 	playerData_pd->playerControl.totalPlayTime = 0; | ||||||
| @@ -119,7 +118,7 @@ void initPlayerData(void) | |||||||
| 	playerData_pd->decoderControl.state = DECODE_STATE_STOP; | 	playerData_pd->decoderControl.state = DECODE_STATE_STOP; | ||||||
| 	playerData_pd->decoderControl.seek = 0; | 	playerData_pd->decoderControl.seek = 0; | ||||||
| 	playerData_pd->decoderControl.error = DECODE_ERROR_NOERROR; | 	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) | PlayerData *getPlayerData(void) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Eric Wong
					Eric Wong