Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
                    }
                }
            }
        }
Exemplo n.º 5
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;
                    }
                }
            }
        }
Exemplo n.º 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());
            }
        }