<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    樂樂隨筆

    綠葉

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      14 Posts :: 0 Stories :: 2 Comments :: 0 Trackbacks

     

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;


    //本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/doubaijun/archive/2009/04/07/4053868.aspx

    namespace HIKLib
    {
        interface  IHikClientAdviseSink
        {
            /******************************************************************
            在Setup時被調用,獲取總的播放長度.nLength為總的播放長度,以1/64秒為單位
            */
            //public abstract int OnPosLength(int nLength);

            /******************************************************************
             在Setup后被調用,表示URL已經被成功打開,sucess為1表示成功,0表示失敗
            */
            //public abstract int OnPresentationOpened(int success);

            /************************************************************************
            在Player被停止銷毀后調用
            */
            //public abstract int OnPresentationClosed();

            /************************************************************************
            未使用
            */
            //public abstract int OnPreSeek(uint uOldTime, uint uNewTime);

            /************************************************************************
            未使用
            */
            //public abstract int OnPostSeek(uint uOldTime, uint uNewTime);

            /************************************************************************
            未使用
            */
            //public abstract int OnStop();

            /************************************************************************
            在Pause時被調用,uTime目前都是0
            */
           // public abstract int OnPause(uint uTime);

            /************************************************************************
             在開始播放時調用,uTime目前都是0
             */
            //public abstract int OnBegin(uint uTime);

            /************************************************************************
            在隨機播放時調用,uTime目前都是0
            */
            //public abstract int OnRandomBegin(uint uTime);

            /************************************************************************
             在Setup前調用,pszHost表示正在連接的服務器
             */
            //public abstract int OnContacting(string pszHost);

            /************************************************************************
            在服務器端返回出錯信息是調用, pError中為出錯信息內容
            */
           // public abstract int OnPutErrorMsg(string pError);

            /************************************************************************
            未使用
             */
           // public abstract int OnBuffering(uint uFlag, uint uPercentComplete);

            //public abstract int OnChangeRate(int flag);

            //public abstract int OnDisconnect();

          
        /******************************************************************
     在Setup時被調用,獲取總的播放長度.nLength為總的播放長度,以1/64秒為單位
     */
             int OnPosLength(ulong nLength);

     /******************************************************************
         在Setup后被調用,表示URL已經被成功打開,sucess為1表示成功,0表示失敗
     */
            int OnPresentationOpened(int success);

      /************************************************************************
         在Player被停止銷毀后調用
         */
           int OnPresentationClosed();

      /************************************************************************
         未使用
         */
            int OnPreSeek(ulong uOldTime, ulong uNewTime);

      /************************************************************************
         未使用
         */
           int OnPostSeek(ulong uOldTime, ulong uNewTime);

      /************************************************************************
         未使用
      */
            int OnStop();

      /************************************************************************
         在Pause時被調用,uTime目前都是0
         */
             int OnPause(ulong uTime);

     /************************************************************************
         在開始播放時調用,uTime目前都是0
         */
             int OnBegin(ulong uTime);

         /************************************************************************
         在隨機播放時調用,uTime目前都是0
         */
             int OnRandomBegin(ulong uTime);

     /************************************************************************
         在Setup前調用,pszHost表示正在連接的服務器
         */
             int OnContacting(string pszHost);
       
     /************************************************************************
     在服務器端返回出錯信息是調用, pError中為出錯信息內容
     */
           int OnPutErrorMsg(string pError);
     
     /************************************************************************
        未使用
         */
            int OnBuffering(uint uFlag, ushort uPercentComplete);

            int OnChangeRate(int flag);

             int OnDisconnect();
        };

     

        public delegate int pDataRec(int sid, int iusrdata, int idatatype, StringBuilder pdata, int ilen);
        public delegate int pMsgBack(int sid, int opt, int param1, int param2);

     


        class hkClient
        {

            [DllImport("client.dll", SetLastError = true)]
            public static extern int HIKS_CreatePlayer(IHikClientAdviseSink pSink, IntPtr pWndSiteHandle, pDataRec pRecFunc, pMsgBack pMsgFunc, int TransMethod);

            [DllImport("client.dll", SetLastError = true)]
            public static extern int InitStreamClientLib();

            [DllImport("client.dll")]
            public static extern int FiniStreamClientLib();

            [DllImport("client.dll", SetLastError = true, CharSet = CharSet.Ansi)]
            public static extern int HIKS_OpenURL(int hSession, string pszURL, int iusrdata);

            [DllImport("client.dll", SetLastError = true, CharSet = CharSet.Auto)]
            public static extern int HIKS_Play(int hSession);
            [DllImport("client.dll")]
            public static extern int HIKS_RandomPlay(int hSession, int timepos);
            [DllImport("client.dll")]
            public static extern int HIKS_Pause(int hSession);
            [DllImport("client.dll")]
            public static extern int HIKS_Resume(int hSession);
            [DllImport("client.dll")]
            public static extern int HIKS_Stop(int hSession);
            [DllImport("client.dll")]
            public static extern int HIKS_GetCurTime(int hSession, ref  ushort utime);
            [DllImport("client.dll")]
            public static extern int HIKS_ChangeRate(int hSession, int scale);
            [DllImport("client.dll")]
            public static extern int HIKS_Destroy(int hSession);
            [DllImport("client.dll")]
            public static extern int HIKS_GetVideoParams(int hSession, ref  int ibri, ref int icon, ref int isat, ref int ihue);
            [DllImport("client.dll")]
            public static extern int HIKS_SetVideoParams(int hSession, int ibri, int icon, int isat, int ihue);
            [DllImport("client.dll")]
            public static extern int HIKS_PTZControl(int hSession, ushort ucommand, int iparam1, int iparam2, int iparam3, int iparam4);
            [DllImport("client.dll")]
            public static extern int HIKS_SetVolume(int hSession, ushort volume);
            [DllImport("client.dll")]
            public static extern int HIKS_OpenSound(int hSession, bool bExclusive);
            [DllImport("client.dll")]
            public static extern int HIKS_CloseSound(int hSession);
            [DllImport("client.dll")]
            public static extern int HIKS_ThrowBFrameNum(int hSession, uint nNum);
            [DllImport("client.dll")]
            public static extern int HIKS_GrabPic(int hSession, string szPicFileName, ushort byPicType);


        }

    }




    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using vvmc.util;
    using System.Threading;

    //本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/doubaijun/archive/2009/04/07/4053868.aspx
    // C# 流媒體服務器客戶端封裝

    namespace HIKLib
    {
        class StreamClient : IHikClientAdviseSink
        {
            // private inheritAdviseSink adviseSink;
            /// <summary>
            /// 播放的總時間
            /// </summary>
            private int m_totaltime;
            /// <summary>
            /// url是否被打開
            /// </summary>
            private int m_opened=-1;
            private void setOpened(int openedvalue) {
                lock (this)
                {
                    this.m_opened = openedvalue;
                }
            }
            private int m_Pause = -1;

            /// <summary>
            /// 播放句柄
            /// </summary>
            private int playSession = -1;
            public StreamClient()
            {
                  int ok;
                 ok= hkClient.InitStreamClientLib();
                 if (ok == -1)
                 {
                     //MessageBox.Show("初始化失敗!");
                     LogManager.WriteLog(LogFile.Error, "初始化流媒體庫失敗!");
                 }
                 Console.WriteLine("----------->初始化流媒體庫,返回值:{0}",ok);


            }
            /// <summary>
            /// 關閉是調用
            /// </summary>
            public void FiniStreamClientLib()
            {
                hkClient.FiniStreamClientLib();
            }

            /// <summary>
            /// 開始之前調用
            /// </summary>
            public int CreatePlayer(IntPtr mHand)
            {
                pMsgBack mb = new pMsgBack(MsgBack);
                //pDataRec dr = new pDataRec(DataRec);
                playSession = hkClient.HIKS_CreatePlayer(null, mHand, null, mb, 1);
                GC.KeepAlive(mb);
                //GC.KeepAlive(dr);
                if (playSession == -1)
                {
                    LogManager.WriteLog(LogFile.Error, "創建play句柄失敗!");
                }

                return playSession;

            }


            /// <summary>
            /// 根據URL,連接服務器
            /// </summary>
            /// <param name="hSession">。hSession 是Player 的標示,應該設置為HIKS_CreatePlayer 成功返回的新建Player 的標示</param>
            /// <param name="pszURL">pszURL 即為服務器的地址</param>
            /// <param name="iusrdata">iusrdata 為用戶數據。</param>
            /// <returns>返回值:成功返回 1,失敗返回-1。</returns>
            public int HIKS_OpenURL(string pszURL, int iusrdata)
            {
                int ok=-1;
                ///qq176122348
                ///
                try
                {
                    int icount = 0;
                    /**
                    while (this.m_opened == 0&&icount<10) {
                        Console.WriteLine("等待直到上個連接打開成功!");
                        Thread.Sleep(100);
                        icount++;
                    }
                     */
                    lock (this)
                    {
                        Console.WriteLine("等待結束時,opened={0},pause={1},threadId:{2}", this.m_opened, this.m_Pause, Thread.CurrentThread.ManagedThreadId);
                        this.setOpened(0);
                        this.m_Pause = 0;
                        ok = hkClient.HIKS_OpenURL(playSession, pszURL, iusrdata);
                        if (ok == -1)
                        {
                            LogManager.WriteLog(LogFile.Error, "連接服務器失敗!");
                        }
                        else
                        {
                            LogManager.WriteLog(LogFile.Error, "連接服務器成功!");
                        }
                    }
                }catch(Exception ex){
                    LogManager.WriteLog(LogFile.Error, "HIKS_OpenURL,異常原因:"+ex.Message);
                }
                return ok;


            }

            public int DataRec(int sid, int iusrdata, int idatatype, StringBuilder pdata, int ilen) {
               
                LogManager.WriteLog(LogFile.Error, "接收到數據.........");
                return 0;
            }

            private int  MsgBack(int sid, int opt, int param1, int param2)
            {

                Console.WriteLine("msgBack:opt={0},param1={1},param2={2}",opt,param1,param2);
                int len = -1;
                switch (opt)
                {
                    case 1:
                        m_totaltime = param1;
                        break;
                    case 2:
                        //m_opened = param1;
                        this.setOpened(param1);
                        break;
                    case 3:
                        break;
                    case 4:
                        break;
                    case 5:
                        break;
                    case 6:
                        break;
                    case 7://暫停
                        this.m_Pause = 1;

                        break;
                    case 8:
                        break;
                    case 9:
                        break;
                    case 10:
                        break;
                    case 11:
                        break;
                    case 12:
                        break;
                    case 13:
                        //m_speeded = true;
                        break;
                    case 14:
                        //PostMessage(WM_DISCONNECT,0,0);
                        break;
                    default:
                        break;
                }
                return 0;
            }

            /// <summary>
            /// 播放
            /// </summary>
            /// <returns></returns>
            public int HIKS_Play()
            {
                int ok = hkClient.HIKS_Play(playSession);
                if (ok == -1)
                {
                    //MessageBox.Show("播放失敗!");
                    LogManager.WriteLog(LogFile.Error, "Play播放失敗!");
                 

                }
                else
                {
                    LogManager.WriteLog(LogFile.Error, "Play播放成功!");
                 
                }

                return ok;

            }
            /// <summary>
            /// 停止播放
            /// </summary>
            /// <returns></returns>
            public int HIKS_Pause()
            {
              
               int ok= hkClient.HIKS_Pause(playSession);
               if (ok == -1)
               {
                   LogManager.WriteLog(LogFile.Error, "暫停播放失敗!");

               }
               else
               {

                   LogManager.WriteLog(LogFile.Error, "暫停播放成功!");
               }

               return ok;

            }

            public int HIKS_Resume()
            {
                int ok = hkClient.HIKS_Resume(playSession);
                if (ok == -1)
                {
                    LogManager.WriteLog(LogFile.Error, "恢復播放失敗!");

                }
                else
                {

                    LogManager.WriteLog(LogFile.Error, "恢復播放成功!");
                }

                return ok;

            }
            public int HIKS_Stop()
            {
                int ok = hkClient.HIKS_Stop(playSession);
                if (ok == -1)
                {
       
                    LogManager.WriteLog(LogFile.Error, "停止播放失敗!");

                }
                else
                {
                    //log.Writelog("停止播放成功!");
                }

                return ok;

            }
            public int HIKS_GetCurTime(ref  ushort utime)
            {
                int ok = hkClient.HIKS_GetCurTime(playSession, ref utime);


                if (ok == -1)
                {
                  
                    LogManager.WriteLog(LogFile.Error, "獲取播放時間失敗!");
                 

                }
                else
                {

                    //log.Writelog("獲取播放時間成功!");
                }

                return ok;

            }
            /// <summary>
            /// 作用:改變播放速率,在快進或慢進的時候用。
            /// </summary>
            /// <param name="scale"></param>
            /// <returns>返回值:成功返回 0,失敗返回-1。</returns>
            public int HIKS_ChangeRate(int scale)
            {
                int ok = hkClient.HIKS_ChangeRate(playSession,2);


                if (ok == -1)
                {
                    MessageBox.Show("改變速度失敗!");

                   // log.Writelog("改變速度失敗!");

                }
                else
                {

                    //log.Writelog("改變速度成功!");
                }

                return ok;

            }
            /// <summary>
            /// 作用:銷毀Player,只在HIKS_OpenURL 函數失敗的請況下調用。
            /// </summary>
            /// <returns>返回值:成功返回 0,失敗返回-1。</returns>
            public int HIKS_Destroy()
            {
                int ok = hkClient.HIKS_Destroy(playSession);


                if (ok == -1)
                {
                 
                    LogManager.WriteLog(LogFile.Error, "銷毀失敗!");

                }
                else
                {

                   // log.Writelog("銷毀成功!");
                }

                return ok;

            }

            /// <summary>
            /// 聲音控制
            /// </summary>
            /// <param name="volume"></param>
            /// <returns></returns>
            public int HIKS_SetVolume(ushort volume)
            {

                return hkClient.HIKS_SetVolume(playSession, volume);
            }

            /// <summary>
            /// 作用:打開聲音播放。hSession 是Player 的標示。bExclusive 表示打開聲音
            //的方式,false 表示共享打開,true 表示獨占打開。
            /// </summary>
            /// <param name="bExclusive"></param>
            /// <returns></returns>
            public int HIKS_OpenSound(bool bExclusive)
            {
                return hkClient.HIKS_OpenSound(playSession, bExclusive);

            }
            /// <summary>
            ///關閉聲音
            /// </summary>
            /// <returns></returns>
            public int HIKS_CloseSound()
            {
                return hkClient.HIKS_CloseSound(playSession);

            }
            /// <summary>
            /// :本地抓圖。hSession 表示Player 的標示。szPicFileName 表示文件名。
            //byPicType 表示圖片的類型,0 表示bmp 圖片,1 表示jpeg 圖片。
            /// </summary>
            /// <param name="szPicFileName"></param>
            /// <param name="byPicType"></param>
            /// <returns></returns>
            public int HIKS_GrabPic(string szPicFileName, ushort byPicType)
            {
                Random ra=new Random();
                return hkClient.HIKS_GrabPic(playSession,System.DateTime.Now.Date.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + ra.Next().ToString(), 0);

            }

            /// <summary>
            /// 作用:獲取視頻參數。hSession 是Player 的標示
            /// </summary>
            /// <param name="ibri">是亮度</param>
            /// <param name="icon">是對比度</param>
            /// <param name="isat">是飽和度</param>
            /// <param name="ihue">是色調</param>
            /// <returns>成功返回 0,失敗返回-1。</returns>
            public int HIKS_GetVideoParams(ref  int ibri, ref int icon, ref int isat, ref int ihue)
            {

                return hkClient.HIKS_GetVideoParams(playSession,ref  ibri, ref icon, ref isat, ref ihue);
            }
            /// <summary>
            /// 作用:設置視頻參數。hSession 是Player 的標示, ibri 是亮度,icon 是對比度,
            ///值域范圍:ibri 1-10, icon 1-10, isat 1-10, ihue 1-10。
            /// </summary>
             /// <param name="ibri">是亮度</param>
            /// <param name="icon">是對比度</param>
            /// <param name="isat">是飽和度</param>
            /// <param name="ihue">是色調</param>
            /// <returns>成功返回 0,失敗返回-1。</returns>
            public int HIKS_SetVideoParams(int ibri, int icon, int isat, int ihue)
            {

                return hkClient.HIKS_SetVideoParams( playSession,  ibri,  icon,  isat,  ihue);
            }

            /// <summary>
            /// 云臺控制
            /// </summary>
            /// <param name="ucommand"></param>
            /// <param name="iparam1"></param>
            /// <param name="iparam2"></param>
            /// <param name="iparam3"></param>
            /// <param name="iparam4"></param>
            /// <returns></returns>
            public int HIKS_PTZControl(ushort ucommand, int iparam1, int iparam2, int iparam3, int iparam4)
            {
                return hkClient.HIKS_PTZControl(playSession,ucommand, iparam1,  iparam2,  iparam3,  iparam4);
            }

            /// <summary>
            /// 隨即播放
            /// </summary>
            /// <param name="timepos"></param>
            /// <returns></returns>
            public int HIKS_RandomPlay(int timepos)
            {
                return 0;

            }
            /**
            public  int OnPosLength(ulong nLength)
            {
                return 0;
            }

            public  int OnPresentationOpened(int success)
            {
                Console.WriteLine("Url Opened Successed");
                return 0;
            }

            public  int OnPresentationClosed()
            {
                return 0;
            }

            public  int OnPreSeek(ulong uOldTime, ulong uNewTime)
            {
                return 0;
            }

            public  int OnPostSeek(ulong uOldTime, ulong uNewTime)
            {
                return 0;
            }

            public  int OnStop()
            {
                return 0;
            }

            public  int OnPause(ulong uTime)
            {
                return 0;
            }

            public override int OnBegin(ulong uTime)
            {
                return 0;
            }

            public  int OnRandomBegin(ulong uTime)
            {
                return 0;
            }

            public  int OnContacting(string pszHost)
            {
                return 0;
            }

            public  int OnPutErrorMsg(string pError)
            {
                return 0;
            }

            public  int OnBuffering(uint uFlag, uint uPercentComplete)
            {
                return 0;
            }

            public  int OnChangeRate(int flag)
            {
                return 0;
            }

            public  int OnDisconnect()
            {
                return 0;
            }
            */

     

     

            #region IHikClientAdviseSink 成員

            int IHikClientAdviseSink.OnPosLength(ulong nLength)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnPresentationOpened(int success)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnPresentationClosed()
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnPreSeek(ulong uOldTime, ulong uNewTime)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnPostSeek(ulong uOldTime, ulong uNewTime)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnStop()
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnPause(ulong uTime)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnBegin(ulong uTime)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnRandomBegin(ulong uTime)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnContacting(string pszHost)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnPutErrorMsg(string pError)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnBuffering(uint uFlag, ushort uPercentComplete)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnChangeRate(int flag)
            {
                throw new Exception("The method or operation is not implemented.");
            }

            int IHikClientAdviseSink.OnDisconnect()
            {
                throw new Exception("The method or operation is not implemented.");
            }

            #endregion
        }
    }


    posted on 2010-02-05 17:31 綠葉 閱讀(2318) 評論(1)  編輯  收藏 所屬分類: 海康sdk

    Feedback

    # re: 調用海康SDK 2011-03-01 20:00 往事如煙
    我也正在研究海康SDK 有時間交流一下QQ:12348328  回復  更多評論
      


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲人成色4444在线观看| 久久久久亚洲AV成人网| 亚洲成人福利网站| 51精品视频免费国产专区| 亚洲福利视频网站| 国产h视频在线观看网站免费| 777亚洲精品乱码久久久久久| 亚洲免费视频在线观看| 亚洲美女视频网址| 一级女人18毛片免费| 亚洲日韩看片无码电影| 日韩一品在线播放视频一品免费| 亚洲乱码日产精品一二三| 国产v片免费播放| 成人性生交大片免费看好| 精品亚洲麻豆1区2区3区| 在线观看日本免费a∨视频| 国内精品久久久久影院亚洲| 日韩黄色免费观看| 男女一边桶一边摸一边脱视频免费 | 亚洲AV综合色区无码一二三区 | 永久免费观看黄网站| 亚洲精品无码永久中文字幕| 久久久免费精品re6| 亚洲中文无码永久免| 亚洲午夜日韩高清一区| 99精品视频免费在线观看| 亚洲天然素人无码专区| 亚洲午夜精品第一区二区8050| 久久久久久夜精品精品免费啦| 自拍日韩亚洲一区在线| 亚洲精品麻豆av| 最近中文字幕国语免费完整| 亚洲一区二区三区在线观看网站 | 无码免费午夜福利片在线| 羞羞视频在线观看免费| 亚洲系列国产精品制服丝袜第 | 亚洲AV无码不卡无码| 精品久久久久国产免费| 一个人免费观看视频在线中文 | 国产精品亚洲综合一区|