Tange Cloud for Device
 Rev.333
载入中...
搜索中...
未找到
icam_p2p.h 文件参考
#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)
 获取当前设备状态.
 

结构体说明

◆ FRAMEHEAD_t

struct FRAMEHEAD_t

Audio/Video Frame Header Info

在文件 icam_p2p.h46 行定义.

成员变量
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

◆ RespHdr

struct RespHdr

命令请求/响应包头

在文件 icam_p2p.h112 行定义.

成员变量
uint32_t cmd
uint32_t len

◆ RespBuff

struct RespBuff

在文件 icam_p2p.h118 行定义.

成员变量
RespHdr hdr
union RespBuff.__unnamed13__ __unnamed__

◆ CmdPkt

struct CmdPkt

在文件 icam_p2p.h126 行定义.

成员变量
int size resp 所指向的缓冲区大小
struct RespBuff * resp

◆ FrameBuff

struct FrameBuff

在文件 icam_p2p.h141 行定义.

成员变量
FRAMEHEAD_t fi
uint8_t data[1]

◆ FramePkt

struct FramePkt

在文件 icam_p2p.h145 行定义.

成员变量
int size memory size pointed by {frame}
struct FrameBuff * frame

◆ MEDIAINFO

struct MEDIAINFO

在文件 icam_p2p.h214 行定义.

成员变量
int type
union MEDIAINFO.u u

◆ RESPPROCESSOR

struct RESPPROCESSOR

在文件 icam_p2p.h324 行定义.

成员变量
int status 响应状态
unsigned char * resp cb_resp == NULL 时为原始响应数据缓冲区。否则忽略
int resp_buf_size in: size of the buffer pointed by {resp}
int resp_size out: bytes filled in {resp}
RESPCALLBACK cb_resp if {cb_resp} is not NULL, {resp} and {resp_size} are passed as the 1st and 2nd parameters
void * pUser Private data for cb_resp

◆ ICAMAUTOCMD

struct ICAMAUTOCMD

批处理的单条指令描述

在文件 icam_p2p.h335 行定义.

成员变量
int cmd 命令
unsigned char * req 命令请求数据
int req_len 请求数据长度
RESPPROCESSOR rspProc responsed data processor

◆ RespBuff.__unnamed13__

union RespBuff.__unnamed13__

在文件 icam_p2p.h120 行定义.

成员变量
int cmd_status[2]
char buff[2048]

◆ MEDIAINFO.u

union MEDIAINFO.u

在文件 icam_p2p.h216 行定义.

成员变量
struct MEDIAINFO.u.mt mt

◆ MEDIAINFO.u.mt

struct MEDIAINFO.u.mt

在文件 icam_p2p.h217 行定义.

成员变量
int n_achn
int n_vchn
int n_streams_per_vchn
unsigned char types[32]

宏定义说明

◆ ICAMP2P_C_EXPORTS

#define ICAMP2P_C_EXPORTS

在文件 icam_p2p.h25 行定义.

◆ P2PCONN_TYPE_LAN

#define P2PCONN_TYPE_LAN   1

在文件 icam_p2p.h38 行定义.

◆ P2PCONN_TYPE_P2P

#define P2PCONN_TYPE_P2P   2

在文件 icam_p2p.h39 行定义.

◆ P2PCONN_TYPE_RELAY

#define P2PCONN_TYPE_RELAY   3

在文件 icam_p2p.h40 行定义.

◆ MAKE_CONNFLAGS

#define MAKE_CONNFLAGS ( bLanSearch,
iP2pTryTime,
bRelay )
值:
((bLanSearch?1:0) | (bRelay?0:0x20) | ( ((iP2pTryTime==0?15:iP2pTryTime) & 0x1f) << 1 ) )

在文件 icam_p2p.h80 行定义.

类型定义说明

◆ HP2PRAW

typedef struct P2PRAW* HP2PRAW

