blob: 5e5364a3c874ec7a7429640a1680620d5469b8d2 [file] [log] [blame]
Jean-Marc Valind4e93402011-08-27 00:52:26 -04001/* 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 Valincb05e7c2012-04-20 16:40:24 -040018 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 Valind4e93402011-08-27 00:52:26 -040020 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 Giles1b951962011-09-07 10:40:25 -070028/**
29 * @file opus_multistream.h
30 * @brief Opus reference implementation multistream API
31 */
Jean-Marc Valind4e93402011-08-27 00:52:26 -040032
33#ifndef OPUS_MULTISTREAM_H
34#define OPUS_MULTISTREAM_H
35
36#include "opus.h"
37
Ralph Giles64c2dd72012-05-23 16:33:14 -070038#ifdef __cplusplus
39extern "C" {
40#endif
41
Jean-Marc Valind4e93402011-08-27 00:52:26 -040042typedef struct OpusMSEncoder OpusMSEncoder;
43typedef struct OpusMSDecoder OpusMSDecoder;
44
Jean-Marc Valinaf50ce92011-09-11 20:13:47 -040045#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 Giles1c1cf7d2011-09-13 23:56:42 -070054/** Allocate and initialize a multistream encoder state object.
55 * Call opus_multistream_encoder_destroy() to release
56 * this object when finished. */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -040057OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create(
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070058 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'hab0b5f52011-11-23 15:17:30 +000062 const unsigned char *mapping, /**< Encoded mapping between channels and streams */
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070063 int application, /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */
64 int *error /**< Error code */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -040065) OPUS_ARG_NONNULL(5);
Jean-Marc Valind4e93402011-08-27 00:52:26 -040066
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070067/** Initialize an already allocated multistream encoder state. */
Jean-Marc Valind4e93402011-08-27 00:52:26 -040068OPUS_EXPORT int opus_multistream_encoder_init(
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070069 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'hab0b5f52011-11-23 15:17:30 +000074 const unsigned char *mapping, /**< Encoded mapping between channels and streams */
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070075 int application /**< Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO) */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -040076) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
Jean-Marc Valind4e93402011-08-27 00:52:26 -040077
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070078/** Returns length of the data payload (in bytes) or a negative error code */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -040079OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode(
Ralph Giles1b951962011-09-07 10:40:25 -070080 OpusMSEncoder *st, /**< Encoder state */
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070081 const opus_int16 *pcm, /**< Input signal as interleaved samples. Length is frame_size*channels */
Ralph Giles1b951962011-09-07 10:40:25 -070082 int frame_size, /**< Number of samples per frame of input signal */
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070083 unsigned char *data, /**< Output buffer for the compressed payload (no more than max_data_bytes long) */
Jean-Marc Valin59354a72012-03-08 12:19:07 -050084 opus_int32 max_data_bytes /**< Allocated memory for payload; don't use for controlling bitrate */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -040085) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
Jean-Marc Valind4e93402011-08-27 00:52:26 -040086
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070087/** Returns length of the data payload (in bytes) or a negative error code. */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -040088OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float(
Ralph Giles1c1cf7d2011-09-13 23:56:42 -070089 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 Valin59354a72012-03-08 12:19:07 -050093 opus_int32 max_data_bytes /**< Allocated memory for payload; don't use for controlling bitrate */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -040094) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4);
Jean-Marc Valind4e93402011-08-27 00:52:26 -040095
Gregory Maxwellc81b5102011-10-30 02:16:25 -040096/** Gets the size of an OpusMSEncoder structure.
97 * @returns size
98 */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -040099OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size(
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400100 int streams, /**< Total number of coded streams */
101 int coupled_streams /**< Number of coupled (stereo) streams */
102);
103
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700104/** Deallocate a multstream encoder state */
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400105OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st);
106
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700107/** Get or set options on a multistream encoder state */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400108OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400109
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700110/** Allocate and initialize a multistream decoder state object.
111 * Call opus_multistream_decoder_destroy() to release
112 * this object when finished. */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400113OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create(
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700114 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'hab0b5f52011-11-23 15:17:30 +0000118 const unsigned char *mapping, /**< Stream to channel mapping table */
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700119 int *error /**< Error code */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400120) OPUS_ARG_NONNULL(5);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400121
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700122/** Intialize a previously allocated decoder state object. */
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400123OPUS_EXPORT int opus_multistream_decoder_init(
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700124 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'hab0b5f52011-11-23 15:17:30 +0000129 const unsigned char *mapping /**< Stream to channel mapping table */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400130) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400131
Ralph Giles1b951962011-09-07 10:40:25 -0700132/** Returns the number of samples decoded or a negative error code */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400133OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode(
Ralph Giles1b951962011-09-07 10:40:25 -0700134 OpusMSDecoder *st, /**< Decoder state */
135 const unsigned char *data, /**< Input payload. Use a NULL pointer to indicate packet loss */
Jean-Marc Valin59354a72012-03-08 12:19:07 -0500136 opus_int32 len, /**< Number of bytes in payload */
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700137 opus_int16 *pcm, /**< Output signal, samples interleaved in channel order . length is frame_size*channels */
Ralph Giles1b951962011-09-07 10:40:25 -0700138 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. */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400141) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400142
Ralph Giles1b951962011-09-07 10:40:25 -0700143/** Returns the number of samples decoded or a negative error code */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400144OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float(
Ralph Giles1b951962011-09-07 10:40:25 -0700145 OpusMSDecoder *st, /**< Decoder state */
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700146 const unsigned char *data, /**< Input payload buffer. Use a NULL pointer to indicate packet loss */
Jean-Marc Valin59354a72012-03-08 12:19:07 -0500147 opus_int32 len, /**< Number of payload bytes in data */
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700148 float *pcm, /**< Buffer for the output signal (interleaved iin channel order). length is frame_size*channels */
Ralph Giles1b951962011-09-07 10:40:25 -0700149 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. */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400152) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400153
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400154/** Gets the size of an OpusMSDecoder structure.
155 * @returns size
156 */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400157OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size(
Gregory Maxwellc81b5102011-10-30 02:16:25 -0400158 int streams, /**< Total number of coded streams */
159 int coupled_streams /**< Number of coupled (stereo) streams */
160);
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700161
162/** Get or set options on a multistream decoder state */
Gregory Maxwellc64f4a42012-06-01 02:21:53 -0400163OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1);
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400164
Ralph Giles1c1cf7d2011-09-13 23:56:42 -0700165/** Deallocate a multistream decoder state object */
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400166OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st);
167
Ralph Giles64c2dd72012-05-23 16:33:14 -0700168#ifdef __cplusplus
169}
170#endif
171
Jean-Marc Valind4e93402011-08-27 00:52:26 -0400172#endif /* OPUS_MULTISTREAM_H */