chrisp
chrisp

Reputation: 629

LIVE555 - Set SPS and PPS after receiving first frame

I have a device which delivers H264 encoded frames. Those I would like to transmit over the network using LIVE555.

Problem: These frames do not include the SPS and PPS NAL units. However, I have access to a function which delivers me the SPS and PPS NAL units after the device encoded the first frame.

Question: How can I set the SPS and PPS NAL units after the event loop of LIVE555 has already started? I've read numerous posts about similar issues but all these posts suggested the following solutions:

All these solutions aren't useful in my case because I haven't got the SPS and PPS NAL units at these moments. Is there some sort of way to update these NAL units after the event loop has already started?

Upvotes: 1

Views: 1276

Answers (2)

chrisp
chrisp

Reputation: 629

It has been quite some time. But as it has been requested, a general overview of what my solution was. I have no idea whether it was or is a good solution. For that it has been too long:

  1. I encoded one frame at the very start and used the mentioned function to grab the SPS and PPS NAL units
  2. ... then immediately destroyed the encoder
  3. ... removed the start code from the result
  4. ... base64-encoded the SPS and PPS NAL units separately and concatenated them in the format SPS + "," + PPS
  5. ... created a ServerMediaSession
  6. ... created a custom MediaSubsession which extends OnDemandServerMediaSubsession with the methods createNewStreamSource and createNewRTPSink
  7. ... created a new instance of the encoder and passed it to a H264VideoStreamDiscreteFramer in the createNewStreamSource method
  8. ... used a H264VideoRTPSink in the createNewRTPSink method to which I passed the above mentioned concatenated SPS and PPS NAL units

Upvotes: 2

Ralf
Ralf

Reputation: 9573

You haven't provided enough information about the application design/architecture to provide a better answer:

Not sure if I understand your problem correctly, but it sounds like you are only instantiating the encoder after an RTSP client request. However the DESCRIBE request passes the SPS, PPS and at the time of DESCRIBE, you haven't encoded any data and hence don't have the SPS and PPS.

If the encoder is being instantiated in the live555 event loop after a client request, then one solution would be to

  • instantiate an encoder with the desired configuration (or with all possible configurations) on application start-up
  • encode a frame
  • retrieve and save the SPS and PPS
  • close the encoder
  • proceed with "normal" event loop and await RTSP client connections.

In my experience the SPS and PPS don't usually change (often), and you must be getting your encoder configuration from somewhere (config file?).

If this does not answer your question, provide more detail about e.g. application threads, what event loops are running, encoder lifetimes, etc.

Upvotes: 3

Related Questions