CSharpRTMP.Core.Protocols.Rtsp.InboundConnectivity.FeedData C# (CSharp) Method

FeedData() public method

public FeedData ( uint channelId, InputStream buffer, uint length ) : bool
channelId uint
buffer CSharpRTMP.Common.InputStream
length uint
return bool
        public bool FeedData(uint channelId, InputStream buffer,uint length)
        {
            //1. Is the chanel number a valid chanel?
            if (channelId >= 4)
            {
                FATAL("Invalid chanel number: {0}", channelId);
                return false;
            }
            if (!_protocols.ContainsKey(channelId))
            {
                FATAL("Invalid chanel number: {0}", channelId);
                return false;
            }
            _inputBuffer.IgnoreAll();
            buffer.CopyPartTo(_inputBuffer,(int)length);
            _inputBuffer.Published = length;
            _inputBuffer.Position = 0;
            //_protocols[channelId].InputBuffer.WriteBytes(buffer);
            return _protocols[channelId].SignalInputData(_inputBuffer, _dummyAddress);
        }

Usage Example

Beispiel #1
0
        public override bool SignalInputData(int recAmount)
        {
            while (InputBuffer.AvaliableByteCounts > 0)
            {
                switch (_state)
                {
                case RtspState.InterleavedHeader:
                    //6. Do we have enough data?
                    if (InputBuffer.AvaliableByteCounts < _rtpDataLength)
                    {
                        return(true);
                    }
                    _state = RtspState.Playload;
                    goto case RtspState.Playload;

                case RtspState.NormalHeader:
                    ParseNormalHeaders();
                    if (_state != RtspState.Playload)
                    {
                        return(true);
                    }
                    goto case RtspState.Playload;

                case RtspState.Header:

                    if (InputBuffer.Reader.PeekChar() == '$')
                    {
                        //1. Marl this as a interleaved content
                        _rtpData = true;
                        //2. Do we have at least 4 bytes ($ sign, channel byte an 2-bytes length)?
                        var bufferLength = InputBuffer.AvaliableByteCounts;
                        if (bufferLength < 4)
                        {
                            return(true);
                        }
                        //3. Get the buffer
                        InputBuffer.Reader.ReadByte();
                        //4. Get the channel id
                        _rtpDataChanel = InputBuffer.Reader.ReadByte();
                        //5. Get the packet length
                        _rtpDataLength = InputBuffer.Reader.ReadUInt16();

                        if (_rtpDataLength > 8192)
                        {
                            FATAL("RTP data length too big");
                            return(false);
                        }
                        //6. Do we have enough data?
                        if (_rtpDataLength + 4 > bufferLength)
                        {
                            _state = RtspState.InterleavedHeader;
                            return(true);
                        }
                        _state = RtspState.Playload;
                        goto case RtspState.Playload;
                    }
                    _state = RtspState.NormalHeader;
                    goto case RtspState.NormalHeader;

                case RtspState.Playload:
                    if (_rtpData)
                    {
                        if (InboundConnectivity != null)
                        {
                            if (!InboundConnectivity.FeedData(
                                    _rtpDataChanel, InputBuffer, _rtpDataLength))
                            {
                                FATAL("Unable to handle raw RTP packet");
                                return(false);
                            }
                        }
                        else
                        {
                            InputBuffer.Ignore(_rtpDataLength);
                        }
                        _state = RtspState.Header;
                    }
                    else
                    {
                        if (!HandleRTSPMessage())
                        {
                            FATAL("Unable to handle content");
                            return(false);
                        }
                    }
                    break;
                }
            }
            return(false);
        }