Пример #1
0
        private bool TryParseChunk(ref SequenceReader <byte> reader, out RtmpChunk chunk, out RtmpMessageEntry messageEntry)
        {
            messageEntry = null;
            chunk        = null;
            _logger.LogDebug($"Before parsing chunk: Sequence Reader Length:{reader.Length}: Consumed:{reader.Consumed}  Remaining:{reader.Remaining}");
            var header = new RtmpChunkHeader();

            if (!header.TryParse(ref reader))
            {
                return(false);
            }

            if (!_messageCache.TryGetValue(header.StreamId, out messageEntry))
            {
                messageEntry = new RtmpMessageEntry();
                _messageCache.Add(header.StreamId, messageEntry);
            }

            var message = new RtmpMessageHeader();

            if (!message.TryParse(ref reader, header.HeaderType, messageEntry.LastChunk?.Message))
            {
                return(false);
            }

            chunk = new RtmpChunk(header, message);
            if (header.HeaderType != RtmpChunkHeaderType.Type3)
            {
                messageEntry.Length    = chunk.Message.Length;
                messageEntry.BytesRead = 0;
            }
            else
            {
            }

            var chunkLength = Math.Min(messageEntry.BytesRemaining, _session.IncomingChunkLength);

            if (!chunk.TryParseBody(ref reader, chunkLength))
            {
                return(false);
            }
            _logger.LogDebug($"After parsing chunk: Sequence Reader Length:{reader.Length}: Consumed:{reader.Consumed}  Remaining:{reader.Remaining}");
            _logger.LogDebug($"Parsed chunk Header :{chunk.Header}: Message: {chunk.Message}");
            messageEntry.LastChunk = chunk;
            return(true);
        }
Пример #2
0
        public static bool TryParseHeader(ref SequenceReader <byte> reader, out RtmpChunk chunk)
        {
            chunk = null;
            var header = new RtmpChunkHeader();

            if (!header.TryParse(ref reader))
            {
                return(false);
            }

            var message = new RtmpMessageHeader();

            if (!message.TryParse(ref reader, header.HeaderType, previous: null))
            {
                return(false);
            }

            chunk = new RtmpChunk(header, message);
            return(true);
        }