Skip to content

AidStream C++ API Documentation

C++ API Overview

StructurePublic Member VariableTypeDescription
Imagedataconst char *Pointer to the buffer storing data
data_maskconst char *Pointer to the buffer storing mask data (reserved)
stream_idstringUnique ID identifying the stream (required, convenient for locating in multi-threaded conditions)
widthintTarget image width
heightintTarget image height
width_paddingintTarget image width padding (only used for 6490 ql)
height_paddingintTarget image height padding (only used for 6490 ql)
sizeuint64_tMemory length occupied by image data
fpsdoubleFrame rate
idxuint64_tFrame counter
frame_timestringFrame timestamp (only used for 6490 ql)
Public FunctionDescription
void clogger(const char* path_and_prefix)Create log, set filename and path
void set_log_level(GSTLogLevel log_level)Set log level
typedef function<int8_t( const Image & )> GetImageCBInput parameter for the stream start function, used to get image resources. This function is customized by the user. The interface only provides type definitions to standardize the definition of callback functions.
int start_stream(string stream_id, GetImageCB &cb)Start a stream based on stream id (since stream configuration is complex, it is recommended to configure the stream through a configuration file, this interface is the only recommended interface)
int start_stream_input_file(string file_path, GetImageCB cb, StreamType display_type, string target_path, int width, int height, string stream_id)Start file stream
int start_stream_input_rtsp(string rtsp_addr, GetImageCB cb, StreamType display_type, string target_path, int width, int height, string stream_id)Start RTSP stream
int start_stream_input_rtmp(string rtmp_addr, GetImageCB cb, StreamType display_type, string target_path, int width, int height, string stream_id)Start RTMP stream
ENUMPublic Member VariableTypeDescription
GSTLogLevelSINFOuint8_tLog level SINFO
SWARNINGuint8_tLog level SWARNING
SERRORuint8_tLog level SERROR
SDEBUGuint8_tLog level SDEBUG
SOFFuint8_tLog level SOFF
StreamTypeEMPTYuint8_tStream protocol type empty
WAYLANDSINKuint8_tStream protocol type WayLand
RTSPSINKuint8_tStream protocol type RTSP
RTMPSINKuint8_tStream protocol type RTMP

Structure Image

Defines image data-related information, including image configuration information and pointer variables.

Member VariableTypeDefault ValueDescription
dataconst char *Pointer to the buffer storing data
data_maskconst char *Pointer to the buffer storing mask data (reserved)
stream_idstringUnique ID identifying the stream (required, convenient for locating in multi-threaded conditions)
widthintImage width
heightintImage height
width_paddingintTarget image width padding (only used for 6490 ql)
height_paddingintTarget image height padding (only used for 6490 ql)
sizeuint64_tMemory length occupied by image data
fpsdoubleFrame rate
idxuint64_tFrame counter
frame_timestringFrame timestamp (only used for 6490 ql)

WARNING

Unless otherwise specified, all definitions belong to the namespace Aidlux::AidStream. It can be introduced in the code with the following command:

using namespace Aidlux::AidStream;

Start Stream Based on Stream ID

APIint start_stream(string stream_id, GetImageCB &cb)
DescriptionStart a stream. Parameter is stream id.
Stream id and corresponding configuration are defined in the file /usr/local/share/aidstream-gst/conf/aidstream-gst.conf.
The stream id in this configuration file must be unique.
Note: This interface is the only strongly recommended interface
Parametersstream_id: Identifies a unique stream configuration.
cb: Callback function. Regarding callback functions, please refer to Callback Function.
For information on how to set up the configuration file, please refer to Reference
Return Value0: Success,
-1: Failure

Example:

cpp
// Start a stream identified as stream1
int res = start_stream("stream1", my_cb);

Start File Stream

APIint start_stream_input_file(string file_path, GetImageCB cb, StreamType display_type, string target_path, int width, int height, string stream_id)
DescriptionStart a file stream. Does not depend on configuration file, directly configure corresponding parameters.
Parametersfile_path: Source MP4 data file.
cb: Callback function.
display_type: Output stream type.
target_path: Output stream target address.
Note: width and height are no longer effective
Return Value0: Success,
-1: Failure

