正在显示
2 个修改的文件
包含
43 行增加
和
17 行删除
@@ -53,6 +53,9 @@ using namespace std; | @@ -53,6 +53,9 @@ using namespace std; | ||
53 | ISrsLog* _srs_log = new ISrsLog(); | 53 | ISrsLog* _srs_log = new ISrsLog(); |
54 | ISrsThreadContext* _srs_context = new ISrsThreadContext(); | 54 | ISrsThreadContext* _srs_context = new ISrsThreadContext(); |
55 | 55 | ||
56 | +// use this default timeout in us, if user not set. | ||
57 | +#define SRS_SOCKET_DEFAULT_TIMEOUT 30 * 1000 * 1000LL | ||
58 | + | ||
56 | /** | 59 | /** |
57 | * export runtime context. | 60 | * export runtime context. |
58 | */ | 61 | */ |
@@ -104,6 +107,10 @@ struct Context | @@ -104,6 +107,10 @@ struct Context | ||
104 | // the aac sequence header. | 107 | // the aac sequence header. |
105 | std::string aac_specific_config; | 108 | std::string aac_specific_config; |
106 | 109 | ||
110 | + // user set timeout, in us. | ||
111 | + int64_t stimeout; | ||
112 | + int64_t rtimeout; | ||
113 | + | ||
107 | Context() { | 114 | Context() { |
108 | rtmp = NULL; | 115 | rtmp = NULL; |
109 | skt = NULL; | 116 | skt = NULL; |
@@ -112,6 +119,7 @@ struct Context | @@ -112,6 +119,7 @@ struct Context | ||
112 | h264_sps_pps_sent = false; | 119 | h264_sps_pps_sent = false; |
113 | h264_sps_changed = false; | 120 | h264_sps_changed = false; |
114 | h264_pps_changed = false; | 121 | h264_pps_changed = false; |
122 | + rtimeout = stimeout = -1; | ||
115 | } | 123 | } |
116 | virtual ~Context() { | 124 | virtual ~Context() { |
117 | srs_freep(req); | 125 | srs_freep(req); |
@@ -577,9 +585,12 @@ int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_ | @@ -577,9 +585,12 @@ int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_ | ||
577 | } | 585 | } |
578 | 586 | ||
579 | Context* context = (Context*)rtmp; | 587 | Context* context = (Context*)rtmp; |
588 | + | ||
589 | + context->stimeout = send_timeout_ms * 1000; | ||
590 | + context->rtimeout = recv_timeout_ms * 1000; | ||
580 | 591 | ||
581 | - context->skt->set_recv_timeout(recv_timeout_ms * 1000LL); | ||
582 | - context->skt->set_send_timeout(send_timeout_ms * 1000LL); | 592 | + context->skt->set_recv_timeout(context->rtimeout); |
593 | + context->skt->set_send_timeout(context->stimeout); | ||
583 | 594 | ||
584 | return ret; | 595 | return ret; |
585 | } | 596 | } |
@@ -640,6 +651,16 @@ int srs_rtmp_connect_server(srs_rtmp_t rtmp) | @@ -640,6 +651,16 @@ int srs_rtmp_connect_server(srs_rtmp_t rtmp) | ||
640 | srs_assert(rtmp != NULL); | 651 | srs_assert(rtmp != NULL); |
641 | Context* context = (Context*)rtmp; | 652 | Context* context = (Context*)rtmp; |
642 | 653 | ||
654 | + // set timeout if user not set. | ||
655 | + if (context->stimeout == -1) { | ||
656 | + context->stimeout = SRS_SOCKET_DEFAULT_TIMEOUT; | ||
657 | + context->skt->set_send_timeout(context->stimeout); | ||
658 | + } | ||
659 | + if (context->rtimeout == -1) { | ||
660 | + context->rtimeout = SRS_SOCKET_DEFAULT_TIMEOUT; | ||
661 | + context->skt->set_recv_timeout(context->rtimeout); | ||
662 | + } | ||
663 | + | ||
643 | if ((ret = srs_librtmp_context_connect(context)) != ERROR_SUCCESS) { | 664 | if ((ret = srs_librtmp_context_connect(context)) != ERROR_SUCCESS) { |
644 | return ret; | 665 | return ret; |
645 | } | 666 | } |
@@ -88,29 +88,34 @@ extern int srs_version_revision(); | @@ -88,29 +88,34 @@ extern int srs_version_revision(); | ||
88 | // the RTMP handler. | 88 | // the RTMP handler. |
89 | typedef void* srs_rtmp_t; | 89 | typedef void* srs_rtmp_t; |
90 | typedef void* srs_amf0_t; | 90 | typedef void* srs_amf0_t; |
91 | - | 91 | + |
92 | /** | 92 | /** |
93 | -* create/destroy a rtmp protocol stack. | ||
94 | -* @url rtmp url, for example: | ||
95 | -* rtmp://localhost/live/livestream | ||
96 | -* | ||
97 | -* @return a rtmp handler, or NULL if error occured. | ||
98 | -*/ | 93 | + * create/destroy a rtmp protocol stack. |
94 | + * @url rtmp url, for example: | ||
95 | + * rtmp://localhost/live/livestream | ||
96 | + * @remark default timeout to 30s if not set by srs_rtmp_set_timeout. | ||
97 | + * | ||
98 | + * @return a rtmp handler, or NULL if error occured. | ||
99 | + */ | ||
99 | extern srs_rtmp_t srs_rtmp_create(const char* url); | 100 | extern srs_rtmp_t srs_rtmp_create(const char* url); |
100 | /** | 101 | /** |
101 | -* create rtmp with url, used for connection specified application. | ||
102 | -* @param url the tcUrl, for exmple: | ||
103 | -* rtmp://localhost/live | ||
104 | -* @remark this is used to create application connection-oriented, | ||
105 | -* for example, the bandwidth client used this, no stream specified. | ||
106 | -* | ||
107 | -* @return a rtmp handler, or NULL if error occured. | ||
108 | -*/ | 102 | + * create rtmp with url, used for connection specified application. |
103 | + * @param url the tcUrl, for exmple: | ||
104 | + * rtmp://localhost/live | ||
105 | + * @remark this is used to create application connection-oriented, | ||
106 | + * for example, the bandwidth client used this, no stream specified. | ||
107 | + * @remark default timeout to 30s if not set by srs_rtmp_set_timeout. | ||
108 | + * | ||
109 | + * @return a rtmp handler, or NULL if error occured. | ||
110 | + */ | ||
109 | extern srs_rtmp_t srs_rtmp_create2(const char* url); | 111 | extern srs_rtmp_t srs_rtmp_create2(const char* url); |
110 | /** | 112 | /** |
111 | * set socket timeout | 113 | * set socket timeout |
112 | * @param recv_timeout_ms the timeout for receiving messages in ms. | 114 | * @param recv_timeout_ms the timeout for receiving messages in ms. |
113 | * @param send_timeout_ms the timeout for sending message in ms. | 115 | * @param send_timeout_ms the timeout for sending message in ms. |
116 | + * @remark user can set timeout once srs_rtmp_create/srs_rtmp_create2, | ||
117 | + * or before srs_rtmp_handshake or srs_rtmp_dns_resolve to connect to server. | ||
118 | + * @remark default timeout to 30s if not set by srs_rtmp_set_timeout. | ||
114 | * | 119 | * |
115 | * @return 0, success; otherswise, failed. | 120 | * @return 0, success; otherswise, failed. |
116 | */ | 121 | */ |
-
请 注册 或 登录 后发表评论