在文件 icam_p2p.h32 行定义.

◆ HP2PCLT

typedef struct P2PCLT* HP2PCLT

p2p连接句柄

在文件 icam_p2p.h35 行定义.

◆ FRAMECALLBACK

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.h72 行定义.

◆ ICAMEVENTCALLBACK

typedef void(* ICAMEVENTCALLBACK) (const RTMSG_t *msg, int len, HP2PCLT hClt, void *pUser)

在文件 icam_p2p.h174 行定义.

◆ ICAMCMDDATACALLBACK

typedef void(* ICAMCMDDATACALLBACK) (const void *data, int len, HP2PCLT hClt, void *pUser)

在文件 icam_p2p.h175 行定义.

◆ RESPCALLBACK

typedef int(* RESPCALLBACK) (const void *body, int len, void *pUser)

在文件 icam_p2p.h321 行定义.

函数说明

◆ iCamP2pInit()

ICAMP2P_C_EXPORTS int iCamP2pInit ( )

初始化p2p库.

Windows下需要自己调用 WSAStartup()

◆ iCamRawRecvN()

ICAMP2P_C_EXPORTS int iCamRawRecvN ( HP2PRAW handle,
int avIndex,
void * buff,
int size,
int timeout )

带超时读取N字节.

返回值
size(>0)字节数(=size)
ICAM_E_TIMEOUTED超时。读取的字节数为0
<0错误码, 连接已断开
注解
该操作如果在超时到达时读取了部分字节,会忽略超时断续读,直到读到 size 个字节或者连接断开

◆ iCamRawRecvN2()

ICAMP2P_C_EXPORTS int iCamRawRecvN2 ( HP2PRAW handle,
int avIndex,
void * buff,
int size,
const SA_BOOL * b_run )

无超时读取N字节.

注解
本操作会一直循环读直到如下条件之一发生:
  1. 读到了指定字节, 返回 1
  2. 连接断开,返回错误码(<0)
  3. *b_run 在外部被修改为0,返回0

◆ iCamRawReadCmdPkt()

ICAMP2P_C_EXPORTS int iCamRawReadCmdPkt ( HP2PRAW hRaw,
struct CmdPkt * pkt,
int timeout,
SA_BOOL * pbRun )

在命令通道上读一个完整包.

参数
pkt如果空间不足,库内部会重新分配
timeout读取到头前的超时时间(ms).
pbRun指向一个变量,当值变为0时会中断读操作。
返回
length of packet, or error code(<0)
注解
读到头后会一直循环直到读取到完整包, 或者 *pbRun==0。 中断后不应该再调用读取操作,因为丢失了包边界。

◆ iCamRawRecvFramePkt()

ICAMP2P_C_EXPORTS int iCamRawRecvFramePkt ( HP2PRAW hRaw,
int avIndex,
struct FramePkt * pkt,
int timeout,
SA_BOOL * pbRun )

在通道上读一个完整帧.

参数
hClt
avIndexp2p通道
pkt如果空间不足,库内部会重新分配
timeout读取到头前的超时时间(ms).
pbRun指向一个变量,当值变为0时会中断读操作。
返回
length of packet, or error code(<0)
注解
读到头后会一直循环直到读取到完整包, 或者 *pbRun==0。 中断后不应该再调用读取操作,因为丢失了包边界。

◆ iCamP2pConnect()

ICAMP2P_C_EXPORTS int iCamP2pConnect ( const char * server_cfg,
const char * did,
const char * key,
int fConnFlags,
HP2PCLT * phP2pClt )

连接设备.

参数
server服务器配置字符串
didp2p id
key口令
fConnFlags连接标志, 0 for default
phP2pClt用于返回连接句柄
返回
0:success; <0:error code

◆ iCamP2pSetCallback()

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回调的用户参数

◆ iCamP2pConnect2()

