Home
AV module

AudioPacketEncoder

PacketProcessor that encodes raw audio samples (PlanarAudioPacket or AudioPacket) into compressed packets via AudioEncoder.

AudioPacketEncoder

#include <icy/av/audiopacketencoder.h>
class AudioPacketEncoder

Defined in src/av/include/icy/av/audiopacketencoder.h:44

Inherits: AudioEncoder, PacketProcessor

PacketProcessor that encodes raw audio samples (PlanarAudioPacket or AudioPacket) into compressed packets via AudioEncoder.

Drop this into a PacketStream between a source that emits raw audio (e.g. MediaCapture) and a sink that expects encoded data (e.g. WebRtcTrackSender or MultiplexPacketEncoder).

Example:

auto encoder = std::make_sharedav::AudioPacketEncoder(); encoder->oparams = av::AudioCodec("opus", "libopus", 2, 48000);

PacketStream stream; stream.attachSource(capture); stream.attach(encoder, 1, true); stream.attach(&webrtcSender, 5, false); stream.start();

List of all members

NameKindOwner
PacketStreamfriendDeclared here
AudioPacketEncoderfunctionDeclared here
~AudioPacketEncoderfunctionDeclared here
AudioPacketEncoderfunctionDeclared here
operator=functionDeclared here
processfunctionDeclared here
acceptsfunctionDeclared here
_initializedvariableDeclared here
_mutexvariableDeclared here
onStreamStateChangefunctionDeclared here
fifovariableInherited from AudioEncoder
formatvariableInherited from AudioEncoder
nextOutputPtsvariableInherited from AudioEncoder
AudioEncoderfunctionInherited from AudioEncoder
~AudioEncoderfunctionInherited from AudioEncoder
createfunctionInherited from AudioEncoder
closefunctionInherited from AudioEncoder
encodefunctionInherited from AudioEncoder
encodefunctionInherited from AudioEncoder
encodefunctionInherited from AudioEncoder
flushfunctionInherited from AudioEncoder
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
PacketProcessorfunctionInherited from PacketProcessor
processfunctionInherited from PacketProcessor
acceptsfunctionInherited from PacketProcessor
operator<<functionInherited from PacketProcessor
PacketStreamAdapterfunctionInherited from PacketStreamAdapter
~PacketStreamAdapterfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
emitfunctionInherited from PacketStreamAdapter
getEmitterfunctionInherited from PacketStreamAdapter
retentionfunctionInherited from PacketStreamAdapter
onStreamStateChangefunctionInherited from PacketStreamAdapter
_emittervariableInherited from PacketStreamAdapter
PacketStreamAdapterfunctionInherited from PacketStreamAdapter
operator=functionInherited from PacketStreamAdapter
PacketStreamAdapterfunctionInherited from PacketStreamAdapter
operator=functionInherited from PacketStreamAdapter

Inherited from AudioEncoder

KindNameDescription
variablefifo
variableformat
variablenextOutputPtsRunning 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.
functionAudioEncoderConstruct an encoder, optionally tied to an existing muxer context.
function~AudioEncoder noexcept override
functioncreate virtual overrideInitialise the AVCodecContext using oparams. Adds an audio stream to format if one was provided at construction.
functionclose virtual overrideClose and free the AVCodecContext, FIFO buffer, and associated resources.
functionencode virtual overrideEncode interleaved audio samples.
functionencode virtual overrideEncode planar audio samples.
functionencode virtual overrideEncode a single AVFrame (typically from a decoder or resampler).
functionflush virtual overrideFlush remaining packets to be encoded. This method should be called once before stream closure.

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.

Inherited from PacketProcessor

KindNameDescription
functionPacketProcessor inline
functionprocess virtualThis method performs processing on the given packet and emits the result.
functionaccepts virtual inlineThis method ensures compatibility with the given packet type. Return false to reject the packet.
functionoperator<< virtual inlineStream operator alias for process()

Inherited from PacketStreamAdapter

KindNameDescription
functionPacketStreamAdapterConstruct the adapter, binding it to the given packet signal.
function~PacketStreamAdapter virtual inline
functionemit virtualEmit a mutable raw buffer as a packet.
functionemit virtualEmit a read-only raw buffer as a packet (data is copied internally).
functionemit virtualEmit a string as a packet (data is copied internally).
functionemit virtualEmit a flag-only packet carrying no payload data.
functionemit virtualEmit an existing packet directly onto the outgoing signal.
functiongetEmitterReturns a reference to the outgoing packet signal.
functionretention virtual constReturns how this adapter treats incoming packet lifetime. Most adapters are synchronous and therefore only borrow the packet for the current call chain. Queue-style adapters override this to advertise that they clone before deferred use. Callers may treat the first adapter reporting Cloned or Retained as the explicit ownership boundary in the stream graph.
functiononStreamStateChange virtual inlineCalled by the PacketStream to notify when the internal Stream state changes. On receiving the Stopped state, it is the responsibility of the adapter to have ceased all outgoing packet transmission, especially in multi-thread scenarios.
variable_emitter
functionPacketStreamAdapterNonCopyable and NonMovable.
functionoperator=Deleted assignment operator.
functionPacketStreamAdapterDeleted constructor.
functionoperator=Deleted assignment operator.

Friends

NameDescription
PacketStream

PacketStream

friend class PacketStream

Defined in src/av/include/icy/av/audiopacketencoder.h:64

Public Methods

ReturnNameDescription
AudioPacketEncoder
AudioPacketEncoderDeleted constructor.
voidprocess virtual overrideProcess an AudioPacket or PlanarAudioPacket from the stream. Encodes the samples and emits the resulting compressed packet.
boolaccepts virtual overrideAccept AudioPacket and PlanarAudioPacket types.

AudioPacketEncoder

AudioPacketEncoder(AVFormatContext * format = nullptr)

Defined in src/av/include/icy/av/audiopacketencoder.h:48


AudioPacketEncoder

AudioPacketEncoder(const AudioPacketEncoder &) = delete

Defined in src/av/include/icy/av/audiopacketencoder.h:51

Deleted constructor.


process

virtual override

virtual void process(IPacket & packet) override

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

Process an AudioPacket or PlanarAudioPacket from the stream. Encodes the samples and emits the resulting compressed packet.

Reimplements

accepts

virtual override

virtual bool accepts(IPacket * packet) override

Defined in src/av/include/icy/av/audiopacketencoder.h:59

Accept AudioPacket and PlanarAudioPacket types.

Reimplements

Protected Attributes

ReturnNameDescription
bool_initialized
std::mutex_mutex

_initialized

bool _initialized = false

Defined in src/av/include/icy/av/audiopacketencoder.h:66


_mutex

std::mutex _mutex

Defined in src/av/include/icy/av/audiopacketencoder.h:67

Protected Methods

ReturnNameDescription
voidonStreamStateChange virtual overrideCalled by the PacketStream to notify when the internal Stream state changes. On receiving the Stopped state, it is the responsibility of the adapter to have ceased all outgoing packet transmission, especially in multi-thread scenarios.

onStreamStateChange

virtual override

virtual void onStreamStateChange(const PacketStreamState &) override

Defined in src/av/include/icy/av/audiopacketencoder.h:62

Called by the PacketStream to notify when the internal Stream state changes. On receiving the Stopped state, it is the responsibility of the adapter to have ceased all outgoing packet transmission, especially in multi-thread scenarios.

Reimplements