Fix Mingw compiling
[jpcrr.git] / streamtools / output-drv.hpp
blobdaf455b96cc489800b1c035d9a204e4b67615223
1 #ifndef _output_drv__hpp__included__
2 #define _output_drv__hpp__included__
4 #include <stdint.h>
5 #include <string>
6 #include <map>
7 #include "resize.hpp"
8 #include "digital-filter.hpp"
10 class audio_settings
12 public:
13 audio_settings(uint32_t _rate);
14 uint32_t get_rate() const;
15 private:
16 uint32_t rate;
19 class audio_dyncall_base
21 public:
22 virtual ~audio_dyncall_base();
23 virtual void operator()(short left, short right) = 0;
26 class audio_end_dyncall_base
28 public:
29 virtual ~audio_end_dyncall_base();
30 virtual void operator()() = 0;
33 template<class T>
34 class audio_dyncall : public audio_dyncall_base
36 public:
37 audio_dyncall(T& _object, void (T::*_ptr)(short left, short right))
38 : object(_object)
40 ptr = _ptr;
43 ~audio_dyncall()
47 void operator()(short left, short right)
49 (object.*ptr)(left, right);
51 private:
52 T& object;
53 void (T::*ptr)(short left, short right);
56 template<class T>
57 class audio_end_dyncall : public audio_end_dyncall_base
59 public:
60 audio_end_dyncall(T& _object, void (T::*_ptr)())
61 : object(_object)
63 ptr = _ptr;
66 ~audio_end_dyncall()
70 void operator()()
72 (object.*ptr)();
74 private:
75 T& object;
76 void (T::*ptr)();
79 class video_settings
81 public:
82 video_settings(uint32_t _width, uint32_t _height, uint32_t _rate_num, uint32_t _rate_denum);
83 uint32_t get_width() const;
84 uint32_t get_height() const;
85 uint32_t get_rate_num() const;
86 uint32_t get_rate_denum() const; //WARNING: Zero if framerate is variable!
87 private:
88 uint32_t width;
89 uint32_t height;
90 uint32_t rate_num;
91 uint32_t rate_denum;
94 class video_dyncall_base
96 public:
97 virtual ~video_dyncall_base();
98 virtual void operator()(uint64_t timestamp, const uint8_t* raw_rgbx_data) = 0;
101 template<class T>
102 class video_dyncall : public video_dyncall_base
104 public:
105 video_dyncall(T& _object, void (T::*_ptr)(uint64_t timestamp, const uint8_t* raw_rgbx_data))
106 : object(_object)
108 ptr = _ptr;
111 ~video_dyncall()
115 void operator()(uint64_t timestamp, const uint8_t* raw_rgbx_data)
117 (object.*ptr)(timestamp, raw_rgbx_data);
119 private:
120 T& object;
121 void (T::*ptr)(uint64_t timestamp, const uint8_t* raw_rgbx_data);
124 class subtitle_settings
126 public:
127 subtitle_settings();
128 private:
131 class subtitle_dyncall_base
133 public:
134 virtual ~subtitle_dyncall_base();
135 virtual void operator()(uint64_t basetime, uint64_t duration, const uint8_t* text) = 0;
138 template<class T>
139 class subtitle_dyncall : public subtitle_dyncall_base
141 public:
142 subtitle_dyncall(T& _object, void (T::*_ptr)(uint64_t basetime, uint64_t duration, const uint8_t* text))
143 : object(_object)
145 ptr = _ptr;
148 ~subtitle_dyncall()
152 void operator()(uint64_t basetime, uint64_t duration, const uint8_t* text)
154 (object.*ptr)(basetime, duration, text);
156 private:
157 T& object;
158 void (T::*ptr)(uint64_t basetime, uint64_t duration, const uint8_t* text);
162 class output_driver
164 public:
165 output_driver();
166 virtual ~output_driver();
167 virtual void ready() = 0;
168 void set_audio_settings(audio_settings a);
169 void set_video_settings(video_settings v);
170 void set_subtitle_settings(subtitle_settings s);
171 const audio_settings& get_audio_settings();
172 const video_settings& get_video_settings();
173 const subtitle_settings& get_subtitle_settings();
174 template<class T> void set_audio_callback(T& object, void (T::*ptr)(short left, short right))
176 audio_dyncall_base* old = audio_handler;
177 audio_handler = new audio_dyncall<T>(object, ptr);
178 delete old;
181 template<class T> void set_audio_end_callback(T& object, void (T::*ptr)())
183 audio_end_dyncall_base* old = audio_end_handler;
184 audio_end_handler = new audio_end_dyncall<T>(object, ptr);
185 delete old;
188 template<class T> void set_video_callback(T& object, void (T::*ptr)(uint64_t timestamp, const uint8_t* raw_rgbx_data))
190 video_dyncall_base* old = video_handler;
191 video_handler = new video_dyncall<T>(object, ptr);
192 delete old;
195 template<class T> void set_subtitle_callback(T& object, void (T::*ptr)(uint64_t basetime, uint64_t duration,
196 const uint8_t* text))
198 audio_dyncall_base* old = audio_handler;
199 audio_handler = new audio_dyncall<T>(object, ptr);
200 delete old;
203 void do_audio_callback(short left, short right);
204 void do_audio_end_callback();
205 void do_video_callback(uint64_t timestamp, const uint8_t* raw_rgbx_data);
206 void do_subtitle_callback(uint64_t basetime, uint64_t duration, const uint8_t* text);
207 private:
208 output_driver(const output_driver&);
209 output_driver& operator=(const output_driver&);
210 audio_dyncall_base* audio_handler;
211 audio_end_dyncall_base* audio_end_handler;
212 video_dyncall_base* video_handler;
213 subtitle_dyncall_base* subtitle_handler;
214 audio_settings asettings;
215 video_settings vsettings;
216 subtitle_settings ssettings;
219 void distribute_audio_callback(short left, short right);
220 void distribute_audio_callback(npair<short> sample);
221 void distribute_video_callback(uint64_t timestamp, const uint8_t* raw_rgbx_data);
222 void distribute_subtitle_callback(uint64_t basetime, uint64_t duration, const uint8_t* text);
223 void distribute_subtitle_callback(struct packet& p);
224 void set_audio_parameters(audio_settings a);
225 void set_video_parameters(video_settings v);
226 void set_subtitle_parameters(subtitle_settings s);
227 void add_output_driver(const std::string& type, const std::string& name, const std::string& parameters);
228 void close_output_drivers();
230 std::string get_output_driver_list();
232 class output_driver_factory
234 public:
235 output_driver_factory(const std::string& type);
236 virtual ~output_driver_factory();
237 static output_driver& make_by_type(const std::string& type, const std::string& name,
238 const std::string& parameters);
239 virtual output_driver& make(const std::string& type, const std::string& name,
240 const std::string& parameters) = 0;
241 private:
242 static std::map<std::string, output_driver_factory*>* factories;
243 friend std::string get_output_driver_list();
246 #endif