正在显示
2 个修改的文件
包含
43 行增加
和
17 行删除
| @@ -54,6 +54,9 @@ using namespace std; | @@ -54,6 +54,9 @@ using namespace std; | ||
| 54 | ISrsLog* _srs_log = new ISrsLog(); | 54 | ISrsLog* _srs_log = new ISrsLog(); |
| 55 | ISrsThreadContext* _srs_context = new ISrsThreadContext(); | 55 | ISrsThreadContext* _srs_context = new ISrsThreadContext(); |
| 56 | 56 | ||
| 57 | +// use this default timeout in us, if user not set. | ||
| 58 | +#define SRS_SOCKET_DEFAULT_TIMEOUT 30 * 1000 * 1000LL | ||
| 59 | + | ||
| 57 | /** | 60 | /** |
| 58 | * export runtime context. | 61 | * export runtime context. |
| 59 | */ | 62 | */ |
| @@ -105,6 +108,10 @@ struct Context | @@ -105,6 +108,10 @@ struct Context | ||
| 105 | // the aac sequence header. | 108 | // the aac sequence header. |
| 106 | std::string aac_specific_config; | 109 | std::string aac_specific_config; |
| 107 | 110 | ||
| 111 | + // user set timeout, in us. | ||
| 112 | + int64_t stimeout; | ||
| 113 | + int64_t rtimeout; | ||
| 114 | + | ||
| 108 | Context() { | 115 | Context() { |
| 109 | rtmp = NULL; | 116 | rtmp = NULL; |
| 110 | skt = NULL; | 117 | skt = NULL; |
| @@ -113,6 +120,7 @@ struct Context | @@ -113,6 +120,7 @@ struct Context | ||
| 113 | h264_sps_pps_sent = false; | 120 | h264_sps_pps_sent = false; |
| 114 | h264_sps_changed = false; | 121 | h264_sps_changed = false; |
| 115 | h264_pps_changed = false; | 122 | h264_pps_changed = false; |
| 123 | + rtimeout = stimeout = -1; | ||
| 116 | } | 124 | } |
| 117 | virtual ~Context() { | 125 | virtual ~Context() { |
| 118 | srs_freep(req); | 126 | srs_freep(req); |
| @@ -571,9 +579,12 @@ int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_ | @@ -571,9 +579,12 @@ int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_ | ||
| 571 | } | 579 | } |
| 572 | 580 | ||
| 573 | Context* context = (Context*)rtmp; | 581 | Context* context = (Context*)rtmp; |
| 582 | + | ||
| 583 | + context->stimeout = send_timeout_ms * 1000; | ||
| 584 | + context->rtimeout = recv_timeout_ms * 1000; | ||
| 574 | 585 | ||
| 575 | - context->skt->set_recv_timeout(recv_timeout_ms * 1000LL); | ||
| 576 | - context->skt->set_send_timeout(send_timeout_ms * 1000LL); | 586 | + context->skt->set_recv_timeout(context->rtimeout); |
| 587 | + context->skt->set_send_timeout(context->stimeout); | ||
| 577 | 588 | ||
| 578 | return ret; | 589 | return ret; |
| 579 | } | 590 | } |
| @@ -634,6 +645,16 @@ int srs_rtmp_connect_server(srs_rtmp_t rtmp) | @@ -634,6 +645,16 @@ int srs_rtmp_connect_server(srs_rtmp_t rtmp) | ||
| 634 | srs_assert(rtmp != NULL); | 645 | srs_assert(rtmp != NULL); |
| 635 | Context* context = (Context*)rtmp; | 646 | Context* context = (Context*)rtmp; |
| 636 | 647 | ||
| 648 | + // set timeout if user not set. | ||
| 649 | + if (context->stimeout == -1) { | ||
| 650 | + context->stimeout = SRS_SOCKET_DEFAULT_TIMEOUT; | ||
| 651 | + context->skt->set_send_timeout(context->stimeout); | ||
| 652 | + } | ||
| 653 | + if (context->rtimeout == -1) { | ||
| 654 | + context->rtimeout = SRS_SOCKET_DEFAULT_TIMEOUT; | ||
| 655 | + context->skt->set_recv_timeout(context->rtimeout); | ||
| 656 | + } | ||
| 657 | + | ||
| 637 | if ((ret = srs_librtmp_context_connect(context)) != ERROR_SUCCESS) { | 658 | if ((ret = srs_librtmp_context_connect(context)) != ERROR_SUCCESS) { |
| 638 | return ret; | 659 | return ret; |
| 639 | } | 660 | } |
| @@ -102,29 +102,34 @@ extern int srs_version_revision(); | @@ -102,29 +102,34 @@ extern int srs_version_revision(); | ||
| 102 | // the RTMP handler. | 102 | // the RTMP handler. |
| 103 | typedef void* srs_rtmp_t; | 103 | typedef void* srs_rtmp_t; |
| 104 | typedef void* srs_amf0_t; | 104 | typedef void* srs_amf0_t; |
| 105 | - | 105 | + |
| 106 | /** | 106 | /** |
| 107 | -* create/destroy a rtmp protocol stack. | ||
| 108 | -* @url rtmp url, for example: | ||
| 109 | -* rtmp://localhost/live/livestream | ||
| 110 | -* | ||
| 111 | -* @return a rtmp handler, or NULL if error occured. | ||
| 112 | -*/ | 107 | + * create/destroy a rtmp protocol stack. |
| 108 | + * @url rtmp url, for example: | ||
| 109 | + * rtmp://localhost/live/livestream | ||
| 110 | + * @remark default timeout to 30s if not set by srs_rtmp_set_timeout. | ||
| 111 | + * | ||
| 112 | + * @return a rtmp handler, or NULL if error occured. | ||
| 113 | + */ | ||
| 113 | extern srs_rtmp_t srs_rtmp_create(const char* url); | 114 | extern srs_rtmp_t srs_rtmp_create(const char* url); |
| 114 | /** | 115 | /** |
| 115 | -* create rtmp with url, used for connection specified application. | ||
| 116 | -* @param url the tcUrl, for exmple: | ||
| 117 | -* rtmp://localhost/live | ||
| 118 | -* @remark this is used to create application connection-oriented, | ||
| 119 | -* for example, the bandwidth client used this, no stream specified. | ||
| 120 | -* | ||
| 121 | -* @return a rtmp handler, or NULL if error occured. | ||
| 122 | -*/ | 116 | + * create rtmp with url, used for connection specified application. |
| 117 | + * @param url the tcUrl, for exmple: | ||
| 118 | + * rtmp://localhost/live | ||
| 119 | + * @remark this is used to create application connection-oriented, | ||
| 120 | + * for example, the bandwidth client used this, no stream specified. | ||
| 121 | + * @remark default timeout to 30s if not set by srs_rtmp_set_timeout. | ||
| 122 | + * | ||
| 123 | + * @return a rtmp handler, or NULL if error occured. | ||
| 124 | + */ | ||
| 123 | extern srs_rtmp_t srs_rtmp_create2(const char* url); | 125 | extern srs_rtmp_t srs_rtmp_create2(const char* url); |
| 124 | /** | 126 | /** |
| 125 | * set socket timeout | 127 | * set socket timeout |
| 126 | * @param recv_timeout_ms the timeout for receiving messages in ms. | 128 | * @param recv_timeout_ms the timeout for receiving messages in ms. |
| 127 | * @param send_timeout_ms the timeout for sending message in ms. | 129 | * @param send_timeout_ms the timeout for sending message in ms. |
| 130 | + * @remark user can set timeout once srs_rtmp_create/srs_rtmp_create2, | ||
| 131 | + * or before srs_rtmp_handshake or srs_rtmp_dns_resolve to connect to server. | ||
| 132 | + * @remark default timeout to 30s if not set by srs_rtmp_set_timeout. | ||
| 128 | * | 133 | * |
| 129 | * @return 0, success; otherswise, failed. | 134 | * @return 0, success; otherswise, failed. |
| 130 | */ | 135 | */ |
-
请 注册 或 登录 后发表评论