Using the C Producer Library - Amazon Kinesis Video Streams
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Using the C Producer Library

You can use the Amazon Kinesis Video Streams provided C Producer Library to write application code to send media data from a device to a Kinesis video stream.

Object model

The Kinesis Video Streams C Producer Library is based on a common component called Platform Independent Codebase (PIC), which is available on GitHub at https://github.com/awslabs/amazon-kinesis-video-streams-pic/. The PIC contains platform-independent business logic for the foundational components. The Kinesis Video Streams C Producer Library wraps PIC with additional layer of API that allows scenario-and platform-specific callbacks and events. The Kinesis Video Streams C Producer Library has the following components built on top of PIC:

  • Device info providers – Exposes the DeviceInfo structure that can be directly supplied to the PIC API. You can configure a set of providers, including application scenario-optimized provider that can optimize the content store based on the number and types of streams that your application handles and the amount of required buffering configured based on the amount of available RAM.

  • Stream info provider – Exposes the StreamInfo structure that can be directly supplied to the PIC API. There's a set of providers that are specific to the application types and the common types of streaming scenarios. These include providers such as video, audio, and audio and video multitrack. Each of these scenarios have defaults that you can customize according to your application's requirements.

  • Callback provider – Exposes the ClientCallbacks structure that can be directly supplied to the PIC API. This includes a set of callback providers for networking (CURL-based API callbacks), authorization (Amazon credentials API), and retry streaming on errors callbacks. The Callback Provider API takes a number of arguments to configure, such as the Amazon Web Services Region and authorization information. This is done by using IoT certificates or by using Amazon AccessKeyId, SecretKey, or SessionToken. You can enhance Callback Provider with custom callbacks if your application needs further processing of a particular callback to achieve some application-specific logic.

  • FrameOrderCoordinator – Helps handle audio and video synchronization for multi-track scenarios. It has default behavior, which you can customize to handle your application's specific logic. It also streamlines the frame metadata packaging in PIC Frame structure before submitting it to the lower-layer PIC API. For non-multitrack scenarios, this component is a pass-through to PIC putFrame API.

The C library provides the following objects to manage sending data to a Kinesis video stream:

  • KinesisVideoClient – Contains information about your device and maintains callbacks to report on Kinesis Video Streams events.

  • KinesisVideoStream – Represents information about the video stream's parameters, such as name, data retention period, and media content type.

Putting media into the stream

You can use the C library provided methods (for example, PutKinesisVideoFrame) to put data into the KinesisVideoStream object. The library then manages the internal state of the data, which can include the following tasks:

  • Performing authentication.

  • Watching for network latency. If the latency is too high, the library might choose to drop frames.

  • Tracking status of streaming in progress.

Procedure: Using the C Producer SDK

This procedure demonstrates how to use the Kinesis Video Streams client and media sources in a C application to send H.264-encoded video frames to your Kinesis video stream.

The procedure includes the following steps:

Prerequisites

  • Credentials – In the sample code, you provide credentials by specifying a profile that you set up in your Amazon credentials profile file. If you haven't already done so, first set up your credentials profile.

    For more information, see Set up Amazon Credentials and Region for Development.

  • Certificate store integration – The Kinesis Video Streams Producer Library must establish trust with the service it calls. This is done through validating the certificate authorities (CAs) in the public certificate store. On Linux-based models, this store is located in the /etc/ssl/ directory.

    Download the certificate from the following location to your certificate store:

    https://www.amazontrust.com/repository/SFSRootCAG2.pem

  • Install the following build dependencies for macOS:

  • Install the following build dependencies for Ubuntu:

    • Git: sudo apt install git

    • CMake: sudo apt install cmake

    • G++: sudo apt install g++

    • pkg-config: sudo apt install pkg-config

    • OpenJDK: sudo apt install openjdk-8-jdk

    • Set the JAVA_HOME environment variable: export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/

Next step

Step 1: Download the C Producer Library code