MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ drain()

bool MayaFlux::IO::AudioEncodeContext::drain ( FFmpegMuxContext mux)

Flush the FIFO remainder and encoder internal delay to the mux.

Pads the final partial FIFO frame with silence if needed, sends it, then sends a null frame to signal EOS to the encoder and drains all buffered output packets. Call once before FFmpegMuxContext::close().

Parameters
muxMux context to receive remaining packets.
Returns
True if all remaining packets were written successfully.

Definition at line 288 of file AudioEncodeContext.cpp.

289{
290 if (!is_valid())
291 return false;
292
293 while (av_audio_fifo_size(fifo) > 0) {
294 if (!send_fifo_frame(mux, true))
295 return false;
296 }
297
298 if (avcodec_send_frame(codec_context, nullptr) < 0) {
299 m_last_error = "avcodec_send_frame(null) failed during drain";
300 return false;
301 }
302
303 return drain_packets(mux);
304}
bool is_valid() const
True if codec, resampler, and FIFO are all ready.
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.
AVCodecContext * codec_context
Owned; freed in destructor.
AVAudioFifo * fifo
Owned; freed in destructor.

References codec_context, drain_packets(), fifo, is_valid(), m_last_error, and send_fifo_frame().

Referenced by MayaFlux::IO::SoundFileWriter::worker_loop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: