Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 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 | |
| 8 | - Redistributions of source code must retain the above copyright |
| 9 | notice, this list of conditions and the following disclaimer. |
| 10 | |
| 11 | - Redistributions in binary form must reproduce the above copyright |
| 12 | notice, this list of conditions and the following disclaimer in the |
| 13 | documentation and/or other materials provided with the distribution. |
| 14 | |
| 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
Jean-Marc Valin | cb05e7c | 2012-04-20 16:40:24 -0400 | [diff] [blame] | 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
| 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 28 | /** |
| 29 | * @file opus_multistream.h |
| 30 | * @brief Opus reference implementation multistream API |
| 31 | */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 32 | |
| 33 | #ifndef OPUS_MULTISTREAM_H |
| 34 | #define OPUS_MULTISTREAM_H |
| 35 | |
| 36 | #include "opus.h" |
| 37 | |
Ralph Giles | 64c2dd7 | 2012-05-23 16:33:14 -0700 | [diff] [blame] | 38 | #ifdef __cplusplus |
| 39 | extern "C" { |
| 40 | #endif |
| 41 | |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 42 | typedef struct OpusMSEncoder OpusMSEncoder; |
| 43 | typedef struct OpusMSDecoder OpusMSDecoder; |
| 44 | |
Jean-Marc Valin | af50ce9 | 2011-09-11 20:13:47 -0400 | [diff] [blame] | 45 | #define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) |
| 46 | #define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) |
| 47 | |
| 48 | #define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 |
| 49 | #define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 |
| 50 | |
| 51 | #define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) |
| 52 | #define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) |
| 53 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 54 | /** Allocate and initialize a multistream encoder state object. |
| 55 | * Call opus_multistream_encoder_destroy() to release |
| 56 | * this object when finished. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 57 | OPUS_EXPORT OpusMSEncoder *opus_multistream_encoder_create( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 58 | opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ |
| 59 | int channels, /**< Number of channels in the input signal */ |
| 60 | int streams, /**< Total number of streams to encode from the input */ |
| 61 | int coupled_streams, /**< Number of coupled (stereo) streams to encode */ |
Vincent Penquerc'h | ab0b5f5 | 2011-11-23 15:17:30 +0000 | [diff] [blame] | 62 | const unsigned char *mapping, /**< Encoded mapping between channels and streams */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 63 | int application, /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ |
| 64 | int *error /**< Error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 65 | ); |
| 66 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 67 | /** Initialize an already allocated multistream encoder state. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 68 | OPUS_EXPORT int opus_multistream_encoder_init( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 69 | OpusMSEncoder *st, /**< Encoder state */ |
| 70 | opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ |
| 71 | int channels, /**< Number of channels in the input signal */ |
| 72 | int streams, /**< Total number of streams to encode from the input */ |
| 73 | int coupled_streams, /**< Number of coupled (stereo) streams to encode */ |
Vincent Penquerc'h | ab0b5f5 | 2011-11-23 15:17:30 +0000 | [diff] [blame] | 74 | const unsigned char *mapping, /**< Encoded mapping between channels and streams */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 75 | int application /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 76 | ); |
| 77 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 78 | /** Returns length of the data payload (in bytes) or a negative error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 79 | OPUS_EXPORT int opus_multistream_encode( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 80 | OpusMSEncoder *st, /**< Encoder state */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 81 | const opus_int16 *pcm, /**< Input signal as interleaved samples. Length is frame_size*channels */ |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 82 | int frame_size, /**< Number of samples per frame of input signal */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 83 | unsigned char *data, /**< Output buffer for the compressed payload (no more than max_data_bytes long) */ |
Jean-Marc Valin | 59354a7 | 2012-03-08 12:19:07 -0500 | [diff] [blame] | 84 | opus_int32 max_data_bytes /**< Allocated memory for payload; don't use for controlling bitrate */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 85 | ); |
| 86 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 87 | /** Returns length of the data payload (in bytes) or a negative error code. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 88 | OPUS_EXPORT int opus_multistream_encode_float( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 89 | OpusMSEncoder *st, /**< Encoder state */ |
| 90 | const float *pcm, /**< Input signal interleaved in channel order. length is frame_size*channels */ |
| 91 | int frame_size, /**< Number of samples per frame of input signal */ |
| 92 | unsigned char *data, /**< Output buffer for the compressed payload (no more than max_data_bytes long) */ |
Jean-Marc Valin | 59354a7 | 2012-03-08 12:19:07 -0500 | [diff] [blame] | 93 | opus_int32 max_data_bytes /**< Allocated memory for payload; don't use for controlling bitrate */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 94 | ); |
| 95 | |
Gregory Maxwell | c81b510 | 2011-10-30 02:16:25 -0400 | [diff] [blame] | 96 | /** Gets the size of an OpusMSEncoder structure. |
| 97 | * @returns size |
| 98 | */ |
| 99 | OPUS_EXPORT opus_int32 opus_multistream_encoder_get_size( |
| 100 | int streams, /**< Total number of coded streams */ |
| 101 | int coupled_streams /**< Number of coupled (stereo) streams */ |
| 102 | ); |
| 103 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 104 | /** Deallocate a multstream encoder state */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 105 | OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); |
| 106 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 107 | /** Get or set options on a multistream encoder state */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 108 | OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...); |
| 109 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 110 | /** Allocate and initialize a multistream decoder state object. |
| 111 | * Call opus_multistream_decoder_destroy() to release |
| 112 | * this object when finished. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 113 | OPUS_EXPORT OpusMSDecoder *opus_multistream_decoder_create( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 114 | opus_int32 Fs, /**< Sampling rate to decode at (Hz) */ |
| 115 | int channels, /**< Number of channels to decode */ |
| 116 | int streams, /**< Total number of coded streams in the multistream */ |
| 117 | int coupled_streams, /**< Number of coupled (stereo) streams in the multistream */ |
Vincent Penquerc'h | ab0b5f5 | 2011-11-23 15:17:30 +0000 | [diff] [blame] | 118 | const unsigned char *mapping, /**< Stream to channel mapping table */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 119 | int *error /**< Error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 120 | ); |
| 121 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 122 | /** Intialize a previously allocated decoder state object. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 123 | OPUS_EXPORT int opus_multistream_decoder_init( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 124 | OpusMSDecoder *st, /**< Encoder state */ |
| 125 | opus_int32 Fs, /**< Sample rate of input signal (Hz) */ |
| 126 | int channels, /**< Number of channels in the input signal */ |
| 127 | int streams, /**< Total number of coded streams */ |
| 128 | int coupled_streams, /**< Number of coupled (stereo) streams */ |
Vincent Penquerc'h | ab0b5f5 | 2011-11-23 15:17:30 +0000 | [diff] [blame] | 129 | const unsigned char *mapping /**< Stream to channel mapping table */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 130 | ); |
| 131 | |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 132 | /** Returns the number of samples decoded or a negative error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 133 | OPUS_EXPORT int opus_multistream_decode( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 134 | OpusMSDecoder *st, /**< Decoder state */ |
| 135 | const unsigned char *data, /**< Input payload. Use a NULL pointer to indicate packet loss */ |
Jean-Marc Valin | 59354a7 | 2012-03-08 12:19:07 -0500 | [diff] [blame] | 136 | opus_int32 len, /**< Number of bytes in payload */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 137 | opus_int16 *pcm, /**< Output signal, samples interleaved in channel order . length is frame_size*channels */ |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 138 | int frame_size, /**< Number of samples per frame of input signal */ |
| 139 | int decode_fec /**< Flag (0/1) to request that any in-band forward error correction data be */ |
| 140 | /**< decoded. If no such data is available the frame is decoded as if it were lost. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 141 | ); |
| 142 | |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 143 | /** Returns the number of samples decoded or a negative error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 144 | OPUS_EXPORT int opus_multistream_decode_float( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 145 | OpusMSDecoder *st, /**< Decoder state */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 146 | const unsigned char *data, /**< Input payload buffer. Use a NULL pointer to indicate packet loss */ |
Jean-Marc Valin | 59354a7 | 2012-03-08 12:19:07 -0500 | [diff] [blame] | 147 | opus_int32 len, /**< Number of payload bytes in data */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 148 | float *pcm, /**< Buffer for the output signal (interleaved iin channel order). length is frame_size*channels */ |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 149 | int frame_size, /**< Number of samples per frame of input signal */ |
| 150 | int decode_fec /**< Flag (0/1) to request that any in-band forward error correction data be */ |
| 151 | /**< decoded. If no such data is available the frame is decoded as if it were lost. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 152 | ); |
| 153 | |
Gregory Maxwell | c81b510 | 2011-10-30 02:16:25 -0400 | [diff] [blame] | 154 | /** Gets the size of an OpusMSDecoder structure. |
| 155 | * @returns size |
| 156 | */ |
| 157 | OPUS_EXPORT opus_int32 opus_multistream_decoder_get_size( |
| 158 | int streams, /**< Total number of coded streams */ |
| 159 | int coupled_streams /**< Number of coupled (stereo) streams */ |
| 160 | ); |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 161 | |
| 162 | /** Get or set options on a multistream decoder state */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 163 | OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...); |
| 164 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 165 | /** Deallocate a multistream decoder state object */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 166 | OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); |
| 167 | |
Ralph Giles | 64c2dd7 | 2012-05-23 16:33:14 -0700 | [diff] [blame] | 168 | #ifdef __cplusplus |
| 169 | } |
| 170 | #endif |
| 171 | |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 172 | #endif /* OPUS_MULTISTREAM_H */ |