You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.9 KiB
138 lines
3.9 KiB
namespace EC.Util.CameraSDK;
|
|
|
|
public class YuShiSDK : ICameraSDK
|
|
{
|
|
#region Attr
|
|
|
|
private IntPtr LoginId { get; set; } = IntPtr.Zero;
|
|
|
|
private IntPtr RealplayHandle { get; set; } = IntPtr.Zero;
|
|
|
|
#endregion Attr
|
|
|
|
public YuShiSDK(CameraInfo cameraInfo) : base(cameraInfo)
|
|
{
|
|
}
|
|
|
|
#region Base Method
|
|
|
|
public override bool Init()
|
|
{
|
|
bool ret = ConnectSuccess();
|
|
if (ret) return true;
|
|
|
|
YuShiOriSDK.NETDEV_DEVICE_LOGIN_INFO_S loginInfo = new();
|
|
loginInfo.szIPAddr = CameraInfo.Ip;
|
|
loginInfo.dwPort = CameraInfo.Port;
|
|
loginInfo.szUserName = CameraInfo.UserName;
|
|
loginInfo.szPassword = CameraInfo.Password;
|
|
YuShiOriSDK.NETDEV_SELOG_INFO_S logInfo = new();
|
|
LoginId = YuShiOriSDK.NETDEV_Login_V30(ref loginInfo, ref logInfo);
|
|
ret = ConnectSuccess();
|
|
|
|
return ret;
|
|
}
|
|
|
|
public override bool Destory()
|
|
{
|
|
bool ret = ConnectSuccess();
|
|
if (!ret) return true;
|
|
|
|
ret = YuShiOriSDK.NETDEV_Logout(LoginId);
|
|
if (ret) LoginId = IntPtr.Zero;
|
|
|
|
return ret;
|
|
}
|
|
|
|
public override bool ConnectSuccess()
|
|
{
|
|
return LoginId != IntPtr.Zero;
|
|
}
|
|
|
|
public override void BuildException()
|
|
{
|
|
int errCode = YuShiOriSDK.NETDEV_GetLastError();
|
|
if (errCode == 0) return;
|
|
throw CameraException.New(CameraInfo, errCode);
|
|
}
|
|
|
|
#endregion Base Method
|
|
|
|
#region Ptz Method
|
|
|
|
public override PtzInfo GetPtzInfo()
|
|
{
|
|
bool ret = ConnectSuccess();
|
|
if (!ret) return PtzInfo.Default;
|
|
|
|
YuShiOriSDK.NETDEV_PTZ_STATUS_S entity = new();
|
|
ret = YuShiOriSDK.NETDEV_PTZGetStatus(LoginId, 1, ref entity);
|
|
if (!ret) { BuildException(); return PtzInfo.Default; }
|
|
|
|
return PtzInfo.New(entity.fPanTiltX, entity.fPanTiltY, entity.fZoomX);
|
|
}
|
|
|
|
public override bool TryGetPtzInfo(out PtzInfo ptzInfo)
|
|
{
|
|
bool ret = ConnectSuccess();
|
|
if (!ret) { ptzInfo = PtzInfo.Default; return false; }
|
|
|
|
YuShiOriSDK.NETDEV_PTZ_STATUS_S entity = new();
|
|
ret = YuShiOriSDK.NETDEV_PTZGetStatus(LoginId, 1, ref entity);
|
|
if (!ret) { BuildException(); ptzInfo = PtzInfo.Default; return false; }
|
|
|
|
ptzInfo = PtzInfo.New(entity.fPanTiltX, entity.fPanTiltY, entity.fZoomX);
|
|
return true;
|
|
}
|
|
|
|
public override bool PtzMove(int cmd, int stop, int speed)
|
|
{
|
|
if (!ConnectSuccess()) return false;
|
|
if (stop == 1) cmd = YuShiOriSDK.ALLSTOP;
|
|
int channel = 1;
|
|
int flag = YuShiOriSDK.NETDEV_PTZControl_Other(LoginId, channel, cmd, speed);
|
|
return flag == YuShiOriSDK.TRUE;
|
|
}
|
|
|
|
public override bool PtzPreset(int cmd, int presetId)
|
|
{
|
|
if (!ConnectSuccess()) return false;
|
|
int channel = 1;
|
|
int flag = YuShiOriSDK.NETDEV_PTZPreset_Other(LoginId, channel, cmd, Array.Empty<byte>(), presetId);
|
|
return flag == YuShiOriSDK.TRUE;
|
|
}
|
|
|
|
#endregion Ptz Method
|
|
|
|
#region Video Method
|
|
|
|
public override void StartPlay(IntPtr hwnd)
|
|
{
|
|
if (!ConnectSuccess() || IsPlaying()) return;
|
|
YuShiOriSDK.NETDEV_PREVIEWINFO_S stPreviewInfo = new()
|
|
{
|
|
hPlayWnd = hwnd,
|
|
dwChannelID = 1,
|
|
dwStreamType = 0, // YuShiOriSDK.NETDEV_LIVE_STREAM_INDEX_E
|
|
dwLinkMode = 1, // YuShiOriSDK.NETDEV_PROTOCAL_E
|
|
dwFluency = 0, // YuShiOriSDK.NETDEV_PICTURE_FLUENCY_E
|
|
};
|
|
RealplayHandle = YuShiOriSDK.NETDEV_RealPlay(LoginId, ref stPreviewInfo, IntPtr.Zero, IntPtr.Zero);
|
|
if (RealplayHandle == IntPtr.Zero) BuildException();
|
|
}
|
|
|
|
public override void StopPlay()
|
|
{
|
|
if (!IsPlaying()) return;
|
|
int flag = YuShiOriSDK.NETDEV_StopRealPlay(RealplayHandle);
|
|
RealplayHandle = IntPtr.Zero;
|
|
if (flag == YuShiOriSDK.FALSE) BuildException();
|
|
}
|
|
|
|
public override bool IsPlaying()
|
|
{
|
|
return RealplayHandle != IntPtr.Zero;
|
|
}
|
|
|
|
#endregion Video Method
|
|
}
|