Пример #1
0
        public bool Update(StreamPacket packet)
        {
            UniviewStreamPacket usp = (UniviewStreamPacket)packet;

            _decoder.InputData(usp.DecodeTag, usp.Buffer);
            return(true);
        }
Пример #2
0
 public bool Update(StreamPacket packet)
 {
     if (_decoder != null)
     {
         return(_decoder.InputData(1, packet.Buffer));
     }
     return(false);
 }
Пример #3
0
        /// <summary>
        ///     Extracts the subtitles from a movie.dat.
        /// </summary>
        /// <param name="Movie">The movie.dat file path</param>
        /// <param name="Output">The output folder</param>
        /// <param name="Game">The game being tampered (MGS3 or MGS4)</param>
        private static void Extract(string Movie, string Output, MGSGame Game)
        {
            Directory.CreateDirectory(Output);
            MGSText.Initialize();

            using (FileStream Input = new FileStream(Movie, FileMode.Open))
            {
                MovieSubtitle      Out    = new MovieSubtitle();
                EndianBinaryReader Reader = null;

                switch (Game)
                {
                case MGSGame.MGSTS:
                    Reader = new EndianBinaryReader(Input, Endian.Big);
                    Game   = MGSGame.MGS3;
                    break;

                case MGSGame.MGS3: Reader = new EndianBinaryReader(Input, Endian.Little); break;

                case MGSGame.MGS4: Reader = new EndianBinaryReader(Input, Endian.Big); break;
                }

                int Index = 0;
                while (Input.Position < Input.Length)
                {
                    StreamPacket Packet = StreamPacket.FromStream(Reader, Game);

                    switch (Packet.Type)
                    {
                    case PacketType.Subtitle: Out.Subtitles.Add((SubtitlePacket)Packet); break;

                    case PacketType.EndOfStream:
                        string XmlName  = string.Format("Subtitle_{0:D5}.xml", Index++);
                        string FileName = Path.Combine(Output, XmlName);

                        XmlSerializerNamespaces NameSpaces = new XmlSerializerNamespaces();
                        NameSpaces.Add(string.Empty, string.Empty);
                        XmlWriterSettings Settings = new XmlWriterSettings
                        {
                            Encoding = Encoding.UTF8,
                            Indent   = true
                        };

                        XmlSerializer Serializer = new XmlSerializer(typeof(MovieSubtitle));
                        using (FileStream OutputStream = new FileStream(FileName, FileMode.Create))
                        {
                            XmlWriter Writer = XmlWriter.Create(OutputStream, Settings);
                            Serializer.Serialize(Writer, Out, NameSpaces);
                        }

                        Out.Subtitles.Clear();
                        break;
                    }

                    ReportProgress((float)Input.Position / Input.Length);
                }
            }
        }
Пример #4
0
 public bool Update(StreamPacket packet)
 {
     if (_decoder != null)
     {
         return(_decoder.Update(packet));
     }
     Console.WriteLine("_decoder == NULL!");
     return(false);
 }
Пример #5
0
 public bool Update(StreamPacket packet)
 {
     FfmpegDecoder.VideoFrame frame = _decoder?.Decode(1, (ulong)packet.Time.Ticks / 10000, packet.Buffer);
     if (frame != null)
     {
         onDisplay(new VideoFrame(frame.Width, frame.Height, packet.Time.Ticks, frame.Data));
     }
     return(true);
 }
Пример #6
0
            public static void LogPacket(Exception ex, bool isoutput)
            {
                StreamPacket packet = new StreamPacket {
                    IsOutput = isoutput, IsError = true, Exception = ex
                };

                Logger.Log(LogLevel.Debug, packet.ToString());
                Packets.Add(packet);
            }
Пример #7
0
        public override bool Write(StreamPacket packet)
        {
            if (string.IsNullOrEmpty(Message))
            {
                return(false);
            }

            packet.WriteString(Message);
            return(true);
        }
Пример #8
0
        private void SendPacket(byte opcode, byte[] data, EndPoint client)
        {
            StreamPacket packet = new StreamPacket();

            packet.Opcode = opcode;
            packet.Data   = data;
            var datas = packet.ToBytes();

            _client.Send(datas, datas.Length, (IPEndPoint)client);
        }
Пример #9
0
            public static void LogPacket(byte[] data, int offset, int count, bool isoutput)
            {
                byte[] buf = new byte[count];
                Array.Copy(data, offset, buf, 0, count);
                StreamPacket packet = new StreamPacket {
                    IsOutput = isoutput, Data = buf
                };

                Logger.Log(LogLevel.Debug, packet.ToString());
                Packets.Add(packet);
            }
Пример #10
0
 private static VideoStreamsPacket getVideoStreamsPacket(DateTime time)
 {
     StreamPacket[] sp = new StreamPacket[]
     {
         new StreamPacket(time, DataType.StreamDataKey, new byte[50]),
         new StreamPacket(time.AddSeconds(1), DataType.StreamData, new byte[20]),
         new StreamPacket(time.AddSeconds(2), DataType.StreamData, new byte[20]),
         new StreamPacket(time.AddSeconds(3), DataType.StreamData, new byte[20]),
         new StreamPacket(time.AddSeconds(4), DataType.StreamData, new byte[20])
     };
     return(new VideoStreamsPacket(new TimePeriodPacket(time, time.AddSeconds(5)), sp));
 }
