CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
ndi_wrapper.c File Reference

This file contains definitions and functions for the NDI-CDI Converter application. More...

#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "cdi_baseline_profile_02_00_api.h"
#include "test_common.h"
#include "ndi_test.h"
#include "ndi_wrapper.h"

Macros

#define DISABLE_REPEAT_NDI_VIDEO_FRAME
 Enable this define to disable NDI video frame repeat (enabled by default for pending test/logic changes as needed). Note: When a static image is used, NDI only transmits one video frame per second. So for CDI, we should be.
 
#define DEFAULT_RECV_TIMEOUT_MS   (1*1000)
 Default timeout for RECV call.
 
#define REPEAT_FRAME_TIMEOUT_FACTOR   (1.3)
 Expected frame rate multiplied by this value determines how long to wait before repeating a frame.
 
#define CDI_BYTES_PER_AUDIO_SAMPLE   (3)
 Number of bytes in CDI audio sample. CDI requests 24-bit int for audio, so needs three bytes.
 
#define NDI_TIMEOUT_FOR_FINDING_SOURCES_IN_MS   (1000)
 Default sleep time in milliseconds until new sources are found on the network. Set to wait at most 1 second.
 

Functions

static int64_t CDITimestampToNdi (const CdiPtpTimestamp *cdi_timestamp_ptr)
 Convert a CDI timestamp to NDI.
 
static double MAX (float num1, float num2)
 Find maximum between two numbers.
 
static double MIN (float num1, float num2)
 Find minimum between two numbers.
 
static bool NdiToCdiAudioConversion (float *original_audio_ptr, int num_channels, int num_samples, int channel_stride_in_bytes, int *audio_size_byte_ret_ptr)
 Convert audio from 32-bit float Little-Endian to 24-bit int Big-Endian PCM. NDI audio frame appear in stacked channels in 32-bit float Little Endian format and CDI audio frame is requested to be in interleaved channels in 24-bit int Big-Endian PCM. Function goes through each NDI channel, reads audio segment in 4 byte segments, converts segment from 32-bit float Little-Endian to 24-bit int Big-Endian PCM, and places 24-bit int segment in jumps, that match interleaved spacing with corresponding number of channels, in temporary buffer. Temporary buffer replaces original NDI audio buffer and the size of the audio in bytes is updated to its new size.
 
static bool CdiToNdiAudioConversion (const uint8_t *cdi_audio_ptr, int cdi_audio_size, int num_channels, int num_samples_per_channel, int ndi_channel_stride_in_bytes, float *ndi_audio_ptr, int *ndi_size_ptr)
 Convert CDI audio 24-bit Big-Endian interleaved PCM to NDI 32-bit float Little Endian non-interleaved.
 
static CdiReturnStatus NdiToCdiVideo (const FrameData *frame_data_ptr, int *buffer_size_ptr, void **payload_buffer_ptr, int64_t *timestamp_ptr, CdiAvmBaselineConfig *avm_config_ptr)
 Convert a NDI video frame to CDI.
 
static CdiReturnStatus CdiToNdiVideo (const CdiPtpTimestamp *cdi_timestamp_ptr, const CdiAvmBaselineConfig *avm_config_ptr, int payload_size, const CdiSgList *sgl_ptr, FrameData *frame_data_ptr)
 Convert a CDI video frame to NDI.
 
static CdiReturnStatus NdiToCdiAudio (FrameData *frame_data_ptr, int *buffer_size_ptr, void **payload_buffer_ptr, int64_t *timestamp_ptr, CdiAvmBaselineConfig *avm_config_ptr)
 Convert a NDI audio frame to CDI.
 
static CdiReturnStatus CdiToNdiAudio (const CdiPtpTimestamp *cdi_timestamp_ptr, const CdiAvmBaselineConfig *avm_config_ptr, int payload_size, const CdiSgList *sgl_ptr, FrameData *frame_data_ptr)
 Convert CDI audio to NDI audio.
 
static CdiReturnStatus CdiToNdiMetadata (const CdiPtpTimestamp *cdi_timestamp_ptr, const CdiAvmBaselineConfig *avm_config_ptr, int payload_size, const CdiSgList *sgl_ptr, FrameData *frame_data_ptr)
 Convert CDI metadata to NDI metadata.
 
