1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com> 3cabdff1aSopenharmony_ci * 4cabdff1aSopenharmony_ci * This file is part of FFmpeg. 5cabdff1aSopenharmony_ci * 6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 9cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 10cabdff1aSopenharmony_ci * 11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14cabdff1aSopenharmony_ci * Lesser General Public License for more details. 15cabdff1aSopenharmony_ci * 16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19cabdff1aSopenharmony_ci */ 20cabdff1aSopenharmony_ci 21cabdff1aSopenharmony_ci#ifndef AVRESAMPLE_AVRESAMPLE_H 22cabdff1aSopenharmony_ci#define AVRESAMPLE_AVRESAMPLE_H 23cabdff1aSopenharmony_ci 24cabdff1aSopenharmony_ci/** 25cabdff1aSopenharmony_ci * @file 26cabdff1aSopenharmony_ci * @ingroup lavr 27cabdff1aSopenharmony_ci * external API header 28cabdff1aSopenharmony_ci */ 29cabdff1aSopenharmony_ci 30cabdff1aSopenharmony_ci/** 31cabdff1aSopenharmony_ci * @defgroup lavr libavresample 32cabdff1aSopenharmony_ci * @{ 33cabdff1aSopenharmony_ci * 34cabdff1aSopenharmony_ci * Libavresample (lavr) is a library that handles audio resampling, sample 35cabdff1aSopenharmony_ci * format conversion and mixing. 36cabdff1aSopenharmony_ci * 37cabdff1aSopenharmony_ci * Interaction with lavr is done through AVAudioResampleContext, which is 38cabdff1aSopenharmony_ci * allocated with avresample_alloc_context(). It is opaque, so all parameters 39cabdff1aSopenharmony_ci * must be set with the @ref avoptions API. 40cabdff1aSopenharmony_ci * 41cabdff1aSopenharmony_ci * For example the following code will setup conversion from planar float sample 42cabdff1aSopenharmony_ci * format to interleaved signed 16-bit integer, downsampling from 48kHz to 43cabdff1aSopenharmony_ci * 44.1kHz and downmixing from 5.1 channels to stereo (using the default mixing 44cabdff1aSopenharmony_ci * matrix): 45cabdff1aSopenharmony_ci * @code 46cabdff1aSopenharmony_ci * AVAudioResampleContext *avr = avresample_alloc_context(); 47cabdff1aSopenharmony_ci * av_opt_set_int(avr, "in_channel_layout", AV_CH_LAYOUT_5POINT1, 0); 48cabdff1aSopenharmony_ci * av_opt_set_int(avr, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0); 49cabdff1aSopenharmony_ci * av_opt_set_int(avr, "in_sample_rate", 48000, 0); 50cabdff1aSopenharmony_ci * av_opt_set_int(avr, "out_sample_rate", 44100, 0); 51cabdff1aSopenharmony_ci * av_opt_set_int(avr, "in_sample_fmt", AV_SAMPLE_FMT_FLTP, 0); 52cabdff1aSopenharmony_ci * av_opt_set_int(avr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0); 53cabdff1aSopenharmony_ci * @endcode 54cabdff1aSopenharmony_ci * 55cabdff1aSopenharmony_ci * Once the context is initialized, it must be opened with avresample_open(). If 56cabdff1aSopenharmony_ci * you need to change the conversion parameters, you must close the context with 57cabdff1aSopenharmony_ci * avresample_close(), change the parameters as described above, then reopen it 58cabdff1aSopenharmony_ci * again. 59cabdff1aSopenharmony_ci * 60cabdff1aSopenharmony_ci * The conversion itself is done by repeatedly calling avresample_convert(). 61cabdff1aSopenharmony_ci * Note that the samples may get buffered in two places in lavr. The first one 62cabdff1aSopenharmony_ci * is the output FIFO, where the samples end up if the output buffer is not 63cabdff1aSopenharmony_ci * large enough. The data stored in there may be retrieved at any time with 64cabdff1aSopenharmony_ci * avresample_read(). The second place is the resampling delay buffer, 65cabdff1aSopenharmony_ci * applicable only when resampling is done. The samples in it require more input 66cabdff1aSopenharmony_ci * before they can be processed. Their current amount is returned by 67cabdff1aSopenharmony_ci * avresample_get_delay(). At the end of conversion the resampling buffer can be 68cabdff1aSopenharmony_ci * flushed by calling avresample_convert() with NULL input. 69cabdff1aSopenharmony_ci * 70cabdff1aSopenharmony_ci * The following code demonstrates the conversion loop assuming the parameters 71cabdff1aSopenharmony_ci * from above and caller-defined functions get_input() and handle_output(): 72cabdff1aSopenharmony_ci * @code 73cabdff1aSopenharmony_ci * uint8_t **input; 74cabdff1aSopenharmony_ci * int in_linesize, in_samples; 75cabdff1aSopenharmony_ci * 76cabdff1aSopenharmony_ci * while (get_input(&input, &in_linesize, &in_samples)) { 77cabdff1aSopenharmony_ci * uint8_t *output 78cabdff1aSopenharmony_ci * int out_linesize; 79cabdff1aSopenharmony_ci * int out_samples = avresample_get_out_samples(avr, in_samples); 80cabdff1aSopenharmony_ci * 81cabdff1aSopenharmony_ci * av_samples_alloc(&output, &out_linesize, 2, out_samples, 82cabdff1aSopenharmony_ci * AV_SAMPLE_FMT_S16, 0); 83cabdff1aSopenharmony_ci * out_samples = avresample_convert(avr, &output, out_linesize, out_samples, 84cabdff1aSopenharmony_ci * input, in_linesize, in_samples); 85cabdff1aSopenharmony_ci * handle_output(output, out_linesize, out_samples); 86cabdff1aSopenharmony_ci * av_freep(&output); 87cabdff1aSopenharmony_ci * } 88cabdff1aSopenharmony_ci * @endcode 89cabdff1aSopenharmony_ci * 90cabdff1aSopenharmony_ci * When the conversion is finished and the FIFOs are flushed if required, the 91cabdff1aSopenharmony_ci * conversion context and everything associated with it must be freed with 92cabdff1aSopenharmony_ci * avresample_free(). 93cabdff1aSopenharmony_ci */ 94cabdff1aSopenharmony_ci 95cabdff1aSopenharmony_ci#include "libavutil/avutil.h" 96cabdff1aSopenharmony_ci#include "libavutil/channel_layout.h" 97cabdff1aSopenharmony_ci#include "libavutil/dict.h" 98cabdff1aSopenharmony_ci#include "libavutil/frame.h" 99cabdff1aSopenharmony_ci#include "libavutil/log.h" 100cabdff1aSopenharmony_ci#include "libavutil/mathematics.h" 101cabdff1aSopenharmony_ci 102cabdff1aSopenharmony_ci#include "libavresample/version.h" 103cabdff1aSopenharmony_ci 104cabdff1aSopenharmony_ci#define AVRESAMPLE_MAX_CHANNELS 32 105cabdff1aSopenharmony_ci 106cabdff1aSopenharmony_citypedef struct AVAudioResampleContext AVAudioResampleContext; 107cabdff1aSopenharmony_ci 108cabdff1aSopenharmony_ci/** 109cabdff1aSopenharmony_ci * @deprecated use libswresample 110cabdff1aSopenharmony_ci * 111cabdff1aSopenharmony_ci * Mixing Coefficient Types */ 112cabdff1aSopenharmony_cienum attribute_deprecated AVMixCoeffType { 113cabdff1aSopenharmony_ci AV_MIX_COEFF_TYPE_Q8, /** 16-bit 8.8 fixed-point */ 114cabdff1aSopenharmony_ci AV_MIX_COEFF_TYPE_Q15, /** 32-bit 17.15 fixed-point */ 115cabdff1aSopenharmony_ci AV_MIX_COEFF_TYPE_FLT, /** floating-point */ 116cabdff1aSopenharmony_ci AV_MIX_COEFF_TYPE_NB, /** Number of coeff types. Not part of ABI */ 117cabdff1aSopenharmony_ci}; 118cabdff1aSopenharmony_ci 119cabdff1aSopenharmony_ci/** 120cabdff1aSopenharmony_ci * @deprecated use libswresample 121cabdff1aSopenharmony_ci * 122cabdff1aSopenharmony_ci * Resampling Filter Types */ 123cabdff1aSopenharmony_cienum attribute_deprecated AVResampleFilterType { 124cabdff1aSopenharmony_ci AV_RESAMPLE_FILTER_TYPE_CUBIC, /**< Cubic */ 125cabdff1aSopenharmony_ci AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL, /**< Blackman Nuttall Windowed Sinc */ 126cabdff1aSopenharmony_ci AV_RESAMPLE_FILTER_TYPE_KAISER, /**< Kaiser Windowed Sinc */ 127cabdff1aSopenharmony_ci}; 128cabdff1aSopenharmony_ci 129cabdff1aSopenharmony_ci/** 130cabdff1aSopenharmony_ci * @deprecated use libswresample 131cabdff1aSopenharmony_ci */ 132cabdff1aSopenharmony_cienum attribute_deprecated AVResampleDitherMethod { 133cabdff1aSopenharmony_ci AV_RESAMPLE_DITHER_NONE, /**< Do not use dithering */ 134cabdff1aSopenharmony_ci AV_RESAMPLE_DITHER_RECTANGULAR, /**< Rectangular Dither */ 135cabdff1aSopenharmony_ci AV_RESAMPLE_DITHER_TRIANGULAR, /**< Triangular Dither*/ 136cabdff1aSopenharmony_ci AV_RESAMPLE_DITHER_TRIANGULAR_HP, /**< Triangular Dither with High Pass */ 137cabdff1aSopenharmony_ci AV_RESAMPLE_DITHER_TRIANGULAR_NS, /**< Triangular Dither with Noise Shaping */ 138cabdff1aSopenharmony_ci AV_RESAMPLE_DITHER_NB, /**< Number of dither types. Not part of ABI. */ 139cabdff1aSopenharmony_ci}; 140cabdff1aSopenharmony_ci 141cabdff1aSopenharmony_ci/** 142cabdff1aSopenharmony_ci * 143cabdff1aSopenharmony_ci * @deprecated use libswresample 144cabdff1aSopenharmony_ci * 145cabdff1aSopenharmony_ci * Return the LIBAVRESAMPLE_VERSION_INT constant. 146cabdff1aSopenharmony_ci */ 147cabdff1aSopenharmony_ciattribute_deprecated 148cabdff1aSopenharmony_ciunsigned avresample_version(void); 149cabdff1aSopenharmony_ci 150cabdff1aSopenharmony_ci/** 151cabdff1aSopenharmony_ci * 152cabdff1aSopenharmony_ci * @deprecated use libswresample 153cabdff1aSopenharmony_ci * 154cabdff1aSopenharmony_ci * Return the libavresample build-time configuration. 155cabdff1aSopenharmony_ci * @return configure string 156cabdff1aSopenharmony_ci */ 157cabdff1aSopenharmony_ciattribute_deprecated 158cabdff1aSopenharmony_ciconst char *avresample_configuration(void); 159cabdff1aSopenharmony_ci 160cabdff1aSopenharmony_ci/** 161cabdff1aSopenharmony_ci * 162cabdff1aSopenharmony_ci * @deprecated use libswresample 163cabdff1aSopenharmony_ci * 164cabdff1aSopenharmony_ci * Return the libavresample license. 165cabdff1aSopenharmony_ci */ 166cabdff1aSopenharmony_ciattribute_deprecated 167cabdff1aSopenharmony_ciconst char *avresample_license(void); 168cabdff1aSopenharmony_ci 169cabdff1aSopenharmony_ci/** 170cabdff1aSopenharmony_ci * 171cabdff1aSopenharmony_ci * @deprecated use libswresample 172cabdff1aSopenharmony_ci * 173cabdff1aSopenharmony_ci * Get the AVClass for AVAudioResampleContext. 174cabdff1aSopenharmony_ci * 175cabdff1aSopenharmony_ci * Can be used in combination with AV_OPT_SEARCH_FAKE_OBJ for examining options 176cabdff1aSopenharmony_ci * without allocating a context. 177cabdff1aSopenharmony_ci * 178cabdff1aSopenharmony_ci * @see av_opt_find(). 179cabdff1aSopenharmony_ci * 180cabdff1aSopenharmony_ci * @return AVClass for AVAudioResampleContext 181cabdff1aSopenharmony_ci */ 182cabdff1aSopenharmony_ciattribute_deprecated 183cabdff1aSopenharmony_ciconst AVClass *avresample_get_class(void); 184cabdff1aSopenharmony_ci 185cabdff1aSopenharmony_ci/** 186cabdff1aSopenharmony_ci * 187cabdff1aSopenharmony_ci * @deprecated use libswresample 188cabdff1aSopenharmony_ci * 189cabdff1aSopenharmony_ci * Allocate AVAudioResampleContext and set options. 190cabdff1aSopenharmony_ci * 191cabdff1aSopenharmony_ci * @return allocated audio resample context, or NULL on failure 192cabdff1aSopenharmony_ci */ 193cabdff1aSopenharmony_ciattribute_deprecated 194cabdff1aSopenharmony_ciAVAudioResampleContext *avresample_alloc_context(void); 195cabdff1aSopenharmony_ci 196cabdff1aSopenharmony_ci/** 197cabdff1aSopenharmony_ci * 198cabdff1aSopenharmony_ci * @deprecated use libswresample 199cabdff1aSopenharmony_ci * 200cabdff1aSopenharmony_ci * Initialize AVAudioResampleContext. 201cabdff1aSopenharmony_ci * @note The context must be configured using the AVOption API. 202cabdff1aSopenharmony_ci * @note The fields "in_channel_layout", "out_channel_layout", 203cabdff1aSopenharmony_ci * "in_sample_rate", "out_sample_rate", "in_sample_fmt", 204cabdff1aSopenharmony_ci * "out_sample_fmt" must be set. 205cabdff1aSopenharmony_ci * 206cabdff1aSopenharmony_ci * @see av_opt_set_int() 207cabdff1aSopenharmony_ci * @see av_opt_set_dict() 208cabdff1aSopenharmony_ci * @see av_get_default_channel_layout() 209cabdff1aSopenharmony_ci * 210cabdff1aSopenharmony_ci * @param avr audio resample context 211cabdff1aSopenharmony_ci * @return 0 on success, negative AVERROR code on failure 212cabdff1aSopenharmony_ci */ 213cabdff1aSopenharmony_ciattribute_deprecated 214cabdff1aSopenharmony_ciint avresample_open(AVAudioResampleContext *avr); 215cabdff1aSopenharmony_ci 216cabdff1aSopenharmony_ci/** 217cabdff1aSopenharmony_ci * 218cabdff1aSopenharmony_ci * @deprecated use libswresample 219cabdff1aSopenharmony_ci * 220cabdff1aSopenharmony_ci * Check whether an AVAudioResampleContext is open or closed. 221cabdff1aSopenharmony_ci * 222cabdff1aSopenharmony_ci * @param avr AVAudioResampleContext to check 223cabdff1aSopenharmony_ci * @return 1 if avr is open, 0 if avr is closed. 224cabdff1aSopenharmony_ci */ 225cabdff1aSopenharmony_ciattribute_deprecated 226cabdff1aSopenharmony_ciint avresample_is_open(AVAudioResampleContext *avr); 227cabdff1aSopenharmony_ci 228cabdff1aSopenharmony_ci/** 229cabdff1aSopenharmony_ci * 230cabdff1aSopenharmony_ci * @deprecated use libswresample 231cabdff1aSopenharmony_ci * 232cabdff1aSopenharmony_ci * Close AVAudioResampleContext. 233cabdff1aSopenharmony_ci * 234cabdff1aSopenharmony_ci * This closes the context, but it does not change the parameters. The context 235cabdff1aSopenharmony_ci * can be reopened with avresample_open(). It does, however, clear the output 236cabdff1aSopenharmony_ci * FIFO and any remaining leftover samples in the resampling delay buffer. If 237cabdff1aSopenharmony_ci * there was a custom matrix being used, that is also cleared. 238cabdff1aSopenharmony_ci * 239cabdff1aSopenharmony_ci * @see avresample_convert() 240cabdff1aSopenharmony_ci * @see avresample_set_matrix() 241cabdff1aSopenharmony_ci * 242cabdff1aSopenharmony_ci * @param avr audio resample context 243cabdff1aSopenharmony_ci */ 244cabdff1aSopenharmony_ciattribute_deprecated 245cabdff1aSopenharmony_civoid avresample_close(AVAudioResampleContext *avr); 246cabdff1aSopenharmony_ci 247cabdff1aSopenharmony_ci/** 248cabdff1aSopenharmony_ci * 249cabdff1aSopenharmony_ci * @deprecated use libswresample 250cabdff1aSopenharmony_ci * 251cabdff1aSopenharmony_ci * Free AVAudioResampleContext and associated AVOption values. 252cabdff1aSopenharmony_ci * 253cabdff1aSopenharmony_ci * This also calls avresample_close() before freeing. 254cabdff1aSopenharmony_ci * 255cabdff1aSopenharmony_ci * @param avr audio resample context 256cabdff1aSopenharmony_ci */ 257cabdff1aSopenharmony_ciattribute_deprecated 258cabdff1aSopenharmony_civoid avresample_free(AVAudioResampleContext **avr); 259cabdff1aSopenharmony_ci 260cabdff1aSopenharmony_ci/** 261cabdff1aSopenharmony_ci * 262cabdff1aSopenharmony_ci * @deprecated use libswresample 263cabdff1aSopenharmony_ci * 264cabdff1aSopenharmony_ci * Generate a channel mixing matrix. 265cabdff1aSopenharmony_ci * 266cabdff1aSopenharmony_ci * This function is the one used internally by libavresample for building the 267cabdff1aSopenharmony_ci * default mixing matrix. It is made public just as a utility function for 268cabdff1aSopenharmony_ci * building custom matrices. 269cabdff1aSopenharmony_ci * 270cabdff1aSopenharmony_ci * @param in_layout input channel layout 271cabdff1aSopenharmony_ci * @param out_layout output channel layout 272cabdff1aSopenharmony_ci * @param center_mix_level mix level for the center channel 273cabdff1aSopenharmony_ci * @param surround_mix_level mix level for the surround channel(s) 274cabdff1aSopenharmony_ci * @param lfe_mix_level mix level for the low-frequency effects channel 275cabdff1aSopenharmony_ci * @param normalize if 1, coefficients will be normalized to prevent 276cabdff1aSopenharmony_ci * overflow. if 0, coefficients will not be 277cabdff1aSopenharmony_ci * normalized. 278cabdff1aSopenharmony_ci * @param[out] matrix mixing coefficients; matrix[i + stride * o] is 279cabdff1aSopenharmony_ci * the weight of input channel i in output channel o. 280cabdff1aSopenharmony_ci * @param stride distance between adjacent input channels in the 281cabdff1aSopenharmony_ci * matrix array 282cabdff1aSopenharmony_ci * @param matrix_encoding matrixed stereo downmix mode (e.g. dplii) 283cabdff1aSopenharmony_ci * @return 0 on success, negative AVERROR code on failure 284cabdff1aSopenharmony_ci */ 285cabdff1aSopenharmony_ciattribute_deprecated 286cabdff1aSopenharmony_ciint avresample_build_matrix(uint64_t in_layout, uint64_t out_layout, 287cabdff1aSopenharmony_ci double center_mix_level, double surround_mix_level, 288cabdff1aSopenharmony_ci double lfe_mix_level, int normalize, double *matrix, 289cabdff1aSopenharmony_ci int stride, enum AVMatrixEncoding matrix_encoding); 290cabdff1aSopenharmony_ci 291cabdff1aSopenharmony_ci/** 292cabdff1aSopenharmony_ci * 293cabdff1aSopenharmony_ci * @deprecated use libswresample 294cabdff1aSopenharmony_ci * 295cabdff1aSopenharmony_ci * Get the current channel mixing matrix. 296cabdff1aSopenharmony_ci * 297cabdff1aSopenharmony_ci * If no custom matrix has been previously set or the AVAudioResampleContext is 298cabdff1aSopenharmony_ci * not open, an error is returned. 299cabdff1aSopenharmony_ci * 300cabdff1aSopenharmony_ci * @param avr audio resample context 301cabdff1aSopenharmony_ci * @param matrix mixing coefficients; matrix[i + stride * o] is the weight of 302cabdff1aSopenharmony_ci * input channel i in output channel o. 303cabdff1aSopenharmony_ci * @param stride distance between adjacent input channels in the matrix array 304cabdff1aSopenharmony_ci * @return 0 on success, negative AVERROR code on failure 305cabdff1aSopenharmony_ci */ 306cabdff1aSopenharmony_ciattribute_deprecated 307cabdff1aSopenharmony_ciint avresample_get_matrix(AVAudioResampleContext *avr, double *matrix, 308cabdff1aSopenharmony_ci int stride); 309cabdff1aSopenharmony_ci 310cabdff1aSopenharmony_ci/** 311cabdff1aSopenharmony_ci * 312cabdff1aSopenharmony_ci * @deprecated use libswresample 313cabdff1aSopenharmony_ci * 314cabdff1aSopenharmony_ci * Set channel mixing matrix. 315cabdff1aSopenharmony_ci * 316cabdff1aSopenharmony_ci * Allows for setting a custom mixing matrix, overriding the default matrix 317cabdff1aSopenharmony_ci * generated internally during avresample_open(). This function can be called 318cabdff1aSopenharmony_ci * anytime on an allocated context, either before or after calling 319cabdff1aSopenharmony_ci * avresample_open(), as long as the channel layouts have been set. 320cabdff1aSopenharmony_ci * avresample_convert() always uses the current matrix. 321cabdff1aSopenharmony_ci * Calling avresample_close() on the context will clear the current matrix. 322cabdff1aSopenharmony_ci * 323cabdff1aSopenharmony_ci * @see avresample_close() 324cabdff1aSopenharmony_ci * 325cabdff1aSopenharmony_ci * @param avr audio resample context 326cabdff1aSopenharmony_ci * @param matrix mixing coefficients; matrix[i + stride * o] is the weight of 327cabdff1aSopenharmony_ci * input channel i in output channel o. 328cabdff1aSopenharmony_ci * @param stride distance between adjacent input channels in the matrix array 329cabdff1aSopenharmony_ci * @return 0 on success, negative AVERROR code on failure 330cabdff1aSopenharmony_ci */ 331cabdff1aSopenharmony_ciattribute_deprecated 332cabdff1aSopenharmony_ciint avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix, 333cabdff1aSopenharmony_ci int stride); 334cabdff1aSopenharmony_ci 335cabdff1aSopenharmony_ci/** 336cabdff1aSopenharmony_ci * 337cabdff1aSopenharmony_ci * @deprecated use libswresample 338cabdff1aSopenharmony_ci * 339cabdff1aSopenharmony_ci * Set a customized input channel mapping. 340cabdff1aSopenharmony_ci * 341cabdff1aSopenharmony_ci * This function can only be called when the allocated context is not open. 342cabdff1aSopenharmony_ci * Also, the input channel layout must have already been set. 343cabdff1aSopenharmony_ci * 344cabdff1aSopenharmony_ci * Calling avresample_close() on the context will clear the channel mapping. 345cabdff1aSopenharmony_ci * 346cabdff1aSopenharmony_ci * The map for each input channel specifies the channel index in the source to 347cabdff1aSopenharmony_ci * use for that particular channel, or -1 to mute the channel. Source channels 348cabdff1aSopenharmony_ci * can be duplicated by using the same index for multiple input channels. 349cabdff1aSopenharmony_ci * 350cabdff1aSopenharmony_ci * Examples: 351cabdff1aSopenharmony_ci * 352cabdff1aSopenharmony_ci * Reordering 5.1 AAC order (C,L,R,Ls,Rs,LFE) to FFmpeg order (L,R,C,LFE,Ls,Rs): 353cabdff1aSopenharmony_ci * { 1, 2, 0, 5, 3, 4 } 354cabdff1aSopenharmony_ci * 355cabdff1aSopenharmony_ci * Muting the 3rd channel in 4-channel input: 356cabdff1aSopenharmony_ci * { 0, 1, -1, 3 } 357cabdff1aSopenharmony_ci * 358cabdff1aSopenharmony_ci * Duplicating the left channel of stereo input: 359cabdff1aSopenharmony_ci * { 0, 0 } 360cabdff1aSopenharmony_ci * 361cabdff1aSopenharmony_ci * @param avr audio resample context 362cabdff1aSopenharmony_ci * @param channel_map customized input channel mapping 363cabdff1aSopenharmony_ci * @return 0 on success, negative AVERROR code on failure 364cabdff1aSopenharmony_ci */ 365cabdff1aSopenharmony_ciattribute_deprecated 366cabdff1aSopenharmony_ciint avresample_set_channel_mapping(AVAudioResampleContext *avr, 367cabdff1aSopenharmony_ci const int *channel_map); 368cabdff1aSopenharmony_ci 369cabdff1aSopenharmony_ci/** 370cabdff1aSopenharmony_ci * 371cabdff1aSopenharmony_ci * @deprecated use libswresample 372cabdff1aSopenharmony_ci * 373cabdff1aSopenharmony_ci * Set compensation for resampling. 374cabdff1aSopenharmony_ci * 375cabdff1aSopenharmony_ci * This can be called anytime after avresample_open(). If resampling is not 376cabdff1aSopenharmony_ci * automatically enabled because of a sample rate conversion, the 377cabdff1aSopenharmony_ci * "force_resampling" option must have been set to 1 when opening the context 378cabdff1aSopenharmony_ci * in order to use resampling compensation. 379cabdff1aSopenharmony_ci * 380cabdff1aSopenharmony_ci * @param avr audio resample context 381cabdff1aSopenharmony_ci * @param sample_delta compensation delta, in samples 382cabdff1aSopenharmony_ci * @param compensation_distance compensation distance, in samples 383cabdff1aSopenharmony_ci * @return 0 on success, negative AVERROR code on failure 384cabdff1aSopenharmony_ci */ 385cabdff1aSopenharmony_ciattribute_deprecated 386cabdff1aSopenharmony_ciint avresample_set_compensation(AVAudioResampleContext *avr, int sample_delta, 387cabdff1aSopenharmony_ci int compensation_distance); 388cabdff1aSopenharmony_ci 389cabdff1aSopenharmony_ci/** 390cabdff1aSopenharmony_ci * 391cabdff1aSopenharmony_ci * @deprecated use libswresample 392cabdff1aSopenharmony_ci * 393cabdff1aSopenharmony_ci * Provide the upper bound on the number of samples the configured 394cabdff1aSopenharmony_ci * conversion would output. 395cabdff1aSopenharmony_ci * 396cabdff1aSopenharmony_ci * @param avr audio resample context 397cabdff1aSopenharmony_ci * @param in_nb_samples number of input samples 398cabdff1aSopenharmony_ci * 399cabdff1aSopenharmony_ci * @return number of samples or AVERROR(EINVAL) if the value 400cabdff1aSopenharmony_ci * would exceed INT_MAX 401cabdff1aSopenharmony_ci */ 402cabdff1aSopenharmony_ciattribute_deprecated 403cabdff1aSopenharmony_ciint avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples); 404cabdff1aSopenharmony_ci 405cabdff1aSopenharmony_ci/** 406cabdff1aSopenharmony_ci * 407cabdff1aSopenharmony_ci * @deprecated use libswresample 408cabdff1aSopenharmony_ci * 409cabdff1aSopenharmony_ci * Convert input samples and write them to the output FIFO. 410cabdff1aSopenharmony_ci * 411cabdff1aSopenharmony_ci * The upper bound on the number of output samples can be obtained through 412cabdff1aSopenharmony_ci * avresample_get_out_samples(). 413cabdff1aSopenharmony_ci * 414cabdff1aSopenharmony_ci * The output data can be NULL or have fewer allocated samples than required. 415cabdff1aSopenharmony_ci * In this case, any remaining samples not written to the output will be added 416cabdff1aSopenharmony_ci * to an internal FIFO buffer, to be returned at the next call to this function 417cabdff1aSopenharmony_ci * or to avresample_read(). 418cabdff1aSopenharmony_ci * 419cabdff1aSopenharmony_ci * If converting sample rate, there may be data remaining in the internal 420cabdff1aSopenharmony_ci * resampling delay buffer. avresample_get_delay() tells the number of remaining 421cabdff1aSopenharmony_ci * samples. To get this data as output, call avresample_convert() with NULL 422cabdff1aSopenharmony_ci * input. 423cabdff1aSopenharmony_ci * 424cabdff1aSopenharmony_ci * At the end of the conversion process, there may be data remaining in the 425cabdff1aSopenharmony_ci * internal FIFO buffer. avresample_available() tells the number of remaining 426cabdff1aSopenharmony_ci * samples. To get this data as output, either call avresample_convert() with 427cabdff1aSopenharmony_ci * NULL input or call avresample_read(). 428cabdff1aSopenharmony_ci * 429cabdff1aSopenharmony_ci * @see avresample_get_out_samples() 430cabdff1aSopenharmony_ci * @see avresample_read() 431cabdff1aSopenharmony_ci * @see avresample_get_delay() 432cabdff1aSopenharmony_ci * 433cabdff1aSopenharmony_ci * @param avr audio resample context 434cabdff1aSopenharmony_ci * @param output output data pointers 435cabdff1aSopenharmony_ci * @param out_plane_size output plane size, in bytes. 436cabdff1aSopenharmony_ci * This can be 0 if unknown, but that will lead to 437cabdff1aSopenharmony_ci * optimized functions not being used directly on the 438cabdff1aSopenharmony_ci * output, which could slow down some conversions. 439cabdff1aSopenharmony_ci * @param out_samples maximum number of samples that the output buffer can hold 440cabdff1aSopenharmony_ci * @param input input data pointers 441cabdff1aSopenharmony_ci * @param in_plane_size input plane size, in bytes 442cabdff1aSopenharmony_ci * This can be 0 if unknown, but that will lead to 443cabdff1aSopenharmony_ci * optimized functions not being used directly on the 444cabdff1aSopenharmony_ci * input, which could slow down some conversions. 445cabdff1aSopenharmony_ci * @param in_samples number of input samples to convert 446cabdff1aSopenharmony_ci * @return number of samples written to the output buffer, 447cabdff1aSopenharmony_ci * not including converted samples added to the internal 448cabdff1aSopenharmony_ci * output FIFO 449cabdff1aSopenharmony_ci */ 450cabdff1aSopenharmony_ciattribute_deprecated 451cabdff1aSopenharmony_ciint avresample_convert(AVAudioResampleContext *avr, uint8_t **output, 452cabdff1aSopenharmony_ci int out_plane_size, int out_samples, 453cabdff1aSopenharmony_ci uint8_t * const *input, int in_plane_size, 454cabdff1aSopenharmony_ci int in_samples); 455cabdff1aSopenharmony_ci 456cabdff1aSopenharmony_ci/** 457cabdff1aSopenharmony_ci * 458cabdff1aSopenharmony_ci * @deprecated use libswresample 459cabdff1aSopenharmony_ci * 460cabdff1aSopenharmony_ci * Return the number of samples currently in the resampling delay buffer. 461cabdff1aSopenharmony_ci * 462cabdff1aSopenharmony_ci * When resampling, there may be a delay between the input and output. Any 463cabdff1aSopenharmony_ci * unconverted samples in each call are stored internally in a delay buffer. 464cabdff1aSopenharmony_ci * This function allows the user to determine the current number of samples in 465cabdff1aSopenharmony_ci * the delay buffer, which can be useful for synchronization. 466cabdff1aSopenharmony_ci * 467cabdff1aSopenharmony_ci * @see avresample_convert() 468cabdff1aSopenharmony_ci * 469cabdff1aSopenharmony_ci * @param avr audio resample context 470cabdff1aSopenharmony_ci * @return number of samples currently in the resampling delay buffer 471cabdff1aSopenharmony_ci */ 472cabdff1aSopenharmony_ciattribute_deprecated 473cabdff1aSopenharmony_ciint avresample_get_delay(AVAudioResampleContext *avr); 474cabdff1aSopenharmony_ci 475cabdff1aSopenharmony_ci/** 476cabdff1aSopenharmony_ci * 477cabdff1aSopenharmony_ci * @deprecated use libswresample 478cabdff1aSopenharmony_ci * 479cabdff1aSopenharmony_ci * Return the number of available samples in the output FIFO. 480cabdff1aSopenharmony_ci * 481cabdff1aSopenharmony_ci * During conversion, if the user does not specify an output buffer or 482cabdff1aSopenharmony_ci * specifies an output buffer that is smaller than what is needed, remaining 483cabdff1aSopenharmony_ci * samples that are not written to the output are stored to an internal FIFO 484cabdff1aSopenharmony_ci * buffer. The samples in the FIFO can be read with avresample_read() or 485cabdff1aSopenharmony_ci * avresample_convert(). 486cabdff1aSopenharmony_ci * 487cabdff1aSopenharmony_ci * @see avresample_read() 488cabdff1aSopenharmony_ci * @see avresample_convert() 489cabdff1aSopenharmony_ci * 490cabdff1aSopenharmony_ci * @param avr audio resample context 491cabdff1aSopenharmony_ci * @return number of samples available for reading 492cabdff1aSopenharmony_ci */ 493cabdff1aSopenharmony_ciattribute_deprecated 494cabdff1aSopenharmony_ciint avresample_available(AVAudioResampleContext *avr); 495cabdff1aSopenharmony_ci 496cabdff1aSopenharmony_ci/** 497cabdff1aSopenharmony_ci * 498cabdff1aSopenharmony_ci * @deprecated use libswresample 499cabdff1aSopenharmony_ci * 500cabdff1aSopenharmony_ci * Read samples from the output FIFO. 501cabdff1aSopenharmony_ci * 502cabdff1aSopenharmony_ci * During conversion, if the user does not specify an output buffer or 503cabdff1aSopenharmony_ci * specifies an output buffer that is smaller than what is needed, remaining 504cabdff1aSopenharmony_ci * samples that are not written to the output are stored to an internal FIFO 505cabdff1aSopenharmony_ci * buffer. This function can be used to read samples from that internal FIFO. 506cabdff1aSopenharmony_ci * 507cabdff1aSopenharmony_ci * @see avresample_available() 508cabdff1aSopenharmony_ci * @see avresample_convert() 509cabdff1aSopenharmony_ci * 510cabdff1aSopenharmony_ci * @param avr audio resample context 511cabdff1aSopenharmony_ci * @param output output data pointers. May be NULL, in which case 512cabdff1aSopenharmony_ci * nb_samples of data is discarded from output FIFO. 513cabdff1aSopenharmony_ci * @param nb_samples number of samples to read from the FIFO 514cabdff1aSopenharmony_ci * @return the number of samples written to output 515cabdff1aSopenharmony_ci */ 516cabdff1aSopenharmony_ciattribute_deprecated 517cabdff1aSopenharmony_ciint avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples); 518cabdff1aSopenharmony_ci 519cabdff1aSopenharmony_ci/** 520cabdff1aSopenharmony_ci * 521cabdff1aSopenharmony_ci * @deprecated use libswresample 522cabdff1aSopenharmony_ci * 523cabdff1aSopenharmony_ci * Convert the samples in the input AVFrame and write them to the output AVFrame. 524cabdff1aSopenharmony_ci * 525cabdff1aSopenharmony_ci * Input and output AVFrames must have channel_layout, sample_rate and format set. 526cabdff1aSopenharmony_ci * 527cabdff1aSopenharmony_ci * The upper bound on the number of output samples is obtained through 528cabdff1aSopenharmony_ci * avresample_get_out_samples(). 529cabdff1aSopenharmony_ci * 530cabdff1aSopenharmony_ci * If the output AVFrame does not have the data pointers allocated the nb_samples 531cabdff1aSopenharmony_ci * field will be set using avresample_get_out_samples() and av_frame_get_buffer() 532cabdff1aSopenharmony_ci * is called to allocate the frame. 533cabdff1aSopenharmony_ci * 534cabdff1aSopenharmony_ci * The output AVFrame can be NULL or have fewer allocated samples than required. 535cabdff1aSopenharmony_ci * In this case, any remaining samples not written to the output will be added 536cabdff1aSopenharmony_ci * to an internal FIFO buffer, to be returned at the next call to this function 537cabdff1aSopenharmony_ci * or to avresample_convert() or to avresample_read(). 538cabdff1aSopenharmony_ci * 539cabdff1aSopenharmony_ci * If converting sample rate, there may be data remaining in the internal 540cabdff1aSopenharmony_ci * resampling delay buffer. avresample_get_delay() tells the number of 541cabdff1aSopenharmony_ci * remaining samples. To get this data as output, call this function or 542cabdff1aSopenharmony_ci * avresample_convert() with NULL input. 543cabdff1aSopenharmony_ci * 544cabdff1aSopenharmony_ci * At the end of the conversion process, there may be data remaining in the 545cabdff1aSopenharmony_ci * internal FIFO buffer. avresample_available() tells the number of remaining 546cabdff1aSopenharmony_ci * samples. To get this data as output, either call this function or 547cabdff1aSopenharmony_ci * avresample_convert() with NULL input or call avresample_read(). 548cabdff1aSopenharmony_ci * 549cabdff1aSopenharmony_ci * If the AVAudioResampleContext configuration does not match the output and 550cabdff1aSopenharmony_ci * input AVFrame settings the conversion does not take place and depending on 551cabdff1aSopenharmony_ci * which AVFrame is not matching AVERROR_OUTPUT_CHANGED, AVERROR_INPUT_CHANGED 552cabdff1aSopenharmony_ci * or AVERROR_OUTPUT_CHANGED|AVERROR_INPUT_CHANGED is returned. 553cabdff1aSopenharmony_ci * 554cabdff1aSopenharmony_ci * @see avresample_get_out_samples() 555cabdff1aSopenharmony_ci * @see avresample_available() 556cabdff1aSopenharmony_ci * @see avresample_convert() 557cabdff1aSopenharmony_ci * @see avresample_read() 558cabdff1aSopenharmony_ci * @see avresample_get_delay() 559cabdff1aSopenharmony_ci * 560cabdff1aSopenharmony_ci * @param avr audio resample context 561cabdff1aSopenharmony_ci * @param output output AVFrame 562cabdff1aSopenharmony_ci * @param input input AVFrame 563cabdff1aSopenharmony_ci * @return 0 on success, AVERROR on failure or nonmatching 564cabdff1aSopenharmony_ci * configuration. 565cabdff1aSopenharmony_ci */ 566cabdff1aSopenharmony_ciattribute_deprecated 567cabdff1aSopenharmony_ciint avresample_convert_frame(AVAudioResampleContext *avr, 568cabdff1aSopenharmony_ci AVFrame *output, AVFrame *input); 569cabdff1aSopenharmony_ci 570cabdff1aSopenharmony_ci/** 571cabdff1aSopenharmony_ci * 572cabdff1aSopenharmony_ci * @deprecated use libswresample 573cabdff1aSopenharmony_ci * 574cabdff1aSopenharmony_ci * Configure or reconfigure the AVAudioResampleContext using the information 575cabdff1aSopenharmony_ci * provided by the AVFrames. 576cabdff1aSopenharmony_ci * 577cabdff1aSopenharmony_ci * The original resampling context is reset even on failure. 578cabdff1aSopenharmony_ci * The function calls avresample_close() internally if the context is open. 579cabdff1aSopenharmony_ci * 580cabdff1aSopenharmony_ci * @see avresample_open(); 581cabdff1aSopenharmony_ci * @see avresample_close(); 582cabdff1aSopenharmony_ci * 583cabdff1aSopenharmony_ci * @param avr audio resample context 584cabdff1aSopenharmony_ci * @param out output AVFrame 585cabdff1aSopenharmony_ci * @param in input AVFrame 586cabdff1aSopenharmony_ci * @return 0 on success, AVERROR on failure. 587cabdff1aSopenharmony_ci */ 588cabdff1aSopenharmony_ciattribute_deprecated 589cabdff1aSopenharmony_ciint avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in); 590cabdff1aSopenharmony_ci 591cabdff1aSopenharmony_ci/** 592cabdff1aSopenharmony_ci * @} 593cabdff1aSopenharmony_ci */ 594cabdff1aSopenharmony_ci 595cabdff1aSopenharmony_ci#endif /* AVRESAMPLE_AVRESAMPLE_H */ 596