summaryrefslogtreecommitdiff
path: root/src/player.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2009-01-30 23:25:36 +0100
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2009-01-31 11:15:48 +0100
commit46b59017ffcc85505cf5f8b98f2ae226121d8a16 (patch)
tree5817bde2c50d88d008f450cb00e3eade309d0604 /src/player.c
parent62ddf6ca4e5f4a03eca660c1d1a9f78a051fd647 (diff)
downloadpianobar-46b59017ffcc85505cf5f8b98f2ae226121d8a16.tar.gz
pianobar-46b59017ffcc85505cf5f8b98f2ae226121d8a16.tar.bz2
pianobar-46b59017ffcc85505cf5f8b98f2ae226121d8a16.zip
Use pthread mutex to block player in pause state
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/player.c b/src/player.c
index b7526e4..7482cc0 100644
--- a/src/player.c
+++ b/src/player.c
@@ -34,18 +34,13 @@ THE SOFTWARE.
#define byteswap32(x) (((x >> 24) & 0x000000ff) | ((x >> 8) & 0x0000ff00) | \
((x << 8) & 0x00ff0000) | ((x << 24) & 0xff000000))
-/* FIXME: not the best solution to poll every second, but the easiest
- * one I know... (pthread's conditions could be another solution) */
+/* wait while locked, but don't slow down main thread by keeping
+* locks too long */
#define QUIT_PAUSE_CHECK \
+ pthread_mutex_lock (&player->pauseMutex); \
+ pthread_mutex_unlock (&player->pauseMutex); \
if (player->doQuit) { \
return 0; \
- } \
- if (player->doPause) { \
- curl_easy_pause (player->audioFd, CURLPAUSE_ALL); \
- while (player->doPause && !player->doQuit) { \
- sleep (1); \
- } \
- curl_easy_pause (player->audioFd, CURLPAUSE_CONT); \
}
/* compute replaygain scale factor
@@ -225,6 +220,8 @@ size_t BarPlayerCurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
(player->bufferFilled - player->bufferRead));
player->bufferFilled = (player->bufferFilled - player->bufferRead);
+ pthread_mutex_unlock (&player->pauseMutex);
+
return size*nmemb;
}
@@ -239,6 +236,7 @@ void *BarPlayerThread (void *data) {
CURLcode curlRet = 0;
/* init handles */
+ pthread_mutex_init (&player->pauseMutex, NULL);
player->audioFd = curl_easy_init ();
player->aacHandle = NeAACDecOpen();
@@ -279,6 +277,7 @@ void *BarPlayerThread (void *data) {
if (player->sampleSize != NULL) {
free (player->sampleSize);
}
+ pthread_mutex_destroy (&player->pauseMutex);
player->mode = PLAYER_FINISHED_PLAYBACK;