|
avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
|
Converts audio between sample rates, sample formats and channel layouts. More...
#include <audioresampler.h>
Public Member Functions | |
| AudioResampler () | |
| Create an uninitialised resampler. | |
| AudioResampler (uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat, uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat, OptionalErrorCode ec=throws()) | |
| Create and initialise a resampler. | |
| AudioResampler (uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat, uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat, Dictionary &options, OptionalErrorCode ec=throws()) | |
| Create and initialise a resampler with options. | |
| AudioResampler (uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat, uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat, Dictionary &&options, OptionalErrorCode ec=throws()) | |
| Create and initialise a resampler with options, moving the dictionary. | |
| AudioResampler (AudioResampler &&other) | |
| Move a resampler. | |
| AudioResampler & | operator= (AudioResampler &&rhs) |
| Move assignment. | |
| void | swap (AudioResampler &other) |
| Exchange the state of two resamplers. | |
| uint64_t | dstChannelLayout () const |
| Channel layout the resampler produces. | |
| int | dstChannels () const |
| Number of channels the resampler produces. | |
| int | dstSampleRate () const |
| Sample rate the resampler produces. | |
| SampleFormat | dstSampleFormat () const |
| Sample format the resampler produces. | |
| uint64_t | srcChannelLayout () const |
| Channel layout the resampler expects. | |
| int | srcChannels () const |
| Number of channels the resampler expects. | |
| int | srcSampleRate () const |
| Sample rate the resampler expects. | |
| SampleFormat | srcSampleFormat () const |
| Sample format the resampler expects. | |
| void | push (const AudioSamples &src, OptionalErrorCode ec=throws()) |
| Push frame to the rescaler context. | |
| bool | pop (AudioSamples &dst, bool getall, OptionalErrorCode ec=throws()) |
| Pop frame from the rescaler context. | |
| AudioSamples | pop (size_t samplesCount, OptionalErrorCode ec=throws()) |
| Pop frame from the rescaler context. | |
| bool | isValid () const |
| Whether the resampler is initialised. | |
| operator bool () const | |
| Whether the resampler is initialised. | |
| int64_t | delay () const |
| Samples still buffered inside the resampler. | |
| bool | init (uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat, uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat, OptionalErrorCode ec=throws()) |
| Initialise the resampler. | |
| bool | init (uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat, uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat, Dictionary &options, OptionalErrorCode ec=throws()) |
| Initialise the resampler with options. | |
| bool | init (uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat, uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat, Dictionary &&options, OptionalErrorCode ec=throws()) |
| Initialise the resampler with options, moving the dictionary. | |
| Public Member Functions inherited from FFWrapperPtr< SwrContext > | |
| FFWrapperPtr ()=default | |
| Create an empty wrapper; isNull() is true. | |
| const SwrContext * | raw () const |
| Read access to the wrapped object. | |
| void | reset (SwrContext *raw=nullptr) |
| Replace the stored pointer. | |
| bool | isNull () const |
| Whether the wrapper is empty. | |
| void | _log (int level, const char *fmt) const |
| Log through the FFmpeg log system, using this wrapper as the context. | |
Static Public Member Functions | |
| static bool | validate (uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat) |
| Whether the output parameters are usable before the input is known. | |
Additional Inherited Members | |
| Protected Member Functions inherited from av::noncopyable | |
| noncopyable (const noncopyable &)=delete | |
| void | operator= (const noncopyable &)=delete |
| Protected Attributes inherited from FFWrapperPtr< SwrContext > | |
| SwrContext * | m_raw |
| The wrapped pointer; owned by the derived class, not by this template. | |
The typical use is a decode-transform-encode pipeline: the decoder produces whatever the stream contains, the encoder accepts one specific layout, and this is the component in between. Construct it with both layouts, or call init() later; push() feeds samples in and pop() takes them out.
A single push can produce several output buffers, and the resampler holds an internal delay, so popping until it returns nothing is part of the contract.
| av::AudioResampler::AudioResampler | ( | ) |
Nothing can be pushed until init() succeeds.
| av::AudioResampler::AudioResampler | ( | uint64_t | dstChannelsLayout, |
| int | dstRate, | ||
| SampleFormat | dstFormat, | ||
| uint64_t | srcChannelsLayout, | ||
| int | srcRate, | ||
| SampleFormat | srcFormat, | ||
| OptionalErrorCode | ec = throws() ) |
| dstChannelsLayout | channel layout to produce, as an AV_CH_LAYOUT_* mask |
| dstRate | sample rate to produce, in hertz |
| dstFormat | sample format to produce |
| srcChannelsLayout | channel layout of the input |
| srcRate | sample rate of the input, in hertz |
| srcFormat | sample format of the input |
| ec | holder for the error code |
| av::AudioResampler::AudioResampler | ( | uint64_t | dstChannelsLayout, |
| int | dstRate, | ||
| SampleFormat | dstFormat, | ||
| uint64_t | srcChannelsLayout, | ||
| int | srcRate, | ||
| SampleFormat | srcFormat, | ||
| Dictionary & | options, | ||
| OptionalErrorCode | ec = throws() ) |
| dstChannelsLayout | channel layout to produce |
| dstRate | sample rate to produce |
| dstFormat | sample format to produce |
| srcChannelsLayout | channel layout of the input |
| srcRate | sample rate of the input |
| srcFormat | sample format of the input |
| options | resampler options; the object stays usable, but FFmpeg removes the options it recognized |
| ec | holder for the error code |
| av::AudioResampler::AudioResampler | ( | uint64_t | dstChannelsLayout, |
| int | dstRate, | ||
| SampleFormat | dstFormat, | ||
| uint64_t | srcChannelsLayout, | ||
| int | srcRate, | ||
| SampleFormat | srcFormat, | ||
| Dictionary && | options, | ||
| OptionalErrorCode | ec = throws() ) |
| dstChannelsLayout | channel layout to produce |
| dstRate | sample rate to produce |
| dstFormat | sample format to produce |
| srcChannelsLayout | channel layout of the input |
| srcRate | sample rate of the input |
| srcFormat | sample format of the input |
| options | resampler options, moved into the call |
| ec | holder for the error code |
| av::AudioResampler::AudioResampler | ( | AudioResampler && | other | ) |
| other | the resampler to move from; left uninitialised |
| int64_t av::AudioResampler::delay | ( | ) | const |
| uint64_t av::AudioResampler::dstChannelLayout | ( | ) | const |
| int av::AudioResampler::dstChannels | ( | ) | const |
| SampleFormat av::AudioResampler::dstSampleFormat | ( | ) | const |
| int av::AudioResampler::dstSampleRate | ( | ) | const |
| bool av::AudioResampler::init | ( | uint64_t | dstChannelsLayout, |
| int | dstRate, | ||
| SampleFormat | dstFormat, | ||
| uint64_t | srcChannelsLayout, | ||
| int | srcRate, | ||
| SampleFormat | srcFormat, | ||
| Dictionary && | options, | ||
| OptionalErrorCode | ec = throws() ) |
| dstChannelsLayout | channel layout to produce |
| dstRate | sample rate to produce |
| dstFormat | sample format to produce |
| srcChannelsLayout | channel layout of the input |
| srcRate | sample rate of the input |
| srcFormat | sample format of the input |
| options | resampler options, moved into the call |
| ec | holder for the error code |
| bool av::AudioResampler::init | ( | uint64_t | dstChannelsLayout, |
| int | dstRate, | ||
| SampleFormat | dstFormat, | ||
| uint64_t | srcChannelsLayout, | ||
| int | srcRate, | ||
| SampleFormat | srcFormat, | ||
| Dictionary & | options, | ||
| OptionalErrorCode | ec = throws() ) |
| dstChannelsLayout | channel layout to produce |
| dstRate | sample rate to produce |
| dstFormat | sample format to produce |
| srcChannelsLayout | channel layout of the input |
| srcRate | sample rate of the input |
| srcFormat | sample format of the input |
| options | resampler options; the object stays usable, but FFmpeg removes the options it recognized |
| ec | holder for the error code |
| bool av::AudioResampler::init | ( | uint64_t | dstChannelsLayout, |
| int | dstRate, | ||
| SampleFormat | dstFormat, | ||
| uint64_t | srcChannelsLayout, | ||
| int | srcRate, | ||
| SampleFormat | srcFormat, | ||
| OptionalErrorCode | ec = throws() ) |
| dstChannelsLayout | channel layout to produce, as an AV_CH_LAYOUT_* mask |
| dstRate | sample rate to produce, in hertz |
| dstFormat | sample format to produce |
| srcChannelsLayout | channel layout of the input |
| srcRate | sample rate of the input, in hertz |
| srcFormat | sample format of the input |
| ec | holder for the error code |
| bool av::AudioResampler::isValid | ( | ) | const |
|
inline |
| AudioResampler & av::AudioResampler::operator= | ( | AudioResampler && | rhs | ) |
| rhs | the resampler to move from; left uninitialised |
| bool av::AudioResampler::pop | ( | AudioSamples & | dst, |
| bool | getall, | ||
| OptionalErrorCode | ec = throws() ) |
Note, single push can produce multiple output frames.
If getall sets to true and false returns, this means that no data at all and resampler fully flushed.
| [out] | dst | frame to store audio data. Frame must be allocated before call. |
| [in] | getall | if true and if avail data less then nb_samples return data as is |
| [in,out] | ec | this represents the error status on exit, if this is pre-initialized to av::throws the function will throw on error instead |
| AudioSamples av::AudioResampler::pop | ( | size_t | samplesCount, |
| OptionalErrorCode | ec = throws() ) |
Note, single push can produce multiple output frames.
If samplesCount sets to the zero and null frame returns, it means that no data at all and resampler fully flushed.
| [in] | samplesCount | samples count to extract. If zero (0) - extract all delayed (buffered) samples. |
| [in,out] | ec | this represents the error status on exit, if this is pre-initialized to av::throws the function will throw on error instead |
| void av::AudioResampler::push | ( | const AudioSamples & | src, |
| OptionalErrorCode | ec = throws() ) |
Note, signle push can produce multiple frames.
| [in] | src | source frame |
| [in,out] | ec | this represents the error status on exit, if this is pre-initialized to av::throws the function will throw on error instead |
| uint64_t av::AudioResampler::srcChannelLayout | ( | ) | const |
| int av::AudioResampler::srcChannels | ( | ) | const |
| SampleFormat av::AudioResampler::srcSampleFormat | ( | ) | const |
| int av::AudioResampler::srcSampleRate | ( | ) | const |
| void av::AudioResampler::swap | ( | AudioResampler & | other | ) |
| other | the resampler to swap with |
|
static |
| dstChannelsLayout | channel layout to produce |
| dstRate | sample rate to produce |
| dstFormat | sample format to produce |