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_AUDIO_CONVERT_H
22cabdff1aSopenharmony_ci#define AVRESAMPLE_AUDIO_CONVERT_H
23cabdff1aSopenharmony_ci
24cabdff1aSopenharmony_ci#include "libavutil/samplefmt.h"
25cabdff1aSopenharmony_ci#include "avresample.h"
26cabdff1aSopenharmony_ci#include "internal.h"
27cabdff1aSopenharmony_ci#include "audio_data.h"
28cabdff1aSopenharmony_ci
29cabdff1aSopenharmony_ci/**
30cabdff1aSopenharmony_ci * Set conversion function if the parameters match.
31cabdff1aSopenharmony_ci *
32cabdff1aSopenharmony_ci * This compares the parameters of the conversion function to the parameters
33cabdff1aSopenharmony_ci * in the AudioConvert context. If the parameters do not match, no changes are
34cabdff1aSopenharmony_ci * made to the active functions. If the parameters do match and the alignment
35cabdff1aSopenharmony_ci * is not constrained, the function is set as the generic conversion function.
36cabdff1aSopenharmony_ci * If the parameters match and the alignment is constrained, the function is
37cabdff1aSopenharmony_ci * set as the optimized conversion function.
38cabdff1aSopenharmony_ci *
39cabdff1aSopenharmony_ci * @param ac             AudioConvert context
40cabdff1aSopenharmony_ci * @param out_fmt        output sample format
41cabdff1aSopenharmony_ci * @param in_fmt         input sample format
42cabdff1aSopenharmony_ci * @param channels       number of channels, or 0 for any number of channels
43cabdff1aSopenharmony_ci * @param ptr_align      buffer pointer alignment, in bytes
44cabdff1aSopenharmony_ci * @param samples_align  buffer size alignment, in samples
45cabdff1aSopenharmony_ci * @param descr          function type description (e.g. "C" or "SSE")
46cabdff1aSopenharmony_ci * @param conv           conversion function pointer
47cabdff1aSopenharmony_ci */
48cabdff1aSopenharmony_civoid ff_audio_convert_set_func(AudioConvert *ac, enum AVSampleFormat out_fmt,
49cabdff1aSopenharmony_ci                               enum AVSampleFormat in_fmt, int channels,
50cabdff1aSopenharmony_ci                               int ptr_align, int samples_align,
51cabdff1aSopenharmony_ci                               const char *descr, void *conv);
52cabdff1aSopenharmony_ci
53cabdff1aSopenharmony_ci/**
54cabdff1aSopenharmony_ci * Allocate and initialize AudioConvert context for sample format conversion.
55cabdff1aSopenharmony_ci *
56cabdff1aSopenharmony_ci * @param avr         AVAudioResampleContext
57cabdff1aSopenharmony_ci * @param out_fmt     output sample format
58cabdff1aSopenharmony_ci * @param in_fmt      input sample format
59cabdff1aSopenharmony_ci * @param channels    number of channels
60cabdff1aSopenharmony_ci * @param sample_rate sample rate (used for dithering)
61cabdff1aSopenharmony_ci * @param apply_map   apply channel map during conversion
62cabdff1aSopenharmony_ci * @return            newly-allocated AudioConvert context
63cabdff1aSopenharmony_ci */
64cabdff1aSopenharmony_ciAudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr,
65cabdff1aSopenharmony_ci                                     enum AVSampleFormat out_fmt,
66cabdff1aSopenharmony_ci                                     enum AVSampleFormat in_fmt,
67cabdff1aSopenharmony_ci                                     int channels, int sample_rate,
68cabdff1aSopenharmony_ci                                     int apply_map);
69cabdff1aSopenharmony_ci
70cabdff1aSopenharmony_ci/**
71cabdff1aSopenharmony_ci * Free AudioConvert.
72cabdff1aSopenharmony_ci *
73cabdff1aSopenharmony_ci * The AudioConvert must have been previously allocated with ff_audio_convert_alloc().
74cabdff1aSopenharmony_ci *
75cabdff1aSopenharmony_ci * @param ac  AudioConvert struct
76cabdff1aSopenharmony_ci */
77cabdff1aSopenharmony_civoid ff_audio_convert_free(AudioConvert **ac);
78cabdff1aSopenharmony_ci
79cabdff1aSopenharmony_ci/**
80cabdff1aSopenharmony_ci * Convert audio data from one sample format to another.
81cabdff1aSopenharmony_ci *
82cabdff1aSopenharmony_ci * For each call, the alignment of the input and output AudioData buffers are
83cabdff1aSopenharmony_ci * examined to determine whether to use the generic or optimized conversion
84cabdff1aSopenharmony_ci * function (when available).
85cabdff1aSopenharmony_ci *
86cabdff1aSopenharmony_ci * The number of samples to convert is determined by in->nb_samples. The output
87cabdff1aSopenharmony_ci * buffer must be large enough to handle this many samples. out->nb_samples is
88cabdff1aSopenharmony_ci * set by this function before a successful return.
89cabdff1aSopenharmony_ci *
90cabdff1aSopenharmony_ci * @param ac     AudioConvert context
91cabdff1aSopenharmony_ci * @param out    output audio data
92cabdff1aSopenharmony_ci * @param in     input audio data
93cabdff1aSopenharmony_ci * @return       0 on success, negative AVERROR code on failure
94cabdff1aSopenharmony_ci */
95cabdff1aSopenharmony_ciint ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in);
96cabdff1aSopenharmony_ci
97cabdff1aSopenharmony_ci/* arch-specific initialization functions */
98cabdff1aSopenharmony_ci
99cabdff1aSopenharmony_civoid ff_audio_convert_init_aarch64(AudioConvert *ac);
100cabdff1aSopenharmony_civoid ff_audio_convert_init_arm(AudioConvert *ac);
101cabdff1aSopenharmony_civoid ff_audio_convert_init_x86(AudioConvert *ac);
102cabdff1aSopenharmony_ci
103cabdff1aSopenharmony_ci#endif /* AVRESAMPLE_AUDIO_CONVERT_H */
104