}
output_next_packet(out, out_len);
合并包的一个可替代方案是仅仅无条件地调用opus_repacketizer_cat()直到失败。这样,可以用opus_repacketizer_out()来获得合并后的包,opus_repacketizer_cat()输入的包需要重新添加到一个新的重新初始化的repacketizer状态.
类型定义文档
typedef struct OpusRepacketizer OpusRepacketizer
函数文档
int opus_repacketizer_cat
( OpusRepacketizer *
rp,
const unsigned char * data, opus_int32
len
)
添加一个包到当前repacketizer状态。
这个包必须符合自从最后一次调用opus_repacketizer_init()后,已经提交给repacketizer状态的任何包的配置。这意味着它必须有相同的编码模式、带宽、帧大小和通道数。可以提前进行检查,方法是通过监测包第一个字节的前6位,检查它们是否与其他任何已提交的包的第一个字节的前6位项匹配。添加这个包以后,单个包的总时长,以及在repacketizer状态的音频总时长都不能超过120毫秒。
This packet must match the configuration of any packets already submitted for repacketization since the last call to opus_repacketizer_init(). This means that it must have the same coding mode, audio bandwidth, frame size, and channel count. This can be checked in advance by examining the top 6 bits of the first byte of the packet, and ensuring they match the top 6 bits of the first byte of any
25
previously submitted packet. The total duration of audio in the repacketizer state also must not exceed 120 ms, the maximum duration of a single packet, after adding this packet.
用opus_repacketizer_out() 或 opus_repacketizer_out_range(),当前repacketizer状态的内容可以被提取到新的包。
The contents of the current repacketizer state can be extracted into new packets using opus_repacketizer_out() or opus_repacketizer_out_range().
如果想添加不同配置的包,或加更多的超过120毫秒的音频数据,就必须调用opus_repacketizer_init()来清除repacketizer状态。如果一个包太大不能整体添加到当前repacketizer状态,它的任何一部分也不能添加,即使这个包包含多个帧,其中部分也许适合添加。如果你想添加这样的包的部分内容,你应当首先使用另一个repacketizer来将这些包分离成适合添加的小片,再一个个地将这些小片加入目标repacketizer状态。
In order to add a packet with a different configuration or to add more audio beyond 120 ms, you must clear the repacketizer state by calling opus_repacketizer_init(). If a packet is too large to add to the current repacketizer state, no part of it is added, even if it contains multiple frames, some of which might fit. If you wish to be able to add parts of such packets, you should first use another repacketizer to split the packet into pieces and add them individually.
参见:
opus_repacketizer_out_range opus_repacketizer_out opus_repacketizer_init 参数:
rp OpusRepacketizer*:将要添加包的repacketizer状态。 The
repacketizer state to which to add the packet.
[in] data
const unsigned char*: 包数据。应用程序必须确保这个指
针合法有效直到对opus_repacketizer_init() 或 opus_repacketizer_destroy()的
26
下一次调用。The packet data. The application must ensure this pointer remains valid
until
the
next
call
to
opus_repacketizer_init()
or
opus_repacketizer_destroy().
packet data.
返回:
表示操作成功与否的错误代码。
An error code indicating whether or not the operation succeeded. 返回值:
OPUS_OK 包的内容已被添加到repacketizer状态。The packet's contents have been added to the repacketizer状态.
OPUS_INVALID_PACKET 包的TOC系列无效,该系列不能与以前提交的包相匹配(编码模式、音频带宽、帧大小或通道数不吻合),或添加这个包将导致存储在repacketizer状态的声音时长超过120毫秒。The packet did not have a valid TOC sequence, the packet's TOC sequence was not compatible with previously submitted packets (because the coding mode, audio bandwidth, frame size, or channel count did not match), or adding this packet would increase the total amount of audio stored in the repacketizer状态 to more than 120 ms.
OpusRepacketizer* opus_repacketizer_create ( void
)
len opus_int32: 包数据中的字节数。The number of bytes in the
为用opus_repacketizer_init()产生的新repacketizer 分配内存和初始化。 Allocates
memory
and
initializes
the
new
repacketizer
with
opus_repacketizer_init().
void opus_repacketizer_destroy ( OpusRepacketizer *
rp )
释放通过opus_repacketizer_create()分配过的OpusRepacketizer。 Frees an OpusRepacketizer allocated by opus_repacketizer_create(). 参数:
27
[in] rp OpusRepacketizer*:将被释放的repacketizer状态。 State to be freed.
int opus_repacketizer_get_nb_frames
)
返回最后一次调用opus_repacketizer_init() 或 opus_repacketizer_create()后,到当前为止通过opus_repacketizer_cat()提交的包数据所包含的帧的总数。
Return the total number of frames contained in packet data submitted to the repacketizer状态 so far via opus_repacketizer_cat() since the last call to opus_repacketizer_init() or opus_repacketizer_create().
这
里
定
义
了
能
被
opus_repacketizer_out_range()
或
( OpusRepacketizer *
rp
opus_repacketizer_out()提取的有效包的范围。
This defines the valid range of packets that can be extracted with opus_repacketizer_out_range() or opus_repacketizer_out().
参数:
rp OpusRepacketizer*: 包含各帧的repacketizer状态。The repacketizer状态 containing the frames.
返回:
提交给repacketizer状态的包所包含的帧的总数。
The total number of frames contained in the packet data submitted to the repacketizer状态.
int opus_repacketizer_get_size ( void 获得 OpusRepacketizer结构的大小
Gets the size of an OpusRepacketizer structure. 返回:
结构体字节的大小 The size in bytes.
28
)
相关推荐: