diff --git a/.gitignore b/.gitignore index 5f8d045a..0fa1d705 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,5 @@ open-source/ outputs tags dependency - .vs +.vscode/ diff --git a/src/JNI/com/amazonaws/kinesis/video/producer/jni/KinesisVideoClientWrapper.cpp b/src/JNI/com/amazonaws/kinesis/video/producer/jni/KinesisVideoClientWrapper.cpp index 621673a9..4c926a45 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/KinesisVideoClientWrapper.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/KinesisVideoClientWrapper.cpp @@ -25,6 +25,9 @@ KinesisVideoClientWrapper::KinesisVideoClientWrapper(JNIEnv* env, CHECK_EXT(FALSE, "Couldn't retrieve the JavaVM reference."); } + // Null-initialize the clientInfo struct + MEMSET(&mDeviceInfo.clientInfo, 0, sizeof(mDeviceInfo.clientInfo)); + // Set the callbacks if (!setCallbacks(env, thiz)) { throwNativeException(env, EXCEPTION_NAME, "Failed to set the callbacks.", STATUS_INVALID_ARG); @@ -1013,6 +1016,9 @@ BOOL KinesisVideoClientWrapper::setCallbacks(JNIEnv* env, jobject thiz) mClientCallbacks.clientShutdownFn = NULL; mClientCallbacks.streamShutdownFn = NULL; + // TODO: Currently we set the shutdown callbacks to NULL. + // We need to expose these in the near future + // Extract the method IDs for the callbacks and set a global reference jclass thizCls = env->GetObjectClass(thiz); if (thizCls == NULL) { diff --git a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp index 515122e5..ed681a27 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -146,6 +146,7 @@ BOOL setDeviceInfo(JNIEnv *env, jobject deviceInfo, PDeviceInfo pDeviceInfo) CHK_JVM_EXCEPTION(env); if (!setClientInfo(env, clientInfo, &pDeviceInfo->clientInfo)) { + // TODO: Consider hard failing here rather than just logging. DLOGW("Failed getting/setting client info."); } } @@ -158,6 +159,8 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { STATUS retStatus = STATUS_SUCCESS; jmethodID methodId = NULL; const char *retChars; + jobject kvsRetryStrategyCallbacks = NULL; + jobject kvsRetryStrategy = NULL; CHECK(env != NULL && clientInfo != NULL && pClientInfo != NULL); @@ -168,7 +171,7 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { CHK(FALSE, STATUS_INVALID_OPERATION); } - // Retrieve the methods and call it + // Retrieve the methods and call them methodId = env->GetMethodID(cls, "getVersion", "()I"); if (methodId == NULL) { DLOGW("Couldn't find method id getVersion"); @@ -201,17 +204,17 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { CHK_JVM_EXCEPTION(env); } - methodId = env->GetMethodID(cls, "getServiceConnectionTimeout", "()J"); + methodId = env->GetMethodID(cls, "getServiceCallConnectionTimeout", "()J"); if (methodId == NULL) { - DLOGW("Couldn't find method id getServiceConnectionTimeout"); + DLOGW("Couldn't find method id getServiceCallConnectionTimeout"); } else { pClientInfo->serviceCallConnectionTimeout = env->CallLongMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); } - methodId = env->GetMethodID(cls, "getServiceCompletionTimeout", "()J"); + methodId = env->GetMethodID(cls, "getServiceCallCompletionTimeout", "()J"); if (methodId == NULL) { - DLOGW("Couldn't find method id getServiceCompletionTimeout"); + DLOGW("Couldn't find method id getServiceCallCompletionTimeout"); } else { pClientInfo->serviceCallCompletionTimeout = env->CallLongMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); @@ -249,10 +252,78 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { CHK_JVM_EXCEPTION(env); } + methodId = env->GetMethodID(cls, "getMetricLoggingPeriod", "()J"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getMetricLoggingPeriod"); + } else { + pClientInfo->metricLoggingPeriod = env->CallLongMethod(clientInfo, methodId); + CHK_JVM_EXCEPTION(env); + } + + methodId = env->GetMethodID(cls, "getReservedCallbackPeriod", "()J"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getReservedCallbackPeriod"); + } else { + pClientInfo->reservedCallbackPeriod = env->CallLongMethod(clientInfo, methodId); + CHK_JVM_EXCEPTION(env); + } + + methodId = env->GetMethodID(cls, "getKvsRetryStrategy", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategy;"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getKvsRetryStrategy"); + } else { + kvsRetryStrategy = (jobject) env->CallObjectMethod(clientInfo, methodId); + CHK_JVM_EXCEPTION(env); + + if (!setKvsRetryStrategy(env, kvsRetryStrategy, &pClientInfo->kvsRetryStrategy)) { + DLOGW("Failed getting/setting KvsRetryStrategy."); + } + } + CleanUp: return STATUS_FAILED(retStatus) ? FALSE : TRUE; } +BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrategy pKvsRetryStrategy) +{ + STATUS retStatus = STATUS_SUCCESS; + jmethodID methodId = NULL; + jclass cls = NULL; + + CHK(env != NULL && pKvsRetryStrategy != NULL, STATUS_NULL_ARG); + CHK_WARN(kvsRetryStrategy != NULL, STATUS_INVALID_OPERATION, "Failed to get Java kvsRetryStrategy class."); + + cls = env->GetObjectClass(kvsRetryStrategy); + CHK_WARN(cls != NULL, STATUS_INVALID_OPERATION, "Failed to create Java kvsRetryStrategy class."); + + methodId = env->GetMethodID(cls, "getRetryStrategy", "()J"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getRetryStrategy."); + } else { + // TODO: Implement once we have support for this in Java. + CHK_JVM_EXCEPTION(env); + } + + methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()J"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getRetryStrategyConfig."); + } else { + // TODO: Implement once we have support for this in Java. + CHK_JVM_EXCEPTION(env); + } + + methodId = env->GetMethodID(cls, "getRetryStrategyType", "()I"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getRetryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT."); + } else { + pKvsRetryStrategy->retryStrategyType = (KVS_RETRY_STRATEGY_TYPE) env->CallIntMethod(kvsRetryStrategy, methodId); + CHK_JVM_EXCEPTION(env); + } + + +CleanUp: + return STATUS_FAILED(retStatus) ? FALSE : TRUE; +} BOOL setTags(JNIEnv *env, jobjectArray tagArray, PTag* ppTags, PUINT32 pTagCount) { diff --git a/src/JNI/include/com/amazonaws/kinesis/video/producer/jni/Parameters.h b/src/JNI/include/com/amazonaws/kinesis/video/producer/jni/Parameters.h index 119c6626..732aa86d 100644 --- a/src/JNI/include/com/amazonaws/kinesis/video/producer/jni/Parameters.h +++ b/src/JNI/include/com/amazonaws/kinesis/video/producer/jni/Parameters.h @@ -17,4 +17,6 @@ BOOL setStreamDataBuffer(JNIEnv* env, jobject dataBuffer, UINT32 offset, PBYTE* BOOL releaseStreamDataBuffer(JNIEnv* env, jobject dataBuffer, UINT32 offset, PBYTE pBuffer); BOOL setTags(JNIEnv *env, jobjectArray tagArray, PTag* ppTags, PUINT32 pTagCount); VOID releaseTags(PTag tags); +BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy); + #endif // __KINESIS_VIDEO_PARAMETERS_CONVERSION_H__