示例#1
0
        ///// <summary>
        ///// 获取流媒体配置的IP
        ///// </summary>
        ///// <param name="configPath"></param>
        ///// <returns></returns>
        //private static string GetLocalIp(string configPath)
        //{
        //    string ip = "";
        //    using (StreamReader sr = new StreamReader(configPath))
        //    {
        //        while (!sr.EndOfStream)
        //        {
        //            string str = sr.ReadLine();
        //            if (str.Contains("ipAddress"))
        //            {
        //                ip = str.Split('=')[1];
        //                break;
        //            }
        //        }
        //    }
        //    return ip;
        //}
        ///// <summary>
        ///// 获取流媒体配置的端口,适用flv和hls
        ///// </summary>
        ///// <param name="configPath"></param>
        ///// <returns></returns>
        //private static int GetMediaHttpPort(string configPath)
        //{
        //    int port=-1;
        //    using (StreamReader sr = new StreamReader(configPath))
        //    {
        //        while (!sr.EndOfStream)
        //        {
        //            string str = sr.ReadLine();
        //            if (str.Contains("httpPort"))
        //            {
        //                port = int.Parse(str.Split('=')[1]);
        //                break;
        //            }
        //        }
        //    }
        //    return port;
        //}
        static ushort MediaInit(string configPath)
        {
            MediaServer.Config config = new MediaServer.Config();
            config.ini_is_path   = 1;
            config.ini           = configPath;
            config.log_file_path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log");
            MediaServer.mk_env_init(ref config);
            ushort ret;

            ret = MediaServer.mk_http_server_start(mediaServerConfig.mk_http_port, 0);
            ret = MediaServer.mk_rtsp_server_start(mediaServerConfig.mk_rtsp_port, 0);
            ret = MediaServer.mk_rtmp_server_start(mediaServerConfig.mk_rtmp_port, 0);
            return(ret);
        }
示例#2
0
        static void Test1()
        {
            string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");

            MediaServer.Config config = new MediaServer.Config();
            config.ini_is_path = 1;
            config.ini         = configPath;
            MediaServer.mk_env_init(ref config);
            uint ret;

            ret = MediaServer.mk_http_server_start(8500, 0);
            ret = MediaServer.mk_rtsp_server_start(554, 0);
            ret = MediaServer.mk_rtmp_server_start(1935, 0);
            DoMedia.StartPlaySDK("fh", "sdklive1", "", "10.128.24.60", "admin", "0123456a?", "8000");
            Console.Read();
        }
示例#3
0
        static void SDKTest()
        {
            string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");

            MediaServer.Config config = new MediaServer.Config();
            config.ini_is_path = 1;
            config.ini         = configPath;
            MediaServer.mk_env_init(ref config);
            uint ret;

            ret = MediaServer.mk_http_server_start(8500, 0);
            ret = MediaServer.mk_rtsp_server_start(554, 0);
            ret = MediaServer.mk_rtmp_server_start(1935, 0);


            ctx = MediaServer.mk_media_create("__defaultVhost__", "fh", "sdklive", 0, 1, 1, 1, 0);
            MediaServer.mk_media_init_video(ctx, 0, 1280, 720, 25);
            MediaServer.mk_media_init_complete(ctx);


            bool m_bInitSDK = CHCNetSDK.NET_DVR_Init();

            CHCNetSDK.NET_DVR_SetLogToFile(0, "", true);
            CHCNetSDK.NET_DVR_USER_LOGIN_INFO struLogInfo = new CHCNetSDK.NET_DVR_USER_LOGIN_INFO();
            //设备IP地址或者域名
            byte[] byIP = System.Text.Encoding.Default.GetBytes("10.128.24.57");
            struLogInfo.sDeviceAddress = new byte[129];
            byIP.CopyTo(struLogInfo.sDeviceAddress, 0);

            //设备用户名
            byte[] byUserName = System.Text.Encoding.Default.GetBytes("admin");
            struLogInfo.sUserName = new byte[64];
            byUserName.CopyTo(struLogInfo.sUserName, 0);

            //设备密码
            byte[] byPassword = System.Text.Encoding.Default.GetBytes("123456a?");
            struLogInfo.sPassword = new byte[64];
            byPassword.CopyTo(struLogInfo.sPassword, 0);

            struLogInfo.wPort = 8000;//设备服务端口号
            CHCNetSDK.NET_DVR_DEVICEINFO_V40 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V40();
            int m_lUserID = CHCNetSDK.NET_DVR_Login_V40(ref struLogInfo, ref DeviceInfo);



            if (RealData == null)
            {
                RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack);//预览实时流回调函数
            }

            CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO();
            //lpPreviewInfo.hPlayWnd = RealPlayWnd.Handle;//预览窗口
            lpPreviewInfo.lChannel        = 1;    //预te览的设备通道
            lpPreviewInfo.dwStreamType    = 0;    //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
            lpPreviewInfo.dwLinkMode      = 0;    //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
            lpPreviewInfo.bBlocked        = true; //0- 非阻塞取流,1- 阻塞取流
            lpPreviewInfo.dwDisplayBufNum = 1;    //播放库播放缓冲区最大缓冲帧数
            lpPreviewInfo.byProtoType     = 0;
            lpPreviewInfo.byPreviewMode   = 0;
            IntPtr pUser         = new IntPtr();//用户数据
            int    m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, /*null*/ RealData, pUser);

            if (m_lRealHandle >= 0)//播放成功
            {
                //eSCallBack = new CHCNetSDK.PlayESCallBack(ESCallBack);
                //bool ret = CHCNetSDK.NET_DVR_SetESRealPlayCallBack(m_lRealHandle, eSCallBack, IntPtr.Zero);
                Task task = Task.Factory.StartNew(HIKDataInput);
            }
            Console.Read();
        }