Exemplo n.º 1
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);
        }
		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;
		}
Exemplo n.º 3
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);
        }