Home
AV module

AudioEncoder

Encodes raw audio samples into a compressed format.

AudioEncoder

#include <icy/av/audioencoder.h>
struct AudioEncoder

Defined in src/av/include/icy/av/audioencoder.h:37

Inherits: AudioContext Subclassed by: AudioPacketEncoder

Encodes raw audio samples into a compressed format.

List of all members

NameKindOwner
fifovariableDeclared here
formatvariableDeclared here
nextOutputPtsvariableDeclared here
AudioEncoderfunctionDeclared here
~AudioEncoderfunctionDeclared here
createfunctionDeclared here
closefunctionDeclared here
encodefunctionDeclared here
encodefunctionDeclared here
encodefunctionDeclared here
flushfunctionDeclared here
emittervariableInherited from AudioContext
iparamsvariableInherited from AudioContext
oparamsvariableInherited from AudioContext
streamvariableInherited from AudioContext
ctxvariableInherited from AudioContext
codecvariableInherited from AudioContext
framevariableInherited from AudioContext
resamplervariableInherited from AudioContext
outputFrameSizevariableInherited from AudioContext
timevariableInherited from AudioContext
ptsvariableInherited from AudioContext
secondsvariableInherited from AudioContext
errorvariableInherited from AudioContext
AudioContextfunctionInherited from AudioContext
~AudioContextfunctionInherited from AudioContext
AudioContextfunctionInherited from AudioContext
operator=functionInherited from AudioContext
AudioContextfunctionInherited from AudioContext
operator=functionInherited from AudioContext
createfunctionInherited from AudioContext
openfunctionInherited from AudioContext
closefunctionInherited from AudioContext
decodefunctionInherited from AudioContext
encodefunctionInherited from AudioContext
encodefunctionInherited from AudioContext
encodefunctionInherited from AudioContext
flushfunctionInherited from AudioContext
recreateResamplerfunctionInherited from AudioContext

Inherited from AudioContext

KindNameDescription
variableemitter
variableiparamsinput parameters
variableoparamsoutput parameters
variablestreamencoder or decoder stream
variablectxencoder or decoder context
variablecodecencoder or decoder codec
variableframelast encoded or decoded frame
variableresampleraudio resampler
variableoutputFrameSizeencoder or decoder output frame size
variabletimestream time in codec time base
variableptslast packet pts value
variablesecondsaudio time in seconds
variableerrorerror message
functionAudioContext
function~AudioContext virtual noexcept
functionAudioContextDeleted constructor.
functionoperator=Deleted assignment operator.
functionAudioContextDeleted constructor.
functionoperator=Deleted assignment operator.
functioncreate virtualInitialise the AVCodecContext with codec-specific defaults. Implemented by AudioEncoder and AudioDecoder.
functionopen virtualOpen the codec and create the resampler if input/output parameters differ. Throws std::runtime_error if the codec context has not been created.
functionclose virtualClose the codec context, free the frame, and reset timestamps.
functiondecode virtualDecode a compressed audio packet and emit the resulting samples.
functionencode virtualEncode a buffer of interleaved audio samples.
functionencode virtualEncode a buffer of planar audio samples.
functionencode virtualEncode a single AVFrame.
functionflush virtualFlush any frames buffered inside the codec and emit remaining output.
functionrecreateResampler virtualRecreate the AudioResampler using the current iparams and oparams. Called automatically by open() when format conversion is required.

Public Attributes

ReturnNameDescription
av::AudioBufferfifo
AVFormatContext *format
int64_tnextOutputPtsRunning PTS counter for encoder output, in encoder time_base units. Anchored to the first input packet's PTS, then advanced by frame->nb_samples per encoded frame. AV_NOPTS_VALUE before anchoring.

fifo

av::AudioBuffer fifo

Defined in src/av/include/icy/av/audioencoder.h:74


format

AVFormatContext * format

Defined in src/av/include/icy/av/audioencoder.h:75


nextOutputPts

int64_t nextOutputPts = AV_NOPTS_VALUE

Defined in src/av/include/icy/av/audioencoder.h:80

Running PTS counter for encoder output, in encoder time_base units. Anchored to the first input packet's PTS, then advanced by frame->nb_samples per encoded frame. AV_NOPTS_VALUE before anchoring.

Public Methods

ReturnNameDescription
AudioEncoderConstruct an encoder, optionally tied to an existing muxer context.
voidcreate virtual overrideInitialise the AVCodecContext using oparams. Adds an audio stream to format if one was provided at construction.
voidclose virtual overrideClose and free the AVCodecContext, FIFO buffer, and associated resources.
boolencode virtual overrideEncode interleaved audio samples.
boolencode virtual overrideEncode planar audio samples.
boolencode virtual overrideEncode a single AVFrame (typically from a decoder or resampler).
voidflush virtual overrideFlush remaining packets to be encoded. This method should be called once before stream closure.

AudioEncoder

AudioEncoder(AVFormatContext * format = nullptr)

Defined in src/av/include/icy/av/audioencoder.h:41

Construct an encoder, optionally tied to an existing muxer context.

Parameters

  • format The AVFormatContext that will receive encoded packets, or nullptr for standalone use.

create

virtual override

virtual void create() override

Defined in src/av/include/icy/av/audioencoder.h:46

Initialise the AVCodecContext using oparams. Adds an audio stream to format if one was provided at construction.

Reimplements

close

virtual override

virtual void close() override

Defined in src/av/include/icy/av/audioencoder.h:49

Close and free the AVCodecContext, FIFO buffer, and associated resources.

Reimplements

encode

virtual override

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

Defined in src/av/include/icy/av/audioencoder.h:56

Encode interleaved audio samples.

Parameters

  • samples The input samples to encode.

  • numSamples The number of input samples per channel.

  • pts The input samples presentation timestamp.

Reimplements

encode

virtual override

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

Defined in src/av/include/icy/av/audioencoder.h:63

Encode planar audio samples.

Parameters

  • samples The input samples to encode.

  • numSamples The number of input samples per channel.

  • pts The input samples presentation timestamp.

Reimplements

encode

virtual override

virtual bool encode(AVFrame * iframe) override

Defined in src/av/include/icy/av/audioencoder.h:68

Encode a single AVFrame (typically from a decoder or resampler).

Parameters

  • iframe The source audio frame with all fields set.

Returns

True if an encoded packet was produced and emitted.

Reimplements

flush

virtual override

virtual void flush() override

Defined in src/av/include/icy/av/audioencoder.h:72

Flush remaining packets to be encoded. This method should be called once before stream closure.

Reimplements