MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::IO::AudioEncodeContext Class Reference

RAII owner of one audio stream's encoder, resampler, and sample FIFO. More...

#include <AudioEncodeContext.hpp>

+ Collaboration diagram for MayaFlux::IO::AudioEncodeContext:

Public Member Functions

 AudioEncodeContext ()=default
 
 AudioEncodeContext (AudioEncodeContext &&)=delete
 
 AudioEncodeContext (const AudioEncodeContext &)=delete
 
void close ()
 Release all owned resources.
 
bool drain (FFmpegMuxContext &mux)
 Flush the FIFO remainder and encoder internal delay to the mux.
 
bool encode_frames (std::span< const double > interleaved, uint32_t num_frames, FFmpegMuxContext &mux)
 Encode a block of interleaved double-precision PCM frames.
 
bool is_valid () const
 True if codec, resampler, and FIFO are all ready.
 
const std::string & last_error () const
 
bool open (FFmpegMuxContext &mux, uint32_t sample_rate, uint32_t channels, AVCodecID codec_id)
 Open the encoder and register an audio stream in the mux context.
 
AudioEncodeContextoperator= (AudioEncodeContext &&)=delete
 
AudioEncodeContextoperator= (const AudioEncodeContext &)=delete
 
 ~AudioEncodeContext ()
 

Public Attributes

AVCodecContext * codec_context {}
 Owned; freed in destructor.
 
AVAudioFifo * fifo {}
 Owned; freed in destructor.
 
uint32_t m_channels {}
 
uint32_t m_sample_rate {}
 
int m_stream_index { -1 }
 
AVStream * stream {}
 Owned by mux; pointer cached here.
 
SwrContext * swr_context {}
 Owned; freed in destructor.
 

Private Member Functions

bool drain_packets (FFmpegMuxContext &mux)
 Drain all packets currently available from the encoder into mux.
 
bool send_fifo_frame (FFmpegMuxContext &mux, bool pad_to_frame_size)
 Pull one frame from the FIFO and send it to the encoder.
 
bool setup_fifo ()
 
bool setup_resampler ()
 

Private Attributes

std::string m_last_error
 
int64_t m_pts = 0
 

Detailed Description

RAII owner of one audio stream's encoder, resampler, and sample FIFO.

Encapsulates all audio-stream-specific FFmpeg objects on the write path:

  • AVCodecContext for the selected or inferred encoder
  • SwrContext converting AV_SAMPLE_FMT_DBL (engine canonical) to the encoder's native sample format
  • AVAudioFifo absorbing arbitrary-size input chunks and emitting fixed-size frames required by block-aligned encoders (AAC: 1024, Vorbis: variable)
  • AVStream registered inside the supplied FFmpegMuxContext

Does NOT own AVFormatContext — that belongs to FFmpegMuxContext.

Destruction order (enforced in destructor): fifo → swr_context → codec_context The associated FFmpegMuxContext must outlive this object.

Open sequence:

  1. FFmpegMuxContext::open()
  2. AudioEncodeContext::open() ← adds stream, configures codec+swr+fifo
  3. FFmpegMuxContext::write_header()
  4. encode_frames() loop
  5. drain() ← flushes fifo remainder + encoder delay
  6. FFmpegMuxContext::close() ← writes trailer

Definition at line 40 of file AudioEncodeContext.hpp.


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