Skip to content

Commit

Permalink
solve srt log bug in 4.0release
Browse files Browse the repository at this point in the history
  • Loading branch information
runner365 committed Jan 29, 2022
1 parent 339d942 commit 51fe845
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion trunk/src/srt/srt_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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_;
}
2 changes: 2 additions & 0 deletions trunk/src/srt/srt_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class srt_conn {

void update_timestamp(long long now_ts);
long long get_last_ts();
int get_write_fail_count();

private:
SRTSOCKET _conn_fd;
Expand All @@ -52,6 +53,7 @@ class srt_conn {
std::string _vhost;
int _mode;
long long _update_timestamp;
int write_fail_cnt_;
};

typedef std::shared_ptr<srt_conn> SRT_CONN_PTR;
Expand Down
13 changes: 13 additions & 0 deletions trunk/src/srt/srt_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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++) {
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 51fe845

Please sign in to comment.