avcpp 3.2.1
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
av::SampleFormat Class Reference

The SampleFormat class is a simple proxy class for AVSampleFormat. More...

#include <sampleformat.h>

Inheritance diagram for av::SampleFormat:

Public Types

enum  Alignment { AlignDefault = 0 , AlignNone = 1 }
 Alignment expected from a sample buffer. More...
using Parent = PixSampleFmtWrapper<SampleFormat, AVSampleFormat>
 The wrapper this type builds on.

Public Member Functions

 SampleFormat ()=default
 Create an unset format, equivalent to AV_SAMPLE_FMT_NONE.
 SampleFormat (const char *name) noexcept
 Look a sample format up by name.
 SampleFormat (const std::string &name) noexcept
 Look a sample format up by name.
const char * name (OptionalErrorCode ec=throws()) const
 Name of the format.
SampleFormat alternativeSampleFormat (bool isPlanar) const noexcept
 The same numeric type in the requested layout.
SampleFormat packedSampleFormat () const noexcept
 The packed variant of this format.
SampleFormat planarSampleFormat () const noexcept
 The planar variant of this format.
bool isPlanar () const noexcept
 Whether the channels are stored in separate planes.
size_t bytesPerSample (OptionalErrorCode ec=throws()) const
 Bytes needed for one sample of one channel.
size_t bitsPerSample (OptionalErrorCode ec=throws()) const
 Bits per sample of one channel.
size_t requiredBufferSize (int nbChannels, int nbSamples, int align, OptionalErrorCode ec=throws()) const
 Size of a buffer for the given amount of audio.
size_t requiredBufferSize (int nbChannels, int nbSamples, int align, int &lineSize, OptionalErrorCode ec=throws()) const
 Size of a buffer for the given amount of audio, and its line size.
Public Member Functions inherited from PixSampleFmtWrapper< SampleFormat, AVSampleFormat >
constexpr PixSampleFmtWrapper ()=default
 Create a wrapper holding NoneValue.
constexpr PixSampleFmtWrapper (AVSampleFormat fmt) noexcept
 Wrap a raw enum value.
 operator AVSampleFormat () const noexcept
 Implicit conversion to the FFmpeg enum.
AVSampleFormat get () const noexcept
 The stored enum value.
 operator AVSampleFormat & () noexcept
 Mutable access to the stored value.
SampleFormat & operator= (AVSampleFormat fmt) noexcept
 Assign a raw enum value.
void set (AVSampleFormat fmt) noexcept
 Assign a raw enum value.
 operator AVSampleFormat () const noexcept
 Implicit conversion to the FFmpeg enum.
 operator AVSampleFormat & () noexcept
 Mutable access to the stored value.

Static Public Member Functions

static size_t requiredBufferSize (SampleFormat fmt, int nbChannels, int nbSamples, int align, OptionalErrorCode ec=throws())
 Size of a buffer for the given amount of audio.
static size_t requiredBufferSize (SampleFormat fmt, int nbChannels, int nbSamples, int align, int &lineSize, OptionalErrorCode ec=throws())
 Size of a buffer for the given amount of audio, and its line size.
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.
static void setSilence (uint8_t **audioData, int offset, int nbSamples, int nbChannels, SampleFormat fmt)
 Write silence into a buffer.

Additional Inherited Members

Protected Attributes inherited from PixSampleFmtWrapper< SampleFormat, AVSampleFormat >
AVSampleFormat m_fmt
 The stored enum value.

Detailed Description

It allows to quckly ask some info about sample format. Only base one is provided. Audio sample format descriptor.

Describes how samples of one channel are stored: the numeric type, the interleaving, and therefore how much memory a buffer needs.

Member Enumeration Documentation

◆ Alignment

The values mirror the align argument of the av_samples_* helpers.

Enumerator
AlignDefault 

Align each line to the interval FFmpeg prefers.

AlignNone 

Do not align: lines follow each other directly.

Constructor & Destructor Documentation

◆ SampleFormat() [1/2]

av::SampleFormat::SampleFormat ( const char * name)
explicitnoexcept
Parameters
namethe name FFmpeg uses, for example "s16"

◆ SampleFormat() [2/2]

