void KinesisVideoClientWrapper::streamFormatChanged()

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


void KinesisVideoClientWrapper::streamFormatChanged(jlong streamHandle, jobject codecPrivateData, jlong trackId)
{
    STATUS retStatus = STATUS_SUCCESS;
    JNIEnv *env;
    mJvm->GetEnv((PVOID*) &env, JNI_VERSION_1_6);
    UINT32 bufferSize = 0;
    PBYTE pBuffer = NULL;
    BOOL releaseBuffer = FALSE;

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

    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);
        goto CleanUp;
    }

    // Get the codec private data byte buffer - null object has a special semmantic of clearing the CPD
    if (codecPrivateData != NULL) {
        bufferSize = (UINT32) env->GetArrayLength((jbyteArray) codecPrivateData);
        if (NULL == (pBuffer = (PBYTE) env->GetByteArrayElements((jbyteArray) codecPrivateData, NULL)))
        {
            DLOGE("Failed getting byte buffer from the java array.");
            throwNativeException(env, EXCEPTION_NAME, "Failed getting byte buffer from the java array.", STATUS_INVALID_OPERATION);
            goto CleanUp;
        }

        // Make sure the buffer is released at the end
        releaseBuffer = TRUE;
    } else {
        pBuffer = NULL;
        bufferSize = 0;
    }

    if (STATUS_FAILED(retStatus = ::kinesisVideoStreamFormatChanged(streamHandle, bufferSize, pBuffer, trackId)))
    {
        DLOGE("Failed to set the stream format with status code 0x%08x", retStatus);
        throwNativeException(env, EXCEPTION_NAME, "Failed to set the stream format.", retStatus);
        goto CleanUp;
    }

CleanUp:

    if (releaseBuffer)
    {
        env->ReleaseByteArrayElements((jbyteArray) codecPrivateData, (jbyte*) pBuffer, JNI_ABORT);
    }
}