Ejemplo n.º 1
0
        private void _mediaMessageReader_MessageReceived(MdvrMediaMessage message)
        {
            if (message.MessageType == MdvrMediaMessageTypes.RealTimeVideo)
            {
                using (var ms = new MemoryStream(message.ByteList.ToArray()))
                {
                    using (var br = new BinaryReader(ms))
                    {
                        var videoData = new RealTimeVideoModel();

                        videoData.FrameType  = br.ReadInt32();
                        videoData.DataLength = br.ReadInt32();
                        videoData.Timestamp  = br.ReadInt64();
                        videoData.Buffer     = br.ReadBytes(videoData.DataLength);

                        if (Directory.Exists("Test") == false)
                        {
                            Directory.CreateDirectory("Test");
                        }

                        using (var fs = File.Create(string.Format("Test/{0}.bin", Guid.NewGuid())))
                        {
                            using (var bw = new BinaryWriter(fs))
                            {
                                bw.Write(videoData.Buffer);
                            }
                        }

                        using (var fs = File.OpenWrite(string.Format("Test/{0}.264", DevIDNO)))
                        {
                            using (var bw = new BinaryWriter(fs))
                            {
                                bw.Write(videoData.Buffer);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Read(byte[] bytes, int byteCnt)
        {
            using (var ms = new MemoryStream(bytes))
            {
                using (var br = new BinaryReader(ms))
                {
                    while (ms.Position < byteCnt)
                    {
                        switch (_field)
                        {
                        case MediaMessageFields.Start:
                            if (MdvrMessageHelper.GetString(br.ReadBytes(8)) == MdvrMessageHelper.MediaMessageStart)
                            {
                                _msg   = new MdvrMediaMessage();
                                _field = MediaMessageFields.MessageLength;
                            }
                            break;

                        case MediaMessageFields.MessageLength:
                            _msg.MessageLength = br.ReadInt32();
                            _field             = MediaMessageFields.MessageType;
                            break;

                        case MediaMessageFields.MessageType:
                            _msg.MessageType = br.ReadInt16();
                            _field           = MediaMessageFields.SerialNo;
                            break;

                        case MediaMessageFields.SerialNo:
                            _msg.SerialNo = br.ReadInt16();
                            _field        = MediaMessageFields.Time;
                            break;

                        case MediaMessageFields.Time:
                            _msg.Tick = br.ReadInt32();
                            _field    = MediaMessageFields.Data;
                            break;

                        case MediaMessageFields.Data:
                            if (_msg.ByteList.Count < _msg.DataLength)
                            {
                                _msg.ByteList.Add(br.ReadByte());
                                if (_msg.ByteList.Count == _msg.DataLength)
                                {
                                    _field = MediaMessageFields.End;
                                }
                            }
                            break;

                        case MediaMessageFields.End:
                            if (MdvrMessageHelper.GetString(br.ReadBytes(4)) == MdvrMessageHelper.MediaMessageEnd)
                            {
                                MessageReceived?.Invoke(_msg);
                            }
                            _field = MediaMessageFields.Start;
                            break;
                        }
                    }
                }
            }
        }