]> git.sesse.net Git - nageru/blob - image_input.h
Refresh ImageInputs from disk every second. Not the most efficient or elegant way...
[nageru] / image_input.h
1 #ifndef _IMAGE_INPUT_H
2 #define _IMAGE_INPUT_H 1
3
4 #include <map>
5 #include <memory>
6 #include <mutex>
7 #include <string>
8 #include <thread>
9
10 #include <time.h>
11
12 #include <movit/flat_input.h>
13
14 // An output that takes its input from a static image, loaded with ffmpeg.
15 // comes from a single 2D array with chunky pixels. The image is refreshed
16 // from disk about every second.
17 class ImageInput : public movit::FlatInput {
18 public:
19         ImageInput(const std::string &filename);
20
21         std::string effect_type_id() const override { return "ImageInput"; }
22         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num) override;
23
24 private:
25         struct Image {
26                 std::unique_ptr<uint8_t[]> pixels;
27                 timespec last_modified;
28         };
29
30         std::string filename;
31         std::shared_ptr<const Image> current_image;
32
33         static std::shared_ptr<const Image> load_image(const std::string &filename);
34         static std::shared_ptr<const Image> load_image_raw(const std::string &filename);
35         static void update_thread_func(const std::string &filename, const timespec &first_modified);
36         static std::mutex all_images_lock;
37         static std::map<std::string, std::shared_ptr<const Image>> all_images;
38         static std::map<std::string, std::thread> update_threads;
39 };
40
41 #endif // !defined(_IMAGE_INPUT_H)