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 | |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 50 | OPUS_EXPORT OpusMSEncoder *opus_multistream_encoder_create( |
Jean-Marc Valin | d9438da | 2011-09-07 14:47:48 -0400 | [diff] [blame] | 51 | opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 52 | int channels, /**< Number of channels (1/2) in input signal */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 53 | int streams, |
| 54 | int coupled_streams, |
| 55 | unsigned char *mapping, |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 56 | int application, /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ |
| 57 | int *error /**< Error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 58 | ); |
| 59 | |
| 60 | OPUS_EXPORT int opus_multistream_encoder_init( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 61 | OpusMSEncoder *st, /**< Encoder state */ |
Jean-Marc Valin | d9438da | 2011-09-07 14:47:48 -0400 | [diff] [blame] | 62 | opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 63 | int channels, /**< Number of channels (1/2) in input signal */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 64 | int streams, |
| 65 | int coupled_streams, |
| 66 | unsigned char *mapping, |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 67 | int application /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 68 | ); |
| 69 | |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 70 | /** Returns length of the data payload (in bytes) */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 71 | OPUS_EXPORT int opus_multistream_encode( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 72 | OpusMSEncoder *st, /**< Encoder state */ |
| 73 | const opus_int16 *pcm, /**< Input signal (interleaved if 2 channels). length is frame_size*channels */ |
| 74 | int frame_size, /**< Number of samples per frame of input signal */ |
| 75 | unsigned char *data, /**< Output payload (no more than max_data_bytes long) */ |
| 76 | 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] | 77 | ); |
| 78 | |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 79 | /** Returns length of the data payload (in bytes) */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 80 | OPUS_EXPORT int opus_multistream_encode_float( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 81 | OpusMSEncoder *st, /**< Encoder state */ |
| 82 | const float *pcm, /**< Input signal (interleaved if 2 channels). length is frame_size*channels */ |
| 83 | int frame_size, /**< Number of samples per frame of input signal */ |
| 84 | unsigned char *data, /**< Output payload (no more than max_data_bytes long) */ |
| 85 | 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] | 86 | ); |
| 87 | |
| 88 | OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); |
| 89 | |
| 90 | OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...); |
| 91 | |
| 92 | OPUS_EXPORT OpusMSDecoder *opus_multistream_decoder_create( |
Jean-Marc Valin | d9438da | 2011-09-07 14:47:48 -0400 | [diff] [blame] | 93 | opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 94 | int channels, /**< Number of channels (1/2) in input signal */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 95 | int streams, |
| 96 | int coupled_streams, |
Jean-Marc Valin | 9d48deb | 2011-08-29 09:56:14 -0400 | [diff] [blame] | 97 | unsigned char *mapping, |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 98 | int *error /**< Error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 99 | ); |
| 100 | |
| 101 | OPUS_EXPORT int opus_multistream_decoder_init( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 102 | OpusMSDecoder *st, /**< Encoder state */ |
Jean-Marc Valin | d9438da | 2011-09-07 14:47:48 -0400 | [diff] [blame] | 103 | opus_int32 Fs, /**< Sampling rate of input signal (Hz) */ |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 104 | int channels, /**< Number of channels (1/2) in input signal */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 105 | int streams, |
| 106 | int coupled_streams, |
| 107 | unsigned char *mapping |
| 108 | ); |
| 109 | |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 110 | /** Returns the number of samples decoded or a negative error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 111 | OPUS_EXPORT int opus_multistream_decode( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 112 | OpusMSDecoder *st, /**< Decoder state */ |
| 113 | const unsigned char *data, /**< Input payload. Use a NULL pointer to indicate packet loss */ |
| 114 | int len, /**< Number of bytes in payload */ |
| 115 | opus_int16 *pcm, /**< Output signal (interleaved if 2 channels). length is frame_size*channels */ |
| 116 | int frame_size, /**< Number of samples per frame of input signal */ |
| 117 | int decode_fec /**< Flag (0/1) to request that any in-band forward error correction data be */ |
| 118 | /**< 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] | 119 | ); |
| 120 | |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 121 | /** Returns the number of samples decoded or a negative error code */ |
Jean-Marc Valin | d4e9340 | 2011-08-27 00:52:26 -0400 | [diff] [blame] | 122 | OPUS_EXPORT int opus_multistream_decode_float( |
Ralph Giles | 1b95196 | 2011-09-07 10:40:25 -0700 | [diff] [blame] | 123 | OpusMSDecoder *st, /**< Decoder state */ |
| 124 | const unsigned char *data, /**< Input payload. Use a NULL pointer to indicate packet loss */ |
| 125 | int len, /**< Number of bytes in payload */ |
| 126 | float *pcm, /**< Output signal (interleaved if 2 channels). length is frame_size*channels */ |
| 127 | int frame_size, /**< Number of samples per frame of input signal */ |
| 128 | int decode_fec /**< Flag (0/1) to request that any in-band forward error correction data be */ |
| 129 | /**< 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] | 130 | ); |
| 131 | |
| 132 | OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...); |
| 133 | |
| 134 | OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); |
| 135 | |
| 136 | #endif /* OPUS_MULTISTREAM_H */ |