mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Micro changes and refines.
This commit is contained in:
parent
173c683566
commit
378bffa34f
20 changed files with 110 additions and 119 deletions
|
@ -142,7 +142,7 @@ void SrsAppCasterFlv::remove(ISrsResource* c)
|
|||
|
||||
std::vector<ISrsConnection*>::iterator it;
|
||||
if ((it = std::find(conns.begin(), conns.end(), conn)) != conns.end()) {
|
||||
conns.erase(it);
|
||||
it = conns.erase(it);
|
||||
}
|
||||
|
||||
// fixbug: ISrsConnection for CasterFlv is not freed, which could cause memory leak
|
||||
|
|
|
@ -206,7 +206,7 @@ void SrsResourceManager::subscribe(ISrsDisposingHandler* h)
|
|||
// Restore the handler from unsubscribing handlers.
|
||||
vector<ISrsDisposingHandler*>::iterator it;
|
||||
if ((it = std::find(unsubs_.begin(), unsubs_.end(), h)) != unsubs_.end()) {
|
||||
unsubs_.erase(it);
|
||||
it = unsubs_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ void SrsResourceManager::unsubscribe(ISrsDisposingHandler* h)
|
|||
{
|
||||
vector<ISrsDisposingHandler*>::iterator it = find(handlers_.begin(), handlers_.end(), h);
|
||||
if (it != handlers_.end()) {
|
||||
handlers_.erase(it);
|
||||
it = handlers_.erase(it);
|
||||
}
|
||||
|
||||
// Put it to the unsubscribing handlers.
|
||||
|
@ -385,7 +385,7 @@ void SrsResourceManager::dispose(ISrsResource* c)
|
|||
|
||||
vector<ISrsResource*>::iterator it = std::find(conns_.begin(), conns_.end(), c);
|
||||
if (it != conns_.end()) {
|
||||
conns_.erase(it);
|
||||
it = conns_.erase(it);
|
||||
}
|
||||
|
||||
// We should copy all handlers, because it may change during callback.
|
||||
|
|
|
@ -166,7 +166,7 @@ void SrsFastTimer::unsubscribe(ISrsFastTimer* timer)
|
|||
{
|
||||
vector<ISrsFastTimer*>::iterator it = std::find(handlers_.begin(), handlers_.end(), timer);
|
||||
if (it != handlers_.end()) {
|
||||
handlers_.erase(it);
|
||||
it = handlers_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,6 +165,10 @@ srs_error_t SrsUdpListener::listen()
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// Ignore if not configured.
|
||||
if (ip.empty() || !port) return err;
|
||||
|
||||
srs_close_stfd(lfd);
|
||||
if ((err = srs_udp_listen(ip, port, &lfd)) != srs_success) {
|
||||
return srs_error_wrap(err, "listen %s:%d", ip.c_str(), port);
|
||||
}
|
||||
|
@ -224,7 +228,7 @@ srs_error_t SrsUdpListener::cycle()
|
|||
SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h)
|
||||
{
|
||||
handler = h;
|
||||
port = 0;
|
||||
port_ = 0;
|
||||
lfd = NULL;
|
||||
label_ = "TCP";
|
||||
trd = new SrsDummyCoroutine();
|
||||
|
@ -245,24 +249,32 @@ SrsTcpListener* SrsTcpListener::set_label(const std::string& label)
|
|||
SrsTcpListener* SrsTcpListener::set_endpoint(const std::string& i, int p)
|
||||
{
|
||||
ip = i;
|
||||
port = p;
|
||||
port_ = p;
|
||||
return this;
|
||||
}
|
||||
|
||||
SrsTcpListener* SrsTcpListener::set_endpoint(const std::string& endpoint)
|
||||
{
|
||||
std::string ip; int port;
|
||||
srs_parse_endpoint(endpoint, ip, port);
|
||||
return set_endpoint(ip, port);
|
||||
std::string ip; int port_;
|
||||
srs_parse_endpoint(endpoint, ip, port_);
|
||||
return set_endpoint(ip, port_);
|
||||
}
|
||||
|
||||
int SrsTcpListener::port()
|
||||
{
|
||||
return port_;
|
||||
}
|
||||
|
||||
srs_error_t SrsTcpListener::listen()
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// Ignore if not configured.
|
||||
if (ip.empty() || !port_) return err;
|
||||
|
||||
srs_close_stfd(lfd);
|
||||
if ((err = srs_tcp_listen(ip, port, &lfd)) != srs_success) {
|
||||
return srs_error_wrap(err, "listen at %s:%d", ip.c_str(), port);
|
||||
if ((err = srs_tcp_listen(ip, port_, &lfd)) != srs_success) {
|
||||
return srs_error_wrap(err, "listen at %s:%d", ip.c_str(), port_);
|
||||
}
|
||||
|
||||
srs_freep(trd);
|
||||
|
@ -272,7 +284,7 @@ srs_error_t SrsTcpListener::listen()
|
|||
}
|
||||
|
||||
int fd = srs_netfd_fileno(lfd);
|
||||
srs_trace("%s listen at tcp://%s:%d, fd=%d", label_.c_str(), ip.c_str(), port, fd);
|
||||
srs_trace("%s listen at tcp://%s:%d, fd=%d", label_.c_str(), ip.c_str(), port_, fd);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ private:
|
|||
private:
|
||||
ISrsTcpHandler* handler;
|
||||
std::string ip;
|
||||
int port;
|
||||
int port_;
|
||||
public:
|
||||
SrsTcpListener(ISrsTcpHandler* h);
|
||||
virtual ~SrsTcpListener();
|
||||
|
@ -123,6 +123,7 @@ public:
|
|||
SrsTcpListener* set_label(const std::string& label);
|
||||
SrsTcpListener* set_endpoint(const std::string& i, int p);
|
||||
SrsTcpListener* set_endpoint(const std::string& endpoint);
|
||||
int port();
|
||||
public:
|
||||
virtual srs_error_t listen();
|
||||
void close();
|
||||
|
|
|
@ -752,9 +752,11 @@ srs_error_t SrsRtcTcpConn::cycle()
|
|||
SrsStatistic::instance()->on_disconnect(get_id().c_str(), err);
|
||||
SrsStatistic::instance()->kbps_add_delta(get_id().c_str(), delta_);
|
||||
|
||||
// TODO: FIXME: Should manage RTC TCP connection by _srs_rtc_manager.
|
||||
// Because we use manager to manage this object, not the http connection object, so we must remove it here.
|
||||
manager_->remove(this);
|
||||
|
||||
// TODO: FIXME: When TCP connection(transport) closed, should notify session to dispose, should not free them simultaneously.
|
||||
// Only remove session when network is established, because client might use other UDP network.
|
||||
if(session_ && session_->tcp()->is_establelished()) {
|
||||
session_->tcp()->set_state(SrsRtcNetworkStateClosed);
|
||||
|
|
|
@ -57,14 +57,21 @@ public:
|
|||
public:
|
||||
srs_error_t encode(std::ostringstream& os);
|
||||
public:
|
||||
// See https://webrtchacks.com/sdp-anatomy/
|
||||
uint32_t ssrc_;
|
||||
// See https://webrtchacks.com/sdp-anatomy/
|
||||
// a=ssrc:3570614608 cname:4TOk42mSjXCkVIa6
|
||||
std::string cname_;
|
||||
// See https://webrtchacks.com/sdp-anatomy/
|
||||
// a=ssrc:2231627014 msid:lgsCFqt9kN2fVKw5wg3NKqGdATQoltEwOdMS daed9400-d0dd-4db3-b949-422499e96e2d
|
||||
// a=ssrc:2231627014 msid:{msid_} {msid_tracker_}
|
||||
// a=ssrc:3570614608 msid:lgsCFqt9kN2fVKw5wg3NKqGdATQoltEwOdMS 35429d94-5637-4686-9ecd-7d0622261ce8
|
||||
// a=ssrc:3570614608 msid:{msid_} {msid_tracker_}
|
||||
std::string msid_;
|
||||
std::string msid_tracker_;
|
||||
// See https://webrtchacks.com/sdp-anatomy/
|
||||
// a=ssrc:3570614608 mslabel:lgsCFqt9kN2fVKw5wg3NKqGdATQoltEwOdMS
|
||||
std::string mslabel_;
|
||||
// See https://webrtchacks.com/sdp-anatomy/
|
||||
// a=ssrc:3570614608 label:35429d94-5637-4686-9ecd-7d0622261ce8
|
||||
std::string label_;
|
||||
};
|
||||
|
||||
|
|
|
@ -491,7 +491,7 @@ void SrsRtcSource::on_consumer_destroy(SrsRtcConsumer* consumer)
|
|||
std::vector<SrsRtcConsumer*>::iterator it;
|
||||
it = std::find(consumers.begin(), consumers.end(), consumer);
|
||||
if (it != consumers.end()) {
|
||||
consumers.erase(it);
|
||||
it = consumers.erase(it);
|
||||
}
|
||||
|
||||
// When all consumers finished, notify publisher to handle it.
|
||||
|
@ -599,7 +599,7 @@ void SrsRtcSource::unsubscribe(ISrsRtcSourceEventHandler* h)
|
|||
std::vector<ISrsRtcSourceEventHandler*>::iterator it;
|
||||
it = std::find(event_handlers_.begin(), event_handlers_.end(), h);
|
||||
if (it != event_handlers_.end()) {
|
||||
event_handlers_.erase(it);
|
||||
it = event_handlers_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1135,6 +1135,7 @@ srs_error_t SrsServer::do_on_tcp_client(ISrsListener* listener, srs_netfd_t& stf
|
|||
if (nn == 10 && b[0] == 0 && b[2] == 0 && b[3] == 1 && b[1] - b[5] == 20
|
||||
&& b[6] == 0x21 && b[7] == 0x12 && b[8] == 0xa4 && b[9] == 0x42
|
||||
) {
|
||||
// TODO: FIXME: Should manage this connection by _srs_rtc_manager
|
||||
resource = new SrsRtcTcpConn(io, ip, port, this);
|
||||
} else {
|
||||
resource = new SrsHttpxConn(listener == http_listener_, this, io, http_server, ip, port);
|
||||
|
@ -1152,8 +1153,11 @@ srs_error_t SrsServer::do_on_tcp_client(ISrsListener* listener, srs_netfd_t& stf
|
|||
} else if (listener == http_listener_ || listener == https_listener_) {
|
||||
bool is_https = listener == https_listener_;
|
||||
resource = new SrsHttpxConn(is_https, this, new SrsTcpConnection(stfd2), http_server, ip, port);
|
||||
#ifdef SRS_RTC
|
||||
} else if (listener == webrtc_listener_) {
|
||||
// TODO: FIXME: Should manage this connection by _srs_rtc_manager
|
||||
resource = new SrsRtcTcpConn(new SrsTcpConnection(stfd2), ip, port, this);
|
||||
#endif
|
||||
} else {
|
||||
srs_close_stfd(stfd2);
|
||||
srs_warn("Close for invalid fd=%d, ip=%s:%d", fd, ip.c_str(), port);
|
||||
|
|
|
@ -489,7 +489,7 @@ void SrsUnSortedHashtable::set(string key, SrsAmf0Any* value)
|
|||
|
||||
if (key == name) {
|
||||
srs_freep(any);
|
||||
properties.erase(it);
|
||||
it = properties.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,11 @@ ISrsResource::~ISrsResource()
|
|||
{
|
||||
}
|
||||
|
||||
std::string ISrsResource::desc()
|
||||
{
|
||||
return "Resource";
|
||||
}
|
||||
|
||||
ISrsResourceManager::ISrsResourceManager()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
// Get the context id of connection.
|
||||
virtual const SrsContextId& get_id() = 0;
|
||||
// The resource description, optional.
|
||||
virtual std::string desc() = 0;
|
||||
virtual std::string desc();
|
||||
};
|
||||
|
||||
// The manager for resource.
|
||||
|
|
|
@ -19,6 +19,7 @@ using namespace std;
|
|||
#include <srs_core_autofree.hpp>
|
||||
#include <srs_protocol_rtmp_stack.hpp>
|
||||
#include <srs_protocol_conn.hpp>
|
||||
#include <srs_protocol_http_stack.hpp>
|
||||
|
||||
SrsHttpParser::SrsHttpParser()
|
||||
{
|
||||
|
@ -451,24 +452,8 @@ string SrsHttpMessage::method_str()
|
|||
if (jsonp && !jsonp_method.empty()) {
|
||||
return jsonp_method;
|
||||
}
|
||||
|
||||
if (is_http_get()) {
|
||||
return "GET";
|
||||
}
|
||||
if (is_http_put()) {
|
||||
return "PUT";
|
||||
}
|
||||
if (is_http_post()) {
|
||||
return "POST";
|
||||
}
|
||||
if (is_http_delete()) {
|
||||
return "DELETE";
|
||||
}
|
||||
if (is_http_options()) {
|
||||
return "OPTIONS";
|
||||
}
|
||||
|
||||
return "OTHER";
|
||||
|
||||
return http_method_str((http_method)_method);
|
||||
}
|
||||
|
||||
bool SrsHttpMessage::is_http_get()
|
||||
|
|
|
@ -3498,8 +3498,6 @@ VOID TEST(ProtocolStackTest, ProtocolExcpectMessage)
|
|||
|
||||
VOID TEST(ProtocolRTMPTest, RTMPRequest)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
SrsRequest req;
|
||||
std::string param;
|
||||
|
||||
|
|
|
@ -1233,8 +1233,6 @@ VOID TEST(ProtocolStackTest, ProtocolRecvVCid1BMin)
|
|||
|
||||
VOID TEST(ProtocolKbpsTest, Connections)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
MockWallClock* clock = new MockWallClock();
|
||||
SrsAutoFree(MockWallClock, clock);
|
||||
|
@ -1400,8 +1398,6 @@ VOID TEST(ProtocolKbpsTest, Connections)
|
|||
|
||||
VOID TEST(ProtocolKbpsTest, Delta)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
MockWallClock* clock = new MockWallClock();
|
||||
SrsAutoFree(MockWallClock, clock);
|
||||
|
@ -1484,8 +1480,6 @@ VOID TEST(ProtocolKbpsTest, Delta)
|
|||
|
||||
VOID TEST(ProtocolKbpsTest, RAWStatistic)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
MockWallClock* clock = new MockWallClock();
|
||||
SrsAutoFree(MockWallClock, clock);
|
||||
|
@ -1650,8 +1644,6 @@ VOID TEST(ProtocolKbpsTest, WriteLargeIOVs)
|
|||
|
||||
VOID TEST(ProtocolKbpsTest, ConnectionsSugar)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
MockWallClock* clock = new MockWallClock();
|
||||
SrsAutoFree(MockWallClock, clock);
|
||||
|
@ -1799,8 +1791,6 @@ VOID TEST(ProtocolKbpsTest, ConnectionsSugar)
|
|||
|
||||
VOID TEST(ProtocolKbpsTest, DeltaSugar)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
MockWallClock* clock = new MockWallClock();
|
||||
SrsAutoFree(MockWallClock, clock);
|
||||
|
@ -1840,8 +1830,6 @@ VOID TEST(ProtocolKbpsTest, DeltaSugar)
|
|||
|
||||
VOID TEST(ProtocolKbpsTest, RAWStatisticSugar)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
MockWallClock* clock = new MockWallClock();
|
||||
SrsAutoFree(MockWallClock, clock);
|
||||
|
@ -2286,8 +2274,6 @@ VOID TEST(ProtocolProtobufTest, FieldKey)
|
|||
|
||||
VOID TEST(ProtocolKbpsTest, NewDelta)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
SrsEphemeralDelta ed;
|
||||
|
||||
|
|
|
@ -515,7 +515,7 @@ VOID TEST(HTTPServerTest, MessageConnection)
|
|||
|
||||
if (true) {
|
||||
SrsHttpMessage m;
|
||||
m.set_basic(HTTP_REQUEST, 100, 0, 0); EXPECT_STREQ("OTHER", m.method_str().c_str());
|
||||
m.set_basic(HTTP_REQUEST, 100, 0, 0); EXPECT_STREQ("<unknown>", m.method_str().c_str());
|
||||
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_GET, 0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_GET, m.method()); EXPECT_STREQ("GET", m.method_str().c_str());
|
||||
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_PUT, 0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_PUT, m.method()); EXPECT_STREQ("PUT", m.method_str().c_str());
|
||||
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_POST, 0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_POST, m.method()); EXPECT_STREQ("POST", m.method_str().c_str());
|
||||
|
|
|
@ -178,7 +178,7 @@ VOID TEST(ServiceStSRTTest, ListenConnectAccept)
|
|||
srs_error_t err = srs_success;
|
||||
|
||||
std::string server_ip = "127.0.0.1";
|
||||
int server_port = 9000;
|
||||
int server_port = 19000;
|
||||
|
||||
MockSrtServer srt_server;
|
||||
HELPER_EXPECT_SUCCESS(srt_server.create_socket());
|
||||
|
@ -223,7 +223,7 @@ VOID TEST(ServiceStSRTTest, ConnectWithStreamid)
|
|||
srs_error_t err = srs_success;
|
||||
|
||||
std::string server_ip = "127.0.0.1";
|
||||
int server_port = 9000;
|
||||
int server_port = 19000;
|
||||
|
||||
MockSrtServer srt_server;
|
||||
HELPER_EXPECT_SUCCESS(srt_server.create_socket());
|
||||
|
@ -235,7 +235,7 @@ VOID TEST(ServiceStSRTTest, ConnectWithStreamid)
|
|||
HELPER_EXPECT_SUCCESS(srs_srt_set_streamid(srt_client_fd, streamid));
|
||||
SrsSrtSocket* srt_client_socket = new SrsSrtSocket(_srt_eventloop->poller(), srt_client_fd);
|
||||
|
||||
HELPER_EXPECT_SUCCESS(srt_client_socket->connect("127.0.0.1", 9000));
|
||||
HELPER_EXPECT_SUCCESS(srt_client_socket->connect(server_ip, server_port));
|
||||
|
||||
srs_srt_t srt_server_accepted_fd = srs_srt_socket_invalid();
|
||||
HELPER_EXPECT_SUCCESS(srt_server.accept(&srt_server_accepted_fd));
|
||||
|
@ -250,7 +250,7 @@ VOID TEST(ServiceStSRTTest, ReadWrite)
|
|||
srs_error_t err = srs_success;
|
||||
|
||||
std::string server_ip = "127.0.0.1";
|
||||
int server_port = 9000;
|
||||
int server_port = 19000;
|
||||
|
||||
MockSrtServer srt_server;
|
||||
HELPER_EXPECT_SUCCESS(srt_server.create_socket());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue