#pragma once #include #include #include #include #include #include #include #include class mpv_handle; class mpv_opengl_cb_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_opengl_cb_context *mpvGl; std::thread renderThread; std::mutex renderMutex; sf::Sprite sprite; sf::Texture texture; sf::Uint8 *textureBuffer; bool alive; }; }