From 4f71f47fc48dad1a0d28e4f0977fdf2c471fbb0d Mon Sep 17 00:00:00 2001 From: "Venkatarama NG. Avadhani" Date: Tue, 4 Jun 2019 17:38:57 +0530 Subject: [PATCH 1/4] Add a connection timeout to the socket When using invalid URL, without an explicit timeout, the connection would fail only after 60s, which is too long. Let the nativeOpen() method set a timeout and if it doesn't, use a default timeout of 10s. --- rtmp-client/src/main/cpp/librtmp-jni.c | 4 +++- rtmp-client/src/main/cpp/librtmp-jni.h | 2 +- rtmp-client/src/main/cpp/librtmp/rtmp.c | 9 +++++++++ .../net/butterflytv/rtmp_client/RtmpClient.java | 14 ++++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/rtmp-client/src/main/cpp/librtmp-jni.c b/rtmp-client/src/main/cpp/librtmp-jni.c index bbf4443..5193735 100644 --- a/rtmp-client/src/main/cpp/librtmp-jni.c +++ b/rtmp-client/src/main/cpp/librtmp-jni.c @@ -30,7 +30,8 @@ Java_net_butterflytv_rtmp_1client_RtmpClient_nativeAlloc(JNIEnv* env, jobject th */ JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thiz, jstring url_, - jboolean isPublishMode, jlong rtmpPointer) { + jboolean isPublishMode, jlong rtmpPointer, + jint timeout) { const char *url = (*env)->GetStringUTFChars(env, url_, NULL); RTMP *rtmp = (RTMP *) rtmpPointer; @@ -40,6 +41,7 @@ Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thi } RTMP_Init(rtmp); + rtmp->Link.timeout = timeout; int ret = RTMP_SetupURL(rtmp, url); if (!ret) { diff --git a/rtmp-client/src/main/cpp/librtmp-jni.h b/rtmp-client/src/main/cpp/librtmp-jni.h index f8cb769..7235cd6 100644 --- a/rtmp-client/src/main/cpp/librtmp-jni.h +++ b/rtmp-client/src/main/cpp/librtmp-jni.h @@ -18,7 +18,7 @@ extern "C" { JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thiz, jstring url, jboolean isPublishMode, - jlong rtmpPointer); + jlong rtmpPointer, jint timeout); /* * Class: net_butterflytv_rtmp_client_RtmpClient diff --git a/rtmp-client/src/main/cpp/librtmp/rtmp.c b/rtmp-client/src/main/cpp/librtmp/rtmp.c index aa9bb22..406bb94 100644 --- a/rtmp-client/src/main/cpp/librtmp/rtmp.c +++ b/rtmp-client/src/main/cpp/librtmp/rtmp.c @@ -909,6 +909,15 @@ RTMP_Connect0(RTMP *r, struct sockaddr * service) r->m_sb.sb_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (r->m_sb.sb_socket != -1) { + int err; + SET_RCVTIMEO(tv, r->Link.timeout); + + err = setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + if (err) + { + RTMP_Log(RTMP_LOGERROR, "Error %d setting SO_SNDTIMEO", errno); + } + if (connect(r->m_sb.sb_socket, service, sizeof(struct sockaddr)) < 0) { int err = GetSockError(); diff --git a/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java b/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java index f2cf104..6f98531 100644 --- a/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java +++ b/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java @@ -13,8 +13,18 @@ public class RtmpClient { private final static int OPEN_SUCCESS = 1; + private final static int TIMEOUT = 10; private long rtmpPointer = 0; + /* Timeout value in seconds */ + private int timeout = TIMEOUT; + /* Sets the timeout variable */ + public void setTimeout(int timeout) { + if (timeout > 0) { + this.timeout = timeout; + } + } + public static class RtmpIOException extends IOException { /** @@ -50,7 +60,7 @@ public RtmpIOException(int errorCode) { public void open(String url, boolean isPublishMode) throws RtmpIOException { rtmpPointer = nativeAlloc(); - int result = nativeOpen(url, isPublishMode, rtmpPointer); + int result = nativeOpen(url, isPublishMode, rtmpPointer, timeout); if (result != OPEN_SUCCESS) { rtmpPointer = 0; throw new RtmpIOException(result); @@ -72,7 +82,7 @@ public void open(String url, boolean isPublishMode) throws RtmpIOException { * * returns {@link #OPEN_SUCCESS} if it is successful, throws RtmpIOException if it is failed */ - private native int nativeOpen(String url, boolean isPublishMode, long rtmpPointer); + private native int nativeOpen(String url, boolean isPublishMode, long rtmpPointer, int timeout); /** * read data from rtmp connection From 3cf84624dd6343a68bbefa67d01811bf96fa4a7e Mon Sep 17 00:00:00 2001 From: "Venkatarama NG. Avadhani" Date: Fri, 21 Jun 2019 21:44:07 +0530 Subject: [PATCH 2/4] Add Receive Timeout Configurability Send timeout can be configured in milliseconds and receive timeout can be set in seconds. --- rtmp-client/src/main/cpp/librtmp-jni.c | 5 +- rtmp-client/src/main/cpp/librtmp-jni.h | 3 +- rtmp-client/src/main/cpp/librtmp/rtmp.c | 6 ++- rtmp-client/src/main/cpp/librtmp/rtmp.h | 3 +- .../butterflytv/rtmp_client/RtmpClient.java | 49 ++++++++++++++----- 5 files changed, 49 insertions(+), 17 deletions(-) diff --git a/rtmp-client/src/main/cpp/librtmp-jni.c b/rtmp-client/src/main/cpp/librtmp-jni.c index 5193735..b763bbd 100644 --- a/rtmp-client/src/main/cpp/librtmp-jni.c +++ b/rtmp-client/src/main/cpp/librtmp-jni.c @@ -31,7 +31,7 @@ Java_net_butterflytv_rtmp_1client_RtmpClient_nativeAlloc(JNIEnv* env, jobject th JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thiz, jstring url_, jboolean isPublishMode, jlong rtmpPointer, - jint timeout) { + jint sendTimeoutInMs, jint receiveTimeoutInS) { const char *url = (*env)->GetStringUTFChars(env, url_, NULL); RTMP *rtmp = (RTMP *) rtmpPointer; @@ -41,7 +41,8 @@ Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thi } RTMP_Init(rtmp); - rtmp->Link.timeout = timeout; + rtmp->Link.timeout = receiveTimeoutInS; + rtmp->Link.sendTimeoutInMs = sendTimeoutInMs; int ret = RTMP_SetupURL(rtmp, url); if (!ret) { diff --git a/rtmp-client/src/main/cpp/librtmp-jni.h b/rtmp-client/src/main/cpp/librtmp-jni.h index 7235cd6..c62084d 100644 --- a/rtmp-client/src/main/cpp/librtmp-jni.h +++ b/rtmp-client/src/main/cpp/librtmp-jni.h @@ -18,7 +18,8 @@ extern "C" { JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thiz, jstring url, jboolean isPublishMode, - jlong rtmpPointer, jint timeout); + jlong rtmpPointer, jint sendTimeoutInMs, + jint receiveTimeoutInS); /* * Class: net_butterflytv_rtmp_client_RtmpClient diff --git a/rtmp-client/src/main/cpp/librtmp/rtmp.c b/rtmp-client/src/main/cpp/librtmp/rtmp.c index 406bb94..b03baad 100644 --- a/rtmp-client/src/main/cpp/librtmp/rtmp.c +++ b/rtmp-client/src/main/cpp/librtmp/rtmp.c @@ -910,9 +910,11 @@ RTMP_Connect0(RTMP *r, struct sockaddr * service) if (r->m_sb.sb_socket != -1) { int err; - SET_RCVTIMEO(tv, r->Link.timeout); + struct timeval send_timeout; - err = setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); + send_timeout.tv_sec = r->Link.sendTimeoutInMs / 1000; + send_timeout.tv_usec = (r->Link.sendTimeoutInMs % 1000) * 1000; + err = setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_SNDTIMEO, &send_timeout, sizeof(send_timeout)); if (err) { RTMP_Log(RTMP_LOGERROR, "Error %d setting SO_SNDTIMEO", errno); diff --git a/rtmp-client/src/main/cpp/librtmp/rtmp.h b/rtmp-client/src/main/cpp/librtmp/rtmp.h index d723070..272746d 100644 --- a/rtmp-client/src/main/cpp/librtmp/rtmp.h +++ b/rtmp-client/src/main/cpp/librtmp/rtmp.h @@ -176,7 +176,8 @@ extern "C" int swfAge; int protocol; - int timeout; /* connection timeout in seconds */ + int timeout; /* connection timeout in seconds */ + int sendTimeoutInMs; /* socket send timeout in milliseconds */ #define RTMP_PUB_NAME 0x0001 /* send login to server */ #define RTMP_PUB_RESP 0x0002 /* send salted password hash */ diff --git a/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java b/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java index 6f98531..2e8ead9 100644 --- a/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java +++ b/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java @@ -13,17 +13,13 @@ public class RtmpClient { private final static int OPEN_SUCCESS = 1; - private final static int TIMEOUT = 10; + private final static int TIMEOUT_IN_MS = 10000; private long rtmpPointer = 0; - /* Timeout value in seconds */ - private int timeout = TIMEOUT; - /* Sets the timeout variable */ - public void setTimeout(int timeout) { - if (timeout > 0) { - this.timeout = timeout; - } - } + /** Socket send timeout value in milliseconds */ + private int sendTimeoutInMs = TIMEOUT_IN_MS; + /** Socket receive timeout value in seconds */ + private int receiveTimeoutInS = (TIMEOUT_IN_MS / 1000); public static class RtmpIOException extends IOException { @@ -58,9 +54,39 @@ public RtmpIOException(int errorCode) { } + /** + * Sets the socket's send timeout value + * @param sendTimeoutInMs + * The send timeout value for the rtmp socket in milliseconds. + * Parameter expects a non-zero positive integer and will reset timeout to the default value + * (10000 ms) if zero or a negative integer is passed. + * */ + public void setSendTimeoutInMs(int sendTimeoutInMs) { + if (sendTimeoutInMs > 0) { + this.sendTimeoutInMs = sendTimeoutInMs; + } else { + this.sendTimeoutInMs = TIMEOUT_IN_MS; + } + } + + /** + * Sets the socket's receive timeout value + * @param receiveTimeoutInS + * The receive timeout value for the rtmp socket in seconds. + * Parameter expects a non-zero positive integer and will reset timeout to the default value + * (10s) if zero or a negative integer is passed. + * */ + public void setReceiveTimeoutInS(int receiveTimeoutInS) { + if (receiveTimeoutInS > 0) { + this.receiveTimeoutInS = receiveTimeoutInS; + } else { + this.receiveTimeoutInS = (TIMEOUT_IN_MS / 1000); + } + } + public void open(String url, boolean isPublishMode) throws RtmpIOException { rtmpPointer = nativeAlloc(); - int result = nativeOpen(url, isPublishMode, rtmpPointer, timeout); + int result = nativeOpen(url, isPublishMode, rtmpPointer, sendTimeoutInMs, receiveTimeoutInS); if (result != OPEN_SUCCESS) { rtmpPointer = 0; throw new RtmpIOException(result); @@ -82,7 +108,8 @@ public void open(String url, boolean isPublishMode) throws RtmpIOException { * * returns {@link #OPEN_SUCCESS} if it is successful, throws RtmpIOException if it is failed */ - private native int nativeOpen(String url, boolean isPublishMode, long rtmpPointer, int timeout); + private native int nativeOpen(String url, boolean isPublishMode, long rtmpPointer, + int sendTimeoutInMs, int receiveTimeoutInS); /** * read data from rtmp connection From 9a138b5640e3c619b88f6b37b9c06cc35a438600 Mon Sep 17 00:00:00 2001 From: "Venkatarama NG. Avadhani" Date: Mon, 24 Jun 2019 17:23:35 +0530 Subject: [PATCH 3/4] Change receive timeout unit to milliseconds --- rtmp-client/src/main/cpp/librtmp-jni.c | 4 ++-- rtmp-client/src/main/cpp/librtmp-jni.h | 2 +- rtmp-client/src/main/cpp/librtmp/rtmp.c | 15 +++++++------ rtmp-client/src/main/cpp/librtmp/rtmp.h | 4 ++-- .../butterflytv/rtmp_client/RtmpClient.java | 21 ++++++++++--------- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/rtmp-client/src/main/cpp/librtmp-jni.c b/rtmp-client/src/main/cpp/librtmp-jni.c index b763bbd..c282964 100644 --- a/rtmp-client/src/main/cpp/librtmp-jni.c +++ b/rtmp-client/src/main/cpp/librtmp-jni.c @@ -31,7 +31,7 @@ Java_net_butterflytv_rtmp_1client_RtmpClient_nativeAlloc(JNIEnv* env, jobject th JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thiz, jstring url_, jboolean isPublishMode, jlong rtmpPointer, - jint sendTimeoutInMs, jint receiveTimeoutInS) { + jint sendTimeoutInMs, jint receiveTimeoutInMs) { const char *url = (*env)->GetStringUTFChars(env, url_, NULL); RTMP *rtmp = (RTMP *) rtmpPointer; @@ -41,7 +41,7 @@ Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thi } RTMP_Init(rtmp); - rtmp->Link.timeout = receiveTimeoutInS; + rtmp->Link.timeout = receiveTimeoutInMs; rtmp->Link.sendTimeoutInMs = sendTimeoutInMs; int ret = RTMP_SetupURL(rtmp, url); diff --git a/rtmp-client/src/main/cpp/librtmp-jni.h b/rtmp-client/src/main/cpp/librtmp-jni.h index c62084d..6090874 100644 --- a/rtmp-client/src/main/cpp/librtmp-jni.h +++ b/rtmp-client/src/main/cpp/librtmp-jni.h @@ -19,7 +19,7 @@ JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thiz, jstring url, jboolean isPublishMode, jlong rtmpPointer, jint sendTimeoutInMs, - jint receiveTimeoutInS); + jint receiveTimeoutInMs); /* * Class: net_butterflytv_rtmp_client_RtmpClient diff --git a/rtmp-client/src/main/cpp/librtmp/rtmp.c b/rtmp-client/src/main/cpp/librtmp/rtmp.c index b03baad..ef1c919 100644 --- a/rtmp-client/src/main/cpp/librtmp/rtmp.c +++ b/rtmp-client/src/main/cpp/librtmp/rtmp.c @@ -338,8 +338,8 @@ RTMP_Init(RTMP *r) r->m_nServerBW = 2500000; r->m_fAudioCodecs = 3191.0; r->m_fVideoCodecs = 252.0; - //making timeout value to 10 from 30 - r->Link.timeout = 10; + //Changing units to milliseconds. Changing from 10 to 10000. + r->Link.timeout = 10000; r->Link.swfAge = 30; } @@ -445,7 +445,7 @@ RTMP_SetupStream(RTMP *r, AVal *subscribepath, AVal *usherToken, int dStart, - int dStop, int bLiveStream, long int timeout) + int dStop, int bLiveStream, long int timeoutInMs) { RTMP_Log(RTMP_LOGDEBUG, "Protocol : %s", RTMPProtocolStrings[protocol&7]); RTMP_Log(RTMP_LOGDEBUG, "Hostname : %.*s", host->av_len, host->av_val); @@ -474,7 +474,7 @@ RTMP_SetupStream(RTMP *r, RTMP_Log(RTMP_LOGDEBUG, "StopTime : %d msec", dStop); RTMP_Log(RTMP_LOGDEBUG, "live : %s", bLiveStream ? "yes" : "no"); - RTMP_Log(RTMP_LOGDEBUG, "timeout : %ld sec", timeout); + RTMP_Log(RTMP_LOGDEBUG, "timeoutInMs : %ld sec", timeoutInMs); #ifdef CRYPTO if (swfSHA256Hash != NULL && swfSize > 0) @@ -518,7 +518,7 @@ RTMP_SetupStream(RTMP *r, r->Link.stopTime = dStop; if (bLiveStream) r->Link.lFlags |= RTMP_LF_LIVE; - r->Link.timeout = timeout; + r->Link.timeout = timeoutInMs; r->Link.protocol = protocol; r->Link.hostname = *host; @@ -949,7 +949,10 @@ RTMP_Connect0(RTMP *r, struct sockaddr * service) /* set timeout */ { - SET_RCVTIMEO(tv, r->Link.timeout); + struct timeval tv; + + tv.tv_sec = r->Link.timeout / 1000; + tv.tv_usec = (r->Link.timeout % 1000) * 1000; if (setsockopt (r->m_sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv))) { diff --git a/rtmp-client/src/main/cpp/librtmp/rtmp.h b/rtmp-client/src/main/cpp/librtmp/rtmp.h index 272746d..468f29e 100644 --- a/rtmp-client/src/main/cpp/librtmp/rtmp.h +++ b/rtmp-client/src/main/cpp/librtmp/rtmp.h @@ -176,7 +176,7 @@ extern "C" int swfAge; int protocol; - int timeout; /* connection timeout in seconds */ + int timeout; /* connection timeout in milliseconds */ int sendTimeoutInMs; /* socket send timeout in milliseconds */ #define RTMP_PUB_NAME 0x0001 /* send login to server */ @@ -312,7 +312,7 @@ extern "C" AVal *subscribepath, AVal *usherToken, int dStart, - int dStop, int bLiveStream, long int timeout); + int dStop, int bLiveStream, long int timeoutInMs); int RTMP_Connect(RTMP *r, RTMPPacket *cp); struct sockaddr; diff --git a/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java b/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java index 2e8ead9..4725408 100644 --- a/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java +++ b/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java @@ -19,7 +19,7 @@ public class RtmpClient { /** Socket send timeout value in milliseconds */ private int sendTimeoutInMs = TIMEOUT_IN_MS; /** Socket receive timeout value in seconds */ - private int receiveTimeoutInS = (TIMEOUT_IN_MS / 1000); + private int receiveTimeoutInMs = TIMEOUT_IN_MS; public static class RtmpIOException extends IOException { @@ -71,22 +71,23 @@ public void setSendTimeoutInMs(int sendTimeoutInMs) { /** * Sets the socket's receive timeout value - * @param receiveTimeoutInS - * The receive timeout value for the rtmp socket in seconds. + * @param receiveTimeoutInMs + * The receive timeout value for the rtmp socket in milliseconds. * Parameter expects a non-zero positive integer and will reset timeout to the default value - * (10s) if zero or a negative integer is passed. + * (10000 ms) if zero or a negative integer is passed. * */ - public void setReceiveTimeoutInS(int receiveTimeoutInS) { - if (receiveTimeoutInS > 0) { - this.receiveTimeoutInS = receiveTimeoutInS; + public void setReceiveTimeoutInMs(int receiveTimeoutInMs) { + if (receiveTimeoutInMs > 0) { + this.receiveTimeoutInMs = receiveTimeoutInMs; } else { - this.receiveTimeoutInS = (TIMEOUT_IN_MS / 1000); + this.receiveTimeoutInMs = TIMEOUT_IN_MS; } } public void open(String url, boolean isPublishMode) throws RtmpIOException { rtmpPointer = nativeAlloc(); - int result = nativeOpen(url, isPublishMode, rtmpPointer, sendTimeoutInMs, receiveTimeoutInS); + int result = nativeOpen(url, isPublishMode, rtmpPointer, sendTimeoutInMs, + receiveTimeoutInMs); if (result != OPEN_SUCCESS) { rtmpPointer = 0; throw new RtmpIOException(result); @@ -109,7 +110,7 @@ public void open(String url, boolean isPublishMode) throws RtmpIOException { * returns {@link #OPEN_SUCCESS} if it is successful, throws RtmpIOException if it is failed */ private native int nativeOpen(String url, boolean isPublishMode, long rtmpPointer, - int sendTimeoutInMs, int receiveTimeoutInS); + int sendTimeoutInMs, int receiveTimeoutInMs); /** * read data from rtmp connection From d5376211b1c5dc76465b780fee6d47a781ce5dd8 Mon Sep 17 00:00:00 2001 From: "Venkatarama NG. Avadhani" Date: Tue, 25 Jun 2019 11:51:00 +0530 Subject: [PATCH 4/4] Code refactor Changing timeout in Link structure to receiveTimeoutInMs. Remove InMs suffix from Java API that set the timeout values. --- rtmp-client/src/main/cpp/librtmp-jni.c | 2 +- rtmp-client/src/main/cpp/librtmp/rtmp.c | 15 +++++++-------- rtmp-client/src/main/cpp/librtmp/rtmp.h | 4 ++-- .../net/butterflytv/rtmp_client/RtmpClient.java | 4 ++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rtmp-client/src/main/cpp/librtmp-jni.c b/rtmp-client/src/main/cpp/librtmp-jni.c index c282964..192f723 100644 --- a/rtmp-client/src/main/cpp/librtmp-jni.c +++ b/rtmp-client/src/main/cpp/librtmp-jni.c @@ -41,7 +41,7 @@ Java_net_butterflytv_rtmp_1client_RtmpClient_nativeOpen(JNIEnv* env, jobject thi } RTMP_Init(rtmp); - rtmp->Link.timeout = receiveTimeoutInMs; + rtmp->Link.receiveTimeoutInMs = receiveTimeoutInMs; rtmp->Link.sendTimeoutInMs = sendTimeoutInMs; int ret = RTMP_SetupURL(rtmp, url); diff --git a/rtmp-client/src/main/cpp/librtmp/rtmp.c b/rtmp-client/src/main/cpp/librtmp/rtmp.c index ef1c919..b9221ee 100644 --- a/rtmp-client/src/main/cpp/librtmp/rtmp.c +++ b/rtmp-client/src/main/cpp/librtmp/rtmp.c @@ -338,8 +338,7 @@ RTMP_Init(RTMP *r) r->m_nServerBW = 2500000; r->m_fAudioCodecs = 3191.0; r->m_fVideoCodecs = 252.0; - //Changing units to milliseconds. Changing from 10 to 10000. - r->Link.timeout = 10000; + r->Link.receiveTimeoutInMs = 10000; r->Link.swfAge = 30; } @@ -518,7 +517,7 @@ RTMP_SetupStream(RTMP *r, r->Link.stopTime = dStop; if (bLiveStream) r->Link.lFlags |= RTMP_LF_LIVE; - r->Link.timeout = timeoutInMs; + r->Link.receiveTimeoutInMs = timeoutInMs; r->Link.protocol = protocol; r->Link.hostname = *host; @@ -585,7 +584,7 @@ static struct urlopt { "Stream stop position in milliseconds" }, { AVC("buffer"), OFF(m_nBufferMS), OPT_INT, 0, "Buffer time in milliseconds" }, - { AVC("timeout"), OFF(Link.timeout), OPT_INT, 0, + { AVC("timeout"), OFF(Link.receiveTimeoutInMs), OPT_INT, 0, "Session timeout in seconds" }, { AVC("pubUser"), OFF(Link.pubUser), OPT_STR, 0, "Publisher username" }, @@ -951,13 +950,13 @@ RTMP_Connect0(RTMP *r, struct sockaddr * service) { struct timeval tv; - tv.tv_sec = r->Link.timeout / 1000; - tv.tv_usec = (r->Link.timeout % 1000) * 1000; + tv.tv_sec = r->Link.receiveTimeoutInMs / 1000; + tv.tv_usec = (r->Link.receiveTimeoutInMs % 1000) * 1000; if (setsockopt (r->m_sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv))) { - RTMP_Log(RTMP_LOGERROR, "%s, Setting socket timeout to %ds failed!", - __FUNCTION__, r->Link.timeout); + RTMP_Log(RTMP_LOGERROR, "%s, Setting socket timeout to %dms failed!", + __FUNCTION__, r->Link.receiveTimeoutInMs); } } diff --git a/rtmp-client/src/main/cpp/librtmp/rtmp.h b/rtmp-client/src/main/cpp/librtmp/rtmp.h index 468f29e..d8c7444 100644 --- a/rtmp-client/src/main/cpp/librtmp/rtmp.h +++ b/rtmp-client/src/main/cpp/librtmp/rtmp.h @@ -176,8 +176,8 @@ extern "C" int swfAge; int protocol; - int timeout; /* connection timeout in milliseconds */ - int sendTimeoutInMs; /* socket send timeout in milliseconds */ + int receiveTimeoutInMs; + int sendTimeoutInMs; #define RTMP_PUB_NAME 0x0001 /* send login to server */ #define RTMP_PUB_RESP 0x0002 /* send salted password hash */ diff --git a/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java b/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java index 4725408..22a48dc 100644 --- a/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java +++ b/rtmp-client/src/main/java/net/butterflytv/rtmp_client/RtmpClient.java @@ -61,7 +61,7 @@ public RtmpIOException(int errorCode) { * Parameter expects a non-zero positive integer and will reset timeout to the default value * (10000 ms) if zero or a negative integer is passed. * */ - public void setSendTimeoutInMs(int sendTimeoutInMs) { + public void setSendTimeout(int sendTimeoutInMs) { if (sendTimeoutInMs > 0) { this.sendTimeoutInMs = sendTimeoutInMs; } else { @@ -76,7 +76,7 @@ public void setSendTimeoutInMs(int sendTimeoutInMs) { * Parameter expects a non-zero positive integer and will reset timeout to the default value * (10000 ms) if zero or a negative integer is passed. * */ - public void setReceiveTimeoutInMs(int receiveTimeoutInMs) { + public void setReceiveTimeout(int receiveTimeoutInMs) { if (receiveTimeoutInMs > 0) { this.receiveTimeoutInMs = receiveTimeoutInMs; } else {