Пример #1
0
        static ByteBuffer EncodeChunkSize(RtmpContext context, ChunkSize chunkSize)
        {
            ByteBuffer output = ByteBuffer.Allocate(4);

            output.PutInt(chunkSize.Size);
            return(output);
        }
Пример #2
0
 public World(Vector3 <decimal> center, Vector3 <decimal> size, Vector3 <decimal> drawBoundingBox)
     : base(center, size, drawBoundingBox)
 {
     Grid           = new UnboundedGrid3D <Tile>(ChunkSize.To <long>());
     MeshRenderer   = new MeshRenderer <BasicMeshVertex>($"{nameof(World)}.{nameof(MeshRenderer)}");
     DiffuseSampler = Sampler.Create($"{nameof(World)} Mesh Diffuse Sampler");
 }
Пример #3
0
        private static ByteBuffer EncodeChunkSize(RtmpContext context, ChunkSize chunkSize)
        {
            ByteBuffer buffer = ByteBuffer.Allocate(4);

            buffer.PutInt(chunkSize.Size);
            return(buffer);
        }
Пример #4
0
        public async Task Upload(string sourceFilePath, string dropboxFilePath)
        {
            string    targetPath = dropboxFilePath;
            const int ChunkSize  = 4096 * 1024;

            using (var fileStream = File.Open(sourceFilePath, FileMode.Open))
            {
                if (fileStream.Length <= ChunkSize)
                {
                    LogMessage(string.Format("File size <= 4MB ({0})", ChunkSize.ToString()));
                    LogMessage("Starting single file upload");
                    try
                    {
                        await this._client.Files.UploadAsync(targetPath, body : fileStream);
                    }
                    catch (Exception ex)
                    {
                        LogErrorAction(string.Format("ERROR: DropBoxClient UpLoadAsync error - {0}", ex.Message));
                    }
                }
                else
                {
                    LogMessage(string.Format("File size > 4MB ({0})", ChunkSize.ToString()));
                    LogMessage("Starting chunk session");
                    await this.ChunkUpload(targetPath, fileStream, ChunkSize);
                }
            }
        }
Пример #5
0
        // Very risky as it may not line up, encodings use variable byte sizes
        public static void ChunkTextFromBytes(ChunkSize size, Stream instrm, Action <String> callback, Encoding encoding = null)
        {
            if (encoding == null)
            {
                encoding = Encoding.UTF8;
            }
            if (!instrm.CanRead)
            {
                throw (new InvalidOperationException("Instrm is not readable"));
            }
            int chunkMB = ((int)size) * 1024 * 1024;

            using (Stream buf = new BufferedStream(instrm, chunkMB))
            {
                byte[] readData = new byte[chunkMB];
                do
                {
                    buf.Read(readData, 0, readData.Length);
                    if (readData.Length > 0)
                    {
                        callback(encoding.GetString(readData));
                    }
                }while (readData.Length > 0);
            }
        }
Пример #6
0
        public static void ChunkBytesFromText(ChunkSize size, TextReader rdr, Action <Byte[]> callback, Encoding encoding = null)
        {
            if (encoding == null)
            {
                encoding = Encoding.UTF8;
            }
            int         chunkMB   = ((int)size) * 1024 * 1024;
            int         chunkSize = 0;
            List <Byte> toSend    = new List <byte>();

            do
            {
                var line = rdr.ReadLine();
                if (line == null)
                {
                    break;
                }
                var bytes = encoding.GetBytes(line);
                toSend.AddRange(bytes);
                toSend.AddRange(encoding.GetBytes(Environment.NewLine));

                chunkSize += bytes.Length;
                if (chunkSize >= chunkMB)
                {
                    callback(toSend.ToArray());
                    toSend.Clear();
                    chunkSize = 0;
                }
            }while (true);
            if (toSend.Count > 0)
            {
                callback(toSend.ToArray()); // Send remaining lines
            }
        }
