You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
5.6KB

  1. /*
  2. * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at)
  3. *
  4. * This file is part of libswresample
  5. *
  6. * libswresample is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * libswresample is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with libswresample; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * libswresample public header
  23. */
  24. #ifndef SWR_H
  25. #define SWR_H
  26. #include <inttypes.h>
  27. #include "libavutil/samplefmt.h"
  28. #define LIBSWRESAMPLE_VERSION_MAJOR 0
  29. #define LIBSWRESAMPLE_VERSION_MINOR 11
  30. #define LIBSWRESAMPLE_VERSION_MICRO 100
  31. #define LIBSWRESAMPLE_VERSION_INT AV_VERSION_INT(LIBSWRESAMPLE_VERSION_MAJOR, \
  32. LIBSWRESAMPLE_VERSION_MINOR, \
  33. LIBSWRESAMPLE_VERSION_MICRO)
  34. #if LIBSWRESAMPLE_VERSION_MAJOR < 1
  35. #define SWR_CH_MAX 32 ///< Maximum number of channels
  36. #endif
  37. #define SWR_FLAG_RESAMPLE 1 ///< Force resampling even if equal sample rate
  38. //TODO use int resample ?
  39. //long term TODO can we enable this dynamically?
  40. enum SwrDitherType {
  41. SWR_DITHER_NONE = 0,
  42. SWR_DITHER_RECTANGULAR,
  43. SWR_DITHER_NB, ///< not part of API/ABI
  44. };
  45. typedef struct SwrContext SwrContext;
  46. /**
  47. * Allocate SwrContext.
  48. *
  49. * If you use this function you will need to set the parameters (manually or
  50. * with swr_alloc_set_opts()) before calling swr_init().
  51. *
  52. * @see swr_alloc_set_opts(), swr_init(), swr_free()
  53. * @return NULL on error, allocated context otherwise
  54. */
  55. struct SwrContext *swr_alloc(void);
  56. /**
  57. * Initialize context after user parameters have been set.
  58. *
  59. * @return AVERROR error code in case of failure.
  60. */
  61. int swr_init(struct SwrContext *s);
  62. /**
  63. * Allocate SwrContext if needed and set/reset common parameters.
  64. *
  65. * This function does not require s to be allocated with swr_alloc(). On the
  66. * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters
  67. * on the allocated context.
  68. *
  69. * @param s Swr context, can be NULL
  70. * @param out_ch_layout output channel layout (AV_CH_LAYOUT_*)
  71. * @param out_sample_fmt output sample format (AV_SAMPLE_FMT_*).
  72. * @param out_sample_rate output sample rate (frequency in Hz)
  73. * @param in_ch_layout input channel layout (AV_CH_LAYOUT_*)
  74. * @param in_sample_fmt input sample format (AV_SAMPLE_FMT_*).
  75. * @param in_sample_rate input sample rate (frequency in Hz)
  76. * @param log_offset logging level offset
  77. * @param log_ctx parent logging context, can be NULL
  78. *
  79. * @see swr_init(), swr_free()
  80. * @return NULL on error, allocated context otherwise
  81. */
  82. struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
  83. int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
  84. int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
  85. int log_offset, void *log_ctx);
  86. /**
  87. * Free the given SwrContext and set the pointer to NULL.
  88. */
  89. void swr_free(struct SwrContext **s);
  90. /**
  91. * Convert audio.
  92. *
  93. * in and in_count can be set to 0 to flush the last few samples out at the
  94. * end.
  95. *
  96. * If more input is provided than output space then the input will be buffered.
  97. * You can avoid this buffering by providing more output space than input.
  98. * Convertion will run directly without copying whenever possible.
  99. *
  100. * @param s allocated Swr context, with parameters set
  101. * @param out output buffers, only the first one need be set in case of packed audio
  102. * @param out_count amount of space available for output in samples per channel
  103. * @param in input buffers, only the first one need to be set in case of packed audio
  104. * @param in_count number of input samples available in one channel
  105. *
  106. * @return number of samples output per channel, negative value on error
  107. */
  108. int swr_convert(struct SwrContext *s, uint8_t **out, int out_count,
  109. const uint8_t **in , int in_count);
  110. /**
  111. * Activate resampling compensation.
  112. */
  113. int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance);
  114. /**
  115. * Set a customized input channel mapping.
  116. *
  117. * @param s allocated Swr context, not yet initialized
  118. * @param channel_map customized input channel mapping (array of channel
  119. * indexes, -1 for a muted channel)
  120. * @return AVERROR error code in case of failure.
  121. */
  122. int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
  123. /**
  124. * Set a customized remix matrix.
  125. *
  126. * @param s allocated Swr context, not yet initialized
  127. * @param matrix remix coefficients; matrix[i + stride * o] is
  128. * the weight of input channel i in output channel o
  129. * @param stride offset between lines of the matrix
  130. * @return AVERROR error code in case of failure.
  131. */
  132. int swr_set_matrix(struct SwrContext *s, const double *matrix, int stride);
  133. /**
  134. * Return the LIBSWRESAMPLE_VERSION_INT constant.
  135. */
  136. unsigned swresample_version(void);
  137. /**
  138. * Return the swr build-time configuration.
  139. */
  140. const char *swresample_configuration(void);
  141. /**
  142. * Return the swr license.
  143. */
  144. const char *swresample_license(void);
  145. #endif