chore: migrate project into clean repository

This commit is contained in:
yuuux
2026-08-13 16:50:52 +08:00
commit d1d25a09e7
27405 changed files with 9422808 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
#ifndef LINGXIN_ASRT_H
#define LINGXIN_ASRT_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdbool.h>
#include <stddef.h>
// 定义ASR事件类型的枚举
typedef enum
{
ASR_EVENT_ON_READY, // 当ASR准备就绪时触发
ASR_EVENT_ON_SEND_START, // 当ASR可以接收音频时触发
ASR_EVENT_ON_SEND_RESULT, // 当ASR结果回调时触发
ASR_EVENT_ON_SEND_END, // 当ASR结果回调完成时触发
ASR_EVENT_ON_ERROR, // 当ASR发生错误时触发
ASR_EVENT_ON_DESTROY // 当ASR对象被销毁时触发
} ASREventType;
typedef struct ASRHandler ASRHandler;
typedef struct
{
char *taskId;
char *requestId; // 请求ID
char *instanceId;
} ASRExtraInfo;
typedef void (*ASREventListener)(ASREventType event, const char *data,
size_t dataSize, ASRExtraInfo *extraInfo);
typedef struct
{
const char *appKey;
const char *sn;
const char *appId;
} ASRConfig;
char *asrCreate(ASRHandler **handlerAddress, ASRConfig *config, ASREventListener listener);
bool asrSendStart(ASRHandler *handler, const char *taskId, const char *payload);
int asrSend(ASRHandler *handler, const char *audioData, size_t dataSize);
bool asrSendStop(ASRHandler *handler, const char *taskId);
void asrDestroy(ASRHandler *handler);
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_ASRT_H

View File

