用C#封装海康HC系列音视频卡网络端户端SDK

    技术2022-05-11  74

    //作者:聂飞   个人主页 http://niefei.f81.net 转载请保留

    using System;using System.Runtime.InteropServices;using System.Drawing;

    namespace PCDvrMonitor{ public  enum SEND_MODE{UDPMODE=0,TCPMODE,MULTIMODE,DIALING,AUDIODETACH};

     public  enum DISP_MODE {NORMALMODE=0,OVERLAYMODE};

     public  enum AUDIO_MODE{SINGLEAUDIO=1,MULTIAUDIO};

     public enum VideoRGBYUVFormat:uint {  vfGeneric                = 0xffffffff,  vfNone                   = 0x80000000,  vfRGB8A_233              = 0x00000001,  vfRGB8R_332              = 0x00000002,  vfRGB15Alpha             = 0x00000004,  vfRGB16                  = 0x00000008,  vfRGB24                  = 0x00000010,  vfRGB24Alpha             = 0x00000020,     vfYUV420Planar           = 0x00000040,  vfYUV422Planar           = 0x00000080,  vfYUV411Planar           = 0x00000100,  vfYUV420Interspersed     = 0x00000200,  vfYUV422Interspersed     = 0x00000400,  vfYUV411Interspersed     = 0x00000800,  vfYUV422Sequence         = 0x00001000,   /* U0, Y0, V0, Y1:  For VO overlay */  vfYUV422SequenceAlpha    = 0x00002000,     /* U0, Y0, V0, Y1:  For VO overlay, with low bit for alpha blending */  vfMono                   = 0x00004000,  /* 8 bit monochrome */

      vfYUV444Planar           = 0x00008000,

      vfDTVCMPlanar            = 0x00010000,  vfDTVCMSequence          = 0x00020000,

      vfYInterleavedUV420      = 0x00040000,  /* YUV420 output by TM2 mpeg2 */

      vfYUV422PlanarAlpha4     = 0x00080000

     }                    /* can be OR'ed */  public struct DISPLAY_PARA {  public int bToScreen;  public int bToVideoOut;  public int nLeft;  public int nTop;  public int nWidth;  public int nHeight;  public VideoRGBYUVFormat format; }

      public struct CLIENT_VIDEOINFO {  public  byte   m_bRemoteChannel;  public  byte   m_bSendMode;  public  byte  m_nImgFormat;  // =0 main channel ; = 1 sub channel  public string m_sIPAddress;  public string m_sUserName;  public string m_sUserPassword;  public bool    m_bUserCheck;  public System.IntPtr   m_hShowVideo; }

     public struct CLIENT_CARDINFO {  public byte    m_bRemoteChannel;  public byte    m_bSendMode;  public byte    m_bRight;  public string    m_sIPAddress;  public string    m_sUserName;  public string    m_sUserPassword;  public bool    m_bUserCheck;  public DISPLAY_PARA displaypara; }

     /// <summary> /// 读实时数据回调 /// </summary> public delegate void ReadDataCallBack(UInt32 nPort,[MarshalAs(UnmanagedType.LPArray)] byte[] pPacketBuffer,UInt32 nPacketSize);

     /// <summary> /// 捕图回调 /// </summary> public delegate void CapPicFun(int StockHandle, [MarshalAs(UnmanagedType.LPArray,SizeConst=152064)] byte[] pBuf,int nSize,int nWidth,int nHeight,int nStamp,int nType,int nReceaved);

        /// <summary>    /// 画    /// </summary> public delegate void DrawFun(int StockHandle,System.Drawing.Graphics  hDc,int nUser);

     /// <summary> /// 加密 /// </summary> public delegate void DecryptFun (int nFrameType,[MarshalAs(UnmanagedType.LPArray)] byte[] pEncryptData,int nEncryptDataSize,[MarshalAs(UnmanagedType.LPArray)] byte[,]  ppDecryptData, out int  pDecryptDataSize,int nReserved);

     

     /// <summary> /// PcHikClient 的摘要说明。 /// </summary> public class PcHikClient {  public PcHikClient()  {

      }

      public static readonly uint WM_USER                        = 0x0400;       public static readonly int  RECDATAERR= 0 ;  public static readonly int  PLAYERR= 1;  public static readonly int REFUSED =2;  public static readonly int VERSIONERR =3;  public static readonly int PLAYERBUSY =4;  public static readonly int GETSTRING =10;

      public static readonly int SUPPORT_DDRAW = 1 ;  public static readonly int SUPPORT_BLT      =   2 ;  public static readonly int SUPPORT_BLTFOURCC=   4 ;  public static readonly int SUPPORT_BLTSHRINKX=  8 ;  public static readonly int SUPPORT_BLTSHRINKY=  16;  public static readonly int SUPPORT_BLTSTRETCHX= 32;  public static readonly int SUPPORT_BLTSTRETCHY= 64;  public static readonly int SUPPORT_CPU        = 128;

      public static readonly int T_UYVY  =1;  public static readonly int T_YV12  =3;  public static readonly int T_RGB32  =7;

      [DllImport("hikclient.dll")]  public static extern int  MP4_ClientStart(ref CLIENT_VIDEOINFO pClientinfo,ReadDataCallBack x);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientStop(int StockHandle);

      [DllImport("hikclient.dll")]  public static extern int  MP4_ClientGetState(int StockHandle);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientStopCapture(int StockHandle);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientStartCapture(int StockHandle);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientStartCaptureFile(int StockHandle, string FileName);

      [DllImport("hikclient.dll")]  public static extern UInt16 MP4_ClientGetServerChanNum(string m_sIPAddress);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientCommandtoServer(string m_lAddrIP, string m_sCommand,System.UInt16  m_wLen);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientCommandtoServer_Handle(int StockHandle,out string m_sCommand,System.UInt16 m_wLen);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientStartup(uint nMessage,System.IntPtr  hWnd);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientCleanup();

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientShut(string m_lAddrIP,char cChannel);

      [DllImport("hikclient.dll")]  public static extern void MP4_ClientReadLastMessage( string m_sIP,out string m_sCommand, out System.UInt16 m_wLen);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientAudioVolume(System.UInt16  wVolume);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientAudioStart(int StockHandle);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientAudioStop();

      [DllImport("hikclient.dll")]  public static extern int  MP4_ClientIsSupport();

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientSetBufferNum(int StockHandle,System.Int16  wBufNum);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientSetNetPort(System.UInt16  dServerPort,UInt16 dClientPort);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientSetTTL( char cTTLVal);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientSetPlayDelay(int StockHandle,UInt16 DelayLen);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientSetWait(UInt32 dEachWaitTime,UInt32 dTrynum);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientSetShowMode(UInt32 dShowType,System.Drawing.Color  colorKey);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientSetQuality(int StockHandle,UInt16 wPicQuality);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientSetCapPicCallBack(int StockHandle,CapPicFun x);

      [DllImport("hikclient.dll")]   public static extern bool  MP4_ClientSavePicFile( [MarshalAs(UnmanagedType.LPArray)] byte[] pBuf,int nSize,int nWidth,int nHeight,int nType,  string sFileName);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientThrowBFrame(int StockHandle,UInt32 dNum);

      [DllImport("hikclient.dll")]  public static extern uint  MP4_ClientGetFrameNum(int StockHandle);

      [DllImport("hikclient.dll")]  public static extern uint  MP4_ClientGetSdkVersion();

      //new  [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientCastGroup(int StockHandle,out string sIP,UInt16 wPort);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientAudioMode(UInt16 wMode);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientAudioStartShare(int StockHandle);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientAudioStopShare(int StockHandle);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientRigisterDrawFun(int StockHandle,DrawFun x,int nUser);

      //decode card   [DllImport("hikclient.dll")]  public static extern int    MP4_ClientInitDevice_Card(out int pDeviceTotal);

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientInitDDraw_Card(System.IntPtr  hParent,System.Drawing.Color  colorKey);

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientReleaseDevice_Card();

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientReleaseDDraw_Card();

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientStart_Card(ref CLIENT_CARDINFO pClientinfo,int nChannelNum,ReadDataCallBack x);

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientResetPara_Card(int StockHandle,out DISPLAY_PARA pPara);

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientAudioStop_Card(int StockHandle);

      /// <summary>  /// 调用时 默认为bAudioPreview true  /// </summary>  /// <param name="StockHandle"></param>  /// <param name="bAudioPreview"></param>  /// <returns></returns>  [DllImport("hikclient.dll")]  public static extern int    MP4_ClientAudioStart_Card(int StockHandle,bool bAudioPreview);

      

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientAudioVolume_Card(int StockHandle,uint nVolume);

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientRefreshSurface_Card();

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientClearSurface_Card();

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientRestoreSurface_Card();

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientGetSerialNo_Card(int nChannelNum,out uint pDeviceSerialNo);

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientCapPicFile_Card(int StockHandle,out string  sFileName);

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientSetDspErrMsg_Card(uint nMessage,System.UIntPtr  hWnd);

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientResetDSP_Card(int nChannelNum);

      [DllImport("hikclient.dll")]  public static extern int    MP4_ClientGetDevice_Card(int nChannelNum,object phChannel);

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientSetDecryptCallback(  DecryptFun x );

      [DllImport("hikclient.dll")]  public static extern bool MP4_ClientCleanBuffer(int nPort,int nCleanType);

      /// <summary>  ///   /// </summary>  /// <param name="strFirstMRIP"></param>  /// <param name="strSecondMRIP"></param>  /// <param name="wFirstMRPort"></param>  /// <returns></returns>  [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientSetMR(String strFirstMRIP,String strSecondMRIP,UInt16 wFirstMRPort);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientSetDisplayType(int StockHandle,int nType);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientSetVideoPara(int StockHandle,UInt32 nRegionNum, int nBrightness, int nContrast, int nSaturation, int nHue);

      [DllImport("hikclient.dll")]  public static extern bool  MP4_ClientGetVideoPara(int StockHandle,UInt32 nRegionNum, out int pBrightness, out int pContrast, out int pSaturation, out int pHue);

      [DllImport("hikclient.dll")]  public static extern int  MP4_ClientStart_Other(CLIENT_CARDINFO pClientinfo,ReadDataCallBack x);

      [DllImport("hikclient.dll")]  public static extern int  MP4_ClientStart_Card_Other(ref CLIENT_CARDINFO pClientinfo,int nChannelNum,ReadDataCallBack x);

     

     }} 


    最新回复(0)