diff options
| -rw-r--r-- | src/main.c | 2 | ||||
| -rw-r--r-- | src/player.c | 10 | ||||
| -rw-r--r-- | src/player.h | 8 | 
3 files changed, 15 insertions, 5 deletions
| @@ -292,7 +292,7 @@ static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) {  		/* prevent race condition, mode must _not_ be DEAD if  		 * thread has been started */ -		app->player.mode = PLAYER_STARTING; +		app->player.mode = PLAYER_WAITING;  		/* start player */  		pthread_create (playerThread, NULL, BarPlayerThread,  				&app->player); diff --git a/src/player.c b/src/player.c index 78a5562..bc3d335 100644 --- a/src/player.c +++ b/src/player.c @@ -85,7 +85,10 @@ void BarPlayerDestroy () {   */  void BarPlayerSetVolume (player_t * const player) {  	assert (player != NULL); -	assert (player->fvolume != NULL); + +	if (player->mode != PLAYER_PLAYING) { +		return; +	}  	int ret;  #ifdef HAVE_AVFILTER_GRAPH_SEND_COMMAND @@ -94,6 +97,7 @@ void BarPlayerSetVolume (player_t * const player) {  	char strbuf[16];  	snprintf (strbuf, sizeof (strbuf), "%fdB",  			player->settings->volume + player->gain); +	assert (player->fgraph != NULL);  	if ((ret = avfilter_graph_send_command (player->fgraph, "volume", "volume",  					strbuf, NULL, 0, 0)) < 0) {  #else @@ -101,6 +105,7 @@ void BarPlayerSetVolume (player_t * const player) {  	const double volume = pow (10, (player->settings->volume + player->gain) / 20);  	/* libav does not provide other means to set this right now. it might not  	 * even work everywhere. */ +	assert (player->fvolume != NULL);  	if ((ret = av_opt_set_double (player->fvolume->priv, "volume", volume,  			0)) != 0) {  #endif @@ -197,7 +202,6 @@ static bool openStream (player_t * const player) {  	player->songPlayed = 0;  	player->songDuration = av_q2d (player->st->time_base) *  			(double) player->st->duration; -	player->mode = PLAYER_PLAYING;  	return true;  } @@ -426,6 +430,7 @@ void *BarPlayerThread (void *data) {  		retry = false;  		if (openStream (player)) {  			if (openFilter (player) && openDevice (player)) { +				player->mode = PLAYER_PLAYING;  				retry = play (player) == AVERROR_INVALIDDATA;  			} else {  				/* filter missing or audio device busy */ @@ -435,6 +440,7 @@ void *BarPlayerThread (void *data) {  			/* stream not found */  			pret = PLAYER_RET_SOFTFAIL;  		} +		player->mode = PLAYER_WAITING;  		finish (player);  	} while (retry); diff --git a/src/player.h b/src/player.h index 0363e59..5c60e59 100644 --- a/src/player.h +++ b/src/player.h @@ -49,9 +49,13 @@ typedef struct {  	pthread_cond_t pauseCond;  	enum { -		PLAYER_DEAD = 0, /* thread is not running */ -		PLAYER_STARTING, /* thread is starting */ +		/* not running */ +		PLAYER_DEAD = 0, +		/* running, but not ready to play music yet */ +		PLAYER_WAITING, +		/* currently playing a song */  		PLAYER_PLAYING, +		/* finished playing a song */  		PLAYER_FINISHED,  	} mode; | 
