opus.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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 COPYRIGHT OWNER
  16. OR 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 to 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 Support for multichannel (up to 255 channels)
  53. * @li Frame sizes from 2.5 ms to 60 ms
  54. * @li Good loss robustness and packet loss concealment (PLC)
  55. * @li Floating point and fixed-point implementation
  56. *
  57. * Documentation sections:
  58. * @li @ref opus_encoder
  59. * @li @ref opus_decoder
  60. * @li @ref opus_repacketizer
  61. * @li @ref opus_libinfo
  62. * @li @ref opus_custom
  63. */
  64. /** @defgroup opus_encoder Opus Encoder
  65. * @{
  66. *
  67. * @brief This page describes the process and functions used to encode Opus.
  68. *
  69. * Since Opus is a stateful codec, the encoding process starts with creating an encoder
  70. * state. This can be done with:
  71. *
  72. * @code
  73. * int error;
  74. * OpusEncoder *enc;
  75. * enc = opus_encoder_create(Fs, channels, application, &error);
  76. * @endcode
  77. *
  78. * From this point, @c enc can be used for encoding an audio stream. An encoder state
  79. * @b must @b not be used for more than one stream at the same time. Similarly, the encoder
  80. * state @b must @b not be re-initialized for each frame.
  81. *
  82. * While opus_encoder_create() allocates memory for the state, it's also possible
  83. * to initialize pre-allocated memory:
  84. *
  85. * @code
  86. * int size;
  87. * int error;
  88. * OpusEncoder *enc;
  89. * size = opus_encoder_get_size(channels);
  90. * enc = malloc(size);
  91. * error = opus_encoder_init(enc, Fs, channels, application);
  92. * @endcode
  93. *
  94. * where opus_encoder_get_size() returns the required size for the encoder state. Note that
  95. * future versions of this code may change the size, so no assuptions should be made about it.
  96. *
  97. * The encoder state is always continuous in memory and only a shallow copy is sufficient
  98. * to copy it (e.g. memcpy())
  99. *
  100. * It is possible to change some of the encoder's settings using the opus_encoder_ctl()
  101. * interface. All these settings already default to the recommended value, so they should
  102. * only be changed when necessary. The most common settings one may want to change are:
  103. *
  104. * @code
  105. * opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate));
  106. * opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity));
  107. * opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type));
  108. * @endcode
  109. *
  110. * where
  111. *
  112. * @arg bitrate is in bits per second (b/s)
  113. * @arg complexity is a value from 1 to 10, where 1 is the lowest complexity and 10 is the highest
  114. * @arg signal_type is either OPUS_AUTO (default), OPUS_SIGNAL_VOICE, or OPUS_SIGNAL_MUSIC
  115. *
  116. * See @ref opus_encoderctls and @ref opus_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.
  117. *
  118. * 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:
  119. * @code
  120. * len = opus_encode(enc, audio_frame, frame_size, packet, max_packet);
  121. * @endcode
  122. *
  123. * where
  124. * <ul>
  125. * <li>audio_frame is the audio data in opus_int16 (or float for opus_encode_float())</li>
  126. * <li>frame_size is the duration of the frame in samples (per channel)</li>
  127. * <li>packet is the byte array to which the compressed data is written</li>
  128. * <li>max_packet is the maximum number of bytes that can be written in the packet (4000 bytes is recommended)</li>
  129. * </ul>
  130. *
  131. * opus_encode() and opus_encode_frame() return the number of bytes actually written to the packet.
  132. * The return value <b>can be negative</b>, which indicates that an error has occurred. If the return value
  133. * is 1 byte, then the packet does not need to be transmitted (DTX).
  134. *
  135. * Once the encoder state if no longer needed, it can be destroyed with
  136. *
  137. * @code
  138. * opus_encoder_destroy(enc);
  139. * @endcode
  140. *
  141. * If the encoder was created with opus_encoder_init() rather than opus_encoder_create(),
  142. * then no action is required aside from potentially freeing the memory that was manually
  143. * allocated for it (calling free(enc) for the example above)
  144. *
  145. */
  146. /** Opus encoder state.
  147. * This contains the complete state of an Opus encoder.
  148. * It is position independent and can be freely copied.
  149. * @see opus_encoder_create,opus_encoder_init
  150. */
  151. typedef struct OpusEncoder OpusEncoder;
  152. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels);
  153. /**
  154. */
  155. /** Allocates and initializes an encoder state.
  156. * There are three coding modes:
  157. *
  158. * @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voice
  159. * signals. It enhances the input signal by high-pass filtering and
  160. * emphasizing formants and harmonics. Optionally it includes in-band
  161. * forward error correction to protect against packet loss. Use this
  162. * mode for typical VoIP applications. Because of the enhancement,
  163. * even at high bitrates the output may sound different from the input.
  164. *
  165. * @ref OPUS_APPLICATION_AUDIO gives best quality at a given bitrate for most
  166. * non-voice signals like music. Use this mode for music and mixed
  167. * (music/voice) content, broadcast, and applications requiring less
  168. * than 15 ms of coding delay.
  169. *
  170. * @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that
  171. * disables the speech-optimized mode in exchange for slightly reduced delay.
  172. * This mode can only be set on an newly initialized or freshly reset encoder
  173. * because it changes the codec delay.
  174. *
  175. * This is useful when the caller knows that the speech-optimized modes will not be needed (use with caution).
  176. * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
  177. * @param [in] channels <tt>int</tt>: Number of channels (1/2) in input signal
  178. * @param [in] application <tt>int</tt>: Coding mode (@ref OPUS_APPLICATION_VOIP/@ref OPUS_APPLICATION_AUDIO/@ref OPUS_APPLICATION_RESTRICTED_LOWDELAY)
  179. * @param [out] error <tt>int*</tt>: @ref opus_errorcodes
  180. * @note Regardless of the sampling rate and number channels selected, the Opus encoder
  181. * can switch to a lower audio audio bandwidth or number of channels if the bitrate
  182. * selected is too low. This also means that it is safe to always use 48 kHz stereo input
  183. * and let the encoder optimize the encoding.
  184. */
  185. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create(
  186. opus_int32 Fs,
  187. int channels,
  188. int application,
  189. int *error
  190. );
  191. /** Initializes a previously allocated encoder state
  192. * The memory pointed to by st must be the size returned by opus_encoder_get_size.
  193. * This is intended for applications which use their own allocator instead of malloc.
  194. * @see opus_encoder_create(),opus_encoder_get_size()
  195. * To reset a previously initialized state use the OPUS_RESET_STATE CTL.
  196. * @param [in] st <tt>OpusEncoder*</tt>: Encoder state
  197. * @param [in] Fs <tt>opus_int32</tt>: Sampling rate of input signal (Hz)
  198. * @param [in] channels <tt>int</tt>: Number of channels (1/2) in input signal
  199. * @param [in] application <tt>int</tt>: Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY)
  200. * @retval OPUS_OK Success or @ref opus_errorcodes
  201. */
  202. OPUS_EXPORT int opus_encoder_init(
  203. OpusEncoder *st,
  204. opus_int32 Fs,
  205. int channels,
  206. int application
  207. ) OPUS_ARG_NONNULL(1);
  208. /** Encodes an Opus frame.
  209. * The passed frame_size must an opus frame size for the encoder's sampling rate.
  210. * For example, at 48kHz the permitted values are 120, 240, 480, or 960.
  211. * Passing in a duration of less than 10ms (480 samples at 48kHz) will
  212. * prevent the encoder from using the LPC or hybrid modes.
  213. * @param [in] st <tt>OpusEncoder*</tt>: Encoder state
  214. * @param [in] pcm <tt>opus_int16*</tt>: Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(opus_int16)
  215. * @param [in] frame_size <tt>int</tt>: Number of samples per frame of input signal
  216. * @param [out] data <tt>char*</tt>: Output payload (at least max_data_bytes long)
  217. * @param [in] max_data_bytes <tt>opus_int32</tt>: Allocated memory for payload; don't use for controlling bitrate
  218. * @returns length of the data payload (in bytes) or @ref opus_errorcodes
  219. */
  220. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode(
  221. OpusEncoder *st,
  222. const opus_int16 *pcm,
  223. int frame_size,
  224. unsigned char *data,
  225. opus_int32 max_data_bytes
  226. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
  227. /** Encodes an Opus frame from floating point input.
  228. * The passed frame_size must an opus frame size for the encoder's sampling rate.
  229. * For example, at 48kHz the permitted values are 120, 240, 480, or 960.
  230. * Passing in a duration of less than 10ms (480 samples at 48kHz) will
  231. * prevent the encoder from using the LPC or hybrid modes.
  232. * @param [in] st <tt>OpusEncoder*</tt>: Encoder state
  233. * @param [in] pcm <tt>float*</tt>: Input in float format (interleaved if 2 channels), with a normal range of +/-1.0.
  234. * Samples with a range beyond +/-1.0 are supported but will
  235. * be clipped by decoders using the integer API and should
  236. * only be used if it is known that the far end supports
  237. * extended dynamic range.
  238. * length is frame_size*channels*sizeof(float)
  239. * @param [in] frame_size <tt>int</tt>: Number of samples per frame of input signal
  240. * @param [out] data <tt>char*</tt>: Output payload (at least max_data_bytes long)
  241. * @param [in] max_data_bytes <tt>opus_int32</tt>: Allocated memory for payload; don't use for controlling bitrate
  242. * @returns length of the data payload (in bytes) or @ref opus_errorcodes
  243. */
  244. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float(
  245. OpusEncoder *st,
  246. const float *pcm,
  247. int frame_size,
  248. unsigned char *data,
  249. opus_int32 max_data_bytes
  250. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
  251. /** Frees an OpusEncoder allocated by opus_encoder_create.
  252. * @param[in] st <tt>OpusEncoder*</tt>: State to be freed.
  253. */
  254. OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st);
  255. /** Perform a CTL function on an Opus encoder.
  256. *
  257. * Generally the request and subsequent arguments are generated
  258. * by a convenience macro.
  259. * @see opus_encoderctls
  260. */
  261. OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
  262. /**@}*/
  263. /** @defgroup opus_decoder Opus Decoder
  264. * @{
  265. *
  266. * @brief This page describes the process and functions used to decode Opus.
  267. *
  268. * The decoding process also starts with creating a decoder
  269. * state. This can be done with:
  270. * @code
  271. * int error;
  272. * OpusDecoder *dec;
  273. * dec = opus_decoder_create(Fs, channels, &error);
  274. * @endcode
  275. * where
  276. * @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 48000
  277. * @li channels is the number of channels (1 or 2)
  278. * @li error will hold the error code in case or failure (or OPUS_OK on success)
  279. * @li the return value is a newly created decoder state to be used for decoding
  280. *
  281. * While opus_decoder_create() allocates memory for the state, it's also possible
  282. * to initialize pre-allocated memory:
  283. * @code
  284. * int size;
  285. * int error;
  286. * OpusDecoder *dec;
  287. * size = opus_decoder_get_size(channels);
  288. * dec = malloc(size);
  289. * error = opus_decoder_init(dec, Fs, channels);
  290. * @endcode
  291. * where opus_decoder_get_size() returns the required size for the decoder state. Note that
  292. * future versions of this code may change the size, so no assuptions should be made about it.
  293. *
  294. * The decoder state is always continuous in memory and only a shallow copy is sufficient
  295. * to copy it (e.g. memcpy())
  296. *
  297. * To decode a frame, opus_decode() or opus_decode_float() must be called with a packet of compressed audio data:
  298. * @code
  299. * frame_size = opus_decode(dec, packet, len, decoded, max_size, 0);
  300. * @endcode
  301. * where
  302. *
  303. * @li packet is the byte array containing the compressed data
  304. * @li len is the exact number of bytes contained in the packet
  305. * @li decoded is the decoded audio data in opus_int16 (or float for opus_decode_float())
  306. * @li max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array
  307. *
  308. * opus_decode() and opus_decode_float() return the number of samples (per channel) decoded from the packet.
  309. * If that value is negative, then an error has occured. This can occur if the packet is corrupted or if the audio
  310. * buffer is too small to hold the decoded audio.
  311. */
  312. /** Opus decoder state.
  313. * This contains the complete state of an Opus decoder.
  314. * It is position independent and can be freely copied.
  315. * @see opus_decoder_create,opus_decoder_init
  316. */
  317. typedef struct OpusDecoder OpusDecoder;
  318. /** Gets the size of an OpusDecoder structure.
  319. * @param [in] channels <tt>int</tt>: Number of channels
  320. * @returns size
  321. */
  322. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels);
  323. /** Allocates and initializes a decoder state.
  324. * @param [in] Fs <tt>opus_int32</tt>: Sample rate to decode at (Hz)
  325. * @param [in] channels <tt>int</tt>: Number of channels (1/2) to decode
  326. * @param [out] error <tt>int*</tt>: OPUS_OK Success or @ref opus_errorcodes
  327. *
  328. * Internally Opus stores data at 48000 Hz, so that should be the default
  329. * value for Fs. However, the decoder can efficiently decode to buffers
  330. * at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use
  331. * data at the full sample rate, or knows the compressed data doesn't
  332. * use the full frequency range, it can request decoding at a reduced
  333. * rate. Likewise, the decoder is capable of filling in either mono or
  334. * interleaved stereo pcm buffers, at the caller's request.
  335. */
  336. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create(
  337. opus_int32 Fs,
  338. int channels,
  339. int *error
  340. );
  341. /** Initializes a previously allocated decoder state.
  342. * The state must be the size returned by opus_decoder_get_size.
  343. * This is intended for applications which use their own allocator instead of malloc. @see opus_decoder_create,opus_decoder_get_size
  344. * To reset a previously initialized state use the OPUS_RESET_STATE CTL.
  345. * @param [in] st <tt>OpusDecoder*</tt>: Decoder state.
  346. * @param [in] Fs <tt>opus_int32</tt>: Sampling rate to decode to (Hz)
  347. * @param [in] channels <tt>int</tt>: Number of channels (1/2) to decode
  348. * @retval OPUS_OK Success or @ref opus_errorcodes
  349. */
  350. OPUS_EXPORT int opus_decoder_init(
  351. OpusDecoder *st,
  352. opus_int32 Fs,
  353. int channels
  354. ) OPUS_ARG_NONNULL(1);
  355. /** Decode an Opus frame
  356. * @param [in] st <tt>OpusDecoder*</tt>: Decoder state
  357. * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indicate packet loss
  358. * @param [in] len <tt>opus_int32</tt>: Number of bytes in payload*
  359. * @param [out] pcm <tt>opus_int16*</tt>: Output signal (interleaved if 2 channels). length
  360. * is frame_size*channels*sizeof(opus_int16)
  361. * @param [in] frame_size Number of samples per channel of available space in *pcm,
  362. * if less than the maximum frame size (120ms) some frames can not be decoded
  363. * @param [in] decode_fec <tt>int</tt>: Flag (0/1) to request that any in-band forward error correction data be
  364. * decoded. If no such data is available the frame is decoded as if it were lost.
  365. * @returns Number of decoded samples or @ref opus_errorcodes
  366. */
  367. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode(
  368. OpusDecoder *st,
  369. const unsigned char *data,
  370. opus_int32 len,
  371. opus_int16 *pcm,
  372. int frame_size,
  373. int decode_fec
  374. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
  375. /** Decode an opus frame with floating point output
  376. * @param [in] st <tt>OpusDecoder*</tt>: Decoder state
  377. * @param [in] data <tt>char*</tt>: Input payload. Use a NULL pointer to indicate packet loss
  378. * @param [in] len <tt>opus_int32</tt>: Number of bytes in payload
  379. * @param [out] pcm <tt>float*</tt>: Output signal (interleaved if 2 channels). length
  380. * is frame_size*channels*sizeof(float)
  381. * @param [in] frame_size Number of samples per channel of available space in *pcm,
  382. * if less than the maximum frame size (120ms) some frames can not be decoded
  383. * @param [in] decode_fec <tt>int</tt>: Flag (0/1) to request that any in-band forward error correction data be
  384. * decoded. If no such data is available the frame is decoded as if it were lost.
  385. * @returns Number of decoded samples or @ref opus_errorcodes
  386. */
  387. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float(
  388. OpusDecoder *st,
  389. const unsigned char *data,
  390. opus_int32 len,
  391. float *pcm,
  392. int frame_size,
  393. int decode_fec
  394. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
  395. /** Perform a CTL function on an Opus decoder.
  396. *
  397. * Generally the request and subsequent arguments are generated
  398. * by a convenience macro.
  399. * @see opus_genericctls
  400. */
  401. OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
  402. /** Frees an OpusDecoder allocated by opus_decoder_create.
  403. * @param[in] st <tt>OpusDecoder*</tt>: State to be freed.
  404. */
  405. OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st);
  406. /** Parse an opus packet into one or more frames.
  407. * Opus_decode will perform this operation internally so most applications do
  408. * not need to use this function.
  409. * This function does not copy the frames, the returned pointers are pointers into
  410. * the input packet.
  411. * @param [in] data <tt>char*</tt>: Opus packet to be parsed
  412. * @param [in] len <tt>opus_int32</tt>: size of data
  413. * @param [out] out_toc <tt>char*</tt>: TOC pointer
  414. * @param [out] frames <tt>char*[48]</tt> encapsulated frames
  415. * @param [out] size <tt>short[48]</tt> sizes of the encapsulated frames
  416. * @param [out] payload_offset <tt>int*</tt>: returns the position of the payload within the packet (in bytes)
  417. * @returns number of frames
  418. */
  419. OPUS_EXPORT int opus_packet_parse(
  420. const unsigned char *data,
  421. opus_int32 len,
  422. unsigned char *out_toc,
  423. const unsigned char *frames[48],
  424. short size[48],
  425. int *payload_offset
  426. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
  427. /** Gets the bandwidth of an Opus packet.
  428. * @param [in] data <tt>char*</tt>: Opus packet
  429. * @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass)
  430. * @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass)
  431. * @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass)
  432. * @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass)
  433. * @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass)
  434. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  435. */
  436. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1);
  437. /** Gets the number of samples per frame from an Opus packet.
  438. * @param [in] data <tt>char*</tt>: Opus packet
  439. * @param [in] Fs <tt>opus_int32</tt>: Sampling rate in Hz
  440. * @returns Number of samples per frame
  441. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  442. */
  443. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1);
  444. /** Gets the number of channels from an Opus packet.
  445. * @param [in] data <tt>char*</tt>: Opus packet
  446. * @returns Number of channels
  447. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  448. */
  449. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1);
  450. /** Gets the number of frames in an Opus packet.
  451. * @param [in] packet <tt>char*</tt>: Opus packet
  452. * @param [in] len <tt>opus_int32</tt>: Length of packet
  453. * @returns Number of frames
  454. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  455. */
  456. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1);
  457. /** Gets the number of samples of an Opus packet.
  458. * @param [in] dec <tt>OpusDecoder*</tt>: Decoder state
  459. * @param [in] packet <tt>char*</tt>: Opus packet
  460. * @param [in] len <tt>opus_int32</tt>: Length of packet
  461. * @returns Number of samples
  462. * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type
  463. */
  464. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
  465. /**@}*/
  466. /** @defgroup opus_repacketizer Repacketizer
  467. * @{
  468. *
  469. * The repacketizer can be used to merge multiple Opus packets into a single packet
  470. * or alternatively to split Opus packets that have previously been merged.
  471. *
  472. */
  473. typedef struct OpusRepacketizer OpusRepacketizer;
  474. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void);
  475. OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
  476. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void);
  477. OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp);
  478. OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2);
  479. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
  480. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1);
  481. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1);
  482. /**@}*/
  483. #ifdef __cplusplus
  484. }
  485. #endif
  486. #endif /* OPUS_H */