Decodes and renders video frames using FFmpeg and SDL. More...
#include <video_decoder.h>
Public Member Functions | |
VideoDecoder (FFmpegPlayer *player) | |
Constructs a VideoDecoder instance. | |
~VideoDecoder () | |
Destroys the VideoDecoder instance and cleans up resources. | |
bool | setup (AVFormatContext *formatContext, SDL_Renderer *renderer, int width, int height) |
Sets up the video decoder with format context and renderer. | |
void | play () |
Starts video playback. | |
void | stop () |
Stops video playback. | |
void | update () |
Updates the video frame based on playback timing. | |
SDL_Texture * | getTexture () const |
Retrieves the current video texture. | |
bool | decodeVideoFrame () |
Decodes the next video frame. | |
void | updateTexture () |
Updates the SDL texture with the current RGB frame data. | |
void | flush () |
Flushes the decoder buffers. | |
void | resetPlaybackTimes () |
Resets playback timing variables. | |
Friends | |
class | FFmpegPlayer |
Decodes and renders video frames using FFmpeg and SDL.
This class manages the decoding of video streams from an AVFormatContext, converts frames to RGB format using SwsContext, and updates an SDL texture for rendering. It works in conjunction with FFmpegPlayer and handles playback timing and cleanup.
VideoDecoder::VideoDecoder | ( | FFmpegPlayer * | player | ) |
Constructs a VideoDecoder instance.
Initializes the decoder with a reference to the parent FFmpegPlayer.
player | Pointer to the FFmpegPlayer instance. |
VideoDecoder::~VideoDecoder | ( | ) |
Destroys the VideoDecoder instance and cleans up resources.
Ensures all allocated FFmpeg and SDL resources are properly freed.
bool VideoDecoder::decodeVideoFrame | ( | ) |
Decodes the next video frame.
Attempts to read and decode a video packet into a frame.
void VideoDecoder::flush | ( | ) |
Flushes the decoder buffers.
Clears any pending frames in the codec context.
SDL_Texture * VideoDecoder::getTexture | ( | ) | const |
Retrieves the current video texture.
void VideoDecoder::play | ( | ) |
Starts video playback.
Resets playback timing to synchronize with the video stream.
void VideoDecoder::resetPlaybackTimes | ( | ) |
Resets playback timing variables.
Sets the video clock and timestamps to initial states.
bool VideoDecoder::setup | ( | AVFormatContext * | formatContext, |
SDL_Renderer * | renderer, | ||
int | width, | ||
int | height | ||
) |
Sets up the video decoder with format context and renderer.
Configures the decoder with the video stream, codec, and rendering parameters.
formatContext | Pointer to the AVFormatContext containing the video stream. |
renderer | Pointer to the SDL_Renderer for texture creation. |
width | Desired width of the output texture. |
height | Desired height of the output texture. |
void VideoDecoder::stop | ( | ) |
Stops video playback.
Flushes the decoder buffers to prepare for a new playback session.
void VideoDecoder::update | ( | ) |
Updates the video frame based on playback timing.
Decodes and renders the next frame if the video clock aligns with elapsed time.
void VideoDecoder::updateTexture | ( | ) |
Updates the SDL texture with the current RGB frame data.
Copies the decoded frame data to the texture for rendering.