mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
refine the forwarder
This commit is contained in:
parent
1f8bb0e935
commit
844718c99b
5 changed files with 50 additions and 8 deletions
|
@ -32,34 +32,34 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
SrsForwarder::SrsForwarder()
|
SrsForwarder::SrsForwarder()
|
||||||
{
|
{
|
||||||
client = new SrsRtmpClient();
|
client = new SrsRtmpClient();
|
||||||
port = 1935;
|
|
||||||
tid = NULL;
|
tid = NULL;
|
||||||
loop = false;
|
loop = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsForwarder::~SrsForwarder()
|
SrsForwarder::~SrsForwarder()
|
||||||
{
|
{
|
||||||
srs_freep(client);
|
|
||||||
|
|
||||||
if (tid) {
|
if (tid) {
|
||||||
loop = false;
|
loop = false;
|
||||||
st_thread_interrupt(tid);
|
st_thread_interrupt(tid);
|
||||||
st_thread_join(tid, NULL);
|
st_thread_join(tid, NULL);
|
||||||
tid = NULL;
|
tid = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srs_freep(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsForwarder::on_publish(std::string vhost, std::string app, std::string stream, std::string forward_server)
|
int SrsForwarder::on_publish(std::string vhost, std::string app, std::string stream, std::string forward_server)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
tc_url = "rtmp://";
|
std::string tc_url = "rtmp://";
|
||||||
tc_url += vhost;
|
tc_url += vhost;
|
||||||
tc_url += "/";
|
tc_url += "/";
|
||||||
tc_url += app;
|
tc_url += app;
|
||||||
|
|
||||||
stream_name = stream;
|
std::string stream_name = stream;
|
||||||
server = forward_server;
|
std::string server = forward_server;
|
||||||
|
int port = 1935;
|
||||||
|
|
||||||
size_t pos = forward_server.find(":");
|
size_t pos = forward_server.find(":");
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
|
|
|
@ -31,6 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <st.h>
|
||||||
|
|
||||||
class SrsSharedPtrMessage;
|
class SrsSharedPtrMessage;
|
||||||
class SrsOnMetaDataPacket;
|
class SrsOnMetaDataPacket;
|
||||||
class SrsRtmpClient;
|
class SrsRtmpClient;
|
||||||
|
@ -45,9 +47,11 @@ private:
|
||||||
std::string stream_name;
|
std::string stream_name;
|
||||||
std::string server;
|
std::string server;
|
||||||
int port;
|
int port;
|
||||||
SrsRtmpClient* client;
|
private:
|
||||||
st_thread_t tid;
|
st_thread_t tid;
|
||||||
bool loop;
|
bool loop;
|
||||||
|
private:
|
||||||
|
SrsRtmpClient* client;
|
||||||
public:
|
public:
|
||||||
SrsForwarder();
|
SrsForwarder();
|
||||||
virtual ~SrsForwarder();
|
virtual ~SrsForwarder();
|
||||||
|
|
|
@ -23,6 +23,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#include <srs_core_rtmp.hpp>
|
#include <srs_core_rtmp.hpp>
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
#include <srs_core_log.hpp>
|
#include <srs_core_log.hpp>
|
||||||
#include <srs_core_error.hpp>
|
#include <srs_core_error.hpp>
|
||||||
#include <srs_core_socket.hpp>
|
#include <srs_core_socket.hpp>
|
||||||
|
@ -181,6 +186,34 @@ SrsRtmpClient::~SrsRtmpClient()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SrsRtmpClient::connect_to(std::string server, int port)
|
||||||
|
{
|
||||||
|
int ret = ERROR_SUCCESS;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string SrsRtmpClient::parse_server(std::string host){
|
||||||
|
if(inet_addr(host.c_str()) != INADDR_NONE){
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
hostent* answer = gethostbyname(host.c_str());
|
||||||
|
if(answer == NULL){
|
||||||
|
srs_error("dns resolve host %s error.", host.c_str());
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char ipv4[16];
|
||||||
|
memset(ipv4, 0, sizeof(ipv4));
|
||||||
|
for(int i = 0; i < answer->h_length; i++){
|
||||||
|
inet_ntop(AF_INET, answer->h_addr_list[i], ipv4, sizeof(ipv4));
|
||||||
|
srs_info("dns resolve host %s to %s.", host.c_str(), ipv4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ipv4;
|
||||||
|
}
|
||||||
|
|
||||||
SrsRtmp::SrsRtmp(st_netfd_t client_stfd)
|
SrsRtmp::SrsRtmp(st_netfd_t client_stfd)
|
||||||
{
|
{
|
||||||
protocol = new SrsProtocol(client_stfd);
|
protocol = new SrsProtocol(client_stfd);
|
||||||
|
|
|
@ -40,6 +40,8 @@ class SrsCommonMessage;
|
||||||
class SrsCreateStreamPacket;
|
class SrsCreateStreamPacket;
|
||||||
class SrsFMLEStartPacket;
|
class SrsFMLEStartPacket;
|
||||||
class SrsPublishPacket;
|
class SrsPublishPacket;
|
||||||
|
class SrsSharedPtrMessage;
|
||||||
|
class SrsOnMetaDataPacket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the original request from client.
|
* the original request from client.
|
||||||
|
@ -102,6 +104,9 @@ private:
|
||||||
public:
|
public:
|
||||||
SrsRtmpClient();
|
SrsRtmpClient();
|
||||||
virtual ~SrsRtmpClient();
|
virtual ~SrsRtmpClient();
|
||||||
|
private:
|
||||||
|
virtual int connect_to(std::string server, int port);
|
||||||
|
std::string parse_server(std::string host);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -618,7 +618,7 @@ int SrsSource::on_publish(std::string vhost, std::string app, std::string stream
|
||||||
|
|
||||||
// create forwarders
|
// create forwarders
|
||||||
SrsConfDirective* conf = config->get_forward(vhost);
|
SrsConfDirective* conf = config->get_forward(vhost);
|
||||||
for (int i = 0; conf && i < conf->args.size(); i++) {
|
for (int i = 0; conf && i < (int)conf->args.size(); i++) {
|
||||||
std::string forward_server = conf->args.at(i);
|
std::string forward_server = conf->args.at(i);
|
||||||
|
|
||||||
SrsForwarder* forwarder = new SrsForwarder();
|
SrsForwarder* forwarder = new SrsForwarder();
|
||||||
|
|
Loading…
Reference in a new issue