]> git.sesse.net Git - nageru/blob - image_input.h
Fix an issue where the mixer lagging too much behind CEF would cause us to display...
[nageru] / image_input.h
1 #ifndef _IMAGE_INPUT_H
2 #define _IMAGE_INPUT_H 1
3
4 #include <epoxy/gl.h>
5 #include <movit/flat_input.h>
6 #include <stdbool.h>
7 #include <time.h>
8 #include <condition_variable>
9 #include <cstdint>
10 #include <map>
11 #include <memory>
12 #include <mutex>
13 #include <string>
14 #include <thread>
15
16 // An output that takes its input from a static image, loaded with ffmpeg.
17 // comes from a single 2D array with chunky pixels. The image is refreshed
18 // from disk about every second.
19 class ImageInput : public movit::FlatInput {
20 public:
21         ImageInput(const std::string &filename);
22
23         std::string effect_type_id() const override { return "ImageInput"; }
24         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num) override;
25         static void shutdown_updaters();
26         
27 private:
28         struct Image {
29                 unsigned width, height;
30                 std::unique_ptr<uint8_t[]> pixels;
31                 timespec last_modified;
32         };
33
34         std::string filename, pathname;
35         std::shared_ptr<const Image> current_image;
36
37         static std::shared_ptr<const Image> load_image(const std::string &filename, const std::string &pathname);
38         static std::shared_ptr<const Image> load_image_raw(const std::string &pathname);
39         static void update_thread_func(const std::string &filename, const std::string &pathname, const timespec &first_modified);
40         static std::mutex all_images_lock;
41         static std::map<std::string, std::shared_ptr<const Image>> all_images;
42         static std::map<std::string, std::thread> update_threads;
43
44         static std::mutex threads_should_quit_mu;
45         static bool threads_should_quit;  // Under threads_should_quit_mu.
46         static std::condition_variable threads_should_quit_modified;  // Signals when threads_should_quit is set.
47 };
48
49 #endif // !defined(_IMAGE_INPUT_H)