mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +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()
 | 
			
		||||
{
 | 
			
		||||
	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;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	srs_freep(client);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SrsForwarder::on_publish(std::string vhost, std::string app, std::string stream, std::string forward_server)
 | 
			
		||||
{
 | 
			
		||||
	int ret = ERROR_SUCCESS;
 | 
			
		||||
	
 | 
			
		||||
	tc_url = "rtmp://";
 | 
			
		||||
	std::string tc_url = "rtmp://";
 | 
			
		||||
	tc_url += vhost;
 | 
			
		||||
	tc_url += "/";
 | 
			
		||||
	tc_url += app;
 | 
			
		||||
	
 | 
			
		||||
	stream_name = stream;
 | 
			
		||||
	server = forward_server;
 | 
			
		||||
	std::string stream_name = stream;
 | 
			
		||||
	std::string server = forward_server;
 | 
			
		||||
	int port = 1935;
 | 
			
		||||
	
 | 
			
		||||
	size_t pos = forward_server.find(":");
 | 
			
		||||
	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 <st.h>
 | 
			
		||||
 | 
			
		||||
class SrsSharedPtrMessage;
 | 
			
		||||
class SrsOnMetaDataPacket;
 | 
			
		||||
class SrsRtmpClient;
 | 
			
		||||
| 
						 | 
				
			
			@ -45,9 +47,11 @@ private:
 | 
			
		|||
	std::string stream_name;
 | 
			
		||||
	std::string server;
 | 
			
		||||
	int port;
 | 
			
		||||
	SrsRtmpClient* client;
 | 
			
		||||
private:
 | 
			
		||||
	st_thread_t tid;
 | 
			
		||||
	bool loop;
 | 
			
		||||
private:
 | 
			
		||||
	SrsRtmpClient* client;
 | 
			
		||||
public:
 | 
			
		||||
	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 <sys/socket.h>
 | 
			
		||||
#include <netinet/in.h>
 | 
			
		||||
#include <arpa/inet.h>
 | 
			
		||||
#include <netdb.h>
 | 
			
		||||
 | 
			
		||||
#include <srs_core_log.hpp>
 | 
			
		||||
#include <srs_core_error.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)
 | 
			
		||||
{
 | 
			
		||||
	protocol = new SrsProtocol(client_stfd);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,6 +40,8 @@ class SrsCommonMessage;
 | 
			
		|||
class SrsCreateStreamPacket;
 | 
			
		||||
class SrsFMLEStartPacket;
 | 
			
		||||
class SrsPublishPacket;
 | 
			
		||||
class SrsSharedPtrMessage;
 | 
			
		||||
class SrsOnMetaDataPacket;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* the original request from client.
 | 
			
		||||
| 
						 | 
				
			
			@ -102,6 +104,9 @@ private:
 | 
			
		|||
public:
 | 
			
		||||
	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
 | 
			
		||||
	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);
 | 
			
		||||
		
 | 
			
		||||
		SrsForwarder* forwarder = new SrsForwarder();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue