opus_private.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. - Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  16. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  21. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef OPUS_PRIVATE_H
  25. #define OPUS_PRIVATE_H
  26. #include "arch.h"
  27. #include "opus.h"
  28. #include "celt.h"
  29. #include <stddef.h> /* offsetof */
  30. struct OpusRepacketizer {
  31. unsigned char toc;
  32. int nb_frames;
  33. const unsigned char *frames[48];
  34. opus_int16 len[48];
  35. int framesize;
  36. };
  37. typedef struct ChannelLayout {
  38. int nb_channels;
  39. int nb_streams;
  40. int nb_coupled_streams;
  41. unsigned char mapping[256];
  42. } ChannelLayout;
  43. int validate_layout(const ChannelLayout *layout);
  44. int get_left_channel(const ChannelLayout *layout, int stream_id, int prev);
  45. int get_right_channel(const ChannelLayout *layout, int stream_id, int prev);
  46. int get_mono_channel(const ChannelLayout *layout, int stream_id, int prev);
  47. #define MODE_SILK_ONLY 1000
  48. #define MODE_HYBRID 1001
  49. #define MODE_CELT_ONLY 1002
  50. #define OPUS_SET_VOICE_RATIO_REQUEST 11018
  51. #define OPUS_GET_VOICE_RATIO_REQUEST 11019
  52. /** Configures the encoder's expected percentage of voice
  53. * opposed to music or other signals.
  54. *
  55. * @note This interface is currently more aspiration than actuality. It's
  56. * ultimately expected to bias an automatic signal classifier, but it currently
  57. * just shifts the static bitrate to mode mapping around a little bit.
  58. *
  59. * @param[in] x <tt>int</tt>: Voice percentage in the range 0-100, inclusive.
  60. * @hideinitializer */
  61. #define OPUS_SET_VOICE_RATIO(x) OPUS_SET_VOICE_RATIO_REQUEST, __opus_check_int(x)
  62. /** Gets the encoder's configured voice ratio value, @see OPUS_SET_VOICE_RATIO
  63. *
  64. * @param[out] x <tt>int*</tt>: Voice percentage in the range 0-100, inclusive.
  65. * @hideinitializer */
  66. #define OPUS_GET_VOICE_RATIO(x) OPUS_GET_VOICE_RATIO_REQUEST, __opus_check_int_ptr(x)
  67. #define OPUS_SET_FORCE_MODE_REQUEST 11002
  68. #define OPUS_SET_FORCE_MODE(x) OPUS_SET_FORCE_MODE_REQUEST, __opus_check_int(x)
  69. typedef void (*downmix_func)(const void *, opus_val32 *, int, int, int, int, int);
  70. void downmix_float(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
  71. void downmix_int(const void *_x, opus_val32 *sub, int subframe, int offset, int c1, int c2, int C);
  72. int encode_size(int size, unsigned char *data);
  73. opus_int32 frame_size_select(opus_int32 frame_size, int variable_duration, opus_int32 Fs);
  74. opus_int32 compute_frame_size(const void *analysis_pcm, int frame_size,
  75. int variable_duration, int C, opus_int32 Fs, int bitrate_bps,
  76. int delay_compensation, downmix_func downmix
  77. #ifndef DISABLE_FLOAT_API
  78. , float *subframe_mem
  79. #endif
  80. );
  81. opus_int32 opus_encode_native(OpusEncoder *st, const opus_val16 *pcm, int frame_size,
  82. unsigned char *data, opus_int32 out_data_bytes, int lsb_depth,
  83. const void *analysis_pcm, opus_int32 analysis_size, int c1, int c2,
  84. int analysis_channels, downmix_func downmix, int float_api);
  85. int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 len,
  86. opus_val16 *pcm, int frame_size, int decode_fec, int self_delimited,
  87. opus_int32 *packet_offset, int soft_clip);
  88. /* Make sure everything is properly aligned. */
  89. static OPUS_INLINE int align(int i)
  90. {
  91. struct foo {char c; union { void* p; opus_int32 i; opus_val32 v; } u;};
  92. unsigned int alignment = offsetof(struct foo, u);
  93. /* Optimizing compilers should optimize div and multiply into and
  94. for all sensible alignment values. */
  95. return ((i + alignment - 1) / alignment) * alignment;
  96. }
  97. int opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
  98. int self_delimited, unsigned char *out_toc,
  99. const unsigned char *frames[48], opus_int16 size[48],
  100. int *payload_offset, opus_int32 *packet_offset);
  101. opus_int32 opus_repacketizer_out_range_impl(OpusRepacketizer *rp, int begin, int end,
  102. unsigned char *data, opus_int32 maxlen, int self_delimited, int pad);
  103. int pad_frame(unsigned char *data, opus_int32 len, opus_int32 new_len);
  104. #endif /* OPUS_PRIVATE_H */