通信接口说明
该接口是视频流引擎正常运行时对外依赖的通信接口。该接口由二次开发者实现,并以动态链接库的形式提供。调用示例如下:
// 函数原型声明,实现由客户提供 using OnNewConnectionCallback = void (*)(int connection); using RegConnectionCBFunc = int (*)(OnNewConnectionCallback newConnCb); using CloseConnectionFunc = int (*)(int connection); using SendFullyFunc = ssize_t (*)(int connection, uint8_t *buf, size_t len); using RecvFunc = ssize_t (*)(int connection, uint8_t *buf, size_t len); const char *soPath = "./libCommunication.so"; //服务端收到新连接回调函数,由云手机引擎提供 //输入参数connection代表新连接的有效句柄 static void OnNewConnection(int conn); void Test() { // 动态加载通信动态库的函数符号 void *handle = dlopen(soPath, RTLD_GLOBAL | RTLD_LAZY | RTLD_NODELETE); RegConnectionCBFunc regConnection = (RegConnectionCBFunc)dlsym(handle, "RegConnectionCB"); CloseConnectionFunc closeConnection = (CloseConnectionFunc)dlsym(handle, "CloseConnection"); SendFullyFunc sendFully = (SendFullyFunc)dlsym(handle, "SendFully"); RecvFunc recvData = (RecvFunc)dlsym(handle, "Recv"); size_t bufSize = 1024; uint8_t *data = malloc(bufSize); // 创建连接,连接服务端 int connRet = regConnection(OnNewConnection); // 发送数据 ssize_t ret = sendFully(conn, data, bufSize); // 接收数据 ret = recvData(conn, data, bufSize); // 释放资源 free(data); closeConnection(conn); dlclose(handle); }
各接口的详细描述请参见RegConnectionCB~Recv。
父主题: 视频流引擎对外依赖的通信接口(C)