tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

opus_private.h (9225B)


      1 /* Copyright (c) 2012 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 COPYRIGHT OWNER
     19   OR 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 
     28 
     29 #ifndef OPUS_PRIVATE_H
     30 #define OPUS_PRIVATE_H
     31 
     32 #include "arch.h"
     33 #include "opus.h"
     34 #include "celt.h"
     35 
     36 #include <stdarg.h> /* va_list */
     37 #include <stddef.h> /* offsetof */
     38 
     39 struct OpusRepacketizer {
     40   unsigned char toc;
     41   int nb_frames;
     42   const unsigned char *frames[48];
     43   opus_int16 len[48];
     44   int framesize;
     45   const unsigned char *paddings[48];
     46   opus_int32 padding_len[48];
     47   unsigned char padding_nb_frames[48];
     48 };
     49 
     50 typedef struct OpusExtensionIterator {
     51   const unsigned char *data;
     52   const unsigned char *curr_data;
     53   const unsigned char *repeat_data;
     54   const unsigned char *last_long;
     55   const unsigned char *src_data;
     56   opus_int32 len;
     57   opus_int32 curr_len;
     58   opus_int32 repeat_len;
     59   opus_int32 src_len;
     60   opus_int32 trailing_short_len;
     61   int nb_frames;
     62   int frame_max;
     63   int curr_frame;
     64   int repeat_frame;
     65   unsigned char repeat_l;
     66 } OpusExtensionIterator;
     67 
     68 typedef struct {
     69   int id;
     70   int frame;
     71   const unsigned char *data;
     72   opus_int32 len;
     73 } opus_extension_data;
     74 
     75 void opus_extension_iterator_init(OpusExtensionIterator *iter,
     76 const unsigned char *data, opus_int32 len, opus_int32 nb_frames);
     77 
     78 void opus_extension_iterator_reset(OpusExtensionIterator *iter);
     79 void opus_extension_iterator_set_frame_max(OpusExtensionIterator *iter,
     80 int frame_max);
     81 int opus_extension_iterator_next(OpusExtensionIterator *iter,
     82 opus_extension_data *ext);
     83 int opus_extension_iterator_find(OpusExtensionIterator *iter,
     84 opus_extension_data *ext, int id);
     85 
     86 typedef struct ChannelLayout {
     87   int nb_channels;
     88   int nb_streams;
     89   int nb_coupled_streams;
     90   unsigned char mapping[256];
     91 } ChannelLayout;
     92 
     93 typedef enum {
     94  MAPPING_TYPE_NONE,
     95  MAPPING_TYPE_SURROUND,
     96  MAPPING_TYPE_AMBISONICS
     97 } MappingType;
     98 
     99 struct OpusMSEncoder {
    100   ChannelLayout layout;
    101   int arch;
    102   int lfe_stream;
    103   int application;
    104   opus_int32 Fs;
    105   int variable_duration;
    106   MappingType mapping_type;
    107   opus_int32 bitrate_bps;
    108   /* Encoder states go here */
    109   /* then opus_val32 window_mem[channels*120]; */
    110   /* then opus_val32 preemph_mem[channels]; */
    111 };
    112 
    113 struct OpusMSDecoder {
    114   ChannelLayout layout;
    115   /* Decoder states go here */
    116 };
    117 
    118 int opus_multistream_encoder_ctl_va_list(struct OpusMSEncoder *st, int request,
    119  va_list ap);
    120 int opus_multistream_decoder_ctl_va_list(struct OpusMSDecoder *st, int request,
    121  va_list ap);
    122 
    123 int validate_layout(const ChannelLayout *layout);
    124 int get_left_channel(const ChannelLayout *layout, int stream_id, int prev);
    125 int get_right_channel(const ChannelLayout *layout, int stream_id, int prev);
    126 int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev);
    127 
    128 typedef void (*opus_copy_channel_in_func)(
    129  opus_res *dst,
    130  int dst_stride,
    131  const void *src,
    132  int src_stride,
    133  int src_channel,
    134  int frame_size,
    135  void *user_data
    136 );
    137 
    138 typedef void (*opus_copy_channel_out_func)(
    139  void *dst,
    140  int dst_stride,
    141  int dst_channel,
    142  const opus_res *src,
    143  int src_stride,
    144  int frame_size,
    145  void *user_data
    146 );
    147 
    148 #define MODE_SILK_ONLY          1000
    149 #define MODE_HYBRID             1001
    150 #define MODE_CELT_ONLY          1002
    151 
    152 #define OPUS_SET_VOICE_RATIO_REQUEST         11018
    153 #define OPUS_GET_VOICE_RATIO_REQUEST         11019
    154 
    155 /** Configures the encoder's expected percentage of voice
    156  * opposed to music or other signals.
    157  *
    158  * @note This interface is currently more aspiration than actuality. It's
    159  * ultimately expected to bias an automatic signal classifier, but it currently
    160  * just shifts the static bitrate to mode mapping around a little bit.
    161  *
    162  * @param[in] x <tt>int</tt>:   Voice percentage in the range 0-100, inclusive.
    163  * @hideinitializer */
    164 #define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, opus_check_int(x)
    165 /** Gets the encoder's configured voice ratio value, @see OPUS_SET_VOICE_RATIO
    166  *
    167  * @param[out] x <tt>int*</tt>:  Voice percentage in the range 0-100, inclusive.
    168  * @hideinitializer */
    169 #define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, opus_check_int_ptr(x)
    170 
    171 
    172 #define OPUS_SET_FORCE_MODE_REQUEST    11002
    173 #define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, opus_check_int(x)
    174 
    175 typedef void (*downmix_func)(const void *, opus_val32 *, int, int, int, int, int);
    176 void downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
    177 void downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
    178 void downmix_int24(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
    179 int is_digital_silence(const opus_res* pcm, int frame_size, int channels, int lsb_depth);
    180 
    181 void opus_pcm_soft_clip_impl(float *_x, int N, int C, float *declip_mem, int arch);
    182 
    183 int encode_size(int size, unsigned char *data);
    184 
    185 opus_int32 frame_size_select(int application, opus_int32 frame_size, int variable_duration, opus_int32 Fs);
    186 
    187 opus_int32 opus_encode_native(OpusEncoder *st, const opus_res *pcm, int frame_size,
    188      unsigned char *data, opus_int32 out_data_bytes, int lsb_depth,
    189      const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2,
    190      int analysis_channels, downmix_func downmix, int float_api);
    191 
    192 int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len,
    193      opus_res *pcm, int frame_size, int decode_fec, int self_delimited,
    194      opus_int32 *packet_offset, int soft_clip, const OpusDRED *dred, opus_int32 dred_offset);
    195 
    196 /* Make sure everything is properly aligned. */
    197 static OPUS_INLINE int align(int i)
    198 {
    199    struct foo {char c; union { void* p; opus_int32 i; opus_val32 v; } u;};
    200 
    201    unsigned int alignment = offsetof(struct foo, u);
    202 
    203    /* Optimizing compilers should optimize div and multiply into and
    204       for all sensible alignment values. */
    205    return ((i + alignment - 1) / alignment) * alignment;
    206 }
    207 
    208 int opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
    209      int self_delimited, unsigned char *out_toc,
    210      const unsigned char *frames[48], opus_int16 size[48],
    211      int *payload_offset, opus_int32 *packet_offset,
    212      const unsigned char **padding, opus_int32 *padding_len);
    213 
    214 opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end,
    215      unsigned char *data, opus_int32 maxlen, int self_delimited, int pad,
    216      const opus_extension_data *extensions, int nb_extensions);
    217 
    218 int pad_frame(unsigned char *data, opus_int32 len, opus_int32 new_len);
    219 
    220 int opus_multistream_encode_native
    221 (
    222  struct OpusMSEncoder *st,
    223  opus_copy_channel_in_func copy_channel_in,
    224  const void *pcm,
    225  int analysis_frame_size,
    226  unsigned char *data,
    227  opus_int32 max_data_bytes,
    228  int lsb_depth,
    229  downmix_func downmix,
    230  int float_api,
    231  void *user_data
    232 );
    233 
    234 int opus_multistream_decode_native(
    235  struct OpusMSDecoder *st,
    236  const unsigned char *data,
    237  opus_int32 len,
    238  void *pcm,
    239  opus_copy_channel_out_func copy_channel_out,
    240  int frame_size,
    241  int decode_fec,
    242  int soft_clip,
    243  void *user_data
    244 );
    245 
    246 opus_int32 opus_packet_extensions_parse(const unsigned char *data,
    247 opus_int32 len, opus_extension_data *extensions, opus_int32 *nb_extensions,
    248 int nb_frames);
    249 
    250 opus_int32 opus_packet_extensions_parse_ext(const unsigned char *data,
    251 opus_int32 len, opus_extension_data *extensions, opus_int32 *nb_extensions,
    252 const opus_int32 *nb_frame_exts, int nb_frames);
    253 
    254 opus_int32 opus_packet_extensions_generate(unsigned char *data, opus_int32 len,
    255 const opus_extension_data *extensions, opus_int32 nb_extensions,
    256 int nb_frames, int pad);
    257 
    258 opus_int32 opus_packet_extensions_count(const unsigned char *data,
    259 opus_int32 len, int nb_frames);
    260 
    261 opus_int32 opus_packet_extensions_count_ext(const unsigned char *data,
    262 opus_int32 len, opus_int32 *nb_frame_exts, int nb_frames);
    263 
    264 opus_int32 opus_packet_pad_impl(unsigned char *data, opus_int32 len, opus_int32 new_len, int pad, const opus_extension_data  *extensions, int nb_extensions);
    265 
    266 #endif /* OPUS_PRIVATE_H */