ICAMP2P_C_EXPORTS int iCamP2pConnect2 ( const char * server_cfg,
const char * did,
int fConnFlags,
HP2PCLT * phP2pClt )

连接设备但不执行口令认证.

要调用 iCamP2pVerifyPassword()

参数
server服务器配置字符串
didp2p id
fConnFlags连接标志, 0 for default
phP2pClt用于返回连接句柄
返回
0:success; <0:error code

◆ iCamP2pStartLiveVideo()

ICAMP2P_C_EXPORTS int iCamP2pStartLiveVideo ( HP2PCLT hClt,
int channel,
FRAMECALLBACK cb,
void * pUser )

开启实时图像.

参数
hCltp2p连接句柄
channel图像通道
cb视频帧回调函数
pUser传给回调函数的用户数据指针

◆ iCamP2pSelectStream()

ICAMP2P_C_EXPORTS int iCamP2pSelectStream ( HP2PCLT hClt,
int channel,
int stream )

选择码流.

要在 iCamP2pStartLiveVideo 后调用.

参数
hClt
channel
stream

◆ iCamP2pStartLiveAudio()

ICAMP2P_C_EXPORTS int iCamP2pStartLiveAudio ( HP2PCLT hClt,
FRAMECALLBACK cb,
void * pUser )

开启实时音频.

参数
hCltp2p连接句柄
cb音频帧回调函数
pUser传给回调函数的用户数据指针

◆ iCamP2pStartTalk()

ICAMP2P_C_EXPORTS int iCamP2pStartTalk ( HP2PCLT hClt)

开始对讲.

成功返回后可以调用 iCamP2pSendAudio 发送音频帧

◆ iCamP2pSendAudio()

ICAMP2P_C_EXPORTS int iCamP2pSendAudio ( HP2PCLT hClt,
const uint8_t * pAudio,
int size )
弃用
发送音频包.
参数
hCltp2p连接句柄
pAudio音频数据缓冲区。目前只支持 8000/16位/mono g711-a 格式的音频包
size包大小

◆ iCamP2pPlaybackStart()

ICAMP2P_C_EXPORTS void iCamP2pPlaybackStart ( HP2PCLT hClt,
FRAMECALLBACK cb_v,
void * pUser_v,
FRAMECALLBACK cb_a,
void * pUser_a )

开始sd卡回放.

参数
hCltp2p连接句柄
cb_v视频数据回调
pUser_v视频回调用户数据
cb_a音频数据回调
pUser_a音频数据回调

◆ iCamP2pPlaybackLocate()

ICAMP2P_C_EXPORTS int iCamP2pPlaybackLocate ( HP2PCLT hClt,
time_t t )

sd卡回放定位.

参数
t回放定位, utc时间

◆ iCamP2pPlaybackSetRate()

ICAMP2P_C_EXPORTS int iCamP2pPlaybackSetRate ( HP2PCLT hClt,
int rate )

设置回放倍速.

参数
rate0-1倍; 1-2倍; 2-4倍数

◆ iCamP2pGetRecordList2()

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返回的录像列表大小
返回
: 0-ok; <0: 错误码
注解
成功返回并且*pNEvents 非0时,调用者要释放列表空间(free(*ppEvents))

◆ iCamP2pGetMaxAwakeTime()

ICAMP2P_C_EXPORTS int iCamP2pGetMaxAwakeTime ( HP2PCLT hClt)

获取低功耗摄像同的最大工作时长

返回
:> 0工作时长,0 不休眠 <0 err

◆ iCamP2pSetDeviceStatus()

ICAMP2P_C_EXPORTS int iCamP2pSetDeviceStatus ( HP2PCLT hClt,
int status )

设置设备开关状态.

参数
status1-打开; 0-关闭

◆ iCamP2pGetDeviceStatus()

ICAMP2P_C_EXPORTS int iCamP2pGetDeviceStatus ( HP2PCLT hClt)

获取当前设备状态.

返回
1:打开; 0:关闭; <0 err