예제 #1
0
 public void TestVideoBaseParam()
 {
     IVideoBaseInfom param = new VideoBaseInfomParam(new VideoInfo("id", 2,"测试"), new TimePeriodPacket(new DateTime(2010, 1, 1), new DateTime(2011, 2, 2)));
     var buffer = VideoBaseInfomParam.Encode(param);
     IVideoBaseInfom param2 = VideoBaseInfomParam.Decode(buffer);
     Assert.AreEqual(param.VideoId, param2.VideoId);
     Assert.AreEqual(param.StreamId, param2.StreamId);
     Assert.AreEqual(param.BeginTime, param2.BeginTime);
     Assert.AreEqual(param.EndTime, param2.EndTime);
     Assert.AreEqual(param.VideoName, param2.VideoName);
 }
예제 #2
0
        private void Adapter_ReceiveCompleted(object sender, ReceiveEventArgs args)
        {
            if (args.ByteLength > 0)
            {
                SocketAdapter adapter = sender as SocketAdapter;
                using (MemoryStream ms = new MemoryStream(args.ReceivedBytes))
                {
                    int    code   = PacketBase.ReadInt(ms);
                    byte[] buffer = null;
                    switch ((ParamCode)code)
                    {
                    case ParamCode.TimePeriods:
                        buffer = getVideoTimePeriodsPacketBuffer(VideoBaseInfomParam.Decode(ms));
                        break;

                    case ParamCode.VideoPacket:
                        buffer = getVideoPacketBuffer(VideoDataParam.Decode(ms));
                        break;

                    case ParamCode.VideoBaseInfo:
                        VideoBaseInfomParam param = VideoBaseInfomParam.Decode(ms);
                        Common.Log.Logger.Default.Trace($"下载视频:{param.BeginTime} - {param.EndTime} - {param.VideoName} - {param.VideoId} - {param.StreamId} -- {adapter.RemoteEndPoint}");
                        _isDownload = true;
                        buffer      = getVideoBasePacketBuffer(param);
                        break;

                    case ParamCode.StorageFlag:
                        onStorageFlag(StorageFlagParam.Decode(ms));
                        break;

                    case ParamCode.StorageFlagAll:
                        buffer = getStorageFlagAll();
                        Console.WriteLine("StorageFlagAll: {0}", buffer.Length);
                        break;
                    }
                    if (buffer != null)
                    {
                        adapter.Send(code, buffer);
                    }
                }
            }
        }