K230 MultimediaMiddleware API Reference#
Directory#
[TOC]
Overview#
Overview#
The location of middleware is k230_sdk/src/common/cdk/user/middleware
This document describes the relevant middleware parts, including video intercom, audio-mixer, fMP4(mp4) muxer and demuxer, players, etc.
Module Description#
Video intercom#
The video intercom supports bidirectional audio and one-way video, is implemented based on rtsp protocol with ONVIF rtsp extension;
The rtsp-server supports audio, video and backchannel audio mediaSubSesisons to send audio, video data to the client and receive audio data from the client.
The rtsp-client supports audio, video and backchannel audio mediaSubSessions to receive audio, video data from the server and send audio data to the server.
Player#
The player supports MP4 file (H264/H265, and G711A-Law/mu-Law).
Audio Mixer#
The audio mixer supports G711 A-Law/mu-Law.
fMP4(Mp4) muxer and demuxer#
This module provides functions of encapsulation, decapsulation for H264/H265 and G711 A-Law/mu-Law in MPEG-4 Part 14(MP4) format, and supports fragment MP4 as well.
API Reference#
Video intercom Server#
KdRtspServer provides the following APIs:
Init:Initializes the rtsp-server.
DeInit:Deinitializes the rtsp-server.
CreateSession:Creates rtsp session.
DestroySession:Destroys rtsp session.
Start:Starts the rtsp-server service.
Stop:Stops the rtsp-server service.
SendVideoData:Writes video stream data.
SendAudioData:Writes audio stream data.
KdRtspServer::Init#
【Description】
Initializes the rtsp-server.
【Syntax】
int Init(Port port = 8554, IOnBackChannel *back_channel = nullptr);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
port |
RTSP service port. |
input |
back_channel |
pointer to the audio data callback. |
input |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: rtsp_server.h
Library files:
【Note】
None
【Example】
None
【See Also】
None
KdRtspServer::DeInit#
【Description】
Deinitializes the rtsp-server.
【Syntax】
void DeInit();
【Parameters】
None
【Return value】
None
【Requirement】
Header files: rtsp_server.h
Library files:
【Example】
None
KdRtspServer::CreateSession#
【Description】
Creates an RtspSession.
【Syntax】
int CreateSession(const std::string &session_name, const SessionAttr &session_attr);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
session_name |
stream url。 |
input |
session_attr |
session configuration parameters. |
input |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: rtsp_server.h
Library files:
【Note】
【Example】
None
KdRtspServer::DestroySession#
【Description】
Destroys the rtsp session。
【Syntax】
int DestroySession(const std::string &session_name);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
session_name |
stream url。 |
input |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: rtsp_server.h
Library files:
【Note】
【Example】
None
【See Also】
None
KdRtspServer::Start#
【Description】
Starts the rtsp-server service.
【Syntax】
void Start();
【Parameters】
None
【Return value】
None
【Requirement】
Header files: rtsp-server.h
Library files:
【Note】
None
【Example】
None
【See Also】
None
KdRtspServer::Stop#
【Description】
Stops the rtsp-server service.
【Syntax】
void Stop();
【Parameters】
None
【Return value】
None
【Requirement】
Header files: rtsp_server.h
Library files:
【Example】
None
KdRtspServer::SendVideoData#
【Description】
Writes the video stream data.
【Syntax】
int SendVideoData(const std::string &session_name, const uint8_t *data, size_t size, uint64_t timestamp);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
session_name |
stream url |
input |
data |
The video data address |
input |
size |
The video data size |
input |
timestamp |
The video data timestamp (ms) |
input |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: rtsp_server.h
Library files:
【Example】
None.
KdRtspServer::SendAudioData#
【Description】
Writes the audio stream data.
【Syntax】
int SendAudioData(const std::string &session_name, const uint8_t *data, size_t size, uint64_t timestamp);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
session_name |
stream url |
input |
data |
The audio stream data address. |
input |
size |
The audio stream data size. |
input |
timestamp |
The audio stream data timestamp (ms) |
input |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: rtsp_server.h
Library files:
【Example】
None
Video intercom Client#
The KdRtspClient module provides the following APIs:
Init:Initializes the rtsp-client.
DeInit:Deinitializes the rtsp-client.
Open:Opens the rtspclient session.
Close:Closes the rtspclient session.
SendAudioData:Writes the backchannel audio stream data.
KdRtspClient::Init#
【Description】
Initializes the rtsp-client
【Syntax】
int Init(const RtspClientInitParam ¶m);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
param |
rtspclient initialization parameters |
input |
class IOnAudioData {
public:
virtual ~IOnAudioData() {}
virtual void OnAudioData(const uint8_t *data, size_t size, uint64_t timestamp) = 0;
};
class IOnVideoData {
public:
enum VideoType {VideoTypeInvalid, VideoTypeH264, VideoTypeH265};
virtual ~IOnVideoData() {}
virtual void OnVideoType(VideoType type, uint8_t *extra_data, size_t extra_data_size) = 0;
virtual void OnVideoData(const uint8_t *data, size_t size, uint64_t timestamp, bool keyframe) = 0;
};
class IRtspClientEvent {
public:
virtual ~IRtspClientEvent() {}
virtual void OnRtspClientEvent(int event) = 0; // event 0: shutdown
};
struct RtspClientInitParam {
IOnVideoData *on_video_data{nullptr}; // callback for video data from server
IOnAudioData *on_audio_data{nullptr}; // callback for audio data from server
IRtspClientEvent *on_event{nullptr}; // callback for rtsp-client event
bool enableBackchanel{false}; // whether enable audio backchannel or not
};
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: rtsp_client.h
Library files:
【Note】
None
【Example】
None
【See Also】
None
KdRtspClient::Deinit#
【Description】
Deinitializes the rtsp-client.
【Syntax】
void DeInit();
【Parameters】
None
【Return value】
None
【Requirement】
Header files: rtsp_client.h
Library files:
【Note】
None
【Example】
None
【See Also】
None
KdRtspClient::Open#
【Description】
Opens the rtspclient session
【Syntax】
int Open(const char *url);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
url |
rtsp url |
input |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: rtsp_client.h
Library files:
【Note】
None
【Example】
None
【See Also】
None
KdRtspClient::Close#
【Description】
Closes the rtsp client。
【Syntax】
void Close();
【Parameters】
None
【Return value】
None
【Requirement】
Header files: rtsp_client.h
Library files:
【Note】
None
【Example】
None
【See Also】
None
KdRtspClient::SendAudioData#
【Description】
Writes the audio back channnel stream data.
【Syntax】
int SendAudioData(const uint8_t *data, size_t size, uint64_t timestamp);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
data |
The audio stream data address |
input |
size |
The audio stream data size |
output |
timestamp |
The audio stream data timestamp (ms) |
output |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: rtsp_client.h
Library files:
【Note】
None
【Example】
None
【See Also】
None
Player#
The KdPlayer module provides the following APIs:
kd_player_init:Initialzes the player.
kd_player_deinit:Deinitializes the player.
kd_player_setdatasource:Sets up media playback file.
kd_player_regcallback:Registers event callbacks.
kd_player_start:Starts to play.
kd_player_stop:Stops.
kd_player_init#
【Description】
Initializes the player.
【Syntax】
k_s32 kd_player_init();
【Parameters】
None
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: kplayer.h
Library files: libkplayer.a
【Note】
None
【Example】
None
【See Also】
None
kd_player_deinit#
【Description】
Deinitializes the player.
【Syntax】
k_s32 kd_player_deinit();
【Parameters】
None
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: kplayer.h
Library files: libkplayer.a
【Note】
None
【Example】
None
【See Also】
None
kd_player_setdatasource#
【Description】
Sets the source file to play.
【Syntax】
k_s32 kd_player_setdatasource(const k_char* filePath);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
filePath |
The path to the media file |
input |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: kplayer.h
Library files: libkplayer.a
【Note】
None
【Example】
None
【See Also】
None
kd_player_regcallback#
【Description】
Registers the event callbacks.
【Syntax】
k_s32 kd_player_regcallback( K_PLAYER_EVENT_FN pfnCallback,void* pData);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
pfnCallback |
The callback function pointer |
input |
pData |
Callback data pointer |
input |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: kplayer.h
Library files: libkplayer.a
【Note】
None
【Example】
None
【See Also】
None
kd_player_start#
【Description】
Starts playing.
【Syntax】
k_s32 kd_player_start();
【Parameters】
None
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: kplayer.h
Library files: libkplayer.a
【Note】
None
【Example】
None
【See Also】
None
kd_player_stop#
【Description】
Stops the playback.
【Syntax】
k_s32 kd_player_stop();
【Parameters】
None
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: kplayer.h
Library files: libkplayer.a
【Note】
None
【Example】
None
【See Also】
None
Audio Mixer#
The Mix module provides the following APIs:
kd_mix_g711a_audio:mixes g711a-law data
kd_mix_g711u_audio:mixer g711mu-law data
kd_mix_g711a_audio#
【Description】
Mixes the G711 a-law data
【Syntax】
k_s32 kd_mix_g711a_audio(k_char *src_data1, k_char *src_data2, k_u32 data_len, k_char *dst_mix_data);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
src_data1 |
Mix source data1 |
input |
src_data2 |
Mix source data 2 |
input |
data_len |
Mix data length |
input |
dst_mix_data |
Mix result data |
output |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: g711_mix_audio.h
Library files: libaudio_mix.a
【Note】
None
【Example】
None
【See Also】
None
kd_mix_g711u_audio#
【Description】
Mixes the G711 mu-law data
【Syntax】
k_s32 kd_mix_g711u_audio(k_char *src_data1, k_char *src_data2, k_u32 data_len, k_char *dst_mix_data);
【Parameters】
Parameter name |
description |
Input/output |
|---|---|---|
src_data1 |
Mix source data1 |
input |
src_data2 |
Mix source data 2 |
input |
data_len |
Mix data length |
input |
dst_mix_data |
Mix result data |
output |
【Return value】
Return value |
description |
|---|---|
0 |
Succeed. |
Non-0 |
Fail. |
【Requirement】
Header files: g711_mix_audio.h
Library files: libaudio_mix.a
【Note】
None
【Example】
None
【See Also】
None
MP4 Muxer and Demuxer#
The MP4 module provides the following APIs:
kd_mp4_create: Creates a MP4 instance
kd_mp4_destroy: Destroys a MP4 instance
kd_mp4_create_track: Creates a track for MP4
kd_mp4_destroy_tracks: Destroys all tracks for MP4
kd_mp4_write_frame: Writes frame data
kd_mp4_get_file_info: Gets information
kd_mp4_get_track_by_index:Gets track information
kd_mp4_get_frame:Gets the audio/video frame data.
kd_mp4_create#
【Description】
Creates a MP4 instance
【Syntax】
int kd_mp4_create(KD_HANDLE *mp4_handle, k_mp4_config_s *mp4_cfg);
【Parameters】
parameter |
description |
Input/output |
|---|---|---|
mp4_handle |
MP4 instance handle |
output |
mp4_cfg |
Parameter configuration information |
input |
【Return value】
Return value |
description |
|---|---|
0 |
succeed |
Non-0 |
fail |
【Requirement】
Header files: mp4_format.h
Library files: libmp4.a
【Note】
Uses mp4_cfg to specify whether to create a muxer instance or a demuxer instance.
【Example】
Refer to the mp4_muxer and mp4_demuxer under the directory “samples”
【See Also】
None
kd_mp4_destroy#
【Description】
Destroys the MP4 instance
【Syntax】
int kd_mp4_destroy(KD_HANDLE mp4_handle);
【Parameters】
parameter |
description |
Input/output |
|---|---|---|
mp4_handle |
MP4 instance handle |
input |
【Return value】
Return value |
description |
|---|---|
0 |
succeed |
Non-0 |
fail |
【Requirement】
Header files: mp4_format.h
Library files: libmp4.a
【Note】
None
【Example】
Refer to the mp4_muxer and mp4_demuxer under the directory “samples”
【See Also】
None
kd_mp4_create_track#
【Description】
Creates a track for MP4
【Syntax】
int kd_mp4_create_track(KD_HANDLE mp4_handle, KD_HANDLE *track_handle, k_mp4_track_info_s *mp4_track_info);
【Parameters】
parameter |
description |
Input/output |
|---|---|---|
mp4_handle |
MP4 instance handle |
input |
track_handle |
Track handle |
output |
mp4_track_info |
Track configuration |
input |
【Return value】
Return value |
description |
|---|---|
0 |
succeed |
Non-0 |
fail |
【Requirement】
Header files: mp4_format.h
Library files: libmp4.a
【Note】
This API is a muxer API and is used when creating an MP4 instance that is a muxer instance
Currently each MP4 instance supports creating up to 3 tracks
【Example】
Refer to the samples under mp4_muxer
【See Also】
None
kd_mp4_destroy_tracks#
【Description】
Destroys all tracks for MP4
【Syntax】
int kd_mp4_destroy_tracks(KD_HANDLE mp4_handle);
【Parameters】
parameter |
description |
Input/output |
|---|---|---|
mp4_handle |
MP4 instance |
input |
【Return value】
Return value |
description |
|---|---|
0 |
succeed |
Non-0 |
fail |
【Requirement】
Header files: mp4_format.h
Library files: libmp4.a
【Note】
None
【Example】
Refer to the samples under mp4_muxer
【See Also】
None
kd_mp4_write_frame#
【Description】
Writes frame data
【Syntax】
int kd_mp4_write_frame(KD_HANDLE mp4_handle, KD_HANDLE track_handle, k_mp4_frame_data_s *frame_data);
【Parameters】
parameter |
description |
Input/output |
|---|---|---|
mp4_handle |
MP4 instance handle |
input |
track_handle |
Track handle |
input |
frame_data |
Frame data information |
input |
【Return value】
Return value |
description |
|---|---|
0 |
succeed |
Non-0 |
fail |
【Requirement】
Header files: mp4_format.h
Library files: libmp4.a
【Note】
None
【Example】
Refer to the samples under mp4_muxer
【See Also】
None
kd_mp4_get_file_info#
【Description】
Gets MP4 file information
【Syntax】
int kd_mp4_get_file_info(KD_HANDLE mp4_handle, k_mp4_file_info_s *file_info);
【Parameters】
parameter |
description |
Input/output |
|---|---|---|
mp4_handle |
MP4 instance handle |
input |
file_info |
MP4 file information |
output |
【Return value】
Return value |
description |
|---|---|
0 |
succeed |
Non-0 |
fail |
【Requirement】
Header files: mp4_format.h
Library files: libmp4.a
【Note】
None
【Example】
Refer to the mp4_demuxer under samples
【See Also】
None
kd_mp4_get_track_by_index#
【Description】
Gets track information based on subscripts
【Syntax】
int kd_mp4_get_track_by_index(KD_HANDLE mp4_handle, uint32_t index, k_mp4_track_info_s *mp4_track_info);
【Parameters】
parameter |
description |
Input/output |
|---|---|---|
mp4_handle |
MP4 instance handle |
input |
index |
subscript |
input |
mp4_track_info |
Track information |
output |
【Return value】
Return value |
description |
|---|---|
0 |
succeed |
Non-0 |
fail |
【Requirement】
Header files: mp4_format.h
Library files: libmp4.a
【Note】
This API is a demuxer API and is used when creating an MP4 instance that is a demuxer instance
【Example】
Refer to the mp4_demuxer under samples
【See Also】
None
kd_mp4_get_frame#
【Description】
Gets the video/audio frame data
【Syntax】
int kd_mp4_get_frame(KD_HANDLE mp4_handle, k_mp4_frame_data_s *frame_data);
【Parameters】
parameter |
description |
Input/output |
|---|---|---|
mp4_handle |
MP4 instance handle |
input |
frame_data |
Stream information |
output |
【Return value】
Return value |
description |
|---|---|
0 |
succeed |
Non-0 |
fail |
【Requirement】
Header files: mp4_format.h
Library files: libmp4.a
【Note】
This API is a demuxer API and is used when creating an MP4 instance that is a demuxer instance
【Example】
Refer to the mp4_demuxer under samples
【See Also】
None
