BOOL setStreamDescription()

in src/JNI/com/amazonaws/kinesis/video/producer/jni/Parameters.cpp [878:1030]


BOOL setStreamDescription(JNIEnv* env, jobject streamDescription, PStreamDescription pStreamDesc)
{
    STATUS retStatus = STATUS_SUCCESS;
    jmethodID methodId = NULL;
    const char *retChars;

    CHECK(env != NULL && streamDescription != NULL && pStreamDesc != NULL);

    // Load StreamDescription
    jclass cls = env->GetObjectClass(streamDescription);
    if (cls == NULL) {
        DLOGE("Failed to create StreamDescription class.");
        CHK(FALSE, STATUS_INVALID_OPERATION);
    }

    // Retrieve the methods and call it
    methodId = env->GetMethodID(cls, "getVersion", "()I");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getVersion");
    } else {
        pStreamDesc->version = env->CallIntMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);
    }

    methodId = env->GetMethodID(cls, "getDeviceName", "()Ljava/lang/String;");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getDeviceName");
    } else {
        jstring retString = (jstring) env->CallObjectMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);

        if (retString != NULL) {
            retChars = env->GetStringUTFChars(retString, NULL);
            STRNCPY(pStreamDesc->deviceName, retChars, MAX_DEVICE_NAME_LEN + 1);
            pStreamDesc->deviceName[MAX_DEVICE_NAME_LEN] = '\0';
            env->ReleaseStringUTFChars(retString, retChars);
        } else {
            pStreamDesc->deviceName[0] = '\0';
        }
    }

    methodId = env->GetMethodID(cls, "getStreamName", "()Ljava/lang/String;");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getStreamName");
    } else {
        jstring retString = (jstring) env->CallObjectMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);

        if (retString != NULL) {
            retChars = env->GetStringUTFChars(retString, NULL);
            STRNCPY(pStreamDesc->streamName, retChars, MAX_STREAM_NAME_LEN + 1);
            pStreamDesc->streamName[MAX_STREAM_NAME_LEN] = '\0';
            env->ReleaseStringUTFChars(retString, retChars);
        } else {
            pStreamDesc->streamName[0] = '\0';
        }
    }

    methodId = env->GetMethodID(cls, "getContentType", "()Ljava/lang/String;");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getContentType");
    } else {
        jstring retString = (jstring) env->CallObjectMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);

        if (retString != NULL) {
            retChars = env->GetStringUTFChars(retString, NULL);
            STRNCPY(pStreamDesc->contentType, retChars, MAX_CONTENT_TYPE_LEN + 1);
            pStreamDesc->contentType[MAX_CONTENT_TYPE_LEN] = '\0';
            env->ReleaseStringUTFChars(retString, retChars);
        } else {
            pStreamDesc->contentType[0] = '\0';
        }
    }

    methodId = env->GetMethodID(cls, "getUpdateVersion", "()Ljava/lang/String;");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getUpdateVersion");
    } else {
        jstring retString = (jstring) env->CallObjectMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);

        if (retString != NULL) {
            retChars = env->GetStringUTFChars(retString, NULL);
            STRNCPY(pStreamDesc->updateVersion, retChars, MAX_UPDATE_VERSION_LEN + 1);
            pStreamDesc->updateVersion[MAX_UPDATE_VERSION_LEN] = '\0';
            env->ReleaseStringUTFChars(retString, retChars);
        } else {
            pStreamDesc->updateVersion[0] = '\0';
        }
    }

    methodId = env->GetMethodID(cls, "getStreamArn", "()Ljava/lang/String;");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getStreamArn");
    } else {
        jstring retString = (jstring) env->CallObjectMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);

        if (retString != NULL) {
            retChars = env->GetStringUTFChars(retString, NULL);
            STRNCPY(pStreamDesc->streamArn, retChars, MAX_ARN_LEN + 1);
            pStreamDesc->streamArn[MAX_ARN_LEN] = '\0';
            env->ReleaseStringUTFChars(retString, retChars);
        } else {
            pStreamDesc->streamArn[0] = '\0';
        }
    }

    methodId = env->GetMethodID(cls, "getCreationTime", "()J");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getCreationTime");
    } else {
        pStreamDesc->creationTime = env->CallLongMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);
    }

    methodId = env->GetMethodID(cls, "getStreamStatus", "()I");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getStreamStatus");
    } else {
        pStreamDesc->streamStatus = (STREAM_STATUS) env->CallIntMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);
    }

    methodId = env->GetMethodID(cls, "getRetention", "()J");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getRetention");
    } else {
        pStreamDesc->retention = env->CallLongMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);
    }

    methodId = env->GetMethodID(cls, "getKmsKeyId", "()Ljava/lang/String;");
    if (methodId == NULL) {
        DLOGW("Couldn't find method id getKmsKeyId");
    } else {
        jstring retString = (jstring) env->CallObjectMethod(streamDescription, methodId);
        CHK_JVM_EXCEPTION(env);

        if (retString != NULL) {
            retChars = env->GetStringUTFChars(retString, NULL);
            STRNCPY(pStreamDesc->kmsKeyId, retChars, MAX_ARN_LEN + 1);
            pStreamDesc->kmsKeyId[MAX_ARN_LEN] = '\0';
            env->ReleaseStringUTFChars(retString, retChars);
        } else {
            pStreamDesc->kmsKeyId[0] = '\0';
        }
    }

CleanUp:
    return STATUS_FAILED(retStatus) ? FALSE : TRUE;
}