@@ -0,0 +1,204 @@
#ifndef __CHAT_API_H__
#define __CHAT_API_H__
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdbool.h>
#include <stddef.h>
typedef char *(*AuthAppIdGetFunc)(void);
typedef char *(*AuthLicenseGetFunc)(void);
typedef char *(*AuthSnGetFunc)(void);
typedef char *(*AuthAppCodeGetFunc)(void);
typedef char *(*DeviceCodeGetFunc)(void);
typedef char *(*ChatBizParameterGetFunc)(void);
typedef char *(*ChatCustomParameterGetFunc)(void);
// 退出完成Code
typedef enum
{
EXIT_REASON_USER_INITIATED, // 0. 主动退出
EXIT_REASON_WEBSOCKET_DISCONNECT, // 1. websocket异常断开可能原因断网
EXIT_REASON_WEBSOCKET_CONNECTION_FAILED, // 2. websocket建联失败
EXIT_REASON_NO_INPUT_TIMEOUT, // 3. 持续无输入超时自动退出
EXIT_REASON_EXCEPTION_TIMEOUT, // 4. 内部异常超时退出
} ExitCode;
// 退出完成事件载荷
typedef struct
{
ExitCode exit_code; // 退出类型
char *reason; // 具体的退出原因
} ExitPayload;
typedef enum
{
CHAT_PHASE_STANDBY, // 0. 待命中
CHAT_PHASE_STARTING, // 1. 启动中
CHAT_PHASE_INPUTING, // 2. 输入中
CHAT_PHASE_THINKING, // 3. 思考中
CHAT_PHASE_OUTPUTING, // 4. 输出中
CHAT_PHASE_INTERRUPTING, // 5. 打断中
CHAT_PHASE_EXITING, // 6. 退出中
} ChatPhaseCode;
// 对话模式阶段变化事件载荷
typedef struct
{
ChatPhaseCode phase_code;
} ChatPhaseChangePayload;
// 对话模式生命周期事件
typedef enum
{
CHAT_LIFE_CYCLE_EVENT_EXIT, // 0. 退出完成
CHAT_LIFE_CYCLE_EVENT_SCHEDULE_EMIT, // 1. 定时任务触发
CHAT_LIFE_CYCLE_EVENT_TEXT_OUT, // 2. 指令+文本
CHAT_LIFE_CYCLE_EVENT_PLAY_END, // 3. 播放完成事件
CHAT_LIFE_CYCLE_EVENT_CHAT_PHASE_CHANGE, // 4. 对话模式阶段变化
CHAT_LIFE_CYCLE_EVENT_ERROR, // 5. 错误事件
} ChatLifeCycleEvent;
typedef void (*ChatLifeCycleEventListener)(ChatLifeCycleEvent event, void *payload);
// 多模态相关方法
// (1) 多模态发送流
typedef struct
{
char *unique_id;
int index;
char *frame;
int content_len;
char *content_type;
bool is_last;
} LingxinSendStreamProps;
typedef bool (*LingxinSendStream)(LingxinSendStreamProps *send_stream_props);
// (2) 多模态发送文本
typedef struct
{
char *content;
} LingxinSendTextProps;
typedef bool (*LingxinSendText)(LingxinSendTextProps *send_text_props);
// (3) 多模态打开内置录音
typedef struct
{
} LingxinStartRecordProps;
typedef bool (*LingxinStartRecord)(LingxinStartRecordProps *start_record_props);
// (4) 多模态关闭内置录音
typedef struct
{
} LingxinStopRecordProps;
typedef bool (*LingxinStopRecord)(LingxinStopRecordProps *stop_record_props);
// (5) 多模态本轮输入结束
typedef struct
{
char *unique_id;
char *content_type;
} LingxinConfirmData;
typedef struct
{
size_t confirm_data_count;
LingxinConfirmData *confirm_data_array;
} LingxinInputEndProps;
typedef bool (*LingxinInputEnd)(LingxinInputEndProps *input_end_props);
// 多模态事件回调
typedef enum
{
LINGXIN_MULTIMODAL_EVENT_INPUT_START = 0,
LINGXIN_MULTIMODAL_EVENT_RECORDER_START = 1,
LINGXIN_MULTIMODAL_EVENT_RECORDER_STOP = 2,
LINGXIN_MULTIMODAL_EVENT_INPUT_INTERRUPT = 3,
LINGXIN_MULTIMODAL_EVENT_STREAM_INPUT_SUCCESS = 4,
} LingxinMultimodalInputEvent;
// 多模态输入开始监听方法参数
typedef struct
{
LingxinSendStream send_stream;
LingxinSendText send_text;
LingxinStartRecord start_record;
LingxinStopRecord stop_record;
LingxinInputEnd input_end;
LingxinMultimodalInputEvent event;
char *event_payload;
} LingxinMultimodalInputListenerProps;
typedef void (*LingxinMultimodalInputListener)(LingxinMultimodalInputListenerProps props);
// 对话模式初始化方法与参数
typedef struct
{
AuthAppIdGetFunc auth_app_id_get_func; // (必填) 获取appId的方法
AuthLicenseGetFunc auth_license_get_func; // (必填) 获取license的方法
AuthSnGetFunc auth_sn_get_func; // (必填) 获取sn的方法
AuthAppCodeGetFunc auth_app_code_get_func; // (必填) 获取appCode的方法也可以是agentCode
DeviceCodeGetFunc device_code_get_func; // 获取设备型号的方法
ChatBizParameterGetFunc chat_biz_parameter_get_func; // 获取业务参数的方法
ChatCustomParameterGetFunc chat_custom_parameter_get_func; // 获取自定义参数的方法
int websocket_check_interval; // 检测websocket连接状态的间隔时间
int websocket_check_timeout; // 检测websocket连接状态的超时时间
ChatLifeCycleEventListener chat_life_cycle_event_listener;
int send_uni_size; // 设置录音单次发送的大小(字节)
int send_cbuf_scale; // 设置录音缓冲区大小对于单次发送大小的倍数
char *welcome_audio_path; // 设置首次唤醒后播放的音频
char *terminate_audio_path; // 设置打断时播放的音频
char *continue_audio_path; // 设置连续对话进入下一轮对话前播放的音频
int is_schedule_task_on; // 是否开启定时任务
int is_log_upload_on; // 是否开启日志
char *props_init_tag; // 标记是否经过灵芯自带的初始化,用户无需关心
char *flash_cache_path; // 设置flash中可用于缓存文件的分区路径分区可用存储空间需要大于600K
} VoiceChatInitProps;
VoiceChatInitProps get_voice_chat_init_default_props();
/**
* 对话模式初始化
* @param init_props 对话模式初始化参数
* @return 0: 初始化成功,-1: 参数有误,-2: 音频格式不支持
*/
int voice_chat_init(VoiceChatInitProps *init_props);
// 对话模式新一轮对话方法与参数
typedef struct
{
bool disable_welcome_audio; // 首次唤醒是否需要开场白
bool disable_vad; // 本轮对话是否启用云端VAD仅首轮禁用废弃
char *task_id; // 本轮对话是否指定task_id
char *task; // 本轮对话的场景 (chat_vad/chat/translate/chat_multimodal)
bool single_round; // 本轮对话是否为仅单轮对话
char *user_input; // 用户输入的文本
LingxinMultimodalInputListener multimodal_input_listener; // 多模输入开始事件监听
char *props_init_tag; // 标记是否经过灵芯自带的初始化,用户无需关心
} StartNewChatProps;
StartNewChatProps get_start_new_chat_default_props();
int start_new_chat(StartNewChatProps *start_props);
// 对话模式主动停止录音方法与参数
typedef struct
{
} StopChatRecordProps; // 用于后续拓展
int stop_chat_record(StopChatRecordProps *stop_record_props);
// 对话模式退出方法与参数
typedef struct
{
bool disable_close_ws_immediately; // 是否立即关闭websockettrue为立即断联false为不立即断联
char *props_init_tag; // 标记是否经过灵芯自带的初始化,用户无需关心
} ExitChatProps;
ExitChatProps get_exit_chat_default_props();
int exit_chat(ExitChatProps *exit_props);
// 加音量
int set_volume(int volume);
#ifdef __cplusplus
}
#endif
#endif // __CHAT_API_H__

