Ejemplo n.º 1
0
        //static bool input_data_flag = false;
        //static Dictionary<string, Queue<byte[]>> dic_data = new Dictionary<string, Queue<byte[]>>();
        //static List<Api_HIK> api_HIKs = new List<Api_HIK>();
        //static Queue<byte[]> queue = new Queue<byte[]>();
        public static string StartPlaySDK(string app, string stream, string device_type, string device_ip, string device_username, string device_password, string device_port)
        {
            string msg = $"app:{app},stream:{stream},,device_ip:{device_ip},device_username:{device_username},device_password:{device_password},device_port:{device_port}     ";
            IntPtr ctx = MediaServer.mk_media_create("__defaultVhost__", app, stream, 0, 1, 1, 1, 0);

            MediaServer.mk_media_init_video(ctx, 0, 1280, 720, 25);
            MediaServer.mk_media_init_complete(ctx);
            string key = GetKey(app, stream);

            if (dic_playProxy_media.ContainsKey(key))
            {
                return(msg + "已经在推流:" + key);
            }

            Api_HIK api_HIK = new Api_HIK();

            api_HIK.SetDataCallBack(
                (byte[] psData, string callback_key) =>
            {
                if (dic_playProxy_media.ContainsKey(callback_key))
                {
                    MediaServer.mk_media_input_ps(dic_playProxy_media[callback_key].ctx, psData.ToArray(), psData.Length);
                }
            }
                );

            //Api_HIK.PSDATACALLBACK pSDATACALLBACK = test;
            //Api_HIK.Instance.SetDataCallBack(pSDATACALLBACK);
            //Task task = Task.Factory.StartNew(PsFrameInput);
            int playHandle = api_HIK.Play(device_ip, device_username, device_password, device_port, key);

            if (playHandle < 0)
            {
                return(msg + "失败");
            }
            dic_playProxy_media.Add(key, new MediaCache()
            {
                ctx = ctx, mediaSrcType = MediaSrcType.sdk, playHandle = playHandle
            });
            return(msg + "成功");
        }
Ejemplo n.º 2
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();
        }