💡 需要该IPC库源码的大佬们,可扫码关注文章末尾的微信公众号二维码,或搜索微信公众号“希望睿智”。添加关注后,输入消息“IPC库”,即可免费获得源码的下载链接。
概述
君正的IPC芯片主要有T31、T40、T41等型号,每个型号的API接口大部分是相同的,但也存在一些不一致和差异化的地方。为了屏蔽不同芯片型号之间的差异,我们需要基于一个公共基类进行封装。在封装之前,我们需要定义自己的错误码和数据结构,用于屏蔽不同君正芯片的实现细节。
错误码定义
为了确保整个IPC库使用统一的错误码,我们在HP_MPPErrorCode.h文件中专门定义了以下错误码。错误码囊括了参数错误、内存错误、溢出错误、不支持、密码错误、非法数据等各种异常情况。
#pragma once
#define E_MPP_OK 0x0000 // 成功
#define E_MPP_Unknown 0xFF00 // 未知错误
#define E_MPP_Param 0xFF01 // 参数错误或不合法
#define E_MPP_Memory 0xFF02 // 内存相关错误
#define E_MPP_Timeout 0xFF03 // 超时
#define E_MPP_NotSupport 0xFF04 // 不支持
#define E_MPP_Format 0xFF05 // 格式错误或不合法
#define E_MPP_ExecFailed 0xFF06 // 执行失败
#define E_MPP_WrongState 0xFF07 // 错误的状态
#define E_MPP_File 0xFF08 // 文件相关错误
#define E_MPP_Priority 0xFF09 // 优先级不够
#define E_MPP_Auth 0xFF0A // 权限不够
#define E_MPP_Overflow 0xFF0B // 溢出错误
#define E_MPP_Occupied 0xFF0C // 已被占用
#define E_MPP_Exhausted 0xFF0D // 已耗尽
#define E_MPP_NotMatch 0xFF0E // 不匹配
#define E_MPP_NoMore 0xFF0F // 没有更多
#define E_MPP_Ended 0xFF10 // 已结束
#define E_MPP_Continue 0xFF11 // 需要继续
#define E_MPP_WouldBlock 0xFF12 // 操作正在进行中
#define E_MPP_Route 0xFF13 // 路由失败
#define E_MPP_Existed 0xFF14 // 已存在
#define E_MPP_NotExist 0xFF15 // 不存在
#define E_MPP_InvalidOperation 0xFF16 // 非法的操作
#define E_MPP_FakeInfo 0xFF17 // 伪造的信息
#define E_MPP_DataCorrupt 0xFF18 // 数据损坏
#define E_MPP_Password 0xFF19 // 密码错误
#define E_MPP_Socket 0xFF1A // 套接字相关错误
#define E_MPP_DNS 0xFF1B // DNS相关错误
#define E_MPP_Disable 0xFF1C // 被禁用
#define E_MPP_InvalidData 0xFF1D // 非法的数据
#define E_MPP_Expired 0xFF1E // 已过期
数据结构定义
君正不同型号的芯片之间,有些数据结构的定义是有差异的。比如:T31芯片中,IMPSensorInfo结构体的定义如下。
typedef struct {
char name[32]; /**< 摄像头名字 */
IMPSensorControlBusType cbus_type; /**< 摄像头控制总线类型 */
union {
IMPI2CInfo i2c; /**< I2C总线信息 */
IMPSPIInfo spi; /**< SPI总线信息 */
};
unsigned short rst_gpio; /**< 摄像头reset接口链接的GPIO,注意:现在没有启用该参数 */
unsigned short pwdn_gpio; /**< 摄像头power down接口链接的GPIO,注意:现在没有启用该参数 */
unsigned short power_gpio; /**< 摄像头power 接口链接的GPIO,注意:现在没有启用该参数 */
} IMPSensorInfo;
T40芯片中,IMPSensorInfo结构体的定义如下。可以看到,T40中多了sensor_id、video_interface、mclk、default_boot等参数。
typedef struct {
char name[32]; /**< 摄像头名字 */
IMPSensorControlBusType cbus_type; /**< 摄像头控制总线类型 */
union {
IMPI2CInfo i2c; /**< I2C总线信息 */
IMPSPIInfo spi; /**< SPI总线信息 */
};
int rst_gpio; /**< 摄像头reset接口链接的GPIO */
int pwdn_gpio; /**< 摄像头power down接口链接的GPIO */
int power_gpio; /**< 摄像头power 接口链接的GPIO,注意:现在没有启用该参数 */
unsigned short sensor_id; /**< 摄像头ID号 */
IMPSensorVinType video_interface; /**< 摄像头数据输入接口 */
IMPSensorMclk mclk; /**< 摄像头Mclk时钟源 */
int default_boot; /**< 摄像头默认启动setting */
} IMPSensorInfo;
为了确保接口层使用统一的数据结构,必须对接口层屏蔽掉君正底层API数据结构的差异。因此,我们在HP_MPPTypes.h文件中定义了跨平台通用的数据结构,在MPP_API_Types.h文件中定义了君正芯片方案通用的数据结构。
HP_MPPTypes.h文件中定义的数据结构如下。
#pragma once
#include <string>
#include <vector>
#include <list>
#include <map>
#include <string.h>
#include <HP_Base/HP_Logger.h>
#include "HP_MPPErrorCode.h"
typedef std::map<std::string, std::string> MppConfigAttrMap;
enum IMppLedState
{
MppLedState_Off,
MppLedState_On,
MppLedState_Twinkle
};
enum IMppWhiteLightMode
{
MppWhiteLightMode_On,
MppWhiteLightMode_Twinkle
};
enum IMppNightVisionMode
{
MppNightVisionMode_BlackWhiteOff,
MppNightVisionMode_BlackWhiteOn,
MppNightVisionMode_BlackWhiteAuto,
MppNightVisionMode_FullColor,
MppNightVisionMode_Smart,
MppNightVisionMode_Count
};
enum IMppIspFlipMode
{
MppIspFlipMode_None,
MppIspFlipMode_Hor,
MppIspFlipMode_Ver,
MppIspFlipMode_HorVer,
MppIspFlipMode_Count
};
enum IMppAntiflickerMode
{
MppAntiflickerMode_Disable,
MppAntiflickerMode_50Hz,
MppAntiflickerMode_60Hz,
MppAntiflickerMode_Count
};
enum IMppCameraControlBusType
{
MppCameraControlBusType_I2C,
MppCameraControlBusType_SPI,
MppCameraControlBusType_Count
};
enum IMppCameraVinType
{
MppCameraVinType_MIPI_CSI0,
MppCameraVinType_MIPI_CSI1,
MppCameraVinType_DVP,
MppCameraVinType_Count
};
enum IMppCameraClock
{
IMppCameraClock_MCLK0,
IMppCameraClock_MCLK1,
IMppCameraClock_MCLK2,
IMppCameraClock_Count
};
enum IMppVideoBitrateCtrlMode
{
MppVideoBitrateCtrlMode_CBR,
MppVideoBitrateCtrlMode_VBR,
MppVideoBitrateCtrlMode_ABR,
MppVideoBitrateCtrlMode_Count
};
enum IMppVideoStreamType
{
MppVideoStreamType_Main,
MppVideoStreamType_Sub,
MppVideoStreamType_Third,
MppVideoStreamType_Count
};
enum IMppVideoCodecAlg
{
MppVideoCodecAlg_H264BaseLine,
MppVideoCodecAlg_H264Main,
MppVideoCodecAlg_H264High,
MppVideoCodecAlg_H265Main,
MppVideoCodecAlg_Count
};
typedef struct _TMppCameraI2cInfo
{
_TMppCameraI2cInfo()
{
nAddr = 0;
nAdapterID = 0;
}
int nAddr;
int nAdapterID;
}TMppCameraI2cInfo;
typedef struct _TMppCameraSpiInfo
{
_TMppCameraSpiInfo()
{
nBusNum = 0;
}
int nBusNum;
}TMppCameraSpiInfo;
typedef struct _TMppCameraInfo
{
_TMppCameraInfo()
{
busType = MppCameraControlBusType_I2C;
nResetGpio = -1;
nPowerGpio = -1;
nPowerDownGpio = -1;
usSensorID = 0;
vinType = MppCameraVinType_MIPI_CSI0;
clk = IMppCameraClock_MCLK0;
nDefaultBoot = 0;
uiMaxFrameRate = 0;
}
std::string strName;
IMppCameraControlBusType busType;
union
{
TMppCameraI2cInfo i2c;
TMppCameraSpiInfo spi;
};
int nResetGpio;
int nPowerGpio;
int nPowerDownGpio;
unsigned short usSensorID;
IMppCameraVinType vinType;
IMppCameraClock clk;
int nDefaultBoot;
unsigned int uiMaxFrameRate;
}TMppCameraInfo;
typedef struct _TMppSystemParam
{
_TMppSystemParam()
{
uiOsdPoolSize = 0;
pLogger = NULL;
}
std::vector<TMppCameraInfo> vctCameraInfo;
unsigned int uiOsdPoolSize;
CHP_Logger *pLogger;
}TMppSystemParam;
typedef struct _TMppVideoFrameInfo
{
_TMppVideoFrameInfo()
{
codecAlg = MppVideoCodecAlg_H264BaseLine;
bKeyFrame = false;
uiWidth = 0;
uiHeight = 0;
ui64TimestampUs = 0;
}
IMppVideoCodecAlg codecAlg;
bool bKeyFrame;
unsigned int uiWidth;
unsigned int uiHeight;
unsigned long long ui64TimestampUs;
}TMppVideoFrameInfo;
enum IMppImagePixelFormat
{
MppImagePixelFormat_MonoWhite,
MppImagePixelFormat_NV12,
MppImagePixelFormat_NV21,
MppImagePixelFormat_RGB24,
MppImagePixelFormat_BGR24,
MppImagePixelFormat_ARGB,
MppImagePixelFormat_RGBA,
MppImagePixelFormat_ABGR,
MppImagePixelFormat_BGRA
};
typedef struct _TMppVideoRawDataInfo
{
_TMppVideoRawDataInfo()
{
format = MppImagePixelFormat_NV12;
uiWidth = 0;
uiHeight = 0;
}
IMppImagePixelFormat format;
unsigned int uiWidth;
unsigned int uiHeight;
}TMppVideoRawDataInfo;
typedef void(*CALLBACK_COMPOSE_CUSTOM_TIME_TEXT)(time_t tmCurTime, std::string &strTimeText, void *pContext);
typedef void(*CALLBACK_VIDEO_FRAME_GOT)(unsigned int uiCameraChannel, IMppVideoStreamType streamType,
unsigned char *pFrame, unsigned int uiFrameLen, const TMppVideoFrameInfo &frameInfo, void *pContext);
typedef void(*CALLBACK_VIDEO_RAW_DATA_GOT)(unsigned int uiCameraChannel, unsigned char *pData,
unsigned int uiDataLen, const TMppVideoRawDataInfo &dataInfo, void *pContext);
typedef struct _TMppVideoBasicParam
{
_TMppVideoBasicParam()
{
uiMaxFrameLen = 0;
bUseStrokeFont = true;
uiTextOverlayVerMargin = 2;
uiMaxTextOverlayCount = 6;
uiMaxRectangleOverlayCount = 4;
uiMaxPolygonOverlayCount = 0;
pCbComposeCustomTimeText = NULL;
pCbVideoFrameGot = NULL;
pCbVideoRawDataGot = NULL;
pCbContext = NULL;
pLogger = NULL;
}
unsigned int uiMaxFrameLen;
bool bUseStrokeFont;
std::string strAsciiFontFile;
std::string strChineseFontFile;
unsigned int uiTextOverlayVerMargin;
unsigned int uiMaxTextOverlayCount;
unsigned int uiMaxRectangleOverlayCount;
unsigned int uiMaxPolygonOverlayCount;
CALLBACK_COMPOSE_CUSTOM_TIME_TEXT pCbComposeCustomTimeText;
CALLBACK_VIDEO_FRAME_GOT pCbVideoFrameGot;
CALLBACK_VIDEO_RAW_DATA_GOT pCbVideoRawDataGot;
void *pCbContext;
CHP_Logger *pLogger;
}TMppVideoBasicParam;
typedef struct _TMppVideoStreamParam
{
_TMppVideoStreamParam()
{
streamType = MppVideoStreamType_Main;
codecAlg = MppVideoCodecAlg_H265Main;
uiWidth = 0;
uiHeight = 0;
ctrlMode = MppVideoBitrateCtrlMode_CBR;
uiFrameRate = 0;
uiMaxFrameRate = 0;
uiBitrateKbps = 0;
uiMaxBitrateKbps = 0;
uiKeyFrameInterval = 0;
bExpandNrVbs = false;
}
IMppVideoStreamType streamType;
IMppVideoCodecAlg codecAlg;
unsigned int uiWidth;
unsigned int uiHeight;
IMppVideoBitrateCtrlMode ctrlMode;
unsigned int uiFrameRate;
unsigned int uiMaxFrameRate;
unsigned int uiBitrateKbps;
unsigned int uiMaxBitrateKbps;
unsigned int uiKeyFrameInterval;
bool bExpandNrVbs;
}TMppVideoStreamParam;
typedef std::vector<TMppVideoStreamParam> TMppVideoStreamParamVector;
enum IMppLogoOverlayPicType
{
MppLogoOverlayPicType_BMP,
MppLogoOverlayPicType_PNG,
MppLogoOverlayPicType_Count
};
typedef struct _TMppLogoOverlayInfo
{
_TMppLogoOverlayInfo()
{
uiVideoWidth = 0;
uiVideoHeight = 0;
picType = MppLogoOverlayPicType_BMP;
}
unsigned int uiVideoWidth;
unsigned int uiVideoHeight;
std::string strPicPath;
IMppLogoOverlayPicType picType;
}TMppLogoOverlayInfo;
typedef std::vector<TMppLogoOverlayInfo> TMppLogoOverlayInfoVector;
typedef struct _TMppPictureStreamParam
{
_TMppPictureStreamParam()
{
usedStreamType = MppVideoStreamType_Main;
uiFrameRate = 0;
ucQualityPercent = 100;
}
IMppVideoStreamType usedStreamType;
unsigned int uiFrameRate;
unsigned char ucQualityPercent;
}TMppPictureStreamParam;
typedef struct _TMppVideoCameraParam
{
_TMppVideoCameraParam()
{
ivsUsedStreamType = MppVideoStreamType_Sub;
rawDataUsedStreamType = MppVideoStreamType_Sub;
}
TMppVideoStreamParamVector vctVideo;
TMppLogoOverlayInfoVector vctLogoOverlay;
TMppPictureStreamParam picture;
IMppVideoStreamType ivsUsedStreamType;
IMppVideoStreamType rawDataUsedStreamType;
}TMppVideoCameraParam;
typedef std::vector<TMppVideoCameraParam> TMppVideoCameraParamVector;
typedef struct _TMppVideoCaptureParam
{
TMppVideoBasicParam basic;
TMppVideoCameraParamVector vctCamera;
}TMppVideoCaptureParam;
enum IMppNoiseSuppressLevel
{
MppNSLevel_Low,
MppNSLevel_Moderate,
MppNSLevel_High,
MppNSLevel_VeryHigh,
MppNSLevel_Count
};
enum IMppAudioCodecAlg
{
MppAudioCodecAlg_G711A,
MppAudioCodecAlg_G711U,
MppAudioCodecAlg_ADPCM,
MppAudioCodecAlg_AAC,
MppAudioCodecAlg_Count
};
typedef struct _TMppAudioFrameInfo
{
_TMppAudioFrameInfo()
{
uiSampleRate = 0;
bStereo = false;
uiBitDepth = 0;
codecAlg = MppAudioCodecAlg_G711A;
ui64TimestampUs = 0;
}
unsigned int uiSampleRate;
bool bStereo;
unsigned int uiBitDepth;
IMppAudioCodecAlg codecAlg;
unsigned long long ui64TimestampUs;
}TMppAudioFrameInfo;
typedef struct _TMppRawAudioInfo
{
_TMppRawAudioInfo()
{
uiSampleRate = 0;
bStereo = false;
uiBitDepth = 0;
}
unsigned int uiSampleRate;
bool bStereo;
unsigned int uiBitDepth;
}TMppRawAudioInfo;
typedef void(*CALLBACK_AUDIO_FRAME_GOT)(unsigned char *pFrame, unsigned int uiFrameLen,
const TMppAudioFrameInfo &frameInfo, void *pContext);
typedef void(*CALLBACK_RAW_AUDIO_GOT)(unsigned char *pData, unsigned int uiDataLen,
const TMppRawAudioInfo &dataInfo, void *pContext);
typedef struct _TMppAudioCaptureParam
{
_TMppAudioCaptureParam()
{
bDigitalMic = false;
uiSampleRate = 0;
bStereo = false;
uiBitDepth = 0;
uiSamplesPerFrame = 0;
nsLevel = MppNSLevel_High;
codecAlg = MppAudioCodecAlg_G711A;
ucGainPercent = 60;
ucVolumePercent = 80;
pCbAudioFrameGot = NULL;
pCbRawAudioGot = NULL;
pCbContext = NULL;
pLogger = NULL;
}
bool bDigitalMic;
unsigned int uiSampleRate;
bool bStereo;
unsigned int uiBitDepth;
unsigned int uiSamplesPerFrame;
IMppNoiseSuppressLevel nsLevel;
IMppAudioCodecAlg codecAlg;
unsigned char ucGainPercent;
unsigned char ucVolumePercent;
CALLBACK_AUDIO_FRAME_GOT pCbAudioFrameGot;
CALLBACK_RAW_AUDIO_GOT pCbRawAudioGot;
void *pCbContext;
CHP_Logger *pLogger;
}TMppAudioCaptureParam;
typedef struct _TMppAudioPlayParam
{
_TMppAudioPlayParam()
{
bDefaultSpeaker = true;
bEnable = true;
ucGainPercent = 60;
ucVolumePercent = 80;
pLogger = NULL;
}
bool bDefaultSpeaker;
bool bEnable;
unsigned char ucGainPercent;
unsigned char ucVolumePercent;
CHP_Logger *pLogger;
}TMppAudioPlayParam;
typedef void(*CALLBACK_PTZ_MOTOR_STATUS_CHANGED)(bool bMovingNow, void *pContext);
typedef struct _TMppPtzMotorParam
{
_TMppPtzMotorParam()
{
uiSensorHorAngle = 0;
uiSensorVerAngle = 0;
uiMaxHorViewDegree = 0;
uiMaxHorViewLeftDegree = 0;
uiMaxVerViewDegree = 0;
uiMaxVerViewDownDegree = 0;
uiHorViewDegreePerStep = 10;
uiVerViewDegreePerStep = 5;
uiMaxSpeed = 500;
uiMinSpeed = 100;
ucSpeedPercent = 50;
bLeftForward = true;
bDownForward = false;
pCbPtzMotorStatusChanged = NULL;
pCbContext = NULL;
pLogger = NULL;
}
unsigned int uiSensorHorAngle;
unsigned int uiSensorVerAngle;
unsigned int uiMaxHorViewDegree;
unsigned int uiMaxHorViewLeftDegree;
unsigned int uiMaxVerViewDegree;
unsigned int uiMaxVerViewDownDegree;
unsigned int uiHorViewDegreePerStep;
unsigned int uiVerViewDegreePerStep;
unsigned int uiMaxSpeed;
unsigned int uiMinSpeed;
unsigned int ucSpeedPercent;
bool bLeftForward;
bool bDownForward;
CALLBACK_PTZ_MOTOR_STATUS_CHANGED pCbPtzMotorStatusChanged;
void *pCbContext;
CHP_Logger *pLogger;
}TMppPtzMotorParam;
typedef struct _TMppPtzMotorStatusInfo
{
_TMppPtzMotorStatusInfo()
{
bMovingNow = false;
fHorPercent = 0.0f;
fVerPercent = 0.0f;
ucSpeedPercent = 0;
}
bool bMovingNow;
float fHorPercent;
float fVerPercent;
unsigned char ucSpeedPercent;
}TMppPtzMotorStatusInfo;
typedef struct _TMppPtzMotorStatusInfoEx
{
_TMppPtzMotorStatusInfoEx()
{
bMovingNow = false;
nHorPos = 0;
nVerPos = 0;
nSpeed = 0;
}
bool bMovingNow;
int nHorPos;
int nVerPos;
int nSpeed;
}TMppPtzMotorStatusInfoEx;
typedef struct _TMppPointInfo
{
_TMppPointInfo()
{
fXRatio = 0.0f;
fYRatio = 0.0f;
}
float fXRatio;
float fYRatio;
}TMppPointInfo;
typedef struct _TMppRectangleInfo
{
_TMppRectangleInfo()
{
fX1Ratio = 0.0f;
fY1Ratio = 0.0f;
fX2Ratio = 0.0f;
fY2Ratio = 0.0f;
}
float fX1Ratio;
float fY1Ratio;
float fX2Ratio;
float fY2Ratio;
}TMppRectangleInfo;
typedef TMppRectangleInfo TMppRectangleOverlayInfo;
typedef struct _TMppPolygonOverlayInfo
{
std::vector<TMppPointInfo> vctPoint;
}TMppPolygonOverlayInfo;
enum IMppVideoOverlayPos
{
MppVideoOverlayPos_LeftTop,
MppVideoOverlayPos_LeftBottom,
MppVideoOverlayPos_RightTop,
MppVideoOverlayPos_RightBottom,
MppVideoOverlayPos_Center,
MppVideoOverlayPos_Count
};
typedef struct _TMppVideoOverlayPositionInfo
{
_TMppVideoOverlayPositionInfo()
{
pos = MppVideoOverlayPos_LeftTop;
fXRatio = 0.0f;
fYRatio = 0.0f;
}
IMppVideoOverlayPos pos;
float fXRatio;
float fYRatio;
}TMppVideoOverlayPositionInfo;
typedef struct _TMppTextOverlayInfo
{
_TMppTextOverlayInfo()
{
bShow = false;
uiColor = 0;
}
std::string strText;
bool bShow;
unsigned int uiColor;
TMppVideoOverlayPositionInfo posInfo;
}TMppTextOverlayInfo;
enum IMppKeystrokeEvent
{
MppKeystrokeEvent_None,
MppKeystrokeEvent_Reset_LongPress,
MppKeystrokeEvent_Reset_ShortPress,
MppKeystrokeEvent_ExKey_Press
};
typedef void(*CALLBACK_KEYSTROKE_PRESSED)(IMppKeystrokeEvent event, void *pContext);
typedef struct _TMppKeystrokeParam
{
_TMppKeystrokeParam()
{
uiResetKeyCode = 0;
uiExKeyCode = 0;
uiShortPressSec = 2;
uiLongPressSec = 5;
pCbPressed = NULL;
pCbContext = NULL;
pLogger = NULL;
}
unsigned int uiResetKeyCode;
unsigned int uiExKeyCode;
unsigned int uiShortPressSec;
unsigned int uiLongPressSec;
CALLBACK_KEYSTROKE_PRESSED pCbPressed;
void *pCbContext;
CHP_Logger *pLogger;
}TMppKeystrokeParam;
enum IMppWifiEncryptType
{
MppWifiEncryptType_None,
MppWifiEncryptType_Open,
MppWifiEncryptType_WPA,
MppWifiEncryptType_WPA2,
MppWifiEncryptType_WPA3,
MppWifiEncryptType_WEP
};
enum IMppWifiEncryptCipher
{
MppWifiEncryptCipher_None,
MppWifiEncryptCipher_AES,
MppWifiEncryptCipher_TKIP
};
enum IMppWifiAuthSuite
{
MppWifiAuthSuite_None,
MppWifiAuthSuite_PSK,
MppWifiAuthSuite_802_1x
};
enum IMppWifiConnectStatus
{
MppWifiConnectStatus_Disabled,
MppWifiConnectStatus_NoChip,
MppWifiConnectStatus_Init,
MppWifiConnectStatus_Scanning,
MppWifiConnectStatus_Idle,
MppWifiConnectStatus_APNotFound,
MppWifiConnectStatus_WrongPassword,
MppWifiConnectStatus_ConnectingAP,
MppWifiConnectStatus_ConnectingAPFailed,
MppWifiConnectStatus_ConnectingNet,
MppWifiConnectStatus_ConnectNetFailed,
MppWifiConnectStatus_ConnectNetSuccess
};
enum IMppWifiAPEncryptType
{
MppWifiAPEncryptType_None,
MppWifiAPEncryptType_Open,
MppWifiAPEncryptType_WPA_WPA2
};
enum IMppWifiAPConnectStatus
{
MppWifiAPConnectStatus_Disabled,
MppWifiAPConnectStatus_NoChip,
MppWifiAPConnectStatus_Init,
MppWifiAPConnectStatus_Idle,
MppWifiAPConnectStatus_Auth,
MppWifiAPConnectStatus_StartDHCPServer,
MppWifiAPConnectStatus_Success
};
typedef struct _TMppWifiAPInfo
{
_TMppWifiAPInfo()
{
encryptType = MppWifiEncryptType_None;
cipher = MppWifiEncryptCipher_None;
suite = MppWifiAuthSuite_None;
nSignalPercent = 0;
nSignalDb = 0;
}
std::string strSSID;
IMppWifiEncryptType encryptType;
IMppWifiEncryptCipher cipher;
IMppWifiAuthSuite suite;
int nSignalPercent;
int nSignalDb;
}TMppWifiAPInfo;
typedef struct _TMppFlashParam
{
_TMppFlashParam()
{
uiEraseBlockSize = 0;
uiPublicCfgAreaMaxSize = 0;
uiPrivateCfgAreaMaxSize = 0;
uiAuthInfoAreaMaxSize = 0;
pLogger = NULL;
}
unsigned int uiEraseBlockSize;
std::string strCfgPartitionName;
std::string strAppPartitionName;
std::string strAppBackupPartitionName;
unsigned int uiPublicCfgAreaMaxSize;
unsigned int uiPrivateCfgAreaMaxSize;
unsigned int uiAuthInfoAreaMaxSize;
CHP_Logger *pLogger;
}TMppFlashParam;
typedef struct _TMppLedParam
{
_TMppLedParam()
{
uiRedGpio = 0;
uiBlueGpio = 0;
bDefaultRedOn = true;
bDefaultBlueOn = false;
bRedGpioLowOn = false;
bBlueGpioLowOn = false;
pLogger = NULL;
}
unsigned int uiRedGpio;
unsigned int uiBlueGpio;
bool bDefaultRedOn;
bool bDefaultBlueOn;
bool bRedGpioLowOn;
bool bBlueGpioLowOn;
CHP_Logger *pLogger;
}TMppLedParam;
typedef void(*CALLBACK_WHITE_LIGHT_BEFORE_ON)(unsigned int uiCameraChannel, bool bTwinkle, void *pContext);
typedef void(*CALLBACK_WHITE_LIGHT_BEFORE_OFF)(unsigned int uiCameraChannel, void *pContext);
typedef struct _TMppWhiteLightCameraParam
{
_TMppWhiteLightCameraParam()
{
uiGpio = 0;
bGpioLowOn = false;
}
unsigned int uiGpio;
bool bGpioLowOn;
}TMppWhiteLightCameraParam;
typedef std::vector<TMppWhiteLightCameraParam> TMppWhiteLightCameraParamVector;
typedef struct _TMppWhiteLightParam
{
_TMppWhiteLightParam()
{
pCbBeforeOn = NULL;
pCbBeforeOff = NULL;
pCbContext = NULL;
pLogger = NULL;
}
TMppWhiteLightCameraParamVector vctCamera;
CALLBACK_WHITE_LIGHT_BEFORE_ON pCbBeforeOn;
CALLBACK_WHITE_LIGHT_BEFORE_OFF pCbBeforeOff;
void *pCbContext;
CHP_Logger *pLogger;
}TMppWhiteLightParam;
typedef struct _TMppConfigParam
{
_TMppConfigParam()
{
pLogger = NULL;
}
std::string strDefaultCfgFile;
CHP_Logger *pLogger;
}TMppConfigParam;
typedef int(*CALLBACK_CUSTOM_SWITCH_IR_FILTER)(unsigned int uiCameraChannel, bool bNight, void *pContext);
typedef void(*CALLBACK_SWITCH_WHITE_LIGHT)(unsigned int uiCameraChannel, bool bOn, void *pContext);
typedef void(*CALLBACK_GET_WHITE_LIGHT_STATUS)(unsigned int uiCameraChannel, bool &bOpenForEver, bool &bIsOn,
bool &bTwinkle, void *pContext);
enum IMppDayNightDetectMode
{
MppDayNightDetectMode_ADC,
MppDayNightDetectMode_GPIO,
MppDayNightDetectMode_Soft,
MppDayNightDetectMode_Count
};
typedef struct _TMppCameraAdcInfo
{
_TMppCameraAdcInfo()
{
nAdcIndex = 0;
nSwitchToDayAdc = 200;
nSwitchToNightAdc = 80;
}
int nAdcIndex;
int nSwitchToDayAdc;
int nSwitchToNightAdc;
}TMppCameraAdcInfo;
typedef struct _TMppCameraGpioInfo
{
_TMppCameraGpioInfo()
{
uiDayNightDetectGpio = 0;
bDayNightDetectGpioLowDay = false;
}
unsigned int uiDayNightDetectGpio;
bool bDayNightDetectGpioLowDay;
}TMppCameraGpioInfo;
typedef struct _TMppCameraSoftInfo
{
_TMppCameraSoftInfo()
{
uiSwitchToNightEv = 60000;
uiSwitchToDayEv = 8000;
uiBlueGainDiffBetweenCurAndMin = 15;
uiBlueGainDiffBetweenCurAndMax = 15;
}
unsigned int uiSwitchToNightEv;
unsigned int uiSwitchToDayEv;
unsigned int uiBlueGainDiffBetweenCurAndMin;
unsigned int uiBlueGainDiffBetweenCurAndMax;
}TMppCameraSoftInfo;
typedef struct _TMppIspCameraParam
{
_TMppIspCameraParam()
{
uiIrFilterPGpio = 0;
uiIrFilterNGpio = 0;
uiIrLightGpio = 0;
detectMode = MppDayNightDetectMode_ADC;
}
unsigned int uiIrFilterPGpio;
unsigned int uiIrFilterNGpio;
unsigned int uiIrLightGpio;
IMppDayNightDetectMode detectMode;
TMppCameraSoftInfo softInfo;
union
{
TMppCameraAdcInfo adcInfo;
TMppCameraGpioInfo gpioInfo;
};
}TMppIspCameraParam;
typedef std::vector<TMppIspCameraParam> TMppIspCameraParamVector;
typedef struct _TMppIspParam
{
_TMppIspParam()
{
pCbCustomSwitchIrFilter = NULL;
pCbSwitchWhiteLight = NULL;
pCbGetWhiteLightStatus = NULL;
pCbContext = NULL;
pLogger = NULL;
}
TMppIspCameraParamVector vctCamera;
CALLBACK_CUSTOM_SWITCH_IR_FILTER pCbCustomSwitchIrFilter;
CALLBACK_SWITCH_WHITE_LIGHT pCbSwitchWhiteLight;
CALLBACK_GET_WHITE_LIGHT_STATUS pCbGetWhiteLightStatus;
void *pCbContext;
CHP_Logger *pLogger;
}TMppIspParam;
typedef struct _TMppRtcTime
{
_TMppRtcTime()
{
nYear = 0;
nMonth = 0;
nDay = 0;
nHour = 0;
nMinute = 0;
nSecond = 0;
}
int nYear;
int nMonth;
int nDay;
int nHour;
int nMinute;
int nSecond;
}TMppRtcTime;
enum IMppSDCardStatus
{
MppSDCardStatus_NotInserted,
MppSDCardStatus_Formating,
MppSDCardStatus_Exception,
MppSDCardStatus_UnSupportSystem,
MppSDCardStatus_Ready
};
typedef void(*CALLBACK_SD_CARD_STATUS_CHANGED)(IMppSDCardStatus status, void *pContext);
typedef int(*CALLBACK_SD_CARD_CUSTOM_FORMAT)(void *pContext);
typedef bool(*CALLBACK_SD_CARD_IS_CUSTOM_FORMATTED)(void *pContext);
enum IMppSDCardFileSystem
{
MppSDCardFileSystem_Unknown,
MppSDCardFileSystem_Fat32,
MppSDCardFileSystem_Ext4,
MppSDCardFileSystem_Count
};
typedef struct _TMppSDCardInfo
{
_TMppSDCardInfo()
{
fileSystem = MppSDCardFileSystem_Unknown;
ui64TotalBytes = 0;
ui64FreeBytes = 0;
}
IMppSDCardFileSystem fileSystem;
unsigned long long ui64TotalBytes;
unsigned long long ui64FreeBytes;
}TMppSDCardInfo;
typedef struct _TMppSDCardParam
{
_TMppSDCardParam()
{
fileSystem = MppSDCardFileSystem_Fat32;
memset(pszMkfsVfatToolFile, 0, sizeof(pszMkfsVfatToolFile));
memset(pszMke2fsToolFile, 0, sizeof(pszMke2fsToolFile));
pCbStatusChanged = NULL;
pCbCustomFormat = NULL;
pCbIsCustomFormatted = NULL;
pCbContext = NULL;
pLogger = NULL;
}
IMppSDCardFileSystem fileSystem;
std::string strDiskPath;
std::string strMakeNewPartitionScriptFile;
union
{
char pszMkfsVfatToolFile[256];
char pszMke2fsToolFile[256];
};
CALLBACK_SD_CARD_STATUS_CHANGED pCbStatusChanged;
CALLBACK_SD_CARD_CUSTOM_FORMAT pCbCustomFormat;
CALLBACK_SD_CARD_IS_CUSTOM_FORMATTED pCbIsCustomFormatted;
void *pCbContext;
CHP_Logger *pLogger;
}TMppSDCardParam;
typedef void(*CALLBACK_NETWORK_CABLE_PLUG_CHANGED)(bool bPluggedInNow, void *pContext);
typedef struct _TMppWiredNetworkParam
{
_TMppWiredNetworkParam()
{
strNetInterfaceName = "eth0";
uiCheckPlugIntervalMs = 2000;
pCbNetworkCablePlugChanged = NULL;
pCbContext = NULL;
pLogger = NULL;
}
std::string strNetInterfaceName;
unsigned int uiCheckPlugIntervalMs;
CALLBACK_NETWORK_CABLE_PLUG_CHANGED pCbNetworkCablePlugChanged;
void *pCbContext;
CHP_Logger *pLogger;
}TMppWiredNetworkParam;
typedef void(*CALLBACK_WIFI_CONNECT_STATUS_CHANGED)(IMppWifiConnectStatus statusNew,
IMppWifiConnectStatus statusOld, void *pContext);
typedef struct _TMppWifiNetworkParam
{
_TMppWifiNetworkParam()
{
strNetInterfaceName = "wlan0";
pCbWifiConnectStatusChanged = NULL;
pCbContext = NULL;
pLogger = NULL;
}
std::string strNetInterfaceName;
std::string strDriverFile;
std::string strWpaSupplicantToolFile;
std::string strWpaCliToolFile;
std::string strWpaPassphraseToolFile;
std::string strIwlistToolFile;
std::string strHostapdToolFile;
std::string strWritableRootDir;
std::string strPasswordWrongTipFile;
CALLBACK_WIFI_CONNECT_STATUS_CHANGED pCbWifiConnectStatusChanged;
void *pCbContext;
CHP_Logger *pLogger;
}TMppWifiNetworkParam;
enum IMppNetworkType
{
MppNetworkType_Wired,
MppNetworkType_Wifi
};
typedef void(*CALLBACK_NETWORK_TYPE_CHANGED)(IMppNetworkType newType, IMppNetworkType oldType, void *pContext);
enum IMppNetworkSwitchMode
{
MppNetworkSwitchMode_Auto,
MppNetworkSwitchMode_OnlyWired,
MppNetworkSwitchMode_WifiPreferred,
MppNetworkSwitchMode_Count
};
typedef struct _TMppNetworkManagerParam
{
_TMppNetworkManagerParam()
{
bHasWired = true;
bHasWifi = false;
pCbNetworkTypeChanged = NULL;
pCbContext = NULL;
pLogger = NULL;
}
bool bHasWired;
bool bHasWifi;
std::string strDhcpScriptFile;
CALLBACK_NETWORK_TYPE_CHANGED pCbNetworkTypeChanged;
void *pCbContext;
CHP_Logger *pLogger;
}TMppNetworkManagerParam;
typedef struct _TMppMediaStorageParam
{
_TMppMediaStorageParam()
{
uiCameraCount = 0;
uiRecordDurationMinutes = 0;
bSaveMediaOfInvalidTime = false;
uiMaxVideoFrameLen = 0;
uiMaxPoolLen = 0;
uiOverWriteMinFreeMB = 500;
uiOverWriteMaxFreeMB = 1000;
pLogger = NULL;
}
std::string strSDCardPath;
std::string strDevID;
unsigned int uiCameraCount;
unsigned int uiRecordDurationMinutes;
bool bSaveMediaOfInvalidTime;
unsigned int uiMaxVideoFrameLen;
unsigned int uiMaxPoolLen;
unsigned int uiOverWriteMinFreeMB;
unsigned int uiOverWriteMaxFreeMB;
CHP_Logger *pLogger;
}TMppMediaStorageParam;
typedef struct _TMppRecordVideoFrameInfo
{
_TMppRecordVideoFrameInfo()
{
ui64Timestamp = 0;
ui64UTCTimeMs = 0;
bKeyFrame = false;
alg = MppVideoCodecAlg_H264Main;
usFrameRate = 0;
usWidth = 0;
usHeight = 0;
usKeyFrameInterval = 0;
}
unsigned long long ui64Timestamp;
unsigned long long ui64UTCTimeMs;
bool bKeyFrame;
IMppVideoCodecAlg alg;
unsigned short usFrameRate;
unsigned short usWidth;
unsigned short usHeight;
unsigned short usKeyFrameInterval;
}TMppRecordVideoFrameInfo;
typedef struct _TMppRecordAudioFrameInfo
{
_TMppRecordAudioFrameInfo()
{
ui64Timestamp = 0;
ui64UTCTimeMs = 0;
alg = MppAudioCodecAlg_G711A;
uiSampleRate = 0;
ucChannelCount = 0;
ucBitsPerSample = 0;
uiSamplesPerFrame = 0;
}
unsigned long long ui64Timestamp;
unsigned long long ui64UTCTimeMs;
IMppAudioCodecAlg alg;
unsigned int uiSampleRate;
unsigned char ucChannelCount;
unsigned char ucBitsPerSample;
unsigned int uiSamplesPerFrame;
}TMppRecordAudioFrameInfo;
enum IMppRecordFrameType
{
MppRecordFrameType_Video,
MppRecordFrameType_Audio
};
typedef struct _TMppRecordFrameInfo
{
IMppRecordFrameType type;
union _fi
{
TMppRecordVideoFrameInfo vfi;
TMppRecordAudioFrameInfo afi;
_fi() {}
~_fi() {}
}fi;
}TMppRecordFrameInfo;
typedef struct _TMppRecordTimeSpan
{
_TMppRecordTimeSpan()
{
ui64StartTimeMs = 0;
ui64EndTimeMs = 0;
}
unsigned long long ui64StartTimeMs;
unsigned long long ui64EndTimeMs;
}TMppRecordTimeSpan;
typedef struct _TMppRecordFile
{
_TMppRecordFile()
{
uiFileSize = 0;
ui64StartTimeMs = 0;
ui64EndTimeMs = 0;
}
std::string strFileName;
unsigned int uiFileSize;
unsigned long long ui64StartTimeMs;
unsigned long long ui64EndTimeMs;
}TMppRecordFile;
typedef struct _TMppPictureFile
{
_TMppPictureFile()
{
uiFileSize = 0;
ui64TimeMs = 0;
}
std::string strFileName;
unsigned int uiFileSize;
unsigned long long ui64TimeMs;
}TMppPictureFile;
typedef struct _TMppEventResult
{
_TMppEventResult()
{
uiEventID = 0;
uiBindedChannel = 0;
ui64UTCTimeMs = 0;
}
unsigned int uiEventID;
unsigned int uiBindedChannel;
unsigned long long ui64UTCTimeMs;
}TMppEventResult;
typedef struct _TMppWatchdogParam
{
_TMppWatchdogParam()
{
uiTimeoutSec = 60;
pLogger = NULL;
}
unsigned int uiTimeoutSec;
CHP_Logger *pLogger;
}TMppWatchdogParam;
typedef void(*CALLBACK_MOTION_DETECTED)(unsigned int uiCameraChannel,
const std::vector<TMppRectangleInfo> &vctRectInfo, void *pContext);
typedef struct _TMppMotionDetectParam
{
_TMppMotionDetectParam()
{
pCbMotionDetected = NULL;
pCbContext = NULL;
pLogger = NULL;
}
CALLBACK_MOTION_DETECTED pCbMotionDetected;
void *pCbContext;
CHP_Logger *pLogger;
}TMppMotionDetectParam;
typedef void(*CALLBACK_HUMAN_BODY_DETECTED)(unsigned int uiCameraChannel,
const std::vector<TMppRectangleInfo> &vctRectInfo, void *pContext);
typedef struct _TMppHumanBodyDetectParam
{
_TMppHumanBodyDetectParam()
{
pCbHumanBodyDetected = NULL;
pCbContext = NULL;
pLogger = NULL;
}
std::string strModelPath;
CALLBACK_HUMAN_BODY_DETECTED pCbHumanBodyDetected;
void *pCbContext;
CHP_Logger *pLogger;
}TMppHumanBodyDetectParam;
typedef void(*CALLBACK_MOTION_TRACK_MOTOR_NOT_MOVED)(unsigned int uiCameraChannel, void *pContext);
typedef struct _TMppMotionTrackParam
{
_TMppMotionTrackParam()
{
pCbMotorNotMoved = NULL;
pCbContext = NULL;
pLogger = NULL;
}
CALLBACK_MOTION_TRACK_MOTOR_NOT_MOVED pCbMotorNotMoved;
void *pCbContext;
CHP_Logger *pLogger;
}TMppMotionTrackParam;
typedef void(*CALLBACK_VOICE_DETECTED)(void *pContext);
typedef struct _TMppVoiceDetectParam
{
_TMppVoiceDetectParam()
{
uiSampleRate = 0;
bStereo = false;
pCbVoiceDetected = NULL;
pCbContext = NULL;
pLogger = NULL;
}
unsigned int uiSampleRate;
bool bStereo;
CALLBACK_VOICE_DETECTED pCbVoiceDetected;
void *pCbContext;
CHP_Logger *pLogger;
}TMppVoiceDetectParam;
在上面的头文件中,我们定义了很多跨平台通用的数据结构,包括:Led灯状态、白光灯模式、夜视模式、ISP翻转模式、抗闪烁模式、摄像头控制总线类型、摄像头时钟类型、视频码率控制模式、视频流类型、视频编码算法、摄像头信息、视频帧信息、Logo叠加信息、音频降噪等级、音频编码算法等等。
MPP_API_Types.h文件中定义的数据结构如下。
#pragma once
#include "HP_MPPTypes.h"
enum IMppBindDevID
{
MppBindDevID_Fs,
MppBindDevID_Enc,
MppBindDevID_Dec,
MppBindDevID_Ivs,
MppBindDevID_Osd,
MppBindDevID_Count
};
enum IMppVideoEncodeProfile
{
MppVideoEncodeProfile_H264_Baseline,
MppVideoEncodeProfile_H264_Main,
MppVideoEncodeProfile_H264_High,
MppVideoEncodeProfile_H265_Main,
MppVideoEncodeProfile_Jpeg,
MppVideoEncodeProfile_Count
};
enum IMppOsdRegionType
{
MppOsdRegionType_Inv,
MppOsdRegionType_Line,
MppOsdRegionType_Rect,
MppOsdRegionType_Bitmap,
MppOsdRegionType_Cover,
MppOsdRegionType_Pic,
MppOsdRegionType_PicRmem,
MppOsdRegionType_LineHor,
MppOsdRegionType_LineVer,
MppOsdRegionType_Count
};
enum IMppIspWBMode
{
MppIspWBMode_Auto,
MppIspWBMode_Manual,
MppIspWBMode_Count
};
typedef struct _TMppBindItem
{
_TMppBindItem()
{
devID = MppBindDevID_Fs;
nGroupID = 0;
nOutputID = 0;
};
IMppBindDevID devID;
int nGroupID;
int nOutputID;
}TMppBindItem;
typedef struct _TMppIspExposureAttr
{
_TMppIspExposureAttr()
{
uiEv = 0;
uiExprUs = 0;
uiEvLog2 = 0;
uiAgain = 0;
uiDgain = 0;
uiGainLog2 = 0;
}
unsigned int uiEv;
unsigned int uiExprUs;
unsigned int uiEvLog2;
unsigned int uiAgain;
unsigned int uiDgain;
unsigned int uiGainLog2;
}TMppIspExposureAttr;
typedef struct _TMppIspWBAttr
{
_TMppIspWBAttr()
{
mode = MppIspWBMode_Auto;
usRedGain = 0;
usBlueGain = 0;
}
IMppIspWBMode mode;
unsigned short usRedGain;
unsigned short usBlueGain;
}TMppIspWBAttr;
typedef struct _TMppEncChannelVideoSpecParam
{
_TMppEncChannelVideoSpecParam()
{
mode = MppVideoBitrateCtrlMode_CBR;
uiBitrateKbps = 0;
uiMaxBitrateKbps = 0;
uiKeyFrameInterval = 0;
}
IMppVideoBitrateCtrlMode mode;
unsigned int uiBitrateKbps;
unsigned int uiMaxBitrateKbps;
unsigned int uiKeyFrameInterval;
}TMppEncChannelVideoSpecParam;
typedef struct _TMppEncChannelJpegSpecParam
{
_TMppEncChannelJpegSpecParam()
{
ucImageQualityPercent = 0;
}
unsigned char ucImageQualityPercent;
}TMppEncChannelJpegSpecParam;
typedef struct _TMppEncChannelParam
{
_TMppEncChannelParam()
{
profile = MppVideoEncodeProfile_H264_Baseline;
uiWidth = 0;
uiHeight = 0;
uiFrameRate = 0;
uiMaxFrameRate = 0;
}
IMppVideoEncodeProfile profile;
unsigned int uiWidth;
unsigned int uiHeight;
unsigned int uiFrameRate;
unsigned int uiMaxFrameRate;
union
{
TMppEncChannelVideoSpecParam video;
TMppEncChannelJpegSpecParam jpeg;
};
}TMppEncChannelParam;
typedef struct _TMppOsdRegionLineRectData
{
_TMppOsdRegionLineRectData()
{
uiColor = 0;
uiLineWidth = 0;
}
unsigned int uiColor;
unsigned int uiLineWidth;
}TMppOsdRegionLineRectData;
typedef struct _TMppOsdRegionCoverData
{
_TMppOsdRegionCoverData()
{
uiColor = 0;
}
unsigned int uiColor;
}TMppOsdRegionCoverData;
typedef struct _TMppOsdRegionPicData
{
_TMppOsdRegionPicData()
{
pData = NULL;
}
void *pData;
}TMppOsdRegionPicData;
typedef union _TMppOsdRegionData
{
_TMppOsdRegionData()
{
pBmp = NULL;
}
void *pBmp;
TMppOsdRegionLineRectData lineRect;
TMppOsdRegionCoverData cover;
TMppOsdRegionPicData pic;
}TMppOsdRegionData;
typedef struct _TMppOsdRegionAttr
{
_TMppOsdRegionAttr()
{
type = MppOsdRegionType_Inv;
nTopLeftX = 0;
nTopLeftY = 0;
nBottomRightX = 0;
nBottomRightY = 0;
format = MppImagePixelFormat_MonoWhite;
}
IMppOsdRegionType type;
int nTopLeftX;
int nTopLeftY;
int nBottomRightX;
int nBottomRightY;
IMppImagePixelFormat format;
TMppOsdRegionData data;
}TMppOsdRegionAttr;
typedef struct _TMppOsdGroupRegionAttr
{
_TMppOsdGroupRegionAttr()
{
bShow = false;
bEnableAlpha = true;
fScaleX = 1.0f;
fScaleY = 1.0f;
nOsdLayer = 0;
nForeAlpha = 0xFF;
nBackAlpha = 0;
}
bool bShow;
bool bEnableAlpha;
float fScaleX;
float fScaleY;
int nOsdLayer;
int nForeAlpha;
int nBackAlpha;
}TMppOsdGroupRegionAttr;
在上面的头文件中,我们定义了很多君正芯片方案通用的数据结构,包括:绑定类型、OSD区域类型、ISP白平衡模式、ISP曝光属性、编码通道参数、OSD区域属性等等。
在本节中,我们介绍了封装君正底层API接口的概要知识,并给出了错误码定义和数据结构定义。下一节,我们介绍君正底层API的接口封装。