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

One buffer of decoded audio samples. More...

#include <frame.h>

Inheritance diagram for av::AudioSamples:

Public Member Functions

 AudioSamples ()=default
 Create an invalid buffer.
 AudioSamples (SampleFormat sampleFormat, int samplesCount, uint64_t channelLayout, int sampleRate, int align=SampleFormat::AlignDefault)
 Allocate an empty buffer with the given layout.
 AudioSamples (const uint8_t *data, size_t size, SampleFormat sampleFormat, int samplesCount, uint64_t channelLayout, int sampleRate, int align=SampleFormat::AlignDefault)
 Copy external sample data into a buffer.
 AudioSamples (const AudioSamples &other)
 Copy constructor: references the same sample buffer.
 AudioSamples (AudioSamples &&other)
 Move constructor.
AudioSamples & operator= (const AudioSamples &rhs)
 Copy assignment: references the buffer of the other samples.
AudioSamples & operator= (AudioSamples &&rhs)
 Move assignment.
int init (SampleFormat sampleFormat, int samplesCount, uint64_t channelLayout, int sampleRate, int align=SampleFormat::AlignDefault)
 Allocate the buffer storage.
SampleFormat sampleFormat () const
 Sample format of the buffer.
int samplesCount () const
 Number of samples per channel.
int channelsCount () const
 Number of audio channels.
uint64_t channelsLayout () const
 Channel layout as a bit mask.
int sampleRate () const
 Sample rate of the buffer.
size_t sampleBitDepth (OptionalErrorCode ec=throws()) const
 Number of bits per sample.
bool isPlanar () const
 Whether the channels are stored in separate planes.
std::string channelsLayoutString () const
 Human-readable name of the channel layout.
Public Member Functions inherited from av::Frame< AudioSamples >
 FrameCommon ()
 Create an invalid frame.
 FrameCommon (const AVFrame *frame)
 Copy the frame metadata into a new wrapper.
 FrameCommon (const FrameCommon &other)
 Copy constructor: references the same buffer.
 FrameCommon (FrameCommon &&other)
 Move constructor.
AudioSamples clone (size_t align=1) const
 Deep copy of the frame.
Public Member Functions inherited from av::FrameCommon
 FrameCommon ()
 Create an invalid frame.
 FrameCommon (const AVFrame *frame)
 Copy the frame metadata into a new wrapper.
 FrameCommon (const FrameCommon &other)
 Copy constructor: references the same buffer.
 FrameCommon (FrameCommon &&other)
 Move constructor.
bool isReferenced () const
 Whether the frame data is reference counted.
int refCount () const
 Number of references to the frame buffer.
AVFrame * makeRef () const
 Create an independent reference to the frame.
Timestamp pts () const
 Presentation timestamp.
attribute_deprecated void setPts (int64_t pts, Rational ptsTimeBase)
 Set the timestamp and its time base at once.
void setPts (const Timestamp &ts)
 Set the timestamp.
const Rational & timeBase () const
 Time base of the frame.
void setTimeBase (const Rational &value)
 Set the time base.
int streamIndex () const
 Index of the stream the frame belongs to.
void setStreamIndex (int streamIndex)
 Set the stream index.
void setComplete (bool isComplete)
 Mark the frame as complete or incomplete.
bool isComplete () const
 Whether the frame is marked complete.
bool isValid () const
 Whether the wrapper holds a frame.
 operator bool () const
 Whether the wrapper holds a frame.
bool isHwFrame () const
 Whether the frame lives in device memory.
uint8_t * data (size_t plane=0)
 Pointer to one image or audio plane.
const uint8_t * data (size_t plane=0) const
 Pointer to one plane, read-only.
size_t size (size_t plane) const
 Size of one plane.
size_t size () const
 Total size of all planes.
void dump () const
 Print the frame layout through the FFmpeg log system.
void operator= (const FrameCommon &)=delete
 Assignment is deleted: derived classes implement it to avoid slicing.
void swap (FrameCommon &other)
 Exchange the contents of two frames.
const FrameSideData sideData (AVFrameSideDataType type) const
 Get packet side data of the given type.
FrameSideData sideData (AVFrameSideDataType type)
 Mutable access to the side data of the given type.
std::size_t sideDataCount () const noexcept
 Return count of the side data elements.
FrameSideData sideDataIndex (std::size_t index) noexcept
 Get side data element by index.
ArrayView< AVFrameSideData *, FrameSideData, std::size_t > sideData () noexcept
 Observe all packet side data via iterators.
ArrayView< const AVFrameSideData *, FrameSideData, std::size_t > sideData () const noexcept
 Read-only iteration over all side data entries.
void sideDataRemove (AVFrameSideDataType type) noexcept
 Remove and free all side data instances of the given type.
FrameSideData addSideData (AVFrameSideDataType type, std::span< const uint8_t > data, OptionalErrorCode ec=throws())
 Add side data of the given type into packet.
FrameSideData addSideData (AVFrameSideDataType type, std::span< uint8_t > data, wrap_data, OptionalErrorCode ec=throws())
 Add side data of the given type into packet.
FrameSideData addSideData (AVFrameSideDataType type, std::span< uint8_t > data, wrap_data_static, OptionalErrorCode ec=throws())
 Add side data of the given type into packet.
FrameSideData addSideData (AVFrameSideDataType type, BufferRef buf, OptionalErrorCode ec=throws())
 Add side data of the given type into packet.
FrameSideData allocateSideData (AVFrameSideDataType type, std::size_t size, OptionalErrorCode ec=throws())
 Allocate storage for the packet side data of the given type and return reference to it.
