opus.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. /* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited
  2. Written by Jean-Marc Valin and Koen Vos */
  3. /*
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  16. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. /**
  25. * @file opus.h
  26. * @brief Opus reference implementation API
  27. */
  28. #ifndef OPUS_H
  29. #define OPUS_H
  30. #include "opus_types.h"
  31. #include "opus_defines.h"
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /**
  36. * @mainpage Opus
  37. *
  38. * The Opus codec is designed for interactive speech and audio transmission over the Internet.
  39. * It is designed by the IETF Codec Working Group and incorporates technology from
  40. * Skype's SILK codec and Xiph.Org's CELT codec.
  41. *
  42. * The Opus codec is designed to handle a wide range of interactive audio applications,
  43. * including Voice over IP, videoconferencing, in-game chat, and even remote live music
  44. * performances. It can scale from low bit-rate narrowband speech to very high quality
  45. * stereo music. Its main features are:
  46. * @li Sampling rates from 8 to 48 kHz
  47. * @li Bit-rates from 6 kb/s 510 kb/s
  48. * @li Support for both constant bit-rate (CBR) and variable bit-rate (VBR)
  49. * @li Audio bandwidth from narrowband to full-band
  50. * @li Support for speech and music
  51. * @li Support for mono and stereo
  52. * @li Frame sizes from 2.5 ms to 60 ms
  53. * @li Good loss robustness and packet loss concealment (PLC)
  54. * @li Floating point and fixed-point implementation
  55. *
  56. * Documentation sections:
  57. * @li @ref opusencoder
  58. * @li @ref opusdecoder
  59. * @li @ref repacketizer
  60. * @li @ref libinfo
  61. */
  62. /** @defgroup opusencoder Opus Encoder
  63. * @{
  64. *
  65. * Since Opus is a stateful codec, the encoding process starts with creating an encoder
  66. * state. This can be done with:
  67. *
  68. * @code
  69. * int error;
  70. * OpusEncoder *enc;
  71. * enc = opus_encoder_create(Fs, channels, application, &error);
  72. * @endcode
  73. *
  74. * From this point, @c enc can be used for encoding an audio stream. An encoder state
  75. * @b must @b not be used for more than one stream at the same time. Similarly, the encoder
  76. * state @b must @b not be re-initialized for each frame.
  77. *
  78. * While opus_encoder_create() allocates memory for the state, it's also possible
  79. * to initialize pre-allocated memory:
  80. *
  81. * @code
  82. * int size;
  83. * int error;
  84. * OpusEncoder *enc;
  85. * size = opus_encoder_get_size(channels);
  86. * enc = malloc(size);
  87. * error = opus_encoder_init(enc, Fs, channels, application);
  88. * @endcode
  89. *
  90. * where opus_encoder_get_size() returns the required size for the encoder state. Note that
  91. * future versions of this code may change the size, so no assuptions should be made about it.
  92. *
  93. * The encoder state is always continuous in memory and only a shallow copy is sufficient
  94. * to copy it (e.g. memcpy())
  95. *
  96. * It is possible to change some of the encoder's settings using the opus_encoder_ctl()
  97. * interface. All these settings already default to the recommended value, so they should
  98. * only be changed when necessary. The most common settings one may want to change are:
  99. *
  100. * @code
  101. * opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate));
  102. * opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity));
  103. * opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type));
  104. * @endcode
  105. *
  106. * where
  107. *
  108. * @arg bitrate is in bits per second (b/s)
  109. * @arg complexity is a value from 1 to 10, where 1 is the lowest complexity and 10 is the highest
  110. * @arg signal_type is either OPUS_AUTO (default), OPUS_SIGNAL_VOICE, or OPUS_SIGNAL_MUSIC
  111. *
  112. * See @ref encoderctls and @ref genericctls for a complete list of parameters that can be set or queried. Most parameters can be set or changed at any time during a stream.
  113. *
  114. * To encode a frame, opus_encode() or opus_encode_float() must be called with exactly one frame (2.5, 5, 10, 20, 40 or 60 ms) of audio data:
  115. * @code
  116. * len = opus_encode(enc, audio_frame, frame_size, packet, max_packet);
  117. * @endcode
  118. *
  119. * where
  120. * <ul>
  121. * <li>audio_frame is the audio data in opus_int16 (or float for opus_encode_float())</li>
  122. * <li>frame_size is the duration of the frame in samples (per channel)</li>
  123. * <li>packet is the byte array to which the compressed data is written</li>
  124. * <li>max_packet is the maximum number of bytes that can be written in the packet (1276 bytes is recommended)</li>
  125. * </ul>
  126. *
  127. * opus_encode() and opus_encode_frame() return the number of bytes actually written to the packet.
  128. * The return value <b>can be negative</b>, which indicates that an error has occurred. If the return value
  129. * is 1 byte, then the packet does not need to be transmitted (DTX).
  130. *
  131. * Once the encoder state if no longer needed, it can be destroyed with
  132. *
  133. * @code
  134. * opus_encoder_destroy(enc);
  135. * @endcode
  136. *
  137. * If the encoder was created with opus_encoder_init() rather than opus_encoder_create(),
  138. * then no action is required aside from potentially freeing the memory that was manually
  139. * allocated for it (calling free(enc) for the example above)
  140. *
  141. */
  142. /** Opus encoder state.
  143. * This contains the complete state of an Opus encoder.
  144. * It is position independent and can be freely copied.
  145. * @see opus_encoder_create,opus_encoder_init
  146. */
  147. typedef struct OpusEncoder OpusEncoder;
  148. OPUS_EXPORT int opus_encoder_get_size(int channels);
  149. /**
  150. */
  151. /** Allocates and initializes an encoder state.
  152. * There are three coding modes:
  153. *
  154. * @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voice
  155. * signals. It enhances the input signal by high-pass filtering and
  156. * emphasizing formants and harmonics. Optionally it includes in-band
  157. * forward error correction to protect against packet loss. Use this
  158. * mode for typical VoIP applications. Because of the enhancement,
  159. * even at high bitrates the output may sound different from the input.
  160. *
  161. * @ref OPUS_APPLICATION_AUDIO gives best quality at a given bitrate for most
  162. * non-voice signals like music. Use this mode for music and mixed
  163. * (music/voice) content, broadcast, and applications requiring less
  164. * than 15 ms of coding delay.
  165. *
  166. * @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that
  167. * disables the speech-optimized mode in exchange for slightly reduced delay.
  168. *
  169. * This is useful when the caller knows that the speech-optimized modes will not be needed (use with caution).
  170. * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
  171. * @param [in] channels <tt>int</tt>: Number of channels (1/2) in input signal
  172. * @param [in] application <tt>int</tt>: Coding mode (@ref OPUS_APPLICATION_VOIP/@ref OPUS_APPLICATION_AUDIO/@ref OPUS_APPLICATION_RESTRICTED_LOWDELAY)
  173. * @param [out] error <tt>int*</tt>: @ref errorcodes
  174. * @note Regardless of the sampling rate and number channels selected, the Opus encoder
  175. * can switch to a lower audio audio bandwidth or number of channels if the bitrate
  176. * selected is too low. This also means that it is safe to always use 48 kHz stereo input
  177. * and let the encoder optimize the encoding.
  178. */
  179. OPUS_EXPORT OpusEncoder *opus_encoder_create(
  180. opus_int32 Fs,
  181. int channels,
  182. int application,
  183. int *error
  184. );
  185. /** Initializes a previously allocated encoder state
  186. * The memory pointed to by st must be the size returned by opus_encoder_get_size.
  187. * This is intended for applications which use their own allocator instead of malloc.
  188. * @see opus_encoder_create(),opus_encoder_get_size()
  189. * To reset a previously initialized state use the OPUS_RESET_STATE CTL.
  190. * @param [in] st <tt>OpusEncoder*</tt>: Encoder state
  191. * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
  192. * @param [in] channels <tt>int</tt>: Number of channels (1/2) in input signal
  193. * @param [in] application <tt>int</tt>: Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY)
  194. * @retval OPUS_OK Success or @ref errorcodes
  195. */
  196. OPUS_EXPORT int opus_encoder_init(
  197. OpusEncoder *st,
  198. opus_int32 Fs,
  199. int channels,
  200. int application
  201. );
  202. /** Encodes an Opus frame.
  203. * The passed frame_size must an opus frame size for the encoder's sampling rate.
  204. * For example, at 48kHz the permitted values are 120, 240, 480, or 960.
  205. * Passing in a duration of less than 10ms (480 samples at 48kHz) will
  206. * prevent the encoder from using the LPC or hybrid modes.
  207. * @param [in] st <tt>OpusEncoder*</tt>: Encoder state
  208. * @param [in] pcm <tt>opus_int16*</tt>: Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(opus_int16)
  209. * @param [in] frame_size <tt>int</tt>: Number of samples per frame of input signal
  210. * @param [out] data <tt>char*</tt>: Output payload (at least max_data_bytes long)
  211. * @param [in] max_data_bytes <tt>int</tt>: Allocated memory for payload; don't use for controlling bitrate
  212. * @returns length of the data payload (in bytes) or @ref errorcodes
  213. */
  214. OPUS_EXPORT int opus_encode(
  215. OpusEncoder *st,
  216. const opus_int16 *pcm,
  217. int frame_size,
  218. unsigned char *data,
  219. int max_data_bytes
  220. );
  221. /** Encodes an Opus frame from floating point input.
  222. * The passed frame_size must an opus frame size for the encoder's sampling rate.
  223. * For example, at 48kHz the permitted values are 120, 240, 480, or 960.
  224. * Passing in a duration of less than 10ms (480 samples at 48kHz) will
  225. * prevent the encoder from using the LPC or hybrid modes.
  226. * @param [in] st <tt>OpusEncoder*</tt>: Encoder state
  227. * @param [in] pcm <tt>float*</tt>: Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(float)
  228. * @param [in] frame_size <tt>int</tt>: Number of samples per frame of input signal
  229. * @param [out] data <tt>char*</tt>: Output payload (at least max_data_bytes long)
  230. * @param [in] max_data_bytes <tt>int</tt>: Allocated memory for payload; don't use for controlling bitrate
  231. * @returns length of the data payload (in bytes) or @ref errorcodes
  232. */
  233. OPUS_EXPORT int opus_encode_float(
  234. OpusEncoder *st,
  235. const float *pcm,
  236. int frame_size,
  237. unsigned char *data,
  238. int max_data_bytes
  239. );
  240. /** Frees an OpusEncoder allocated by opus_encoder_create.
  241. * @param[in] st <tt>OpusEncoder*</tt>: State to be freed.
  242. */
  243. OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st);
  244. /** Perform a CTL function on an Opus encoder.
  245. * @see encoderctls
  246. */
  247. OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...);
  248. /**@}*/
  249. /** @defgroup opusdecoder Opus Decoder
  250. * @{
  251. *
  252. *
  253. * The decoding process also starts with creating a decoder
  254. * state. This can be done with:
  255. * @code
  256. * int error;
  257. * OpusDecoder *dec;
  258. * dec = opus_decoder_create(Fs, channels, &error);
  259. * @endcode
  260. * where
  261. * @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 48000
  262. * @li channels is the number of channels (1 or 2)
  263. * @li error will hold the error code in case or failure (or OPUS_OK on success)
  264. * @li the return value is a newly created decoder state to be used for decoding
  265. *
  266. * While opus_decoder_create() allocates memory for the state, it's also possible
  267. * to initialize pre-allocated memory:
  268. * @code
  269. * int size;
  270. * int error;
  271. * OpusDecoder *dec;
  272. * size = opus_decoder_get_size(channels);
  273. * dec = malloc(size);
  274. * error = opus_decoder_init(dec, Fs, channels);
  275. * @endcode
  276. * where opus_decoder_get_size() returns the required size for the decoder state. Note that
  277. * future versions of this code may change the size, so no assuptions should be made about it.
  278. *
  279. * The decoder state is always continuous in memory and only a shallow copy is sufficient
  280. * to copy it (e.g. memcpy())
  281. *
  282. * To decode a frame, opus_decode() or opus_decode_float() must be called with a packet of compressed audio data:
  283. * @code
  284. * frame_size = opus_decode(enc, packet, len, decoded, max_size);
  285. * @endcode
  286. * where
  287. *
  288. * @li packet is the byte array containing the compressed data
  289. * @li len is the exact number of bytes contained in the packet
  290. * @li decoded is the decoded audio data in opus_int16 (or float for opus_decode_float())
  291. * @li max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array
  292. *
  293. * opus_decode() and opus_decode_frame() return the number of samples ()per channel) decoded from the packet.
  294. * If that value is negative, then an error has occured. This can occur if the packet is corrupted or if the audio
  295. * buffer is too small to hold the decoded audio.
  296. */
  297. /** Opus decoder state.
  298. * This contains the complete state of an Opus decoder.
  299. * It is position independent and can be freely copied.
  300. * @see opus_decoder_create,opus_decoder_init
  301. */
  302. typedef struct OpusDecoder OpusDecoder;
  303. /** Gets the size of an OpusDecoder structure.
  304. * @param [in] channels <tt>int</tt>: Number of channels
  305. * @returns size
  306. */
  307. OPUS_EXPORT int opus_decoder_get_size(int channels);
  308. /** Allocates and initializes a decoder state.
  309. * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
  310. * @param [in] channels <tt>int</tt>: Number of channels (1/2) in input signal
  311. * @param [out] error <tt>int*</tt>: OPUS_OK Success or @ref errorcodes
  312. */
  313. OPUS_EXPORT OpusDecoder *opus_decoder_create(
  314. opus_int32 Fs,
  315. int channels,
  316. int *error
  317. );
  318. /** Initializes a previously allocated decoder state.
  319. * The state must be the size returned by opus_decoder_get_size.
  320. * This is intended for applications which use their own allocator instead of malloc. @see opus_decoder_create,opus_decoder_get_size
  321. * To reset a previously initialized state use the OPUS_RESET_STATE CTL.
  322. * @param [in] st <tt>OpusDecoder*</tt>: Decoder state.
  323. * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
  324. * @param [in] channels <tt>int</tt>: Number of channels (1/2) in input signal
  325. * @retval OPUS_OK Success or @ref errorcodes
  326. */
  327. OPUS_EXPORT int opus_decoder_init(
  328. OpusDecoder *st,
  329. opus_int32 Fs,
  330. int channels
  331. );
  332. /** Decode an Opus frame
  333. * @param [in] st <tt>OpusDecoder*</tt>: Decoder state
  334. * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indicate packet loss
  335. * @param [in] len <tt>int</tt>: Number of bytes in payload*
  336. * @param [out] pcm <tt>opus_int16*</tt>: Output signal (interleaved if 2 channels). length
  337. * is frame_size*channels*sizeof(opus_int16)
  338. * @param [in] frame_size Number of samples per channel of available space in *pcm,
  339. * if less than the maximum frame size (120ms) some frames can not be decoded
  340. * @param [in] decode_fec <tt>int</tt>: Flag (0/1) to request that any in-band forward error correction data be
  341. * decoded. If no such data is available the frame is decoded as if it were lost.
  342. * @returns Number of decoded samples or @ref errorcodes
  343. */
  344. OPUS_EXPORT int opus_decode(
  345. OpusDecoder *st,
  346. const unsigned char *data,
  347. int len,
  348. opus_int16 *pcm,
  349. int frame_size,
  350. int decode_fec
  351. );
  352. /** Decode an opus frame with floating point output
  353. * @param [in] st <tt>OpusDecoder*</tt>: Decoder state
  354. * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indicate packet loss
  355. * @param [in] len <tt>int</tt>: Number of bytes in payload
  356. * @param [out] pcm <tt>float*</tt>: Output signal (interleaved if 2 channels). length
  357. * is frame_size*channels*sizeof(float)
  358. * @param [in] frame_size Number of samples per channel of available space in *pcm,
  359. * if less than the maximum frame size (120ms) some frames can not be decoded
  360. * @param [in] decode_fec <tt>int</tt>: Flag (0/1) to request that any in-band forward error correction data be
  361. * decoded. If no such data is available the frame is decoded as if it were lost.
  362. * @returns Number of decoded samples or @ref errorcodes
  363. */
  364. OPUS_EXPORT int opus_decode_float(
  365. OpusDecoder *st,
  366. const unsigned char *data,
  367. int len,
  368. float *pcm,
  369. int frame_size,
  370. int decode_fec
  371. );
  372. /** Perform a CTL function on an Opus decoder.
  373. * @see decoderctls
  374. */
  375. OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...);
  376. /** Frees an OpusDecoder allocated by opus_decoder_create.
  377. * @param[in] st <tt>OpusDecoder*</tt>: State to be freed.
  378. */
  379. OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);
  380. /** Parse an opus packet into one or more frames.
  381. * Opus_decode will perform this operation internally so most applications do
  382. * not need to use this function.
  383. * This function does not copy the frames, the returned pointers are pointers into
  384. * the input packet.
  385. * @param [in] data <tt>char*</tt>: Opus packet to be parsed
  386. * @param [in] len <tt>int</tt>: size of data
  387. * @param [out] out_toc <tt>char*</tt>: TOC pointer
  388. * @param [out] frames <tt>char*[48]</tt> encapsulated frames
  389. * @param [out] size <tt>short[48]</tt> sizes of the encapsulated frames
  390. * @param [out] payload_offset <tt>int*</tt>: returns the position of the payload within the packet (in bytes)
  391. * @returns number of frames
  392. */
  393. OPUS_EXPORT int opus_packet_parse(
  394. const unsigned char *data,
  395. int len,
  396. unsigned char *out_toc,
  397. const unsigned char *frames[48],
  398. short size[48],
  399. int *payload_offset
  400. );
  401. /** Gets the bandwidth of an Opus packet.
  402. * @param [in] data <tt>char*</tt>: Opus packet
  403. * @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass)
  404. * @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass)
  405. * @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass)
  406. * @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass)
  407. * @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass)
  408. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  409. */
  410. OPUS_EXPORT int opus_packet_get_bandwidth(const unsigned char *data);
  411. /** Gets the number of samples per frame from an Opus packet.
  412. * @param [in] data <tt>char*</tt>: Opus packet
  413. * @param [in] Fs <tt>opus_int32</tt>: Sampling rate in Hz
  414. * @returns Number of samples per frame
  415. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  416. */
  417. OPUS_EXPORT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs);
  418. /** Gets the number of channels from an Opus packet.
  419. * @param [in] data <tt>char*</tt>: Opus packet
  420. * @returns Number of channels
  421. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  422. */
  423. OPUS_EXPORT int opus_packet_get_nb_channels(const unsigned char *data);
  424. /** Gets the number of frame in an Opus packet.
  425. * @param [in] packet <tt>char*</tt>: Opus packet
  426. * @param [in] len <tt>int</tt>: Length of packet
  427. * @returns Number of frames
  428. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  429. */
  430. OPUS_EXPORT int opus_packet_get_nb_frames(const unsigned char packet[], int len);
  431. /** Gets the number of samples of an Opus packet.
  432. * @param [in] dec <tt>OpusDecoder*</tt>: Decoder state
  433. * @param [in] packet <tt>char*</tt>: Opus packet
  434. * @param [in] len <tt>int</tt>: Length of packet
  435. * @returns Number of samples
  436. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  437. */
  438. OPUS_EXPORT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], int len);
  439. /**@}*/
  440. /** @defgroup repacketizer Repacketizer
  441. * @{
  442. *
  443. * The repacketizer can be used to merge multiple Opus packets into a single packet
  444. * or alternatively to split Opus packets that have previously been merged.
  445. *
  446. */
  447. typedef struct OpusRepacketizer OpusRepacketizer;
  448. OPUS_EXPORT int opus_repacketizer_get_size(void);
  449. OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp);
  450. OPUS_EXPORT OpusRepacketizer *opus_repacketizer_create(void);
  451. OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp);
  452. OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, int len);
  453. OPUS_EXPORT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, int maxlen);
  454. OPUS_EXPORT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp);
  455. OPUS_EXPORT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, int maxlen);
  456. /**@}*/
  457. #ifdef __cplusplus
  458. }
  459. #endif
  460. #endif /* OPUS_H */