1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 03:41:55 +00:00

SRT: Reduce the SRT bug by limit the max times for retry.

This commit is contained in:
Alex.CR 2022-01-29 01:07:01 -06:00 committed by GitHub
parent 339d942e7b
commit 0c036e0435
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View file

@ -122,7 +122,8 @@ bool get_streamid_info(const std::string& streamid, int& mode, std::string& url_
}
srt_conn::srt_conn(SRTSOCKET conn_fd, const std::string& streamid):_conn_fd(conn_fd),
_streamid(streamid) {
_streamid(streamid),
write_fail_cnt_(0) {
get_streamid_info(streamid, _mode, _url_subpath);
_update_timestamp = now_ms();
@ -195,7 +196,13 @@ int srt_conn::write(unsigned char* data, int len) {
ret = srt_send(_conn_fd, (char*)data, len);
if (ret <= 0) {
srt_log_error("srt write error:%d, socket fd:%d", ret, _conn_fd);
write_fail_cnt_++;
return ret;
}
write_fail_cnt_ = 0;
return ret;
}
int srt_conn::get_write_fail_count() {
return write_fail_cnt_;
}

View file

@ -44,6 +44,7 @@ public:
void update_timestamp(long long now_ts);
long long get_last_ts();
int get_write_fail_count();
private:
SRTSOCKET _conn_fd;
@ -52,6 +53,7 @@ private:
std::string _vhost;
int _mode;
long long _update_timestamp;
int write_fail_cnt_;
};
typedef std::shared_ptr<srt_conn> SRT_CONN_PTR;

View file

@ -26,6 +26,7 @@ static long long MONITOR_TIMEOUT = 5000;
const unsigned int DEF_DATA_SIZE = 188*7;
const long long CHECK_ALIVE_INTERVAL = 5*1000;
const long long CHECK_ALIVE_TIMEOUT = 5*1000;
static const int SRT_WRTIE_FAIL_MAX = 10;
long long srt_now_ms = 0;
@ -216,6 +217,7 @@ void srt_handle::handle_push_data(SRT_SOCKSTATUS status, const std::string& subp
srt_log_info("receive data size(%d) from pusher(%d) to pullers, count:%d",
ret, conn_fd, streamid_iter->second.size());
std::vector<SRTSOCKET> remove_vec;
for (auto puller_iter = streamid_iter->second.begin();
puller_iter != streamid_iter->second.end();
puller_iter++) {
@ -228,6 +230,17 @@ void srt_handle::handle_push_data(SRT_SOCKSTATUS status, const std::string& subp
srt_log_info("send data size(%d) to puller fd:%d", write_ret, puller_iter->first);
if (write_ret > 0) {
puller_iter->second->update_timestamp(srt_now_ms);
} else {
if (player_conn->get_write_fail_count() > SRT_WRTIE_FAIL_MAX) {
remove_vec.push_back(puller_iter->first);
}
}
}
for (auto item : remove_vec) {
streamid_iter->second.erase(item);
if (streamid_iter->second.empty()) {
_streamid_map.erase(streamid_iter);
}
}