Write and examine the code
In this section, you examine the code of the sample application
KvsVideoOnlyStreamingSample.c in the samples folder of the
https://github.com/awslabs/amazon-kinesis-video-streams-producer-csamples/h264SampleFrames to your Kinesis video stream.
This sample application has three sections:
-
Initialization and configuration:
-
Initializing and configuring the platform-specific media pipeline.
-
Initializing and configuring KinesisVideoClient and KinesisVideoStream for the pipeline, setting the callbacks, integrating scenario-specific authentication, extracting and submitting codec private data, and getting the stream to READY state.
-
-
Main loop:
-
Getting the frame from the media pipeline with the timestamps and flags.
-
Submitting the frame to the KinesisVideoStream.
-
-
Teardown:
-
Stopping (sync) KinesisVideoStream, freeing KinesisVideoStream, freeing KinesisVideoClient.
-
This sample application completes the following tasks:
-
Call the
createDefaultDeviceInfoAPI to create thedeviceInfoobject that contains information about the device or storage configuration.// default storage size is 128MB. Use setDeviceInfoStorageSize after create to change storage size. CHK_STATUS(createDefaultDeviceInfo(&pDeviceInfo)); // adjust members of pDeviceInfo here if needed pDeviceInfo->clientInfo.loggerLogLevel = LOG_LEVEL_DEBUG; -
Call the
createRealtimeVideoStreamInfoProviderAPI to create theStreamInfoobject.CHK_STATUS(createRealtimeVideoStreamInfoProvider(streamName, DEFAULT_RETENTION_PERIOD, DEFAULT_BUFFER_DURATION, &pStreamInfo)); // adjust members of pStreamInfo here if needed -
Call the
createDefaultCallbacksProviderWithAwsCredentialsAPI to create the default callbacks provider based on static Amazon credentials.CHK_STATUS(createDefaultCallbacksProviderWithAwsCredentials(accessKey, secretKey, sessionToken, MAX_UINT64, region, cacertPath, NULL, NULL, FALSE, &pClientCallbacks)); -
Call the
createKinesisVideoClientAPI to create theKinesisVideoClientobject that contains information about your device storage and maintains callbacks to report on Kinesis Video Streams events.CHK_STATUS(createKinesisVideoClient(pDeviceInfo, pClientCallbacks, &clientHandle)); -
Call the
createKinesisVideoStreamSyncAPI to create theKinesisVideoStreamobject.CHK_STATUS(createKinesisVideoStreamSync(clientHandle, pStreamInfo, &streamHandle)); -
Set up a sample frame and call
PutKinesisVideoFrameAPI to send that frame to theKinesisVideoStreamobject.// setup sample frame MEMSET(frameBuffer, 0x00, frameSize); frame.frameData = frameBuffer; frame.version = FRAME_CURRENT_VERSION; frame.trackId = DEFAULT_VIDEO_TRACK_ID; frame.duration = HUNDREDS_OF_NANOS_IN_A_SECOND / DEFAULT_FPS_VALUE; frame.decodingTs = defaultGetTime(); // current time frame.presentationTs = frame.decodingTs; while(defaultGetTime() > streamStopTime) { frame.index = frameIndex; frame.flags = fileIndex % DEFAULT_KEY_FRAME_INTERVAL == 0 ? FRAME_FLAG_KEY_FRAME : FRAME_FLAG_NONE; frame.size = SIZEOF(frameBuffer); CHK_STATUS(readFrameData(&frame, frameFilePath)); CHK_STATUS(putKinesisVideoFrame(streamHandle, &frame)); defaultThreadSleep(frame.duration); frame.decodingTs += frame.duration; frame.presentationTs = frame.decodingTs; frameIndex++; fileIndex++; fileIndex = fileIndex % NUMBER_OF_FRAME_FILES; } -
Teardown:
CHK_STATUS(stopKinesisVideoStreamSync(streamHandle)); CHK_STATUS(freeKinesisVideoStream(&streamHandle)); CHK_STATUS(freeKinesisVideoClient(&clientHandle));