Пример #7
0
        public static ByteBuffer EncodePacket(RtmpContext context, RtmpPacket packet)
        {
            RtmpHeader header    = packet.Header;
            int        channelId = header.ChannelId;
            IRtmpEvent message   = packet.Message;

            if (message is ChunkSize)
            {
                ChunkSize size = (ChunkSize)message;
                context.SetWriteChunkSize(size.Size);
            }
            ByteBuffer input = EncodeMessage(context, header, message);

            if (input.Position != 0L)
            {
                input.Flip();
            }
            else
            {
                input.Rewind();
            }
            header.Size = input.Limit;
            RtmpHeader lastWriteHeader = context.GetLastWriteHeader(channelId);
            int        num2            = CalculateHeaderSize(header, lastWriteHeader);

            context.SetLastWriteHeader(channelId, header);
            context.SetLastWritePacket(channelId, packet);
            int writeChunkSize = context.GetWriteChunkSize();
            int num4           = 1;

            if (header.ChannelId > 320)
            {
                num4 = 3;
            }
            else if (header.ChannelId > 0x3f)
            {
                num4 = 2;
            }
            int        num5     = (int)Math.Ceiling((double)(((float)header.Size) / ((float)writeChunkSize)));
            int        capacity = (header.Size + num2) + ((num5 > 0) ? ((num5 - 1) * num4) : 0);
            ByteBuffer buffer   = ByteBuffer.Allocate(capacity);

            EncodeHeader(header, lastWriteHeader, buffer);
            if (num5 == 1)
            {
                ByteBuffer.Put(buffer, input, buffer.Remaining);
            }
            else
            {
                for (int i = 0; i < (num5 - 1); i++)
                {
                    ByteBuffer.Put(buffer, input, writeChunkSize);
                    EncodeHeaderByte(buffer, 3, header.ChannelId);
                }
                ByteBuffer.Put(buffer, input, buffer.Remaining);
            }
            buffer.Flip();
            return(buffer);
        }
Пример #8
0
 public ChunkTraceData(ChunkPosition chunkPosition, ChunkSize size, [CanBeNull] List <LocalBlockPosition> positions = null,
                       [CanBeNull] List <AlphaBlock> blocks = null)
 {
     ChunkPosition = chunkPosition;
     Size          = size;
     Positions     = positions;
     Blocks        = blocks;
 }
Пример #9
0
 public void OnOOBControlMessage(IMessageComponent source, IPipe pipe, OOBControlMessage oobCtrlMsg)
 {
     if ("ConnectionConsumer".Equals(oobCtrlMsg.Target))
     {
         if ("pendingCount".Equals(oobCtrlMsg.ServiceName))
         {
             oobCtrlMsg.Result = this._connection.PendingMessages;
         }
         else if ("pendingVideoCount".Equals(oobCtrlMsg.ServiceName))
         {
             IClientStream streamByChannelId = null;
             if (this._connection is IStreamCapableConnection)
             {
                 streamByChannelId = (this._connection as IStreamCapableConnection).GetStreamByChannelId(this._video.ChannelId);
             }
             if (streamByChannelId != null)
             {
                 oobCtrlMsg.Result = this._connection.GetPendingVideoMessages(streamByChannelId.StreamId);
             }
             else
             {
                 oobCtrlMsg.Result = 0L;
             }
         }
         else if ("writeDelta".Equals(oobCtrlMsg.ServiceName))
         {
             long            num = 0L;
             IBWControllable parentBWControllable = this._connection as IBWControllable;
             while ((parentBWControllable != null) && (parentBWControllable.BandwidthConfiguration == null))
             {
                 parentBWControllable = parentBWControllable.GetParentBWControllable();
             }
             if ((parentBWControllable != null) && (parentBWControllable.BandwidthConfiguration != null))
             {
                 IBandwidthConfigure bandwidthConfiguration = parentBWControllable.BandwidthConfiguration;
                 if (bandwidthConfiguration is IConnectionBWConfig)
                 {
                     num = (bandwidthConfiguration as IConnectionBWConfig).DownstreamBandwidth / 8L;
                 }
             }
             if (num <= 0L)
             {
                 num = 0x1e000L;
             }
             oobCtrlMsg.Result = new long[] { this._connection.WrittenBytes - this._connection.ClientBytesRead, num / 2L };
         }
         else if ("chunkSize".Equals(oobCtrlMsg.ServiceName))
         {
             int num2 = (int)oobCtrlMsg.ServiceParameterMap["chunkSize"];
             if (num2 != this._chunkSize)
             {
                 this._chunkSize = num2;
                 ChunkSize message = new ChunkSize(this._chunkSize);
                 this._connection.GetChannel(2).Write(message);
             }
         }
     }
 }
