public void TestVideoDataParam()
        {
            VideoDataParam param  = new VideoDataParam(new VideoInfo("video", 2), new DateTime(2016, 5, 5));
            var            buffer = VideoDataParam.Encode(param);
            VideoDataParam param2 = VideoDataParam.Decode(buffer);

            Assert.AreEqual(param.VideoId, param2.VideoId);
            Assert.AreEqual(param.StreamId, param2.StreamId);
            Assert.AreEqual(param.Time, param2.Time);
        }
Beispiel #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);
                    }
                }
            }
        }
Beispiel #3
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());
            }
        }