Example:

cpp
// Start file stream
int res = start_stream_input_file("./test.mp4", my_cb, StreamType::WAYLANDSINK, "rtsp://192.168.111.115:8554/aidstream-gst-test-6");

Start RTSP Stream

APIint start_stream_input_rtsp(string rtsp_addr, GetImageCB cb, StreamType display_type, string target_path, int width, int height, string stream_id)
DescriptionStart RTSP stream. Does not depend on configuration file, directly configure corresponding parameters.
Parametersrtsp_addr: Source RTSP address.
cb: Callback function.
display_type: Output stream type.
target_path: Output stream target address.
Note: width and height are no longer effective
Return Value0: Success,
-1: Failure

Example:

cpp
// Start RTSP stream
int res = start_stream_input_rtsp("rtsp://admin:aidlux123@192.168.110.234:554/h264/ch1/main/av_stream", my_cb, StreamType::RTSPSINK, "rtsp://192.168.111.115:8554/aidstream-gst-test-3");

Start RTMP Stream

APIint start_stream_input_rtmp(string rtmp_addr, GetImageCB cb, StreamType display_type, string target_path, int width, int height, string stream_id)
DescriptionStart RTMP stream. Does not depend on configuration file, directly configure corresponding parameters.
Parametersrtmp_addr: Source RTMP address.
cb: Callback function.
display_type: Output stream type.
target_path: Output stream target address.
Note: width and height are no longer effective
Return Value0: Success,
-1: Failure

Example:

cpp
// Start RTMP stream
int res = start_stream_input_rtmp("rtmp://admin:aidlux123@192.168.110.234:554/h264/ch1/main/av_stream", my_cb, StreamType::EMPTY, "rtsp://192.168.111.115:8554/aidstream-gst-test-2");

Create Log, Set Filename and Path (function clogger)

APIvoid clogger(const char* path_and_prefix)
DescriptionCreate log, set filename and path
Parameterspath_and_prefix: Log filename with path.
Example: "./aidclog_aidstream_".
Return ValueNone

Example:

cpp
// Create log, set filename and path
const char* log_path = "./aidclog_aidstream_";
Aidlux::AidStream::clogger(log_path);

Set Log Level (function set_log_level)

APIvoid set_log_level(GSTLogLevel log_level)
DescriptionSet log level.
Parameterslog_level is an enumeration of GSTLogLevel type.
For information about GSTLogLevel, please refer to Enum GSTLogLevel
Return ValueNone

Example:

cpp
// Set log level
Aidlux::AidStream::set_log_level(GSTLogLevel::SINFO);

Log Level (Enum GSTLogLevel)

Member VariableTypeDefault ValueDescription
SINFOuint8_t0Log level SINFO
SWARNINGuint8_tLog level SWARNING
SERRORuint8_tLog level SERROR
SDEBUGuint8_tLog level SDEBUG
SOFFuint8_tLog level SOFF

Stream Type (Enum StreamType Protocol Type)

Member VariableTypeDefault ValueDescription
EMPTYuint8_t0Stream protocol type empty
WAYLANDSINKuint8_tStream protocol type Wayland
RTSPSINKuint8_tStream protocol type RTSP
RTMPSINKuint8_tStream protocol type RTMP

Callback Function GetImageCB

APItypedef std::function<int8_t(const Image & )> GetImageCB
DescriptionInput parameter for the stream start function, used to get image resources. This function is customized by the user. The interface only provides type definitions to standardize the definition of callback functions.
ParametersThe first parameter is an instantiated object of the structure Image, through which data is passed in.
Image object includes parameters such as pointers to data buffer, data width and height, frame rate, etc.
Please refer to Image for details
Return ValueCustom

Example:

cpp
// Callback function definition
int8_t my_get_img_cb(const Image & img)
{
    printf("width: %d, height: %d, fps: %f\n", img.width, img.height, img.fps);
    ......
    return 0;
}