Пример #10
0
        /// <summary>
        /// Send the chunk size.
        /// </summary>
        private void SendChunkSize()
        {
#if !SILVERLIGHT
            if (log.IsDebugEnabled)
            {
                log.Debug(string.Format("Sending chunk size: {0}", _chunkSize));
            }
#endif
            ChunkSize chunkSizeMsg = new ChunkSize(_chunkSize);
            _connection.GetChannel((byte)2).Write(chunkSizeMsg);
            _chunkSizeSent = true;
        }
Пример #11
0
        public MerkleTree CreateFromFile(Stream bytes, ChunkSize chunkSize)
        {
            m_ChunkSize = chunkSize;

            CreateLeafNodes((int)bytes.Length);

            HashLeafNodes(bytes);

            CreateBranchNodes();

            return(this);
        }
Пример #12
0
        /// <summary>
        /// Creates a BoxSelection that fits the volume of a chunk.
        /// </summary>
        /// <param name="position">The position of the chunk volume.</param>
        /// <param name="size">The size of the chunk volume.</param>
        public BoxSelection(ChunkPosition position, ChunkSize size)
            : this()
        {
            var lesser = new BlockPosition(position, new LocalBlockPosition(), size);

            _left    = lesser.X;
            _bottom  = lesser.Y;
            _forward = lesser.Z;
            var greater = new BlockPosition(position, new LocalBlockPosition(size.X - 1, size.Y - 1, size.Z - 1), size);

            _right    = greater.X;
            _top      = greater.Y;
            _backward = greater.Z;
        }
        public override ILexer <Chunk> Create()
        {
            var chunkSize  = ChunkSize.Create();
            var chunkExt   = ChunkExtension.Create();
            var chunkData  = ChunkData.Create();
            var crlf       = NewLine.Create();
            var innerLexer = Concatenation.Create(
                chunkSize,
                Option.Create(chunkExt),
                crlf,
                chunkData,
                crlf);

            return(new ChunkLexer(innerLexer));
        }
Пример #14
0
        public static void ChunkTextFromText(ChunkSize size, TextReader rdr, Action <String> callback, Encoding encoding = null, bool hasHeader = true)
        {
            if (encoding == null)
            {
                encoding = Encoding.UTF8;
            }
            int           chunkMB   = ((int)size) * 1024 * 1024;
            int           chunkSize = 0;
            bool          firstLine = true;
            String        header    = null;
            StringBuilder toSend    = new StringBuilder();

            do
            {
                var line = rdr.ReadLine();
                if (line == null)
                {
                    break;
                }
                if (firstLine && hasHeader)
                {
                    header    = line;
                    firstLine = false;
                    toSend.AppendLine(line); /// Don't count on size to send so that a header is always included
                    continue;
                }
                toSend.AppendLine(line);
                chunkSize += encoding.GetBytes(line).Length;
                if (chunkSize >= chunkMB)
                {
                    callback(toSend.ToString());
                    toSend.Clear();
                    if (hasHeader)
                    {
                        toSend.AppendLine(header);
                    }
                    chunkSize = 0;
                }
            }while (true);
            if (toSend.Length > 0)
            {
                callback(toSend.ToString()); // Send remaining lines
            }
        }
Пример #15
0
        public static void ChunkBytesFromBytes(ChunkSize size, Stream instrm, Action <Byte[]> callback)
        {
            if (!instrm.CanRead)
            {
                throw (new InvalidOperationException("Instrm is not readable"));
            }
            int chunkMB = ((int)size) * 1024 * 1024;

            using (Stream buf = new BufferedStream(instrm, chunkMB))
            {
                byte[] readData = new byte[chunkMB];
                do
                {
                    buf.Read(readData, 0, readData.Length);
                    if (readData.Length > 0)
                    {
                        callback(readData);
                    }
                }while (readData.Length > 0);
            }
        }
