From 1be6167932f5920999d0dbfcc6a47c97cf39f6e5 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:32:14 -0700 Subject: [PATCH 01/17] Add init values --- .../kinesis/video/producer/jni/Parameters.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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..c949a1f9 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -161,6 +161,18 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { CHECK(env != NULL && clientInfo != NULL && pClientInfo != NULL); + // Initialize Java-unused members. These will be set to default values in PIC. + pClientInfo->kvsRetryStrategy.pRetryStrategy = NULL; + pClientInfo->kvsRetryStrategy.pRetryStrategyConfig = NULL; + pClientInfo->kvsRetryStrategy.retryStrategyType = KVS_RETRY_STRATEGY_DISABLED; + pClientInfo->metricLoggingPeriod = 0; + pClientInfo->reservedCallbackPeriod = 0; + pClientInfo->kvsRetryStrategyCallbacks.createRetryStrategyFn = NULL; + pClientInfo->kvsRetryStrategyCallbacks.getCurrentRetryAttemptNumberFn = NULL; + pClientInfo->kvsRetryStrategyCallbacks.freeRetryStrategyFn = NULL; + pClientInfo->kvsRetryStrategyCallbacks.executeRetryStrategyFn = NULL; + + // Load ClientInfo jclass cls = env->GetObjectClass(clientInfo); if (cls == NULL) { From 383f320fe3b04769f26ef2327fccf53fe4484d26 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:33:46 -0700 Subject: [PATCH 02/17] Remove extra line --- src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp | 1 - 1 file changed, 1 deletion(-) 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 c949a1f9..7bed3f0c 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -172,7 +172,6 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { pClientInfo->kvsRetryStrategyCallbacks.freeRetryStrategyFn = NULL; pClientInfo->kvsRetryStrategyCallbacks.executeRetryStrategyFn = NULL; - // Load ClientInfo jclass cls = env->GetObjectClass(clientInfo); if (cls == NULL) { From 4f5f30e825666c85a6f36267bb92c187054dd134 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Fri, 12 Apr 2024 21:24:15 -0700 Subject: [PATCH 03/17] Introduce the structure for setting KvsRetryStrategyCallbacks from Java SDK --- .gitignore | 2 +- .../kinesis/video/producer/jni/Parameters.cpp | 90 ++++++++++++++++++- 2 files changed, 87 insertions(+), 5 deletions(-) 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/Parameters.cpp b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp index 7bed3f0c..b4010637 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -167,10 +167,6 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { pClientInfo->kvsRetryStrategy.retryStrategyType = KVS_RETRY_STRATEGY_DISABLED; pClientInfo->metricLoggingPeriod = 0; pClientInfo->reservedCallbackPeriod = 0; - pClientInfo->kvsRetryStrategyCallbacks.createRetryStrategyFn = NULL; - pClientInfo->kvsRetryStrategyCallbacks.getCurrentRetryAttemptNumberFn = NULL; - pClientInfo->kvsRetryStrategyCallbacks.freeRetryStrategyFn = NULL; - pClientInfo->kvsRetryStrategyCallbacks.executeRetryStrategyFn = NULL; // Load ClientInfo jclass cls = env->GetObjectClass(clientInfo); @@ -259,11 +255,97 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { pClientInfo->automaticStreamingFlags = (AUTOMATIC_STREAMING_FLAGS) env->CallIntMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); } + + jobject kvsRetryStrategyCallbacks = NULL; + methodId = env->GetMethodID(cls, "getKvsRetryStrategyCallbacks", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getKvsRetryStrategyCallbacks"); + } else { + kvsRetryStrategyCallbacks = (jobject) env->CallObjectMethod(clientInfo, methodId); + CHK_JVM_EXCEPTION(env); + } + setKvsRetryStrategyCallbacks(env, kvsRetryStrategyCallbacks, &pClientInfo->kvsRetryStrategyCallbacks); CleanUp: return STATUS_FAILED(retStatus) ? FALSE : TRUE; } +VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks) +{ + jmethodID methodId = NULL; + jclass cls = NULL; + BOOL nullSetCallbacks = FALSE; + + if (kvsRetryStrategyCallbacks == NULL) { + nullSetCallbacks = TRUE; + goto CleanUp; + } + + jclass cls = env->GetObjectClass(kvsRetryStrategyCallbacks); + if (cls == NULL) { + DLOGW("Failed to create Java kvsRetryStrategyCallbacks class."); + nullSetCallbacks = TRUE; + goto CleanUp; + } + +. /* *** */ + /* NOTE: All kvsRetryStrategyCallbacks must be set to NULL in order for PIC to set them to the default callbacks.*/ +. /* *** */ + + methodId = env->GetMethodID(cls, "createRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;)V"); + if (methodId == NULL) { + DLOGW("Couldn't find method id createRetryStrategyFn, setting to NULL"); + pKvsRetryStrategyCallbacks->createRetryStrategyFn = NULL; + nullSetCallbacks = TRUE; + goto CleanUp; + } else { + // TODO: remove this comment used for testing + DLOGW("Found a createRetryStrategyFn - something went wrong..."); + // Set to Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks + // from the Producer Java SDK. + } + + methodId = env->GetMethodID(cls, "getCurrentRetryAttemptNumberFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;I)V"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getCurrentRetryAttemptNumberFn, setting to NULL"); + nullSetCallbacks = TRUE; + goto CleanUp; + } else { + // Set to Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks + // from the Producer Java SDK. + } + + methodId = env->GetMethodID(cls, "freeRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;)V"); + if (methodId == NULL) { + DLOGW("Couldn't find method id freeRetryStrategyFn, setting to NULL"); + nullSetCallbacks = TRUE; + goto CleanUp; + } else { + // Set to Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks + // from the Producer Java SDK. + } + + methodId = env->GetMethodID(cls, "executeRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;J)V"); + if (methodId == NULL) { + DLOGW("Couldn't find method id executeRetryStrategyFn, setting to NULL"); + nullSetCallbacks = TRUE; + goto CleanUp; + } else { + // Set to Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks + // from the Producer Java SDK. + } + +CleanUp: + + // NOTE: If ANY RetryStrategyCallbacks are NULL, then ALL of them will be set to default callbacks in PIC. + if (nullSetCallbacks) { + DLOGI("Setting kvsRetryStrategyCallbacks functions to NULL to be set to defaults callbacks in PIC"); + pKvsRetryStrategyCallbacks->createRetryStrategyFn = NULL; + pKvsRetryStrategyCallbacks->getCurrentRetryAttemptNumberFn = NULL; + pKvsRetryStrategyCallbacks->freeRetryStrategyFn = NULL; + pKvsRetryStrategyCallbacks->executeRetryStrategyFn = NULL; + } +} BOOL setTags(JNIEnv *env, jobjectArray tagArray, PTag* ppTags, PUINT32 pTagCount) { From 20bfd1746f984ce6a72ca84abcb06e616d350330 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Fri, 12 Apr 2024 22:00:28 -0700 Subject: [PATCH 04/17] Fix compiler errors from prev commit --- .../amazonaws/kinesis/video/producer/jni/Parameters.cpp | 8 ++++---- .../com/amazonaws/kinesis/video/producer/jni/Parameters.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) 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 b4010637..a8fca2ac 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -158,6 +158,7 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { STATUS retStatus = STATUS_SUCCESS; jmethodID methodId = NULL; const char *retChars; + jobject kvsRetryStrategyCallbacks = NULL; CHECK(env != NULL && clientInfo != NULL && pClientInfo != NULL); @@ -256,7 +257,6 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { CHK_JVM_EXCEPTION(env); } - jobject kvsRetryStrategyCallbacks = NULL; methodId = env->GetMethodID(cls, "getKvsRetryStrategyCallbacks", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;"); if (methodId == NULL) { DLOGW("Couldn't find method id getKvsRetryStrategyCallbacks"); @@ -281,16 +281,16 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks goto CleanUp; } - jclass cls = env->GetObjectClass(kvsRetryStrategyCallbacks); + cls = env->GetObjectClass(kvsRetryStrategyCallbacks); if (cls == NULL) { DLOGW("Failed to create Java kvsRetryStrategyCallbacks class."); nullSetCallbacks = TRUE; goto CleanUp; } -. /* *** */ + /* *** */ /* NOTE: All kvsRetryStrategyCallbacks must be set to NULL in order for PIC to set them to the default callbacks.*/ -. /* *** */ + /* *** */ methodId = env->GetMethodID(cls, "createRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;)V"); if (methodId == NULL) { 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..e962b17c 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); +VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks); + #endif // __KINESIS_VIDEO_PARAMETERS_CONVERSION_H__ From 61a745c9b6d394035bcf0d9d042cfa2805192281 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:20:00 -0700 Subject: [PATCH 05/17] Start on the other members --- .../kinesis/video/producer/jni/Parameters.cpp | 88 ++++++++++++++++++- 1 file changed, 85 insertions(+), 3 deletions(-) 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 a8fca2ac..12399dbc 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -159,6 +159,7 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { jmethodID methodId = NULL; const char *retChars; jobject kvsRetryStrategyCallbacks = NULL; + jobject kvsRetryStrategy = NULL; CHECK(env != NULL && clientInfo != NULL && pClientInfo != NULL); @@ -176,7 +177,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"); @@ -256,6 +257,22 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { pClientInfo->automaticStreamingFlags = (AUTOMATIC_STREAMING_FLAGS) env->CallIntMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); } + + // Initialize Java-unused members. These will be set to default values in PIC. + pClientInfo->kvsRetryStrategy.pRetryStrategy = NULL; + pClientInfo->kvsRetryStrategy.pRetryStrategyConfig = NULL; + pClientInfo->kvsRetryStrategy.retryStrategyType = KVS_RETRY_STRATEGY_DISABLED; + pClientInfo->metricLoggingPeriod = 0; + pClientInfo->reservedCallbackPeriod = 0; + + 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); + } + setKvsRetryStrategy(env, kvsRetryStrategy, &pClientInfo->kvsRetryStrategy); methodId = env->GetMethodID(cls, "getKvsRetryStrategyCallbacks", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;"); if (methodId == NULL) { @@ -270,6 +287,73 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { return STATUS_FAILED(retStatus) ? FALSE : TRUE; } +VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy) +{ + jmethodID methodId = NULL; + jclass cls = NULL; + BOOL nullSetCallbacks = FALSE; + + if (kvsRetryStrategy == NULL) { + nullSetCallbacks = TRUE; + goto CleanUp; + } + + cls = env->GetObjectClass(kvsRetryStrategy); + if (cls == NULL) { + DLOGW("Failed to create Java kvsRetryStrategy class."); + nullSetCallbacks = TRUE; + goto CleanUp; + } + + // Pointer to metadata/state/details for the retry strategy. + // The actual data type is abstracted and will be inferred by + // the RetryHandlerFn + PRetryStrategy pRetryStrategy; + // Optional configuration used to build the retry strategy. Once the retry strategy is created, + // any changes to the config will be useless. + PRetryStrategyConfig pRetryStrategyConfig; + // Retry strategy type as defined in the above enum + KVS_RETRY_STRATEGY_TYPE retryStrategyType; + + + methodId = env->GetMethodID(cls, "getRetryStrategy", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategy"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getRetryStrategy, setting pRetryStrategy to null."); + pkvsRetryStrategy->pRetryStrategy = NULL; + } else { + // Set to Java class or member once we implement Java support. + } + + methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategy"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getRetryStrategyConfig, setting pRetryStrategyConfig to null."); + pkvsRetryStrategy->pRetryStrategyConfig = NULL; + } else { + // Set to Java class or member once we implement Java support. + } + + methodId = env->GetMethodID(cls, "getRetryStrategy", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategy"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getRetryStrategy, setting pRetryStrategy to null."); + pkvsRetryStrategy->pRetryStrategy = NULL; + } else { + // Set to Java class or member once we implement Java support. + } + + + +CleanUp: + + // NOTE: If ANY RetryStrategyCallbacks are NULL, then ALL of them will be set to default callbacks in PIC. + if (nullSetCallbacks) { + DLOGI("Setting kvsRetryStrategyCallbacks functions to NULL to be set to defaults callbacks in PIC"); + pKvsRetryStrategyCallbacks->createRetryStrategyFn = NULL; + pKvsRetryStrategyCallbacks->getCurrentRetryAttemptNumberFn = NULL; + pKvsRetryStrategyCallbacks->freeRetryStrategyFn = NULL; + pKvsRetryStrategyCallbacks->executeRetryStrategyFn = NULL; + } +} + VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks) { jmethodID methodId = NULL; @@ -299,8 +383,6 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks nullSetCallbacks = TRUE; goto CleanUp; } else { - // TODO: remove this comment used for testing - DLOGW("Found a createRetryStrategyFn - something went wrong..."); // Set to Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks // from the Producer Java SDK. } From 12fa02c4f863e1b5e28fcae2230eb89c2d3d917b Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Sat, 13 Apr 2024 22:29:08 -0700 Subject: [PATCH 06/17] Done, not tested --- .../kinesis/video/producer/jni/Parameters.cpp | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-) 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 12399dbc..618824d9 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -163,13 +163,6 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { CHECK(env != NULL && clientInfo != NULL && pClientInfo != NULL); - // Initialize Java-unused members. These will be set to default values in PIC. - pClientInfo->kvsRetryStrategy.pRetryStrategy = NULL; - pClientInfo->kvsRetryStrategy.pRetryStrategyConfig = NULL; - pClientInfo->kvsRetryStrategy.retryStrategyType = KVS_RETRY_STRATEGY_DISABLED; - pClientInfo->metricLoggingPeriod = 0; - pClientInfo->reservedCallbackPeriod = 0; - // Load ClientInfo jclass cls = env->GetObjectClass(clientInfo); if (cls == NULL) { @@ -258,12 +251,23 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { CHK_JVM_EXCEPTION(env); } - // Initialize Java-unused members. These will be set to default values in PIC. - pClientInfo->kvsRetryStrategy.pRetryStrategy = NULL; - pClientInfo->kvsRetryStrategy.pRetryStrategyConfig = NULL; - pClientInfo->kvsRetryStrategy.retryStrategyType = KVS_RETRY_STRATEGY_DISABLED; - pClientInfo->metricLoggingPeriod = 0; - pClientInfo->reservedCallbackPeriod = 0; + methodId = env->GetMethodID(cls, "getMetricLoggingPeriod", "()J"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getMetricLoggingPeriod"); + pClientInfo->metricLoggingPeriod = 0; + } else { + pClientInfo->metricLoggingPeriod = (jobject) env->CallObjectMethod(clientInfo, methodId); + CHK_JVM_EXCEPTION(env); + } + + methodId = env->GetMethodID(cls, "getReservedCallbackPeriod", "()J"); + if (methodId == NULL) { + DLOGW("Couldn't find method id getReservedCallbackPeriod"); + pClientInfo->reservedCallbackPeriod = 0; + } else { + pClientInfo->reservedCallbackPeriod = (jobject) env->CallObjectMethod(clientInfo, methodId); + CHK_JVM_EXCEPTION(env); + } methodId = env->GetMethodID(cls, "getKvsRetryStrategy", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategy;"); if (methodId == NULL) { @@ -291,31 +295,20 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRet { jmethodID methodId = NULL; jclass cls = NULL; - BOOL nullSetCallbacks = FALSE; + BOOL nullKvsRetryStrategy = FALSE; if (kvsRetryStrategy == NULL) { - nullSetCallbacks = TRUE; + nullKvsRetryStrategy = TRUE; goto CleanUp; } cls = env->GetObjectClass(kvsRetryStrategy); if (cls == NULL) { DLOGW("Failed to create Java kvsRetryStrategy class."); - nullSetCallbacks = TRUE; + nullKvsRetryStrategy = TRUE; goto CleanUp; } - // Pointer to metadata/state/details for the retry strategy. - // The actual data type is abstracted and will be inferred by - // the RetryHandlerFn - PRetryStrategy pRetryStrategy; - // Optional configuration used to build the retry strategy. Once the retry strategy is created, - // any changes to the config will be useless. - PRetryStrategyConfig pRetryStrategyConfig; - // Retry strategy type as defined in the above enum - KVS_RETRY_STRATEGY_TYPE retryStrategyType; - - methodId = env->GetMethodID(cls, "getRetryStrategy", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategy"); if (methodId == NULL) { DLOGW("Couldn't find method id getRetryStrategy, setting pRetryStrategy to null."); @@ -324,7 +317,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRet // Set to Java class or member once we implement Java support. } - methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategy"); + methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyConfig"); if (methodId == NULL) { DLOGW("Couldn't find method id getRetryStrategyConfig, setting pRetryStrategyConfig to null."); pkvsRetryStrategy->pRetryStrategyConfig = NULL; @@ -332,25 +325,21 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRet // Set to Java class or member once we implement Java support. } - methodId = env->GetMethodID(cls, "getRetryStrategy", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategy"); + methodId = env->GetMethodID(cls, "getretryStrategyType", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyType"); if (methodId == NULL) { - DLOGW("Couldn't find method id getRetryStrategy, setting pRetryStrategy to null."); - pkvsRetryStrategy->pRetryStrategy = NULL; + DLOGW("Couldn't find method id getretryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT."); + pkvsRetryStrategy->pRetryStrategy = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; } else { // Set to Java class or member once we implement Java support. } - CleanUp: - - // NOTE: If ANY RetryStrategyCallbacks are NULL, then ALL of them will be set to default callbacks in PIC. - if (nullSetCallbacks) { - DLOGI("Setting kvsRetryStrategyCallbacks functions to NULL to be set to defaults callbacks in PIC"); - pKvsRetryStrategyCallbacks->createRetryStrategyFn = NULL; - pKvsRetryStrategyCallbacks->getCurrentRetryAttemptNumberFn = NULL; - pKvsRetryStrategyCallbacks->freeRetryStrategyFn = NULL; - pKvsRetryStrategyCallbacks->executeRetryStrategyFn = NULL; + if (nullKvsRetryStrategy) { + DLOGI("Setting kvsRetryStrategy members to NULL/default values."); + pkvsRetryStrategy->pRetryStrategy = NULL; + pkvsRetryStrategy->pRetryStrategyConfig = NULL; + pkvsRetryStrategy->pRetryStrategy = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; } } From 77fc8dfffe0234bd1079af62665dbe2e5a065ece Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:18:18 -0700 Subject: [PATCH 07/17] Fix java getter types --- .../com/amazonaws/kinesis/video/producer/jni/Parameters.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 618824d9..ef7dbf4f 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -256,7 +256,7 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { DLOGW("Couldn't find method id getMetricLoggingPeriod"); pClientInfo->metricLoggingPeriod = 0; } else { - pClientInfo->metricLoggingPeriod = (jobject) env->CallObjectMethod(clientInfo, methodId); + pClientInfo->metricLoggingPeriod = env->CallLongMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); } @@ -265,7 +265,7 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { DLOGW("Couldn't find method id getReservedCallbackPeriod"); pClientInfo->reservedCallbackPeriod = 0; } else { - pClientInfo->reservedCallbackPeriod = (jobject) env->CallObjectMethod(clientInfo, methodId); + pClientInfo->reservedCallbackPeriod = env->CallLongMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); } From 745d6672eb3faae4862311b7d98bb513d8b3fa05 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:33:00 -0700 Subject: [PATCH 08/17] Fix typos, build issues --- .../kinesis/video/producer/jni/Parameters.cpp | 14 +++++++------- .../kinesis/video/producer/jni/Parameters.h | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) 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 ef7dbf4f..e4b63ee1 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -291,7 +291,7 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { return STATUS_FAILED(retStatus) ? FALSE : TRUE; } -VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy) +VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrategy pKvsRetryStrategy) { jmethodID methodId = NULL; jclass cls = NULL; @@ -312,7 +312,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRet methodId = env->GetMethodID(cls, "getRetryStrategy", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategy"); if (methodId == NULL) { DLOGW("Couldn't find method id getRetryStrategy, setting pRetryStrategy to null."); - pkvsRetryStrategy->pRetryStrategy = NULL; + pKvsRetryStrategy->pRetryStrategy = NULL; } else { // Set to Java class or member once we implement Java support. } @@ -320,7 +320,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRet methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyConfig"); if (methodId == NULL) { DLOGW("Couldn't find method id getRetryStrategyConfig, setting pRetryStrategyConfig to null."); - pkvsRetryStrategy->pRetryStrategyConfig = NULL; + pKvsRetryStrategy->pRetryStrategyConfig = NULL; } else { // Set to Java class or member once we implement Java support. } @@ -328,7 +328,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRet methodId = env->GetMethodID(cls, "getretryStrategyType", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyType"); if (methodId == NULL) { DLOGW("Couldn't find method id getretryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT."); - pkvsRetryStrategy->pRetryStrategy = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; + pKvsRetryStrategy->pRetryStrategy = NULL; } else { // Set to Java class or member once we implement Java support. } @@ -337,9 +337,9 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRet CleanUp: if (nullKvsRetryStrategy) { DLOGI("Setting kvsRetryStrategy members to NULL/default values."); - pkvsRetryStrategy->pRetryStrategy = NULL; - pkvsRetryStrategy->pRetryStrategyConfig = NULL; - pkvsRetryStrategy->pRetryStrategy = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; + pKvsRetryStrategy->pRetryStrategy = NULL; + pKvsRetryStrategy->pRetryStrategyConfig = NULL; + pKvsRetryStrategy->pRetryStrategy = NULL; } } 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 e962b17c..9f84e73f 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 @@ -18,5 +18,6 @@ BOOL releaseStreamDataBuffer(JNIEnv* env, jobject dataBuffer, UINT32 offset, PBY BOOL setTags(JNIEnv *env, jobjectArray tagArray, PTag* ppTags, PUINT32 pTagCount); VOID releaseTags(PTag tags); VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks); +VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy); #endif // __KINESIS_VIDEO_PARAMETERS_CONVERSION_H__ From d5af077aad637bed26c5c186d22bb5e581240127 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:34:03 -0700 Subject: [PATCH 09/17] Add null checks --- .../com/amazonaws/kinesis/video/producer/jni/Parameters.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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 e4b63ee1..540d74b2 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -297,6 +297,8 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg jclass cls = NULL; BOOL nullKvsRetryStrategy = FALSE; + CHECK(env != NULL && pKvsRetryStrategy != NULL); + if (kvsRetryStrategy == NULL) { nullKvsRetryStrategy = TRUE; goto CleanUp; @@ -349,6 +351,8 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks jclass cls = NULL; BOOL nullSetCallbacks = FALSE; + CHECK(env != NULL && pKvsRetryStrategyCallbacks != NULL); + if (kvsRetryStrategyCallbacks == NULL) { nullSetCallbacks = TRUE; goto CleanUp; From d91592d077d8b8456fbb1e0aa681d225d92d6eb6 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Wed, 17 Apr 2024 21:36:18 -0700 Subject: [PATCH 10/17] Java getters now return null or 0 --- .../jni/KinesisVideoClientWrapper.cpp | 3 +++ .../kinesis/video/producer/jni/Parameters.cpp | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) 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..92478758 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/KinesisVideoClientWrapper.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/KinesisVideoClientWrapper.cpp @@ -1013,6 +1013,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 540d74b2..185696ad 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -316,7 +316,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg DLOGW("Couldn't find method id getRetryStrategy, setting pRetryStrategy to null."); pKvsRetryStrategy->pRetryStrategy = NULL; } else { - // Set to Java class or member once we implement Java support. + pKvsRetryStrategy->pRetryStrategy = env->CallLongMethod(kvsRetryStrategy, methodId); } methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyConfig"); @@ -324,7 +324,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg DLOGW("Couldn't find method id getRetryStrategyConfig, setting pRetryStrategyConfig to null."); pKvsRetryStrategy->pRetryStrategyConfig = NULL; } else { - // Set to Java class or member once we implement Java support. + pKvsRetryStrategy->pRetryStrategyConfig = env->CallLongMethod(kvsRetryStrategy, methodId); } methodId = env->GetMethodID(cls, "getretryStrategyType", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyType"); @@ -332,7 +332,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg DLOGW("Couldn't find method id getretryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT."); pKvsRetryStrategy->pRetryStrategy = NULL; } else { - // Set to Java class or member once we implement Java support. + pKvsRetryStrategy->pRetryStrategy = env->CallObjectMethod(kvsRetryStrategy, methodId); } @@ -366,18 +366,20 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks } /* *** */ - /* NOTE: All kvsRetryStrategyCallbacks must be set to NULL in order for PIC to set them to the default callbacks.*/ + /* NOTE: If ANY of the kvsRetryStrategyCallbacks are NULL, then they will ALL be set to defaults in PIC. */ + /* So, below, if any are NULL, we will set them all to NULL in cleanup */ /* *** */ methodId = env->GetMethodID(cls, "createRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;)V"); if (methodId == NULL) { DLOGW("Couldn't find method id createRetryStrategyFn, setting to NULL"); - pKvsRetryStrategyCallbacks->createRetryStrategyFn = NULL; nullSetCallbacks = TRUE; goto CleanUp; } else { - // Set to Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks + // Use Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks // from the Producer Java SDK. + nullSetCallbacks = TRUE; + goto CleanUp; } methodId = env->GetMethodID(cls, "getCurrentRetryAttemptNumberFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;I)V"); @@ -386,8 +388,10 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks nullSetCallbacks = TRUE; goto CleanUp; } else { - // Set to Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks + // Use Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks // from the Producer Java SDK. + nullSetCallbacks = TRUE; + goto CleanUp; } methodId = env->GetMethodID(cls, "freeRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;)V"); @@ -396,8 +400,10 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks nullSetCallbacks = TRUE; goto CleanUp; } else { - // Set to Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks + // Use Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks // from the Producer Java SDK. + nullSetCallbacks = TRUE; + goto CleanUp; } methodId = env->GetMethodID(cls, "executeRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;J)V"); @@ -406,8 +412,10 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks nullSetCallbacks = TRUE; goto CleanUp; } else { - // Set to Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks + // Use Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks // from the Producer Java SDK. + nullSetCallbacks = TRUE; + goto CleanUp; } CleanUp: From eb64a6b68f507c92fecb5665d6b13fb806e48205 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Wed, 17 Apr 2024 23:10:10 -0700 Subject: [PATCH 11/17] Fix retryStrategyType and compile errors --- .../kinesis/video/producer/jni/Parameters.cpp | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) 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 185696ad..6ea9fe47 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -203,17 +203,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); @@ -316,7 +316,12 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg DLOGW("Couldn't find method id getRetryStrategy, setting pRetryStrategy to null."); pKvsRetryStrategy->pRetryStrategy = NULL; } else { - pKvsRetryStrategy->pRetryStrategy = env->CallLongMethod(kvsRetryStrategy, methodId); + if (env->CallLongMethod(kvsRetryStrategy, methodId) == 0) { + pKvsRetryStrategy->pRetryStrategy = NULL; + } else { + // TODO: Implement once we have support for this in Java, setting to null for safety. + pKvsRetryStrategy->pRetryStrategy = NULL; + } } methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyConfig"); @@ -324,15 +329,20 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg DLOGW("Couldn't find method id getRetryStrategyConfig, setting pRetryStrategyConfig to null."); pKvsRetryStrategy->pRetryStrategyConfig = NULL; } else { - pKvsRetryStrategy->pRetryStrategyConfig = env->CallLongMethod(kvsRetryStrategy, methodId); + if (env->CallLongMethod(kvsRetryStrategy, methodId) == 0) { + pKvsRetryStrategy->pRetryStrategyConfig = NULL; + } else { + // TODO: Implement once we have support for this in Java, setting to null for safety. + pKvsRetryStrategy->pRetryStrategyConfig = NULL; + } } - methodId = env->GetMethodID(cls, "getretryStrategyType", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyType"); + methodId = env->GetMethodID(cls, "getRetryStrategyType", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyType"); if (methodId == NULL) { - DLOGW("Couldn't find method id getretryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT."); - pKvsRetryStrategy->pRetryStrategy = NULL; + DLOGW("Couldn't find method id getRetryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT."); + pKvsRetryStrategy->retryStrategyType = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; } else { - pKvsRetryStrategy->pRetryStrategy = env->CallObjectMethod(kvsRetryStrategy, methodId); + pKvsRetryStrategy->retryStrategyType = (KVS_RETRY_STRATEGY_TYPE) env->CallIntMethod(kvsRetryStrategy, methodId); } @@ -341,7 +351,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg DLOGI("Setting kvsRetryStrategy members to NULL/default values."); pKvsRetryStrategy->pRetryStrategy = NULL; pKvsRetryStrategy->pRetryStrategyConfig = NULL; - pKvsRetryStrategy->pRetryStrategy = NULL; + pKvsRetryStrategy->retryStrategyType = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; } } From 8f7b2488bce03345b5d9175438de6a310983cdfb Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:27:46 -0700 Subject: [PATCH 12/17] Install pkgconfiglite for Windows CI --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27442f27..cfaed44b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -321,6 +321,7 @@ jobs: Move-Item -Path "D:\a\amazon-kinesis-video-streams-producer-sdk-cpp\amazon-kinesis-video-streams-producer-sdk-cpp\*" -Destination "C:\amazon-kinesis-video-streams-producer-sdk-cpp" - name: Install dependencies run: | + choco install pkgconfiglite choco install nasm strawberryperl choco install gstreamer --version=1.22.8 choco install gstreamer-devel --version=1.22.8 From 5a3e503f56b5e085fe15a8fecae9a9a37aae3a0a Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Tue, 23 Apr 2024 10:05:19 -0700 Subject: [PATCH 13/17] Setter funcs return bool, add missing CHK_JVM_EXCEPTIONs --- .../kinesis/video/producer/jni/Parameters.cpp | 27 ++++++++++++++----- .../kinesis/video/producer/jni/Parameters.h | 4 +-- 2 files changed, 22 insertions(+), 9 deletions(-) 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 6ea9fe47..65fd525b 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -276,7 +276,9 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { kvsRetryStrategy = (jobject) env->CallObjectMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); } - setKvsRetryStrategy(env, kvsRetryStrategy, &pClientInfo->kvsRetryStrategy); + if (!setKvsRetryStrategy(env, kvsRetryStrategy, &pClientInfo->kvsRetryStrategy)) { + DLOGW("Failed getting/setting KvsRetryStrategy."); + } methodId = env->GetMethodID(cls, "getKvsRetryStrategyCallbacks", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;"); if (methodId == NULL) { @@ -285,14 +287,17 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { kvsRetryStrategyCallbacks = (jobject) env->CallObjectMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); } - setKvsRetryStrategyCallbacks(env, kvsRetryStrategyCallbacks, &pClientInfo->kvsRetryStrategyCallbacks); + if (!setKvsRetryStrategyCallbacks(env, kvsRetryStrategyCallbacks, &pClientInfo->kvsRetryStrategyCallbacks)) { + DLOGW("Failed getting/setting KvsRetryStrategyCallbacks."); + } CleanUp: return STATUS_FAILED(retStatus) ? FALSE : TRUE; } -VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrategy pKvsRetryStrategy) +BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrategy pKvsRetryStrategy) { + STATUS retStatus = STATUS_SUCCESS; jmethodID methodId = NULL; jclass cls = NULL; BOOL nullKvsRetryStrategy = FALSE; @@ -306,8 +311,9 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg cls = env->GetObjectClass(kvsRetryStrategy); if (cls == NULL) { - DLOGW("Failed to create Java kvsRetryStrategy class."); nullKvsRetryStrategy = TRUE; + DLOGW("Failed to create Java kvsRetryStrategy class."); + CHK(FALSE, STATUS_INVALID_OPERATION); goto CleanUp; } @@ -322,9 +328,10 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg // TODO: Implement once we have support for this in Java, setting to null for safety. pKvsRetryStrategy->pRetryStrategy = NULL; } + CHK_JVM_EXCEPTION(env); } - methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyConfig"); + methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()J"); if (methodId == NULL) { DLOGW("Couldn't find method id getRetryStrategyConfig, setting pRetryStrategyConfig to null."); pKvsRetryStrategy->pRetryStrategyConfig = NULL; @@ -335,6 +342,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg // TODO: Implement once we have support for this in Java, setting to null for safety. pKvsRetryStrategy->pRetryStrategyConfig = NULL; } + CHK_JVM_EXCEPTION(env); } methodId = env->GetMethodID(cls, "getRetryStrategyType", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyType"); @@ -343,6 +351,7 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg pKvsRetryStrategy->retryStrategyType = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; } else { pKvsRetryStrategy->retryStrategyType = (KVS_RETRY_STRATEGY_TYPE) env->CallIntMethod(kvsRetryStrategy, methodId); + CHK_JVM_EXCEPTION(env); } @@ -353,10 +362,12 @@ VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg pKvsRetryStrategy->pRetryStrategyConfig = NULL; pKvsRetryStrategy->retryStrategyType = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; } + return STATUS_FAILED(retStatus) ? FALSE : TRUE; } -VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks) +BOOL setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks) { + STATUS retStatus = STATUS_SUCCESS; jmethodID methodId = NULL; jclass cls = NULL; BOOL nullSetCallbacks = FALSE; @@ -370,8 +381,9 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks cls = env->GetObjectClass(kvsRetryStrategyCallbacks); if (cls == NULL) { - DLOGW("Failed to create Java kvsRetryStrategyCallbacks class."); nullSetCallbacks = TRUE; + DLOGW("Failed to create Java kvsRetryStrategyCallbacks class."); + CHK(FALSE, STATUS_INVALID_OPERATION); goto CleanUp; } @@ -438,6 +450,7 @@ VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks->freeRetryStrategyFn = NULL; pKvsRetryStrategyCallbacks->executeRetryStrategyFn = NULL; } + 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 9f84e73f..8ced911e 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,7 +17,7 @@ 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); -VOID setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks); -VOID setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy); +BOOL setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks); +BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy); #endif // __KINESIS_VIDEO_PARAMETERS_CONVERSION_H__ From e44628d20b41b56acc9f19e8ae55f59d62e8f75f Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:59:13 -0700 Subject: [PATCH 14/17] Address comments --- .../jni/KinesisVideoClientWrapper.cpp | 3 + .../kinesis/video/producer/jni/Parameters.cpp | 135 ++---------------- 2 files changed, 15 insertions(+), 123 deletions(-) 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 92478758..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); 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 65fd525b..60abc205 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."); } } @@ -254,7 +255,6 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { methodId = env->GetMethodID(cls, "getMetricLoggingPeriod", "()J"); if (methodId == NULL) { DLOGW("Couldn't find method id getMetricLoggingPeriod"); - pClientInfo->metricLoggingPeriod = 0; } else { pClientInfo->metricLoggingPeriod = env->CallLongMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); @@ -263,7 +263,6 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { methodId = env->GetMethodID(cls, "getReservedCallbackPeriod", "()J"); if (methodId == NULL) { DLOGW("Couldn't find method id getReservedCallbackPeriod"); - pClientInfo->reservedCallbackPeriod = 0; } else { pClientInfo->reservedCallbackPeriod = env->CallLongMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); @@ -275,11 +274,13 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { } else { kvsRetryStrategy = (jobject) env->CallObjectMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); - } - if (!setKvsRetryStrategy(env, kvsRetryStrategy, &pClientInfo->kvsRetryStrategy)) { - DLOGW("Failed getting/setting KvsRetryStrategy."); + + if (!setKvsRetryStrategy(env, kvsRetryStrategy, &pClientInfo->kvsRetryStrategy)) { + DLOGW("Failed getting/setting KvsRetryStrategy."); + } } + // Note: kvsRetryStrategyCallbacks is not supported yet in Java, the below is a skeleton for the future implementation. methodId = env->GetMethodID(cls, "getKvsRetryStrategyCallbacks", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;"); if (methodId == NULL) { DLOGW("Couldn't find method id getKvsRetryStrategyCallbacks"); @@ -287,9 +288,6 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { kvsRetryStrategyCallbacks = (jobject) env->CallObjectMethod(clientInfo, methodId); CHK_JVM_EXCEPTION(env); } - if (!setKvsRetryStrategyCallbacks(env, kvsRetryStrategyCallbacks, &pClientInfo->kvsRetryStrategyCallbacks)) { - DLOGW("Failed getting/setting KvsRetryStrategyCallbacks."); - } CleanUp: return STATUS_FAILED(retStatus) ? FALSE : TRUE; @@ -300,52 +298,37 @@ BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg STATUS retStatus = STATUS_SUCCESS; jmethodID methodId = NULL; jclass cls = NULL; - BOOL nullKvsRetryStrategy = FALSE; CHECK(env != NULL && pKvsRetryStrategy != NULL); if (kvsRetryStrategy == NULL) { - nullKvsRetryStrategy = TRUE; goto CleanUp; } cls = env->GetObjectClass(kvsRetryStrategy); if (cls == NULL) { - nullKvsRetryStrategy = TRUE; DLOGW("Failed to create Java kvsRetryStrategy class."); CHK(FALSE, STATUS_INVALID_OPERATION); goto CleanUp; } - methodId = env->GetMethodID(cls, "getRetryStrategy", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategy"); + methodId = env->GetMethodID(cls, "getRetryStrategy", "()J"); if (methodId == NULL) { - DLOGW("Couldn't find method id getRetryStrategy, setting pRetryStrategy to null."); - pKvsRetryStrategy->pRetryStrategy = NULL; + DLOGW("Couldn't find method id getRetryStrategy."); } else { - if (env->CallLongMethod(kvsRetryStrategy, methodId) == 0) { - pKvsRetryStrategy->pRetryStrategy = NULL; - } else { - // TODO: Implement once we have support for this in Java, setting to null for safety. - pKvsRetryStrategy->pRetryStrategy = NULL; - } + // 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, setting pRetryStrategyConfig to null."); - pKvsRetryStrategy->pRetryStrategyConfig = NULL; + DLOGW("Couldn't find method id getRetryStrategyConfig."); } else { - if (env->CallLongMethod(kvsRetryStrategy, methodId) == 0) { - pKvsRetryStrategy->pRetryStrategyConfig = NULL; - } else { - // TODO: Implement once we have support for this in Java, setting to null for safety. - pKvsRetryStrategy->pRetryStrategyConfig = NULL; - } + // TODO: Implement once we have support for this in Java. CHK_JVM_EXCEPTION(env); } - methodId = env->GetMethodID(cls, "getRetryStrategyType", "()Lcom/amazonaws/kinesisvideo/producer/RetryStrategyType"); + methodId = env->GetMethodID(cls, "getRetryStrategyType", "()I"); if (methodId == NULL) { DLOGW("Couldn't find method id getRetryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT."); pKvsRetryStrategy->retryStrategyType = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; @@ -356,100 +339,6 @@ BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg CleanUp: - if (nullKvsRetryStrategy) { - DLOGI("Setting kvsRetryStrategy members to NULL/default values."); - pKvsRetryStrategy->pRetryStrategy = NULL; - pKvsRetryStrategy->pRetryStrategyConfig = NULL; - pKvsRetryStrategy->retryStrategyType = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; - } - return STATUS_FAILED(retStatus) ? FALSE : TRUE; -} - -BOOL setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks) -{ - STATUS retStatus = STATUS_SUCCESS; - jmethodID methodId = NULL; - jclass cls = NULL; - BOOL nullSetCallbacks = FALSE; - - CHECK(env != NULL && pKvsRetryStrategyCallbacks != NULL); - - if (kvsRetryStrategyCallbacks == NULL) { - nullSetCallbacks = TRUE; - goto CleanUp; - } - - cls = env->GetObjectClass(kvsRetryStrategyCallbacks); - if (cls == NULL) { - nullSetCallbacks = TRUE; - DLOGW("Failed to create Java kvsRetryStrategyCallbacks class."); - CHK(FALSE, STATUS_INVALID_OPERATION); - goto CleanUp; - } - - /* *** */ - /* NOTE: If ANY of the kvsRetryStrategyCallbacks are NULL, then they will ALL be set to defaults in PIC. */ - /* So, below, if any are NULL, we will set them all to NULL in cleanup */ - /* *** */ - - methodId = env->GetMethodID(cls, "createRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;)V"); - if (methodId == NULL) { - DLOGW("Couldn't find method id createRetryStrategyFn, setting to NULL"); - nullSetCallbacks = TRUE; - goto CleanUp; - } else { - // Use Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks - // from the Producer Java SDK. - nullSetCallbacks = TRUE; - goto CleanUp; - } - - methodId = env->GetMethodID(cls, "getCurrentRetryAttemptNumberFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;I)V"); - if (methodId == NULL) { - DLOGW("Couldn't find method id getCurrentRetryAttemptNumberFn, setting to NULL"); - nullSetCallbacks = TRUE; - goto CleanUp; - } else { - // Use Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks - // from the Producer Java SDK. - nullSetCallbacks = TRUE; - goto CleanUp; - } - - methodId = env->GetMethodID(cls, "freeRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;)V"); - if (methodId == NULL) { - DLOGW("Couldn't find method id freeRetryStrategyFn, setting to NULL"); - nullSetCallbacks = TRUE; - goto CleanUp; - } else { - // Use Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks - // from the Producer Java SDK. - nullSetCallbacks = TRUE; - goto CleanUp; - } - - methodId = env->GetMethodID(cls, "executeRetryStrategyFn", "(Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;J)V"); - if (methodId == NULL) { - DLOGW("Couldn't find method id executeRetryStrategyFn, setting to NULL"); - nullSetCallbacks = TRUE; - goto CleanUp; - } else { - // Use Java-provided callback once we implement Java callback invocation and support setting KvsRetryStrategyCallbacks - // from the Producer Java SDK. - nullSetCallbacks = TRUE; - goto CleanUp; - } - -CleanUp: - - // NOTE: If ANY RetryStrategyCallbacks are NULL, then ALL of them will be set to default callbacks in PIC. - if (nullSetCallbacks) { - DLOGI("Setting kvsRetryStrategyCallbacks functions to NULL to be set to defaults callbacks in PIC"); - pKvsRetryStrategyCallbacks->createRetryStrategyFn = NULL; - pKvsRetryStrategyCallbacks->getCurrentRetryAttemptNumberFn = NULL; - pKvsRetryStrategyCallbacks->freeRetryStrategyFn = NULL; - pKvsRetryStrategyCallbacks->executeRetryStrategyFn = NULL; - } return STATUS_FAILED(retStatus) ? FALSE : TRUE; } From fc71b0122b6999759cd1a8acbf73a5b0d36a825b Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:03:14 -0700 Subject: [PATCH 15/17] Remove unneeded getting, still need to test+cleanup comments --- .../kinesis/video/producer/jni/Parameters.cpp | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) 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 60abc205..ef526bfd 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -280,15 +280,6 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) { } } - // Note: kvsRetryStrategyCallbacks is not supported yet in Java, the below is a skeleton for the future implementation. - methodId = env->GetMethodID(cls, "getKvsRetryStrategyCallbacks", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategyCallbacks;"); - if (methodId == NULL) { - DLOGW("Couldn't find method id getKvsRetryStrategyCallbacks"); - } else { - kvsRetryStrategyCallbacks = (jobject) env->CallObjectMethod(clientInfo, methodId); - CHK_JVM_EXCEPTION(env); - } - CleanUp: return STATUS_FAILED(retStatus) ? FALSE : TRUE; } @@ -299,18 +290,11 @@ BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg jmethodID methodId = NULL; jclass cls = NULL; - CHECK(env != NULL && pKvsRetryStrategy != NULL); - - if (kvsRetryStrategy == NULL) { - goto CleanUp; - } + 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); - if (cls == NULL) { - DLOGW("Failed to create Java kvsRetryStrategy class."); - CHK(FALSE, STATUS_INVALID_OPERATION); - goto CleanUp; - } + CHK_WARN(cls != NULL, STATUS_INVALID_OPERATION, "Failed to create Java kvsRetryStrategy class."); methodId = env->GetMethodID(cls, "getRetryStrategy", "()J"); if (methodId == NULL) { @@ -328,10 +312,10 @@ BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg CHK_JVM_EXCEPTION(env); } + // TODO: Test with logs that this is getting the value from Java, play around with the value. methodId = env->GetMethodID(cls, "getRetryStrategyType", "()I"); if (methodId == NULL) { DLOGW("Couldn't find method id getRetryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT."); - pKvsRetryStrategy->retryStrategyType = KVS_RETRY_STRATEGY_EXPONENTIAL_BACKOFF_WAIT; } else { pKvsRetryStrategy->retryStrategyType = (KVS_RETRY_STRATEGY_TYPE) env->CallIntMethod(kvsRetryStrategy, methodId); CHK_JVM_EXCEPTION(env); From 921222b0eaa4997df65a94370e408a37bb2ce70d Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:24:16 -0700 Subject: [PATCH 16/17] Tested, removed comment --- src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp | 1 - 1 file changed, 1 deletion(-) 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 ef526bfd..ed681a27 100644 --- a/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp +++ b/src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp @@ -312,7 +312,6 @@ BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrateg CHK_JVM_EXCEPTION(env); } - // TODO: Test with logs that this is getting the value from Java, play around with the value. methodId = env->GetMethodID(cls, "getRetryStrategyType", "()I"); if (methodId == NULL) { DLOGW("Couldn't find method id getRetryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT."); From 44065e3b09a0b037e84f30887e0c493754777fa4 Mon Sep 17 00:00:00 2001 From: Stefan Kieszkowski <85728496+stefankiesz@users.noreply.github.com> Date: Fri, 26 Apr 2024 12:25:50 -0700 Subject: [PATCH 17/17] Remove unused method --- .../com/amazonaws/kinesis/video/producer/jni/Parameters.h | 1 - 1 file changed, 1 deletion(-) 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 8ced911e..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,7 +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 setKvsRetryStrategyCallbacks(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategyCallbacks pKvsRetryStrategyCallbacks); BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy); #endif // __KINESIS_VIDEO_PARAMETERS_CONVERSION_H__