Пример #11
0
        public void TestVideoStoragerManager_GetVideoHeader()
        {
            var beginTime = new DateTime(2016, 3, 22, 23, 50, 1, 156);

            Assert.IsNull(VideoStoragerManager.GetVideoHeader("videoId_21 111", 2, new DateTime()));
            Assert.IsNull(VideoStoragerManager.GetVideoHeader("videoId", 2, beginTime));
            StreamPacket sp = VideoStoragerManager.GetVideoHeader("videoId", 2, beginTime.AddMinutes(1));

            Assert.IsNotNull(sp);
            Assert.AreEqual(DataType.SysHead, sp.Type);
            Assert.AreEqual(2, sp.Buffer.Length);
        }
        private void SendPacket(byte opcode, IPEndPoint server, byte[] data)
        {
            StreamPacket packet = new StreamPacket();

            packet.Opcode = opcode;
            packet.Data   = data;
            if (data.Length > 500)
            {
                var tachgoi = SplitByteArray(data);

                //sửa lại cái StreamPacket.
            }
            _client.Send(packet.ToBytes(), packet.ToBytes().Length, server);
        }
Пример #13
0
        /// <summary>获取某通道视频在某时段对应文件的首个视频头</summary>
        public static VideoBasePacket GetVideoBaseInfom(string videoId, int streamId, DateTime beginTime, DateTime endTime)
        {
            string path = GlobalData.VideoPath(videoId, streamId);

            DateTime[] dates = GetFolderPaths(videoId, streamId, beginTime, endTime);
            foreach (var date in dates)
            {
                var header = FolderManager.GetVideoHeader(Path.Combine(path, GlobalProcess.FolderPath(date)), beginTime, endTime);
                if (header != null && header.Type == DataType.SysHead)
                {
                    long length = getLength(path, dates, beginTime, endTime, StreamPacket.Encode(header).Length + 4);
                    return(new VideoBasePacket(header.Buffer, header.Time, length));
                }
            }
            return(null);
        }
        private void Receive(byte[] data)
        {
            StreamPacket packet = new StreamPacket();

            if (!packet.Parse(data))
            {
                return;
            }
            var protocol = ProtocolFactory.CreateProtocol(packet.Opcode);

            if (!protocol.Parse(packet.Data))
            {
                return;
            }
            if (NewDataReceive != null)
            {
                NewDataReceive.Invoke(protocol, packet.Opcode);
            }
        }
Пример #15
0
        public void TestStreamPacket()
        {
            DateTime beginTime = new DateTime(2020, 1, 2, 3, 4, 5, 6);

            byte[]       sBuffer = new byte[] { 11, 12, 13, 14, 15 };
            StreamPacket sData   = new StreamPacket(beginTime, DataType.StreamData, sBuffer);

            byte[]       buffer  = StreamPacket.Encode(sData);
            StreamPacket newData = StreamPacket.Decode(buffer);

            Assert.AreNotSame(sData, newData);
            Assert.AreNotSame(sData.Buffer, newData.Buffer);

            Assert.AreEqual(sData.Time, newData.Time);
            Assert.AreEqual(sData.Type, sData.Type);
            Assert.AreEqual(sData.Buffer.Length, newData.Buffer.Length);
            for (int i = 0; i < sData.Buffer.Length; i++)
            {
                Assert.AreEqual(sData.Buffer[i], newData.Buffer[i]);
            }
        }
Пример #16
0
        public void NewRecieve(byte[] data, EndPoint endpoint)
        {
            StreamPacket packet = new StreamPacket();

            if (!packet.Parse(data))
            {
                return;
            }
            var protocol = ProtocolFactory.CreateProtocol(packet.Opcode);

            if (!protocol.Parse(packet.Data))
            {
                return;
            }
            var handle = HandleFactory.CreateHandle(packet.Opcode);
            var toview = handle.Handling(protocol, endpoint, UDPSocketAdapter.Convert(_socket));

            if (OnReceive != null)
            {
                OnReceive.Invoke(toview);
            }
        }
Пример #17
0
 static void assertAreEqual(StreamPacket exp, StreamPacket act)
 {
     Assert.AreEqual(exp.Time, act.Time);
     Assert.AreEqual(exp.Type, act.Type);
     Assert.AreEqual(exp.Buffer.Length, act.Buffer.Length);
 }
Пример #18
0
 public void SendPacket(StreamPacket packet)
 {
     SendPacket(packet.Encode());
 }
Пример #19
0
 public static void LogPacket(Exception ex, bool isoutput)
 {
     StreamPacket packet = new StreamPacket { IsOutput = isoutput, IsError = true, Exception = ex };
     Logger.Log(LogLevel.Debug, packet.ToString());
     Packets.Add(packet);
 }
