

# Download and build the Kinesis Video Streams C\$1\$1 producer SDK
<a name="producersdk-cpp-rpi-download"></a>

Follow the procedures below to download and build the [Kinesis Video Streams C\$1\$1 producer SDK](https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp). Make sure you've installed the software prerequisites; see [Install software prerequisites](producersdk-cpp-rpi-software.md) for those steps.

1. Navigate to download directory. Open a terminal and change to your preferred download directory. 

   For example:

   ```
   cd ~/Downloads
   ```

1. Clone the SDK repository. Use the `git clone` command to download the SDK from the GitHub repository. Type:

   ```
   git clone https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp.git --single-branch -b master kvs-producer-sdk-cpp
   ```

   This command clones only a single branch (the `master` branch), reducing the download size and time. It also places the downloaded contents into a folder called `kvs-producer-sdk-cpp` within the current directory.

1. Verify the download. Once the cloning process is complete, list the contents of the `kvs-producer-sdk-cpp` folder to verify that the SDK has been downloaded.

   ```
   ls kvs-producer-sdk-cpp
   ```

1. Prepare a build directory. Type:

   ```
   mkdir -p kvs-producer-sdk-cpp/build
   cd kvs-producer-sdk-cpp/build
   ```

1. Configure the build. Run the following `cmake` command to configure the build environment with specific options:

   ```
   cmake .. -DBUILD_GSTREAMER_PLUGIN=ON -DBUILD_DEPENDENCIES=OFF -DALIGNED_MEMORY_MODEL=ON
   ```

   [CMake](https://cmake.org/cmake/help/latest/manual/cmake.1.html) uses the following options to generate the appropriate `Makefiles`:
   + Using the project folder (`..`) as the source directory.
   + Using the current directory (`.`) (`build/`) for build output.
   + `-DBUILD_GSTREAMER_PLUGIN=ON` enables the building of the GStreamer plugin kvssink.
   + `-DBUILD_DEPENDENCIES=OFF` disables building external dependencies from source. The project will find and use the external dependencies installed in a previous step.
   + `-DALIGNED_MEMORY_MODEL=ON` disables the unaligned memory model. Unaligned memory access is not supported by certain Raspberry Pi devices.
**Note**  
For a full list of CMake arguments, see [Download and configure the C\$1\$1 producer library code](producersdk-cpp-download.md).

1. Build the project. After configuring the build, use the `make` command to compile using the `Makefile` generated by `cmake`.

   ```
   make -j$(nproc)
   ```

   The `-j` argument to `make` allows it to run multiple compilation jobs in parallel. To reduce build times, use the `nproc` command to dynamically calculate the number of CPU cores on your Raspberry Pi.

1. Confirm that `libgstkvssink.so` is present. 

   List the files in the current directory.

   **Prompt:**

   ```
   ls
   ```

   **Response:**

   ```
   CMakeCache.txt       dependency                          kvs_gstreamer_sample
   CMakeFiles           kvs_gstreamer_audio_video_sample    kvssink_gstreamer_sample
   Makefile             kvs_gstreamer_file_uploader_sample  libKinesisVideoProducer.so
   cmake_install.cmake  kvs_gstreamer_multistream_sample    libgstkvssink.so
   ```

1. Confirm that GStreamer can load `kvssink`. 

   Set the `GST_PLUGIN_PATH` environment variable to the directory containing `libgstkvssink.so`.

   ```
   export GST_PLUGIN_PATH=`pwd`
   ```

   Have GStreamer load `kvssink`:

   ```
   gst-inspect-1.0 kvssink
   ```

   You should see some documentation about `kvssink`. Use the arrow keys to navigate and press `q` to exit. 

1. (**Optional**) Update your shell's start-up script to include setting the `GST_PLUGIN_PATH` environment variable. This ensures `GST_PLUGIN_PATH` is set properly during a new terminal session. On Raspberry Pi devices, the shell's start-up script is `~/.bashrc`. 

   Run the following command to append the command to the end of the shell's start-up script.

   ```
   echo "export GST_PLUGIN_PATH=~/Downloads/kvs-producer-sdk-cpp/build" >> ~/.bashrc
   ```

   Type the following to run the shell's start-up script, or close the current shell and open a new one.

   ```
   source ~/.bashrc
   ```

   Confirm the `GST_PLUGIN_PATH` is set and you can load `kvssink`.

   ```
   echo $GST_PLUGIN_PATH
   ```

   ```
   gst-inspect-1.0 kvssink
   ```