View File

@@ -0,0 +1,41 @@
#ifndef LINGXIN_LOG_H
#define LINGXIN_LOG_H
#ifdef __cplusplus
extern "C"
{
#endif
/**
*
* 灵芯log模块
* log 方法支持的最长参数为512字节
* log中自动添加当前文件名和代码行无需手动设置
* log格式[time] [version] [level] [module:line] [node]: log内容
*/
/** log级别 */
#define LINGXIN_DEBUG (1 << 0)
#define LINGXIN_WARN (1 << 1)
#define LINGXIN_ERROR (1 << 2)
/* 下面四种方法仅打印log不缓存 */
#define lingxin_log_debug(format, ...) _lingxin_log_print_internal_(LINGXIN_DEBUG, 0, __FILE__, __LINE__, NULL, format, ##__VA_ARGS__)
#define lingxin_log_warn(format, ...) _lingxin_log_print_internal_(LINGXIN_WARN, 0, __FILE__, __LINE__, NULL, format, ##__VA_ARGS__)
#define lingxin_log_error(format, ...) _lingxin_log_print_internal_(LINGXIN_ERROR, 0, __FILE__, __LINE__, NULL, format, ##__VA_ARGS__)
/**
* log_level参数使用上面的log级别
* 该方法log打印并缓存上传云端
* */
#define lingxin_log_ut(log_level, node_name) _lingxin_log_print_internal_(log_level, 1, __FILE__, __LINE__, node_name, "")
#define lingxin_log_ut_with_args(log_level, node_name, format, ...) _lingxin_log_print_internal_(log_level, 1, __FILE__, __LINE__, node_name, format, ##__VA_ARGS__)
// 内部方法,勿用
void _lingxin_log_print_internal_(int log_level, int is_ut, const char *file_path, int line, const char *node_name, const char *format, ...);
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_LOG_H

View File

@@ -0,0 +1,69 @@
#ifndef LINGXIN_MEMORY_H
#define LINGXIN_MEMORY_H
#ifdef __cplusplus
extern "C"
{
#endif
#include "lingxin_memory.h"
/**
* 申请内存
* @param size 申请内存大小,单位是字节
* * @return 返回指向分配内存的指针,内存已清零;如果分配失败则返回 NULL
*/
#define lingxin_malloc(size) _lingxin_malloc_internal_((size), __FILE__, __LINE__)
/**
* 申请内存并清零申请的内存
* @param num 申请的内存块数量
* @param size 每个内存块的大小,单位是字节
* @return 返回指向分配内存的指针,内存已清零;如果分配失败则返回 NULL
*/
#define lingxin_calloc(num, size) _lingxin_calloc_internal_((num), (size), __FILE__, __LINE__)
/**
* 重新分配内存
*/
#define lingxin_realloc(ptr, size) _lingxin_realloc_internal_((void *)(ptr), (size), __FILE__, __LINE__)
/**
* 释放内存
* @param ptr 要释放的内存指针
*/
#define lingxin_free(ptr) _lingxin_free_internal_((void *)(ptr), __FILE__, __LINE__)
/**
* 申请字符串内存并复制字符串
*/
#define lingxin_strdup(message) _lingxin_strdup_internal_((char *)(message), __FILE__, __LINE__)
/**
* 启用内存统计功能
*/
void lingxin_memory_enable_statistics();
/**
* 打印内存使用情况
*/
void lingxin_memory_print_statistics();
/*
* 销毁内存统计数据
*/
void lingxin_memory_destroy_statistics();
/**
* 私有函数实现,不对外
*/
void *_lingxin_malloc_internal_(int size, const char *file_path, int line);
void *_lingxin_calloc_internal_(int num, int size, const char *file_path, int line);
void *_lingxin_realloc_internal_(void *ptr, int size, const char *file_path, int line);
void _lingxin_free_internal_(void *ptr, const char *file_path, int line);
char *_lingxin_strdup_internal_(char *message, const char *file_path, int line);
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_MEMORY_H

View File

@@ -0,0 +1,25 @@
#ifndef LINGXIN_GENERATE_BY_LLM_H
#define LINGXIN_GENERATE_BY_LLM_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdbool.h>
typedef void (*GenerateTextRequestCallback)(char *contents, int finish);
void generateText(const char *appId, const char *sn, const char *appKey, const char *input,
GenerateTextRequestCallback callback);
void generateImage(const char *appId, const char *sn, const char *appKey, const char *requestParams, char **response);
void queryGenerateImageResult(const char *appId, const char *sn,
const char *appKey, const char *requestParams, char **response);
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_GENERATE_BY_LLM_H

View File

@@ -0,0 +1,55 @@
#ifndef LINGXIN_TTS_H
#define LINGXIN_TTS_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdbool.h>
#include <stddef.h>
// 定义tts事件类型的枚举
typedef enum
{
TTS_EVENT_ON_READY, // 当tts准备就绪时触发
TTS_EVENT_ON_SEND_START, // 当tts可以接收文本时触发
TTS_EVENT_ON_SEND_RESULT, // 当tts结果回调时触发
TTS_EVENT_ON_SEND_END, // 当tts结果回调完成时触发
TTS_EVENT_ON_ERROR, // 当tts发生错误时触发
TTS_EVENT_ON_DESTROY // 当tts对象被销毁时触发
} TTSEventType;
typedef struct
{
const char *appKey;
const char *sn;
const char *appId;
} TTSConfig;
typedef struct TTSHandler TTSHandler;
typedef struct
{
char *taskId;
char *requestId; // 请求ID
char *instanceId;
} TTSExtraInfo;
typedef void (*TTSEventListener)(TTSEventType event, const char *data,
const size_t len, TTSExtraInfo *extraInfo);
char *ttsCreate(TTSHandler **handlerAddress, TTSConfig *config, const char *payload, TTSEventListener listener);
bool ttsSendStart(TTSHandler *handler, const char *taskId);
int ttsSend(TTSHandler *handler, const char *taskId, const char *text);
bool ttsSendStop(TTSHandler *handler, const char *taskId);
void ttsDestroy(TTSHandler *handler);
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_TTS_H

View File

@@ -0,0 +1,28 @@
#ifndef AUDIO_BUFFER_PLAY_H
#define AUDIO_BUFFER_PLAY_H
#include "download_audio_play_interface.h"
// 功能在方法里面实现模块的初始化逻辑。并且Chat套件内核会多次回调这个方法如果当前模块已经初始化成功可直接回调初始化成功的回调事件。
// 调用时机由chat套件内核发起调用客户实现
void module_bufferPlay_audioInit(PlaybackEventHandler callback, void *user_data);
// buf为mp3数据 rlen为当前数据长度
void module_bufferPlay_data(void *buf, int rlen);
// 功能指Chat套件内核调用流式播放模块告诉他已经没有流式播放数据了并非要立刻停止播放。
// 调用时机由chat套件内核发起调用客户实现
void module_bufferPlay_audioEnd();
// 功能:停止当前的播放逻辑
// 调用时机由chat套件内核发起调用客户实现
void module_bufferPlay_terminate();
// 功能:设置当前播放的音量
// 调用时机由chat套件内核发起调用客户实现
void module_bufferPlay_setVolume(int volume);
#endif // AUDIO_BUFFER_PLAY_H

View File

@@ -0,0 +1,51 @@
#ifndef CHAT_STATE_MACHINE_EVENT_H
#define CHAT_STATE_MACHINE_EVENT_H
// 模块抛给状态机的事件
typedef enum
{
State_Event_Wakeup_Detected = 0, // 唤醒事件
State_Event_Welcome_Play_End = 1, // 播放欢迎语结束事件
State_Event_VoiceChat_TerminateEnd = 3, // voice chat 打断成功事件
State_Event_VoiceChat_AIEnd = 5, // voice chat 结束推送语音流(注:原文注释有误,已修正)
State_Event_Vad_Stop = 6, // vad 停止
State_Event_Vad_Exit = 7, // vad 退出唤醒
State_Event_BufferPlay_AudioInitEnd = 8, // 流式播放初始化结束
State_Event_BufferPlay_PlayEnd = 9, // 流式播放结束
State_Event_BufferPlay_TerminateEnd = 10, // 流式播放打断后暂停
State_Event_BufferPlay_Error = 11, // 流式播放模块出错
State_Event_Upload_InitEnd = 12, // 录音模块初始化成功
State_Event_Upload_CloseEnd = 13, // 录音模块停止录音
State_Event_Upload_TerminateEnd = 14, // 录音模块打断事件
State_Event_VoiceChat_ExitEnd = 15, // voice chat 对话退出成功
State_Event_WillExit = 16, // 用户调用退出
State_Event_NoVoice_Start = 17, // 开启新一轮novoice模式
State_Event_NoVoice_Error = 18, // noVoice下行阶段服务端推送error
State_Event_NoVoice_TerminateEnd = 19,
State_Event_TerminatePrompt_PlayEnd = 20, // 增加打断唤醒提示音
State_Event_ContinuePrompt_PlayEnd = 21, // 增加连续对话提示音
// ==== 仅 task complete 状态内部使用的事件 ====
Event_Inc_TaskComplete_PlayEnd = 22, // 用于表明已经将时机转发给客户
Event_Inc_TaskComplete_End = 25, // 用于表明已经将时机转发给客户
// ==== 仅 下行 状态内部使用的事件 ====
Event_Inc_Download_End = 24, // 用于下行状态结束
} StateEvent;
/******************** 在chat套件内核中已实现客户调用 ********************/
// 模块抛出事件给调用状态机
void state_machine_run_event(StateEvent event);
// 录音模块把录音数据发送给状态机
void state_machine_post_record_data(void *buf, int rlen, int index);
#endif // CHAT_STATE_MACHINE_EVENT_H

View File

@@ -0,0 +1,24 @@
#ifndef LINGXIN_CHIP_INFO_H
#define LINGXIN_CHIP_INFO_H
#ifdef __cplusplus
extern "C"
{
#endif
/**
* 获取设备对应的芯片名称
* 举例: LINGXIN_芯片名称
*/
char *get_lingxin_device_name();
/**
* 获取设备对应的灵芯版本
* 举例0.0.1
*/
char *get_lingxin_device_version();
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_CHIP_INFO_H

View File

@@ -0,0 +1,88 @@
#ifndef LINGXIN_FILE_H
#define LINGXIN_FILE_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdbool.h>
/**
* 创建指定大小的文件
*
* @param file_path 文件名称
* @param length 文件大小
*
* @return true:创建成功 false:创建失败
*/
bool lingxin_file_create(const char *file_path, int length);
/**
* 根据指定名称的文件,从指定的起始位置开始,读取一定大小的文件内容到缓冲区中
*
* @param file_path 文件名称
* @param buffer 要写入的缓冲区
* @param offet 需要读取的文件内容偏移位置
* @param length 需要读取的文件内容长度
*
* @return true:读取成功 false:读取失败
*/
bool lingxin_file_read(const char *file_path, char *buffer, int offet, int length);
/**
* 向指定名称的文件中写入一定长度的内容
*
* @param file_path 文件名称
* @param is_append 是否以追加模式写入文件
* @param data 要写入的内容
* @param length 要写入的内容长度
*
* @return true:写入成功 false:写入失败
*/
bool lingxin_file_write(const char *file_path, bool is_append, const char *data, int length);
/**
* 检查指定名称的文件是否存在
*
* @param file_path 文件名称
*
* @return true:存在 false:不存在
*/
bool lingxin_file_exist(const char *file_path);
/**
* 获取指定名称的文件内容长度(文件大小)
*
* @param file_path 文件名称
*
* @return 文件内容长度(文件大小)
*/
int lingxin_file_length(const char *file_path);
/**
* 删除指定名称的文件
*
* @param file_path 文件名称
*
* @return true:删除成功 false:删除失败
*/
bool lingxin_file_delete(const char *file_path);
/**
* 清空指定名称的文件内容
*
* @param file_path 文件名称
*
* @return true:清理成功 false:清理失败
*/
bool lingxin_file_clear(const char *file_path);
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_FILE_H

View File

@@ -0,0 +1,45 @@
// httpclient.h
#ifndef LINGXIN_HTTP_HTTPCLIENT_H
#define LINGXIN_HTTP_HTTPCLIENT_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stddef.h>
typedef void (*RequestCallback)(void *contents, size_t size, void *userp);
typedef struct
{
const char *signature;
const char *sn;
const char *app_id;
const char *timestamp;
} HttpHeader;
typedef struct
{
const char *protocol; // http or https
const char *host;
const char *path;
int port;
const char *post_data;
HttpHeader *headers;
} HttpConfig;
/**
* http_post 方法适配
*
* @param config http配置
* @param userCallback 回调函数
* @param userData 需要透传的参数在userCallback中会透传给用户
*
* @return: 0: fail 其他: success
*/
int http_post(HttpConfig *config, RequestCallback userCallback, void *userData);
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_HTTP_HTTPCLIENT_H

View File

@@ -0,0 +1,60 @@
#ifndef __LINGXIN_LOCAL_PLAYER_H__
#define __LINGXIN_LOCAL_PLAYER_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* 本地播放器句柄
*/
typedef void *lingxin_local_player_t;
/**
* 本地播放器回调函数
* @param result 播放结果。0为播放成功-1为播放失败
*/
typedef void (*lingxin_local_player_callback_t)(int result);
/**
* 创建本地播放器
* @return 本地播放器句柄
*/
lingxin_local_player_t lingxin_local_player_create();
/**
* 定义播放参数的结构体
*/
typedef struct {
// 音频路径
char *audio_path;
// 初始音量
int initial_volume;
} lingxin_local_player_play_param_t;
/**
* 播放本地音频
* @param player 本地播放器句柄
* @param param 播放参数结构体的指针
* @param callback 播放回调函数
*/
void lingxin_local_player_play(lingxin_local_player_t player, lingxin_local_player_play_param_t *param, lingxin_local_player_callback_t callback);
/**
* 设置播放的音量
* @param player 本地播放器句柄
* @param volume 音量
*/
void lingxin_local_player_set_volume(lingxin_local_player_t player, int volume);
/**
* 销毁本地播放器
* @param player 本地播放器句柄
*/
void lingxin_local_player_destory(lingxin_local_player_t player);
#ifdef __cplusplus
}
#endif
#endif // __LINGXIN_LOCAL_PLAYER_H__

View File

@@ -0,0 +1,43 @@
#ifndef __LINGXIN_MUTEX_H__
#define __LINGXIN_MUTEX_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
/**
* 互斥锁句柄
*/
typedef void *lingxin_mutex_t;
/**
* 创建互斥锁
*/
lingxin_mutex_t lingxin_mutex_create();
/**
* 互斥锁 Lock
* @param mutex 互斥锁句柄
*/
void lingxin_mutex_lock(lingxin_mutex_t mutex);
/**
* 互斥锁 Unlock
* @param mutex 互斥锁句柄
*/
void lingxin_mutex_unlock(lingxin_mutex_t mutex);
/**
* 销毁互斥锁
* @param mutex 互斥锁句柄
*/
void lingxin_mutex_destroy(lingxin_mutex_t mutex);
#ifdef __cplusplus
}
#endif
#endif /* __LINGXIN_MUTEX_H__ */

View File

@@ -0,0 +1,19 @@
#ifndef __LINGXIN_PRINTF_H__
#define __LINGXIN_PRINTF_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* 打印方法
* @param message 打印信息
*/
void lingxin_printf(char* message);
#ifdef __cplusplus
}
#endif
#endif /* __LINGXIN_PRINTF_H__ */