Public Member Functions inherited from FFWrapperPtr< AVFrame >
 FFWrapperPtr ()=default
 Create an empty wrapper; isNull() is true.
const AVFrame * raw () const
 Read access to the wrapped object.
void reset (AVFrame *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.

Additional Inherited Members

Static Public Member Functions inherited from av::Frame< AudioSamples >
static AudioSamples null ()
 An invalid frame of this type.
Protected Member Functions inherited from av::Frame< AudioSamples >
AudioSamples & assignOperator (const AudioSamples &rhs)
 Copy the other frame into this one.
AudioSamples & moveOperator (AudioSamples &&rhs)
 Move the other frame into this one.
Protected Member Functions inherited from av::FrameCommon
void copyInfoFrom (const FrameCommon &other)
 Copy the avcpp bookkeeping (time base, stream index, completeness).
void clone (FrameCommon &dst, size_t align=1) const
 Make a deep copy of the frame data into another frame object.
Protected Attributes inherited from av::FrameCommon
Rational m_timeBase {}
 Time base of the timestamps in this frame.
int m_streamIndex {-1}
 Index of the stream the frame belongs to; -1 when unset.
bool m_isComplete {false}
 Completeness flag, set through setComplete().
Protected Attributes inherited from FFWrapperPtr< AVFrame >
AVFrame * m_raw
 The wrapped pointer; owned by the derived class, not by this template.

Detailed Description

The samples follow the layout of their format: planar formats keep one plane per channel, packed formats interleave the channels in the first plane. isPlanar() reports which one this buffer uses.

Examples
api2-decode-audio.cpp, api2-decode-encode-audio.cpp, and api2-decode-rasample-audio.cpp.

Constructor & Destructor Documentation

◆ AudioSamples() [1/4]

av::AudioSamples::AudioSamples ( SampleFormat sampleFormat,
int samplesCount,
uint64_t channelLayout,
int sampleRate,
int align = SampleFormat::AlignDefault )
Parameters
sampleFormatsample format of the buffer
samplesCountnumber of samples per channel
channelLayoutAV_CH_LAYOUT_* mask
sampleRatesample rate in hertz
alignalignment in bytes for each plane

◆ AudioSamples() [2/4]

av::AudioSamples::AudioSamples ( const uint8_t * data,
size_t size,
SampleFormat sampleFormat,
int samplesCount,
uint64_t channelLayout,
int sampleRate,
int align = SampleFormat::AlignDefault )
Parameters
databuffer holding the samples
sizesize of the buffer in bytes
sampleFormatsample format of the data
samplesCountnumber of samples per channel
channelLayoutAV_CH_LAYOUT_* mask
sampleRatesample rate in hertz
alignalignment in bytes for each plane

◆ AudioSamples() [3/4]

av::AudioSamples::AudioSamples ( const AudioSamples & other)
Parameters
otherthe buffer to copy

◆ AudioSamples() [4/4]

av::AudioSamples::AudioSamples ( AudioSamples && other)
Parameters
otherthe buffer to move from; left invalid

Member Function Documentation

◆ channelsCount()

int av::AudioSamples::channelsCount ( ) const
Returns
the channel count, or zero for an invalid buffer
Examples
api2-decode-audio.cpp, api2-decode-encode-audio.cpp, and api2-decode-rasample-audio.cpp.

◆ channelsLayout()

uint64_t av::AudioSamples::channelsLayout ( ) const
Returns
the AV_CH_LAYOUT_* mask, or zero when it is not set

◆ channelsLayoutString()

std::string av::AudioSamples::channelsLayoutString ( ) const
Returns
a string such as "stereo", or an empty string when the layout is unknown
Examples
api2-decode-audio.cpp, api2-decode-encode-audio.cpp, and api2-decode-rasample-audio.cpp.

◆ init()

int av::AudioSamples::init ( SampleFormat sampleFormat,
int samplesCount,
uint64_t channelLayout,
int sampleRate,
int align = SampleFormat::AlignDefault )
Parameters
sampleFormatsample format of the buffer
samplesCountnumber of samples per channel
channelLayoutAV_CH_LAYOUT_* mask
sampleRatesample rate in hertz
alignalignment in bytes for each plane
Returns
zero on success, a negative FFmpeg error code otherwise

◆ isPlanar()

bool av::AudioSamples::isPlanar ( ) const
Returns
true for planar formats, false for packed ones

◆ operator=() [1/2]

AudioSamples & av::AudioSamples::operator= ( AudioSamples && rhs)
Parameters
rhsthe buffer to move from; left invalid
Returns
this buffer

◆ operator=() [2/2]

AudioSamples & av::AudioSamples::operator= ( const AudioSamples & rhs)
Parameters
rhsthe buffer to assign from
Returns
this buffer

◆ sampleBitDepth()

size_t av::AudioSamples::sampleBitDepth ( OptionalErrorCode ec = throws()) const
Parameters
echolder for the error code
Returns
the bit depth of the sample format

◆ sampleFormat()

SampleFormat av::AudioSamples::sampleFormat ( ) const
Returns
the format, or AV_SAMPLE_FMT_NONE for an invalid buffer

◆ sampleRate()

int av::AudioSamples::sampleRate ( ) const
Returns
samples per second, or zero for an invalid buffer
Examples
api2-decode-audio.cpp, api2-decode-encode-audio.cpp, and api2-decode-rasample-audio.cpp.

◆ samplesCount()

int av::AudioSamples::samplesCount ( ) const
Returns
the sample count, or zero for an invalid buffer
Examples
api2-decode-audio.cpp, api2-decode-encode-audio.cpp, and api2-decode-rasample-audio.cpp.

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