EncodeAndPack() public static method

public static EncodeAndPack ( AESEngine aesEncrypt, H2NBinaryWriter writer, uint farId, int ignore ) : void
aesEncrypt AESEngine
writer CSharpRTMP.Common.H2NBinaryWriter
farId uint
ignore int
return void
        public override void Flush(byte type)
        {
            Writer.BaseStream.Position = 6;
            Writer.Write((byte)0x0b);
            Writer.Write(RtmfpUtils.TimeNow());
            Writer.Write(type);
            Writer.Write((short)(Writer.BaseStream.GetAvaliableByteCounts() - 2));
            var encoder = AesEncrypt.Next(AESEngine.AESType.SYMMETRIC);

            RtmfpUtils.EncodeAndPack(encoder, Writer, 0);
            EnqueueForOutbound(OutputBuffer);
            Writer.Clear(11);
        }
Beispiel #2
0
        public void Flush(byte marker, bool echoTime, AESEngine.AESType aesType)
        {
            _lastFlowWriter = null;
            if (IsEnqueueForDelete)
            {
                return;
            }
            var outputBuffer = Writer.BaseStream;

            if (outputBuffer.Length >= Defines.RTMFP_MIN_PACKET_SIZE)
            {
                //Debug.WriteLine(outputBuffer.Length);
                if (RecTimestamp.Elapsed > TimeSpan.FromSeconds(30))
                {
                    echoTime = false;
                }
                var offset = 0;
                if (echoTime)
                {
                    marker += 4;
                }
                else
                {
                    offset = 2;
                }
                var timeStamp = RtmfpUtils.TimeNow();
                //_outputBuffer.Ignore(offset);
                outputBuffer.Position = 6 + offset;
                outputBuffer.WriteByte(marker);
                Writer.Write(timeStamp);
                if (echoTime)
                {
                    Writer.Write((ushort)(TimeSent + RtmfpUtils.Time(RecTimestamp.Elapsed)));
                }
                RtmfpUtils.EncodeAndPack(AesEncrypt.Next(aesType), Writer, FarId, offset);
                EnqueueForOutbound(outputBuffer as MemoryStream, offset);
                Writer.Clear(11);
            }
        }
Beispiel #3
0
        public virtual void SendStream(Stream stream, int len)
        {
            var marker   = stream.ReadByte() | 0xF0;
            var echoTime = marker == (Target == null ? 0xFE : 0xFD);

            stream.ReadUShort();
            if (echoTime)
            {
                stream.ReadUShort();
            }
            var type = stream.ReadByte();
            var size = stream.ReadUShort();

            switch (type)
            {
            case 0x51:
                var idFlow      = stream.Read7BitLongValue();
                var bufferSize  = stream.Read7BitLongValue();
                var stageReaden = stream.Read7BitLongValue();
                var tail        = "";
                while (stream.GetAvaliableByteCounts() > 0)
                {
                    tail += " " + stream.Read7BitLongValue();
                }
                Debug.WriteLine("from {1}:{0:X} ack {2} on flow {3} {4}", type, Target == null ? "server" : "client", stageReaden, idFlow, tail);
                break;

            case 0x10:
                var flags = stream.ReadByte();
                idFlow = stream.Read7BitLongValue();
                var stage     = stream.Read7BitLongValue();
                var deltaNAck = stream.Read7BitLongValue();
                Debug.WriteLine("from {1}:{0:X} stage {2} deltaNAck {4} on flow {3}", type, Target == null ? "server" : "client", stage, idFlow, deltaNAck);
                if ((flags & FlowWriter.MESSAGE_HEADER) != 0)
                {
                    var signturelen = stream.ReadByte();
                    stream.Position += signturelen;
                    if (stream.ReadByte() > 0)
                    {
                        if (stream.ReadByte() != 0x0A)
                        {
                            Logger.WARN("Unknown fullduplex header part for the flow {0}", idFlow);
                        }
                        else
                        {
                            var assocFlowId = stream.Read7BitLongValue();
                        }
                        var length = stream.ReadByte();
                        while (length > 0 && stream.GetAvaliableByteCounts() > 0)
                        {
                            Logger.WARN("Unknown message part on flow {0}", idFlow);
                            stream.Position += length;
                            length           = stream.ReadByte();
                        }
                        if (length > 0)
                        {
                            Logger.FATAL("Bad header message part, finished before scheduled");
                        }
                    }
                    var stype = stream.ReadByte();//type
                    //var timestamp = stream.ReadUInt();//timestamp
                    switch (stype)
                    {
                    case 0x08:
                    case 0x09:
                        break;

                    case Defines.RM_HEADER_MESSAGETYPE_FLEX:
                        stream.ReadByte();
                        goto case Defines.RM_HEADER_MESSAGETYPE_INVOKE;

                    case Defines.RM_HEADER_MESSAGETYPE_INVOKE:
                        var timestamp = stream.ReadUInt();    //timestamp
                        var amfReader = new AMF0Reader(stream);
                        var str       = amfReader.ReadShortString(true);
                        Logger.Debug("from {1}:{0:X} to {2:X} on flow {3}", type, Target == null ? "server" : "client", str, idFlow);
                        break;

                    default:
                        Logger.Debug("from {1}:{0:X} to {2:X} on flow {3}", type, Target == null ? "server" : "client", stype, idFlow);
                        break;
                    }
                }
                break;

            default:
                Logger.Debug("from {1}:{0:X}", type, Target == null ? "server" : "client");
                break;
            }


            stream.Position        = 0;
            _outputBuffer.Position = 0;
            stream.CopyPartTo(_outputBuffer, len);
            RtmfpUtils.EncodeAndPack(AesEncrypt.Next(PrevAesType), Writer, FarId);
            EnqueueForOutbound(_outputBuffer);
        }