Пример #20
0
 public static void LogPacket(byte[] data, int offset, int count, bool isoutput)
 {
     byte[] buf = new byte[count];
     Array.Copy(data, offset, buf, 0, count);
     StreamPacket packet = new StreamPacket { IsOutput = isoutput, Data = buf };
     Logger.Log(LogLevel.Debug, packet.ToString());
     Packets.Add(packet);
 }
Пример #21
0
        private void BtnStart_Click(object sender, RoutedEventArgs e)
        {
            IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Parse("192.168.178.26"), 1920);

            CommunicationProvider provider = new CommunicationProvider(ProtocolType.Tcp);

            provider.Socket.Connect(clientEndPoint);

            DeepSeaServer = new DeepSeaServer(provider);

            if (!DeepSeaServer.Send(new ConnectionRequestPacket()
            {
                options = 0
            }))
            {
                provider.Socket.Close();
                return;
            }

            receivedBytes = provider.Socket.Receive(buffer);
            if (DeepSea.GetPacketType(buffer) != PacketType.ClientDefinition)
            {
                provider.Socket.Close();
                return;
            }

            ClientDefinitionPacket clientDefinitionPacket = DeepSea.GetPacket <ClientDefinitionPacket>(buffer, receivedBytes);

            ClientScreenSize.X = clientDefinitionPacket.width;
            ClientScreenSize.Y = clientDefinitionPacket.height;

            Point targetDefinition = ClientScreenSize;

            if (!DeepSeaServer.Send(new TargetDefinitionPacket()
            {
                width = Convert.ToUInt16(targetDefinition.X), height = Convert.ToUInt16(targetDefinition.Y)
            }))
            {
                provider.Socket.Close();
                return;
            }

            receivedBytes = provider.Socket.Receive(buffer);
            if (DeepSea.GetPacketType(buffer) != PacketType.StreamRequest)
            {
                provider.Socket.Close();
                return;
            }

            //TODO: Start streaming the video
            Graphics graphics     = Graphics.FromImage(imageBuffer);
            Socket   streamSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            StreamPacket streamPacket = new StreamPacket();

            streamPacket.imageBytes = buffer;
            MemoryStream memoryStream = new MemoryStream(buffer);

            byte       packetTypeByte    = Convert.ToByte(PacketType.Stream);
            IPEndPoint clientUdpEndPoint = new IPEndPoint(clientEndPoint.Address, 1080);

            while (true)
            {
                graphics.CopyFromScreen(0, 0, 0, 0, imageBuffer.Size);
                imageBuffer.Save(memoryStream, ImageFormat.Jpeg);

                System.Buffer.BlockCopy(buffer, 0, buffer, 1, buffer.Length - 1);
                buffer[0] = packetTypeByte;

                streamSocket.SendTo(buffer, clientUdpEndPoint);
            }
        }
Пример #22
0
 public override bool Read(StreamPacket packet)
 {
     message = packet.ReadString();
     return !string.IsNullOrEmpty(message);
 }
Пример #23
0
        /// <summary>
        ///     Inserts extracted subtitles into a movie.dat.
        /// </summary>
        /// <param name="Movie">The movie.dat file path</param>
        /// <param name="Input">The input folder with subtitles in XML</param>
        /// <param name="Game">The game being tampered (MGS3 or MGS4)</param>
        private static void Insert(string Movie, string Input, MGSGame Game)
        {
            string[] Files = Directory.GetFiles(Input);
            MGSText.Initialize();

            string     NewFile = Path.GetTempFileName();
            FileStream In      = new FileStream(Movie, FileMode.Open);
            FileStream Out     = new FileStream(NewFile, FileMode.Create);

            Endian Endian = Endian.Default;

            switch (Game)
            {
            case MGSGame.MGSTS:
                Endian = Endian.Big;
                Game   = MGSGame.MGS3;
                break;

            case MGSGame.MGS3: Endian = Endian.Little; break;

            case MGSGame.MGS4: Endian = Endian.Big; break;
            }

            EndianBinaryReader Reader = new EndianBinaryReader(In, Endian);
            EndianBinaryWriter Writer = new EndianBinaryWriter(Out, Endian);

            int           Index    = 0;
            int           SubIndex = 0;
            MovieSubtitle Subtitle = GetSubtitle(Files[0]);

            while (In.Position < In.Length)
            {
                StreamPacket Packet = StreamPacket.FromStream(Reader, Game);

                switch (Packet.Type)
                {
                case PacketType.Subtitle: SubtitlePacket.ToStream(Writer, Subtitle.Subtitles[SubIndex++], Game); break;

                case PacketType.EndOfStream:
                    if (++Index < Files.Length)
                    {
                        Subtitle = GetSubtitle(Files[Index]);
                    }
                    SubIndex = 0;
                    break;
                }

                if (Packet.Type != PacketType.Subtitle)
                {
                    StreamPacket.ToStream(Writer, Packet, Game);
                }

                ReportProgress((float)In.Position / In.Length);
            }

            In.Close();
            Out.Close();

            File.Delete(Movie);
            File.Move(NewFile, Movie);
            File.Delete(NewFile);
        }