1

I want to retrieve some video data from a device with RTSP.

RTSP over UDP works well, but I need it over TCP.

After issuing the RTSP commands, I receive RTPs but I do not how to handle them here. The payload is as follows: $[channel - 1 byte][length - 2bytes][data]

The thing is that I receive such packets and sometimes further packets where channel is 10 or 99 etc.

So could anyone please provide some input on how to handle the payload ?

Display Name
  • 349
  • 2
  • 10
  • 19

4 Answers4

2

You have it all in RFC 2326 "Real Time Streaming Protocol (RTSP)". You need "10.12 Embedded (Interleaved) Binary Data":

Stream data such as RTP packets is encapsulated by an ASCII dollar sign (24 hexadecimal), followed by a one-byte channel identifier, followed by the length of the encapsulated binary data as a binary, two-byte integer in network byte order. The stream data follows immediately afterwards, without a CRLF, but including the upper-layer protocol headers. Each $ block contains exactly one upper-layer protocol data unit, e.g., one RTP packet.

There is a small example there as well:

 S->C: $\000{2 byte length}{"length" bytes data, w/RTP header}
 S->C: $\000{2 byte length}{"length" bytes data, w/RTP header}
 S->C: $\001{2 byte length}{"length" bytes  RTCP packet}
Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • That's the exact document that I've followed; But I do not find that data enough. Moreover, I've inspected the input with Wireshark and saw this message: [Malformed Packet: RTP]. Should I concatenate the all payloads for a RTP until receiving another payload like in the fist two lines you depicted ? Also, the payload is quite large while the data length only says 22 bytes. And where can I grab the PPS and SPS from in this case ? – Display Name Aug 24 '12 at 13:45
  • It should be basically the same data you otherwise receive over UDP. – Roman R. Aug 24 '12 at 14:10
1

Getting PPS is IMO straightforward and does not really require parseing the packet.

Your request for SPS , im guessing , will require getting into the packet ( i dont think you need to worry about WS msg 'invalid packet'.

What about using Type at PT at 0x09 ?

see here for packet description

sample implementations of unpacking RTP in the answer here

try looking here for more info related to RTSP control and SDP over TCP. If you are getting into inspecting the details of the RTSP session/conversation and the messaging details about control protocol selection for the respective tracks in your video. If u can get your answer without a diversion into SDP / RTCP then , obviously, thats faster/better.

Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
1

this is the packet format for TCP/RTP :

[$ - 1byte][Transport Channel - 1byte][RTP data length - 2bytes][RTP data]

the rest is like upd

for more info read process raw rtp packets

Community
  • 1
  • 1
arash kordi
  • 2,470
  • 1
  • 22
  • 24
0

Just explain something, I'm working for this as well, If you want use RTSP over TCP, please be careful about your socket reading code. The suitable socket process like below:

while (socket.connected) {
  char magic = socket.read a char;
  if (magic == '$') {  // is a RTP over TCP packet
     byte channel = socket.read 1 byte;
     unsigned short len = socket.read 2 byte; // len = ((byte1 & 0xFF) << 8) + (byte2 &0xFF);
     int readTotal = 0;
     byte rtpPacket[len];
     while (readTotal < len) {
         // read remaing bytes to rtpPacket from index readTotal
         int r = socket.read(rtpPacket, readTotal, len - readTotal); 
         if (r > 0)
            readTotal += r;
         else    // -1 means socket read error
            break;   
     }
     // now we get full RTP packet, process it!
     call back channel, rtpPacket;
  } else {  // is RTSP protocol response
     string array header;
     while (line = socket.readline() != null) {
        if (line == "") {
           int body_len = Parse header "Content-Length";
           byte body[body_len];
           int readBody = 0;
           while (readBody < body_len) {
              int r = socket.read(body, readBody, body_len - readBody);
              if (r>0)
                readBody += r;
              else
                break;
           }

           // Now we get full header, body of RTSP response, process it
           Callback header, body;   
        } else {
           header.add(line);
        }
     }
  }
}
Kingron
  • 11
  • 1