Пример #1
0
        public void TestVideoBasePacketLong()
        {
            VideoBasePacket packet = new VideoBasePacket(new byte[30], new DateTime(2016, 1, 1), 1000000000000);

            byte[] buffer  = VideoBasePacket.Encode(packet);
            var    packet2 = VideoBasePacket.Decode(buffer);

            AssertAreEqual(packet, packet2);
        }
Пример #2
0
        private void Client_ReceiveCompleted(object sender, ReceiveEventArgs args)
        {
            try
            {
                if (args.ByteLength > 0)
                {
                    onBytesLengthReceived(args.ByteLength);
                    using (MemoryStream ms = new MemoryStream(args.ReceivedBytes))
                    {
                        int code = PacketBase.ReadInt(ms);
                        switch ((ParamCode)code)
                        {
                        case ParamCode.TimePeriods:
                            onVideoStoragePacket(VideoTimePeriodsPacket.Decode(ms));
                            break;

                        case ParamCode.VideoPacket:
                            onVideoPacket(VideoStreamsPacket.Decode(ms));
                            break;

                        case ParamCode.VideoBaseInfo:
                            onVideoBasePacket(VideoBasePacket.Decode(ms));
                            break;

                        case ParamCode.DownloadInfosAll:
                            onDownloadInfosAll(DownloadInfoExpandPacket.DecodeArray(ms));
                            break;

                        case ParamCode.DownloadInfosAdd:
                            onDownloadInfosAdd(DownloadInfoExpandPacket.Decode(ms));
                            break;

                        case ParamCode.DownloadInfoPart:
                            onDownloadInfoPart(DownloadInfoPartConverter.Decode(ms));
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                onException(ex);
            }
        }
Пример #3
0
        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;
                    }
                }
            }
        }