Skip to content

Commit 6afe131

Browse files
authored
reconnect when the network quality is temporarily poor and causes frequent connections to the host in a short period of time
1 parent 55ce20b commit 6afe131

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Audio.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,9 @@ void Audio::playChunk() {
24232423
}
24242424
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
24252425
void Audio::loop() {
2426+
static uint8_t interval_short_cnt = 0;
2427+
static uint32_t connect_host_time = millis();
2428+
24262429
if(!m_f_running) return;
24272430

24282431
if(m_playlistFormat != FORMAT_M3U8) { // normal process
@@ -2473,6 +2476,20 @@ void Audio::loop() {
24732476
else { // host == NULL means connect to m3u8 URL
24742477
if(m_lastM3U8host) httpPrint(m_lastM3U8host);
24752478
else httpPrint(m_lastHost); // if url has no first redirection
2479+
2480+
if(millis() - connect_host_time < 1000) {
2481+
if(++interval_short_cnt >= 5) { // connect to host too often (maybe cause by temporary bad network quality)
2482+
interval_short_cnt = 0;
2483+
2484+
AUDIO_INFO("connect host interval too short, try to reconnect...");
2485+
connecttohost(m_lastHost);
2486+
}
2487+
}
2488+
else {
2489+
interval_short_cnt = 0;
2490+
}
2491+
connect_host_time = millis();
2492+
24762493
m_dataMode = HTTP_RESPONSE_HEADER; // we have a new playlist now
24772494
}
24782495
break;

0 commit comments

Comments
 (0)