View File

@@ -0,0 +1,74 @@
#ifndef __LINGXIN_RECORDER_H__
#define __LINGXIN_RECORDER_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* 录音器句柄
*/
typedef void *lingxin_recorder_t;
/**
* 录音器开启/关闭回调函数
* @param result 开启/关闭结果。0为开启/关闭成功;-1为开启/关闭失败
*/
typedef void (*lingxin_recorder_callback_t)(int result);
/******************** 由chat套件内核发起调用客户实现 ********************/
/**
* 创建录音
*/
lingxin_recorder_t lingxin_recorder_create();
/**
* 开启录音参数的结构体
*/
typedef struct {
// 录音单次发送的大小
int frame_size;
} lingxin_recorder_open_param_t;
/**
* 开启录音
* @param recorder 录音句柄
* @param param 开启录音参数的结构体的指针
* @param callback 录音开启的回调(参数result: 0-成功/-1-失败)
*/
void lingxin_recorder_open(lingxin_recorder_t recorder, lingxin_recorder_open_param_t *param, lingxin_recorder_callback_t callback);
/**
* 关闭录音
* @param recorder 录音句柄
* @param callback 录音关闭的回调(参数result: 0-成功/-1-失败)
*/
void lingxin_recorder_close(lingxin_recorder_t recorder, lingxin_recorder_callback_t callback);
/**
* 销毁录音
* @param recorder 录音句柄
*/
void lingxin_recorder_destroy(lingxin_recorder_t recorder);
/**
* 获取默认每毫秒的录音大小
* @return 每毫秒的录音大小
*/
int lingxin_recorder_get_size_per_ms();
/******************** 由chat套件内核实现客户调用 ********************/
/**
* 发送录音数据
* @param data 录音数据指针
* @param len 录音数据长度
*/
void lingxin_process_record_data(void *data, int len);
#ifdef __cplusplus
}
#endif
#endif // __LINGXIN_RECORDER_H__

