avcpp  2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
audioresampler.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 
5 #include "ffmpeg.h"
6 #include "frame.h"
7 #include "dictionary.h"
8 #include "avutils.h"
9 #include "sampleformat.h"
10 #include "averror.h"
11 
12 namespace av {
13 
14 // TODO: support New Channel Layout directly
15 
16 class AudioResampler : public FFWrapperPtr<SwrContext>, public noncopyable
17 {
18 public:
20 
21  AudioResampler(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
22  uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
23  OptionalErrorCode ec = throws());
24 
25  AudioResampler(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
26  uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
27  Dictionary &options,
28  OptionalErrorCode ec = throws());
29 
30  AudioResampler(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
31  uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
32  Dictionary &&options,
33  OptionalErrorCode ec = throws());
34 
36 
39 
40  void swap(AudioResampler& other);
41 
42  uint64_t dstChannelLayout() const;
43  int dstChannels() const;
44  int dstSampleRate() const;
46 
47  uint64_t srcChannelLayout() const;
48  int srcChannels() const;
49  int srcSampleRate() const;
51 
59  void push(const AudioSamples &src, OptionalErrorCode ec = throws());
60 
75  bool pop(AudioSamples &dst, bool getall, OptionalErrorCode ec = throws());
76 
90  AudioSamples pop(size_t samplesCount, OptionalErrorCode ec = throws());
91 
92  bool isValid() const;
93  operator bool() const { return isValid(); }
94 
95  int64_t delay() const;
96 
97  bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
98  uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
99  OptionalErrorCode ec = throws());
100 
101  bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
102  uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
103  Dictionary &options,
104  OptionalErrorCode ec = throws());
105 
106  bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
107  uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
108  Dictionary &&options,
109  OptionalErrorCode ec = throws());
110 
111  static
112  bool validate(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat);
113 
114 private:
115  bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat,
116  uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat,
117  AVDictionary **dict, OptionalErrorCode ec);
118 
119 private:
120  // Cached values to avoid access to the av_opt
121  uint64_t m_dstChannelsLayout;
122  int m_dstRate;
123  SampleFormat m_dstFormat;
124  uint64_t m_srcChannelsLayout;
125  int m_srcRate;
126  SampleFormat m_srcFormat;
127 
128  int m_streamIndex = -1;
129  Timestamp m_prevPts;
130  Timestamp m_nextPts;
131 
132  int64_t m_filterSize;
133 };
134 
135 } // namespace av
136 
av::AudioResampler::push
void push(const AudioSamples &src, OptionalErrorCode ec=throws())
Push frame to the rescaler context.
Definition: audioresampler.cpp:248
av::AudioResampler::AudioResampler
AudioResampler()
Definition: audioresampler.cpp:10
av::AudioResampler::init
bool init(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat, uint64_t srcChannelsLayout, int srcRate, SampleFormat srcFormat, OptionalErrorCode ec=throws())
Definition: audioresampler.cpp:303
av::AudioResampler::operator=
AudioResampler & operator=(AudioResampler &&rhs)
Definition: audioresampler.cpp:55
av::Dictionary
Implements interface to access to the AVDictionary entity.
Definition: dictionary.h:30
averror.h
ffmpeg.h
FFWrapperPtr
Definition: ffmpeg.h:68
av::AudioResampler::validate
static bool validate(uint64_t dstChannelsLayout, int dstRate, SampleFormat dstFormat)
Definition: audioresampler.cpp:335
av::AudioResampler
Definition: audioresampler.h:16
av::OptionalErrorCode
Definition: averror.h:63
av::AudioResampler::delay
int64_t delay() const
Definition: audioresampler.cpp:296
av::AudioResampler::dstChannelLayout
uint64_t dstChannelLayout() const
Definition: audioresampler.cpp:80
avutils.h
av::AudioResampler::dstSampleRate
int dstSampleRate() const
Definition: audioresampler.cpp:115
frame.h
sampleformat.h
av::AudioSamples
Definition: frame.h:391
av::AudioResampler::dstSampleFormat
SampleFormat dstSampleFormat() const
Definition: audioresampler.cpp:120
av::AudioResampler::srcSampleFormat
SampleFormat srcSampleFormat() const
Definition: audioresampler.cpp:140
dictionary.h
av::AudioResampler::srcChannels
int srcChannels() const
Definition: audioresampler.cpp:130
av
Definition: audioresampler.cpp:8
av::AudioResampler::~AudioResampler
~AudioResampler()
Definition: audioresampler.cpp:41
av::noncopyable
Definition: avutils.h:69
av::AudioResampler::dstChannels
int dstChannels() const
Definition: audioresampler.cpp:110
av::AudioResampler::srcChannelLayout
uint64_t srcChannelLayout() const
Definition: audioresampler.cpp:125
av::AudioResampler::isValid
bool isValid() const
Definition: audioresampler.cpp:291
av::Timestamp
The Timestamp class represents timestamp value and it timebase.
Definition: timestamp.h:13
av::AudioResampler::swap
void swap(AudioResampler &other)
Definition: audioresampler.cpp:64
av::AudioResampler::srcSampleRate
int srcSampleRate() const
Definition: audioresampler.cpp:135
av::AudioResampler::pop
bool pop(AudioSamples &dst, bool getall, OptionalErrorCode ec=throws())
Pop frame from the rescaler context.
Definition: audioresampler.cpp:145
av::SampleFormat
The SampleFormat class is a simple proxy class for AVSampleFormat.
Definition: sampleformat.h:21