ASAPCabinetFE
 
Loading...
Searching...
No Matches
AudioDecoder Class Reference

Decodes and plays audio streams using FFmpeg and SDL. More...

#include <audio_decoder.h>

+ Collaboration diagram for AudioDecoder:

Public Member Functions

 AudioDecoder (FFmpegPlayer *player)
 Constructs an AudioDecoder instance.
 
 ~AudioDecoder ()
 Destroys the AudioDecoder instance and cleans up resources.
 
bool setup (AVFormatContext *formatContext)
 Sets up the audio decoder with a format context.
 
void play ()
 Starts audio playback.
 
void stop ()
 Stops audio playback.
 
void update ()
 Updates the audio buffer by decoding frames.
 
bool decodeAudioFrame ()
 Decodes the next audio frame.
 
void fillAudioStream (Uint8 *stream, int len)
 Fills the SDL audio stream buffer with decoded audio.
 
void setVolume (float volume)
 Sets the audio volume.
 
void setMute (bool mute)
 Toggles the mute state.
 
void flush ()
 Flushes the decoder buffers.
 

Static Public Member Functions

static void SDLAudioCallback (void *userdata, Uint8 *stream, int len)
 SDL audio callback function.
 

Friends

class FFmpegPlayer
 

Detailed Description

Decodes and plays audio streams using FFmpeg and SDL.

This class manages the decoding of audio streams from an AVFormatContext, resamples audio to a compatible format, and buffers it for playback via SDL audio callbacks. It works with FFmpegPlayer and handles volume and mute settings.

Constructor & Destructor Documentation

◆ AudioDecoder()

AudioDecoder::AudioDecoder ( FFmpegPlayer player)

Constructs an AudioDecoder instance.

Initializes the decoder with a reference to the parent FFmpegPlayer.

Parameters
playerPointer to the FFmpegPlayer instance.

◆ ~AudioDecoder()

AudioDecoder::~AudioDecoder ( )

Destroys the AudioDecoder instance and cleans up resources.

Ensures all allocated FFmpeg and SDL resources are properly freed.

Member Function Documentation

◆ decodeAudioFrame()

bool AudioDecoder::decodeAudioFrame ( )

Decodes the next audio frame.

Attempts to read and decode an audio packet into a frame.

Returns
True if a valid frame was decoded, false otherwise.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fillAudioStream()

void AudioDecoder::fillAudioStream ( Uint8 *  stream,
int  len 
)

Fills the SDL audio stream buffer with decoded audio.

Applies volume and mute settings to the audio data.

Parameters
streamPointer to the audio buffer.
lenLength of the audio buffer in bytes.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flush()

void AudioDecoder::flush ( )

Flushes the decoder buffers.

Clears any pending frames in the codec context.

+ Here is the caller graph for this function:

◆ play()

void AudioDecoder::play ( )

Starts audio playback.

Unpauses the SDL audio device to begin playback.

+ Here is the caller graph for this function:

◆ SDLAudioCallback()

void AudioDecoder::SDLAudioCallback ( void *  userdata,
Uint8 *  stream,
int  len 
)
static

SDL audio callback function.

Static callback invoked by SDL to fill the audio buffer.

Parameters
userdataPointer to the AudioDecoder instance.
streamPointer to the audio buffer.
lenLength of the audio buffer in bytes.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMute()

void AudioDecoder::setMute ( bool  mute)

Toggles the mute state.

Parameters
muteTrue to mute, false to unmute.
+ Here is the caller graph for this function:

◆ setup()

bool AudioDecoder::setup ( AVFormatContext *  formatContext)

Sets up the audio decoder with a format context.

Configures the decoder with the audio stream and initializes SDL audio device.

Parameters
formatContextPointer to the AVFormatContext containing the audio stream.
Returns
True on successful setup, false otherwise.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setVolume()

void AudioDecoder::setVolume ( float  volume)

Sets the audio volume.

Applies a logarithmic scale to the input volume (0-100) and updates the current volume.

Parameters
volumeVolume level (0-100).
+ Here is the caller graph for this function:

◆ stop()

void AudioDecoder::stop ( )

Stops audio playback.

Pauses the SDL audio device and flushes the audio FIFO.

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

◆ update()

void AudioDecoder::update ( )

Updates the audio buffer by decoding frames.

Ensures the audio FIFO has sufficient samples for continuous playback.

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

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