This project is read-only.

SendRtspRequest bug - not all parts recieved


Project Media, file Rtsp/RtspClient.cs:
//Send the bytes

//Fire the event

//Increment our byte counters for Rtsp
m_SentBytes += buffer.Length;
m_RecievedBytes += m_RtspSocket.Receive(m_Buffer);
m_RtspSocket.Receive(m_Buffer) - is incorrect receive pattern. If answer splitted to some parts (header / content for example) only first part of answer will received. Captured with VLC in streaming mode at SendDescribe method. Need to look to Content-Length field at header (first part of answer) and read rest of answer.

Look unsafe, slow, but working code:
var firstBlockLength = m_RecievedBytes += m_RtspSocket.Receive(m_Buffer);

var s1 = Encoding.Default.GetString(m_Buffer).Trim(new[] {'\0'}).
    Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).
    Select(p =>
        var idx = p.IndexOf(':');
        if (idx <= 0) return null;
        return new
            name = p.Substring(0, idx),
            value = p.Substring(idx + 1, p.Length - idx - 1)
    }).FirstOrDefault(p => p != null && == "content-length");
if (s1 != null)
    var len = int.Parse(s1.value);
    if (len > 0)
        var stm = new MemoryStream();
        stm.Write(m_Buffer, 0, firstBlockLength);
        m_RecievedBytes += (firstBlockLength = m_RtspSocket.Receive(m_Buffer, len, SocketFlags.None));
        stm.Write(m_Buffer, 0, firstBlockLength);
        Array.Copy(stm.ToArray(), 0, m_Buffer, 0, stm.Length);


aaronc wrote Jan 5, 2014 at 10:52 AM

Sorry I can't find the block of code you are referring to. Could you provide the line number in that file?

juliusfriedman wrote Jun 28, 2014 at 12:33 AM

You are correct, there is also a RtspClient / RtpClient implementation here

I am working on providing some help integrating it into the code after I have some work done in the Video Encoding and Decoding realm for my project.

Until then you can easily use that client in place of the included one if needed.