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 |
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.
| AudioDecoder::AudioDecoder | ( | FFmpegPlayer * | player | ) |
Constructs an AudioDecoder instance.
Initializes the decoder with a reference to the parent FFmpegPlayer.
| player | Pointer to the FFmpegPlayer instance. |
| AudioDecoder::~AudioDecoder | ( | ) |
Destroys the AudioDecoder instance and cleans up resources.
Ensures all allocated FFmpeg and SDL resources are properly freed.
| bool AudioDecoder::decodeAudioFrame | ( | ) |
Decodes the next audio frame.
Attempts to read and decode an audio packet into a frame.
Here is the call graph for this function:
Here is the caller graph for this function:| 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.
| stream | Pointer to the audio buffer. |
| len | Length of the audio buffer in bytes. |
Here is the call graph for this function:
Here is the caller graph for this function:| void AudioDecoder::flush | ( | ) |
Flushes the decoder buffers.
Clears any pending frames in the codec context.
Here is the caller graph for this function:| void AudioDecoder::play | ( | ) |
Starts audio playback.
Unpauses the SDL audio device to begin playback.
Here is the caller graph for this function:
|
static |
SDL audio callback function.
Static callback invoked by SDL to fill the audio buffer.
| userdata | Pointer to the AudioDecoder instance. |
| stream | Pointer to the audio buffer. |
| len | Length of the audio buffer in bytes. |
Here is the call graph for this function:
Here is the caller graph for this function:| void AudioDecoder::setMute | ( | bool | mute | ) |
Toggles the mute state.
| mute | True to mute, false to unmute. |
Here is the caller graph for this function:| 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.
| formatContext | Pointer to the AVFormatContext containing the audio stream. |
Here is the call graph for this function:
Here is the caller graph for this function:| void AudioDecoder::setVolume | ( | float | volume | ) |
Sets the audio volume.
Applies a logarithmic scale to the input volume (0-100) and updates the current volume.
| volume | Volume level (0-100). |
Here is the caller graph for this function:| 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:| 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: