summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-03-07 16:20:26 +0100
committerLars-Dominik Braun <lars@6xq.net>2015-03-07 16:20:26 +0100
commit310900e4be52d11388792d776d9f6b89380bbecd (patch)
treed4dc1b3d91043b0e8afd73cb9459ba0288d608da
parent1cd5c5ec77ea43088982a439b58499be87c62087 (diff)
downloadpianobar-windows-310900e4be52d11388792d776d9f6b89380bbecd.tar.gz
pianobar-windows-310900e4be52d11388792d776d9f6b89380bbecd.tar.bz2
pianobar-windows-310900e4be52d11388792d776d9f6b89380bbecd.zip
player: Ignore volume change before playback started
Fixes issue #508.
-rw-r--r--src/main.c2
-rw-r--r--src/player.c10
-rw-r--r--src/player.h8
3 files changed, 15 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index c4bb95a..21d833f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;