mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-31 00:37:39 +08:00
HLS: 修复http客户端连接复用导致hls播放异常的bug: #1294
This commit is contained in:
parent
f27893ffa5
commit
6a044f0726
@ -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<int>() / 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<HlsPlayer, PlayerBase>::onShutdown(ex);
|
||||
_demuxer = nullptr;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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<HttpChunkedSplitter> _chunkedSplitter;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user