mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +00:00 
			
		
		
		
	merge from 2.0
This commit is contained in:
		
						commit
						14760003ba
					
				
					 4 changed files with 87 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -113,8 +113,16 @@ int main(int argc, char** argv)
 | 
			
		|||
        srs_human_trace("duration and timeout must be positive.");
 | 
			
		||||
        exit(-3);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    rtmp = srs_rtmp_create(rtmp_url);
 | 
			
		||||
    
 | 
			
		||||
    if ((rtmp = srs_rtmp_create(rtmp_url)) == NULL) {
 | 
			
		||||
        srs_human_trace("create rtmp failed");
 | 
			
		||||
        ret = -1;
 | 
			
		||||
        goto rtmp_destroy;
 | 
			
		||||
    }
 | 
			
		||||
    if ((ret = srs_rtmp_set_timeout(rtmp, timeout * 1000, timeout * 1000)) != 0) {
 | 
			
		||||
        srs_human_trace("set timeout for rtmp failed. errno=%d", ret);
 | 
			
		||||
        goto rtmp_destroy;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    if ((ret = srs_rtmp_dns_resolve(rtmp)) != 0) {
 | 
			
		||||
        srs_human_trace("dns resolve failed. ret=%d", ret);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
			
		|||
 | 
			
		||||
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
 | 
			
		||||
#ifndef _WIN32
 | 
			
		||||
    #define SOCKET_ETIME ETIME
 | 
			
		||||
    #define SOCKET_ETIME EWOULDBLOCK
 | 
			
		||||
    #define SOCKET_ECONNRESET ECONNRESET
 | 
			
		||||
 | 
			
		||||
    #define SOCKET_ERRNO() errno
 | 
			
		||||
| 
						 | 
				
			
			@ -160,10 +160,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
			
		|||
        
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
    void srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
 | 
			
		||||
    int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
 | 
			
		||||
    {
 | 
			
		||||
        SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
 | 
			
		||||
        
 | 
			
		||||
        int sec = timeout_us / (1000 * 1000LL);
 | 
			
		||||
        int microsec = timeout_us / 1000LL % 1000;
 | 
			
		||||
        
 | 
			
		||||
        sec = srs_max(0, sec);
 | 
			
		||||
        microsec = srs_max(0, microsec);
 | 
			
		||||
        
 | 
			
		||||
        struct timeval tv = { sec , microsec };
 | 
			
		||||
        if (setsockopt(skt->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
 | 
			
		||||
            return SOCKET_ERRNO();
 | 
			
		||||
        }
 | 
			
		||||
        skt->recv_timeout = timeout_us;
 | 
			
		||||
        
 | 
			
		||||
        return ERROR_SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
    int64_t srs_hijack_io_get_recv_timeout(srs_hijack_io_t ctx)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -175,10 +188,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
			
		|||
        SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
 | 
			
		||||
        return skt->recv_bytes;
 | 
			
		||||
    }
 | 
			
		||||
    void srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
 | 
			
		||||
    int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us)
 | 
			
		||||
    {
 | 
			
		||||
        SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx;
 | 
			
		||||
        
 | 
			
		||||
        int sec = timeout_us / (1000 * 1000LL);
 | 
			
		||||
        int microsec = timeout_us / 1000LL % 1000;
 | 
			
		||||
 | 
			
		||||
        sec = srs_max(0, sec);
 | 
			
		||||
        microsec = srs_max(0, microsec);
 | 
			
		||||
 | 
			
		||||
        struct timeval tv = { sec , microsec };
 | 
			
		||||
        if (setsockopt(skt->fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) {
 | 
			
		||||
            return SOCKET_ERRNO();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        skt->send_timeout = timeout_us;
 | 
			
		||||
        
 | 
			
		||||
        return ERROR_SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
    int64_t srs_hijack_io_get_send_timeout(srs_hijack_io_t ctx)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -480,14 +480,6 @@ int srs_librtmp_context_resolve_host(Context* context)
 | 
			
		|||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
    
 | 
			
		||||
    // create socket
 | 
			
		||||
    srs_freep(context->skt);
 | 
			
		||||
    context->skt = new SimpleSocketStream();
 | 
			
		||||
    
 | 
			
		||||
    if ((ret = context->skt->create_socket()) != ERROR_SUCCESS) {
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // connect to server:port
 | 
			
		||||
    context->ip = srs_dns_resolve(context->host);
 | 
			
		||||
    if (context->ip.empty()) {
 | 
			
		||||
| 
						 | 
				
			
			@ -534,6 +526,17 @@ srs_rtmp_t srs_rtmp_create(const char* url)
 | 
			
		|||
{
 | 
			
		||||
    Context* context = new Context();
 | 
			
		||||
    context->url = url;
 | 
			
		||||
 | 
			
		||||
    // create socket
 | 
			
		||||
    srs_freep(context->skt);
 | 
			
		||||
    context->skt = new SimpleSocketStream();
 | 
			
		||||
 | 
			
		||||
    if (context->skt->create_socket() != ERROR_SUCCESS) {
 | 
			
		||||
        // free the context and return NULL
 | 
			
		||||
        srs_freep(context);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return context;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -546,8 +549,34 @@ srs_rtmp_t srs_rtmp_create2(const char* url)
 | 
			
		|||
    // auto append stream.
 | 
			
		||||
    context->url += "/livestream";
 | 
			
		||||
    
 | 
			
		||||
    // create socket
 | 
			
		||||
    srs_freep(context->skt);
 | 
			
		||||
    context->skt = new SimpleSocketStream();
 | 
			
		||||
    
 | 
			
		||||
    if (context->skt->create_socket() != ERROR_SUCCESS) {
 | 
			
		||||
        // free the context and return NULL
 | 
			
		||||
        srs_freep(context);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return context;
 | 
			
		||||
}
 | 
			
		||||
   
 | 
			
		||||
int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_ms)
 | 
			
		||||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
 | 
			
		||||
    if (!rtmp) {
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Context* context = (Context*)rtmp;
 | 
			
		||||
 | 
			
		||||
    context->skt->set_recv_timeout(recv_timeout_ms * 1000LL);
 | 
			
		||||
    context->skt->set_send_timeout(send_timeout_ms * 1000LL);
 | 
			
		||||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void srs_rtmp_destroy(srs_rtmp_t rtmp)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -121,6 +121,14 @@ extern srs_rtmp_t srs_rtmp_create(const char* url);
 | 
			
		|||
* @return a rtmp handler, or NULL if error occured.
 | 
			
		||||
*/
 | 
			
		||||
extern srs_rtmp_t srs_rtmp_create2(const char* url);
 | 
			
		||||
/**
 | 
			
		||||
 * set socket timeout
 | 
			
		||||
 * @param recv_timeout_ms the timeout for receiving messages in ms.
 | 
			
		||||
 * @param send_timeout_ms the timeout for sending message in ms.
 | 
			
		||||
 *
 | 
			
		||||
 * @return 0, success; otherswise, failed.
 | 
			
		||||
 */
 | 
			
		||||
extern int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_ms);
 | 
			
		||||
/**
 | 
			
		||||
* close and destroy the rtmp stack.
 | 
			
		||||
* @remark, user should never use the rtmp again.
 | 
			
		||||
| 
						 | 
				
			
			@ -1010,7 +1018,7 @@ typedef void* srs_hijack_io_t;
 | 
			
		|||
    * set the socket recv timeout.
 | 
			
		||||
    * @return 0, success; otherswise, failed.
 | 
			
		||||
    */
 | 
			
		||||
    extern void srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
 | 
			
		||||
    extern int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
 | 
			
		||||
    /**
 | 
			
		||||
    * get the socket recv timeout.
 | 
			
		||||
    * @return 0, success; otherswise, failed.
 | 
			
		||||
| 
						 | 
				
			
			@ -1025,7 +1033,7 @@ typedef void* srs_hijack_io_t;
 | 
			
		|||
    * set the socket send timeout.
 | 
			
		||||
    * @return 0, success; otherswise, failed.
 | 
			
		||||
    */
 | 
			
		||||
    extern void srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
 | 
			
		||||
    extern int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us);
 | 
			
		||||
    /**
 | 
			
		||||
    * get the socket send timeout.
 | 
			
		||||
    * @return 0, success; otherswise, failed.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue