swresample.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 6
  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. #define SWR_CH_MAX 16 ///< Maximum number of channels
  35. #define SWR_FLAG_RESAMPLE 1 ///< Force resampling even if equal sample rate
  36. //TODO use int resample ?
  37. //long term TODO can we enable this dynamically?
  38. struct SwrContext;
  39. /**
  40. * Allocate SwrContext.
  41. *
  42. * If you use this function you will need to set the parameters (manually or
  43. * with swr_alloc_set_opts()) before calling swr_init().
  44. *
  45. * @see swr_alloc_set_opts(), swr_init(), swr_free()
  46. * @return NULL on error, allocated context otherwise
  47. */
  48. struct SwrContext *swr_alloc(void);
  49. /**
  50. * Initialize context after user parameters have been set.
  51. *
  52. * @return AVERROR error code in case of failure.
  53. */
  54. int swr_init(struct SwrContext *s);
  55. /**
  56. * Allocate SwrContext if needed and set/reset common parameters.
  57. *
  58. * This function does not require s to be allocated with swr_alloc(). On the
  59. * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters
  60. * on the allocated context.
  61. *
  62. * @param s Swr context, can be NULL
  63. * @param out_ch_layout output channel layout (AV_CH_LAYOUT_*)
  64. * @param out_sample_fmt output sample format (AV_SAMPLE_FMT_*).
  65. * @param out_sample_rate output sample rate (frequency in Hz)
  66. * @param in_ch_layout input channel layout (AV_CH_LAYOUT_*)
  67. * @param in_sample_fmt input sample format (AV_SAMPLE_FMT_*).
  68. * @param in_sample_rate input sample rate (frequency in Hz)
  69. * @param log_offset logging level offset
  70. * @param log_ctx parent logging context, can be NULL
  71. *
  72. * @see swr_init(), swr_free()
  73. * @return NULL on error, allocated context otherwise
  74. */
  75. struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
  76. int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
  77. int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
  78. int log_offset, void *log_ctx);
  79. /**
  80. * Free the given SwrContext and set the pointer to NULL.
  81. */
  82. void swr_free(struct SwrContext **s);
  83. /**
  84. * Convert audio.
  85. *
  86. * in and in_count can be set to 0 to flush the last few samples out at the
  87. * end.
  88. *
  89. * @param s allocated Swr context, with parameters set
  90. * @param out output buffers, only the first one need be set in case of packed audio
  91. * @param out_count amount of space available for output in samples per channel
  92. * @param in input buffers, only the first one need to be set in case of packed audio
  93. * @param in_count number of input samples available in one channel
  94. *
  95. * @return number of samples output per channel
  96. */
  97. int swr_convert(struct SwrContext *s, uint8_t *out[SWR_CH_MAX], int out_count,
  98. const uint8_t *in [SWR_CH_MAX], int in_count);
  99. /**
  100. * Activate resampling compensation.
  101. */
  102. int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance);
  103. /**
  104. * Set a customized input channel mapping.
  105. *
  106. * @param s allocated Swr context, not yet initialized
  107. * @param channel_map customized input channel mapping (array of channel
  108. * indexes, -1 for a muted channel)
  109. * @return AVERROR error code in case of failure.
  110. */
  111. int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map);
  112. /**
  113. * Return the LIBSWRESAMPLE_VERSION_INT constant.
  114. */
  115. unsigned swresample_version(void);
  116. /**
  117. * Return the swr build-time configuration.
  118. */
  119. const char *swresample_configuration(void);
  120. /**
  121. * Return the swr license.
  122. */
  123. const char *swresample_license(void);
  124. #endif