diff --git a/rtmp-client/src/main/cpp/librtmp-jni.c b/rtmp-client/src/main/cpp/librtmp-jni.c index 7a2769a..49bc503 100644 --- a/rtmp-client/src/main/cpp/librtmp-jni.c +++ b/rtmp-client/src/main/cpp/librtmp-jni.c @@ -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)); @@ -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; } diff --git a/rtmp-client/src/main/cpp/librtmp/rtmp.c b/rtmp-client/src/main/cpp/librtmp/rtmp.c index 13362d9..88986cb 100644 --- a/rtmp-client/src/main/cpp/librtmp/rtmp.c +++ b/rtmp-client/src/main/cpp/librtmp/rtmp.c @@ -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; }