diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/player.c | 10 | ||||
-rw-r--r-- | src/settings.c | 9 | ||||
-rw-r--r-- | src/settings.h | 2 | ||||
-rw-r--r-- | src/ui.c | 17 |
5 files changed, 33 insertions, 7 deletions
@@ -293,7 +293,7 @@ static void BarMainPlayerCleanup (BarApp_t *app, pthread_t *playerThread) { app->playerErrors = 0; } else if (threadRet == (void *) PLAYER_RET_SOFTFAIL) { ++app->playerErrors; - if (app->playerErrors >= app->settings.maxPlayerErrors) { + if (app->playerErrors >= app->settings.maxRetry) { /* don't continue playback if thread reports too many error */ app->nextStation = NULL; } diff --git a/src/player.c b/src/player.c index 977007d..df962fa 100644 --- a/src/player.c +++ b/src/player.c @@ -174,8 +174,16 @@ static bool openStream (player_t * const player) { player->fctx->interrupt_callback.callback = intCb; player->fctx->interrupt_callback.opaque = player; + /* in microseconds */ + unsigned long int timeout = player->settings->timeout*1000000; + char timeoutStr[16]; + ret = snprintf (timeoutStr, sizeof (timeoutStr), "%lu", timeout); + assert (ret < sizeof (timeoutStr)); + AVDictionary *options = NULL; + av_dict_set (&options, "timeout", timeoutStr, 0); + assert (player->url != NULL); - if ((ret = avformat_open_input (&player->fctx, player->url, NULL, NULL)) < 0) { + if ((ret = avformat_open_input (&player->fctx, player->url, NULL, &options)) < 0) { softfail ("Unable to open audio file"); } diff --git a/src/settings.c b/src/settings.c index 9f05adc..06ad818 100644 --- a/src/settings.c +++ b/src/settings.c @@ -161,8 +161,9 @@ void BarSettingsRead (BarSettings_t *settings) { settings->autoselect = true; settings->history = 5; settings->volume = 0; + settings->timeout = 30; /* seconds */ settings->gainMul = 1.0; - settings->maxPlayerErrors = 5; + settings->maxRetry = 3; settings->sortOrder = BAR_SORT_NAME_AZ; settings->loveIcon = strdup (" <3"); settings->banIcon = strdup (" </3"); @@ -337,8 +338,10 @@ void BarSettingsRead (BarSettings_t *settings) { settings->eventCmd = BarSettingsExpandTilde (val, userhome); } else if (streq ("history", key)) { settings->history = atoi (val); - } else if (streq ("max_player_errors", key)) { - settings->maxPlayerErrors = atoi (val); + } else if (streq ("max_retry", key)) { + settings->maxRetry = atoi (val); + } else if (streq ("timeout", key)) { + settings->timeout = atoi (val); } else if (streq ("sort", key)) { size_t i; static const char *mapping[] = {"name_az", diff --git a/src/settings.h b/src/settings.h index b70e4f9..9b74602 100644 --- a/src/settings.h +++ b/src/settings.h @@ -84,7 +84,7 @@ typedef struct { typedef struct { bool autoselect; - unsigned int history, maxPlayerErrors; + unsigned int history, maxRetry, timeout; int volume; float gainMul; BarStationSorting_t sortOrder; @@ -205,6 +205,7 @@ static CURLcode BarPianoHttpRequest (CURL * const http, setAndCheck (CURLOPT_PROGRESSDATA, &lint); setAndCheck (CURLOPT_NOPROGRESS, 0); setAndCheck (CURLOPT_POST, 1); + setAndCheck (CURLOPT_TIMEOUT, settings->timeout); if (settings->caBundle != NULL) { setAndCheck (CURLOPT_CAINFO, settings->caBundle); } @@ -241,7 +242,21 @@ static CURLcode BarPianoHttpRequest (CURL * const http, list = curl_slist_append (list, "Content-Type: text/plain"); setAndCheck (CURLOPT_HTTPHEADER, list); - httpret = curl_easy_perform (http); + unsigned int retry = 0; + do { + httpret = curl_easy_perform (http); + ++retry; + if (httpret == CURLE_OPERATION_TIMEDOUT) { + free (buffer.data); + buffer.data = NULL; + buffer.pos = 0; + if (retry > settings->maxRetry) { + break; + } + } else { + break; + } + } while (true); curl_slist_free_all (list); |