static CdiReturnStatus NdiToCdiMeta (FrameData *frame_data_ptr, int *buffer_size_ptr, void **payload_buffer_ptr, int64_t *timestamp_ptr, CdiAvmBaselineConfig *avm_config_ptr)
 Convert a NDI metadata frame to CDI.
 
NdiTime NdiTimeBreakdown (int64_t ndi_timestamp)
 A function that breaks down the NDI Timestamp, in 100ns format, into seconds, milliseconds, and nanoseconds.
 
bool NdiInitialize (void)
 A function which initializes the NDI SDK.
 
NDIlib_send_instance_t NdiCreateSender (const TestSettings *test_settings_ptr)
 A function which creates a NDI sender.
 
void NdiShowSources (void)
 Show available NDI sources and exit.
 
NDIlib_recv_instance_t NdiCreateReceiver (const TestSettings *test_settings_ptr)
 A function which creates a NDI finder, looks for NDI sources, creates a NDI receiver, and connects to a NDI source to receive stream information.
 
void NdiReleasePayload (FrameData *frame_data_ptr)
 A function that releases the memory of a NDI video, audio, or metadata frame, and puts back memory pool allocation.
 
CdiReturnStatus NdiConvertNdiToCdi (FrameData *frame_data_ptr, int *buffer_size_ptr, void **payload_buffer_ptr, int64_t *timestamp_ptr, CdiAvmBaselineConfig *avm_config_ptr)
 A function that maps information of NDI frame to an AVM structure that is compatible with CDI.
 
CdiReturnStatus NdiConvertCdiToNdi (const CdiPtpTimestamp *cdi_timestamp_ptr, const CdiAvmBaselineConfig *avm_config_ptr, int payload_size, const CdiSgList *sgl_ptr, FrameData *frame_data_ptr)
 Convert CDI payload to NDI frame.
 
CDI_THREAD NdiReceivePayloadThread (void *ptr)
 A function that captures NDI frames that is to be written to the memory pool and put in the Payload FIFO. Function also reads from Callback FIFO to determine if NDI frame memory should be released or resent. Function uses a receding time clock element to determine if video frames are being sent consistently at the expected time. If video frame is not seen in expected time, function resends last seen video frame, else it keeps sending new video frames.
 
CDI_THREAD NdiTransmitPayloadThread (void *ptr)
 Thread used to transmit NDI frames.
 

Detailed Description

This file contains definitions and functions for the NDI-CDI Converter application.

Function Documentation

◆ CDITimestampToNdi()

static int64_t CDITimestampToNdi ( const CdiPtpTimestamp * cdi_timestamp_ptr)
static

Convert a CDI timestamp to NDI.

Returns
NDI timestamp value.

◆ CdiToNdiAudio()

static CdiReturnStatus CdiToNdiAudio ( const CdiPtpTimestamp * cdi_timestamp_ptr,
const CdiAvmBaselineConfig * avm_config_ptr,
int payload_size,
const CdiSgList * sgl_ptr,
FrameData * frame_data_ptr )
static

Convert CDI audio to NDI audio.

Parameters
cdi_timestamp_ptrPointer to CDI timestamp.
avm_config_ptrPointer to CDI AVM configuration data.
payload_sizeSize of CDI payload in bytes.
sgl_ptrPointer to CDI payload data in Scatter-Gather-List format.
frame_data_ptrPointer where to write NDI frame data.
Returns
A value from the CdiReturnStatus enumeration.

◆ CdiToNdiAudioConversion()

static bool CdiToNdiAudioConversion ( const uint8_t * cdi_audio_ptr,
int cdi_audio_size,
int num_channels,
int num_samples_per_channel,
int ndi_channel_stride_in_bytes,
float * ndi_audio_ptr,
int * ndi_size_ptr )
static

Convert CDI audio 24-bit Big-Endian interleaved PCM to NDI 32-bit float Little Endian non-interleaved.

Parameters
cdi_audio_ptrPointer to CDI audio sample data.
cdi_audio_sizeSize in bytes of CDI audio data.
num_channelsNumber of audio channels.
num_samples_per_channelNumber of audio samples per channel.
ndi_channel_stride_in_bytesStride in bytes of each NDI channel.
ndi_audio_ptrPointer where to write the NDI audio data.
ndi_size_ptrSize of the NDI audio data buffer.
Returns
Returns status of whether function was successful or not.

◆ CdiToNdiMetadata()

