ASAPCabinetFE
 
Loading...
Searching...
No Matches
vlc_player.h
1#ifndef VLC_PLAYER_H
2#define VLC_PLAYER_H
3
4#include "render/ivideo_player.h"
5#include <SDL2/SDL.h>
6#include <vlc/vlc.h>
7#include <string>
8
17public:
22
26 ~VlcVideoPlayer() override;
27
36 bool setup(SDL_Renderer* renderer, const std::string& path, int width, int height) override;
37
41 void play() override;
42
46 void stop() override;
47
51 void update() override;
52
57 SDL_Texture* getTexture() const override;
58
62 int getFrameCount() const;
63
64
69 bool isPlaying() const override;
70
75 void setVolume(float volume) override;
76
81 void setMute(bool mute) override;
82
83private:
87 struct VideoContext {
88 libvlc_instance_t* instance;
89 libvlc_media_player_t* player;
90 SDL_Renderer* renderer;
91 SDL_Texture* texture;
92 void* pixels;
93 int pitch;
94 int width;
95 int height;
96 SDL_mutex* mutex;
97 bool isPlaying;
98 bool frameReady; // New: Flag to indicate if a new frame is ready for texture update
99 int frameCount; // Diagnostic: count frames received from VLC
100 };
101
102 VideoContext* ctx_;
103
104
111 static void* lock([[maybe_unused]] void* data, void** pixels);
112
119 static void unlock([[maybe_unused]] void* data, [[maybe_unused]] void* id, [[maybe_unused]] void* const* pixels);
120
126 static void display([[maybe_unused]] void* data, [[maybe_unused]] void* id);
127
131 void cleanupContext();
132};
133
134#endif // VLC_PLAYER_H
Interface for a video player.
Definition ivideo_player.h:19
Concrete implementation of IVideoPlayer using VLC (libVLC).
Definition vlc_player.h:16
VlcVideoPlayer()
Constructs a VlcVideoPlayer instance.
Definition vlc_player.cpp:11
void stop() override
Stops video playback.
Definition vlc_player.cpp:201
SDL_Texture * getTexture() const override
Retrieves the current video frame as an SDL_Texture.
Definition vlc_player.cpp:245
int getFrameCount() const
Returns the number of frames received from VLC (diagnostic).
Definition vlc_player.cpp:249
void setMute(bool mute) override
Sets the mute state for the video's audio track.
Definition vlc_player.cpp:272
void play() override
Starts video playback.
Definition vlc_player.cpp:187
bool isPlaying() const override
Checks if the video is currently playing.
Definition vlc_player.cpp:253
void setVolume(float volume) override
Sets the volume for the video's audio track.
Definition vlc_player.cpp:261
bool setup(SDL_Renderer *renderer, const std::string &path, int width, int height) override
Sets up the VLC video player with the given renderer, path, and dimensions.
Definition vlc_player.cpp:88
~VlcVideoPlayer() override
Destroys the VlcVideoPlayer instance and cleans up VLC resources.
Definition vlc_player.cpp:13
void update() override
Updates the video frame and texture.
Definition vlc_player.cpp:212