The repacketizer can be used to merge multiple Opus packets into a single packet or alternatively to split Opus packets that have previously been merged.
More...
|
| int | opus_repacketizer_get_size (void) |
| | Gets the size of an OpusRepacketizer structure.
|
| OpusRepacketizer * | opus_repacketizer_init (OpusRepacketizer *rp) |
| | (Re)initializes a previously allocated repacketizer state.
|
| OpusRepacketizer * | opus_repacketizer_create (void) |
| | Allocates memory and initializes the new repacketizer with opus_repacketizer_init().
|
| void | opus_repacketizer_destroy (OpusRepacketizer *rp) |
| | Frees an OpusRepacketizer allocated by opus_repacketizer_create().
|
| int | opus_repacketizer_cat (OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) |
| | Add a packet to the current repacketizer state.
|
| opus_int32 | opus_repacketizer_out_range (OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) |
| | Construct a new packet from data previously submitted to the repacketizer state via opus_repacketizer_cat().
|
| int | opus_repacketizer_get_nb_frames (OpusRepacketizer *rp) |
| | Return the total number of frames contained in packet data submitted to the repacketizer state so far via opus_repacketizer_cat() since the last call to opus_repacketizer_init() or opus_repacketizer_create().
|
| opus_int32 | opus_repacketizer_out (OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) |
| | Construct a new packet from data previously submitted to the repacketizer state via opus_repacketizer_cat().
|
| int | opus_packet_pad (unsigned char *data, opus_int32 len, opus_int32 new_len) |
| | Pads a given Opus packet to a larger size (possibly changing the TOC sequence).
|
| opus_int32 | opus_packet_unpad (unsigned char *data, opus_int32 len) |
| | Remove all padding from a given Opus packet and rewrite the TOC sequence to minimize space usage.
|
| int | opus_multistream_packet_pad (unsigned char *data, opus_int32 len, opus_int32 new_len, int nb_streams) |
| | Pads a given Opus multi-stream packet to a larger size (possibly changing the TOC sequence).
|
| opus_int32 | opus_multistream_packet_unpad (unsigned char *data, opus_int32 len, int nb_streams) |
| | Remove all padding from a given Opus multi-stream packet and rewrite the TOC sequence to minimize space usage.
|
The repacketizer can be used to merge multiple Opus packets into a single packet or alternatively to split Opus packets that have previously been merged.
Splitting valid Opus packets is always guaranteed to succeed, whereas merging valid packets only succeeds if all frames have the same mode, bandwidth, and frame size, and when the total duration of the merged packet is no more than 120 ms. The 120 ms limit comes from the specification and limits decoder memory requirements at a point where framing overhead becomes negligible.
The repacketizer currently only operates on elementary Opus streams. It will not manipulate multistream packets successfully, except in the degenerate case where they consist of data from a single stream.
The repacketizing process starts with creating a repacketizer state, either by calling opus_repacketizer_create() or by allocating the memory yourself, e.g.,
if (rp != NULL)
struct OpusRepacketizer OpusRepacketizer
Definition opus.h:948
int opus_repacketizer_get_size(void)
Gets the size of an OpusRepacketizer structure.
OpusRepacketizer * opus_repacketizer_init(OpusRepacketizer *rp)
(Re)initializes a previously allocated repacketizer state.
Then the application should submit packets with opus_repacketizer_cat(), extract new packets with opus_repacketizer_out() or opus_repacketizer_out_range(), and then reset the state for the next set of input packets via opus_repacketizer_init().
For example, to split a sequence of packets into individual frames:
unsigned char *data;
int len;
while (get_next_packet(&data, &len))
{
unsigned char out[1276];
int nb_frames;
int err;
int i;
{
release_packet(data);
return err;
}
for (i = 0; i < nb_frames; i++)
{
if (out_len < 0)
{
release_packet(data);
return (int)out_len;
}
output_next_packet(out, out_len);
}
release_packet(data);
}
#define OPUS_OK
No error.
Definition opus_defines.h:46
int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len)
Add a packet to the current repacketizer state.
int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp)
Return the total number of frames contained in packet data submitted to the repacketizer state so far...
opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen)
Construct a new packet from data previously submitted to the repacketizer state via opus_repacketizer...
int opus_int32
Definition opus_types.h:161
Alternatively, to combine a sequence of frames into packets that each contain up to TARGET_DURATION_MS milliseconds of data:
unsigned char *data[(TARGET_DURATION_MS*2/5)+1];
int nb_packets;
unsigned char out[1277*(TARGET_DURATION_MS*2/2)];
int prev_toc;
nb_packets = 0;
while (get_next_packet(data+nb_packets, len+nb_packets))
{
int nb_frames;
int err;
if (nb_frames < 1)
{
release_packets(data, nb_packets+1);
return nb_frames;
}
if (nb_packets > 0 && (
((prev_toc & 0xFC) != (data[nb_packets][0] & 0xFC)) ||
TARGET_DURATION_MS*48))
{
if (out_len < 0)
{
release_packets(data, nb_packets+1);
return (int)out_len;
}
output_next_packet(out, out_len);
release_packets(data, nb_packets);
data[0] = data[nb_packets];
len[0] = len[nb_packets];
nb_packets = 0;
}
{
release_packets(data, nb_packets+1);
return err;
}
prev_toc = data[nb_packets][0];
nb_packets++;
}
if (nb_packets > 0)
{
release_packets(data, nb_packets);
if (out_len < 0)
return (int)out_len;
output_next_packet(out, out_len);
}
int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len)
Gets the number of frames in an Opus packet.
int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs)
Gets the number of samples per frame from an Opus packet.
opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen)
Construct a new packet from data previously submitted to the repacketizer state via opus_repacketizer...
An alternate way of merging packets is to simply call opus_repacketizer_cat() unconditionally until it fails. At that point, the merged packet can be obtained with opus_repacketizer_out() and the input packet for which opus_repacketizer_cat() needs to be re-added to a newly reinitialized repacketizer state.