View File

@@ -0,0 +1,50 @@
#ifndef __LINGXIN_SEMAPHORE_H__
#define __LINGXIN_SEMAPHORE_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/**
* 信号量句柄
*/
typedef void *lingxin_semaphore_t;
/**
* 创建信号量
* @param cnt 信号量初始值
*/
lingxin_semaphore_t lingxin_semaphore_create(uint32_t cnt);
/**
* 等待信号量
* @param sem 信号量句柄
* @param timeout_ms 等待超时时间,单位为毫秒
*/
void lingxin_semaphore_pend(lingxin_semaphore_t sem, uint32_t timeout_ms);
/**
* 发送信号量
* @param sem 信号量句柄
*/
void lingxin_semaphore_post(lingxin_semaphore_t sem);
/**
* 给信号量设值,用于清零信号量
* @param sem 信号量句柄
*/
void lingxin_semaphore_set_value(lingxin_semaphore_t sem, uint32_t cnt);
/**
* 销毁信号量
* @param sem 信号量句柄
*/
void lingxin_semaphore_destroy(lingxin_semaphore_t sem);
#ifdef __cplusplus
}
#endif
#endif /* __LINGXIN_SEMAPHORE_H__ */

View File

@@ -0,0 +1,17 @@
#ifndef __LINGXIN_SYSTEM_H__
#define __LINGXIN_SYSTEM_H__
#ifdef __cplusplus
extern "C" {
#endif
/**
* 系统重启函数(仅在适配测试时需实现)
*/
void lingxin_system_abort();
#ifdef __cplusplus
}
#endif
#endif // __LINGXIN_SYSTEM_H__

