Tange Cloud for Device
Rev.333 |
#include "platforms.h"
#include "icam_const.h"
#include "TgCloudCmd.h"
#include "TgCloudCmdEx.h"
#include "TgCloudConst.h"
#include "icam_struct.h"
结构体 | |
struct | FRAMEHEAD_t |
Audio/Video Frame Header Info 更多... | |
struct | RespHdr |
命令请求/响应包头 更多... | |
struct | RespBuff |
struct | CmdPkt |
struct | FrameBuff |
struct | FramePkt |
struct | MEDIAINFO |
struct | RESPPROCESSOR |
struct | ICAMAUTOCMD |
批处理的单条指令描述 更多... | |
union | RespBuff.__unnamed13__ |
union | MEDIAINFO.u |
struct | MEDIAINFO.u.mt |
宏定义 | |
#define | ICAMP2P_C_EXPORTS |
#define | P2PCONN_TYPE_LAN 1 |
#define | P2PCONN_TYPE_P2P 2 |
#define | P2PCONN_TYPE_RELAY 3 |
#define | MAKE_CONNFLAGS(bLanSearch, iP2pTryTime, bRelay) |
类型定义 | |
typedef struct P2PRAW * | HP2PRAW |
typedef struct P2PCLT * | HP2PCLT |
p2p连接句柄 | |
typedef void(* | FRAMECALLBACK) (FRAMEHEAD_t *fi, unsigned char *data, void *pUser) |
音视频视回调. | |
typedef void(* | ICAMEVENTCALLBACK) (const RTMSG_t *msg, int len, HP2PCLT hClt, void *pUser) |
typedef void(* | ICAMCMDDATACALLBACK) (const void *data, int len, HP2PCLT hClt, void *pUser) |
typedef int(* | RESPCALLBACK) (const void *body, int len, void *pUser) |
函数 | |
ICAMP2P_C_EXPORTS const char * | iCamP2pGetConnTypeName (int connType) |
ICAMP2P_C_EXPORTS int | iCamP2pInit () |
初始化p2p库. | |
ICAMP2P_C_EXPORTS void | iCamP2pDeinit () |
清除p2p库 | |
ICAMP2P_C_EXPORTS int | iCamRawConnect (const char *server, const char *did, int fConnFlags, HP2PRAW *phP2pRaw) |
ICAMP2P_C_EXPORTS int | iCamRawGetConnType (HP2PRAW hRaw) |
ICAMP2P_C_EXPORTS int | iCamRawDisconnect (HP2PRAW hRaw) |
ICAMP2P_C_EXPORTS SA_BOOL | iCamRawCheckValid (HP2PRAW hRaw) |
检查当前连接是否仍有效 | |
ICAMP2P_C_EXPORTS int | iCamRawCheckBuffer (HP2PRAW, int chn, unsigned int to_send, int *fill_percent) |
ICAMP2P_C_EXPORTS int | iCamRawRecv (HP2PRAW hRaw, int avIndex, void *buff, int size, int timeout) |
ICAMP2P_C_EXPORTS int | iCamRawSend (HP2PRAW hRaw, int avIndex, const void *buff, size_t len) |
ICAMP2P_C_EXPORTS int | iCamRawSendV (HP2PRAW hRaw, int avIndex, struct iovec *v, int size) |
ICAMP2P_C_EXPORTS int | iCamRawRecvN (HP2PRAW handle, int avIndex, void *buff, int size, int timeout) |
带超时读取N字节. | |
ICAMP2P_C_EXPORTS int | iCamRawRecvN2 (HP2PRAW handle, int avIndex, void *buff, int size, const SA_BOOL *b_run) |
无超时读取N字节. | |
ICAMP2P_C_EXPORTS int | iCamRawReadCmdPkt (HP2PRAW hRaw, struct CmdPkt *pkt, int timeout, SA_BOOL *pbRun) |
在命令通道上读一个完整包. | |
ICAMP2P_C_EXPORTS int | iCamRawRecvFramePkt (HP2PRAW hRaw, int avIndex, struct FramePkt *pkt, int timeout, SA_BOOL *pbRun) |
在通道上读一个完整帧. | |
ICAMP2P_C_EXPORTS int | iCamRawSendCmd (HP2PRAW handle, int cmd, const void *req, int len) |
ICAMP2P_C_EXPORTS int | iCamRawSendMedia (HP2PRAW hRaw, TCMEDIA mt, uint32_t ts, uint32_t uFrameFlags, const uint8_t *pData, int size) |
ICAMP2P_C_EXPORTS SA_BOOL | iCamP2pCheckValid (HP2PCLT hClt) |
ICAMP2P_C_EXPORTS int | iCamP2pSendCmd (HP2PCLT hClt, int cmd, const void *data, int len) |
ICAMP2P_C_EXPORTS const char * | iCamP2pGetErrorString (int err) |
ICAMP2P_C_EXPORTS int | iCamP2pConnect (const char *server_cfg, const char *did, const char *key, int fConnFlags, HP2PCLT *phP2pClt) |
连接设备. | |
ICAMP2P_C_EXPORTS int | iCamP2pSetCallback (HP2PCLT hClt, ICAMEVENTCALLBACK event_cb, ICAMCMDDATACALLBACK data_cb, void *pUser) |
设备连接的消息/数据回调. | |
ICAMP2P_C_EXPORTS int | iCamP2pConnect2 (const char *server_cfg, const char *did, int fConnFlags, HP2PCLT *phP2pClt) |
连接设备但不执行口令认证. | |
ICAMP2P_C_EXPORTS int | iCamP2pConnectByToken (const char *token, int fConnFlags, HP2PCLT *hP2pClt) |
ICAMP2P_C_EXPORTS int | iCamP2pDisconnect (HP2PCLT hClt) |
断开连接 | |
ICAMP2P_C_EXPORTS void | iCamP2pBreakConnecting () |
中断当前正在进行中连接过程 | |
ICAMP2P_C_EXPORTS int | iCamP2pGetMediaTypeInfo (HP2PCLT hClt, MEDIAINFO *mi) |
ICAMP2P_C_EXPORTS int | iCamP2pVerifyPassword (HP2PCLT hClt, const char *password) |
ICAMP2P_C_EXPORTS int | iCamP2pChangePassword (HP2PCLT hClt, const char *oldpasswd, const char *newpasswd) |
修改直接模式密码 | |
ICAMP2P_C_EXPORTS int | iCamP2pStartLiveVideo (HP2PCLT hClt, int channel, FRAMECALLBACK cb, void *pUser) |
开启实时图像. | |
ICAMP2P_C_EXPORTS int | iCamP2pStopLiveVideo (HP2PCLT hClt, int channel) |
停止视频传输 | |
ICAMP2P_C_EXPORTS int | iCamP2pSelectStream (HP2PCLT hClt, int channel, int stream) |
选择码流. | |
ICAMP2P_C_EXPORTS int | iCamP2pPause (HP2PCLT hClt) |
ICAMP2P_C_EXPORTS int | iCamP2pContinue (HP2PCLT hClt) |
ICAMP2P_C_EXPORTS int | iCamP2pStartLiveAudio (HP2PCLT hClt, FRAMECALLBACK cb, void *pUser) |
开启实时音频. | |
ICAMP2P_C_EXPORTS int | iCamP2pStopLiveAudio (HP2PCLT hClt) |
停止音频传输 | |
ICAMP2P_C_EXPORTS int | iCamP2pStartTalk (HP2PCLT hClt) |
开始对讲. | |
ICAMP2P_C_EXPORTS int | iCamP2pStopTalk (HP2PCLT hClt) |
停止对讲 | |
ICAMP2P_C_EXPORTS int | iCamP2pSendAudio (HP2PCLT hClt, const uint8_t *pAudio, int size) |
ICAMP2P_C_EXPORTS int | iCamP2pSendMedia (HP2PCLT hClt, TCMEDIA mt, uint32_t ts, uint32_t uFrameFlags, const uint8_t *pMedia, int size) |
发关对讲音视频 | |
ICAMP2P_C_EXPORTS void | iCamP2pPlaybackStart (HP2PCLT hClt, FRAMECALLBACK cb_v, void *pUser_v, FRAMECALLBACK cb_a, void *pUser_a) |
开始sd卡回放. | |
ICAMP2P_C_EXPORTS int | iCamP2pPlaybackLocate (HP2PCLT hClt, time_t t) |
sd卡回放定位. | |
ICAMP2P_C_EXPORTS void | iCamP2pPlaybackStop (HP2PCLT hClt) |
停止回放 | |
ICAMP2P_C_EXPORTS int | iCamP2pPlaybackPause (HP2PCLT hClt, int bPause) |
回放暂停 | |
ICAMP2P_C_EXPORTS int | iCamP2pPlaybackSetRate (HP2PCLT hClt, int rate) |
设置回放倍速. | |
ICAMP2P_C_EXPORTS int | iCamP2pGetRecordList2 (HP2PCLT hClt, time_t t_start, int tlen, SAvEvent2 **ppEvents, unsigned int *pNEvents) |
查询sd卡录像列表. | |
ICAMP2P_C_EXPORTS int | iCamP2pGetFeatures (HP2PCLT hClt, CAMFEATURES *pFeatures) |
获取设备能力集. | |
ICAMP2P_C_EXPORTS int | iCamP2pBatchExecute (HP2PCLT hClt, ICAMAUTOCMD *cmds, int nCmds, int timeout) |
执行多条命令 | |
ICAMP2P_C_EXPORTS int | _iCamP2pExecute (HP2PCLT hClt, int cmd, const void *pReq, int lenReqData, RESPPROCESSOR *rp, int timeout, struct RespWaitBundle **ppPoll) |
ICAMP2P_C_EXPORTS SA_BOOL | RwbPoll (struct RespWaitBundle *rwb, int timeout, int *status) |
ICAMP2P_C_EXPORTS void | RwbFree (struct RespWaitBundle *rwb, HP2PCLT hClt) |
ICAMP2P_C_EXPORTS int | iCamP2pExecute (HP2PCLT hClt, int cmd, const void *pReq, int lenReq, void *pResp, int sizeResp, int timeout) |
ICAMP2P_C_EXPORTS int | iCamP2pSetBatchMode (HP2PCLT hClt) |
ICAMP2P_C_EXPORTS int | iCamP2pBatchModeFlush (HP2PCLT hClt, int timeout) |
ICAMP2P_C_EXPORTS int | iCamP2pGetCloudVideoQuality (HP2PCLT hClt) |
获取云录像清晰度设置 | |
ICAMP2P_C_EXPORTS int | iCamP2pSetCloudVideoQuality (HP2PCLT hClt, int quality) |
设置云录像清晰度 | |
ICAMP2P_C_EXPORTS int | iCamP2pEnterSetup (HP2PCLT hClt) |
通知低功耗设备app进入设置界面,不要休眠 | |
ICAMP2P_C_EXPORTS int | iCamP2pLeaveSetup (HP2PCLT hClt) |
通知低功耗设备app离开设置界面,可以休眠 | |
ICAMP2P_C_EXPORTS int | iCamP2pAnswerToCall (HP2PCLT hClt, int state) |
ICAMP2P_C_EXPORTS int | iCamP2pSetMaxAwakeTime (HP2PCLT hClt, int maxAwakeTime) |
设置低功耗摄像头的最大工作时长 | |
ICAMP2P_C_EXPORTS int | iCamP2pGetMaxAwakeTime (HP2PCLT hClt) |
获取低功耗摄像同的最大工作时长 | |
ICAMP2P_C_EXPORTS int | iCamP2pRebootDev (HP2PCLT hClt) |
设备重启 | |
ICAMP2P_C_EXPORTS int | iCamP2pSetDeviceStatus (HP2PCLT hClt, int status) |
设置设备开关状态. | |
ICAMP2P_C_EXPORTS int | iCamP2pGetDeviceStatus (HP2PCLT hClt) |
获取当前设备状态. | |
struct FRAMEHEAD_t |
Audio/Video Frame Header Info
在文件 icam_p2p.h 第 46 行定义.
成员变量 | ||
---|---|---|
unsigned short | codec_id |
非0时, 低8位为 TCMEDIA, 高8位为视频通道号. 为0时,本结构为 RTMSGHEAD_t |
unsigned char | flags |
For video frame, is of ENUM_FRAMEFLAG. for Audio Frame: flags = (samplerate << 2) | (databits << 1) | (channel) 音频采样格式 |
unsigned char | cam_index | 0 (>0 may be used in future) |
unsigned char | rt_flags | 当帧类型为视频时,bit0 为是否在录像的标志 |
unsigned char | seq_no[3] | 1~0xffffff. sequency number for frame, used internally by sdk to detect frame loss. |
unsigned int | frame_size | Size of frame |
unsigned int | timestamp | Timestamp of the frame, in milliseconds |
struct RespHdr |
命令请求/响应包头
在文件 icam_p2p.h 第 112 行定义.
成员变量 | ||
---|---|---|
uint32_t | cmd | |
uint32_t | len |
struct RespBuff |
在文件 icam_p2p.h 第 118 行定义.
成员变量 | ||
---|---|---|
RespHdr | hdr | |
union RespBuff.__unnamed13__ | __unnamed__ |
struct CmdPkt |
在文件 icam_p2p.h 第 126 行定义.
成员变量 | ||
---|---|---|
int | size | resp 所指向的缓冲区大小 |
struct RespBuff * | resp |
struct FrameBuff |
在文件 icam_p2p.h 第 141 行定义.
成员变量 | ||
---|---|---|
FRAMEHEAD_t | fi | |
uint8_t | data[1] |
struct FramePkt |
在文件 icam_p2p.h 第 145 行定义.
成员变量 | ||
---|---|---|
int | size | memory size pointed by {frame} |
struct FrameBuff * | frame |
struct MEDIAINFO |
在文件 icam_p2p.h 第 214 行定义.
成员变量 | ||
---|---|---|
int | type | |
union MEDIAINFO.u | u |
struct RESPPROCESSOR |
在文件 icam_p2p.h 第 324 行定义.
struct ICAMAUTOCMD |
批处理的单条指令描述
在文件 icam_p2p.h 第 335 行定义.
成员变量 | ||
---|---|---|
int | cmd | 命令 |
unsigned char * | req | 命令请求数据 |
int | req_len | 请求数据长度 |
RESPPROCESSOR | rspProc | responsed data processor |
union RespBuff.__unnamed13__ |
在文件 icam_p2p.h 第 120 行定义.
成员变量 | ||
---|---|---|
int | cmd_status[2] | |
char | buff[2048] |
union MEDIAINFO.u |
在文件 icam_p2p.h 第 216 行定义.
成员变量 | ||
---|---|---|
struct MEDIAINFO.u.mt | mt |
struct MEDIAINFO.u.mt |
在文件 icam_p2p.h 第 217 行定义.
成员变量 | ||
---|---|---|
int | n_achn | |
int | n_vchn | |
int | n_streams_per_vchn | |
unsigned char | types[32] |
#define ICAMP2P_C_EXPORTS |
在文件 icam_p2p.h 第 25 行定义.
#define P2PCONN_TYPE_LAN 1 |
在文件 icam_p2p.h 第 38 行定义.
#define P2PCONN_TYPE_P2P 2 |
在文件 icam_p2p.h 第 39 行定义.
#define P2PCONN_TYPE_RELAY 3 |
在文件 icam_p2p.h 第 40 行定义.
#define MAKE_CONNFLAGS | ( | bLanSearch, | |
iP2pTryTime, | |||
bRelay ) |
在文件 icam_p2p.h 第 80 行定义.
typedef struct P2PRAW* HP2PRAW |
在文件 icam_p2p.h 第 32 行定义.
typedef struct P2PCLT* HP2PCLT |
p2p连接句柄
在文件 icam_p2p.h 第 35 行定义.
typedef void(* FRAMECALLBACK) (FRAMEHEAD_t *fi, unsigned char *data, void *pUser) |
音视频视回调.
fi | 帧信息. 为NULL时, (int)data为错误码(定义在 icam_const.h) |
data | 帧数据, 长度在 fi->frame_size |
pUser | 用户数据指针 |
在文件 icam_p2p.h 第 72 行定义.
在文件 icam_p2p.h 第 174 行定义.
typedef void(* ICAMCMDDATACALLBACK) (const void *data, int len, HP2PCLT hClt, void *pUser) |
在文件 icam_p2p.h 第 175 行定义.
typedef int(* RESPCALLBACK) (const void *body, int len, void *pUser) |
在文件 icam_p2p.h 第 321 行定义.
ICAMP2P_C_EXPORTS int iCamP2pInit | ( | ) |
初始化p2p库.
Windows下需要自己调用 WSAStartup()
ICAMP2P_C_EXPORTS int iCamRawRecvN | ( | HP2PRAW | handle, |
int | avIndex, | ||
void * | buff, | ||
int | size, | ||
int | timeout ) |
带超时读取N字节.
size(>0) | 字节数(=size) |
ICAM_E_TIMEOUTED | 超时。读取的字节数为0 |
<0 | 错误码, 连接已断开 |
ICAMP2P_C_EXPORTS int iCamRawRecvN2 | ( | HP2PRAW | handle, |
int | avIndex, | ||
void * | buff, | ||
int | size, | ||
const SA_BOOL * | b_run ) |
无超时读取N字节.
ICAMP2P_C_EXPORTS int iCamRawReadCmdPkt | ( | HP2PRAW | hRaw, |
struct CmdPkt * | pkt, | ||
int | timeout, | ||
SA_BOOL * | pbRun ) |
在命令通道上读一个完整包.
pkt | 如果空间不足,库内部会重新分配 |
timeout | 读取到头前的超时时间(ms). |
pbRun | 指向一个变量,当值变为0时会中断读操作。 |
ICAMP2P_C_EXPORTS int iCamRawRecvFramePkt | ( | HP2PRAW | hRaw, |
int | avIndex, | ||
struct FramePkt * | pkt, | ||
int | timeout, | ||
SA_BOOL * | pbRun ) |
在通道上读一个完整帧.
hClt | |
avIndex | p2p通道 |
pkt | 如果空间不足,库内部会重新分配 |
timeout | 读取到头前的超时时间(ms). |
pbRun | 指向一个变量,当值变为0时会中断读操作。 |
ICAMP2P_C_EXPORTS int iCamP2pConnect | ( | const char * | server_cfg, |
const char * | did, | ||
const char * | key, | ||
int | fConnFlags, | ||
HP2PCLT * | phP2pClt ) |
连接设备.
server | 服务器配置字符串 |
did | p2p id |
key | 口令 |
fConnFlags | 连接标志, 0 for default |
phP2pClt | 用于返回连接句柄 |
ICAMP2P_C_EXPORTS int iCamP2pSetCallback | ( | HP2PCLT | hClt, |
ICAMEVENTCALLBACK | event_cb, | ||
ICAMCMDDATACALLBACK | data_cb, | ||
void * | pUser ) |
设备连接的消息/数据回调.
在连接建立后就设置.
event_cb | 事件消息回调. Can be NULL |
data_cb | 未处理的命令应答数据回调, Can be NULL。基本上只用于代理透传 |
pUser | 回调的用户参数 |
ICAMP2P_C_EXPORTS int iCamP2pConnect2 | ( | const char * | server_cfg, |
const char * | did, | ||
int | fConnFlags, | ||
HP2PCLT * | phP2pClt ) |
连接设备但不执行口令认证.
要调用 iCamP2pVerifyPassword()
server | 服务器配置字符串 |
did | p2p id |
fConnFlags | 连接标志, 0 for default |
phP2pClt | 用于返回连接句柄 |
ICAMP2P_C_EXPORTS int iCamP2pStartLiveVideo | ( | HP2PCLT | hClt, |
int | channel, | ||
FRAMECALLBACK | cb, | ||
void * | pUser ) |
开启实时图像.
hClt | p2p连接句柄 |
channel | 图像通道 |
cb | 视频帧回调函数 |
pUser | 传给回调函数的用户数据指针 |
ICAMP2P_C_EXPORTS int iCamP2pSelectStream | ( | HP2PCLT | hClt, |
int | channel, | ||
int | stream ) |
选择码流.
要在 iCamP2pStartLiveVideo 后调用.
hClt | |
channel | |
stream |
ICAMP2P_C_EXPORTS int iCamP2pStartLiveAudio | ( | HP2PCLT | hClt, |
FRAMECALLBACK | cb, | ||
void * | pUser ) |
开启实时音频.
hClt | p2p连接句柄 |
cb | 音频帧回调函数 |
pUser | 传给回调函数的用户数据指针 |
ICAMP2P_C_EXPORTS int iCamP2pStartTalk | ( | HP2PCLT | hClt | ) |
开始对讲.
成功返回后可以调用 iCamP2pSendAudio 发送音频帧
ICAMP2P_C_EXPORTS int iCamP2pSendAudio | ( | HP2PCLT | hClt, |
const uint8_t * | pAudio, | ||
int | size ) |
hClt | p2p连接句柄 |
pAudio | 音频数据缓冲区。目前只支持 8000/16位/mono g711-a 格式的音频包 |
size | 包大小 |
ICAMP2P_C_EXPORTS void iCamP2pPlaybackStart | ( | HP2PCLT | hClt, |
FRAMECALLBACK | cb_v, | ||
void * | pUser_v, | ||
FRAMECALLBACK | cb_a, | ||
void * | pUser_a ) |
开始sd卡回放.
hClt | p2p连接句柄 |
cb_v | 视频数据回调 |
pUser_v | 视频回调用户数据 |
cb_a | 音频数据回调 |
pUser_a | 音频数据回调 |
ICAMP2P_C_EXPORTS int iCamP2pPlaybackLocate | ( | HP2PCLT | hClt, |
time_t | t ) |
sd卡回放定位.
t | 回放定位, utc时间 |
ICAMP2P_C_EXPORTS int iCamP2pPlaybackSetRate | ( | HP2PCLT | hClt, |
int | rate ) |
设置回放倍速.
rate | 0-1倍; 1-2倍; 2-4倍数 |
ICAMP2P_C_EXPORTS int iCamP2pGetRecordList2 | ( | HP2PCLT | hClt, |
time_t | t_start, | ||
int | tlen, | ||
SAvEvent2 ** | ppEvents, | ||
unsigned int * | pNEvents ) |
查询sd卡录像列表.
t_start | 起始时间(utc) |
tlen | 时间跨度(秒) |
ppEvents | 用于返回录像列表指针 |
pNEvents | 返回的录像列表大小 |
ICAMP2P_C_EXPORTS int iCamP2pGetMaxAwakeTime | ( | HP2PCLT | hClt | ) |
获取低功耗摄像同的最大工作时长
ICAMP2P_C_EXPORTS int iCamP2pSetDeviceStatus | ( | HP2PCLT | hClt, |
int | status ) |
设置设备开关状态.
status | 1-打开; 0-关闭 |
ICAMP2P_C_EXPORTS int iCamP2pGetDeviceStatus | ( | HP2PCLT | hClt | ) |
获取当前设备状态.