void KinesisVideoClientWrapper::getKinesisVideoStreamMetrics()

in src/JNI/com/amazonaws/kinesis/video/producer/jni/KinesisVideoClientWrapper.cpp [215:278]


void KinesisVideoClientWrapper::getKinesisVideoStreamMetrics(jlong streamHandle, jobject kinesisVideoStreamMetrics)
{
    STATUS retStatus = STATUS_SUCCESS;
    JNIEnv *env;
    mJvm->GetEnv((PVOID*) &env, JNI_VERSION_1_6);

    if (!IS_VALID_CLIENT_HANDLE(mClientHandle))
    {
        DLOGE("Invalid client object");
        throwNativeException(env, EXCEPTION_NAME, "Invalid call after the client is freed.", STATUS_INVALID_OPERATION);
        return;
    }

    if (!IS_VALID_STREAM_HANDLE(streamHandle))
    {
        DLOGE("Invalid stream handle 0x%016" PRIx64 , (UINT64) streamHandle);
        throwNativeException(env, EXCEPTION_NAME, "Invalid stream handle.", STATUS_INVALID_OPERATION);
        return;
    }

    if (NULL == kinesisVideoStreamMetrics)
    {
        DLOGE("KinesisVideoStreamMetrics object is null");
        throwNativeException(env, EXCEPTION_NAME, "KinesisVideoStreamMetrics object is null.", STATUS_NULL_ARG);
        return;
    }

    StreamMetrics metrics;
    metrics.version = STREAM_METRICS_CURRENT_VERSION;

    if (STATUS_FAILED(retStatus = ::getKinesisVideoStreamMetrics(streamHandle, &metrics)))
    {
        DLOGE("Failed to get StreamMetrics with status code 0x%08x", retStatus);
        throwNativeException(env, EXCEPTION_NAME, "Failed to get StreamMetrics.", retStatus);
        return;
    }

    //get the class
    jclass metricsClass = env->GetObjectClass(kinesisVideoStreamMetrics);
    if (metricsClass == NULL){
        DLOGE("Failed to get metrics class object");
        throwNativeException(env, EXCEPTION_NAME, "Failed to get metrics class object.", STATUS_INVALID_OPERATION);
        return;
    }

    // Set the Java object
    jmethodID setterMethodId = env->GetMethodID(metricsClass, "setMetrics", "(JJJJDJ)V");
    if (setterMethodId == NULL)
    {
        DLOGE("Failed to get the setter method id.");
        throwNativeException(env, EXCEPTION_NAME, "Failed to get setter method id.", STATUS_INVALID_OPERATION);
        return;
    }

    // call the setter method
    env->CallVoidMethod(kinesisVideoStreamMetrics,
                        setterMethodId,
                        metrics.overallViewSize,
                        metrics.currentViewSize,
                        metrics.overallViewDuration,
                        metrics.currentViewDuration,
                        metrics.currentFrameRate,
                        metrics.currentTransferRate);
}