View File

@@ -0,0 +1,35 @@
#ifndef LINGXIN_SYSTEM_TIME_H
#define LINGXIN_SYSTEM_TIME_H
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct
{
int mill_sec;
int sec;
int min;
int hour;
int day;
int mon;
int year;
} LINGXIN_TIME;
/**
* 获取当前时间
* @param lingxin_time 灵芯时间结构体
*/
void lingxin_get_current_time(LINGXIN_TIME *lingxin_time);
/**
* 获取秒级时间戳10 位长度的整数
* @return 时间戳
*/
long lingxin_get_timestamp_s();
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_SYSTEM_TIME_H

View File

@@ -0,0 +1,75 @@
#ifndef __LINGXIN_THREAD_H__
#define __LINGXIN_THREAD_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
/**
* 线程名称最大长度
*/
#define LINXIN_THREAD_NAME_MAX_LENGTH 16
/**
* 线程ID
*/
typedef int lingxin_tid_t;
/**
* 定义线程参数的结构体
*/
typedef struct {
// 线程的名称,最大长度由 LINXIN_THREAD_NAME_MAX_LENGTH 定义
char* name;
// 线程的优先级
int priority;
// 线程的栈大小
int stack_size;
} lingxin_thread_param_t;
/**
* 创建线程
* @param thread 指向存储新线程 ID 的变量的指针
* @param param 指向线程参数结构体的指针
* @param start_routine 线程启动时执行的函数指针
* @param args 传递给线程启动函数的参数
* @return 操作结果的状态码(0表示成功-1表示失败)
*/
int lingxin_thread_create(lingxin_tid_t *thread, const lingxin_thread_param_t *param, void *(*start_routine)(void *), void *args);
/**
* 线程销毁模式枚举
*/
typedef enum {
LINGXIN_THREAD_DESTROY_WAIT = 0, // 等待线程结束
LINGXIN_THREAD_DESTROY_DETACH = 1, // 分离线程,线程运行结束时自动销毁
LINGXIN_THREAD_DESTROY_CANCEL = 2, // 立即取消线程
} lingxin_thread_destroy_mode_t;
/**
* 销毁线程
* @param thread 线程 ID
* @param mode 销毁模式
*/
void lingxin_thread_destroy(lingxin_tid_t thread, lingxin_thread_destroy_mode_t mode);
/**
* 获取当前所在线程名称
* @return 线程名称,如果获取失败则返回 NULL
*/
char* lingxin_get_current_thread_name();
/**
* 线程休眠
* @param time 休眠时间,单位为毫秒
*/
void lingxin_thread_sleep(int time);
#ifdef __cplusplus
}
#endif
#endif /* __LINGXIN_THREAD_H__ */

