avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
audioresampler.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <functional>
11
12#include "ffmpeg.h"
13#include "frame.h"
14#include "dictionary.h"
15#include "avutils.h"
16#include "sampleformat.h"
17#include "averror.h"
18
19namespace av {
20
21// TODO: support New Channel Layout directly
22
34class AudioResampler : public FFWrapperPtr<SwrContext>, public noncopyable
35{
36public:
43
55 AudioResampler(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
56 uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
57 OptionalErrorCode ec = throws());
58
71 AudioResampler(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
72 uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
73 Dictionary &options,
74 OptionalErrorCode ec = throws());
75
88 AudioResampler(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
89 uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
90 Dictionary &&options,
91 OptionalErrorCode ec = throws());
92
94
109
115 void swap(AudioResampler& other);
116
122 uint64_t dstChannelLayout() const;
128 int dstChannels() const;
134 int dstSampleRate() const;
141
147 uint64_t srcChannelLayout() const;
153 int srcChannels() const;
159 int srcSampleRate() const;
166
174 void push(const AudioSamples &src, OptionalErrorCode ec = throws());
175
190 bool pop(AudioSamples &dst, bool getall, OptionalErrorCode ec = throws());
191
205 AudioSamples pop(size_t samplesCount, OptionalErrorCode ec = throws());
206
212 bool isValid() const;
218 operator bool() const { return isValid(); }
219
225 int64_t delay() const;
226
240 bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
241 uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
242 OptionalErrorCode ec = throws());
243
258 bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
259 uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
260 Dictionary &options,
261 OptionalErrorCode ec = throws());
262
277 bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
278 uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
279 Dictionary &&options,
280 OptionalErrorCode ec = throws());
281
282 static
292 bool validate(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat);
293
294private:
295 bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
296 uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
297 AVDictionary **dict, OptionalErrorCode ec);
298
299private:
300 // Cached values to avoid access to the av_opt
301 uint64_t m_dstChannelsLayout;
302 int m_dstRate;
303 SampleFormat m_dstFormat;
304 uint64_t m_srcChannelsLayout;
305 int m_srcRate;
306 SampleFormat m_srcFormat;
307
308 int m_streamIndex = -1;
309 Timestamp m_prevPts;
310 Timestamp m_nextPts;
311
312 int64_t m_filterSize;
313};
314
315} // namespace av
316
Error codes, error categories and the OptionalErrorCode convention.
Common helpers: comparisons, value lookup, non-copyable base, string utilities.
uint64_t dstChannelLayout() const
Channel layout the resampler produces.
bool isValid() const
Whether the resampler is initialised.
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.
int64_t delay() const
Samples still buffered inside the resampler.
static bool validate(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat)
Whether the output parameters are usable before the input is known.
AudioResampler()
Create an uninitialised 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.
SampleFormat srcSampleFormat() const
Sample format the resampler expects.
AudioResampler(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat, uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat, OptionalErrorCode ec=throws())
Create and initialise a resampler.
AudioSamples pop(size_t samplesCount, OptionalErrorCode ec=throws())
Pop frame from the rescaler context.
AudioResampler & operator=(AudioResampler &&rhs)
Move assignment.
bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat, uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat, OptionalErrorCode ec=throws())
Initialise the 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.
int srcSampleRate() const
Sample rate the resampler expects.
uint64_t srcChannelLayout() const
Channel layout the resampler expects.
int dstSampleRate() const
Sample rate the resampler produces.
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.
void swap(AudioResampler &other)
Exchange the state of two resamplers.
int dstChannels() const
Number of channels the resampler produces.
AudioResampler(AudioResampler &&other)
Move a resampler.
int srcChannels() const
Number of channels 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.
SampleFormat dstSampleFormat() const
Sample format the resampler produces.
One buffer of decoded audio samples.
Definition frame.h:892
Implements interface to access to the AVDictionary entity.
Definition dictionary.h:38
Carries the caller's choice between exceptions and error codes.
Definition averror.h:96
The SampleFormat class is a simple proxy class for AVSampleFormat.
Definition sampleformat.h:35
The Timestamp class represents timestamp value and it timebase.
Definition timestamp.h:25
AVDictionary wrappers: Dictionary and DictionaryArray.
FFmpeg types re-exported for the public API and small value wrappers.
Video frames, audio samples and their common frame interface.
Root namespace of the library.
Definition audioresampler.h:19
Audio sample formats.