<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  回復  更多評論
      


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


    網站導航:
     
    主站蜘蛛池模板: 免费中文熟妇在线影片| 欧洲人免费视频网站在线| av无码国产在线看免费网站 | 羞羞漫画小舞被黄漫免费| 国内免费高清在线观看| 亚洲午夜无码久久久久小说| 毛片免费观看的视频在线| 成人亚洲国产va天堂| 国产美女无遮挡免费网站| 窝窝影视午夜看片免费| 国产亚洲精品福利在线无卡一| 国产免费区在线观看十分钟| 亚洲中文字幕无码久久精品1 | 精品一区二区三区无码免费视频| 日韩精品一区二区亚洲AV观看| 免费看男女下面日出水来| 亚洲男同gay片| 亚洲福利精品电影在线观看| 丁香花在线观看免费观看图片| 亚洲AV无码一区二区乱子伦| 57pao一国产成永久免费| 中中文字幕亚洲无线码| 国产成人免费ā片在线观看| 国产在线精品观看免费观看| 精品亚洲麻豆1区2区3区| 成年在线观看免费人视频草莓| 午夜成人无码福利免费视频| 亚洲第一中文字幕| 妞干网免费视频在线观看| 一级毛片试看60分钟免费播放| 亚洲AV一宅男色影视| 国产免费av片在线看| 一区免费在线观看| 亚洲综合区图片小说区| 国产免费久久精品久久久| a级毛片免费观看视频| 亚洲日本人成中文字幕| 日韩精品亚洲aⅴ在线影院| 57pao一国产成视频永久免费| 国产亚洲精品91| 亚洲韩国在线一卡二卡|