Exemple #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 + "成功");
        }
Exemple #2
0
 static void HIKDataInput()
 {
     while (true)
     {
         try
         {
             if (queue.Count > 0)
             {
                 byte[] psData = queue.Dequeue();
                 if (psData[0] == 0 && psData[1] == 0 && psData[2] == 1 && psData[3] == 186)
                 {
                     if (cache.Count != 0)
                     {
                         MediaServer.mk_media_input_ps(ctx, cache.ToArray(), cache.Count);
                         cache.Clear();
                     }
                     cache.AddRange(psData);
                 }
                 else if (psData[0] == 0 && psData[1] == 0 && psData[2] == 1 && psData[3] == 223)
                 {
                     if (cache.Count != 0)
                     {
                         cache.AddRange(psData);
                     }
                 }
                 else if (psData[0] == 0 && psData[1] == 0 && psData[2] == 1 && psData[3] == 224)
                 {
                     if (cache.Count != 0)
                     {
                         cache.AddRange(psData);
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
             Console.WriteLine(ex.StackTrace);
         }
     }
 }