4

I'm trying to stream live video from my android phone to a desktop RTSP server on my PC. The streamed video can be played in another device. I'm using H.264 video encoder, so the SDP returned by the server (as the reply of DESCRIBE request) should contain the profile-level-id and sprop-parameter-sets fields.

The Spydroid project shows how to extract these info from a dummy file recorded to SD card by parsing it (from the avcC block). But I cannot do it like that. In Spydroid, the media recorder and the RTSP server are on the same device, so the server can always record a test file with the same configuration as the recorder before streaming. But I'm streaming the video directly from the phone to the remote server as an RTP stream.

So my question is:

  1. How can I provide these values to the server maintaining the protocols?
  2. Is there any way to find out these two fields from the RTP stream?

Edit:

I'm using android phones to generate the streams, but the server can receive RTP stream from any source. So, is there any generic way to get these values?

Sufian Latif
  • 13,086
  • 3
  • 33
  • 70
  • `2` It depends - parameter sets might be included into RTP stream, but might be not (in which case one would have to take them from SDP). – Roman R. Sep 09 '12 at 11:18

1 Answers1

7

You can extract the profile-level-id from the Sequence Parameter Set NAL Unit (if, in fact, the parameter sets are even being sent in the stream), it's the first 3 bytes after the NAL header. i.e. the first four bytes of the SPS NAL unit from a Baseline Profile stream with level 3.0 would look like this:

67 42 00 1E

Disregard the first byte, this just indicates that it is an SPS NAL Unit (0x67 & 0x1F == 0x7 SPS is NAL Type 7, PPS is NAL Type 8). The other 3 bytes give you the profile, constraint flags, and level (in fact, it's simply level times 10 in the 3rd byte).

sprop-parameter-sets is the Base64 encoded Sequence Parameter Sets and Picture Parameter Sets, separated by commas. So just Base64 encode the SPS and PPS NAL Units (Nal type 7 and NAL type 8) and separate by comma and you should be good to go.

jgh
  • 2,017
  • 14
  • 13
  • +1 Thanks! But I analyzed an RTP stream from my android phone, no packet has `0x7` or `0x8` in the type field, I get only `0x5` and `0x1` as the type (those are for I-frame and P-frame, I think). I tested on 3 different phones, but it's all the same :( – Sufian Latif Sep 10 '12 at 05:05
  • Yeah it looks like you aren't getting the SPS or PPS data in the RTP stream, you'll have to find some other way of getting it. – jgh Sep 10 '12 at 21:23
  • Well, the `MediaRecorder` class does not produce packets with NAL unit type `0x7` and `0x8`. Actually, the output is generated for writing to a file, not for streaming. SPS and PPS are written once, in the file header. So I'm going with the SpyDroid approach - record a small file, then parse its header for SPS and PPS. I'm sending these in packets with type `0x7` and `0x8` just before sending each NAL unit of type `0x5`. It's working fine! – Sufian Latif Sep 27 '12 at 05:02