]> git.sesse.net Git - nageru/blob - image_input.h
Write 1.4.0 changelog.
[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 <cstdint>
9 #include <map>
10 #include <memory>
11 #include <mutex>
12 #include <string>
13 #include <thread>
14
15 // An output that takes its input from a static image, loaded with ffmpeg.
16 // comes from a single 2D array with chunky pixels. The image is refreshed
17 // from disk about every second.
18 class ImageInput : public movit::FlatInput {
19 public:
20         ImageInput(const std::string &pathname);
21
22         std::string effect_type_id() const override { return "ImageInput"; }
23         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num) override;
24         static void shutdown_updaters();
25         
26 private:
27         struct Image {
28                 std::unique_ptr<uint8_t[]> pixels;
29                 timespec last_modified;
30         };
31
32         std::string pathname;
33         std::shared_ptr<const Image> current_image;
34
35         static std::shared_ptr<const Image> load_image(const std::string &pathname);
36         static std::shared_ptr<const Image> load_image_raw(const std::string &pathname);
37         static void update_thread_func(const std::string &pathname, const timespec &first_modified);
38         static std::mutex all_images_lock;
39         static std::map<std::string, std::shared_ptr<const Image>> all_images;
40         static std::map<std::string, std::thread> update_threads;
41         static volatile bool threads_should_quit;
42 };
43
44 #endif // !defined(_IMAGE_INPUT_H)