Search code examples
rtpoggopus

How many bytes of Opus payload need to be sent in one RTP packet


I have Ogg format file containing OPUS frames. As per my requirement, I need to parse this file (frames/packets), and send OPUS compressed data to a remote device through RTP.

My question is in one RTP packet (assuming 48khz sampling rate)
1. One OPUS frame will be sent
2. Or multiple OPUS frames will be sent
3. Or one packet as per Ogg file format specification, which may be one frame, 2 frames or arbitrary number of frames will be sent


Solution

  • Each Opus RTP packet contains only one Opus packet, as defined by the Opus specification. That may contain more than one Opus frame internally, but it must have the correct header bytes to signal this and conform to other rules, so make sure you mean the same thing the spec does by "frame".

    Basically, you want to send each Opus packet out of the Ogg file in its own RTP packet. There's no packing at the RTP payload level. Don't send the Id or Comment headers in the first two packets of the .opus Ogg stream, and of course you need to prepend RTP headers with the appropriate flags, timestamp and so on.

    See https://git.xiph.org/?p=opus-tools.git;a=blob;f=src/opusrtp.c#l517 for a toy implementation of this.