diff --git a/src/Http/HlsPlayer.cpp b/src/Http/HlsPlayer.cpp index 25046951..29140bfe 100644 --- a/src/Http/HlsPlayer.cpp +++ b/src/Http/HlsPlayer.cpp @@ -28,11 +28,15 @@ void HlsPlayer::play_l(){ teardown_l(SockException(Err_shutdown, "所有hls url都尝试播放失败!")); return; } + if (alive() && _waiting_response) { + return; + } float playTimeOutSec = (*this)[Client::kTimeoutMS].as() / 1000.0f; setMethod("GET"); if(!(*this)[kNetAdapter].empty()) { setNetAdapter((*this)[kNetAdapter]); } + _waiting_response = true; sendRequest(_m3u8_list.back(), playTimeOutSec); } @@ -173,6 +177,7 @@ void HlsPlayer::onResponseBody(const char *buf, size_t size, size_t recvedSize, } void HlsPlayer::onResponseCompleted() { + _waiting_response = false; if (HlsParser::parse(getUrl(), _m3u8)) { playDelay(); if (_first) { @@ -208,6 +213,7 @@ float HlsPlayer::delaySecond() { } void HlsPlayer::onDisconnect(const SockException &ex) { + _waiting_response = false; if (_first) { //第一次失败,则播放失败 _first = false; @@ -219,6 +225,8 @@ void HlsPlayer::onDisconnect(const SockException &ex) { if (ex.getErrCode() == Err_shutdown) { if (_m3u8_list.size() <= 1) { //全部url都播放失败 + _timer = nullptr; + _timer_ts = nullptr; onShutdown(ex); } else { _m3u8_list.pop_back(); @@ -399,6 +407,7 @@ void HlsPlayerImp::onPlayResult(const SockException &ex) { } void HlsPlayerImp::onShutdown(const SockException &ex) { + WarnL << ex.what(); PlayerImp::onShutdown(ex); _demuxer = nullptr; } diff --git a/src/Http/HlsPlayer.h b/src/Http/HlsPlayer.h index 453110a4..2ad94dae 100644 --- a/src/Http/HlsPlayer.h +++ b/src/Http/HlsPlayer.h @@ -112,6 +112,7 @@ private: private: bool _is_m3u8 = false; bool _first = true; + bool _waiting_response = false; int64_t _last_sequence = -1; string _m3u8; Timer::Ptr _timer; diff --git a/src/Http/HttpClient.cpp b/src/Http/HttpClient.cpp index e3062a24..69079a12 100644 --- a/src/Http/HttpClient.cpp +++ b/src/Http/HttpClient.cpp @@ -80,20 +80,27 @@ void HttpClient::sendRequest(const string &strUrl, float fTimeOutSec) { startConnect(host, port, fTimeOutSec); } else { SockException ex; - onConnect(ex); + onConnect_l(ex); } } void HttpClient::clear() { + _url.clear(); _header.clear(); _body.reset(); _method.clear(); _path.clear(); - _parser.Clear(); - _recvedBodySize = 0; - _totalBodySize = 0; _aliveTicker.resetTime(); _chunkedSplitter.reset(); + _fTimeOutSec = 0; + clearResponse(); +} + +void HttpClient::clearResponse() { + _recvedBodySize = 0; + _totalBodySize = 0; + _parser.Clear(); + _chunkedSplitter = nullptr; HttpRequestSplitter::reset(); } @@ -131,16 +138,17 @@ const string &HttpClient::getUrl() const { } void HttpClient::onConnect(const SockException &ex) { + onConnect_l(ex); +} + +void HttpClient::onConnect_l(const SockException &ex) { _aliveTicker.resetTime(); if (ex) { onDisconnect(ex); return; } - _totalBodySize = 0; - _recvedBodySize = 0; - HttpRequestSplitter::reset(); - _chunkedSplitter.reset(); + clearResponse(); _StrPrinter printer; printer << _method + " " << _path + " HTTP/1.1\r\n"; @@ -280,8 +288,6 @@ void HttpClient::onManager() { } void HttpClient::onResponseCompleted_l() { - _totalBodySize = 0; - _recvedBodySize = 0; onResponseCompleted(); } diff --git a/src/Http/HttpClient.h b/src/Http/HttpClient.h index 61354f7d..e7fc4d87 100644 --- a/src/Http/HttpClient.h +++ b/src/Http/HttpClient.h @@ -165,7 +165,9 @@ protected: private: void onResponseCompleted_l(); + void onConnect_l(const SockException &ex); void checkCookie(HttpHeader &headers); + void clearResponse(); protected: bool _isHttps; @@ -176,13 +178,14 @@ private: HttpBody::Ptr _body; string _method; string _path; + string _lastHost; + Ticker _aliveTicker; + float _fTimeOutSec = 0; + //recv size_t _recvedBodySize; ssize_t _totalBodySize; Parser _parser; - string _lastHost; - Ticker _aliveTicker; - float _fTimeOutSec = 0; std::shared_ptr _chunkedSplitter; };