Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
Changing timeout in Link structure to receiveTimeoutInMs.

Remove InMs suffix from Java API that set the timeout values.
  • Loading branch information
vavadhani committed Jun 25, 2019
1 parent 9a138b5 commit d537621
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rtmp-client/src/main/cpp/librtmp-jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 7 additions & 8 deletions rtmp-client/src/main/cpp/librtmp/rtmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions rtmp-client/src/main/cpp/librtmp/rtmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit d537621

Please sign in to comment.