View File

@@ -0,0 +1,60 @@
#ifndef LINGXIN_TIMER_H
#define LINGXIN_TIMER_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
#define INVALID_TIMER_ID (-1)
// 周期性定时器
/**
* @brief sys_timer定时扫描增加接口创建一个周期性定时器
* @param priv 定时器回调函数func的私有参数
* @param func 超时扫描回调函数
* @param msec 超时时间, 单位:毫秒
* @return 定时器分配的id号, 创建失败时返回INVALID_TIMER_ID
*/
int lingxin_sys_timer_add(void *priv, void (*func)(void *priv), long msec);
/**
* @brief sys_timer定时扫描删除接口
* @param timer_id sys_timer_add分配的id号
* @return 删除结果0-成功,-1-失败)
*/
int lingxin_sys_timer_del(int timer_id);
/**
* @brief sys_timer定时扫描重置接口
* @param timer_id sys_timer_add分配的id号
* @return 重置结果0-成功,-1-失败)
*/
int lingxin_sys_timer_re_run(int timer_id);
// 一次性定时器
/**
* @brief 创建一个一次性定时器
* @param priv 定时器回调函数func的私有参数
* @param func 定时器回调函数
* @param countdown 超时时间, 单位毫秒值可能为0
* @return 定时器分配的id号, 创建失败时返回INVALID_TIMER_ID
*/
int lingxin_one_shot_timer_create(void *priv, void (*func)(void *priv), long countdown);
/**
* @brief 删除指定的一次性定时器
* @param timerId 定时器ID
* @return 删除结果0-成功,-1-失败)
*/
int lingxin_one_shot_timer_delete(int timerId);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,57 @@
#ifndef LINGXIN_WEBSOCKET_H
#define LINGXIN_WEBSOCKET_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdbool.h>
#include <stddef.h>
typedef enum
{
ON_WEBSOCKET_CONNECTION_SUCCESS, // 建联成功
ON_WEBSOCKET_CONNECTION_FAIL, // 建联失败
ON_WEBSOCKET_DATA_RECEIVED, // 收到数据
ON_WEBSOCKET_DESTROY, // 销毁完成
ON_WEBSOCKET_ERROR // 收到错误
} WebSocketEventType;
typedef void (*WebSocketEventListener)(WebSocketEventType event, const char *data, size_t data_len, const int isBinary, void *userContext);
typedef struct
{
const char *protocol; // ws or wss
const char *host;
const char *path;
const char *header_signature;
const char *header_sn;
const char *header_app_id;
const char *header_timestamp;
int port;
void *userContext;
WebSocketEventListener listener;
} WebsocketConfig;
typedef struct
{
void *clientHandler;
WebsocketConfig *config;
} WebsocketClient;
WebsocketClient *initWebsocket(WebsocketConfig *config);
bool startWebsocket(WebsocketClient *client);
bool websocketSendText(WebsocketClient *client, const char *message);
int websocketSendBinary(WebsocketClient *client, const char *audioData, size_t dataSize);
void closeWebsocket(WebsocketClient *client);
#ifdef __cplusplus
}
#endif
#endif // LINGXIN_WEBSOCKET_H