diff --git a/trunk/src/core/srs_core_forward.cpp b/trunk/src/core/srs_core_forward.cpp index b947f3027..d585b2c04 100644 --- a/trunk/src/core/srs_core_forward.cpp +++ b/trunk/src/core/srs_core_forward.cpp @@ -23,19 +23,53 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +#include + #include +#include +#include SrsForwarder::SrsForwarder() { + client = new SrsRtmpClient(); + port = 1935; + tid = NULL; + loop = false; } SrsForwarder::~SrsForwarder() { + srs_freep(client); + + if (tid) { + loop = false; + st_thread_interrupt(tid); + st_thread_join(tid, NULL); + tid = NULL; + } } int SrsForwarder::on_publish(std::string vhost, std::string app, std::string stream, std::string forward_server) { int ret = ERROR_SUCCESS; + + tc_url = "rtmp://"; + tc_url += vhost; + tc_url += "/"; + tc_url += app; + + stream_name = stream; + server = forward_server; + + size_t pos = forward_server.find(":"); + if (pos != std::string::npos) { + port = ::atoi(forward_server.substr(pos + 1).c_str()); + server = forward_server.substr(0, pos); + } + + srs_trace("forward stream=%s, tcUrl=%s to server=%s, port=%d", + stream_name.c_str(), tc_url.c_str(), server.c_str(), port); + return ret; } diff --git a/trunk/src/core/srs_core_forward.hpp b/trunk/src/core/srs_core_forward.hpp index 0b00f92f4..f6ef78c7d 100644 --- a/trunk/src/core/srs_core_forward.hpp +++ b/trunk/src/core/srs_core_forward.hpp @@ -33,12 +33,21 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. class SrsSharedPtrMessage; class SrsOnMetaDataPacket; +class SrsRtmpClient; /** * forward the stream to other servers. */ class SrsForwarder { +private: + std::string tc_url; + std::string stream_name; + std::string server; + int port; + SrsRtmpClient* client; + st_thread_t tid; + bool loop; public: SrsForwarder(); virtual ~SrsForwarder(); diff --git a/trunk/src/core/srs_core_rtmp.cpp b/trunk/src/core/srs_core_rtmp.cpp index d1d4bf992..fa46e0f22 100644 --- a/trunk/src/core/srs_core_rtmp.cpp +++ b/trunk/src/core/srs_core_rtmp.cpp @@ -163,6 +163,24 @@ SrsResponse::~SrsResponse() { } +SrsRtmpClient::SrsRtmpClient() +{ + stfd = NULL; +} + +SrsRtmpClient::~SrsRtmpClient() +{ + if (stfd) { + int fd = st_netfd_fileno(stfd); + st_netfd_close(stfd); + stfd = NULL; + + // st does not close it sometimes, + // close it manually. + close(fd); + } +} + SrsRtmp::SrsRtmp(st_netfd_t client_stfd) { protocol = new SrsProtocol(client_stfd); diff --git a/trunk/src/core/srs_core_rtmp.hpp b/trunk/src/core/srs_core_rtmp.hpp index 2f40c2846..accddb9e3 100644 --- a/trunk/src/core/srs_core_rtmp.hpp +++ b/trunk/src/core/srs_core_rtmp.hpp @@ -92,6 +92,18 @@ enum SrsClientType SrsClientFlashPublish, }; +/** +* implements the client role protocol. +*/ +class SrsRtmpClient +{ +private: + st_netfd_t stfd; +public: + SrsRtmpClient(); + virtual ~SrsRtmpClient(); +}; + /** * the rtmp provices rtmp-command-protocol services, * a high level protocol, media stream oriented services,