Пример #16
0
            public byte[] SerializeHeader()
            {
                List <byte> data = new List <byte>();

                data.AddRange(RiffHeader);
                data.AddRange(ChunkSize.GetBytesLE());
                data.AddRange(WaveHeader);

                data.AddRange(FmtHeader);
                data.AddRange(Subchunk1Size.GetBytesLE());
                data.AddRange(AudioFormat.GetBytesLE());
                data.AddRange(NumChannels.GetBytesLE());
                data.AddRange(SampleRate.GetBytesLE());
                data.AddRange(ByteRate.GetBytesLE());
                data.AddRange(BlockAlign.GetBytesLE());
                data.AddRange(BitsPerSample.GetBytesLE());

                data.AddRange(DataHeader);
                data.AddRange(Subchunk2Size.GetBytesLE());

                return(data.ToArray());
            }
Пример #17
0
 public void ReadLoop()
 {
     try
     {
         while (this.Continue)
         {
             RtmpHeader header = this.ReadHeader();
             this._rtmpHeaders[header.StreamId] = header;
             RtmpPacket packet1;
             if (!this._rtmpPackets.TryGetValue(header.StreamId, out packet1) || packet1 == null)
             {
                 packet1 = new RtmpPacket(header);
                 this._rtmpPackets[header.StreamId] = packet1;
             }
             byte[] bytes = this._reader.ReadBytes(Math.Min(packet1.Length + (header.Timestamp >= 16777215 ? 4 : 0) - packet1.CurrentLength, this._readChunkSize));
             packet1.AddBytes(bytes);
             if (packet1.IsComplete)
             {
                 this._rtmpPackets.Remove(header.StreamId);
                 RtmpEvent packet2 = this.ParsePacket(packet1);
                 this.OnEventReceived(new EventReceivedEventArgs(packet2));
                 ChunkSize chunkSize = packet2 as ChunkSize;
                 if (chunkSize != null)
                 {
                     this._readChunkSize = chunkSize.Size;
                 }
                 Abort abort = packet2 as Abort;
                 if (abort != null)
                 {
                     this._rtmpPackets.Remove(abort.StreamId);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         this.OnDisconnected(new ExceptionalEventArgs("rtmp-packet-reader", ex));
     }
 }
Пример #18
0
        /// <summary>
        /// Returns multiline string with wav file metadata.
        /// </summary>
        /// <returns></returns>
        public string GetMetadataString()
        {
            var sw = new System.IO.StringWriter();

            sw.WriteLine("Nazwa pliku: " + FileName);
            sw.WriteLine("Czas trwania: " + Subchunk2Size / ByteRate + "s");
            sw.WriteLine();
            sw.WriteLine("---- METADATA ----");
            sw.WriteLine("Chunkid: " + System.Text.Encoding.UTF8.GetString(ChunkID));
            sw.WriteLine("Rozmiar: " + ChunkSize.ToString());
            sw.WriteLine("Format: " + System.Text.Encoding.UTF8.GetString(Format));
            sw.WriteLine("Subchunk1 ID: " + System.Text.Encoding.UTF8.GetString(Subchunk1ID));
            sw.WriteLine("Subchunk1 rozmiar: " + Subchunk1Size.ToString());
            sw.WriteLine("Audio format: " + AudioFormat.ToString());
            sw.WriteLine("Kanaly: " + NumChannels.ToString());
            sw.WriteLine("Sample rate: " + SampleRate.ToString());
            sw.WriteLine("Byte rate: " + ByteRate.ToString());
            sw.WriteLine("Block align: " + BlockAlign.ToString());
            sw.WriteLine("Bits per sample: " + BitsPerSample.ToString());
            sw.WriteLine("Subchunk2 ID: " + System.Text.Encoding.UTF8.GetString(Subchunk2ID));
            sw.WriteLine("Subchunk2 rozmiar: " + Subchunk2Size.ToString());

            return(sw.ToString());
        }
Пример #19
0
        private void WritePacket(RtmpPacket packet)
        {
            RtmpHeader header   = packet.Header;
            int        streamId = header.StreamId;
            RtmpEvent  body     = packet.Body;

            byte[] messageBytes = this.GetMessageBytes(header, body);
            header.PacketLength = messageBytes.Length;
            RtmpHeader previousHeader;

            this._rtmpHeaders.TryGetValue(streamId, out previousHeader);
            this._rtmpHeaders[streamId] = header;
            this._rtmpPackets[streamId] = packet;
            this.WriteMessageHeader(header, previousHeader);
            bool flag  = true;
            int  index = 0;

            while (index < header.PacketLength)
            {
                if (!flag)
                {
                    this.WriteBasicHeader(ChunkMessageHeaderType.Continuation, header.StreamId);
                }
                int count = index + this._writeChunkSize > header.PacketLength ? header.PacketLength - index : this._writeChunkSize;
                this._writer.Write(messageBytes, index, count);
                flag   = false;
                index += this._writeChunkSize;
            }
            ChunkSize chunkSize = body as ChunkSize;

            if (chunkSize == null)
            {
                return;
            }
            this._writeChunkSize = chunkSize.Size;
        }
Пример #20
0
 protected override void OnChunkSize(RtmpConnection connection, RtmpChannel channel, RtmpHeader source, ChunkSize chunkSize)
 {
     //ChunkSize is not implemented yet
 }
Пример #21
0
 /// <summary>
 /// This method supports the infrastructure and is not intended to be used directly from your code.
 /// </summary>
 /// <param name="connection"></param>
 /// <param name="channel"></param>
 /// <param name="source"></param>
 /// <param name="chunkSize"></param>
 protected abstract void OnChunkSize(RtmpConnection connection, RtmpChannel channel, RtmpHeader source, ChunkSize chunkSize);
Пример #22
0
 public override string ToString()
 {
     return(ChunkId + " " + ChunkSize.ToString() + " " + Format + " " + Subchunk1Id + " " + Subchunk1Size.ToString() + " " +
            AudioFormat.ToString() + " " + NumChannels.ToString() + " " + SampleRate.ToString() + " " + ByteRate.ToString() +
            " " + BlockAlign.ToString() + " " + BitPerSample.ToString() + " " + Subchunk2Id + " " + Subchunk2Size);
 }
        /// <summary>
        /// Decodes a RTMP packet.
        /// </summary>
        /// <param name="context">RTMP protocol state.</param>
        /// <param name="stream">Buffer to be decoded.</param>
        /// <returns>The decoded RTMP packet.</returns>
        public static RtmpPacket DecodePacket(RtmpContext context, ByteBuffer stream)
        {
            int remaining = stream.Remaining;

            // We need at least one byte
            if (remaining < 1)
            {
#if !SILVERLIGHT
                if (log.IsDebugEnabled)
                {
                    log.Debug(__Res.GetString(__Res.Rtmp_DataBuffering, remaining, 1));
                }
#endif
                context.SetBufferDecoding(1);
                return(null);
            }
            int  position   = (int)stream.Position;
            byte headerByte = stream.Get();
            int  headerValue;
            int  byteCount;
            if ((headerByte & 0x3f) == 0)
            {
                // Two byte header
                if (remaining < 2)
                {
                    stream.Position = position;
#if !SILVERLIGHT
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Rtmp_DataBuffering, remaining, 2));
                    }
#endif
                    context.SetBufferDecoding(2);
                    return(null);
                }
                headerValue = ((int)headerByte & 0xff) << 8 | ((int)stream.Get() & 0xff);
                byteCount   = 2;
            }
            else if ((headerByte & 0x3f) == 1)
            {
                // Three byte header
                if (remaining < 3)
                {
                    stream.Position = position;
#if !SILVERLIGHT
                    if (log.IsDebugEnabled)
                    {
                        log.Debug(__Res.GetString(__Res.Rtmp_DataBuffering, remaining, 3));
                    }
#endif
                    context.SetBufferDecoding(3);
                    return(null);
                }
                headerValue = ((int)headerByte & 0xff) << 16 | ((int)stream.Get() & 0xff) << 8 | ((int)stream.Get() & 0xff);
                byteCount   = 3;
            }
            else
            {
                // Single byte header
                headerValue = (int)headerByte & 0xff;
                byteCount   = 1;
            }
            byte channelId = DecodeChannelId(headerValue, byteCount);
            if (channelId < 0)
            {
                throw new ProtocolException("Bad channel id: " + channelId);
            }
            byte headerSize   = DecodeHeaderSize(headerValue, byteCount);
            int  headerLength = GetHeaderLength(headerSize);
            headerLength += byteCount - 1;

            //if(headerLength > remaining)
            if (headerLength + byteCount - 1 > remaining)
            {
#if !SILVERLIGHT
                if (log.IsDebugEnabled)
                {
                    log.Debug(__Res.GetString(__Res.Rtmp_HeaderBuffering, remaining));
                }
#endif
                stream.Position = position;
                //context.SetBufferDecoding(headerLength);
                context.SetBufferDecoding(headerLength + byteCount - 1);
                return(null);
            }
            // Move the position back to the start
            stream.Position = position;

            RtmpHeader header = DecodeHeader(context, context.GetLastReadHeader(channelId), stream);
#if !SILVERLIGHT
            log.Debug("Decoded " + header);
#endif

            if (header == null)
            {
                throw new ProtocolException("Header is null, check for error");
            }

            // Save the header
            context.SetLastReadHeader(channelId, header);
            // Check to see if this is a new packet or continue decoding an existing one.
            RtmpPacket packet = context.GetLastReadPacket(channelId);
            if (packet == null)
            {
                packet = new RtmpPacket(header);
                context.SetLastReadPacket(channelId, packet);
            }

            ByteBuffer buf     = packet.Data;
            int        addSize = (header.Timer == 0xffffff ? 4 : 0);
            //int addSize = 0;
            int readRemaining = header.Size + addSize - (int)buf.Position;
            int chunkSize     = context.GetReadChunkSize();
            int readAmount    = (readRemaining > chunkSize) ? chunkSize : readRemaining;
            if (stream.Remaining < readAmount)
            {
#if !SILVERLIGHT
                if (log.IsDebugEnabled)
                {
                    log.Debug(__Res.GetString(__Res.Rtmp_ChunkSmall, stream.Remaining, readAmount));
                }
#endif
                //Skip the position back to the start
                stream.Position = position;
                context.SetBufferDecoding(headerLength + readAmount);

                //string path = FluorineFx.Context.FluorineContext.Current.GetFullPath(@"log\chunk.bin");
                //stream.Dump(path);
                return(null);
            }

            //http://osflash.org/pipermail/free_osflash.org/2005-September/000261.html
            //http://www.acmewebworks.com/Downloads/openCS/091305-initialMeeting.txt
            ByteBuffer.Put(buf, stream, readAmount);
            if (buf.Position < header.Size + addSize)
            {
                context.ContinueDecoding();
                return(null);
            }
            if (buf.Position > header.Size + addSize)
            {
#if !SILVERLIGHT
                log.Warn(string.Format("Packet size expanded from {0} to {1} ({2})", header.Size + addSize, buf.Position, header));
#endif
            }

            buf.Flip();

            try
            {
                IRtmpEvent message = DecodeMessage(context, packet.Header, buf);
                packet.Message = message;

                if (message is ChunkSize)
                {
                    ChunkSize chunkSizeMsg = message as ChunkSize;
                    context.SetReadChunkSize(chunkSizeMsg.Size);
                }
            }
            finally
            {
                context.SetLastReadPacket(channelId, null);
            }
#if !SILVERLIGHT
            if (log.IsDebugEnabled)
            {
                log.Debug("Decoded " + packet.ToString());
            }
#endif
            return(packet);
        }
