RTSP server on live555 start send client on I-Frame (h264)

105 Views Asked by At

I wrote a simple rtsp server using live555. I took most of the code from here Live555: X264 Stream Live source based on "testOnDemandRTSPServer"

When a new client connects, it begins to receive packets from the one that currently came from the encoder. This can be a P-frame and an I-frame. How can I make sure that when connected, the client starts receiving data only from the I-frame?

1

There are 1 best solutions below

2
Christoph On

You could inspect the nal unit type, based on your requierements i think deliverFrame would be good, i dont check the whole code but nal unit have information about the frame Type.

Look Here for more Infos H264 Nal Unit you can identify the I-Frame by Coded slice of an IDR picture

void LiveSourceWithx264::deliverFrame()
{
    if(!isCurrentlyAwaitingData() || nalQueue.empty()) return;

    x264_nal_t nal = nalQueue.front();
    // Extract the NAL unit type
    int nalType = nal.p_payload[4] & 0x1F; // Assuming 4-byte start code

    // Check if we're looking for the first I-frame
    if (firstFrame && nalType != 5) {
        nalQueue.pop(); // Discard non-I-frames at the beginning
        return; // Skip until we find an I-frame
    }

    firstFrame = false; // Reset flag after finding the first I-frame

    // Existing logic to handle frame delivery
    nalQueue.pop();
    ...
}