av::SampleFormat::SampleFormat ( const std::string & name)
explicitnoexcept
Parameters
namethe name FFmpeg uses, for example "s16"

Member Function Documentation

◆ alternativeSampleFormat()

SampleFormat av::SampleFormat::alternativeSampleFormat ( bool isPlanar) const
noexcept
Parameters
isPlanartrue for a planar format, false for a packed one
Returns
the matching format, or an unset one when there is no such pair

◆ bitsPerSample()

size_t av::SampleFormat::bitsPerSample ( OptionalErrorCode ec = throws()) const

Unlike bytesPerSample(), this reports the stored depth of the type, so a 24-bit sample in a 32-bit container reports 24.

Parameters
echolder for the error code
Returns
the bit depth

◆ bytesPerSample()

size_t av::SampleFormat::bytesPerSample ( OptionalErrorCode ec = throws()) const
Parameters
echolder for the error code
Returns
the size in bytes

◆ fillArrays()

void av::SampleFormat::fillArrays ( uint8_t ** audioData,
int * linesize,
const uint8_t * buf,
int nbChannels,
int nbSamples,
SampleFormat fmt,
int align,
OptionalErrorCode ec = throws() )
static
Parameters
audioDataarray that receives one pointer per plane
linesizearray that receives the line size per plane
bufthe buffer to split
nbChannelsnumber of channels
nbSamplesnumber of samples per channel
fmtsample format
alignan Alignment value
echolder for the error code

◆ isPlanar()

bool av::SampleFormat::isPlanar ( ) const
noexcept
Returns
true for planar formats

◆ name()

const char * av::SampleFormat::name ( OptionalErrorCode ec = throws()) const
Parameters
echolder for the error code; an unset format reports an error
Returns
a static string owned by FFmpeg

◆ packedSampleFormat()

SampleFormat av::SampleFormat::packedSampleFormat ( ) const
noexcept
Returns
the packed format, or the same value when it already is packed

◆ planarSampleFormat()

SampleFormat av::SampleFormat::planarSampleFormat ( ) const
noexcept
Returns
the planar format, or the same value when it already is planar

◆ requiredBufferSize() [1/4]

size_t av::SampleFormat::requiredBufferSize ( int nbChannels,
int nbSamples,
int align,
int & lineSize,
OptionalErrorCode ec = throws() ) const
Parameters
nbChannelsnumber of channels
nbSamplesnumber of samples per channel
alignan Alignment value
lineSizereceives the size of one line in bytes
echolder for the error code
Returns
the required size in bytes

◆ requiredBufferSize() [2/4]

size_t av::SampleFormat::requiredBufferSize ( int nbChannels,
int nbSamples,
int align,
OptionalErrorCode ec = throws() ) const
Parameters
nbChannelsnumber of channels
nbSamplesnumber of samples per channel
alignan Alignment value
echolder for the error code
Returns
the required size in bytes

◆ requiredBufferSize() [3/4]

size_t av::SampleFormat::requiredBufferSize ( SampleFormat fmt,
int nbChannels,
int nbSamples,
int align,
int & lineSize,
OptionalErrorCode ec = throws() )
static
Parameters
fmtsample format
nbChannelsnumber of channels
nbSamplesnumber of samples per channel
alignan Alignment value
lineSizereceives the size of one line in bytes
echolder for the error code
Returns
the required size in bytes

◆ requiredBufferSize() [4/4]

size_t av::SampleFormat::requiredBufferSize ( SampleFormat fmt,
int nbChannels,
int nbSamples,
int align,
OptionalErrorCode ec = throws() )
static
Parameters
fmtsample format
nbChannelsnumber of channels
nbSamplesnumber of samples per channel
alignan Alignment value
echolder for the error code
Returns
the required size in bytes

◆ setSilence()

void av::SampleFormat::setSilence ( uint8_t ** audioData,
int offset,
int nbSamples,
int nbChannels,
SampleFormat fmt )
static

The silent value depends on the format: zero for unsigned samples and for floating point, the middle of the range for signed ones.

Parameters
audioDataper-plane data pointers
offsetoffset in bytes to start at
nbSamplesnumber of samples per channel to silence
nbChannelsnumber of channels
fmtsample format

The documentation for this class was generated from the following file: