diff options
Diffstat (limited to 'include/Video.hpp')
-rw-r--r-- | include/Video.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/include/Video.hpp b/include/Video.hpp new file mode 100644 index 0000000..f148c07 --- /dev/null +++ b/include/Video.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include <SFML/Graphics/RenderWindow.hpp> +#include <SFML/Graphics/Texture.hpp> +#include <SFML/Graphics/Sprite.hpp> +#include <SFML/Window/Context.hpp> +#include <thread> +#include <mutex> +#include <atomic> +#include <stdexcept> + +class mpv_handle; +class mpv_render_context; + +namespace dchat +{ + class VideoInitializationException : public std::runtime_error + { + public: + VideoInitializationException(const std::string &errMsg) : std::runtime_error(errMsg) {} + }; + + class Video + { + public: + // Throws VideoInitializationException on error + Video(unsigned int width, unsigned int height, const char *file, bool loop = false); + ~Video(); + + void setPosition(float x, float y); + void draw(sf::RenderWindow &window); + + // This counter is incremented when mpv wants to redraw content + std::atomic_int redrawCounter; + private: + sf::Context context; + mpv_handle *mpv; + mpv_render_context *mpvGl; + std::thread renderThread; + std::mutex renderMutex; + sf::Sprite sprite; + sf::Texture texture; + sf::Uint8 *textureBuffer; + }; +} |