2020-01-14 13:10:33 +00:00
|
|
|
#ifndef SRT_HANDLE_H
|
|
|
|
#define SRT_HANDLE_H
|
|
|
|
#include <srt/srt.h>
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <memory>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <queue>
|
|
|
|
#include <string.h>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
#include "srt_conn.hpp"
|
2020-01-17 11:43:54 +00:00
|
|
|
#include "srt_to_rtmp.hpp"
|
2020-01-14 13:10:33 +00:00
|
|
|
|
|
|
|
class srt_handle {
|
|
|
|
public:
|
2020-02-12 02:23:39 +00:00
|
|
|
srt_handle(int pollid);
|
2020-01-14 13:10:33 +00:00
|
|
|
~srt_handle();
|
|
|
|
|
|
|
|
//add new srt connection into epoll event
|
|
|
|
void add_newconn(SRT_CONN_PTR conn_ptr, int events);
|
2020-02-12 02:23:39 +00:00
|
|
|
//handle recv/send srt socket
|
|
|
|
void handle_srt_socket(SRT_SOCKSTATUS status, SRTSOCKET conn_fd);
|
|
|
|
//check srt connection whether it's still alive.
|
|
|
|
void check_alive();
|
|
|
|
|
|
|
|
private:
|
2020-01-14 13:10:33 +00:00
|
|
|
//get srt conn object by srt socket
|
|
|
|
SRT_CONN_PTR get_srt_conn(SRTSOCKET conn_srt_socket);
|
|
|
|
|
|
|
|
void handle_push_data(SRT_SOCKSTATUS status, const std::string& subpath, SRTSOCKET conn_fd);
|
|
|
|
void handle_pull_data(SRT_SOCKSTATUS status, const std::string& subpath, SRTSOCKET conn_fd);
|
|
|
|
|
|
|
|
//add new puller into puller list and conn_map
|
|
|
|
void add_new_puller(SRT_CONN_PTR, std::string stream_id);
|
|
|
|
//remove pull srt from play list
|
|
|
|
void close_pull_conn(SRTSOCKET srtsocket, std::string stream_id);
|
|
|
|
|
|
|
|
//add new pusher into pusher map: <socket fd, pusher conn ptr>
|
|
|
|
bool add_new_pusher(SRT_CONN_PTR conn_ptr);
|
|
|
|
//remove push connection and remove epoll
|
|
|
|
void close_push_conn(SRTSOCKET srtsocket);
|
|
|
|
|
|
|
|
//debug statics
|
|
|
|
void debug_statics(SRTSOCKET srtsocket, const std::string& streamid);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int _handle_pollid;
|
|
|
|
|
2020-01-15 02:30:20 +00:00
|
|
|
std::unordered_map<SRTSOCKET, SRT_CONN_PTR> _conn_map;//save all srt connection: pull or push
|
2020-01-14 13:10:33 +00:00
|
|
|
|
2020-01-15 02:30:20 +00:00
|
|
|
//save push srt connection for prevent from repeat push connection
|
|
|
|
std::unordered_map<std::string, SRT_CONN_PTR> _push_conn_map;//key:streamid, value:SRT_CONN_PTR
|
2020-01-14 13:10:33 +00:00
|
|
|
//streamid, play map<SRTSOCKET, SRT_CONN_PTR>
|
|
|
|
std::unordered_map<std::string, std::unordered_map<SRTSOCKET, SRT_CONN_PTR>> _streamid_map;
|
|
|
|
|
|
|
|
long long _last_timestamp;
|
|
|
|
long long _last_check_alive_ts;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //SRT_HANDLE_H
|