Пример #24
0
/*
 * FlexInvoke flexInvoke = new FlexInvoke();
 * flexInvoke.Cmd = "onstatus";
 * flexInvoke.DataType = DataType.TypeUnknown;
 * StatusASO statusASO = StatusASO.GetStatusObject(StatusASO.NC_CONNECT_CLOSED, connection.ObjectEncoding);
 * flexInvoke.Parameters = new object[]{ statusASO };
 * RtmpChannel channel = connection.GetChannel(3);
 * channel.Write(flexInvoke);
 */


        protected override void OnChunkSize(RtmpConnection connection, RtmpChannel channel, RtmpHeader source, ChunkSize chunkSize)
        {
            if (connection is IStreamCapableConnection)
            {
                IStreamCapableConnection streamCapableConnection = connection as IStreamCapableConnection;
                {
                    foreach (IClientStream stream in streamCapableConnection.GetStreams())
                    {
                        if (stream is IClientBroadcastStream)
                        {
                            IClientBroadcastStream bs    = stream as IClientBroadcastStream;
                            IBroadcastScope        scope = bs.Scope.GetBasicScope(Constants.BroadcastScopeType, bs.PublishedName) as IBroadcastScope;
                            if (scope == null)
                            {
                                continue;
                            }

                            OOBControlMessage setChunkSize = new OOBControlMessage();
                            setChunkSize.Target      = "ClientBroadcastStream";
                            setChunkSize.ServiceName = "chunkSize";
                            setChunkSize.ServiceParameterMap.Add("chunkSize", chunkSize.Size);
                            scope.SendOOBControlMessage((IConsumer)null, setChunkSize);
                            if (log.IsDebugEnabled)
                            {
                                log.Debug("Sending chunksize " + chunkSize + " to " + bs.Provider);
                            }
                        }
                    }
                }
            }
        }
