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 |
| 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| 19 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 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 | |
| 38 | typedef struct OpusMSEncoder OpusMSEncoder; |
| 39 | typedef struct OpusMSDecoder OpusMSDecoder; |
| 40 | |
Jean-Marc Valin | af50ce9 | 2011-09-11 20:13:47 -0400 | [diff] [blame] | 41 | #define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) |
| 42 | #define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) |
| 43 | |
| 44 | #define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 |
| 45 | #define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 |
| 46 | |
| 47 | #define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) |
| 48 | #define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) |
| 49 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 50 | /** Allocate and initialize a multistream encoder state object. |
| 51 | * Call opus_multistream_encoder_destroy() to release |
| 52 | * this object when finished. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 53 | OPUS_EXPORT OpusMSEncoder *opus_multistream_encoder_create( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 54 | opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ |
| 55 | int channels, /**< Number of channels in the input signal */ |
| 56 | int streams, /**< Total number of streams to encode from the input */ |
| 57 | int coupled_streams, /**< Number of coupled (stereo) streams to encode */ |
| 58 | unsigned char *mapping, /**< Encoded mapping between channels and streams */ |
| 59 | int application, /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ |
| 60 | int *error /**< Error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 61 | ); |
| 62 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 63 | /** Initialize an already allocated multistream encoder state. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 64 | OPUS_EXPORT int opus_multistream_encoder_init( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 65 | OpusMSEncoder *st, /**< Encoder state */ |
| 66 | opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ |
| 67 | int channels, /**< Number of channels in the input signal */ |
| 68 | int streams, /**< Total number of streams to encode from the input */ |
| 69 | int coupled_streams, /**< Number of coupled (stereo) streams to encode */ |
| 70 | unsigned char *mapping, /**< Encoded mapping between channels and streams */ |
| 71 | int application /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 72 | ); |
| 73 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 74 | /** 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] | 75 | OPUS_EXPORT int opus_multistream_encode( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 76 | OpusMSEncoder *st, /**< Encoder state */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 77 | 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] | 78 | int frame_size, /**< Number of samples per frame of input signal */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 79 | unsigned char *data, /**< Output buffer for the compressed payload (no more than max_data_bytes long) */ |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 80 | int 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] | 81 | ); |
| 82 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 83 | /** 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] | 84 | OPUS_EXPORT int opus_multistream_encode_float( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 85 | OpusMSEncoder *st, /**< Encoder state */ |
| 86 | const float *pcm, /**< Input signal interleaved in channel order. length is frame_size*channels */ |
| 87 | int frame_size, /**< Number of samples per frame of input signal */ |
| 88 | unsigned char *data, /**< Output buffer for the compressed payload (no more than max_data_bytes long) */ |
| 89 | int 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] | 90 | ); |
| 91 | |
Gregory Maxwell | c81b510 | 2011-10-30 02:16:25 -0400 | [diff] [blame^] | 92 | /** Gets the size of an OpusMSEncoder structure. |
| 93 | * @returns size |
| 94 | */ |
| 95 | OPUS_EXPORT opus_int32 opus_multistream_encoder_get_size( |
| 96 | int streams, /**< Total number of coded streams */ |
| 97 | int coupled_streams /**< Number of coupled (stereo) streams */ |
| 98 | ); |
| 99 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 100 | /** Deallocate a multstream encoder state */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 101 | OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); |
| 102 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 103 | /** Get or set options on a multistream encoder state */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 104 | OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...); |
| 105 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 106 | /** Allocate and initialize a multistream decoder state object. |
| 107 | * Call opus_multistream_decoder_destroy() to release |
| 108 | * this object when finished. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 109 | OPUS_EXPORT OpusMSDecoder *opus_multistream_decoder_create( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 110 | opus_int32 Fs, /**< Sampling rate to decode at (Hz) */ |
| 111 | int channels, /**< Number of channels to decode */ |
| 112 | int streams, /**< Total number of coded streams in the multistream */ |
| 113 | int coupled_streams, /**< Number of coupled (stereo) streams in the multistream */ |
| 114 | unsigned char *mapping, /**< Stream to channel mapping table */ |
| 115 | int *error /**< Error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 116 | ); |
| 117 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 118 | /** Intialize a previously allocated decoder state object. */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 119 | OPUS_EXPORT int opus_multistream_decoder_init( |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 120 | OpusMSDecoder *st, /**< Encoder state */ |
| 121 | opus_int32 Fs, /**< Sample rate of input signal (Hz) */ |
| 122 | int channels, /**< Number of channels in the input signal */ |
| 123 | int streams, /**< Total number of coded streams */ |
| 124 | int coupled_streams, /**< Number of coupled (stereo) streams */ |
| 125 | unsigned char *mapping /**< Stream to channel mapping table */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 126 | ); |
| 127 | |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 128 | /** Returns the number of samples decoded or a negative error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 129 | OPUS_EXPORT int opus_multistream_decode( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 130 | OpusMSDecoder *st, /**< Decoder state */ |
| 131 | const unsigned char *data, /**< Input payload. Use a NULL pointer to indicate packet loss */ |
| 132 | int len, /**< Number of bytes in payload */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 133 | 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] | 134 | int frame_size, /**< Number of samples per frame of input signal */ |
| 135 | int decode_fec /**< Flag (0/1) to request that any in-band forward error correction data be */ |
| 136 | /**< 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] | 137 | ); |
| 138 | |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 139 | /** Returns the number of samples decoded or a negative error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 140 | OPUS_EXPORT int opus_multistream_decode_float( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 141 | OpusMSDecoder *st, /**< Decoder state */ |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 142 | const unsigned char *data, /**< Input payload buffer. Use a NULL pointer to indicate packet loss */ |
| 143 | int len, /**< Number of payload bytes in data */ |
| 144 | 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] | 145 | int frame_size, /**< Number of samples per frame of input signal */ |
| 146 | int decode_fec /**< Flag (0/1) to request that any in-band forward error correction data be */ |
| 147 | /**< 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] | 148 | ); |
| 149 | |
Gregory Maxwell | c81b510 | 2011-10-30 02:16:25 -0400 | [diff] [blame^] | 150 | /** Gets the size of an OpusMSDecoder structure. |
| 151 | * @returns size |
| 152 | */ |
| 153 | OPUS_EXPORT opus_int32 opus_multistream_decoder_get_size( |
| 154 | int streams, /**< Total number of coded streams */ |
| 155 | int coupled_streams /**< Number of coupled (stereo) streams */ |
| 156 | ); |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 157 | |
| 158 | /** Get or set options on a multistream decoder state */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 159 | OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...); |
| 160 | |
Ralph Giles | 1c1cf7d | 2011-09-13 23:56:42 -0700 | [diff] [blame] | 161 | /** Deallocate a multistream decoder state object */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 162 | OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); |
| 163 | |
| 164 | #endif /* OPUS_MULTISTREAM_H */ |