avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
sampleformat.h
Go to the documentation of this file.
1#pragma once
2
9
10#include <iostream>
11#include <string>
12
13#include "averror.h"
14#include "ffmpeg.h"
15
16extern "C" {
17#include <libavutil/samplefmt.h>
18}
19
20namespace av {
21
34class SampleFormat : public PixSampleFmtWrapper<SampleFormat, AVSampleFormat>
35{
36public:
43 {
48 };
49
52 using Parent::Parent;
53
57 SampleFormat() = default;
63 explicit SampleFormat(const char* name) noexcept;
69 explicit SampleFormat(const std::string& name) noexcept;
70
78 const char* name(OptionalErrorCode ec = throws()) const;
79
100
106 bool isPlanar() const noexcept;
107
127
138 size_t requiredBufferSize(int nbChannels, int nbSamples, int align, OptionalErrorCode ec = throws()) const;
150 size_t requiredBufferSize(int nbChannels, int nbSamples, int align, int &lineSize, OptionalErrorCode ec = throws()) const;
151
152 // Static helper methods
153
165 static size_t requiredBufferSize(SampleFormat fmt, int nbChannels, int nbSamples, int align, OptionalErrorCode ec = throws());
178 static size_t requiredBufferSize(SampleFormat fmt, int nbChannels, int nbSamples, int align, int &lineSize, OptionalErrorCode ec = throws());
179
192 static void fillArrays(uint8_t **audioData,
193 int *linesize,
194 const uint8_t *buf,
195 int nbChannels,
196 int nbSamples,
197 SampleFormat fmt,
198 int align,
200
213 static void setSilence(uint8_t **audioData,
214 int offset,
215 int nbSamples,
216 int nbChannels,
217 SampleFormat fmt);
218
219#if 0
220 // WARNING: use this function only if required API call expect data allocated with av_alloc() proc families.
221 // You must free allocated data with av_free(&audioData[0]);
222 static void samplesAlloc(uint8_t **audioData,
223 int *linesize,
224 int nbChannels,
225 int nbSamples,
226 SampleFormat fmt,
227 int align,
228 OptionalErrorCode ec = throws());
229#endif
230
231};
232
233} // namespace av
234
Error codes, error categories and the OptionalErrorCode convention.
Carries the caller's choice between exceptions and error codes.
Definition averror.h:96
static void setSilence(uint8_t **audioData, int offset, int nbSamples, int nbChannels, SampleFormat fmt)
Write silence into a buffer.
SampleFormat planarSampleFormat() const noexcept
The planar variant of this format.
const char * name(OptionalErrorCode ec=throws()) const
Name of the format.
SampleFormat()=default
Create an unset format, equivalent to AV_SAMPLE_FMT_NONE.
size_t requiredBufferSize(int nbChannels, int nbSamples, int align, OptionalErrorCode ec=throws()) const
Size of a buffer for the given amount of audio.
SampleFormat packedSampleFormat() const noexcept
The packed variant of this format.
SampleFormat(const char *name) noexcept
Look a sample format up by name.
size_t bitsPerSample(OptionalErrorCode ec=throws()) const
Bits per sample of one channel.
bool isPlanar() const noexcept
Whether the channels are stored in separate planes.
PixSampleFmtWrapper< SampleFormat, AVSampleFormat > Parent
The wrapper this type builds on.
Definition sampleformat.h:51
SampleFormat(const std::string &name) noexcept
Look a sample format up by name.
static void fillArrays(uint8_t **audioData, int *linesize, const uint8_t *buf, int nbChannels, int nbSamples, SampleFormat fmt, int align, OptionalErrorCode ec=throws())
Point the per-channel data pointers at a contiguous buffer.
size_t bytesPerSample(OptionalErrorCode ec=throws()) const
Bytes needed for one sample of one channel.
SampleFormat alternativeSampleFormat(bool isPlanar) const noexcept
The same numeric type in the requested layout.
Alignment
Alignment expected from a sample buffer.
Definition sampleformat.h:43
@ AlignDefault
Align each line to the interval FFmpeg prefers.
Definition sampleformat.h:45
@ AlignNone
Do not align: lines follow each other directly.
Definition sampleformat.h:47
FFmpeg types re-exported for the public API and small value wrappers.
Root namespace of the library.
Definition audioresampler.h:19
OptionalErrorCode throws()
Helper to construct null OptionalErrorCode object.
Definition averror.h:310