Esempio n. 1
0
        /// <summary>
        /// body的组成 : 5|DateType
        /// </summary>
        /// <param name="requestInfo"></param>
        private int handleWebCommand(MyUdpRequestInfo requestInfo)
        {
            var      startTime = DateTime.Now;
            DateTime endTime;
            int      seconds = HandleUdpUtils.getLasingTime(requestInfo.Body, out startTime, out endTime);

            if (seconds == 0)
            {
                LOG.Error(requestInfo.SessionID + "|获取录像持续时间失败!");
                return(0);
            }
            string privateKey = "";

            PRIVATE_KEY.TryGetValue(requestInfo.SessionID, out privateKey);



            if (!addVideoPackageModel(requestInfo.SessionID, privateKey, startTime, endTime, seconds))
            {
                Console.WriteLine(requestInfo.SessionID + "|添加失败!");
                LOG.Error(requestInfo.SessionID + "|添加失败!");//TODO 存在更新的操作
                return(-1);
            }
            else
            {
                Console.WriteLine(requestInfo.SessionID + "|添加成功!");
                LOG.Info(requestInfo.SessionID + "|添加成功!");
                return(1);
            }
        }
        /// <summary>
        /// 过滤器接受信息 解析byte[]
        /// </summary>
        /// <param name="readBuffer"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        /// <param name="toBeCopied"></param>
        /// <param name="rest"></param>
        /// <returns></returns>
        public MyUdpRequestInfo Filter(byte[] readBuffer, int offset, int length, bool toBeCopied, out int rest)
        {
            var endFlag = HandleUdpUtils.getEndFlagStr(readBuffer, length);

            if (!endFlag.Equals(HandleUdpUtils.IMG_END_FLAG) || !endFlag.Equals(HandleUdpUtils.WEB_END_FLAG)) //判断结束标志
            {
                int    endFlagSize = 2;
                string privateKey  = HandleUdpUtils.getPrivateKey(readBuffer);
                string sesssionId  = HandleUdpUtils.getMachineCode(readBuffer); //machineCode 当成sessionId
                rest = 0;
                byte[] body = readBuffer.Skip(
                    HandleUdpUtils.MACHINE_CODE_LENGTH).Take(length - HandleUdpUtils.MACHINE_CODE_LENGTH - endFlagSize).ToArray();
                return(new MyUdpRequestInfo(privateKey, sesssionId)
                {
                    Body = body
                });
            }
            else
            {
                rest = 0;
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 处理设备发来的视频
        /// </summary>
        /// <param name="requestInfo"></param>
        private void handleDeviceInfo(MyUdpRequestInfo requestInfo)
        {
            VideoPackageModel videoModel = getVideoPackage(requestInfo.SessionID);

            if (videoModel == null || requestInfo.Body.Length < MIN_IMG_SIZE)
            {
                return;
            }

            MemoryStream stream = null;

            stream = new MemoryStream(requestInfo.Body);
            Bitmap img = null;

            try
            {
                img = HandleUdpUtils.BytesToBitmap(requestInfo.Body);
                // img.Save("D:\\JGHPCXReadVersionD\\video\\001\\test.jpg");
                videoModel.wirteVideo(img);
            }
            catch (Exception e)
            {
                LOG.Error(requestInfo.SessionID + "|" + e.ToString());
                Console.WriteLine(requestInfo.SessionID + "|" + e.ToString());
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
                if (img != null)
                {
                    img.Dispose();
                }
            }
        }