ASAPCabinetFE
 
Loading...
Searching...
No Matches
video_decoder.h
Go to the documentation of this file.
1#ifndef VIDEO_DECODER_H
2#define VIDEO_DECODER_H
3
4#include <SDL2/SDL.h>
5extern "C" {
6#include <libavutil/buffer.h>
7#include <libavutil/pixfmt.h>
8}
9#include <chrono>
10#include <string>
11
12// Forward declarations for FFmpeg structs
13struct AVFormatContext;
14struct AVCodecContext;
15struct AVFrame;
16struct AVPacket;
17struct SwsContext;
18
19class FFmpegPlayer; // Forward declaration
20
39public:
48
55
67 bool setup(AVFormatContext* formatContext, SDL_Renderer* renderer, int width, int height);
68
74 void play();
75
81 void stop();
82
88 void update();
89
95 SDL_Texture* getTexture() const;
96
104 bool decodeVideoFrame();
105
111 void updateTexture();
112
118 void flush();
119
125 void resetPlaybackTimes();
126
127private:
128 friend class FFmpegPlayer; // Allow FFmpegPlayer to access private members
129 FFmpegPlayer* player_;
130 AVCodecContext* videoCodecContext_;
131 SDL_Renderer* renderer_;
132 int width_;
133 int height_;
134 AVFrame* videoFrame_;
135 AVFrame* rgbFrame_;
136 AVPacket* videoPacket_;
137 SwsContext* swsContext_;
138 int videoStreamIndex_;
139 uint8_t* rgbBuffer_;
140 SDL_Texture* texture_;
141 double videoClock_;
142 std::chrono::high_resolution_clock::time_point lastFrameTime_;
143 std::chrono::high_resolution_clock::time_point playbackStartTime_;
144 bool needsReset_;
145 AVBufferRef* hwDeviceCtx_ = nullptr;
146 AVPixelFormat expectedSwFormat_ = AV_PIX_FMT_NONE;
147
153 void cleanup();
154
155};
156
157#endif // VIDEO_DECODER_H
Implements video and audio playback using FFmpeg.
Definition ffmpeg_player.h:30
Decodes and renders video frames using FFmpeg and SDL.
Definition video_decoder.h:38
void resetPlaybackTimes()
Resets playback timing variables.
Definition video_decoder.cpp:419
void stop()
Stops video playback.
Definition video_decoder.cpp:210
void updateTexture()
Updates the SDL texture with the current RGB frame data.
Definition video_decoder.cpp:382
void play()
Starts video playback.
Definition video_decoder.cpp:205
SDL_Texture * getTexture() const
Retrieves the current video texture.
Definition video_decoder.cpp:253
void flush()
Flushes the decoder buffers.
Definition video_decoder.cpp:412
~VideoDecoder()
Destroys the VideoDecoder instance and cleans up resources.
Definition video_decoder.cpp:27
void update()
Updates the video frame based on playback timing.
Definition video_decoder.cpp:215
bool decodeVideoFrame()
Decodes the next video frame.
Definition video_decoder.cpp:257
bool setup(AVFormatContext *formatContext, SDL_Renderer *renderer, int width, int height)
Sets up the video decoder with format context and renderer.
Definition video_decoder.cpp:32