Contents |
All API functions return zero for success, non-zero for failure.
VAST1, VAST2, and linux embedded NVR support connection with SSL.
The SSL port of VAST1 and VAST2 is 3443, and linux embedded NVR
uses port 443.
All non-streaming APIs can enable SSL by setting useSSL field in
PlatformSDK.Login.
For example, login VAST with SSL:
void login(ref int loginID) { TLoginInfo loginInfo = new TLoginInfo(); loginInfo.IP = "127.0.0.1"; loginInfo.userName = "user"; loginInfo.password = "pswd"; loginInfo.port = 3443; loginInfo.pfMessCB = null; loginInfo.context = IntPtr.Zero; loginInfo.timeoutSeconds = 60; loginInfo.blockLogin = true; loginInfo.heartBeatLostRetryTimes = 0; loginInfo.useSSL = true; PlatformSDK.Login(ref loginID, ref loginInfo); }
Then all the APIs used loginID will transmit data with SSL.
The streaming API of live channel, playback channel, and export channel,
can enable SSL by setting useSSL field in creating channel function.
For example, play VAST live stream with SSL:
public class ViewCell : Form { public void CreateLiveChannel(string serverIP, string serverUserName, string serverPassword, string cameraID) { TStreamInfo streamInfo = new TStreamInfo(); streamInfo.streamSource = PlatformSDK.EStreamSource.VAST; streamInfo.serverIP = serverIP; streamInfo.serverUserName = serverUserName; streamInfo.serverPassword = serverPassword; streamInfo.serverPort = 3443; streamInfo.cameraID = cameraID; streamInfo.pfStreamDataCB = null; streamInfo.pfPCMDataCB = null; streamInfo.pfYV12DataCB = null; streamInfo.pfVideoDecodeCB = null; streamInfo.pfStreamStatusCB = null; streamInfo.hDisplayWindow = this.Handle; streamInfo.streamMode = PlatformSDK.EStreamMode.noramlStream; streamInfo.useSSL = true; streamInfo.videoDisplayMode = PlatformSDK.EVideoDisplayMode.fillViewCell; PlatformSDK.CreateLiveChannel(ref hChannel, ref streamInfo); } }
The web socket API also support SSL, user just set URL field with "https://IP:SSL-Port/...".
For example, get camera information from VAST server with SSL:
PlatformSDK.pfHttpRequestCallBack httpRequestCB = new PlatformSDK.pfHttpRequestCallBack(GetCameraInfoCallBack); void GetCameraInfoCallBack(IntPtr message, uint messageLen, IntPtr context) { if (messageLen == 0) return; string response = Marshal.PtrToStringAnsi(message); System.Console.WriteLine(response); } private void GetCameraInfo(string serverIP, string serverPort, string deviceID, string username, string password) { string data = "<GetNodeInfo><Node>" + deviceID +"</Node></GetNodeInfo>"; string url = "https://" + serverIP + ":3443/Tunnel/Message.aspx"; THttpRequest request = new THttpRequest(); request.method = PlatformSDK.EHttpMethod.POST; request.URL = url; request.userName = username; request.password = password; request.header = null; request.headerLen = 0; request.POSTData = data; request.POSTDataLen = 0; request.callback = httpRequestCB; int ret = PlatformSDK.SendHttpRequest(ref request); EventLog.Write("PlatformSDK.SendHttpRequest Ret = {0:X}", ret); }
Method:
int PlatformSDK.Initial()
Description:
Initialize PlatformSDK. User must call PlatformSDK.Release to release the resource if PlatformSDK is no longer used.
Error codes:
(0x80700000) : fail to initialize server.
Method:
int PlatformSDK.Release()
Description:
Release the resources of PlatformSDK.
Description:
PlatformSDK.Login would setup a consistent tunnel with target server. It will be terminated when PlatformSDK.Logout is called. When login success, then phLoginID will be assigned and would be used for other commands to communicate through the tunnel. When login success, the login callback function will receive the status of EConnectionStatus.connected. When login timeout or fail to login, the login callback function will receive EConnectionStatus.disconnected. User must call PlatformSDK.Logout if the phLoginID is no longer used.
Remark:
When input an invalid IP or network was disconnected, the callback function will receive server type EServerType.configServer and EConnectionStatus.disconnected after timeout. When input invalid account or password, the callback function will receive server type EServerType.configServer and EConnectionStatus.disconnected immediately. Support multi-thread execution only if phLoginID is different in each thread.
Method:
uint PlatformSDK.Login(ref int phLoginID, ref TLoginInfo ptLoginOption)
Related structure:
[Serializable, StructLayout(LayoutKind.Sequential)] public struct TLoginInfo { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_IPHOST_LEN + 1)] public string IP; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_USERNAME_LEN + 1)] public string userName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HEXPWD_LEN + 1)] public string password; public int port; [MarshalAs(UnmanagedType.FunctionPtr)] public pfMessCallBack pfMessCB; public IntPtr context; public int timeoutSeconds; public bool blockLogin; public uint heartBeatLostRetryTimes; public uint heartbeatPeriodSeconds; public uint VAST2WebSocketPort; public bool useSSL; }
IP : Server IP. userName : User account. password : User password. port : Server port. pfMessCB : Callback function for notifying the connection status. context : User passed information. timeoutSeconds : Login timeout seconds, used when bBlockLogin = true. blockLogin : false = non-block login, true = block login until success or timeout. heartBeatLostRetryTimes: Retry times of heartbeat lost, the interval of each retry is heartbeatPeriodSeconds. heartbeatPeriodSeconds : The detect period of heartbeat, set zero to disable heartbeat check. VAST2WebSocketPort : Web socket port, used for VAST2. useSSL : Connection with SSL.
public enum EServerType : uint { configServer, eventServer, queryServer, } public enum EConnectionStatus : uint { unknown, connected, disconnected, receiveHeartBeat, heartBeatLost, } [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TServerStatusInfo { public int hLoginID; public EServerType serverType; public EConnectionStatus status; public IntPtr context; }
hLoginID : Login ID. serverType : Indicate the server type. status : EConnectionStatus.disconnected for disconnection, EConnectionStatus.connected for login success. context : User passed information.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfMessCallBack(IntPtr pStatusInfo);
pStatusInfo : Pointer to the structure of TServerStatusInfo.
Login by block mode:
void login(ref int loginID) { TLoginInfo loginInfo = new TLoginInfo(); loginInfo.IP = "127.0.0.1"; loginInfo.userName = "user"; loginInfo.password = "pswd"; loginInfo.port = 3454; loginInfo.pfMessCB = null; loginInfo.context = IntPtr.Zero; loginInfo.timeoutSeconds = 60; loginInfo.blockLogin = true; loginInfo.heartBeatLostRetryTimes = 0; loginInfo.useSSL = false; PlatformSDK.Login(ref loginID, ref loginInfo); }
Login by non-block mode:
int loginID = 0; PlatformSDK.pfMessCallBack messCB = new PlatformSDK.pfMessCallBack(LoginCallBack); void LoginCallBack(IntPtr pStatusInfo) { TServerStatusInfo info = (TServerStatusInfo)Marshal.PtrToStructure(pStatusInfo, typeof(TServerStatusInfo)); if (info.servertype == PlatformSDK.EServerType.configServer) { switch (status) { case PlatformSDK.EConnectionStatus.connected: //Handle config server connect success break; case PlatformSDK.EConnectionStatus.disconnected: //Handle config server disconnect break; case PlatformSDK.EConnectionStatus.receiveHeartBeat: //Handle receive config server heartbeat break; case PlatformSDK.EConnectionStatus.heartBeatLost: //Handle config server heartbeat lost break; case PlatformSDK.EConnectionStatus.heartBeatLostRetry: //Handle config server heartbeat lost retry break; } } if (info.servertype == PlatformSDK.EServerType.eventServer) { switch (status) { case PlatformSDK.EConnectionStatus.connected: //Handle event server connect success break; case PlatformSDK.EConnectionStatus.disconnected: //Handle event server disconnect break; } } } void login(ref loginID) { TLoginInfo loginInfo = new TLoginInfo(); loginInfo.IP = "127.0.0.1"; loginInfo.userName = "user"; loginInfo.password = "pswd"; loginInfo.port = 3454; loginInfo.pfMessCB = messCB; loginInfo.context = IntPtr.Zero; loginInfo.blockLogin = false; loginInfo.heartBeatLostRetryTimes = 0; loginInfo.useSSL = false; PlatformSDK.Login(ref loginID, ref loginInfo); }
Sample code for handling server connection status:
int loginID = 0; PlatformSDK.pfMessCallBack messCB = new PlatformSDK.pfMessCallBack(LoginCallBack); void LoginCallBack(IntPtr pStatusInfo) { TServerStatusInfo info = (TServerStatusInfo)Marshal.PtrToStructure(pStatusInfo, typeof(TServerStatusInfo)); if (info.servertype == PlatformSDK.EServerType.configServer) { switch (status) { case PlatformSDK.EConnectionStatus.connected: // After login config server successfully, // we will get EConnectionStatus.connected. break; case PlatformSDK.EConnectionStatus.disconnected: // When the config server is disconnected, // we will get EConnectionStatus.disconnected. break; case PlatformSDK.EConnectionStatus.receiveHeartBeat: // When the config server is connected, // we will send a heartbeat to confirm it is alive. // if it is alive, we receive EConnectionStatus.receiveHeartBeat repeatedly. break; case PlatformSDK.EConnectionStatus.heartBeatLostRetry: // When the config server is connected, // we will send a heartbeat to confirm it is alive. // if it is not alive, we will retry and send a heartbeat again, // and we receive EConnectionStatus.heartBeatLostRetry in the callback. // We will only try n times which is defined in loginInfo.heartBeatLostRetryTimes. break; case PlatformSDK.EConnectionStatus.heartBeatLost: // After we reach the maximum retry times, // we receive EConnectionStatus.heartBeatLost in the callback, // and it means that we are completely disconnected from the server. break; } } } void login(ref loginID) { TLoginInfo loginInfo = new TLoginInfo(); loginInfo.IP = "127.0.0.1"; loginInfo.userName = "user"; loginInfo.password = "pswd"; loginInfo.port = 3454; loginInfo.pfMessCB = messCB; loginInfo.context = IntPtr.Zero; loginInfo.blockLogin = false; loginInfo.heartBeatLostRetryTimes = 3; loginInfo.heartbeatPeriodSeconds = 5; loginInfo.useSSL = false; PlatformSDK.Login(ref loginID, ref loginInfo); }
Error codes:
(0x80000003) : Parameter phLoginID or ptLoginOpt is invalid (0x80700116) : Login with empty user name (0x80700117) : Login with empty password (0x80700115) : Can not login config server (0x80700111) : Can not login event server (0x80700112) : Can not login query server
Description:
Logout server.
Remark:
Support multi-thread execution only if phLoginID is different in each thread.
Method:
uint PlatformSDK.Logout(ref int phLoginID)
Usage:
PlatformSDK.Logout(ref loginID);
Error codes:
(0x80000003) : Parameter phLoginID is invalid (0x80700113) : The previous logout does not finish
Description:
Get camera list, I/O Box list, and sub-station list. The retrieve data are stored in the array of structure of type TDeviceInfo. The content of response will keep until the next time call PlatformSDK.GetDeviceList. User must copy the data of TSDKDeviceInfo to reserve device information.
Method:
int PlatformSDK.GetDeviceList(int hLoginID, ref TDeviceListRequest request, ref TDeviceListResponse response)
Parameters:
hLoginID : Login ID. request : The structure of TDeviceListRequest. response : The structure of TDeviceListResponse, which retrieves data will store in.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TDeviceListRequest { public int timeoutMillisecond; public string stationID; }
timeoutMillisecond : Time out milliseconds of request. stationID : Substation ID, used for CMS.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TDeviceInfo { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string type; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string deviceID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_REFNAME_LEN + 1)] public string refName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_IPHOST_LEN + 1)] public string IP; public int port; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_USERNAME_LEN + 1)] public string userName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HEXPWD_LEN + 1)] public string password; public int channelIndex; public int DINum; public int DONum; };
type : String of device type: "Camera", "Station", "IOBox". deviceID : Device ID, prefix of camera is "C_", prefix of station is "S_", prefix of I/O Box is "D_". refName : Reference name of device. IP : Device IP. port : Device port. userName : User account, only used for I/O Box. password : User password, only used for I/O Box. channelIndex : channel index, start from 1, used for video server. DINum : DI count. DONum : DO count.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TDeviceListResponse { public IntPtr pDeviceList; public int deviceNum; }
pDeviceList : Pointer to an array of structue TDeviceInfo. deviceNum : The number of element in pDeviceList.
Usage:
void GetDeviceList(List<TDeviceInfo> listDevice) { TDeviceListRequest request = new TDeviceListRequest(); TDeviceListResponse response = new TDeviceListResponse(); request.stationID = ""; request.timeoutMillisecond = 5000; int ret = PlatformSDK.GetDeviceList(loginID, ref request, ref response); if (ret != 0) { return; } listDevice.Clear(); for (int i = 0; i < response.deviceNum; ++i) { IntPtr pDevice = new IntPtr(response.pDeviceList.ToInt64() + Marshal.SizeOf(typeof(TDeviceInfo)) * i); TDeviceInfo device = (TDeviceInfo)Marshal.PtrToStructure(pDevice, typeof(TDeviceInfo)); listDevice.Add(device); } }
Error codes:
(0x80000001) : hLoginID is invalid (0x80000003) : request or response is invalid (0x80700115) : tunnel is not connected (0x80700108) : tunnel send request failed
Description:
Get login station and cameras detail information. The retrieve data are stored in the structure of type TDeviceDetailListResponse. The content of response will keep until the next time call PlatformSDK.GetDeviceListWithDetails. User must copy the data of TSDKDeviceDetailsInfo to reserve device information.
Remark:
Not support multi-thread execution.
Method:
int PlatformSDK.GetDeviceListWithDetails(int hLoginID, ref TDeviceListRequest request, ref TDeviceDetailListResponse response)
Parameters:
hLoginID : Login ID. request : The structure of TDeviceListRequest. response : The structure of TDeviceDetailListResponse, which retrieves data will store in.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TDeviceListRequest { public uint timeoutMillisecond; public string stationID; }
timeoutMillisecond : Time out milliseconds of request. stationID : Substation ID, used for CMS.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TDeviceDetailInfo { public EDeviceType deviceType; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string deviceID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_REFNAME_LEN + 1)] public string refName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_IPHOST_LEN + 1)] public string IP; public uint port; public int DINum; public int DONum; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_FIRMWARE_VERSION_LEN + 1)] public string firmwareVersion; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_MAC_LEN + 1)] public string mac; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_MODEL_LEN + 1)] public string modelName; public int fisheyeCapability; public int ptzCapability; public int streamNum; public bool supportPTZ; };
type : String of device type: "Camera", "Station". deviceID : Device ID, prefix of camera is "C_". refName : Reference name of device. IP : Device IP. port : Device port. DINum : DI count. DONum : DO count. firmwareVersion : The version of device firware. mac : The MAC of camera. modelName : The model name of device. fisheyeCapability : Whether the camera has the fisheye feature or not. supportPTZ : Whether the camera has support PTZ or not. ptzCapability : PTZ capabilities for camera. The following is every single bit definition: Bit 0: Support camera control function 0(not support), 1(support) Bit 1: Build-in or external camera. 0(external), 1(build-in) Bit 2: Support pan operation. 0(not support), 1(support) Bit 3: Support tilt operation. 0(not support), 1(support) Bit 4: Support zoom operation. 0(not support), 1(support) Bit 5: Support focus operation. 0(not support), 1(support) Bit 6: Support Iris operation. 0(not support), 1(support) Bit 7: Build-in or external pan and tilt operation. 1(external), 0(build-in) Bit 14 : Support joystick. 0(not support), 1(support). If the camera does not have capability for joystick, and the camera is new model and support PTZ and not TC-series, then it support joystick. Bit 15 : If the camera is not built in, whether the current camera is PTZ enabled or not. streamNum : Camera stream count.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TDeviceListResponse { public IntPtr pDeviceList; public int deviceNum; }
pDeviceList : Pointer to an array of structue TDeviceDetailInfo. deviceNum : The number of element in pDeviceList.
Usage:
void GetDeviceListWithDetails(List<TDeviceDetailInfo> listDevice) { TDeviceListRequest request = new TDeviceListRequest(); TDeviceDetailListResponse response = new TDeviceDetailListResponse(); request.stationID = ""; request.timeoutMillisecond = 5000; int ret = PlatformSDK.GetDeviceListWithDetails(loginID, ref request, ref response); if (ret != 0) { return; } listDevice.Clear(); for (int i = 0; i < response.deviceNum; ++i) { IntPtr pDevice = new IntPtr(response.pDeviceList.ToInt64() + Marshal.SizeOf(typeof(TDeviceDetailInfo)) * i); TDeviceDetailInfo device = (TDeviceDetailInfo)Marshal.PtrToStructure(pDevice, typeof(TDeviceDetailInfo)); listDevice.Add(device); } }
Error codes:
(0x80000001) : hLoginID is invalid (0x80000003) : hLoginID, request or response is invalid (0x80700115) : tunnel is not connected (0x80700108) : tunnel send request failed
Method:
int PlatformSDK.GetAlarmInfoList(int hLoginID, ref IntPtr ppAlarmInfoList, int* pAlarmInfoNum)
Description:
Get alarm list
Parameters:
ppAlarmInfoList : Pointer to the array of structure of type TAlarmInfo. pAlarmInfoNum : Pointer to the item number of ppAlarmInfoList.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TAlarmInfo { public int ID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_REFNAME_LEN + 1)] public string alarmName; public IntPtr content; public int contentLen; }
ID : Alarm ID. alarmName : Alarm name. content : Alarm XML string. contentLen : The size of content.
Usage:
void GetAlarmList(List<TAlarmInfo> listAlarm) { listAlarm.Clear(); int alarmNum = 0; IntPtr pAlarmList = IntPtr.Zero; PlatformSDK.GetAlarmInfoList(loginID, ref pAlarmList, &alarmNum); for (int i = 0; i < alarmNum; ++i) { IntPtr pAlarmInfo = new IntPtr(pAlarmList.ToInt64() + Marshal.SizeOf(typeof(TAlarmInfo)) * i); TAlarmInfo alarmInfo = (TAlarmInfo)Marshal.PtrToStructure(pAlarmInfo, typeof(TAlarmInfo)); listAlarm.Add(alarmInfo); } }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter ppAlarmInfoList or pAlarmInfoNum is invalid (0x80700108) : Tunnel send request failed (0x80700111) : Tunnel is not connected
Description:
Get alarm records
Remark:
Not support multi-thread execution.
Method:
int PlatformSDK.QueryAlarm(int hLoginID, ref TQueryAlarmRequest ptQueryAlarmReqInfo, ref IntPtr pptAlarmRecords, int* pdwQueryAlarmNum)
Parameters:
ptQueryAlarmReqInfo : The structure of TQueryAlarmRequest. pptAlarmRecords : Pointer to the array of structure of type TQueryAlarmResponse. pdwQueryAlarmNum : Pointer to the item number of pptAlarmRecords.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TQueryAlarmRequest { public uint startTime; public uint endTime; public uint maxRecords; }
startTime : Query alarm start time, in seconds since Jan 1 1970 00:00:00. endTime : Query alarm end time, in seconds since Jan 1 1970 00:00:00. maxRecords : Maximum number of searching alarm.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TQueryAlarmResponse { public IntPtr content; public uint contentLength; }
content : the raw alarm xml string. contentLen : the size of content.
Usage:
public void QueryAlarm(int hLoginID) { var ptQueryAlarmReqInfo = new PlatformSDK.TQueryAlarmRequest(); ptQueryAlarmReqInfo.maxRecords = 100; ptQueryAlarmReqInfo.startTime = 1575504000; ptQueryAlarmReqInfo.endTime = 1575504000 + 86400; int alarmRecordNum = 0; IntPtr pAlarmRecords = IntPtr.Zero; int ret = PlatformSDK.QueryAlarm(hLoginID, ref ptQueryAlarmReqInfo, ref pAlarmRecords, &alarmRecordNum); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter ppAlarmInfoList, ppAlarmInfoList or pAlarmInfoNum is invalid (0x80700108) : tunnel send request failed (0x80700112) : Can not login query server
Method:
int PlatformSDK.TriggerAlarm(int hLoginID, ref TManualAlarmInfo alarmInfo)
Description:
Trigger the indicated alarm ID. User can pass a message to server by the structure member szDescription of alarmInfo.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TManualAlarmInfo { public int ID; [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_ALARM_DESC_LEN + 1)] public byte[] szUTF8Description; }
ID : Alarm ID for trigger. szUTF8Description : User message passed to server, must be UTF8 encoding and end with character '\0'.
Usage:
TManualAlarmInfo alarmInfo = new TManualAlarmInfo(); alarmInfo.ID = indicated alarm ID; alarmInfo.szDescription = new byte[PlatformSDK.MAX_ALARM_DESC_LEN + 1]; byte[] asciiDescription = Encoding.UTF8.GetBytes("User message"); Array.Copy(asciiDescription, alarmInfo.szDescription, asciiDescription.Length); PlatformSDK.TriggerAlarm(hLoginID, ref alarmInfo);
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80700111) : Can not login event server (0x80700108) : tunnel send request failed
Method:
int PlatformSDK.UpdateAlarm(int hLoginID, IntPtr pszMessage)
Description:
Update alarm information.
Parameters:
hLoginID : Login ID. pszMessage : The XML string used to update alarm information.
Remark:
UpdateAlarm sends a XML message of <Tmcard> to server to update alarm information. Before calling UpdateAlarm, we must call GetAlarmList first, Because of each alarm operation will change the tag value of <Revision> in <Tmcard>. We should call GetAlarmList to get the valid tag value of <Revision>.
Usage:
IntPtr message = Marshal.StringToHGlobalAnsi(alarmXMLinfo); PlatformSDK.UpdateAlarm(loginID, message); Marshal.FreeHGlobal(message);
alarmXMLinfo pointers to a XML string of <Tmcard>, for example:
<Tmcard> <Revision>10</Revision> <TmcardID>3</TmcardID> <Name>gdgrsd</Name> <Enabled>true</Enabled> <TriggerLatency>5</TriggerLatency> <TriggerList> <ExtDeviceEventTrigger> <EventType>ExtIODevice</EventType> <ExtIODevice> <DeviceName>D_2</DeviceName> <EventType>DO</EventType> <DO> <Index>3</Index> <Value>Rising</Value> </DO> </ExtIODevice> <Rule> <Latency>5</Latency> </Rule> </ExtDeviceEventTrigger> <ExtDeviceEventTrigger> <EventType>ExtIODevice</EventType> <ExtIODevice> <DeviceName>D_2</DeviceName> <EventType>DO</EventType> <DO> <Index>16</Index> <Value>Rising</Value> </DO> </ExtIODevice> <Rule> <Latency>5</Latency> </Rule> </ExtDeviceEventTrigger> </TriggerList> <ActionMode>Sequential</ActionMode> <ActionInterval>0</ActionInterval> <ActionList> <Action> <Order>0</Order> <ClientNotification> <Type>Popup Window</Type> <PopupWindow> <Size>Large</Size> <ShowTime>5</ShowTime> <AutoClose>false</AutoClose> <IncludeTriggerCam>true</IncludeTriggerCam> <Cam>C_93</Cam> </PopupWindow> </ClientNotification> </Action> </ActionList> <Priority>Normal</Priority> <EnableNotification>true</EnableNotification> <Mapping> <Ele> <Frame> <Name>Always</Name> <Holiday>false</Holiday> <RepeatMod>Weekly</RepeatMod> <DLMod>SingleDay</DLMod> <Intervals> <Ele B="0" E="86400"/> </Intervals> <DayList> <Ele B="1.0"/> <Ele B="2.0"/> <Ele B="3.0"/> <Ele B="4.0"/> <Ele B="5.0"/> <Ele B="6.0"/> <Ele B="7.0"/> </DayList> <Range> <Period> <TmS>2008-12-08 00:00:00.000</TmS> <TmE>2035-01-01 00:00:00.000</TmE> </Period> <End>false</End> </Range> <RepeatFreq>1</RepeatFreq> </Frame> </Ele> </Mapping> </Tmcard>
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter pszMessage is invalid (0x80700111) : Can not login event server (0x80700108) : tunnel send request failed
Description:
Register a callback function to monitor device status. If you no longer want to monitor device status, you could set NULL to the statusCB field.
Remark:
Support multi-thread execution only if hLoginID is different in each thread.
Method:
int PlatformSDK.MonitorDeviceStatus(int hLoginID, pfDeviceStatusCallBack statusCB, IntPtr context)
Parameters:
hLoginID : Login ID. statusCB : The call back function is used to receive status notification, set NULL will stop monitoring. context : User passed information.
Related structure:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfDeviceStatusCallBack(IntPtr pStatusList, int statusNum, IntPtr context);
pStatusList : Pointer to the array of structure of type TDeviceStatusInfo. statusNum : The item number of pStatusList. context : User passed information.
public enum EDeviceConnectionStatus : uint { unknown, connected, disonnected } public enum ERecordingStatus : uint { stop, start, } [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TDeviceStatusInfo { public EDeviceType deviceType; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string deviceID; public EDeviceConnectionStatus connectionStatus; public IntPtr recordingStatusInfo; public bool init; public ERecordingStatus recordingStatus; }
deviceType : The device type. deviceID : The device ID. connectionStatus : The connection status of device. recordingStatusInfo: If the value is non-zero, it pointer to TDeviceRecordingStatusInfo. init : Is initial status or not. recordingStatus : The recording status of device.
Usage:
PlatformSDK.pfDeviceStatusCallBack deviceStatusCB = new PlatformSDK.pfDeviceStatusCallBack(DeviceStatusCallBack); void DeviceStatusCallBack(IntPtr pStatusList, int statusNum, IntPtr context) { for (int i = 0; i < statusNum; ++i) { IntPtr pEventInfo = new IntPtr(pStatusList.ToInt64() + Marshal.SizeOf(typeof(TDeviceStatusInfo)) * i); TDeviceStatusInfo statusInfo = (TDeviceStatusInfo)Marshal.PtrToStructure(pEventInfo, typeof(TDeviceStatusInfo)); Console.WriteLine("Device ID: {0}, connection status: {1}, recording status: {2}" , statusInfo.deviceID , (int)statusInfo.connectionStatus , (int)statusInfo.recordingStatus ); } } void MonitorDeviceStatus(int loginID) { PlatformSDK.MonitorDeviceStatus(loginID, deviceStatusCB, IntPtr.Zero); }
Stop monitoring:
void StopMonitorDeviceStatus(int loginID) { PlatformSDK.MonitorDeviceStatus(loginID, null, IntPtr.Zero); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : callback function is null before monitor event (0x80700111) : tunnel is not connected (0x80700108) : tunnel send request failed
Method:
int PlatformSDK.MonitorAlarmNotification(int hLoginID, pfAlarmNotificationCallBack pfAlarmNotificationCB, IntPtr context)
Description:
Register a callback function to monitor alarm notification.
Related structure:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] delegate void pfAlarmNotificationCallBack(IntPtr pAlarmNotificationList, int alarmNotificationNum, IntPtr context);
pAlarmNotificationList : Pointer to the array of structure of type TAlarmNotification. alarmNotificationNum : The item number of pAlarmNotificationList. context : User passed information.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TAlarmNotification { public IntPtr content; public int contentLen; }
content : The content of alarm notification, which is a XML string. contentLen : The length of content.
Usage:
PlatformSDK.pfAlarmNotificationCallBack alarmNotificationCB = new PlatformSDK.pfAlarmNotificationCallBack(AlarmNotificationCallBack); void AlarmNotificationCallBack(IntPtr pAlarmNotificationList, int alarmNotificationNum, IntPtr context) { for (int i = 0; i < alarmNotificationNum; ++i) { IntPtr pAlarmInfo = new IntPtr(pAlarmNotificationList.ToInt64() + Marshal.SizeOf(typeof(TAlarmNotification)) * i); TAlarmNotification alarmInfo = (TAlarmNotification)Marshal.PtrToStructure(pAlarmInfo, typeof(TAlarmNotification)); string str = Marshal.PtrToStringAnsi(alarmInfo.content); Console.WriteLine("Receive alarm notification: " + "len = " + alarmInfo.contentLen + ", context = " + str ); } } void TestMonitorAlarmNotification() { PlatformSDK.MonitorAlarmNotification(loginID, alarmNotificationCB, IntPtr.Zero); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80700111) : tunnel is not connected (0x80700108) : tunnel send request failed
Description:
Register a callback function to monitor event. It parses event XML information and store event information in the structure TEventInfo. If you no longer want to monitor events, you could set NULL to the eventCB field.
Remark:
Support multi-thread execution only if hLoginID is different in each thread.
Method:
int PlatformSDK.MonitorEvent(int hLoginID, pfEventCallBack eventCB, IntPtr context)
Parameters:
hLoginID : Login ID. eventCB : The call back function is used to receive event notification, set NULL will stop monitoring. context : You can set any data into this field, and it will bring it back when you receive the event notification.
Related structure:
enum EDeviceType : uint { unknown, camera, externalDevice, station, cmsStation, } enum EEventType : uint { unknown, DI, DO, motion, PIR, tampering, videoLoss, fanStatus, storageConn, //Is the storage available for recording. storageCap, //Is there enough free space on storage for recording. } public struct TEventInfo { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string deviceID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_EVENT_TIME_LEN + 1)] public string time; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_EVENT_ARGS_LEN + 1)] public string args; public EDeviceType deviceType; public EEventType eventType; public byte init; public byte trigger; public int index; }
deviceID : Device ID. time : Event trigger time. When the trigger device is Camera, it's camera time. The others is server time. args : Extra information. In motion event the value is percent, in videoLoss event the value is a description string. deviceType : Device type. eventType : Event type. init : Mark if it is a initialized event: 0 for normal event, 1 for initialized event. trigger : Defined in Event Structure Definition.html index : The index value of DI, DO, Motion, and PIR event.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TEventListInfo { public IntPtr pEventList; //pointer to array of TEventInfo public uint eventNum; public IntPtr rawContent; public uint rawContentLen; public IntPtr context; }
pEventList : Pointer to the array of TEventInfo. eventNum : The number of pEventList. rawContent : The raw event data, in XML format. rawContentLen: The length of raw event data. context : User passed information.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfEventCallBack(IntPtr pEventListInfo);
pEventListInfo : Pointer to the structure of TEventListInfo.
Usage:
PlatformSDK.pfEventCallBack eventCB = new PlatformSDK.pfEventCallBack(EventCallBack); void EventCallBack(IntPtr pEventListInfo) { TEventListInfo info = (TEventListInfo)Marshal.PtrToStructure(pEventListInfo, typeof(TEventListInfo)); for (uint i = 0; i < info.eventNum; ++i) { IntPtr pEventInfo = new IntPtr(info.pEventList.ToInt64() + Marshal.SizeOf(typeof(TEventInfo)) * i); TEventInfo eventInfo = (TEventInfo)Marshal.PtrToStructure(pEventInfo, typeof(TEventInfo)); Console.WriteLine("device ID = " + eventInfo.deviceID + ", event type = " + eventInfo.eventType); } } void MonitorEvent() { PlatformSDK.MonitorEvent(loginID, eventCB, IntPtr.Zero); }
void StopMonitorEvent() { PlatformSDK.MonitorEvent(loginID, null, IntPtr.Zero); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : callback function is null before monitor event (0x80700111) : tunnel is not connected (0x80700108) : tunnel send request failed
Description:
Create a channel to export the video of indicated time range, the callback function pfExportCallBack will be invoked when exoprt fail or finish. User must call PlatformSDK.DeleteExportMediaFileChannel to release the channel resource when export finish.
Remark:
Support multi-thread execution.
Method:
int PlatformSDK.CreateExportMediaFileChannel(ref int phChannel, ref TExportFileInfo tExportFileInfo)
Parameters:
phChannel : Pointer to channel ID. tExportFileInfo : Export option.
Related structure:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public unsafe delegate void pfExportCallBack(int iResult, IntPtr context);
iResult : Return value: zero for success, non-zero for error code. context : User passed information.
enum EMediaType : int { e3gp = 0 } [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TExportFileInfo { public EMediaType mediaType; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_IPHOST_LEN + 1)] public string serverIP; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_USERNAME_LEN + 1)] public string serverUserName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HEXPWD_LEN + 1)] public string serverPassword; public int serverPort; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string substationID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string cameraID; public short streamIndex; public int startTime; public int endTime; public IntPtr context; public string exportDir; public string exportFilename; public pfStreamStatusCallBack pfExportStatusCB; public pfExportInfoCallBack pfExportInfoCB; public bool useSSL; public int rateLimit; }
mediaType : The format of media file: 3GP. serverIP : Server IP. serverUserName : Server user account. serverPassword : Server user password. serverPort : Server port. substationID : substation ID, used for export video of substation. cameraID : camera ID. streamIndex : camera stream index, start from 1. startTime : Export start time, in seconds since Jan 1 1970 00:00:00. endTime : Export end time, in seconds since Jan 1 1970 00:00:00. context : User passed information. exportDir : Output directory. exportFilename : Output fine name. pfExportStatusCB: Callback function, used to notify the export finish message. pfExportInfoCB : callback function to notify export progress. useSSL : Streaming over SSL. rateLimit : Bandwidth limitation, the unit is bps
Usage1 (not set pfExportInfoCB):
PlatformSDK.pfExportCallBack exportStatusCB = new PlatformSDK.pfExportStatusCB(ExportStatusCallBack); delegate void HandleDeleteExportChannelDelegate(int channel); event HandleDeleteExportChannelDelegate deleteExportChannelEvent += new HandleDeleteExportChannelDelegate(HandleDeleteExportChannel); void HandleDeleteExportChannel(int channel) { PlatformSDK.DeleteExportMediaFileChannel(ref channel); } unsafe void ExportStatusCallBack(int iResult, IntPtr context) { TStreamStatusInfo info = (TStreamStatusInfo)Marshal.PtrToStructure(pStatusInfo, typeof(TStreamStatusInfo)); string str = Marshal.PtrToStringAnsi(info.context); Console.WriteLine("StreamStatusCallBack: hChannel = {0:X}, Status = {1}, {2}", info.hChannel, info.status, str); if (info.status == PlatformSDK.EStreamStatus.exportFinish) { Marshal.FreeHGlobal(info.context); Task.Factory.StartNew(() => deleteExportChannelEvent(info.hChannel)); } } void TestExportFile(string serverIP, string serverUserName, string serverPassword, int serverPort) { TimeSpan nowSeconds = (DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1)); int stime = (int)((nowSeconds - TimeSpan.FromSeconds(5)).TotalSeconds); int etime = (int)((nowSeconds - TimeSpan.FromSeconds(10)).TotalSeconds); string cam = "C_1"; string dir = "D:\\ExportTest"; string file = "test.3gp"; int phChannel = 0; TExportFileInfo tExportInfo = new TExportFileInfo(); tExportInfo.startTime = stime; tExportInfo.endTime = etime; tExportInfo.serverIP = serverIP; tExportInfo.serverUserName = serverUserName; tExportInfo.serverPassword = serverPassword; tExportInfo.serverPort = serverPort; tExportInfo.mediaType = PlatformSDK.EMediaType.e3gp; tExportInfo.cameraID = cam; tExportInfo.substationID = ""; tExportInfo.streamIndex = 1; tExportInfo.exportDir = dir; tExportInfo.exportFilename = file; tExportInfo.context = Marshal.StringToHGlobalAnsi(cam); tExportInfo.pfExportStatusCB = exportStatusCB; tExportInfo.pfExportInfoCB = null; tExportInfo.useSSL = false; PlatformSDK.CreateExportMediaFileChannel(ref phChannel, ref tExportInfo); }
Usage2 (set pfExportInfoCB):
System.Timers.Timer loopUpdateExportingProgress = new System.Timers.Timer(1000); //set loopUpdateExportingProgress: loopUpdateExportingProgress.Elapsed += new System.Timers.ElapsedEventHandler(LoopUpdateExportingProgress); loopUpdateExportingProgress.AutoReset = true; loopUpdateExportingProgress.Enabled = false; PlatformSDK.pfExportCallBack exportStatusCB = new PlatformSDK.pfExportStatusCB(ExportStatusCallBack); PlatformSDK.pfExportInfoCallBack exportInfoCB = new PlatformSDK.pfExportInfoCallBack(ExportInfoCallBack); delegate void HandleDeleteExportChannelDelegate(int channel); event HandleDeleteExportChannelDelegate deleteExportChannelEvent += new HandleDeleteExportChannelDelegate(HandleDeleteExportChannel); void HandleDeleteExportChannel(int channel) { loopUpdateExportingProgress.Enabled = false; PlatformSDK.DeleteExportMediaFileChannel(ref channel); } unsafe void ExportStatusCallBack(IntPtr pStatusInfo) { TStreamStatusInfo info = (TStreamStatusInfo)Marshal.PtrToStructure(pStatusInfo, typeof(TStreamStatusInfo)); string str = Marshal.PtrToStringAnsi(info.context); Console.WriteLine("StreamStatusCallBack: hChannel = {0:X}, Status = {1}, {2}", info.hChannel, info.status, str); if (info.status == PlatformSDK.EStreamStatus.exportFinish) { newExportingProgress = 100; Marshal.FreeHGlobal(info.context); Task.Factory.StartNew(() => deleteExportChannelEvent(info.hChannel)); } } void LoopUpdateExportingProgress(object source, System.Timers.ElapsedEventArgs e) { Console.WriteLine("Exporting Progress = " + newExportingProgress + " %"); } unsafe void ExportInfoCallBack(IntPtr pExportInf) { TStreamStatusInfo info = (TStreamStatusInfo)Marshal.PtrToStructure(pStatusInfo, typeof(TStreamStatusInfo)); string str = Marshal.PtrToStringAnsi(info.context); Console.WriteLine("StreamStatusCallBack: hChannel = {0:X}, Status = {1}, {2}", info.hChannel, info.status, str); if (info.status == PlatformSDK.EStreamStatus.exportFinish) { Marshal.FreeHGlobal(info.context); Task.Factory.StartNew(() => deleteExportChannelEvent(info.hChannel)); } } void TestExportFile(string serverIP, string serverUserName, string serverPassword, int serverPort) { TimeSpan nowSeconds = (DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1)); int stime = (int)((nowSeconds - TimeSpan.FromSeconds(5)).TotalSeconds); int etime = (int)((nowSeconds - TimeSpan.FromSeconds(10)).TotalSeconds); string cam = "C_1"; string dir = "D:\\ExportTest"; string file = "test.3gp"; int phChannel = 0; TExportFileInfo tExportInfo = new TExportFileInfo(); tExportInfo.startTime = stime; tExportInfo.endTime = etime; tExportInfo.serverIP = serverIP; tExportInfo.serverUserName = serverUserName; tExportInfo.serverPassword = serverPassword; tExportInfo.serverPort = serverPort; tExportInfo.mediaType = PlatformSDK.EMediaType.e3gp; tExportInfo.cameraID = cam; tExportInfo.substationID = ""; tExportInfo.streamIndex = 1; tExportInfo.exportDir = dir; tExportInfo.exportFilename = file; tExportInfo.context = Marshal.StringToHGlobalAnsi(cam); tExportInfo.pfExportStatusCB = exportStatusCB; tExportInfo.pfExportInfoCB = null; tExportInfo.useSSL = false; PlatformSDK.CreateExportMediaFileChannel(ref phChannel, ref tExportInfo); loopUpdateExportingProgress.Enabled = true; }
Error codes:
(0x80000003) : Parameter phChannel is invalid (0x8070021B) : Create channel failed
Description:
Delete the channel of exporting media file. We cannot call DeleteExportMediaFile in the callback function which set by CreateExportMediaFile, otherwise, deadlock might ensue. DeleteExportMediaFile must be called in the different thread from the export callback function.
Remark:
Support multi-thread execution.
Method:
int PlatformSDK.DeleteExportMediaFileChannel(ref int phChannel)
Parameters:
phChannel: Pointer to channel ID.
Usage:
Please see CreateExportMediaFileChannel.
Error codes:
(0x80000001) : Parameter phChannel is invalid (0x8070020B) : Previous deleteChannel does not finished (0x80700201) : Channel is invalid (0x80700207) : Fail to wait decode finish event. (0x8070020E) : Fail to wait AVCallback finish event.
Description:
Set the DO value on the indicated device.
Remark:
Support multi-thread execution only if hLoginID is different in each thread.
Method:
int PlatformSDK.SetDO(int hLoginID, IntPtr deviceID, int index, int value)
Parameters:
hLoginID : Login ID. deviceID : Device ID. index : DO index, starts from 1. value : 1 = trigger, 0 = normal.
Usage:
IntPtr pDeviceID = Marshal.StringToHGlobalAnsi("C_1"); PlatformSDK.SetDO(loginID, pDeviceID, 1, 1); Marshal.FreeHGlobal(pDeviceID);
Error codes:
(0x80000001) : Parameter phLoginID is invalid (0x80000003) : Parameter deviceID is empty or null (0x80700108) : tunnel send request failed
Description:
Set the DO value on the indicated NVR.
Remark:
Support multi-thread execution only if hLoginID is different in each thread.
Method:
int PlatformSDK.SetNVRDO(int hLoginID, int index, int value)
Parameters:
hLoginID : Login ID. index : DO index, starts from 1. value : 1 = trigger, 0 = normal.
Usage:
PlatformSDK.SetNVRDO(loginID, 1, 1);
Error codes:
(0x80000001) : Parameter phLoginID is invalid (0x80700108) : tunnel send request failed
Method:
int PlatformSDK.ClosePopupWindow(int hLoginID, int* camIDList, int camNum)
Description:
Close the popup windows of the indicated camera on LiveClient view cell and eMap. The API only works on VAST 1.9.4.0.
Parameters:
hLoginID : Login ID. camIDList : Camera ID value array. The camera ID value is the xxx value in camera ID "C_xxx". camNum : The number of elements in camIDList.
Usage:
int camID = 1; PlatformSDK.ClosePopupWindow(loginID, &camID, 1);
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter camIDList is invalid (0x80700108) : Tunnel send request failed (0x80700111) : Tunnel is not connected
Description:
Play live stream. User must call PlatformSDK.DeleteLiveChannel to release the channel resource if channel is no longer used.
Remark:
Support multi-thread execution.
Method:
int PlatformSDK.CreateLiveChannel(ref int phChannel, ref TStreamInfo streamInfo);
Parameters:
phChannel : The channel handle of live stream, used to delete, pause, start, and stop stream. streamInfo: Stream information.
Related structure:
enum EStreamSource : uint { VAST, CMS } public enum EStreamStatus : uint { ok, timeout, otherError, stopped, authFailed, exportFinish, badRequest, maxConnections, clientForbidden, cameraUnreachable, byePacket, exportError, } public enum EVideoDecodeType : uint { JPEG, BMP24, BMP32, YUV, YV12, } public enum EStreamTimeType : uint { recordingTime, cameraTime, } public enum ERawDataFormat : uint { RGB24, RGB32, YUV } public enum EStreamInitStatus : uint { play, pause, } public enum EHardwareAcceleration : uint { none, Nvidia_CUDA, Microsoft_DXVA2, Intel_QuickSync, } public enum EVideoDisplayMode : uint { fillViewCell, keepAspectRatio, } public enum ECapabilityVersion : uint { VAST, NVR, CMS, unknown, } public enum EPlaybackMode : uint { normal, download, synchronous, } public enum EStreamCodecType : uint { video_JPEG, video_H263, video_MP4, video_H264, video_Dummy, audio_G7221, audio_G729A, audio_AAC, audio_GAMR, audio_SAMR, audio_G711, audio_G711A, audio_G726, audio_Dummy, iva, metx, metj, unknown, }
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TStreamInfo { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_IPHOST_LEN + 1)] public string serverIP; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_USERNAME_LEN + 1)] public string serverUserName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HEXPWD_LEN + 1)] public string serverPassword; public int serverPort; public IntPtr hDisplayWindow; public EStreamSource streamSource; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string substationID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string szCameraID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_REFNAME_LEN + 1)] public string szCameraRefName; public short streamIndex; public uint startTime; public uint endTime; public IntPtr context; [MarshalAs(UnmanagedType.FunctionPtr)] public pfStreamDataCallBack pfStreamDataCB; [MarshalAs(UnmanagedType.FunctionPtr)] public pfYV12DataCallBack pfYV12DataCB; [MarshalAs(UnmanagedType.FunctionPtr)] public pfPCMDataCallBack pfPCMDataCB; [MarshalAs(UnmanagedType.FunctionPtr)] public pfVideoDecodeCallBack pfVideoDecodeCB; [MarshalAs(UnmanagedType.FunctionPtr)] public pfStreamStatusCallBack pfStreamStatusCB; public EVideoDecodeType decodeType; public EStreamMode streamMode; public EStreamTimeType timeType; public EPlayDirection playDirection; public EStreamInitStatus streamInitStatus; public ETimeKind timeKind; public ECapabilityVersion capVersion; public bool useSSL; public EVideoDisplayMode videoDisplayMode; public EPlaybackMode playbackMode; public uint rateLimit; public uint iFrameOnlyInterval; [MarshalAs(UnmanagedType.FunctionPtr)] public pfRawDataCallBack pfRawDataCB; public ERawDataFormat rawDataFormat; }
serverIP : Server IP. serverUserName : Server user account. serverPassword : Server user password. serverPort : Server port. hDisplayWindow : The window handle for display, set IntPtr.Zero if no need to display. streamSource : Indicated the server type: EStreamSource.VAST or EStreamSource.CMS substationID : Substation ID. cameraID : Camera ID. cameraRefName : Camera reference name. The name will show on view panel if be given. streamIndex : Stream index, starts from 1. startTime : Start time, in seconds since Jan 1 1970 00:00:00, used for CreateNetFileChannel. endTime : End time, in seconds since Jan 1 1970 00:00:00, used for CreateNetFileChannel.(optional) context : User passed information. pfStreamDataCB : The callback function will be invoked if hDisplayWindow is not IntPtr.Zero. pfYV12DataCB : The callback function will be invoked in video stream if hDisplayWindow is given. pfPCMDataCB : The callback function will be invoked in audio stream if hDisplayWindow is given. pfVideoDecodeCB : The callback function will be invoked in video stream if hDisplayWindow is given. pfStreamStatusCB : Use to callback the stream status, ex: connected or disconnected. decodeType : Use for decode stream. Indicated the decode type. streamMode : Use normalStream to play stream. Use retrieveOneSnapshot to retrieve only the first frame. timeType : Use for blayback stream. Indicated the query time type: recording time or camera time. playDirection : Forward or backward. streamInitStatus : Initial play status. timeKind : Query playback stream by UTC time or local time. capVersion : Capability version. useSSL : Streaming over SSL. videoDisplayMode : The video display mode. playbackMode : Playback mode, used for CreateNetFileChannel. rateLimit : Unused iFrameOnlyInterval : The number of skipped intra frame, used for CreateNetFileChannel. (Assume that there are I-frames 0 1 2 3 4 5 6 and iframeonlyinterval=2, it will send I-Frame 0 3 6 means pick one and skip two) pfRawDataCB : The callback function will be invoked if hDisplayWindow set to IntPtr.Zero. rawDataFormat : Raw data format of the video stream
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TStreamDataInfo { public int hChannel; public Int width; public int height; public uint frameLocalTimeSecond; public uint frameLocalTimeMilSec; public IntPtr context; public uint frameUTCTimeSecond; public uint frameUTCTimeMilSec; public EStreamCodecType codecType; public uint bitRate; public uint frameSize; public bool dummyPacket; }
hChannel : Channel handle. width : The width of original frame height : The height of original frame frameLocalTimeSecond : Frame local time in seconds. frameLocalTimeMilSec : The millisecond of frame local time. context : User passed information frameUTCTimeSecond : Frame UTC time in seconds frameUTCTimeMilSec : The millisecond of frame UTC time. codecType : The codec type of streaming bitRate : The number of kbits that are conveyed or processed per second. frameSize : The size of a frame. It's unit in bytes. dummyPacket : This frame is dummy or not.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfStreamDataCallBack(IntPtr pStreamDataInfo);
pStreamDataInfo : Pointer to the structure of TStreamDataInfo.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfYV12DataCallBack(int hChannel, IntPtr pBuffer, uint bufferSize , int height, int width, int dataType, IntPtr context);
hChannel : Channel handle. pBuffer : Pointer to stream data. bufferSize : THe size of stream data. height : Image height. width : Image width. dataType : The pixel format, here the value is always 16, it is a enum value of EPIXELFORMAT in AvSynchronizer. context : User passed information.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfPCMDataCallBack(int hChannel, IntPtr pBuffer, uint bufferSize , uint samplingFreq, uint samplingSize, uint channelNum, IntPtr context);
hChannel : Channel handle. pBuffer : Pointer to stream data. bufferSize : THe size of stream data. samplingFreq : Sampling frequence. samplingSize : Unused. channelNum : The channel number of audio. context : User passed information.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfVideoDecodeCallBack(IntPtr pVideoDecodeInfo);
pVideoDecodeInfo pointer to the structure of TVideoDecodeInfo.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TVideoDecodeInfo { public int hChannel; public IntPtr pBuffer; public int bufSize; public int height; public int width; public uint frameSecond; public uint frameMilSec; public IntPtr context; }
hChannel : Channel handle. pBuffer : The decoded image raw data bufSize : The byte size of image. height : Image height. width : Image width. frameSecond: Seconds of frame time. frameMilSec: Milliseconds of frame time. context : User passed information.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfStreamStatusCallBack(IntPtr pStatusInfo);
pStatusInfo pointer to the structure of TStreamStatusInfo.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TStreamStatusInfo { public int hChannel; public EStreamStatus status; public IntPtr context; }
hChannel : Channel handle. status : The status of stream connection. Please reference: Streaming error status context : User passed information.
Usage for playing stream and dealing with camera disconnected:(For more detailed information, please refer to sample code)
public class ViewCell : Form { PlatformSDK.pfStreamStatusCallBack streamStatusCB = new PlatformSDK.pfStreamStatusCallBack(StreamStatusCallBack); public void StreamStatusCallBack(IntPtr pStatusInfo) { TStreamStatusInfo info = (TStreamStatusInfo)Marshal.PtrToStructure(pStatusInfo, typeof(TStreamStatusInfo)); EventLog.Write("StreamStatusCallBack: hChannel = {0:X}, Status = {1}", info.hChannel, info.status); this.Invoke((MethodInvoker)delegate () { if (info.status == PlatformSDK.EStreamStatus.stopped) { DisconnectPanel.Visible = true; ReconnectButton.Show(); } else { DisconnectPanel.Visible = false; ReconnectButton.Hide(); } }); } public void CreateLiveChannel(string serverIP, string serverUserName, string serverPassword, int serverPort, string cameraID) { TStreamInfo streamInfo = new TStreamInfo(); streamInfo.streamSource = PlatformSDK.EStreamSource.VAST; streamInfo.serverIP = serverIP; streamInfo.serverUserName = serverUserName; streamInfo.serverPassword = serverPassword; streamInfo.serverPort = serverPort; streamInfo.cameraID = cameraID; streamInfo.pfStreamDataCB = null; streamInfo.pfPCMDataCB = null; streamInfo.pfYV12DataCB = null; streamInfo.pfVideoDecodeCB = null; streamInfo.pfStreamStatusCB = streamStatusCB; streamInfo.hDisplayWindow = this.Handle; streamInfo.streamMode = PlatformSDK.EStreamMode.noramlStream; streamInfo.useSSL = false; streamInfo.videoDisplayMode = PlatformSDK.EVideoDisplayMode.fillViewCell; PlatformSDK.CreateLiveChannel(ref hChannel, ref streamInfo); } }
Usage for video decode:
public class ViewCell : Form { void VideoDecodeCallBack(IntPtr pVideoDecodeInfo) { TVideoDecodeInfo info = (TVideoDecodeInfo)Marshal.PtrToStructure(pVideoDecodeInfo, typeof(TVideoDecodeInfo)); System.DateTime time = new System.DateTime(1970, 1, 1).AddSeconds(info.frameSecond); Console.WriteLine("VideoDecodeCallBack: hChannel = {0:X}, time = {1:G}, {2} x {3}" , info.hChannel, time, info.width, info.height); } public void CreateLiveChannel(string serverIP, string serverUserName, string serverPassword, int serverPort, string cameraID) { TStreamInfo streamInfo = new TStreamInfo(); streamInfo.streamSource = PlatformSDK.EStreamSource.VAST; streamInfo.serverIP = serverIP; streamInfo.serverUserName = serverUserName; streamInfo.serverPassword = serverPassword; streamInfo.serverPort = serverPort; streamInfo.cameraID = cameraID; streamInfo.pfStreamDataCB = null; streamInfo.pfPCMDataCB = null; streamInfo.pfYV12DataCB = null; streamInfo.pfVideoDecodeCB = VideoDecodeCB; streamInfo.pfStreamStatusCB = null; streamInfo.decodeType = PlatformSDK.EVideoDecodeType.JPEG; streamInfo.hDisplayWindow = this.Handle; streamInfo.streamMode = PlatformSDK.EStreamMode.retrieveOneSnapshot; streamInfo.useSSL = false; streamInfo.videoDisplayMode = PlatformSDK.EVideoDisplayMode.fillViewCell; PlatformSDK.CreateLiveChannel(ref hChannel, ref streamInfo); } }
Render without display window:
public class ViewCell : Form { PlatformSDK.pfRawDataCallBack rawDataCallBack = new PlatformSDK.pfRawDataCallBack(RawDataCallBack); public void RawDataCallBack(int hChannel, IntPtr pBuffer, uint bufferSize, int height, int width, uint frameSecond, uint frameMSec) { if (pBuffer == IntPtr.Zero) { return; } EventLog.Write("RawDataCallBack Ret = {0} {1} {2} {3} time:{4}.{5}", hChannel, bufferSize, height, width, frameSecond, frameMSec); } public void CreateLiveChannel(string serverIP, string serverUserName, string serverPassword, int serverPort, string cameraID) { TStreamInfo streamInfo = new TStreamInfo(); streamInfo.streamSource = PlatformSDK.EStreamSource.VAST; streamInfo.serverIP = serverIP; streamInfo.serverUserName = serverUserName; streamInfo.serverPassword = serverPassword; streamInfo.serverPort = serverPort; streamInfo.cameraID = cameraID; streamInfo.pfRawDataCB = rawDataCallBack; streamInfo.hDisplayWindow = IntPtr.Zero; streamInfo.rawDataFormat = PlatformSDK.ERawDataFormat.RGB24; streamInfo.streamMode = PlatformSDK.EStreamMode.noramlStream; streamInfo.useSSL = false; PlatformSDK.CreateLiveChannel(ref hChannel, ref streamInfo); } }
Error codes:
(0x80000003) : Parameter phChannel or ptStreamInfo is invalid (0x8070020F) : Camera ID is invalid (0x8070020C) : Previous display window handle not released (0x80700204) : Channel connection is already exist (0x80700201) : Create channel failed (0x80700212) : Start channel failed
When the camera disconnect, it will callback EStreamStatus.stopped. When using the incorrect username/password in streaming information, it will callback EStreamStatus.authFailed. When using the incorrect camera Id or stream index, it will callback EStreamStatus.badRequest. When the number of streaming connections reach limitation, it will callback EStreamStatus.maxConnections. When the user has no permission to view the streaming, it will callback EStreamStatus.clientForbidden. When the camera is unreachable, it will callback EStreamStatus.cameraUnreachable.
Description:
Delete the live channel.
Remark:
Support multi-thread execution.
Method:
int PlatformSDK.DeleteLiveChannel(ref int phChannel)
Usage:
PlatformSDK.DeleteLiveChannel(ref hChannel);
Error codes:
(0x80000001) : Parameter phChannel is invalid (0x8070020B) : Previous deleteChannel does not finished (0x80700201) : Channel is invalid
Description:
Playback the indicated time range of recording data. User must call PlatformSDK.DeleteNetFileChannel to release the channel resource if channel is no longer used.
Remark:
Support multi-thread execution.
Method:
int PlatformSDK.CreateNetFileChannel(ref int phChannel, ref TStreamInfo streamInfo)
Related structure:
Please reference: PlatformSDK.CreateLiveChannel
Usage: (For more detailed information, please refer to sample code)
public class ViewCell : Form { PlatformSDK.pfStreamStatusCallBack streamStatusCB = new PlatformSDK.pfStreamStatusCallBack(StreamStatusCallBack); PlatformSDK.pfStreamDataCallBack streamDataCB = new PlatformSDK.pfStreamDataCallBack(StreamDataCallBack); public void StreamStatusCallBack(IntPtr pStatusInfo) { TStreamStatusInfo info = (TStreamStatusInfo)Marshal.PtrToStructure(pStatusInfo, typeof(TStreamStatusInfo)); EventLog.Write("StreamStatusCallBack: hChannel = {0:X}, Status = {1}", info.hChannel, info.status); this.Invoke((MethodInvoker)delegate () { if (info.status == PlatformSDK.EStreamStatus.stopped) { DisconnectPanel.Visible = true; ReconnectButton.Show(); } else { DisconnectPanel.Visible = false; ReconnectButton.Hide(); } }); } public void StreamDataCallBack(IntPtr pStreamDataInfo) { TStreamDataInfo info = (TStreamDataInfo)Marshal.PtrToStructure(pStreamDataInfo, typeof(TStreamDataInfo)); EventLog.Write("StreamDataCallBack codecType: {0}", info.codecType); try { this.Invoke((MethodInvoker)delegate () { var isDummyFrame = info.dummyPacket; dummyPanel.Visible = isDummyFrame; }); } catch (System.ObjectDisposedException) { EventLog.Write("ViewCell is disposed"); } catch (System.InvalidOperationException) { EventLog.Write("ViewCell is not created"); } } public void CreateNetFileChannel(string serverIP, string serverUserName, string serverPassword, int serverPort, string cameraID, uint startLocalTime, uint endLocalTime, short streamIndex) { TStreamInfo streamInfo = new TStreamInfo(); streamInfo.streamSource = PlatformSDK.EStreamSource.VAST; streamInfo.serverIP = serverIP; streamInfo.serverUserName = serverUserName; streamInfo.serverPassword = serverPassword; streamInfo.serverPort = serverPort; streamInfo.cameraID = cameraID; streamInfo.pfStreamDataCB = streamDataCB; streamInfo.pfPCMDataCB = null; streamInfo.pfYV12DataCB = null; streamInfo.hDisplayWindow = this.Handle; streamInfo.startTime = startLocalTime; streamInfo.endTime = endLocalTime; streamInfo.streamIndex = streamIndex; streamInfo.pfStreamStatusCB = streamStatusCB; streamInfo.streamInitStatus = PlatformSDK.EStreamInitStatus.play; streamInfo.timeKind = PlatformSDK.ETimeKind.local; streamInfo.timeType = PlatformSDK.EStreamTimeType.recordingTime; streamInfo.useSSL = false; streamInfo.videoDisplayMode = PlatformSDK.EVideoDisplayMode.fillViewCell; PlatformSDK.CreateNetFileChannel(ref hChannel, ref streamInfo); } }
Render without display window:
public class ViewCell : Form { PlatformSDK.pfRawDataCallBack rawDataCallBack = new PlatformSDK.pfRawDataCallBack(RawDataCallBack); public void RawDataCallBack(int hChannel, IntPtr pBuffer, uint bufferSize, int height, int width, uint frameSecond, uint frameMSec) { if (pBuffer == IntPtr.Zero) { return; } EventLog.Write("RawDataCallBack Ret = {0} {1} {2} {3} time:{4}.{5}", hChannel, bufferSize, height, width, frameSecond, frameMSec); } public void CreateNetFileChannel_RawData(string serverIP, string serverUserName, string serverPassword, int serverPort, string cameraID, uint startLocalTime, uint endLocalTime, short streamIndex) { TStreamInfo streamInfo = new TStreamInfo(); streamInfo.streamSource = PlatformSDK.EStreamSource.VAST; streamInfo.streamMode = PlatformSDK.EStreamMode.normalStream; streamInfo.timeType = PlatformSDK.ETimeType.recordingTime; streamInfo.serverIP = serverIP; streamInfo.serverUserName = serverUserName; streamInfo.serverPassword = serverPassword; streamInfo.serverPort = serverPort; streamInfo.cameraID = cameraID; streamInfo.hDisplayWindow = IntPtr.Zero; streamInfo.pfRawDataCB = rawDataCallBack; streamInfo.rawDataFormat = PlatformSDK.ERawDataFormat.RGB24; streamInfo.startTime = startLocalTime; streamInfo.endTime = endLocalTime; streamInfo.streamIndex = streamIndex; streamInfo.streamInitStatus = PlatformSDK.EStreamInitStatus.play; streamInfo.timeKind = PlatformSDK.ETimeKind.local; streamInfo.useSSL = false; PlatformSDK.CreateNetFileChannel(ref hChannel, ref streamInfo); } }
Error codes:
(0x80000003) : Parameter phChannel or ptStreamInfo is invalid (0x8070020C) : Previous display window handle not released (0x80700204) : Channel connection is already exist (0x80700201) : Create channel failed (0x80700212) : Start channel failed
Streaming error status:
When playback streaming disconnect, it will callback EStreamStatus.stopped. When using the incorrect username/password in streaming information, it will callback EStreamStatus.authFailed. When using the incorrect camera Id, it will callback EStreamStatus.badRequest. When the number of streaming connections reach limitation, it will callback EStreamStatus.maxConnections. When the user has no permission to view the streaming, it will callback EStreamStatus.clientForbidden. When playback to the end or end of file, it will callback EStreamStatus.byePacket.
Description:
Delete network file channel.
Remark:
Support multi-thread execution.
Method:
int PlatformSDK.DeleteNetFileChannel(ref int phChannel)
Usage:
PlatformSDK.DeleteNetFileChannel(ref hChannel);
Error codes:
(0x80000001) : Parameter phChannel is invalid (0x8070020B) : Previous deleteChannel does not finished (0x80700201) : Channel is invalid
Description:
Start digital zoom on existed channel
Method:
int PlatformSDK.StartDigitalZoom(int hChannel, ref TDigitalZoomInfo digitalZoomInfo)
Related structure:
public struct TDigitalZoomInfo { public int top; public int left; public int bottom; public int right; }
top : left top point of area you want to zoom left : left top point of area you want to zoom bottom : bottom right point of area you want to zoom right : bottom right point of area you want to zoom
Usage:
PlatformSDK.TDigitalZoomInfo digitalZoomInfo = new PlatformSDK.TDigitalZoomInfo(); digitalZoomInfo.top = 100; digitalZoomInfo.left = 100; digitalZoomInfo.bottom = 300; digitalZoomInfo.right = 300; PlatformSDK.StartDigitalZoom(hChannel, ref digitalZoomInfo);
Error codes:
(0x80000003) : Parameter hChannel or digitalZoomInfo is invalid (0x80700201) : Channel is invalid or is not connected (0x80400000) : Start digital zoom failed
Description:
Stop digital zoom on zoomed channel
Method:
int PlatformSDK.StopDigitalZoom(int hChannel)
Usage:
PlatformSDK.StopDigitalZoom(hChannel);
Error codes:
(0x80000003) : Parameter hChannel is invalid (0x80700201) : Channel is invalid or is not connected (0x80400000) : Stop digital zoom failed
Description:
Play stream.
Method:
int PlatformSDK.StartChannel(int hChannel)
Usage:
PlatformSDK.StartChannel(hChannel);
Error codes:
(0x80000001) : Parameter phChannel is invalid (0x80700201) : Channel is invalid (0x80700212) : Start channel failed
Description:
Stop stream.
Method:
int PlatformSDK.StopChannel(int hChannel)
Usage:
PlatformSDK.StopChannel(hChannel);
Error codes:
(0x80000001) : Parameter phChannel is invalid (0x8070020A) : Previous stopChannel does not finished (0x80700201) : Channel is invalid
Description:
Pause stream.
Method:
int PlatformSDK.PauseChannel(int hChannel)
Usage:
PlatformSDK.PauseChannel(hChannel);
Error codes:
(0x80000001) : Parameter phChannel is invalid (0x80700201) : Channel is invalid (0x80700213) : Pause channel failed
Description:
Create a group for synchronous playback.
Method:
int PlatformSDK.CreateSyncPlaybackGroup(ref int hPlaybackGroup)
Parameters:
hPlaybackGroup : The handle for synchronous playback.
Usage:
PlatformSDK.CreateSyncPlaybackGroup(ref hPlaybackGroup);
Error codes:
(0x80000001) : hPlaybackGroup is invalid (0x80700301) : fail to create synchronous playback group
Description:
Delete the synchronous playback group.
Method:
int PlatformSDK.DeleteSyncPlaybackGroup(ref int hPlaybackGroup)
Parameters:
hPlaybackGroup : The handle for synchronous playback.
Usage:
PlatformSDK.DeleteSyncPlaybackGroup(ref hPlaybackGroup);
Error codes:
(0x80000001) : hPlaybackGroup is invalid (0x80700302) : fail to delete synchronous playback group
Description:
Insert channel to a group for synchronous playback.
Method:
int PlatformSDK.InsertChannelToGroup(int hPlaybackGroup, int hChannel)
Parameters:
hPlaybackGroup : The handle for synchronous playback.
hChannel: The channel handle of stream.
Usage:
PlatformSDK.InsertChannelToGroup(hAvSyncPlaybackGroup, hChannel);
Error codes:
(0x80000001) : hPlaybackGroup, hChannel is invalid (0x80700303) : fail to insert chanel to synchronous playback group
Description:
Remove channel to a group for synchronous playback.
Method:
int PlatformSDK.RemoveChannelFromGroup(int hPlaybackGroup, int hChannel)
Parameters:
hPlaybackGroup : The handle for synchronous playback.
hChannel: The channel handle of stream.
Usage:
PlatformSDK.RemoveChannelFromGroup(hAvSyncPlaybackGroup, hChannel);
Error codes:
(0x80000001) : hPlaybackGroup, hChannel is invalid (0x80700304) : fail to remove channel to synchronous playback group
Description:
Start a synchronous playback group.
Method:
int PlatformSDK.StartSyncPlaybackGroup(int hPlaybackGroup, ref TSDKSyncPlaybackOption option)
Parameters:
hPlaybackGroup : The handle for synchronous playback group. option : The options for synchronous playback.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TSDKSyncPlaybackOption { public uint startTime; public uint endTime; [MarshalAs(UnmanagedType.FunctionPtr)] public pfSyncStatusCallback statusCB; public IntPtr statusContext; public ETimeKind timeKind; public uint startTimeMilSec; public uint endTimeMilSec; }
startTime : Start time, in seconds since Jan 1 1970 00:00:00. endTime : End time, in seconds since Jan 1 1970 00:00:00.(optional) pfSyncStatusCallback : The callback function will be invoked when streaming is finished. statusContext : User passed information. timeKind : Start synchronize playback by UTC time or local time. startTimeMilisec : Millisecond of start time. endTimeMilisec : Millisecond of end time.
Usage:
void TestStartSyncPlaybackGroup() { int hAvSyncPlaybackGroup = 0; PlatformSDK.CreateSyncPlaybackGroup(ref hAvSyncPlaybackGroup); int channel1 = 0; PlatformSDK.CreateNetFileChannel(ref channel1, ...) int channel2 = 0; PlatformSDK.CreateNetFileChannel(ref channel2, ...) PlatformSDK.InsertChannelToGroup(hAvSyncPlaybackGroup, channel1); PlatformSDK.InsertChannelToGroup(hAvSyncPlaybackGroup, channel2); var option = new PlatformSDK.TSDKSyncPlaybackOption(); option.startTime = 1574843651; //2019/11/27 08:34:11 option.endTime = 1574930051; //2019/11/28 08:34:11 option.statusCB = null; option.statusContext = IntPtr.Zero; PlatformSDK.StartSyncPlaybackGroup(hAvSyncPlaybackGroup, ref option); }
Error codes:
(0x80000001) : hPlaybackGroup is invalid (0x80000003) : option is invalid (0x80700305) : fail to start synchronous playback group
Description:
Stop a synchronous playback group.
Method:
int PlatformSDK.StopSyncPlaybackGroup(int hPlaybackGroup);
Parameters:
hPlaybackGroup : The handle for synchronous playback group.
Usage:
PlatformSDK.StopSyncPlaybackGroup(hAvSyncPlaybackGroup);
Error codes:
(0x80000001) : hPlaybackGroup is invalid (0x80700306) : fail to stop synchronous playback group
Description:
Pause a synchronous playback group.
Method:
int PlatformSDK.SyncPause(int hPlaybackGroup)
Parameters:
hPlaybackGroup : The handle for synchronous playback.
Usage:
void TestSyncPause() { int hAvSyncPlaybackGroup = 0; PlatformSDK.CreateSyncPlaybackGroup(ref hAvSyncPlaybackGroup); int channel1 = 0; PlatformSDK.CreateNetFileChannel(ref channel1, ...) int channel2 = 0; PlatformSDK.CreateNetFileChannel(ref channel2, ...) PlatformSDK.InsertChannelToGroup(hAvSyncPlaybackGroup, channel1); PlatformSDK.InsertChannelToGroup(hAvSyncPlaybackGroup, channel2); PlatformSDK.StartSyncPlaybackGroup(hAvSyncPlaybackGroup, ...); PlatformSDK.SyncPause(hAvSyncPlaybackGroup); }
Error codes:
(0x80000001) : hPlaybackGroup is invalid (0x80700307) : fail to pause synchronous playback group
Description:
Resume a synchronous playback group.
Method:
int PlatformSDK.SyncResume(int hPlaybackGroup)
Parameters:
hPlaybackGroup : The handle for synchronous playback.
Usage:
void TestSyncResume() { int hPlaybackGroup = 0; PlatformSDK.CreateSyncPlaybackGroup(ref hPlaybackGroup); int channel1 = 0; PlatformSDK.CreateNetFileChannel(ref channel1, ...) int channel2 = 0; PlatformSDK.CreateNetFileChannel(ref channel2, ...) PlatformSDK.InsertChannelToGroup(hPlaybackGroup, channel1); PlatformSDK.InsertChannelToGroup(hPlaybackGroup, channel2); PlatformSDK.StartSyncPlaybackGroup(hPlaybackGroup, ...); PlatformSDK.SyncPause(hPlaybackGroup); PlatformSDK.SyncResume(hPlaybackGroup); }
Error codes:
(0x80000001) : hPlaybackGroup is invalid (0x80700308) : fail to resume synchronous playback group
Description:
Set a synchronous playback group to next frame.
Method:
int PlatformSDK.SyncNextFrame(int hPlaybackGroup)
Parameters:
hPlaybackGroup : The handle for synchronous playback.
Usage:
void TestSyncNextFrame() { int hPlaybackGroup = 0; PlatformSDK.CreateSyncPlaybackGroup(ref hPlaybackGroup); int channel1 = 0; PlatformSDK.CreateNetFileChannel(ref channel1, ...) int channel2 = 0; PlatformSDK.CreateNetFileChannel(ref channel2, ...) PlatformSDK.InsertChannelToGroup(hPlaybackGroup, channel1); PlatformSDK.InsertChannelToGroup(hPlaybackGroup, channel2); PlatformSDK.StartSyncPlaybackGroup(hPlaybackGroup, ...); PlatformSDK.SyncPause(hPlaybackGroup); PlatformSDK.SyncNextFrame(hPlaybackGroup); }
Error codes:
(0x80000001) : hPlaybackGroup is invalid (0x80700309) : fail to get next frame for synchronous playback group
Description:
Set a synchronous playback group to demand speed.
Method:
int PlatformSDK.ChangeSyncSpeed(int hPlaybackGroup, ref TSDKChannelList channelList, float speed, ref TPlaybackOption option);
Parameters:
hPlaybackGroup : The handle for synchronous playback group. channelList : The channels in synchronous playback group. speed : The speed for synchronous playback (from 0.125 to 64). option : The options for synchronous playback.
Usage:
void TestChangeSyncSpeed() { // Get Current Playback Time uint currentPlaybackSeconds = getCurrentPlaybackSeconds(); uint currentPlaybackMilisecs = getcurrentPlaybackMilisecs(); var option = new PlatformSDK.TPlaybackOption(); option.startTime = currentPlaybackSeconds; option.startTimeMilisec = currentPlaybackMilisecs; option.endTime = UtcDateTime2time_t(dateTimePickerEndTime.Value); option.endTimeMilisec = 0; var channelArray = channelHandles.ToArray(); IntPtr pChannelList = Marshal.AllocHGlobal(channelArray.Length * Marshal.SizeOf(typeof(int))); Marshal.Copy(channelArray, 0, pChannelList, channelArray.Length); var channelList = new PlatformSDK.TSDKChannelList(); channelList.dwChannelNum = (uint)channelHandles.Count; channelList.ptChannelList = pChannelList; var ret = PlatformSDK.ChangeSyncSpeed(syncPlaybackGroupHandle, ref channelList, speed, ref option); }
Error codes:
(0x80000001) : hPlaybackGroup is invalid (0x80000003) : channelList or option is invalid, or the speed is out of range (0x8070030A) : fail to set speed of synchronous playback group
Description:
Change the playback option at synchronous playback mode.
Method:
int UpdateSyncPlaybackOption(int hPlaybackGroup, ref TSDKChannelList channelList, ref TPlaybackOption option)
Parameters:
hPlaybackGroup : The handle for synchronous playback group. channelList : The channels in synchronous playback group. option : The options for synchronous playback.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TSDKChannelList { public uint dwChannelNum; public IntPtr ptChannelList; }
dwChannelNum : The number of elements in ptChannelList. ptChannelList : Channel handle value array.
enum EPlayDirection : uint { forward, backward, } [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TPlaybackOption { public uint startTime; public uint endTime; public EPlayDirection ePlayDirection; public uint startTimeMilisec; public uint endTimeMilisec; }
startTime : Start time, in seconds since Jan 1 1970 00:00:00. endTime : End time, in seconds since Jan 1 1970 00:00:00. playDirection : Forward or backward. startTimeMilisec : Millisecond of start time. endTimeMilisec : Millisecond of end time.
Usage:
static public void seek(uint startTime, uint endTime) { var syncOption = new PlatformSDK.TPlaybackOption(); syncOption.startTime = startTime; syncOption.endTime = endTime; int[] channelArray = { channel, channel2 }; IntPtr pChannelList = Marshal.AllocHGlobal(channelArray.Length * Marshal.SizeOf(typeof(int))); Marshal.Copy(channelArray, 0, pChannelList, channelArray.Length); var channelList = new PlatformSDK.TSDKChannelList(); channelList.dwChannelNum = (uint)channelArray.Length; channelList.ptChannelList = pChannelList; var ret = PlatformSDK.UpdateSyncPlaybackOption(hAvSyncPlaybackGroup, ref channelList, ref syncOption); EventLog.Write("PlatformSDK.UpdateSyncPlaybackOption Ret = {0:X}", ret); }
Error codes:
(0x80000001) : hPlaybackGroup is invalid (0x80000003) : channelList or option is invalid (0x8070030B) : fail to update synchronous playback option
Description:
Reconnect streaming when synchronous playback stopped.
Remark:
Support multi-thread execution.
Method:
int ReconnectSyncPlaybackChannel(int hPlaybackGroup, int hChannel, ref TPlaybackOption option)
Parameters:
hPlaybackGroup : The handle for synchronous playback group. hChannel : The channel for reconnect. option : The options for synchronous playback.
Related structure:
enum EPlayDirection : uint { forward, backward, } [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TPlaybackOption { public uint startTime; public uint endTime; public EPlayDirection ePlayDirection; public uint startTimeMilisec; public uint endTimeMilisec; }
startTime : Start time, in seconds since Jan 1 1970 00:00:00. endTime : End time, in seconds since Jan 1 1970 00:00:00. playDirection : Forward or backward. startTimeMilisec : Millisecond of start time. endTimeMilisec : Millisecond of end time.
Usage:
private int hAvSyncPlaybackGroup = 0; private int startTime = 0; private int endTime = 0; private int startTimeMilisec = 0; void TestStartSyncPlaybackGroup() { TStreamInfo streamInfo = new TStreamInfo(); ... streamInfo.pfStreamStatusCB = new PlatformSDK.pfStreamStatusCallBack(StreamStatusCallBack); streamInfo.pfStreamDataCB = new PlatformSDK.pfStreamDataCallBack(StreamDataCallBack); hAvSyncPlaybackGroup = 0; PlatformSDK.CreateSyncPlaybackGroup(ref hAvSyncPlaybackGroup); int channel1 = 0; PlatformSDK.CreateNetFileChannel(ref channel1, ref streamInfo) int channel2 = 0; PlatformSDK.CreateNetFileChannel(ref channel2, ref streamInfo) PlatformSDK.InsertChannelToGroup(hAvSyncPlaybackGroup, channel1); PlatformSDK.InsertChannelToGroup(hAvSyncPlaybackGroup, channel2); var option = new PlatformSDK.TSDKSyncPlaybackOption(); option.startTime = 1574843651; //2019/11/27 08:34:11 option.endTime = 1574930051; //2019/11/28 08:34:11 option.statusCB = null; option.statusContext = IntPtr.Zero; // Store time interval when initialized startTime = option.startTime; endTime = option.endTime; PlatformSDK.StartSyncPlaybackGroup(hAvSyncPlaybackGroup, ref option); } void StreamDataCallBack(IntPtr pStreamDataInfo) { TStreamDataInfo info = (TStreamDataInfo)Marshal.PtrToStructure(pStreamDataInfo, typeof(TStreamDataInfo)); // Update start time when frame updated startTime = info.frameUTCTimeSecond; startTimeMilisec = info.frameUTCTimeMilSec; } void StreamStatusCallBack(IntPtr pStatusInfo) { TStreamStatusInfo info = (TStreamStatusInfo)Marshal.PtrToStructure(pStatusInfo, typeof(TStreamStatusInfo)); if (info.status == PlatformSDK.EStreamStatus.stopped) { PlatformSDK.TPlaybackOption option = new PlatformSDK.TPlaybackOption(); option.startTime = frameUTCTimeSecond; option.endTime = endTime; var ret = PlatformSDK.ReconnectSyncPlaybackChannel(syncGroupHandler, info.hChannel, ref option); EventLog.Write("PlatformSDK.ReconnectSyncPlaybackChannel Ret = {0:X}", ret); // Recovery streaming status info.status = (ret == 0) ? PlatformSDK.EStreamStatus.ok : PlatformSDK.EStreamStatus.stopped; } }
Error codes:
(0x80000001) : hChannel or hPlaybackGroup is invalid (0x80000003) : option is invalid (0x8070030C) : fail to reconnect synchronous playback channel
Method:
int PlatformSDK.BlockedSetDO(int hLoginID, IntPtr deviceID, int index, int value, int timeoutMilSec)
Description:
Set the DO value on the indicated device in blocked mode. If DO is Successfully set in indicated timeout milliseconds, it returns 0, otherwise returns non-zero.
Parameters:
hLoginID : Login ID. deviceID : Device ID. index : DO index, starts from 1. value : 1 = trigger, 0 = normal. timeoutMilSec: Timeout milliseconds.
Usage:
IntPtr pDeviceID = Marshal.StringToHGlobalAnsi("C_1"); PlatformSDK.SetDO(loginID, pDeviceID, 1, 1, 3000); //trigger the DO-1 of C_1 Marshal.FreeHGlobal(pDeviceID);
Error codes:
(0x80000001) : hLoginID is invalid (0x80000003) : deviceID is empty or invalid (0x80700214) : set blocked DO failed
Method:
int PlatformSDK.Relogin(int hLoginID, EServerType serverType)
Description:
Relogin the indicated server.
Related structure:
public enum EServerType : uint { configServer, eventServer, queryServer, }
Parameters:
hLoginID : Login ID. serverType: Setver type.
Usage:
void ReloginEventServer(int loginID) { PlatformSDK.Relogin(loginID, EServerType.eventServer); }
Error codes:
(0x80000001) : hLoginID is invalid (0x80000003) : serverType is invalid (0x80700115) : Can not login config server (0x80700111) : Can not login event server (0x80700112) : Can not login query server
Method:
int PlatformSDK.GetRecordingDeviceList(int loginID, ref TDeviceListRequest request, ref TRecordingDeviceList deviceList)
Description:
Get recording device list.
Parameters:
loginID : Login ID. request : Pointer to request info. deviceList: Pointer to device list.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TDeviceListRequest { public int timeoutMillisecond; public string stationID; }
timeoutMillisecond: Milliseconds of timeout to retrieve the device list. stationID : Substation path, set NULL for main station.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TRecordingDeviceInfo { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string deviceID; //Camera (C_XXX) [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_REFNAME_LEN + 1)] public string refName; //device reference name [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_LOC_NAME_LEN + 1)] public string locationID; }
deviceID : Camera ID. refName : Camera reference name. locationID : Location ID.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TRecordingDeviceList { public IntPtr deviceList; public uint deviceNum; }
ptDeviceList : Pointer to device list (TRecordingDeviceInfo). dwDeviceNum : The number of device.
Usage:
void GetRecordingDeviceList(int loginID) { TDeviceListReqInfo request = new TDeviceListReqInfo(); TRecordingDeviceList deviceList = new TRecordingDeviceList(); request.stationID = null; request.timeoutMillisecond = 5000; PlatformSDK.GetRecordingDeviceList(loginID, ref request, ref deviceList); for (uint i = 0; i < deviceList.deviceNum; ++i) { IntPtr pDevice = new IntPtr(deviceList.deviceList.ToInt64() + Marshal.SizeOf(typeof(TRecordingDeviceInfo)) * i); TRecordingDeviceInfo device = (TRecordingDeviceInfo)Marshal.PtrToStructure(pDevice, typeof(TRecordingDeviceInfo)); Console.WriteLine(device.deviceID + ", " + device.refName.Substring(2) + ", " + device.locationID); } }
Error codes:
(0x80000001) : loginID is invalid (0x80000003) : request or deviceList is invalid (0x80700108) : tunnel send request failed (0x80700112) : Can not login query server
Description:
Get recording date list.
Method:
uint GetRecordingDateList(int hLoginID, ref TRecordingDateReqInfo request, ref TRecordingDateList dateList)
Parameters:
hLoginID : Login ID. request : Pointer to request info. dateList : Pointer to date list.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TRecordingDateReqInfo { public int timeoutMillisecond; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_LOC_NAME_LEN + 1)] public string locationID; public uint utcStartTimeSeconds; public uint utcEndTimeSeconds; }
timeoutMillisecond: Milliseconds of timeout to retrieve the device list. locationID : Location ID. uTCStartTimeSeconds: Seconds of UTC start time. uTCEndTimeSeconds : Seconds of UTC end time.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TRecordingDate { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_DATE_LEN + 1)] public string date; public int dayLightSavingSecond; }
date : Recording date string. dayLightSaving: Seconds of day light saving.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TRecordingDateList { public uint dateNum; public IntPtr dateList; }
dateList: Pointer to date list (TRecordingDate). dateNum : The number of date.
Precondition:
Use GetRecordingDeviceList to retrieve locationID from device list.
Usage:
void GetRecordingDateList(int loginID, string locationID) { TRecordingDateReqInfo request = new TRecordingDateReqInfo(); TRecordingDateList dateList = new TRecordingDateList(); request.locationID = locationID; request.timeoutMillisecond = 5000; request.utcStartTimeSeconds = 0; //1970-01-01 request.utcEndTimeSeconds = 2082758399; //2035-12-31 PlatformSDK.GetRecordingDateList(loginID, ref request, ref dateList); PlatformSDK.GetRecordingDateList Ret = {0:X}", ret); for (uint j = 0; j < dateList.dateNum; ++j) { IntPtr pDate = new IntPtr(dateList.dateList.ToInt64() + Marshal.SizeOf(typeof(TRecordingDate)) * j); TRecordingDate recDate = (TRecordingDate)Marshal.PtrToStructure(pDate, typeof(TRecordingDate)); Console.WriteLine(recDate.date); } }
Error codes:
(0x80000001) : hLoginID is invalid (0x80000003) : request or dateList is invalid (0x80700112) : tunnel is not connected (0x80700108) : tunnel send request failed
Description:
Get recording time list.
Method:
int GetRecordingTimeList(int hLoginID, ref TRecordingTimeReqInfo request, ref TRecordingTimeList timeList)
Remark:
Not support multi-thread execution.
Parameters:
hLoginID : Login ID. request : Pointer to request info. timeList : Pointer to time interval list.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TRecordingTimeReqInfo { public uint timeoutMillisecond; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_LOC_NAME_LEN + 1)] public string locationID; public uint utcStartTimeSeconds; public uint utcEndTimeSeconds; }
timeoutMillisecond : Milliseconds of timeout to retrieve the device list. locationID : Location ID. uTCStartTimeSeconds: Seconds of UTC start time. uTCEndTimeSeconds : Seconds of UTC end time.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TTimeInterval { public uint startSecond; public uint startMilSec; public int startDayLightSavingSecond; public int startTimeZoneSecond; public uint endSecond; public uint endMilSec; public int endDayLightSavingSecond; public int endTimeZoneSecond; }
startSecond : Seconds of UTC start time. startMilSec : Milliseconds of start time. startDayLightSavingSecond: Day light saving seconds of start time. startTimeZoneSecond : Time zone seconds of start time. endSecond : Seconds of UTC end time. endMilSec : Milliseconds of end time. endDayLightSavingSecond : Day light saving seconds of end time. endTimeZoneSecond : Time zone seconds of end time.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TRecordingTime { public TTimeInterval tServerTime; public TTimeInterval tCameraTime; }
tServerTime: Server time. tCameraTime: Camera time.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TRecordingTimeList { public IntPtr timeList; public uint timeNum; }
timeList: Pointer to time intervallist (TRecordingTime). timeNum : The number of time interval.
Usage:
void GetRecordingTimeList(int loginID, string locationID, uint utcStartTimeSeconds, uint utcEndTimeSeconds) { TRecordingTimeReqInfo request = new TRecordingTimeReqInfo(); TRecordingTimeList timeList = new TRecordingTimeList(); request.utcStartTimeSeconds = utcStartTimeSeconds; request.utcEndTimeSeconds = utcEndTimeSeconds; request.locationID = locationID; request.timeoutMillisecond = 5000; PlatformSDK.GetRecordingTimeList(loginID, ref request, ref timeList); for (uint i = 0; i < recTimeList.timeNum; ++i) { IntPtr pTime = new IntPtr(recTimeList.timeList.ToInt64() + Marshal.SizeOf(typeof(TRecordingTime)) * i); TRecordingTime timeInfo = (TRecordingTime)Marshal.PtrToStructure(pTime, typeof(TRecordingTime)); long startLocalSeconds = timeInfo.tServerTime.startSecond + timeInfo.tServerTime.startTimeZoneSecond + timeInfo.tServerTime.startDayLightSavingSecond; long endLocalSeconds = timeInfo.tServerTime.endSecond + timeInfo.tServerTime.endTimeZoneSecond + timeInfo.tServerTime.endDayLightSavingSecond; DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(startLocalSeconds); DateTime endDate = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(endLocalSeconds); Console.WriteLine(startDate.ToString("yyyy-MM-dd HH:mm:ss") + " ~ " + endDate.ToString("yyyy-MM-dd HH:mm:ss")); } }
Error codes:
(0x80000001) : hLoginID is invalid (0x80000003) : request or timeList is invalid (0x80700112) : tunnel is not connected (0x80700108) : tunnel send request failed
Method:
int GetRecordingGroup(int hLoginID, ref TRecordingGroupReqInfo request, ref TRecordingGroupList recGroupList)
Description:
Get recording group information.
Parameters:
hLoginID : Login ID. request : Pointer to request info. recGroupList: Pointer to recording group list.
Related structure:
struct TRecordingGroupReqInfo { public uint timeoutMillisecond; public string stationID; }
timeoutMillisecond: Milliseconds of timeout to retrieve the group list. stationID : Pointer to substation, set NULL for main station.
enum ERecordingPathType : uint { unknown, local, networkDomain, networkHost, }
unknown : Unknown storage. local : Local storage. networkDomain: Describe storage by a network domain name. networkHost : Describe storage by a network host.
struct TRecordingGroupPathInfo { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_REC_PATH_LEN + 1)] public string path; public bool bConnected; public uint reserveSpace; public ERecordingPathType type; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_IPHOST_LEN + 1)] public string hostDomain; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_USERNAME_LEN + 1)] public string hostUsername; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HEXPWD_LEN + 1)] public string hostPassword; }
path : Recording path. connected : If the path can be connected to access. reserveSpace: The reserve size of path. It's unit in mega-bytes. recordingType: The enumeration value of ESDKRecordingType. hostDomain : The host domain name, used for network recording type. hostUser : The user name, used for network recording type. hostPassword: The password, used for network recording type.
struct TRecordingGroupDeviceInfo { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string deviceID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_REFNAME_LEN + 1)] public string refName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_LOC_NAME_LEN + 1)] public string locationID; public uint streamIndex; public uint preEventSecond; public uint postEventSecond; public bool enableTimeShift; public bool enableSeamless; public bool enableKeyFrameOnly; }
deviceID : Device ID, "C_XXX" means camera device. refName : The reference name of device. locationID : Location ID, in format of "LocXXX". streamIndex : Stream index, start from 1. preEventSecond : The pre-event seconds. postEventSecond : The post-event seconds. enableTimeShift : If enable time shift recording. enableSeamless : If enable seamless recording. enableKeyFrameOnly : If enable key frame only.
struct TRecordingGroup { public uint groupID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_REC_GROUP_NAME_LEN + 1)] public string groupName; public IntPtr pathList; public uint pathNum; public IntPtr deviceList; public uint deviceNum; public bool enableTimeBaseCycle; public uint reserveCycleMinute; }
groupID : The unique ID of recording group. groupName : The group name. pathList : Recording path list, pointer to TRecordingGroupPathInfo. pathNum : The number of recording path. deviceList : Recording device list, pointer to TRecordingGroupDeviceInfo. deviceNum : The number of device. enableTimeBaseCycle: If enable time-base cycle. reserveCycleMinute : The reserve cycle time, in unit of minute.
struct TRecordingGroupList { public IntPtr groupList; public uint groupNum; }
ptRecGroup : Recording group list, pointer to TRecordingGroup. dwGroupNum : The number of recording group.
Usage:
using TRecordingGroupPathInfo = PlatformSDK.TRecordingGroupPathInfo; using TRecordingGroupDeviceInfo = PlatformSDK.TRecordingGroupDeviceInfo; public void GetRecordingGroupList(int loginID, int mainUILoginID) { loginID = mainUILoginID; TRecordingGroupReqInfo request = new TRecordingGroupReqInfo(); TRecordingGroupList groupList = new TRecordingGroupList(); request.stationID = null; request.timeoutMillisecond = 3000; PlatformSDK.GetRecordingGroup(loginID, ref request, ref groupList); for (uint i = 0; i < groupList.groupNum; ++i) { IntPtr pGroup = new IntPtr(groupList.groupList.ToInt64() + Marshal.SizeOf(typeof(TRecordingGroup)) * i); TRecordingGroup group = (TRecordingGroup)Marshal.PtrToStructure(pGroup, typeof(TRecordingGroup)); Console.WriteLine("Group name:" + group.groupName); for (uint j = 0; j < group.pathNum; ++j) { IntPtr pPath = new IntPtr(group.pathList.ToInt64() + Marshal.SizeOf(typeof(TRecordingGroupPathInfo)) * j); TRecordingGroupPathInfo path = (TRecordingGroupPathInfo)Marshal.PtrToStructure(pPath, typeof(TRecordingGroupPathInfo)); Console.WriteLine(" Path: " + path.path + " (" + path.reserveSpace + " MB)"); } for (uint j = 0; j < group.deviceNum; ++j) { IntPtr pDevice = new IntPtr(group.deviceList.ToInt64() + Marshal.SizeOf(typeof(TRecordingGroupDeviceInfo)) * j); TRecordingGroupDeviceInfo device = (TRecordingGroupDeviceInfo)Marshal.PtrToStructure(pDevice, typeof(TRecordingGroupDeviceInfo)); Console.WriteLine(" Camera: " + device.refName.Substring(2) + " (" + device.deviceID + ")"); } } }
Error codes:
(0x80000001) : hLoginID is invalid (0x80000003) : request or recGroupList is invalid (0x80700108) : tunnel send request failed
Method:
int GetCameraStatus(int hLoginID, ref TGetCameraStatusReqInfo request, ref TCameraStatusList statusList)
Description:
Get camera connection status and recording status.
Parameters:
hLoginID : Login ID. request : Pointer to request info. statusList: Pointer to camera status list.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TGetCameraStatusReqInfo { public bool getAllCameraStatus; public string cameraID; public uint timeoutMillisecond; };
getAllCameraStatus: Set TRUE to get status of all camera, set FALSE to get camera status by pszCameraID. cameraID : Camera ID (C_XXX). timeoutMillisecond: Milliseconds of timeout to retrieve camera status.
enum ERecordingState : uint { none, scheduled, manual, byEvent, continuous, unknown, };
Indicate each recording state.
enum ESeamlessState : uint { notRecovering, recoveringMedia, recoveringEvent, };
notRecovering : Not in seamless recovering mode. recoveringMedia: Recovering seamless media from camera. recoveringEvent: Recovering seamless event from camera.
enum EConnectionStatus : uint { unknown, connected, disconnected, receiveHeartBeat, heartBeatLost, heartBeatLostRetry, };
enum ERecordingStatus : uint { stop, start, }
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TDeviceRecordingStatusInfo { public ERecordingState deviceRecordingState; public ERecordingState groupRecordingState; public uint groupID; public ESeamlessState seamlessState; }
deviceRecordingState: Recording state of device groupRecordingState : Recording state of group. groupID : Group ID. seamlessState : Seamesss state.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TDeviceStatusInfo { public EDeviceType deviceType; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string deviceID; public EDeviceConnectionStatus connectionStatus; public IntPtr recordingStatusInfo; public bool init; public ERecordingStatus recordingStatus; }
deviceType : The device type. deviceID : The device ID. connectionStatus : The connection status of device. recordingStatusInfo: If the value is not IntPtr.Zero, it pointer to TDeviceRecordingStatusInfo. init : Is initial status or not. recordingStatus : The recording status of device.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TSDKCameraStatusList { IntPtr statusList; uint statusNum; };
statusList: Device status list, pointer to TDeviceStatusInfo. statusNum : The number of device status.
Usage:
string GetConnStatusString(PlatformSDK.EConnectionStatus status) { switch (status) { case EConnectionStatus.connected: return "connected"; case EConnectionStatus.disconnected: return "disconnected"; case EConnectionStatus.receiveHeartBeat: return "receive heartbeat"; case EConnectionStatus.heartBeatLost: return "heartbeat lost"; case EConnectionStatus.heartBeatLostRetry: return "heartbeat lost retry"; } return "unknown"; } string GetRecordingStatusString(PlatformSDK.ERecordingState status) { switch (status) { case ERecordingState.none: return "none"; case ERecordingState.scheduled: return "scheduled"; case ERecordingState.manual: return "manual"; case ERecordingState.byEvent: return "event"; case ERecordingState.continuous: return "continuous"; } return "unknown"; } void CheckCameraStatus(int loginID) { TCameraStatusList camStatusList = new TCameraStatusList(); TGetCameraStatusReqInfo request = new TGetCameraStatusReqInfo(); request.getAllCameraStatus = true; request.timeoutMillisecond = 5000; int ret = PlatformSDK.GetCameraStatus(loginID, ref request, ref camStatusList); if (ret != 0) return; for (uint i = 0; i < camStatusList.statusNum; ++i) { IntPtr pStatusInfo = new IntPtr(camStatusList.statusList.ToInt64() + Marshal.SizeOf(typeof(TDeviceStatusInfo)) * i); TDeviceStatusInfo status = (TDeviceStatusInfo)Marshal.PtrToStructure(pStatusInfo, typeof(TDeviceStatusInfo)); string info = status.deviceID + " (" + GetConnStatusString(status.connectionStatus) + ")"; if (status.recordingStatusInfo != IntPtr.Zero) { IntPtr pRecStatus = new IntPtr(status.recordingStatusInfo.ToInt64()); TDeviceRecordingStatusInfo recStatus = (TDeviceRecordingStatusInfo)Marshal.PtrToStructure(pRecStatus, typeof(TDeviceRecordingStatusInfo)); info += ", recording state: " + GetRecordingStatusString(recStatus.deviceRecordingState); if (recStatus.groupID > 0) { info += ", Group ID: " + recStatus.groupID.ToString(); info += " (" + GetRecordingStatusString(recStatus.groupRecordingState) + ")"; } } Console.WriteLine(info); } }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter request or statusList is invalid (0x80700108) : Tunnel send request failed (0x80700115) : Tunnel is not connected
Description:
Change stream speed.
Method:
int ChangeSpeed(int hChannel, float speed)
Parameters:
hChannel: The channel handle of stream. speed : Stream speed, the range is from 0.125 to 64.
Usage:
int ChangeNetStreamSpeed(int hChannel, float speed) { return PlatformSDK.UpdateStreamingSetting(hChannel, speed); }
Error codes:
(0x80000001) : phChannel is invalid (0x80000003) : speed is out of range (0x80700201) : Channel is invalid (0x80700214) : Change speed failed
Description:
When channel is paused, the function will display the next frame, and callback frame data with function TStreamInfo::pfStreamDataCB.
Method:
long NextFrame(int hChannel);
Parameters:
hChannel : The channel handle of net file stream.
Usage:
void TestRetrievalNextFrame() { int hChannel = 0; PlatformSDK.CreateNetFileChannel(&hChannel, ...); PlatformSDK.PauseChannel(hChannel); PlatformSDK.NextFrame(hChannel); //move to the next frame }
Error codes:
(0x80000001) : hChannel is invalid (0x8070021A) : failed to get next frame
Method:
int UpdatePlaybackDirection(int hChannel, EPlayDirection playDirection)
Description:
Change play direction (forward or backward) in the time range setted by PlatformSDK.CreateNetFileChannel.
Parameters:
hChannel : The channel handle of net file stream. playDirection : Forward or backward.
Related structure:
enum EPlayDirection : uint { forward, backward, };
Usage:
void UpdatePlaybackDirection(int hChannel, EPlayDirection playDirection) { PlatformSDK.UpdatePlaybackDirection(hChannel, playDirection); }
Error codes:
(0x80000001) : Parameter hChannel is invalid (0x80700201) : Channel is invalid (0x80700212) : Start channel with new direction failed (0x80700219) : Not support (only support net file channel)
Method:
int UpdatePlaybackOption(int hChannel, ref TPlaybackOption option)
Description:
Change playback start/end time and direction (forward or backward).
Parameters:
hChannel: The channel handle of net file stream. option : Pointer to the structure of TSDKPlaybackOption.
Related structure:
enum EPlayDirection : uint { forward, backward, } [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TPlaybackOption { uint startTime; uint endTime; EPlayDirection playDirection; uint startTimeMilisec; uint endTimeMilisec; };
startTime : Start time, in seconds since Jan 1 1970 00:00:00. endTime : End time, in seconds since Jan 1 1970 00:00:00. playDirection : Forward or backward. startTimeMilisec : Millisecond of start time. endTimeMilisec : Millisecond of end time.
Usage:
void UpdatePlaybackDirection(int hChannel, uint startTime, uint endTime, EPlayDirection playDirection) { TPlaybackOption option = new TPlaybackOption(); option.startTime = startTime; option.endTime = endTime; option.playDirection = playDirection; PlatformSDK.UpdatePlaybackOption(hChannel, ref option); }
Error codes:
(0x80000001) : Parameter hChannel is invalid (0x80700201) : Channel is invalid (0x80700212) : Start channel with new option failed (0x80700219) : Not support (only support net file channel)
Description:
Set display information.
Method:
int SetDisplayInfo(int hChannel, ref TStreamingDisplayInfo displayInfo)
Parameters:
hChannel : The channel handle of stream. displayInfo: Pointer to streaming setting information.
Related structure:
enum ETimeKind : uint { UTC, local, }; enum ESDKTimeSource : uint { cameraTime, recordingTime, }; [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TStreamingDisplayInfo { public bool showFrameTime; public bool showMillisecond; public ETimeSource timeSource; public ETimeKind timeKind; public uint ARGBTextColor; public uint fontSize; public bool showTextShadow; public bool opaqueBackground; public uint ARGBBackgroundColor; };
showFrameTime : Enable frame time show on the upper left corner of view cell. showMillisecond : Show frame time millisecond. timeSource : Show camera time or recording time (just use for playback stream). timeKind : Show UTC or local time (consider time zone and day light saving). ARGBTextColor : The text color in ARGB format. fontSize : The font size. showTextShadow : Use shadow text, enabled when opaqueBackground set to FALSE. opaqueBackground : Use opaque text background. ARGBBackgroundColor : The background color in ARGB format, enabled when opaqueBackground set to TRUE.
Usage:
void ShowLocalCameraTimeWithGreenText(int hChannel) { TStreamingDisplayInfo info = new TStreamingDisplayInfo(); info.showFrameTime = true; info.showMillisecond = true; info.timeSource = PlatformSDK.ETimeSource.cameraTime; info.timeKind = PlatformSDK.ETimeKind.local; info.ARGBTextColor = (0<<16) | (250<<8) | 0; info.fontSize = 19; info.showTextShadow = false; info.opaqueBackground = false; info.ARGBBackgroundColor = 0; PlatformSDK.SetDisplayInfo(hChannel, ref info); }
Error codes:
(0x80000001) : Parameter phChannel is invalid (0x80000003) : Parameter ptDisplayInfo is invalid
Description:
Send PTZ control command.
Remark:
Support multi-thread execution only if hLoginID is different in each thread.
Method:
int PTZControl(int hLoginID, ref TPTZRequest request)
Parameters:
hLoginID : The login ID. ptPTZCtrlInfo: PTZ control information.
Related structure:
enum EPTZCommand : uint { right, left, up, down, home, leftUp, rightUp, leftDown, rightDown, focusAuto, focusNear, focusFar, zoomIn, zoomOut, startPan, startPatrol, stopPan, irisAuto, irisOpen, irisClose, setHome, defaultHome, }
enum EPTZType { physicalPTZ, ePTZ, };
struct TPTZRequest { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string cameraID; public uint channelIndex; public uint streamIndex; public EPTZType PTZType; public EPTZCommand command; public int speed; };
cameraID : Camera ID. channelIndex : The channel index of video server, start from 1. streamIndex : The stream index camera, start from 1. PTZType : Mechanical PTZ or electric PTZ. command : PTZ command. speed : Used for the PTZ commands of change speed, speed range is from 0.125 to 64.
Usage:
void PTZControl(int hLoginID, string cameraID, uint streamIndex, EPTZType PTZType, EPTZCommand command) { TPTZRequest request = new TPTZRequest(); request.cameraID = cameraID; request.channelIndex = 1; request.streamIndex = streamIndex; request.PTZType = PTZType; request.command = command; PlatformSDK.PTZControl(hLoginID, ref request); } TestPhysicalRotateRight(int hLoginID, string cameraID) { PTZControl(hLoginID, cameraID, 1, EPTZType.physicalPTZ, EPTZCommand.right) }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter request is invalid (0x80700108) : tunnel send request failed
Description:
Send continuous PTZ control command.
Remark:
Support multi-thread execution only if hLoginID is different in each thread.
Method:
int ContinuousPTZControl(int hLoginID, ref TContinuousPTZRequest request)
Parameters:
hLoginID : The login ID. request : Continuous PTZ control information.
Related structure:
struct TContinuousPTZRequest { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string cameraID; public uint channelIndex; public uint streamIndex; public int speed; public int x; public int y; };
cameraID : Camera ID. channelIndex : The channel index of video server, start from 1. streamIndex : The stream index camera, start from 1. speed : Used for the PTZ commands of change speed, speed range is from 1 to 64. x : Camera moving direction x. y : Camera moving direction y.
Usage:
void ContinuousPTZControl(int hLoginID, string cameraID, uint streamIndex, int speed, int x, int y) { TContinuousPTZRequest request = new TContinuousPTZRequest(); request.cameraID = cameraID; request.channelIndex = 1; request.streamIndex = streamIndex; request.speed = speed; request.x = x; request.y = y; PlatformSDK.ContinuousPTZControl(hLoginID, ref request); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter request is invalid (0x80700108) : tunnel send request failed
Description:
Send stop PTZ control command.
Remark:
Support multi-thread execution only if hLoginID is different in each thread.
Method:
int StopPTZControl(int hLoginID, ref TContinuousPTZRequest request)
Parameters:
hLoginID : The login ID. request : Stop PTZ control information.
Related structure:
struct TContinuousPTZRequest { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string cameraID; public uint channelIndex; public uint streamIndex; public int speed; public int x; public int y; };
cameraID : Camera ID. channelIndex : The channel index of video server, start from 1. streamIndex : The stream index camera, start from 1. speed : Unused. x : Unused. y : Unused.
Usage:
void StopPTZControl(int hLoginID, string cameraID, uint streamIndex) { TContinuousPTZRequest request = new TContinuousPTZRequest(); request.cameraID = cameraID; request.channelIndex = 1; request.streamIndex = streamIndex; PlatformSDK.StopPTZControl(hLoginID, ref request); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter request is invalid (0x80700108) : tunnel send request failed
Method:
int PlatformSDK.ManualRecording(int hLoginID, ref TSDKManualRecordingRequest ptManualRecRequest)
Description:
Start or stop manual recording. Note: The VAST recording schedule setting must set recording mode to "None".
Parameters:
hLoginID : Login ID. ptManualRecRequest : Pointer to request information.
Method:
int PlatformSDK.SystemShutdown(int hLoginID, ref TSDKSystemShutdownReqInfo ptReqInfo)
Description:
Shutdown or reboot NVR.
Parameters:
hLoginID : Login ID. TSDKSystemShutdownReqInfo : Pointer to request info.
Method:
int BlockedSendRequest(int hLoginID, ref TBlockedRequestInfo request, ref TBlockedResponseInfo response)
Description:
Send request message in blocked mode. All of the messages are described in MessageDocument.doc.
Parameters:
hLoginID: The login ID. request : The request information. response: The response information.
Related structure:
enum EServerType : uint { configServer, eventServer, queryServer, } struct TBlockedRequestInfo { public EServerType serverType; public string commandName; public IntPtr commandBody; public uint timeoutMillisecond; }
serverType : Server type of the command. commandName : Command name. commandBody : Command content. timeoutMillisecond: Timeout milliseconds.
struct TBlockedResponseInfo { public IntPtr content; public uint contentLen; }
content : Response message. contentLen: The length of response message.
Usage:
void GetUserLogHistory(int loginID) { string commandBody = "<LoginPeriod TZ=\"+08:00\">" + "<TmS>2016-01-29T01:15:59Z</TmS>" + "<TmE>2016-03-29T02:15:59Z</TmE>" + "</LoginPeriod>" + "<LogoutPeriod TZ=\"+08:00\">" + "<TmS>2017-01-29T01:15:59Z</TmS>" + "<TmE>2017-03-29T02:15:59Z</TmE>" + "</LogoutPeriod>"; IntPtr ansiCommandBody = Marshal.StringToHGlobalAnsi(commandBody); TBlockedRequestInfo request = new TBlockedRequestInfo(); TBlockedResponseInfo response = new TBlockedResponseInfo(); request.commandName = "QryLoginHist"; request.commandBody = ansiCommandBody; request.serverType = EServerType.queryServer; request.timeoutMillisecond = 3000; PlatformSDK.BlockedSendRequest(loginID, ref request, ref response); Marshal.FreeHGlobal(ansiCommandBody); string responseMessage = Marshal.PtrToStringAnsi(response.content); Console.WriteLine(responseMessage); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter request or response is invalid (0x8070011D) : Tunnel blocked send request failed
Method:
int NonBlockedSendRequest(int hLoginID, ref TNonBlockedRequestInfo request)
Description:
Send request message in non-blocked mode. All of the messages are described in MessageDocument.doc.
Parameters:
hLoginID: The login ID. request : The request information.
Related structure:
enum ESDKRequestStatus : uint { none, timeout, terminate, responsePart, responseComplete, } enum EServerType : uint { configServer, eventServer, queryServer, } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfNonBlockedRequestCallBack(IntPtr response, uint responseLen, ESDKRequestStatus status, IntPtr context);
response : The response string. responseLen: The length of response. status : The request status: The status of response is responsePart if not yet receive complete. The status of final response is responseComplete. context : User passed information.
struct TNonBlockedRequestInfo { public EServerType serverType; public string commandName; public IntPtr commandBody; [MarshalAs(UnmanagedType.FunctionPtr)] public pfNonBlockedRequestCallBack callback; public IntPtr context; }
serverType : Server type of the command. commandName : Command name. commandBody : Command content. callback : Response callback function. context : User passed information.
Usage:
PlatformSDK.pfNonBlockedRequestCallBack nonBlockedRequestCB = new PlatformSDK.pfNonBlockedRequestCallBack(NonBlockedRequestCallBack); void NonBlockedRequestCallBack(IntPtr response, uint responseLen, ESDKRequestStatus status, IntPtr context) { string responseMessage = Marshal.PtrToStringAnsi(response); Console.WriteLine("status = " + status); Console.WriteLine(responseMessage); } void GetUserLogHistory(int loginID) { string commandBody = "<LoginPeriod TZ=\"+08:00\">" + "<TmS>2016-01-29T01:15:59Z</TmS>" + "<TmE>2016-03-29T02:15:59Z</TmE>" + "</LoginPeriod>" + "<LogoutPeriod TZ=\"+08:00\">" + "<TmS>2017-01-29T01:15:59Z</TmS>" + "<TmE>2017-03-29T02:15:59Z</TmE>" + "</LogoutPeriod>"; IntPtr ansiCommandBody = Marshal.StringToHGlobalAnsi(commandBody); TNonBlockedRequestInfo request = new TNonBlockedRequestInfo(); request.commandName = "QryLoginHist"; request.commandBody = ansiCommandBody; request.serverType = EServerType.queryServer; request.callback = nonBlockedRequestCB; request.context = IntPtr.Zero; PlatformSDK.NonBlockedSendRequest(loginID, ref request); Marshal.FreeHGlobal(ansiCommandBody); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter request is invalid (0x8070011E) : Tunnel nonblocked send request failed
Description:
Get live snapshot with raw data.
Method:
int GetLiveSnapshot(int hLoginID, ref TLiveSnapshotRequest request)
Parameters:
hLoginID : The login ID. ptRequest: Pointer to the request information.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TSnapshotCallbackInfo { public IntPtr image; public int imageSize; public IntPtr context; };
image : Pointer to the image data. imageSize: Image size, in unit of Byte. context : User passed information.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfSnapshotCallBack(IntPtr pSnapshotInfo) [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TLiveSnapshotRequest { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string cameraID; public uint channelIndex; public uint streamIndex; public uint width; public uint height; public uint timeoutSeconds; public bool IFrameOnly; [MarshalAs(UnmanagedType.FunctionPtr)] public pfSnapshotCallBack pfSnapshotCB; public IntPtr context; }
cameraID : Camera ID. channelIndex : Used for video server, start from 1. Set 0 will use the default channel. streamIndex : Stream index, start from 1. Set 0 will use the default stream. width : Used for resize, the value muse be the multiple of 16. Set 0 for actual size. height : Used for resize, the value muse be the multiple of 16. Set 0 for actual size. timeoutSeconds : Timeout seconds, set 0 will use the internal default timeout seconds. IFrameOnly : Set true to retrieve only I-frame snapshot. pfSnapshotCB : Snapshot callback. context : User passed information.
Usage:
unsafe void SnapshotCallBack(IntPtr pSnapshotInfo) { TSnapshotCBInfo snapshotInfo = (TSnapshotCBInfo)Marshal.PtrToStructure(pSnapshotInfo, typeof(TSnapshotCBInfo)); TSnapshotContext context = (TSnapshotContext)Marshal.PtrToStructure(snapshotInfo.context, typeof(TSnapshotContext)); if (snapshotInfo.imageSize == 0) return; byte[] image = new byte[snapshotInfo.imageSize]; Marshal.Copy(snapshotInfo.image, image, 0, snapshotInfo.imageSize); try { BinaryWriter writer = new BinaryWriter(File.Open(context.savePath, FileMode.OpenOrCreate)); writer.Write(image, 0, snapshotInfo.imageSize); writer.Flush(); writer.Close(); } catch (IOException e) { System.Console.Write("Fail to write file \"" + context.savePath + "\":\n" + e.ToString()); } } PlatformSDK.pfSnapshotCallBack snapshotCB = null; struct TSnapshotContext { public string savePath; } void GetLiveSnapshot(int loginID, string cameraID) { if (snapshotCB == null) { snapshotCB = new PlatformSDK.pfSnapshotCallBack(SnapshotCallBack); } Directory.CreateDirectory("D:/Export"); TSnapshotContext context = new TSnapshotContext(); context.savePath = "D:/Export/Live_" + System.DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".jpg"; IntPtr pContext = Marshal.AllocHGlobal(Marshal.SizeOf(context)); Marshal.StructureToPtr(context, pContext, false); TLiveSnapshotRequest request = new TLiveSnapshotRequest(); request.cameraID = cameraID; request.channelIndex = 0; request.streamIndex = 0; request.pfSnapshotCB = snapshotCB; request.width = 0; request.height = 0; request.IFrameOnly = false; request.context = pContext; request.timeoutSeconds = 4; PlatformSDK.GetLiveSnapshot(loginID, ref request); Marshal.FreeHGlobal(pContext); }
Error codes:
(0x80000001) : parameter hLoginID is invalid (0x80000003) : parameter request is invalid (0x80700119) : no live snapshot data (0x8070020F) : cameraId is invalid (0x80700116) : fail to connect server
Another method for NVR to get snapshot:
Get NVR live snapshot related API:
Please reference: PlatformSDK.CreateLiveChannel PlatformSDK.DeleteLiveChannel
Get NVR live snapshot usage:
private void GetNVRSnapshot(ref int hLiveChannel, string serverIP, string serverUserName, string serverPassword, int serverPort, string cameraID) { TStreamInfo streamInfo = new TStreamInfo(); streamInfo.streamSource = PlatformSDK.EStreamSource.VAST; streamInfo.streamMode = PlatformSDK.EStreamMode.retrieveOneSnapshot; streamInfo.timeType = PlatformSDK.ETimeType.recordingTime; streamInfo.serverIP = serverIP; streamInfo.serverUserName = serverUserName; streamInfo.serverPassword = serverPassword; streamInfo.serverPort = serverPort; streamInfo.cameraID = cameraID; streamInfo.pfVideoDecodeCB = new PlatformSDK.pfVideoDecodeCallBack(VideoDecodeCallBack); streamInfo.hDisplayWindow = IntPtr.Zero; streamInfo.streamIndex = 1; streamInfo.capVersion = PlatformSDK.ECapabilityVersion.VAST; streamInfo.streamInitStatus = PlatformSDK.EStreamInitStatus.play; int ret = PlatformSDK.CreateLiveChannel(ref hLiveChannel, ref streamInfo); EventLog.Write("PlatformSDK.CreateLiveChannel Ret = {0:X}", ret); } private void VideoDecodeCallBack(IntPtr pVideoDecodeInfo) { TVideoDecodeInfo decodeInfo = (TVideoDecodeInfo)Marshal.PtrToStructure(pVideoDecodeInfo, typeof(TVideoDecodeInfo)); if (decodeInfo.pBuffer == IntPtr.Zero) return; SaveImage(ref decodeInfo); int ret = PlatformSDK.DeleteLiveChannel(ref hLiveChannel); EventLog.Write("DeleteLiveChannel: {0:X}", ret); } unsafe void SaveImage(ref TVideoDecodeInfo decodeInfo) { if (decodeInfo.pBuffer == IntPtr.Zero) return; System.DateTime time = new System.DateTime(1970, 1, 1).AddSeconds(decodeInfo.frameSecond); string savePath = "D:\\Export\\" + time.ToString("yyyyMMdd_HHmmss") + "_" + decodeInfo.frameMilSec + ".jpg"; try { byte[] image = new byte[decodeInfo.bufSize]; Marshal.Copy(decodeInfo.pBuffer, image, 0, decodeInfo.bufSize); FileStream file = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write); file.Write(image, 0, decodeInfo.bufSize); file.Close(); } catch (IOException e) { EventLog.Write("Fail to save image \"" + savePath + "\":\n" + e.ToString()); } }
Description:
Get playback snapshot with raw data.
Method:
int GetPlaybackSnapshot(int hLoginID, ref TPlaybackSnapshotRequest request)
Parameters:
hLoginID : The login ID. ptRequest: Pointer to the request information.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TSnapshotCallbackInfo { public IntPtr image; public int imageSize; public IntPtr context; };
image : Pointer to the image data. imageSize: Image size, in unit of Byte. context : User passed information.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void pfSnapshotCallBack(IntPtr pSnapshotInfo) [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TPlaybackSnapshotRequest { public uint timeSeconds; public uint millisceondsOfTime; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string cameraID; public uint width; public uint height; public uint timeoutSeconds; public ETimeKind timeKind; public ETimeType timeType; public bool IFrameOnly; [MarshalAs(UnmanagedType.FunctionPtr)] public pfSnapshotCallBack pfSnapshotCB; public IntPtr context; }
timeSeconds : Datetime seconds, value type: time_t. millisecondsOfTime: The milliseconds of the retrieval time, range: 0 ~ 999. cameraID : Camera ID. width : Used for resize, the value muse be the multiple of 16. Set 0 for actual size. height : Used for resize, the value muse be the multiple of 16. Set 0 for actual size. timeoutSeconds : Timeout seconds, set 0 will use the internal default timeout seconds. timeKind : Get snapshot by local time or UTC time. timeType : Retrieve by recording time or camera time. IFrameOnly : Set true to retrieve only I-frame snapshot. pfSnapshotCB : Snapshot callback. context : User passed information.
Usage:
unsafe void SnapshotCallBack(IntPtr pSnapshotInfo) { TSnapshotCBInfo snapshotInfo = (TSnapshotCBInfo)Marshal.PtrToStructure(pSnapshotInfo, typeof(TSnapshotCBInfo)); TSnapshotContext context = (TSnapshotContext)Marshal.PtrToStructure(snapshotInfo.context, typeof(TSnapshotContext)); if (snapshotInfo.imageSize == 0) return; byte[] image = new byte[snapshotInfo.imageSize]; Marshal.Copy(snapshotInfo.image, image, 0, snapshotInfo.imageSize); try { BinaryWriter writer = new BinaryWriter(File.Open(context.savePath, FileMode.OpenOrCreate)); writer.Write(image, 0, snapshotInfo.imageSize); writer.Flush(); writer.Close(); } catch (IOException e) { System.Console.Write("Fail to write file \"" + context.savePath + "\":\n" + e.ToString()); } } PlatformSDK.pfSnapshotCallBack snapshotCB = null; struct TSnapshotContext { public string savePath; } static readonly DateTime dateTime1970 = new DateTime(1970, 1, 1); uint UtcDateTime2time_t(string cameraID, DateTime datetime) { TimeSpan diff = datetime.ToUniversalTime() - dateTime1970; return (uint)(diff.TotalSeconds); } void GetPlaybackSnapshot(int loginID, string cameraID, DateTime datetime) { if (snapshotCB == null) { snapshotCB = new PlatformSDK.pfSnapshotCallBack(SnapshotCallBack); } Directory.CreateDirectory("D:/Export"); TSnapshotContext context = new TSnapshotContext(); context.savePath = "D:/Export/Playback_" + datetime.ToString("yyyyMMdd_HHmmss") + ".jpg"; IntPtr pContext = Marshal.AllocHGlobal(Marshal.SizeOf(context)); Marshal.StructureToPtr(context, pContext, false); TPlaybackSnapshotRequest request = new TPlaybackSnapshotRequest(); request.cameraID = cameraID; request.timeSeconds = UtcDateTime2time_t(datetime); request.millisceondsOfTime = 0; request.width = 0; request.height = 0; request.timeKind = PlatformSDK.ETimeKind.local; request.timeType = PlatformSDK.ETimeType.recordingTime; request.pfSnapshotCB = snapshotCB; request.IFrameOnly = false; request.context = pContext; request.timeoutSeconds = 4; PlatformSDK.GetPlaybackSnapshot(loginID, ref request); Marshal.FreeHGlobal(pContext); }
Error codes:
(0x80000001) : parameter hLoginID is invalid (0x80000003) : parameter request is invalid (0x8070020F) : cameraId is invalid (0x80700116) : fail to connect server (0x80700119) : send http request failed (0x8070011C) : no playback snapshot data
Another method for NVR to get snapshot:
Get NVR playback snapshot related API:
Please reference: PlatformSDK.CreateNetFileChannel PlatformSDK.DeleteNetFileChannel
Get NVR playback snapshot usage:
private void GetNVRSnapshot(ref int hPlaybackChannel, string serverIP, string serverUserName, string serverPassword, int serverPort, string cameraID, int startTime, int endTime) { TStreamInfo streamInfo = new TStreamInfo(); streamInfo.streamSource = PlatformSDK.EStreamSource.VAST; streamInfo.streamMode = PlatformSDK.EStreamMode.retrieveOneSnapshot; streamInfo.timeType = PlatformSDK.ETimeType.recordingTime; streamInfo.serverIP = serverIP; streamInfo.serverUserName = serverUserName; streamInfo.serverPassword = serverPassword; streamInfo.serverPort = serverPort; streamInfo.cameraID = cameraID; streamInfo.pfVideoDecodeCB = new PlatformSDK.pfVideoDecodeCallBack(VideoDecodeCallBack); streamInfo.hDisplayWindow = IntPtr.Zero; streamInfo.streamIndex = 1; streamInfo.capVersion = PlatformSDK.ECapabilityVersion.VAST; streamInfo.streamInitStatus = PlatformSDK.EStreamInitStatus.play; streamInfo.startTime = startTime; streamInfo.endTime = endTime; streamInfo.timeKind = PlatformSDK.ETimeKind.local; int ret = PlatformSDK.CreateNetFileChannel(ref hPlaybackChannel, ref streamInfo); EventLog.Write("PlatformSDK.CreateNetFileChannel Ret = {0:X}", ret); } private void VideoDecodeCallBack(IntPtr pVideoDecodeInfo) { TVideoDecodeInfo decodeInfo = (TVideoDecodeInfo)Marshal.PtrToStructure(pVideoDecodeInfo, typeof(TVideoDecodeInfo)); if (decodeInfo.pBuffer == IntPtr.Zero) return; SaveImage(ref decodeInfo); int ret = PlatformSDK.DeleteNetFileChannel(ref hPlaybackChannel); EventLog.Write("DeleteNetFileChannel: {0:X}", ret); } unsafe void SaveImage(ref TVideoDecodeInfo decodeInfo) { if (decodeInfo.pBuffer == IntPtr.Zero) return; System.DateTime time = new System.DateTime(1970, 1, 1).AddSeconds(decodeInfo.frameSecond); string savePath = "D:\\Export\\" + time.ToString("yyyyMMdd_HHmmss") + "_" + decodeInfo.frameMilSec + ".jpg"; try { byte[] image = new byte[decodeInfo.bufSize]; Marshal.Copy(decodeInfo.pBuffer, image, 0, decodeInfo.bufSize); FileStream file = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write); file.Write(image, 0, decodeInfo.bufSize); file.Close(); } catch (IOException e) { EventLog.Write("Fail to save image \"" + savePath + "\":\n" + e.ToString()); } }
Description:
Save the snapshot of current channel to file.
Method:
int PlatformSDK.SaveChannelSnapshot(int hChannel, ref TSDKChannelSnapshotInfo snapshotInfo)
Parameters:
hChannel : The channel handle created by PlatformSDK.CreateLiveChannel or PlatformSDK.CreateNetFileChannel. snapshotInfo: Pointer to the structure of TSDKChannelSnapshotInfo.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TSDKChannelSnapshotInfo { public IntPtr pszOutputDir; public IntPtr pszFileName; }
pszOutputDir : output directory pszFileName : output filename
Usage:
void SaveChannelSnapshot(int hChannel, string dir, string filename) { IntPtr pDir = Marshal.StringToHGlobalAnsi(dir); IntPtr pFilename = Marshal.StringToHGlobalAnsi(filename); PlatformSDK.TChannelSnapshotInfo snapshotInfo = new PlatformSDK.TChannelSnapshotInfo(); snapshotInfo.pszFileName = pFilename; snapshotInfo.pszOutputDir = pDir; PlatformSDK.SaveChannelSnapshot(hChannel, ref snapshotInfo); Marshal.FreeHGlobal(pFilename); Marshal.FreeHGlobal(pDir); }
Error codes:
(0x80000001) : hChannel is invalid (0x80000003) : snapshotInfo is invalid (0x80700201) : connect channel failed (0x80700215) : get snapshot failed (0x80700216) : write snapshot to file failed
Description:
Get the snapshot of current channel with raw data
Remark:
Support multi-thread execution only if hChannel is different in each thread.
Method:
int PlatformSDK.GetChannelSnapshot(int hChannel, ref TSnapshotRawInfo snapshotRawInfo)
Parameters:
hChannel : The channel handle created by PlatformSDK.CreateLiveChannel or PlatformSDK.CreateNetFileChannel. snapshotRawInfo: Pointer to the structure of TSnapshotRawInfo.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TSnapshotRawInfo { public IntPtr pBuffer; public int bufSize; public int height; public int width; }
pBuffer : The decoded image raw data bufSize : The byte size of image height : Image height width : Image width
Usage:
void GetChannelSnapshot(int hChannel) { PlatformSDK.TSnapshotRawInfo snapshotRawInfo = new PlatformSDK.TSnapshotRawInfo(); var ret = PlatformSDK.GetChannelSnapshot(hChannel, ref snapshotRawInfo); EventLog.Write("PlatformSDK.GetChannelSnapshot Ret = {0:X}", ret); if (snapshotRawInfo.pBuffer == IntPtr.Zero) return; string savePath = "D:\\FromRawData.jpg"; byte[] image = new byte[snapshotRawInfo.bufSize]; Marshal.Copy(snapshotRawInfo.pBuffer, image, 0, snapshotRawInfo.bufSize); FileStream file = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write); file.Write(image, 0, snapshotRawInfo.bufSize); file.Close(); }
Error codes:
(0x80000001) : hChannel is invalid (0x80000003) : snapshotRawInfo is invalid (0x80700201) : connect channel failed (0x80700215) : get snapshot failed (0x80700216) : write snapshot to snapshotRawInfo failed
Description:
Get the fisheye snapshot of current channel with raw data
Method:
int PlatformSDK.GetFisheyeChannelSnapshot(int hChannel, int hWindow, ref TSnapshotRawInfo snapshotRawInfo)
Parameters:
hChannel : The channel handle created by PlatformSDK.CreateLiveChannel or PlatformSDK.CreateNetFileChannel. hWindow : The display window handle of the channel snapshotRawInfo: Pointer to the structure of TSnapshotRawInfo.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TSnapshotRawInfo { public IntPtr pBuffer; public int bufSize; public int height; public int width; }
pBuffer : The decoded image raw data bufSize : The byte size of image height : Image height width : Image width
Usage:
void GetChannelSnapshot(int hChannel, int hWindow) { PlatformSDK.TSnapshotRawInfo snapshotRawInfo = new PlatformSDK.TSnapshotRawInfo(); var ret = PlatformSDK.GetFisheyeChannelSnapshot(hChannel, hWindow, ref snapshotRawInfo); EventLog.Write("PlatformSDK.GetFisheyeChannelSnapshot Ret = {0:X}", ret); if (snapshotRawInfo.pBuffer == IntPtr.Zero) return; string savePath = "D:\\FromRawData.jpg"; byte[] image = new byte[snapshotRawInfo.bufSize]; Marshal.Copy(snapshotRawInfo.pBuffer, image, 0, snapshotRawInfo.bufSize); FileStream file = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write); file.Write(image, 0, snapshotRawInfo.bufSize); file.Close(); }
Error codes:
(0x80000001) : hChannel or hWindow is invalid (0x80000003) : snapshotRawInfo is invalid (0x80700201) : connect channel failed (0x80700215) : get snapshot failed (0x80700216) : write snapshot to snapshotRawInfo failed
Description:
Get server information.
Remark:
Not support multi-thread execution.
Method:
int GetServerInfo(int hLoginID, ref TServerInfo serverInfo);
Parameters:
hLoginID : The login ID. ptServerInfo: Pointer to the request information.
Related structure:
enum ECapabilityVersion { VAST, NVR, CMS, unknown, } [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TServerInfo { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string stationID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_REFNAME_LEN + 1)] public string refName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_IPHOST_LEN + 1)] public string IP; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_VERSION_LEN + 1)] public string version; public uint HTTPPort; public uint HTTPSPort; public uint RTSPPort; public uint VCAHTTPSPort; public bool enableWebAccess; public ECapabilityVersion capVersion; }
stationID : Station ID. refName : Station reference name. IP : Station IP. version : Station version. HTTPPort : HTTP port. HTTPSPort : HTTPS port. RTSPPort : RTSP port. VCAHTTPSPort : VCA HTTPS port. enableWebAccess: If station enable web access. capVersion : VAST, NVR, or CMS.
Usage:
void GetServerInfo(int loginID) { PlatformSDK.TServerInfo serverInfo = new PlatformSDK.TServerInfo(); PlatformSDK.GetServerInfo(loginID, ref serverInfo); System.Console.WriteLine("Station name: {0}", tServerInfo.refName); System.Console.WriteLine("Version: {0}", tServerInfo.version); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter serverInfo is invalid (0x80700108) : Tunnel send request failed
Method:
int GetBookmarkList(int hLoginID, ref TBookmarkRequest request, ref TBookmarkList bookmarkList)
Description:
Get VAST2 bookmark list.
Parameters:
loginID : The login ID. request : Pointer to the request information. bookmarkList: Pointer to the bookmark list.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TBookmarkReqInfo { uint timeoutSeconds; }
timeoutSeconds: The timeout seconds, set 0 will use the internal default timeout seconds.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TBookmark { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string bookmarkID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_NODEUNIT_LEN + 1)] public string cameraID; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_BOOKMARK_DESCRIPTION_LEN + 1)] public string describe; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_USERNAME_LEN + 1)] public string creator; }
bookmarkID: Bookmark ID. cameraID : Camera ID. describe : Bookmark describe. creator : Creator.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct TBookmarkList { public IntPtr bookmarkList; public uint bookmarkNum; }
bookmarkList: Pointer to bookmark list. bookmarkNum : The namber of bookmarks.
Usage:
void GetBookmarkList(int loginID) { TBookmarkList list = new TBookmarkList(); TBookmarkRequest request = new TBookmarkRequest(); request.dwTimeoutSeconds = 5; PlatformSDK.GetBookmarkList(loginID, ref request, ref list); for (uint i = 0; i < list.bookmarkNum; ++i) { IntPtr pBookmark = new IntPtr(list.bookmarkList.ToInt64() + Marshal.SizeOf(typeof(TBookmark)) * i); TBookmark bookmark = (TBookmark)Marshal.PtrToStructure(pBookmark, typeof(TBookmark)); System.Console.WriteLine("bookmarkID: {0}", bookmark.bookmarkID); System.Console.WriteLine("cameraID: {0}", bookmark.cameraID); System.Console.WriteLine("creator: {0}", bookmark.creator); System.Console.WriteLine("describe: {0}", bookmark.describe); } }
Error codes:
(0x80000001) : hLoginID is invalid (0x80000003) : request or bookmarkList is invalid (0x80700118) : server parse JSON failed (0x80700119) : send http request failed
Method:
int SendHttpRequest(ref THttpRequest request)
Description:
Send HTTP request and handle response callback in blocked mode. All of the request messages are described in CGI document.
Parameters:
request: Pointer to the request information.
Related structure:
enum EHttpMethod : uint { GET, POST, } [StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] struct THttpRequest { public EHttpMethod method; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_URL_LEN + 1)] public string URL; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_USERNAME_LEN + 1)] public string userName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_HEXPWD_LEN + 1)] public string password; public string POSTData; public uint POSTDataLen; public string header; public uint headerLen; public uint timeoutSeconds; public pfHttpRequestCallBack callback; public IntPtr context; }
method : HTTP method (GET or POST). URL : Includes protocol (HTTP or HTTPS) IP, port, and query parameters. userName : User account. password : User password. POSTData : Pointer to the POST date. Set to NULL if not used. POSTDataLen : The length of the POST data. header : The HTTP header. headerLen : The length of HTTP header. timeoutSeconds: The timeout seconds, set 0 will use the internal default timeout seconds. callback : Response callback. context : User passed information.
Usage:
PlatformSDK.pfHttpRequestCallBack httpRequestCB = new PlatformSDK.pfHttpRequestCallBack(GetCameraInfoCallBack); void GetCameraInfoCallBack(IntPtr message, uint messageLen, IntPtr context) { if (messageLen == 0) return; string response = Marshal.PtrToStringAnsi(message); System.Console.WriteLine(response); } private void GetCameraInfo(string serverIP, string serverPort, string deviceID, string username, string password) { string data = "<GetNodeInfo><Node>" + deviceID +"</Node></GetNodeInfo>"; string url = "http://" + serverIP + ":" + serverPort + "/Tunnel/Message.aspx"; THttpRequest request = new THttpRequest(); request.method = PlatformSDK.EHttpMethod.POST; request.URL = url; request.userName = username; request.password = password; request.header = null; request.headerLen = 0; request.POSTData = data; request.POSTDataLen = data.Length(); request.callback = httpRequestCB; int ret = PlatformSDK.SendHttpRequest(ref request); EventLog.Write("PlatformSDK.SendHttpRequest Ret = {0:X}", ret); }
Error codes:
(0x80000003) : request is invalid (0x80700119) : send http request failed
Description:
Get all preset name from camera.
Remark:
Not support multi-thread execution.
Method:
uint GetPresetList(int hLoginID, IntPtr camID, ref TSDKPresetList presetList);
hLoginID : Login ID. camID : It's the camera ID, which is started with "C_". presetList : The list of preset names.
Related structure:
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TSDKPresetList { public uint dwPresetNum; public IntPtr ptPresetList; }
dwPresetNum : The number of the preset list. ptPresetList : Pointer to the structure of TSDKPreset.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public struct TSDKPreset { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PRESET_NAME_LEN + 1)] public string szPresetName; }
szPresetName : The name of the camera preset.
Usage:
public void GetPresetList(int loginID) { IntPtr pCamID = Marshal.StringToHGlobalAnsi("C_1"); TSDKPresetList presetList = new TSDKPresetList(); var ret = PlatformSDK.GetPresetList(loginID, pCamID, ref presetList); EventLog.Write("PlatformSDK.GetPresetList = {0:X}, Number of Preset = {1}", ret, presetList.dwPresetNum); for (int i = 0; i < presetList.dwPresetNum; ++i) { IntPtr pPreset = new IntPtr(presetList.ptPresetList.ToInt64() + Marshal.SizeOf(typeof(TSDKPreset)) * i); TSDKPreset eventInfo = (TSDKPreset)Marshal.PtrToStructure(pPreset, typeof(TSDKPreset)); EventLog.Write("Preset Name = {0}", eventInfo.szPresetName); } }
Error codes:
(0x80000001) : parameter hLoginID is invalid (0x80000003) : camID is invalid (0x80700108) : tunnel send request failed (0x80700115) : tunnel is not connected
Description:
Move the camera view to preset position.
Remark:
Support multi-thread execution only if hLoginID is different in each thread.
Method:
uint MoveToPreset(int hLoginID, IntPtr camID, IntPtr presetName);
hLoginID : Login ID. camID : It's the camera ID, which is started with "C_". presetName : The name of the camera preset.
Usage:
public void MoveToPreset(int loginID) { IntPtr pCamID = Marshal.StringToHGlobalAnsi("C_1"); IntPtr pPresetName = Marshal.StringToHGlobalAnsi("P1"); var ret = PlatformSDK.MoveToPreset(loginHandle, pCamID, pPresetName); EventLog.Write("PlatformSDK.MoveToPreset = {0:X}", ret); }
Error codes:
(0x80000001) : parameter hLoginID is invalid (0x80000003) : camID or presetName is invalid (0x80700108) : tunnel send request failed (0x80700115) : tunnel is not connected
Description:
Get NVR log records
Remark:
Not support multi-thread execution.
Method:
int PlatformSDK.QueryNVRLogList(int hLoginID, ref TQueryNVRLogRequest ptQueryNVRLogReqInfo, ref IntPtr pptNVRLogRecords, int* pdwQueryNVRLogNum)
Parameters:
ptQueryNVRLogReqInfo : The structure of TQueryNVRLogRequest. pptNVRLogRecords : Pointer to the array of structure of type TQueryNVRLogResponse. pdwQueryNVRLogNum : Pointer to the item number of pptNVRLogRecords.
Related structure:
public enum ENVRLogType : uint { system, recording, user, error, abnormalEvent, unknown, }
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TQueryNVRLogRequest { public uint startTime; public uint endTime; public uint maxRecords; public ENVRLogType logType; }
startTime : Query NVR log start time, in seconds since Jan 1 1970 00:00:00. endTime : Query NVR log end time, in seconds since Jan 1 1970 00:00:00. maxRecords : Maximum number of searching NVR log. logType : NVR log type.
[StructLayout(LayoutKind.Sequential, Pack = 4), Serializable] public unsafe struct TQueryNVRLogResponse { public IntPtr content; public uint contentLength; }
content : the raw NVR log xml string. Each NVR log is defined by XML string. see more about "NVR Log Record XML Schema". contentLen : the size of content.
Usage:
public void QueryNVRLogList(int hLoginID) { var request = new PlatformSDK.TQueryNVRLogRequest(); request.maxRecords = 100; request.startTime = 1575504000; request.endTime = 1575504000 + 86400; request.logType = PlatformSDK.ENVRLogType.user; int logNVRRecordNum = 0; IntPtr pLogNVRRecords = IntPtr.Zero; int ret = PlatformSDK.QueryNVRLogList(hLoginID, ref request, ref pLogNVRRecords, &logNVRRecordNum); }
Error codes:
(0x80000001) : Parameter hLoginID is invalid (0x80000003) : Parameter ptQueryNVRLogReqInfo, pptNVRLogRecords or pdwQueryNVRLogNum is invalid (0x80700108) : tunnel send request failed (0x80700112) : Can not login query server
Description:
Before call any fisheye function (ex: PlatformSDK.SetFisheyeDisplayMode), we must invoke PlatformSDK.GetFisheyeMountType to check if the channel be setted to the correct mount type. For non-fisheye camera, it returns eFisheyeMountType_NonFisheyeCamera.
Method:
int PlatformSDK.GetFisheyeMountType(int hChannel, ref EFisheyeMountType eType);
Parameters:
hChannel : The channel handle created from PlatformSDK.CreateLiveChannel or PlatformSDK.CreateNetFileChannel or PlatformSDK.CreateExportMediaFileChannel. eType : The fisheye camera mount type.
Related structure:
public enum EFisheyeMountType : uint { unknown, wall, ceiling, floor, nonFisheyeCamera }
Usage:
public bool CheckValidFisheyeCamera(int hChannel) { const int MAX_RETRY_COUNT = 10; int retryCount = 0; var mountType = PlatformSDK.EFisheyeMountType.unknown; while (mountType == PlatformSDK.EFisheyeMountType.unknown) { if (retryCount == MAX_RETRY_COUNT) break; retryCount++; var ret = PlatformSDK.GetFisheyeMountType(hChannel, ref mountType); EventLog.Write("PlatformSDK.GetFisheyeMountType Ret = {0:X}", ret); Thread.Sleep(500); } return mountType != PlatformSDK.EFisheyeMountType.unknown && mountType != PlatformSDK.EFisheyeMountType.nonFisheyeCamera; }
Error codes:
(0x80000001) : hChannel is null pointer (0x80700201) : hChannel is invalid
Description:
Set fisheye display mode.
Remark:
Support multi-thread execution only if hChannel is different in each thread.
Method:
int PlatformSDK.SetFisheyeDisplayMode(int hChannel, EFisheyeDisplayMode eMode);
Parameters:
hChannel : The channel handle created from PlatformSDK.CreateLiveChannel or PlatformSDK.CreateNetFileChannel or PlatformSDK.CreateExportMediaFileChannel. eMode : The fisheye camera display mode.
Related structure:
public enum EFisheyeDisplayMode : uint { mode_None, mode_1O, mode_1O_Unstretched, mode_1R, mode_1P, mode_2P_Unstretched, mode_2P, mode_1P2R, mode_1O3R, mode_4R, mode_4R_Interfered, mode_1P3R, mode_1O8R, mode_1P3R_TopPanorama, mode_1P2R_TopPanorama, }
The mount type wall support displaye mode : 1O, 1O_Unstretched, 1R, 1P, 1P2R, 1O3R, 4R, 1P3R, 1P3R_TopPanorama, 1P2R_TopPanorama, Not support ePTZ operation mode: 1P, 4P The mount type ceiling support displaye mode : 1O, 1O_Unstretched, 1R, 1P, 2P, 2P_Unstretched, 1O3R, 4R, 4R_Interfered, 1O8R, 1P3R_TopPanorama, 1P2R_TopPanorama The mount type floor support displaye mode : 1O, 1O_Unstretched, 1R, 1P, 2P, 2P_Unstretched, 1O3R, 4R, 4R_Interfered, 1O8R, 1P3R_TopPanorama, 1P2R_TopPanorama
Usage:
private void SetFisheyeDisplayMode(object sender, EventArgs e) { var ret = PlatformSDK.SetFisheyeDisplayMode(hChannel, PlatformSDK.EFisheyeDisplayMode.mode_1R); EventLog.Write("PlatformSDK.SetFisheyeDisplayMode Ret = {0:X}", ret); }
Error codes:
(0x80000001) : hChannel is null pointer (0x80700201) : hChannel is invalid (0x8070020d) : PlatformSDK.GetFisheyeMountType should be invoked before using PlatformSDK.SetFisheyeDisplayMode (0x80700217) : set fisheye camera display mode failed
Method:
int PlatformSDK.SetFisheyeMouseEvent(int hChannel, ref TMouseEvent mouseEvent);
Description:
User can pass mouse left key down/up, mouse move event to control fisheye rotation, and pass mouse wheel rotation value to control fisheye zoom in.
Parameters:
hChannel : The channel handle created from PlatformSDK.CreateLiveChannel or PlatformSDK.CreateNetFileChannel or PlatformSDK.CreateExportMediaFileChannel. mouseEvent : The mouse action.
Related structure:
public unsafe struct TMouseEvent { public EMouseEventType eventType; public int x; public int y; public int wheelRotation; }
Usage:
private void MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { mouseLeftDown = true; HandleMouseEvent(e, PlatformSDK.EMouseEventType.leftDown); } private void MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (mouseLeftDown) HandleMouseEvent(e, PlatformSDK.EMouseEventType.dragging); } private void MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { mouseLeftDown = false; HandleMouseEvent(e, PlatformSDK.EMouseEventType.leftUp); } private void MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { HandleMouseEvent(e, PlatformSDK.EMouseEventType.wheelRotation); } private void HandleMouseEvent(System.Windows.Forms.MouseEventArgs e, PlatformSDK.EMouseEventType eType) { PlatformSDK.TMouseEvent mouseEvent = new PlatformSDK.TMouseEvent(); mouseEvent.eventType = eType; mouseEvent.x = e.X; mouseEvent.y = e.Y; mouseEvent.wheelRotation = e.Delta; var ret = PlatformSDK.SetFisheyeMouseEvent(hChannel, ref mouseEvent); EventLog.Write("PlatformSDK.SetFisheyeMouseEvent Ret = {0:X}", ret); }
Error codes:
(0x80000001) : hChannel is null pointer (0x80000003) : mouseEvent is null pointer (0x80700201) : hChannel is invalid (0x80700218) : Set fisheye camera mouse event failed
Method:
int PlatformSDK.AudioOn(int hChannel, bool turn);
Description:
User can turn on or off the camera audio.
Parameters:
hChannel : Channel handle. turn : ture for turn on, false for turn off.
Usage:
void AudioOn(turn) { int channel = 0; PlatformSDK.CreateLiveChannel(ref channel, ...); PlatformSDK.AudioOn(ref channel, turn); }
Error codes:
(0x80000001) : hChannel is null pointer (0x80700201) : hChannel is invalid (0x80400000) : turn on or off audio failed