AV module

AudioContext

Base context for audio encoding and decoding via FFmpeg.

AudioContext

#include <icy/av/audiocontext.h>

Subclassed by: AudioDecoder, AudioEncoder

Base context for audio encoding and decoding via FFmpeg.

Public Attributes

ReturnNameDescription
PacketSignalemitter
AudioCodeciparamsinput parameters
AudioCodecoparamsoutput parameters
AVStream *streamencoder or decoder stream
AVCodecContext *ctxencoder or decoder context
const AVCodec *codecencoder or decoder codec
AVFrame *framelast encoded or decoded frame
std::unique_ptr< AudioResampler >resampleraudio resampler
intoutputFrameSizeencoder or decoder output frame size
int64_ttimestream time in codec time base
int64_tptslast packet pts value
doublesecondsaudio time in seconds
std::stringerrorerror message

emitter

PacketSignal emitter

iparams

AudioCodec iparams

input parameters


oparams

AudioCodec oparams

output parameters


stream

AVStream * stream

encoder or decoder stream


ctx

AVCodecContext * ctx

encoder or decoder context


codec

const AVCodec * codec

encoder or decoder codec


frame

AVFrame * frame

last encoded or decoded frame


resampler

std::unique_ptr< AudioResampler > resampler

audio resampler


outputFrameSize

int outputFrameSize

encoder or decoder output frame size


time

int64_t time

stream time in codec time base


pts

int64_t pts

last packet pts value


seconds

double seconds

audio time in seconds


error

std::string error

error message

Public Methods

ReturnNameDescription
AudioContext
AudioContextDeleted constructor.
AudioContextDeleted constructor.
voidcreateInitialise the AVCodecContext with codec-specific defaults. Implemented by AudioEncoder and AudioDecoder.
voidopen virtualOpen the codec and create the resampler if input/output parameters differ. Throws std::runtime_error if the codec context has not been created.
voidclose virtualClose the codec context, free the frame, and reset timestamps.
booldecode virtualDecode a compressed audio packet and emit the resulting samples.
boolencode virtualEncode a buffer of interleaved audio samples.
boolencode virtualEncode a buffer of planar audio samples.
boolencode virtualEncode a single AVFrame.
voidflush virtualFlush any frames buffered inside the codec and emit remaining output.
boolrecreateResampler virtualRecreate the AudioResampler using the current iparams and oparams. Called automatically by open() when format conversion is required.

AudioContext

AudioContext()

AudioContext

AudioContext(const AudioContext &) = delete

Deleted constructor.


AudioContext

AudioContext(AudioContext &&) = delete

Deleted constructor.


create

void create()

Initialise the AVCodecContext with codec-specific defaults. Implemented by AudioEncoder and AudioDecoder.


open

virtual

virtual void open()

Open the codec and create the resampler if input/output parameters differ. Throws std::runtime_error if the codec context has not been created.


close

virtual

virtual void close()

Close the codec context, free the frame, and reset timestamps.


decode

virtual

virtual bool decode(AVPacket & ipacket)

Decode a compressed audio packet and emit the resulting samples.

Parameters

  • ipacket The compressed audio packet to decode.

Returns

True if one or more decoded frames were emitted, false otherwise.


encode

virtual

virtual bool encode(uint8_t * samples, int numSamples, int64_t pts)

Encode a buffer of interleaved audio samples.

Parameters

  • samples Pointer to the interleaved sample buffer.

  • numSamples Number of samples per channel.

  • pts Presentation timestamp in stream time base units.

Returns

True if an encoded packet was produced and emitted.


encode

virtual

virtual bool encode(uint8_t * samples, int numSamples, int64_t pts)

Encode a buffer of planar audio samples.

Parameters

  • samples Array of per-channel sample buffers (up to 4 planes).

  • numSamples Number of samples per channel.

  • pts Presentation timestamp in stream time base units.

Returns

True if an encoded packet was produced and emitted.


encode

virtual

virtual bool encode(AVFrame * iframe)

Encode a single AVFrame.

Parameters

  • iframe The source audio frame; must have all fields set correctly.

Returns

True if an encoded packet was produced and emitted.


flush

virtual

virtual void flush()

Flush any frames buffered inside the codec and emit remaining output.


recreateResampler

virtual

virtual bool recreateResampler()

Recreate the AudioResampler using the current iparams and oparams. Called automatically by open() when format conversion is required.

Returns

True if the resampler was successfully created.