summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2008-10-17 20:00:56 +0200
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2008-10-17 20:00:56 +0200
commit56b1686b8c27a0b01d0ae3f50615974d03574947 (patch)
treea0b2c7cf833fcc5ccd0fe2e89db7a79f98bb3233
parent3fa2e6d50393d0acd683a23989a5b49e615adc66 (diff)
downloadpianobar-windows-56b1686b8c27a0b01d0ae3f50615974d03574947.tar.gz
pianobar-windows-56b1686b8c27a0b01d0ae3f50615974d03574947.tar.bz2
pianobar-windows-56b1686b8c27a0b01d0ae3f50615974d03574947.zip
Resume aborted song transfer
This fixes those my-favorite-song-suddenly-aborted-"bugs", as well as the pause mode, which was more like a stop mode, because pandora *always* aborted the transfer after a few minutes.
-rw-r--r--src/player.c20
-rw-r--r--src/player.h1
2 files changed, 20 insertions, 1 deletions
diff --git a/src/player.c b/src/player.c
index b009b4f..57fc443 100644
--- a/src/player.c
+++ b/src/player.c
@@ -76,6 +76,7 @@ size_t BarPlayerCurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
memcpy (player->buffer+player->bufferFilled, data, size*nmemb);
player->bufferFilled += size*nmemb;
player->bufferRead = 0;
+ player->bytesReceived += size*nmemb;
if (player->mode == PLAYER_RECV_DATA) {
short int *aacDecoded;
@@ -231,6 +232,9 @@ size_t BarPlayerCurlCb (void *ptr, size_t size, size_t nmemb, void *stream) {
void *BarPlayerThread (void *data) {
struct aacPlayer *player = data;
NeAACDecConfigurationPtr conf;
+ struct curl_slist *extraHeader = NULL;
+ char rangeHeader[255];
+ CURLcode curlRet = 0;
/* init handles */
player->audioFd = curl_easy_init ();
@@ -254,7 +258,21 @@ void *BarPlayerThread (void *data) {
player->mode = PLAYER_INITIALIZED;
- curl_easy_perform (player->audioFd);
+ /* This loop should work around song abortions by requesting the
+ * missing part of the song */
+ do {
+ /* if curl failed, setup new headers _everytime_ (the range changed) */
+ if (curlRet == CURLE_PARTIAL_FILE) {
+ snprintf (rangeHeader, sizeof (rangeHeader),
+ "Range: bytes=%i-", player->bytesReceived);
+ extraHeader = curl_slist_append (extraHeader, rangeHeader);
+ curl_easy_setopt (player->audioFd, CURLOPT_HTTPHEADER,
+ extraHeader);
+ }
+ curlRet = curl_easy_perform (player->audioFd);
+ curl_slist_free_all (extraHeader);
+ extraHeader = NULL;
+ } while (curlRet == CURLE_PARTIAL_FILE);
NeAACDecClose(player->aacHandle);
ao_close(player->audioOutDevice);
diff --git a/src/player.h b/src/player.h
index e542d4d..ee89237 100644
--- a/src/player.h
+++ b/src/player.h
@@ -36,6 +36,7 @@ struct aacPlayer {
PLAYER_AUDIO_INITIALIZED, PLAYER_FOUND_STSZ,
PLAYER_SAMPLESIZE_INITIALIZED, PLAYER_RECV_DATA,
PLAYER_FINISHED_PLAYBACK} mode;
+ size_t bytesReceived;
/* stsz atom: sample sizes */
unsigned int *sampleSize;
size_t sampleSizeN;