static CdiReturnStatus CdiToNdiMetadata ( const CdiPtpTimestamp * cdi_timestamp_ptr,
const CdiAvmBaselineConfig * avm_config_ptr,
int payload_size,
const CdiSgList * sgl_ptr,
FrameData * frame_data_ptr )
static

Convert CDI metadata to NDI metadata.

Parameters
cdi_timestamp_ptrPointer to CDI timestamp.
avm_config_ptrPointer to CDI AVM configuration data.
payload_sizeSize of CDI payload in bytes.
sgl_ptrPointer to CDI payload data in Scatter-Gather-List format.
frame_data_ptrPointer where to write NDI frame data.
Returns
A value from the CdiReturnStatus enumeration.

◆ CdiToNdiVideo()

static CdiReturnStatus CdiToNdiVideo ( const CdiPtpTimestamp * cdi_timestamp_ptr,
const CdiAvmBaselineConfig * avm_config_ptr,
int payload_size,
const CdiSgList * sgl_ptr,
FrameData * frame_data_ptr )
static

Convert a CDI video frame to NDI.

Returns
A value from the CdiReturnStatus enumeration.

◆ MAX()

static double MAX ( float num1,
float num2 )
static

Find maximum between two numbers.

Parameters
num1Float number.
num2Float number.
Returns
Returns the greater number of the two given.

◆ MIN()

static double MIN ( float num1,
float num2 )
static

Find minimum between two numbers.

Parameters
num1Float number.
num2Float number.
Returns
Returns the lesser number of the two given.

◆ NdiConvertCdiToNdi()

CdiReturnStatus NdiConvertCdiToNdi ( const CdiPtpTimestamp * cdi_timestamp_ptr,
const CdiAvmBaselineConfig * avm_config_ptr,
int payload_size,
const CdiSgList * sgl_ptr,
FrameData * frame_data_ptr )

Convert CDI payload to NDI frame.

Returns
A value from the CdiReturnStatus enumeration.

◆ NdiConvertNdiToCdi()

CdiReturnStatus NdiConvertNdiToCdi ( FrameData * arg_ptr,
int * data_size_ptr,
void ** data_ptr,
int64_t * timestamp_ptr,
CdiAvmBaselineConfig * avm_baseline_config_ptr )

A function that maps information of NDI frame to an AVM structure that is compatible with CDI.

Parameters
arg_ptrFrame Data pointer which stores NDI frame.
data_size_ptrArgument passed in to CDI send containing size of data.
data_ptrArgument passed in to CDI send containing data.
timestamp_ptrArgument passed in to CDI send containing timestamp of data.
avm_baseline_config_ptrArgument passed in to CDI send containing configuration of data.
Returns
A value from the CdiReturnStatus enumeration.

◆ NdiCreateReceiver()

NDIlib_recv_instance_t NdiCreateReceiver ( const TestSettings * test_settings_ptr)

A function which creates a NDI finder, looks for NDI sources, creates a NDI receiver, and connects to a NDI source to receive stream information.

Parameters
test_settings_ptrPointer to Test Settings argument to find NDI source based from the command line, if given.
Returns
Returns a NDI receiver that is connected to a NDI source.

◆ NdiCreateSender()

NDIlib_send_instance_t NdiCreateSender ( const TestSettings * test_settings_ptr)

A function which creates a NDI sender.

Parameters
test_settings_ptrPointer to Test Settings argument to create NDI source based from the command line, if given.
Returns
Returns a NDI sender.

◆ NdiInitialize()

bool NdiInitialize ( void )

A function which initializes the NDI SDK.

Returns
true or false.

◆ NdiReceivePayloadThread()

CDI_THREAD NdiReceivePayloadThread ( void * ndi_thread_data_ptr)

A function that captures NDI frames that is to be written to the memory pool and put in the Payload FIFO. Function also reads from Callback FIFO to determine if NDI frame memory should be released or resent. Function uses a receding time clock element to determine if video frames are being sent consistently at the expected time. If video frame is not seen in expected time, function resends last seen video frame, else it keeps sending new video frames.

Parameters
ndi_thread_data_ptrContains necessary and unchanged data like Test Connections Information.
Returns
Always returns 0.

◆ NdiReleasePayload()

void NdiReleasePayload ( FrameData * arg_ptr)

