Skip to content

Commit abe8cbd

Browse files
stefankieszsirknightj
authored andcommitted
Fix un-initialized JNI ClientInfo members (#1161)
* Add init values * Remove extra line * Introduce the structure for setting KvsRetryStrategyCallbacks from Java SDK * Fix compiler errors from prev commit * Start on the other members * Done, not tested * Fix java getter types * Fix typos, build issues * Add null checks * Java getters now return null or 0 * Fix retryStrategyType and compile errors * Install pkgconfiglite for Windows CI * Setter funcs return bool, add missing CHK_JVM_EXCEPTIONs * Address comments * Remove unneeded getting, still need to test+cleanup comments * Tested, removed comment * Remove unused method
1 parent 3318c47 commit abe8cbd

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ open-source/
1010
outputs
1111
tags
1212
dependency
13-
.vs
13+
.vs
14+
.vscode/

src/JNI/com/amazonaws/kinesis/video/producer/jni/KinesisVideoClientWrapper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ KinesisVideoClientWrapper::KinesisVideoClientWrapper(JNIEnv* env,
2525
CHECK_EXT(FALSE, "Couldn't retrieve the JavaVM reference.");
2626
}
2727

28+
// Null-initialize the clientInfo struct
29+
MEMSET(&mDeviceInfo.clientInfo, 0, sizeof(mDeviceInfo.clientInfo));
30+
2831
// Set the callbacks
2932
if (!setCallbacks(env, thiz)) {
3033
throwNativeException(env, EXCEPTION_NAME, "Failed to set the callbacks.", STATUS_INVALID_ARG);
@@ -1014,6 +1017,9 @@ BOOL KinesisVideoClientWrapper::setCallbacks(JNIEnv* env, jobject thiz)
10141017
mClientCallbacks.clientShutdownFn = NULL;
10151018
mClientCallbacks.streamShutdownFn = NULL;
10161019

1020+
// TODO: Currently we set the shutdown callbacks to NULL.
1021+
// We need to expose these in the near future
1022+
10171023
// Extract the method IDs for the callbacks and set a global reference
10181024
jclass thizCls = env->GetObjectClass(thiz);
10191025
if (thizCls == NULL) {

src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ BOOL setDeviceInfo(JNIEnv *env, jobject deviceInfo, PDeviceInfo pDeviceInfo)
146146
CHK_JVM_EXCEPTION(env);
147147

148148
if (!setClientInfo(env, clientInfo, &pDeviceInfo->clientInfo)) {
149+
// TODO: Consider hard failing here rather than just logging.
149150
DLOGW("Failed getting/setting client info.");
150151
}
151152
}
@@ -158,6 +159,8 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) {
158159
STATUS retStatus = STATUS_SUCCESS;
159160
jmethodID methodId = NULL;
160161
const char *retChars;
162+
jobject kvsRetryStrategyCallbacks = NULL;
163+
jobject kvsRetryStrategy = NULL;
161164

162165
CHECK(env != NULL && clientInfo != NULL && pClientInfo != NULL);
163166

@@ -168,7 +171,7 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) {
168171
CHK(FALSE, STATUS_INVALID_OPERATION);
169172
}
170173

171-
// Retrieve the methods and call it
174+
// Retrieve the methods and call them
172175
methodId = env->GetMethodID(cls, "getVersion", "()I");
173176
if (methodId == NULL) {
174177
DLOGW("Couldn't find method id getVersion");
@@ -201,17 +204,17 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) {
201204
CHK_JVM_EXCEPTION(env);
202205
}
203206

204-
methodId = env->GetMethodID(cls, "getServiceConnectionTimeout", "()J");
207+
methodId = env->GetMethodID(cls, "getServiceCallConnectionTimeout", "()J");
205208
if (methodId == NULL) {
206-
DLOGW("Couldn't find method id getServiceConnectionTimeout");
209+
DLOGW("Couldn't find method id getServiceCallConnectionTimeout");
207210
} else {
208211
pClientInfo->serviceCallConnectionTimeout = env->CallLongMethod(clientInfo, methodId);
209212
CHK_JVM_EXCEPTION(env);
210213
}
211214

212-
methodId = env->GetMethodID(cls, "getServiceCompletionTimeout", "()J");
215+
methodId = env->GetMethodID(cls, "getServiceCallCompletionTimeout", "()J");
213216
if (methodId == NULL) {
214-
DLOGW("Couldn't find method id getServiceCompletionTimeout");
217+
DLOGW("Couldn't find method id getServiceCallCompletionTimeout");
215218
} else {
216219
pClientInfo->serviceCallCompletionTimeout = env->CallLongMethod(clientInfo, methodId);
217220
CHK_JVM_EXCEPTION(env);
@@ -249,10 +252,78 @@ BOOL setClientInfo(JNIEnv *env, jobject clientInfo, PClientInfo pClientInfo) {
249252
CHK_JVM_EXCEPTION(env);
250253
}
251254

255+
methodId = env->GetMethodID(cls, "getMetricLoggingPeriod", "()J");
256+
if (methodId == NULL) {
257+
DLOGW("Couldn't find method id getMetricLoggingPeriod");
258+
} else {
259+
pClientInfo->metricLoggingPeriod = env->CallLongMethod(clientInfo, methodId);
260+
CHK_JVM_EXCEPTION(env);
261+
}
262+
263+
methodId = env->GetMethodID(cls, "getReservedCallbackPeriod", "()J");
264+
if (methodId == NULL) {
265+
DLOGW("Couldn't find method id getReservedCallbackPeriod");
266+
} else {
267+
pClientInfo->reservedCallbackPeriod = env->CallLongMethod(clientInfo, methodId);
268+
CHK_JVM_EXCEPTION(env);
269+
}
270+
271+
methodId = env->GetMethodID(cls, "getKvsRetryStrategy", "()Lcom/amazonaws/kinesisvideo/producer/KvsRetryStrategy;");
272+
if (methodId == NULL) {
273+
DLOGW("Couldn't find method id getKvsRetryStrategy");
274+
} else {
275+
kvsRetryStrategy = (jobject) env->CallObjectMethod(clientInfo, methodId);
276+
CHK_JVM_EXCEPTION(env);
277+
278+
if (!setKvsRetryStrategy(env, kvsRetryStrategy, &pClientInfo->kvsRetryStrategy)) {
279+
DLOGW("Failed getting/setting KvsRetryStrategy.");
280+
}
281+
}
282+
252283
CleanUp:
253284
return STATUS_FAILED(retStatus) ? FALSE : TRUE;
254285
}
255286

287+
BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategy, PKvsRetryStrategy pKvsRetryStrategy)
288+
{
289+
STATUS retStatus = STATUS_SUCCESS;
290+
jmethodID methodId = NULL;
291+
jclass cls = NULL;
292+
293+
CHK(env != NULL && pKvsRetryStrategy != NULL, STATUS_NULL_ARG);
294+
CHK_WARN(kvsRetryStrategy != NULL, STATUS_INVALID_OPERATION, "Failed to get Java kvsRetryStrategy class.");
295+
296+
cls = env->GetObjectClass(kvsRetryStrategy);
297+
CHK_WARN(cls != NULL, STATUS_INVALID_OPERATION, "Failed to create Java kvsRetryStrategy class.");
298+
299+
methodId = env->GetMethodID(cls, "getRetryStrategy", "()J");
300+
if (methodId == NULL) {
301+
DLOGW("Couldn't find method id getRetryStrategy.");
302+
} else {
303+
// TODO: Implement once we have support for this in Java.
304+
CHK_JVM_EXCEPTION(env);
305+
}
306+
307+
methodId = env->GetMethodID(cls, "getRetryStrategyConfig", "()J");
308+
if (methodId == NULL) {
309+
DLOGW("Couldn't find method id getRetryStrategyConfig.");
310+
} else {
311+
// TODO: Implement once we have support for this in Java.
312+
CHK_JVM_EXCEPTION(env);
313+
}
314+
315+
methodId = env->GetMethodID(cls, "getRetryStrategyType", "()I");
316+
if (methodId == NULL) {
317+
DLOGW("Couldn't find method id getRetryStrategyType, setting retryStrategyType to EXPONENTIAL_BACKOFF_WAIT.");
318+
} else {
319+
pKvsRetryStrategy->retryStrategyType = (KVS_RETRY_STRATEGY_TYPE) env->CallIntMethod(kvsRetryStrategy, methodId);
320+
CHK_JVM_EXCEPTION(env);
321+
}
322+
323+
324+
CleanUp:
325+
return STATUS_FAILED(retStatus) ? FALSE : TRUE;
326+
}
256327

257328
BOOL setTags(JNIEnv *env, jobjectArray tagArray, PTag* ppTags, PUINT32 pTagCount)
258329
{

src/JNI/include/com/amazonaws/kinesis/video/producer/jni/Parameters.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ BOOL setStreamDataBuffer(JNIEnv* env, jobject dataBuffer, UINT32 offset, PBYTE*
1717
BOOL releaseStreamDataBuffer(JNIEnv* env, jobject dataBuffer, UINT32 offset, PBYTE pBuffer);
1818
BOOL setTags(JNIEnv *env, jobjectArray tagArray, PTag* ppTags, PUINT32 pTagCount);
1919
VOID releaseTags(PTag tags);
20+
BOOL setKvsRetryStrategy(JNIEnv *env, jobject kvsRetryStrategyCallbacks, PKvsRetryStrategy pKvsRetryStrategy);
21+
2022
#endif // __KINESIS_VIDEO_PARAMETERS_CONVERSION_H__

0 commit comments

Comments
 (0)