Skip to content

Commit

Permalink
Fix error return values from nativeRead
Browse files Browse the repository at this point in the history
Propagate the error codes from RTMP read to nativeRead function and
return errors as expected. This commit also corrects exception throws
from nativeRead.
  • Loading branch information
vavadhani committed Jun 4, 2019
1 parent 504b06f commit 2f91c36
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 15 additions & 2 deletions rtmp-client/src/main/cpp/librtmp-jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RtmpClient_nativeRead
RTMP *rtmp = (RTMP *) rtmpPointer;
if (rtmp == NULL) {
throwIOException(env, "First call open function");
return 0;
}
int connected = RTMP_IsConnected(rtmp);
if (!connected) {
throwIOException(env, "Connection to server is lost");
return 0;
}

char* data = malloc(size*sizeof(char));
Expand All @@ -90,8 +92,19 @@ JNIEXPORT jint JNICALL Java_net_butterflytv_rtmp_1client_RtmpClient_nativeRead
(*env)->SetByteArrayRegion(env, data_, offset, readCount, data); // copy
}
free(data);
if (readCount == 0) {
return -1;
if (readCount <= 0) {
switch (readCount) {
/* For return values READ_EOF and READ_COMPLETE, return -1 to indicate stream is
* complete. */
case RTMP_READ_EOF:
case RTMP_READ_COMPLETE:
return -1;

case RTMP_READ_IGNORE:
case RTMP_READ_ERROR:
default:
return 0;
}
}
return readCount;

This comment has been minimized.

Copy link
@umangsaini

umangsaini Jun 20, 2019

Indentation for return statement can be corrected.

}
Expand Down
7 changes: 3 additions & 4 deletions rtmp-client/src/main/cpp/librtmp/rtmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4975,12 +4975,11 @@ RTMP_Read(RTMP *r, char *buf, int size)
/* can't continue */
fail:
switch (r->m_read.status) {
case RTMP_READ_ERROR: /* corrupted stream, resume failed */
SetSockError(EINVAL);
case RTMP_READ_EOF:
case RTMP_READ_COMPLETE:
return 0;
case RTMP_READ_ERROR: /* corrupted stream, resume failed */
SetSockError(EINVAL);
return -1;
return r->m_read.status;
default:
break;
}
Expand Down

2 comments on commit 2f91c36

@vavadhani
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vavadhani
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposed fix for ant-media#69, also tracked on google/ExoPlayer#4337.

Please sign in to comment.