Commit 6c0fea4c by xiongziliang

Merge branch 'master' of https://gitee.com/xia-chu/ZLMediaKit

parents 8da23da3 75b17b3a
...@@ -42,7 +42,22 @@ void HlsPlayer::teardown_l(const SockException &ex) { ...@@ -42,7 +42,22 @@ void HlsPlayer::teardown_l(const SockException &ex) {
_play_result = true; _play_result = true;
onPlayResult(ex); onPlayResult(ex);
} else { } else {
onShutdown(ex); //如果不是主动关闭的,则重新拉取索引文件
if (ex.getErrCode() != Err_shutdown) {
// 当切片列表已空, 且没有正在下载的切片并且重试次数已经达到最大次数时, 则认为失败关闭播放器
if (_ts_list.empty() && !(_http_ts_player && _http_ts_player->waitResponse())
&& _try_fetch_index_times >= MAX_TRY_FETCH_INDEX_TIMES) {
onShutdown(ex);
} else {
_try_fetch_index_times += 1;
shutdown(ex);
WarnL << "重新尝试拉取索引文件[" << _try_fetch_index_times << "]:" << _play_url;
fetchIndexFile();
return;
}
} else {
onShutdown(ex);
}
} }
_timer.reset(); _timer.reset();
_timer_ts.reset(); _timer_ts.reset();
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define MIN_TIMEOUT_MULTIPLE 2 #define MIN_TIMEOUT_MULTIPLE 2
#define MAX_TIMEOUT_MULTIPLE 5 #define MAX_TIMEOUT_MULTIPLE 5
#define MAX_TRY_FETCH_INDEX_TIMES 5
namespace mediakit { namespace mediakit {
...@@ -105,6 +106,7 @@ private: ...@@ -105,6 +106,7 @@ private:
std::set<std::string, UrlComp> _ts_url_cache; std::set<std::string, UrlComp> _ts_url_cache;
HttpTSPlayer::Ptr _http_ts_player; HttpTSPlayer::Ptr _http_ts_player;
int _timeout_multiple = MIN_TIMEOUT_MULTIPLE; int _timeout_multiple = MIN_TIMEOUT_MULTIPLE;
int _try_fetch_index_times = 0;
}; };
class HlsPlayerImp : public PlayerImp<HlsPlayer, PlayerBase>, private TrackListener { class HlsPlayerImp : public PlayerImp<HlsPlayer, PlayerBase>, private TrackListener {
......
...@@ -9,29 +9,32 @@ ...@@ -9,29 +9,32 @@
*/ */
#include <string.h> #include <string.h>
#include "Common/macros.h"
#include "HttpChunkedSplitter.h" #include "HttpChunkedSplitter.h"
using namespace std; using namespace std;
//[chunk size][\r\n][chunk data][\r\n][chunk size][\r\n][chunk data][\r\n][chunk size = 0][\r\n][\r\n]
namespace mediakit{ namespace mediakit{
const char *HttpChunkedSplitter::onSearchPacketTail(const char *data, size_t len) { const char *HttpChunkedSplitter::onSearchPacketTail(const char *data, size_t len) {
auto pos = strstr(data,"\r\n"); auto pos = strstr(data, "\r\n");
if(!pos){ if (!pos) {
return nullptr; return nullptr;
} }
return pos + 2; return pos + 2;
} }
void HttpChunkedSplitter::onRecvContent(const char *data, size_t len) { void HttpChunkedSplitter::onRecvContent(const char *data, size_t len) {
onRecvChunk(data,len - 2); onRecvChunk(data, len - 2);
} }
ssize_t HttpChunkedSplitter::onRecvHeader(const char *data, size_t len) { ssize_t HttpChunkedSplitter::onRecvHeader(const char *data, size_t len) {
string str(data,len - 2); int size;
int ret; CHECK(sscanf(data, "%X", &size) == 1 && size >= 0);
sscanf(str.data(),"%X",&ret); //包括后面\r\n两个字节
return ret + 2; return size + 2;
} }
}//namespace mediakit }//namespace mediakit
\ No newline at end of file
...@@ -21,12 +21,10 @@ public: ...@@ -21,12 +21,10 @@ public:
/** /**
* len == 0时代表结束 * len == 0时代表结束
*/ */
typedef std::function<void (const char *data,size_t len)> onChunkData; using onChunkData = std::function<void(const char *data, size_t len)>;
HttpChunkedSplitter(const onChunkData &cb){ HttpChunkedSplitter(const onChunkData &cb) { _onChunkData = cb; };
_onChunkData = cb; ~HttpChunkedSplitter() override { _onChunkData = nullptr; };
};
~HttpChunkedSplitter() override {} ;
protected: protected:
ssize_t onRecvHeader(const char *data,size_t len) override; ssize_t onRecvHeader(const char *data,size_t len) override;
......
...@@ -137,7 +137,7 @@ void HlsMaker::flushLastSegment(bool eof){ ...@@ -137,7 +137,7 @@ void HlsMaker::flushLastSegment(bool eof){
if (seg_dur <= 0) { if (seg_dur <= 0) {
seg_dur = 100; seg_dur = 100;
} }
_seg_dur_list.push_back(std::make_tuple(seg_dur, std::move(_last_file_name))); _seg_dur_list.emplace_back(seg_dur, std::move(_last_file_name));
delOldSegment(); delOldSegment();
//先flush ts切片,否则可能存在ts文件未写入完毕就被访问的情况 //先flush ts切片,否则可能存在ts文件未写入完毕就被访问的情况
onFlushLastSegment(seg_dur); onFlushLastSegment(seg_dur);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论