Esempio n. 1
0
        public RTMPMessageHeader(RTMPConnection connection, BinaryReader br)
        {
            Connection = connection;

            //format
            ReadFormatAndChunkStreamID(br);
            RTMPChunkStream csinfo = Connection.GetChunkStream((int)ChunkStreamID);
            //yay code repetition ftw!
            switch (Format)
            {
                case RTMPMessageFormat.BasicHeader_1:
                    Timestamp = csinfo.Timestamp;
                    MessageLength = csinfo.MessageLength;
                    MessageTypeID = csinfo.MessageTypeID;
                    MessageStreamID = csinfo.MessageStreamID;
                    break;
                case RTMPMessageFormat.BasicHeaderAndTime_4:
                    ReadTimestamp(br);
                    ReadExtendedTimestamp(br);

                    csinfo.Timestamp = Timestamp;
                    MessageLength = csinfo.MessageLength;
                    MessageTypeID = csinfo.MessageTypeID;
                    MessageStreamID = csinfo.MessageStreamID;
                    break;
                case RTMPMessageFormat.NoMessageId_8:
                    ReadTimestamp(br);
                    ReadMessageLength(br);
                    ReadMessageTypeID(br);
                    ReadExtendedTimestamp(br);

                    csinfo.Timestamp = Timestamp;
                    csinfo.MessageLength = MessageLength;
                    csinfo.MessageTypeID = MessageTypeID;
                    MessageStreamID = csinfo.MessageStreamID;
                    break;
                case RTMPMessageFormat.FullHeader_12:
                    ReadTimestamp(br);
                    ReadMessageLength(br);
                    ReadMessageTypeID(br);
                    ReadMessageStreamID(br);
                    ReadExtendedTimestamp(br);

                    csinfo.Timestamp = Timestamp;
                    csinfo.MessageLength = MessageLength;
                    csinfo.MessageTypeID = MessageTypeID;
                    csinfo.MessageStreamID = MessageStreamID;
                    break;
            }

            /*Timestamp = info.Timestamp;
            MessageLengthFromHeader = info.MessageLength;
            MessageTypeID = info.MessageTypeID;
            MessageStreamID = info.MessageStreamID;*/
        }
Esempio n. 2
0
 public void Do(BinaryWriter bw, BinaryReader br)
 {
     PrepareC0();
     SendC0(bw);
     PrepareC1();
     SendC1(bw);
     ReceiveS0(br);
     ReceiveS1(br);
     ReceiveS2(br);
     PrepareC2();
     SendC2(bw);
 }
Esempio n. 3
0
        public RTMPConnection(IPAddress address, int port, int timeoutMilliseconds = 2000)
        {
            TcpClientWithTimeout tcpClient = new TcpClientWithTimeout(new IPEndPoint(address, port));
            tcpClient.Connect(timeoutMilliseconds);
            InternalTcpClient = tcpClient.InternalClient;
            Counter = new CountingStream(InternalTcpClient.GetStream());
            InternalBinaryReader = new BinaryReader(Counter);
            InternalBinaryWriter = new BinaryWriter(Counter);

            IncomingChunkSize = 128;
            OutgoingChunkSize = 128;

            readerThread = new Thread(reader_run);
            readerThread.IsBackground = true;
            readerThread.Start();
        }
Esempio n. 4
0
 protected virtual void ReceiveS2(BinaryReader br)
 {
     S2 = br.ReadBytes(1536); // S2 (copy of C1)
 }
Esempio n. 5
0
 protected virtual void ReceiveS1(BinaryReader br)
 {
     S1 = br.ReadBytes(1536); // S1
 }
Esempio n. 6
0
 protected virtual void ReceiveS0(BinaryReader br)
 {
     S0 = new byte[] { br.ReadByte() };
 }
Esempio n. 7
0
 private void ReadTimestamp(BinaryReader br)
 {
     // timestamp
     byte[] tmstmp = br.ReadBytes(3);
     Timestamp = 0;
     Timestamp |= (uint)(tmstmp[0] << 16);
     Timestamp |= (uint)(tmstmp[1] << 8);
     Timestamp |= (uint)tmstmp[2];
     extendedTimeStamp = Timestamp == 0xFFFFFF; // extended timestamp, 4 bytes
 }
Esempio n. 8
0
 private void ReadMessageTypeID(BinaryReader br)
 {
     MessageTypeID = (RTMPMessageTypeID)br.ReadByte();
 }
Esempio n. 9
0
 private void ReadMessageStreamID(BinaryReader br)
 {
     br.InputEndianness = Endianness.LittleEndian;
     MessageStreamID = br.ReadInt(); // little endian??? crzy people
     br.InputEndianness = Endianness.BigEndian;
 }
Esempio n. 10
0
 private void ReadMessageLength(BinaryReader br)
 {
     byte[] bodysize = br.ReadBytes(3);
     MessageLength = 0;
     MessageLength |= bodysize[0] << 16;
     MessageLength |= bodysize[1] << 8;
     MessageLength |= bodysize[2];
 }
Esempio n. 11
0
 private void ReadFormatAndChunkStreamID(BinaryReader br)
 {
     byte fmt = br.ReadByte();
     Format = (RTMPMessageFormat)(fmt >> 6); // b11000000
     //chunk stream id
     byte csid = (byte)(fmt & 0x3f); // b00111111
     switch (csid)
     {
         case 0: //extended with 1 byte
             byte next1 = br.ReadByte();
             ChunkStreamID = (RTMPMessageChunkStreamID)(64 + next1);
             break;
         case 1: //extended with 2 bytes
             next1 = br.ReadByte();
             byte next2 = br.ReadByte();
             ChunkStreamID = (RTMPMessageChunkStreamID)(64 + next1 + (next2 * 256));
             break;
         case 2: //low level message
             ChunkStreamID = RTMPMessageChunkStreamID.LowLevelMessage;
             break;
         default:
             ChunkStreamID = (RTMPMessageChunkStreamID)csid;
             break;
     }
 }
Esempio n. 12
0
 private void ReadExtendedTimestamp(BinaryReader br)
 {
     if (extendedTimeStamp)
     {
         byte[] tmstmp = br.ReadBytes(4);
         Timestamp = 0;
         Timestamp |= (uint)(tmstmp[0] << 24);
         Timestamp |= (uint)(tmstmp[1] << 16);
         Timestamp |= (uint)(tmstmp[2] << 8);
         Timestamp |= (uint)tmstmp[3];
     }
 }