A function that releases the memory of a NDI video, audio, or metadata frame, and puts back memory pool allocation.

Parameters
arg_ptrA pointer to an Frame Data structure that is to be released.

◆ NdiTimeBreakdown()

NdiTime NdiTimeBreakdown ( int64_t ndi_timestamp)

A function that breaks down the NDI Timestamp, in 100ns format, into seconds, milliseconds, and nanoseconds.

Parameters
ndi_timestampNDI timestamp.
Returns
Returns a structure containing breakdown of NDI timestamp in seconds, milliseconds, and nanoseconds.

◆ NdiToCdiAudio()

static CdiReturnStatus NdiToCdiAudio ( FrameData * frame_data_ptr,
int * buffer_size_ptr,
void ** payload_buffer_ptr,
int64_t * timestamp_ptr,
CdiAvmBaselineConfig * avm_config_ptr )
static

Convert a NDI audio frame to CDI.

Parameters
frame_data_ptrFrame Data pointer which stores NDI frame.
buffer_size_ptrArgument passed in to CDI send containing size of data.
payload_buffer_ptrArgument passed in to CDI send containing data.
timestamp_ptrArgument passed in to CDI send containing timestamp of data.
avm_config_ptrArgument passed in to CDI send containing configuration of data.
Returns
A value from the CdiReturnStatus enumeration.

◆ NdiToCdiAudioConversion()

static bool NdiToCdiAudioConversion ( float * original_audio_ptr,
int num_channels,
int num_samples,
int channel_stride_in_bytes,
int * audio_size_byte_ret_ptr )
static

Convert audio from 32-bit float Little-Endian to 24-bit int Big-Endian PCM. NDI audio frame appear in stacked channels in 32-bit float Little Endian format and CDI audio frame is requested to be in interleaved channels in 24-bit int Big-Endian PCM. Function goes through each NDI channel, reads audio segment in 4 byte segments, converts segment from 32-bit float Little-Endian to 24-bit int Big-Endian PCM, and places 24-bit int segment in jumps, that match interleaved spacing with corresponding number of channels, in temporary buffer. Temporary buffer replaces original NDI audio buffer and the size of the audio in bytes is updated to its new size.

Parameters
original_audio_ptr32-bit float audio given from NDI audio frame.
num_channelsNumber of audio channels given from NDI audio frame.
num_samplesNumber of audio samples given from NDI audio frame.
channel_stride_in_bytesLength of channel stride in bytes given from NDI audio frame.
audio_size_byte_ret_ptrNew total length of audio size in bytes for CDI.
Returns
Returns status of whether function was successful or not.

◆ NdiToCdiMeta()

static CdiReturnStatus NdiToCdiMeta ( FrameData * frame_data_ptr,
int * buffer_size_ptr,
void ** payload_buffer_ptr,
int64_t * timestamp_ptr,
CdiAvmBaselineConfig * avm_config_ptr )
static

Convert a NDI metadata frame to CDI.

Parameters
frame_data_ptrFrame Data pointer which stores NDI frame.
buffer_size_ptrArgument passed in to CDI send containing size of data.
payload_buffer_ptrArgument passed in to CDI send containing data.
timestamp_ptrArgument passed in to CDI send containing timestamp of data.
avm_config_ptrArgument passed in to CDI send containing configuration of data.
Returns
A value from the CdiReturnStatus enumeration.

◆ NdiToCdiVideo()

static CdiReturnStatus NdiToCdiVideo ( const FrameData * frame_data_ptr,
int * buffer_size_ptr,
void ** payload_buffer_ptr,
int64_t * timestamp_ptr,
CdiAvmBaselineConfig * avm_config_ptr )
static

Convert a NDI video frame to CDI.

Parameters
frame_data_ptrPointer to NDI frame data.
buffer_size_ptrPointer where to write the returned size of the CDI payload.
payload_buffer_ptrPointer where to write the returned pointer to the CDI payload data.
timestamp_ptrPointer where to write the returned CDI timestamp.
avm_config_ptrPointer where to write the return CDI AVM data.
Returns
A value from the CdiReturnStatus enumeration.

◆ NdiTransmitPayloadThread()

CDI_THREAD NdiTransmitPayloadThread ( void * ndi_thread_data_ptr)

Thread used to transmit NDI frames.

Parameters
ndi_thread_data_ptrPointer to NDI thread data.
Returns
Always returns 0.