opus_multistream.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /* Copyright (c) 2011 Xiph.Org Foundation
  2. Written by Jean-Marc Valin */
  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_multistream.h
  26. * @brief Opus reference implementation multistream API
  27. */
  28. #ifndef OPUS_MULTISTREAM_H
  29. #define OPUS_MULTISTREAM_H
  30. #include "opus.h"
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /** @cond OPUS_INTERNAL_DOC */
  35. /** Macros to trigger compilation errors when the wrong types are provided to a
  36. * CTL. */
  37. /**@{*/
  38. #define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr)))
  39. #define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr)))
  40. /**@}*/
  41. /** These are the actual encoder and decoder CTL ID numbers.
  42. * They should not be used directly by applications.
  43. * In general, SETs should be even and GETs should be odd.*/
  44. /**@{*/
  45. #define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120
  46. #define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122
  47. /**@}*/
  48. /** @endcond */
  49. /** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTLs
  50. *
  51. * These are convenience macros that are specific to the
  52. * opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl()
  53. * interface.
  54. * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and
  55. * @ref opus_decoderctls may be applied to a multistream encoder or decoder as
  56. * well.
  57. * In addition, you may retrieve the encoder or decoder state for an specific
  58. * stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or
  59. * #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually.
  60. */
  61. /**@{*/
  62. /** Gets the encoder state for an individual stream of a multistream encoder.
  63. * @param[in] x <tt>opus_int32</tt>: The index of the stream whose encoder you
  64. * wish to retrieve.
  65. * This must be non-negative and less than
  66. * the <code>streams</code> parameter used
  67. * to initialize the encoder.
  68. * @param[out] y <tt>OpusEncoder**</tt>: Returns a pointer to the given
  69. * encoder state.
  70. * @retval OPUS_BAD_ARG The index of the requested stream was out of range.
  71. * @hideinitializer
  72. */
  73. #define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y)
  74. /** Gets the decoder state for an individual stream of a multistream decoder.
  75. * @param[in] x <tt>opus_int32</tt>: The index of the stream whose decoder you
  76. * wish to retrieve.
  77. * This must be non-negative and less than
  78. * the <code>streams</code> parameter used
  79. * to initialize the decoder.
  80. * @param[out] y <tt>OpusDecoder**</tt>: Returns a pointer to the given
  81. * decoder state.
  82. * @retval OPUS_BAD_ARG The index of the requested stream was out of range.
  83. * @hideinitializer
  84. */
  85. #define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y)
  86. /**@}*/
  87. /** @defgroup opus_multistream Opus Multistream API
  88. * @{
  89. *
  90. * The multistream API allows individual Opus streams to be combined into a
  91. * single packet, enabling support for up to 255 channels. Unlike an
  92. * elementary Opus stream, the encoder and decoder must negotiate the channel
  93. * configuration before the decoder can successfully interpret the data in the
  94. * packets produced by the encoder. Some basic information, such as packet
  95. * duration, can be computed without any special negotiation.
  96. *
  97. * The format for multistream Opus packets is defined in the
  98. * <a href="http://tools.ietf.org/html/draft-terriberry-oggopus">Ogg
  99. * encapsulation specification</a> and is based on the self-delimited Opus
  100. * framing described in Appendix B of <a href="http://tools.ietf.org/html/rfc6716">RFC 6716</a>.
  101. * Normal Opus packets are just a degenerate case of multistream Opus packets,
  102. * and can be encoded or decoded with the multistream API by setting
  103. * <code>streams</code> to <code>1</code> when initializing the encoder or
  104. * decoder.
  105. *
  106. * Multistream Opus streams can contain up to 255 elementary Opus streams.
  107. * These may be either "uncoupled" or "coupled", indicating that the decoder
  108. * is configured to decode them to either 1 or 2 channels, respectively.
  109. * The streams are ordered so that all coupled streams appear at the
  110. * beginning.
  111. *
  112. * A <code>mapping</code> table defines which decoded channel <code>i</code>
  113. * should be used for each input/output (I/O) channel <code>j</code>. This table is
  114. * typically provided as an unsigned char array.
  115. * Let <code>i = mapping[j]</code> be the index for I/O channel <code>j</code>.
  116. * If <code>i < 2*coupled_streams</code>, then I/O channel <code>j</code> is
  117. * encoded as the left channel of stream <code>(i/2)</code> if <code>i</code>
  118. * is even, or as the right channel of stream <code>(i/2)</code> if
  119. * <code>i</code> is odd. Otherwise, I/O channel <code>j</code> is encoded as
  120. * mono in stream <code>(i - coupled_streams)</code>, unless it has the special
  121. * value 255, in which case it is omitted from the encoding entirely (the
  122. * decoder will reproduce it as silence). Each value <code>i</code> must either
  123. * be the special value 255 or be less than <code>streams + coupled_streams</code>.
  124. *
  125. * The output channels specified by the encoder
  126. * should use the
  127. * <a href="http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-800004.3.9">Vorbis
  128. * channel ordering</a>. A decoder may wish to apply an additional permutation
  129. * to the mapping the encoder used to achieve a different output channel
  130. * order (e.g. for outputing in WAV order).
  131. *
  132. * Each multistream packet contains an Opus packet for each stream, and all of
  133. * the Opus packets in a single multistream packet must have the same
  134. * duration. Therefore the duration of a multistream packet can be extracted
  135. * from the TOC sequence of the first stream, which is located at the
  136. * beginning of the packet, just like an elementary Opus stream:
  137. *
  138. * @code
  139. * int nb_samples;
  140. * int nb_frames;
  141. * nb_frames = opus_packet_get_nb_frames(data, len);
  142. * if (nb_frames < 1)
  143. * return nb_frames;
  144. * nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames;
  145. * @endcode
  146. *
  147. * The general encoding and decoding process proceeds exactly the same as in
  148. * the normal @ref opus_encoder and @ref opus_decoder APIs.
  149. * See their documentation for an overview of how to use the corresponding
  150. * multistream functions.
  151. */
  152. /** Opus multistream encoder state.
  153. * This contains the complete state of a multistream Opus encoder.
  154. * It is position independent and can be freely copied.
  155. * @see opus_multistream_encoder_create
  156. * @see opus_multistream_encoder_init
  157. */
  158. typedef struct OpusMSEncoder OpusMSEncoder;
  159. /** Opus multistream decoder state.
  160. * This contains the complete state of a multistream Opus decoder.
  161. * It is position independent and can be freely copied.
  162. * @see opus_multistream_decoder_create
  163. * @see opus_multistream_decoder_init
  164. */
  165. typedef struct OpusMSDecoder OpusMSDecoder;
  166. /**\name Multistream encoder functions */
  167. /**@{*/
  168. /** Gets the size of an OpusMSEncoder structure.
  169. * @param streams <tt>int</tt>: The total number of streams to encode from the
  170. * input.
  171. * This must be no more than 255.
  172. * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
  173. * to encode.
  174. * This must be no larger than the total
  175. * number of streams.
  176. * Additionally, The total number of
  177. * encoded channels (<code>streams +
  178. * coupled_streams</code>) must be no
  179. * more than 255.
  180. * @returns The size in bytes on success, or a negative error code
  181. * (see @ref opus_errorcodes) on error.
  182. */
  183. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size(
  184. int streams,
  185. int coupled_streams
  186. );
  187. /** Allocates and initializes a multistream encoder state.
  188. * Call opus_multistream_encoder_destroy() to release
  189. * this object when finished.
  190. * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
  191. * This must be one of 8000, 12000, 16000,
  192. * 24000, or 48000.
  193. * @param channels <tt>int</tt>: Number of channels in the input signal.
  194. * This must be at most 255.
  195. * It may be greater than the number of
  196. * coded channels (<code>streams +
  197. * coupled_streams</code>).
  198. * @param streams <tt>int</tt>: The total number of streams to encode from the
  199. * input.
  200. * This must be no more than the number of channels.
  201. * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
  202. * to encode.
  203. * This must be no larger than the total
  204. * number of streams.
  205. * Additionally, The total number of
  206. * encoded channels (<code>streams +
  207. * coupled_streams</code>) must be no
  208. * more than the number of input channels.
  209. * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
  210. * encoded channels to input channels, as described in
  211. * @ref opus_multistream. As an extra constraint, the
  212. * multistream encoder does not allow encoding coupled
  213. * streams for which one channel is unused since this
  214. * is never a good idea.
  215. * @param application <tt>int</tt>: The target encoder application.
  216. * This must be one of the following:
  217. * <dl>
  218. * <dt>#OPUS_APPLICATION_VOIP</dt>
  219. * <dd>Process signal for improved speech intelligibility.</dd>
  220. * <dt>#OPUS_APPLICATION_AUDIO</dt>
  221. * <dd>Favor faithfulness to the original input.</dd>
  222. * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
  223. * <dd>Configure the minimum possible coding delay by disabling certain modes
  224. * of operation.</dd>
  225. * </dl>
  226. * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
  227. * code (see @ref opus_errorcodes) on
  228. * failure.
  229. */
  230. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create(
  231. opus_int32 Fs,
  232. int channels,
  233. int streams,
  234. int coupled_streams,
  235. const unsigned char *mapping,
  236. int application,
  237. int *error
  238. ) OPUS_ARG_NONNULL(5);
  239. /** Initialize a previously allocated multistream encoder state.
  240. * The memory pointed to by \a st must be at least the size returned by
  241. * opus_multistream_encoder_get_size().
  242. * This is intended for applications which use their own allocator instead of
  243. * malloc.
  244. * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
  245. * @see opus_multistream_encoder_create
  246. * @see opus_multistream_encoder_get_size
  247. * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
  248. * @param Fs <tt>opus_int32</tt>: Sampling rate of the input signal (in Hz).
  249. * This must be one of 8000, 12000, 16000,
  250. * 24000, or 48000.
  251. * @param channels <tt>int</tt>: Number of channels in the input signal.
  252. * This must be at most 255.
  253. * It may be greater than the number of
  254. * coded channels (<code>streams +
  255. * coupled_streams</code>).
  256. * @param streams <tt>int</tt>: The total number of streams to encode from the
  257. * input.
  258. * This must be no more than the number of channels.
  259. * @param coupled_streams <tt>int</tt>: Number of coupled (2 channel) streams
  260. * to encode.
  261. * This must be no larger than the total
  262. * number of streams.
  263. * Additionally, The total number of
  264. * encoded channels (<code>streams +
  265. * coupled_streams</code>) must be no
  266. * more than the number of input channels.
  267. * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
  268. * encoded channels to input channels, as described in
  269. * @ref opus_multistream. As an extra constraint, the
  270. * multistream encoder does not allow encoding coupled
  271. * streams for which one channel is unused since this
  272. * is never a good idea.
  273. * @param application <tt>int</tt>: The target encoder application.
  274. * This must be one of the following:
  275. * <dl>
  276. * <dt>#OPUS_APPLICATION_VOIP</dt>
  277. * <dd>Process signal for improved speech intelligibility.</dd>
  278. * <dt>#OPUS_APPLICATION_AUDIO</dt>
  279. * <dd>Favor faithfulness to the original input.</dd>
  280. * <dt>#OPUS_APPLICATION_RESTRICTED_LOWDELAY</dt>
  281. * <dd>Configure the minimum possible coding delay by disabling certain modes
  282. * of operation.</dd>
  283. * </dl>
  284. * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
  285. * on failure.
  286. */
  287. OPUS_EXPORT int opus_multistream_encoder_init(
  288. OpusMSEncoder *st,
  289. opus_int32 Fs,
  290. int channels,
  291. int streams,
  292. int coupled_streams,
  293. const unsigned char *mapping,
  294. int application
  295. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
  296. /** Encodes a multistream Opus frame.
  297. * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
  298. * @param[in] pcm <tt>const opus_int16*</tt>: The input signal as interleaved
  299. * samples.
  300. * This must contain
  301. * <code>frame_size*channels</code>
  302. * samples.
  303. * @param frame_size <tt>int</tt>: Number of samples per channel in the input
  304. * signal.
  305. * This must be an Opus frame size for the
  306. * encoder's sampling rate.
  307. * For example, at 48 kHz the permitted values
  308. * are 120, 240, 480, 960, 1920, and 2880.
  309. * Passing in a duration of less than 10 ms
  310. * (480 samples at 48 kHz) will prevent the
  311. * encoder from using the LPC or hybrid modes.
  312. * @param[out] data <tt>unsigned char*</tt>: Output payload.
  313. * This must contain storage for at
  314. * least \a max_data_bytes.
  315. * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
  316. * memory for the output
  317. * payload. This may be
  318. * used to impose an upper limit on
  319. * the instant bitrate, but should
  320. * not be used as the only bitrate
  321. * control. Use #OPUS_SET_BITRATE to
  322. * control the bitrate.
  323. * @returns The length of the encoded packet (in bytes) on success or a
  324. * negative error code (see @ref opus_errorcodes) on failure.
  325. */
  326. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode(
  327. OpusMSEncoder *st,
  328. const opus_int16 *pcm,
  329. int frame_size,
  330. unsigned char *data,
  331. opus_int32 max_data_bytes
  332. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
  333. /** Encodes a multistream Opus frame from floating point input.
  334. * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
  335. * @param[in] pcm <tt>const float*</tt>: The input signal as interleaved
  336. * samples with a normal range of
  337. * +/-1.0.
  338. * Samples with a range beyond +/-1.0
  339. * are supported but will be clipped by
  340. * decoders using the integer API and
  341. * should only be used if it is known
  342. * that the far end supports extended
  343. * dynamic range.
  344. * This must contain
  345. * <code>frame_size*channels</code>
  346. * samples.
  347. * @param frame_size <tt>int</tt>: Number of samples per channel in the input
  348. * signal.
  349. * This must be an Opus frame size for the
  350. * encoder's sampling rate.
  351. * For example, at 48 kHz the permitted values
  352. * are 120, 240, 480, 960, 1920, and 2880.
  353. * Passing in a duration of less than 10 ms
  354. * (480 samples at 48 kHz) will prevent the
  355. * encoder from using the LPC or hybrid modes.
  356. * @param[out] data <tt>unsigned char*</tt>: Output payload.
  357. * This must contain storage for at
  358. * least \a max_data_bytes.
  359. * @param [in] max_data_bytes <tt>opus_int32</tt>: Size of the allocated
  360. * memory for the output
  361. * payload. This may be
  362. * used to impose an upper limit on
  363. * the instant bitrate, but should
  364. * not be used as the only bitrate
  365. * control. Use #OPUS_SET_BITRATE to
  366. * control the bitrate.
  367. * @returns The length of the encoded packet (in bytes) on success or a
  368. * negative error code (see @ref opus_errorcodes) on failure.
  369. */
  370. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float(
  371. OpusMSEncoder *st,
  372. const float *pcm,
  373. int frame_size,
  374. unsigned char *data,
  375. opus_int32 max_data_bytes
  376. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
  377. /** Frees an <code>OpusMSEncoder</code> allocated by
  378. * opus_multistream_encoder_create().
  379. * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to be freed.
  380. */
  381. OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st);
  382. /** Perform a CTL function on a multistream Opus encoder.
  383. *
  384. * Generally the request and subsequent arguments are generated by a
  385. * convenience macro.
  386. * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state.
  387. * @param request This and all remaining parameters should be replaced by one
  388. * of the convenience macros in @ref opus_genericctls,
  389. * @ref opus_encoderctls, or @ref opus_multistream_ctls.
  390. * @see opus_genericctls
  391. * @see opus_encoderctls
  392. * @see opus_multistream_ctls
  393. */
  394. OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
  395. /**@}*/
  396. /**\name Multistream decoder functions */
  397. /**@{*/
  398. /** Gets the size of an <code>OpusMSDecoder</code> structure.
  399. * @param streams <tt>int</tt>: The total number of streams coded in the
  400. * input.
  401. * This must be no more than 255.
  402. * @param coupled_streams <tt>int</tt>: Number streams to decode as coupled
  403. * (2 channel) streams.
  404. * This must be no larger than the total
  405. * number of streams.
  406. * Additionally, The total number of
  407. * coded channels (<code>streams +
  408. * coupled_streams</code>) must be no
  409. * more than 255.
  410. * @returns The size in bytes on success, or a negative error code
  411. * (see @ref opus_errorcodes) on error.
  412. */
  413. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size(
  414. int streams,
  415. int coupled_streams
  416. );
  417. /** Allocates and initializes a multistream decoder state.
  418. * Call opus_multistream_decoder_destroy() to release
  419. * this object when finished.
  420. * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
  421. * This must be one of 8000, 12000, 16000,
  422. * 24000, or 48000.
  423. * @param channels <tt>int</tt>: Number of channels to output.
  424. * This must be at most 255.
  425. * It may be different from the number of coded
  426. * channels (<code>streams +
  427. * coupled_streams</code>).
  428. * @param streams <tt>int</tt>: The total number of streams coded in the
  429. * input.
  430. * This must be no more than 255.
  431. * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
  432. * (2 channel) streams.
  433. * This must be no larger than the total
  434. * number of streams.
  435. * Additionally, The total number of
  436. * coded channels (<code>streams +
  437. * coupled_streams</code>) must be no
  438. * more than 255.
  439. * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
  440. * coded channels to output channels, as described in
  441. * @ref opus_multistream.
  442. * @param[out] error <tt>int *</tt>: Returns #OPUS_OK on success, or an error
  443. * code (see @ref opus_errorcodes) on
  444. * failure.
  445. */
  446. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create(
  447. opus_int32 Fs,
  448. int channels,
  449. int streams,
  450. int coupled_streams,
  451. const unsigned char *mapping,
  452. int *error
  453. ) OPUS_ARG_NONNULL(5);
  454. /** Intialize a previously allocated decoder state object.
  455. * The memory pointed to by \a st must be at least the size returned by
  456. * opus_multistream_encoder_get_size().
  457. * This is intended for applications which use their own allocator instead of
  458. * malloc.
  459. * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL.
  460. * @see opus_multistream_decoder_create
  461. * @see opus_multistream_deocder_get_size
  462. * @param st <tt>OpusMSEncoder*</tt>: Multistream encoder state to initialize.
  463. * @param Fs <tt>opus_int32</tt>: Sampling rate to decode at (in Hz).
  464. * This must be one of 8000, 12000, 16000,
  465. * 24000, or 48000.
  466. * @param channels <tt>int</tt>: Number of channels to output.
  467. * This must be at most 255.
  468. * It may be different from the number of coded
  469. * channels (<code>streams +
  470. * coupled_streams</code>).
  471. * @param streams <tt>int</tt>: The total number of streams coded in the
  472. * input.
  473. * This must be no more than 255.
  474. * @param coupled_streams <tt>int</tt>: Number of streams to decode as coupled
  475. * (2 channel) streams.
  476. * This must be no larger than the total
  477. * number of streams.
  478. * Additionally, The total number of
  479. * coded channels (<code>streams +
  480. * coupled_streams</code>) must be no
  481. * more than 255.
  482. * @param[in] mapping <code>const unsigned char[channels]</code>: Mapping from
  483. * coded channels to output channels, as described in
  484. * @ref opus_multistream.
  485. * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes)
  486. * on failure.
  487. */
  488. OPUS_EXPORT int opus_multistream_decoder_init(
  489. OpusMSDecoder *st,
  490. opus_int32 Fs,
  491. int channels,
  492. int streams,
  493. int coupled_streams,
  494. const unsigned char *mapping
  495. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
  496. /** Decode a multistream Opus packet.
  497. * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
  498. * @param[in] data <tt>const unsigned char*</tt>: Input payload.
  499. * Use a <code>NULL</code>
  500. * pointer to indicate packet
  501. * loss.
  502. * @param len <tt>opus_int32</tt>: Number of bytes in payload.
  503. * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
  504. * samples.
  505. * This must contain room for
  506. * <code>frame_size*channels</code>
  507. * samples.
  508. * @param frame_size <tt>int</tt>: The number of samples per channel of
  509. * available space in \a pcm.
  510. * If this is less than the maximum packet duration
  511. * (120 ms; 5760 for 48kHz), this function will not be capable
  512. * of decoding some packets. In the case of PLC (data==NULL)
  513. * or FEC (decode_fec=1), then frame_size needs to be exactly
  514. * the duration of audio that is missing, otherwise the
  515. * decoder will not be in the optimal state to decode the
  516. * next incoming packet. For the PLC and FEC cases, frame_size
  517. * <b>must</b> be a multiple of 2.5 ms.
  518. * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
  519. * forward error correction data be decoded.
  520. * If no such data is available, the frame is
  521. * decoded as if it were lost.
  522. * @returns Number of samples decoded on success or a negative error code
  523. * (see @ref opus_errorcodes) on failure.
  524. */
  525. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode(
  526. OpusMSDecoder *st,
  527. const unsigned char *data,
  528. opus_int32 len,
  529. opus_int16 *pcm,
  530. int frame_size,
  531. int decode_fec
  532. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
  533. /** Decode a multistream Opus packet with floating point output.
  534. * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
  535. * @param[in] data <tt>const unsigned char*</tt>: Input payload.
  536. * Use a <code>NULL</code>
  537. * pointer to indicate packet
  538. * loss.
  539. * @param len <tt>opus_int32</tt>: Number of bytes in payload.
  540. * @param[out] pcm <tt>opus_int16*</tt>: Output signal, with interleaved
  541. * samples.
  542. * This must contain room for
  543. * <code>frame_size*channels</code>
  544. * samples.
  545. * @param frame_size <tt>int</tt>: The number of samples per channel of
  546. * available space in \a pcm.
  547. * If this is less than the maximum packet duration
  548. * (120 ms; 5760 for 48kHz), this function will not be capable
  549. * of decoding some packets. In the case of PLC (data==NULL)
  550. * or FEC (decode_fec=1), then frame_size needs to be exactly
  551. * the duration of audio that is missing, otherwise the
  552. * decoder will not be in the optimal state to decode the
  553. * next incoming packet. For the PLC and FEC cases, frame_size
  554. * <b>must</b> be a multiple of 2.5 ms.
  555. * @param decode_fec <tt>int</tt>: Flag (0 or 1) to request that any in-band
  556. * forward error correction data be decoded.
  557. * If no such data is available, the frame is
  558. * decoded as if it were lost.
  559. * @returns Number of samples decoded on success or a negative error code
  560. * (see @ref opus_errorcodes) on failure.
  561. */
  562. OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float(
  563. OpusMSDecoder *st,
  564. const unsigned char *data,
  565. opus_int32 len,
  566. float *pcm,
  567. int frame_size,
  568. int decode_fec
  569. ) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
  570. /** Perform a CTL function on a multistream Opus decoder.
  571. *
  572. * Generally the request and subsequent arguments are generated by a
  573. * convenience macro.
  574. * @param st <tt>OpusMSDecoder*</tt>: Multistream decoder state.
  575. * @param request This and all remaining parameters should be replaced by one
  576. * of the convenience macros in @ref opus_genericctls,
  577. * @ref opus_decoderctls, or @ref opus_multistream_ctls.
  578. * @see opus_genericctls
  579. * @see opus_decoderctls
  580. * @see opus_multistream_ctls
  581. */
  582. OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
  583. /** Frees an <code>OpusMSDecoder</code> allocated by
  584. * opus_multistream_decoder_create().
  585. * @param st <tt>OpusMSDecoder</tt>: Multistream decoder state to be freed.
  586. */
  587. OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st);
  588. /**@}*/
  589. /**@}*/
  590. #ifdef __cplusplus
  591. }
  592. #endif
  593. #endif /* OPUS_MULTISTREAM_H */