void kinesis_video_producer_init()

in src/gstreamer/gstkvssink.cpp [235:315]


void kinesis_video_producer_init(GstKvsSink *kvssink)
{
    auto data = kvssink->data;
    unique_ptr<DeviceInfoProvider> device_info_provider(new KvsSinkDeviceInfoProvider(kvssink->storage_size));
    unique_ptr<ClientCallbackProvider> client_callback_provider(new KvsSinkClientCallbackProvider());
    unique_ptr<StreamCallbackProvider> stream_callback_provider(new KvsSinkStreamCallbackProvider(data));

    char const *access_key;
    char const *secret_key;
    char const *session_token;
    char const *default_region;
    string access_key_str;
    string secret_key_str;
    string session_token_str;
    string region_str;
    bool credential_is_static = true;

    // This needs to happen after we've read in ALL of the properties
    if (!kvssink->disable_buffer_clipping) {
        gst_collect_pads_set_clip_function(kvssink->collect,
                                           GST_DEBUG_FUNCPTR(gst_collect_pads_clip_running_time), kvssink);
    }

    if (0 == strcmp(kvssink->access_key, DEFAULT_ACCESS_KEY)) { // if no static credential is available in plugin property.
        if (nullptr == (access_key = getenv(ACCESS_KEY_ENV_VAR))
            || nullptr == (secret_key = getenv(SECRET_KEY_ENV_VAR))) { // if no static credential is available in env var.
            credential_is_static = false; // No static credential available.
            access_key_str = "";
            secret_key_str = "";
        } else {
            access_key_str = string(access_key);
            secret_key_str = string(secret_key);
            session_token_str = "";
            if (nullptr != (session_token = getenv(SESSION_TOKEN_ENV_VAR))) {
                session_token_str = string(session_token);
            }
        }

    } else {
        access_key_str = string(kvssink->access_key);
        secret_key_str = string(kvssink->secret_key);
    }

    if (nullptr == (default_region = getenv(DEFAULT_REGION_ENV_VAR))) {
        region_str = string(kvssink->aws_region);
    } else {
        region_str = string(default_region); // Use env var if both property and env var are available.
    }

    unique_ptr<CredentialProvider> credential_provider;

    if (credential_is_static) {
        kvssink->credentials_.reset(new Credentials(access_key_str,
                secret_key_str,
                session_token_str,
                std::chrono::seconds(DEFAULT_ROTATION_PERIOD_SECONDS)));
        credential_provider.reset(new StaticCredentialProvider(*kvssink->credentials_));
    } else if (kvssink->iot_certificate) {
        std::map<std::string, std::string> iot_cert_params;
        if (!kvs_sink_util::parseIotCredentialGstructure(kvssink->iot_certificate, iot_cert_params)){
            LOG_AND_THROW("Failed to parse Iot credentials");
        }

        credential_provider.reset(new IotCertCredentialProvider(iot_cert_params[IOT_GET_CREDENTIAL_ENDPOINT],
                iot_cert_params[CERTIFICATE_PATH],
                iot_cert_params[PRIVATE_KEY_PATH],
                iot_cert_params[ROLE_ALIASES],
                iot_cert_params[CA_CERT_PATH],
                kvssink->stream_name));
    } else {
        credential_provider.reset(new RotatingCredentialProvider(kvssink->credential_file_path));
    }

    data->kinesis_video_producer = KinesisVideoProducer::createSync(move(device_info_provider),
                                                                    move(client_callback_provider),
                                                                    move(stream_callback_provider),
                                                                    move(credential_provider),
                                                                    region_str,
                                                                    "",
                                                                    KVS_CLIENT_USER_AGENT_NAME);
}