Пример #25
0
 protected override void OnChunkSize(RtmpConnection connection, RtmpChannel channel, RtmpHeader source, ChunkSize chunkSize)
 {
 }
Пример #26
0
 public override string ToString()
 {
     return(Unk0.ToString() + ": " + ChunkSize.ToString() + ", " + ChannelCount.ToString() + " channels");
 }
Пример #27
0
 long BeginChunk(ChunkSize size, ChunkName name)
 => BeginChunk((uint)size, name);
Пример #28
0
        // Process Quest Data block (04)
        public static void ProcessBlock04(Form1 Form)
        {
            string InputFile = $"{Environment.CurrentDirectory}\\Blocks\\Block_04.bin";

            using (BinaryReader Reader = new BinaryReader(File.Open(InputFile, FileMode.Open)))
            {
                int ChunkCount = Reader.ReadInt32(); Utility.Log($"Block 04 Chunk Count: {ChunkCount}", Form);
                for (int i = 0, QuestID, FileCount, ChunkSize; i < ChunkCount; i++)
                {
                    // Read chunk header
                    QuestID   = Reader.ReadInt32();
                    FileCount = Reader.ReadInt32();
                    ChunkSize = Reader.ReadInt32();
                    Utility.Log($"Block 04 Chunk {i.ToString("D4")}: q{QuestID.ToString("D5")} ({FileCount} files with total size 0x{ChunkSize.ToString("D8")})", Form);

                    for (int j = 0, FileSize; j < FileCount; j++)
                    {
                        FileSize = Reader.ReadInt32();
                        byte[] FileData = Reader.ReadBytes(FileSize);

                        // Extract GMD
                        string GmdLangTag = "";
                        if (FileData[0] == 0x47 && FileData[1] == 0x4D && FileData[2] == 0x44)
                        {
                            switch (FileData[8])
                            {
                            case 0: GmdLangTag = "jpn"; break;

                            case 1: GmdLangTag = "eng"; break;

                            case 2: GmdLangTag = "fre"; break;

                            case 3: GmdLangTag = "spa"; break;

                            case 4: GmdLangTag = "ger"; break;

                            case 5: GmdLangTag = "ita"; break;

                            case 6: GmdLangTag = "kor"; break;

                            case 7: GmdLangTag = "chT"; break;

                            case 8: GmdLangTag = "chS"; break;

                            case 10: GmdLangTag = "rus"; break;

                            case 11: GmdLangTag = "pol"; break;

                            case 21: GmdLangTag = "ptB"; break;

                            case 22: GmdLangTag = "ara"; break;

                            default: GmdLangTag = FileData[8].ToString("D3"); break;
                            }
                            File.WriteAllBytes($"{Environment.CurrentDirectory}\\tss\\quest\\text\\q{QuestID.ToString("D5")}_{GmdLangTag}.gmd", FileData);
                        }
                        // Extract MIB
                        else if (FileData.Length == 1008)
                        {
                            File.WriteAllBytes($"{Environment.CurrentDirectory}\\tss\\quest\\questData_{QuestID.ToString("D5")}.mib", FileData);
                        }
                        // Extract acEquip
                        else if (FileData[0] == 0xAA && FileData[1] == 0x01 && FileData[2] == 0x05)
                        {
                            File.WriteAllBytes($"{Environment.CurrentDirectory}\\tss\\quest\\acEquip\\acEquip_{QuestID.ToString("D5")}.aeq", FileData);
                        }
                        // Extract anything else
                        else
                        {
                            File.WriteAllBytes($"Quest_{QuestID.ToString("D5")}\\{j.ToString("D2")}.bin", FileData);
                        }
                    }

                    // Add quest name to ComboBoxEntries and fill dict
                    string QuestName = Utility.GetQuestTitle($"{Environment.CurrentDirectory}\\tss\\quest\\text\\q{QuestID.ToString("D5")}_eng.gmd");
                    Form.ComboBoxEntries.Items.Add(QuestName);
                    Form1.EventQuests.Add(QuestID, QuestName);
                }
            }
        }
