Beispiel #1
0
        public void TestPacketBase_string_more()
        {
            string str = "testString";

            byte[] nullBuffer = PacketBase.GetBytes(str);
            using (MemoryStream ms = new MemoryStream(nullBuffer))
            {
                Assert.AreEqual(str, PacketBase.ReadString(ms));
            }
        }
        public new static UniviewStreamPacket Decode(MemoryStream ms)
        {
            DateTime time   = PacketBase.ReadTime(ms);
            DataType type   = (DataType)PacketBase.ReadInt(ms);
            string   dTag   = PacketBase.ReadString(ms);
            int      length = PacketBase.ReadInt(ms);

            byte[] buf = PacketBase.ReadByteArray(ms, length);
            return(new UniviewStreamPacket(time, type, buf, dTag));
        }
        public static UniviewHeaderPacket Decode(MemoryStream ms)
        {
            int videoType = PacketBase.ReadInt(ms);

            if (videoType != (int)VideoType.Uniview)
            {
                return(null);
            }
            int    streamId   = PacketBase.ReadInt(ms);
            string streamName = PacketBase.ReadString(ms);
            string streamUrl  = PacketBase.ReadString(ms);

            return(new UniviewHeaderPacket(streamId, streamName, streamUrl));
        }
Beispiel #4
0
        public void TestPacketBase_string_null()
        {
            string str = null;

            byte[] nullBuffer = PacketBase.GetBytes(str);
            using (MemoryStream ms = new MemoryStream(nullBuffer))
            {
                Assert.IsNull(PacketBase.ReadString(ms));
            }
            str = string.Empty;
            byte[] buffer = PacketBase.GetBytes(str);
            using (MemoryStream ms = new MemoryStream(buffer))
            {
                Assert.AreEqual(string.Empty, PacketBase.ReadString(ms));
            }
        }
        private void onReceived(object sender, ReceiveEventArgs args)
        {
            if (args.ByteLength > 0)
            {
                using (MemoryStream ms = new MemoryStream(args.ReceivedBytes))
                {
                    int code = PacketBase.ReadInt(ms);
                    //Console.WriteLine("{0} - {1}", (ParamCode)code, args.ByteLength);
                    switch ((ParamCode)code)
                    {
                    case ParamCode.TimePeriods:
                        //接收所有有效视频分布
                        onTimePeriodsAll(VideoTimePeriodsPacket.Decode(ms).TimePeriods);
                        break;

                    case ParamCode.VideoBaseInfo:
                        //设置视频基本信息
                        onVideoBase(VideoBasePacket.Decode(ms));
                        break;

                    case ParamCode.DownloadProgress:
                        //接收推送的下载进度。
                        onTimePeriodsDownloaded(VideoTimePeriodsPacket.Decode(ms).TimePeriods);
                        break;

                    case ParamCode.VideoPacket:
                        //接收视频包数据流
                        onVideoStreams(VideoStreamsPacket.Decode(ms));
                        break;

                    case ParamCode.LocalDownloadPath:
                        onDownloadPathReceived(PacketBase.ReadString(ms));
                        break;

                    case ParamCode.Message:
                        onVideoMessageFeedback(MessagePacket.Decode(ms));
                        break;
                    }
                }
            }
        }
Beispiel #6
0
        private void onReceiveCompleted(object sender, ReceiveEventArgs args)
        {
            try
            {
                if (args.ByteLength > 0)
                {
                    using (MemoryStream ms = new MemoryStream(args.ReceivedBytes))
                    {
                        ParamCode code   = (ParamCode)PacketBase.ReadInt(ms);
                        byte[]    buffer = null;
                        switch (code)
                        {
                        case ParamCode.VideoInfosTimePeriods:
                            updateVideoInfosTimePeriods(VideoDataInfoParam.Decode(ms));
                            break;

                        case ParamCode.DownloadBegin:
                            beginDownload(DownloadInfoParam.Decode(ms));
                            break;

                        case ParamCode.DownloadToLocal:
                            downloadToLocal(PacketBase.ReadString(ms));
                            break;

                        case ParamCode.VideoPacket:
                            getVideoStreamsPacket(VideoDataParam.Decode(ms));
                            break;

                        case ParamCode.ProbeTime:
                            setProbeTime(PacketBase.ReadTime(ms));
                            break;

                        case ParamCode.DownloadInfosAll:
                            feedbackDownloadInfosToClient();
                            break;

                        case ParamCode.DownloadControl:
                            var controlCode = (DownloadControlCode)PacketBase.ReadInt(ms);
                            onDownloadControl(controlCode, ms);
                            break;

                        case ParamCode.LocalDownloadPath:
                            onLocalDownloadPath(PacketBase.ReadString(ms));
                            break;

                        case ParamCode.LocalDownloadBegin:
                            onLocalDownloadStart(LocalDownloadInfoPacket.Decode(ms));
                            break;
                        }
                        if (buffer != null)
                        {
                            send((ParamCode)code, buffer);
                        }
                    }
                }
            }
            catch (IOException ex)
            {
                sendMessage(MessageType.Warn, ex.Message, null);
            }
            catch (Exception ex)
            {
                sendMessage(MessageType.Error, ex.Message, null);
                Console.WriteLine(ex.ToString());
            }
        }