Пример #29
0
        public static ByteBuffer EncodePacket(RtmpContext context, RtmpPacket packet)
        {
            RtmpHeader header    = packet.Header;
            int        channelId = header.ChannelId;
            IRtmpEvent message   = packet.Message;
            ByteBuffer data;

            if (message is ChunkSize)
            {
                ChunkSize chunkSizeMsg = (ChunkSize)message;
                context.SetWriteChunkSize(chunkSizeMsg.Size);
            }

            data = EncodeMessage(context, header, message);

            if (data.Position != 0)
            {
                data.Flip();
            }
            else
            {
                data.Rewind();
            }
            header.Size = (int)data.Limit;

            RtmpHeader lastHeader = context.GetLastWriteHeader(channelId);
            int        headerSize = CalculateHeaderSize(header, lastHeader);

            context.SetLastWriteHeader(channelId, header);
            context.SetLastWritePacket(channelId, packet);

            int chunkSize       = context.GetWriteChunkSize();
            int chunkHeaderSize = 1;

            if (header.ChannelId > 320)
            {
                chunkHeaderSize = 3;
            }
            else if (header.ChannelId > 63)
            {
                chunkHeaderSize = 2;
            }
            int        numChunks = (int)Math.Ceiling(header.Size / (float)chunkSize);
            int        bufSize   = (int)header.Size + headerSize + (numChunks > 0 ? (numChunks - 1) * chunkHeaderSize : 0);
            ByteBuffer output    = ByteBuffer.Allocate(bufSize);

            EncodeHeader(header, lastHeader, output);

            if (numChunks == 1)
            {
                // we can do it with a single copy
                ByteBuffer.Put(output, data, output.Remaining);
            }
            else
            {
                for (int i = 0; i < numChunks - 1; i++)
                {
                    ByteBuffer.Put(output, data, chunkSize);
                    EncodeHeaderByte(output, (byte)HeaderType.HeaderContinue, header.ChannelId);
                }
                ByteBuffer.Put(output, data, output.Remaining);
            }
            //data.Close();
            output.Flip();
            return(output);
        }
Пример #30
0
 private void RouterOptionWindow_Loaded(object sender, RoutedEventArgs e)
 {
     ChunkSize.Focus();
 }