1 #ifndef _advdumper__hpp__included__
2 #define _advdumper__hpp__included__
10 #include "library/framebuffer.hpp"
11 #include "library/dispatch.hpp"
12 #include "library/threads.hpp"
15 class dumper_factory_base
;
19 class dumper_factory_base
28 virtual ~notifier() throw();
29 virtual void dumpers_updated() throw() = 0;
34 static const unsigned target_type_mask
;
35 static const unsigned target_type_file
;
36 static const unsigned target_type_prefix
;
37 static const unsigned target_type_special
;
41 * Parameter id: The ID of dumper.
42 * Throws std::bad_alloc: Not enough memory.
44 dumper_factory_base(const std::string
& id
);
46 * Unregister a dumper.
48 ~dumper_factory_base();
54 const std::string
& id() throw();
56 * Get set of all dumpers.
59 * Throws std::bad_alloc: Not enough memory.
61 static std::set
<dumper_factory_base
*> get_dumper_set();
63 * List all valid submodes.
65 * Returns: List of all valid submodes. Empty list means this dumper has no submodes.
66 * Throws std::bad_alloc: Not enough memory.
68 virtual std::set
<std::string
> list_submodes() = 0;
72 * parameter mode: The submode.
73 * Returns: Mode details flags
75 virtual unsigned mode_details(const std::string
& mode
) throw() = 0;
77 * Get mode extensions. Only called if mode details specifies that output is a single file.
79 * parameter mode: The submode.
80 * Returns: Mode extension
82 virtual std::string
mode_extension(const std::string
& mode
) throw() = 0;
84 * Get human-readable name for this dumper.
87 * Throws std::bad_alloc: Not enough memory.
89 virtual std::string
name() = 0;
91 * Get human-readable name for submode.
93 * Parameter mode: The submode.
95 * Throws std::bad_alloc: Not enough memory.
97 virtual std::string
modename(const std::string
& mode
) = 0;
101 * parameter mode: The mode to dump using.
102 * parameter targetname: The target filename or prefix.
103 * returns: The dumper object.
104 * Throws std::bad_alloc: Not enough memory.
105 * Throws std::runtime_error: Can't start dump.
107 virtual dumper_base
* start(master_dumper
& _mdumper
, const std::string
& mode
, const std::string
& targetname
)
112 virtual bool hidden() const { return false; }
114 * Add dumper update notifier object.
116 static void add_notifier(notifier
& n
);
118 * Remove dumper update notifier object.
120 static void drop_notifier(notifier
& n
);
122 * Notify ctor finished.
126 * Notify dumper change.
128 static void run_notify();
137 * Information about run.
143 * Construct game info.
149 std::string gamename
;
151 * Run length in seconds.
155 * Rerecord count (base 10 ASCII)
157 std::string rerecords
;
159 * Authors. The first components are real names, the second components are nicknames. Either (but not both) may be
162 std::vector
<std::pair
<std::string
, std::string
>> authors
;
164 * Format human-redable representation of the length.
166 * Parameter digits: Number of sub-second digits to use.
167 * Returns: The time formated.
168 * Throws std::bad_alloc: Not enough memory.
170 std::string
get_readable_time(unsigned digits
) const;
172 * Get number of authors.
174 * Returns: Number of authors.
176 size_t get_author_count() const throw();
178 * Get short name of author (nickname if present, otherwise full name).
180 * Parameter idx: Index of author (0-based).
181 * Returns: The short name.
182 * Throws std::bad_alloc: Not enough memory.
184 std::string
get_author_short(size_t idx
) const;
186 * Get long name of author (full name and nickname if present).
188 * Parameter idx: Index of author (0-based).
189 * Returns: The long name.
190 * Throws std::bad_alloc: Not enough memory.
192 std::string
get_author_long(size_t idx
) const;
194 * Get rerecord count as a number. If rerecord count is too high, returns the maximum representatible count.
196 * Returns: The rerecord count.
198 uint64_t get_rerecords() const throw();
206 virtual ~notifier() throw();
207 virtual void dump_status_change() = 0;
212 master_dumper(lua_state
& _lua2
);
214 * Get instance for specified dumper.
216 dumper_base
* get_instance(dumper_factory_base
* dumper
) throw();
218 * Is dumper busy in this instance?
220 bool busy(dumper_factory_base
* dumper
) throw()
222 return get_instance(dumper
) != NULL
;
225 * Call start on dumper.
227 dumper_base
* start(dumper_factory_base
& factory
, const std::string
& mode
, const std::string
& targetname
);
229 * Add dumper update notifier object.
231 void add_notifier(notifier
& n
);
233 * Remove dumper update notifier object.
235 void drop_notifier(notifier
& n
);
237 * Add dumper update notifier object.
239 void add_dumper(dumper_base
& n
);
241 * Remove dumper update notifier object.
243 void drop_dumper(dumper_base
& n
);
245 * Get number of active dumpers.
247 unsigned get_dumper_count() throw();
249 * Call all notifiers (on_frame).
251 void on_frame(struct framebuffer::raw
& _frame
, uint32_t fps_n
, uint32_t fps_d
);
253 * Call all notifiers (on_sample).
255 void on_sample(short l
, short r
);
257 * Call all notifiers (on_rate_change)
259 * Also changes builtin rate variables.
261 void on_rate_change(uint32_t n
, uint32_t d
);
263 * Call all notifiers (on_gameinfo_change)
265 * Also changes builtin gameinfo structure.
267 void on_gameinfo_change(const gameinfo
& gi
);
269 * Get current sound rate in effect.
271 std::pair
<uint32_t, uint32_t> get_rate();
273 * Get current gameinfo in effect.
275 const gameinfo
& get_gameinfo();
283 void set_output(std::ostream
* _output
);
285 * Render Lua HUD on video.
287 * Parameter target: The target screen to render on.
288 * Parameter source: The source screen to read.
289 * Parameter hscl: The horizontal scale factor.
290 * Parameter vscl: The vertical scale factor.
291 * Parameter lgap: Left gap.
292 * Parameter tgap: Top gap.
293 * Parameter rgap: Right gap
294 * Parameter bgap: Bottom gap.
295 * Parameter fn: Function to call between running lua hooks and actually rendering.
296 * Returns: True if frame should be dumped, false if not.
298 template<bool X
> bool render_video_hud(struct framebuffer::fb
<X
>& target
, struct framebuffer::raw
& source
,
299 uint32_t hscl
, uint32_t vscl
, uint32_t lgap
, uint32_t tgap
, uint32_t rgap
, uint32_t bgap
,
300 std::function
<void()> fn
);
302 * Calculate number of sound samples to drop due to dropped frame.
304 uint64_t killed_audio_length(uint32_t fps_n
, uint32_t fps_d
, double& fraction
);
307 friend class dumper_base
;
308 std::map
<dumper_factory_base
*, dumper_base
*> dumpers
;
309 std::set
<notifier
*> notifications
;
310 std::set
<dumper_base
*> sdumpers
;
311 uint32_t current_rate_n
;
312 uint32_t current_rate_d
;
314 std::ostream
* output
;
323 dumper_base(master_dumper
& _mdumper
, dumper_factory_base
& _fbase
);
324 virtual ~dumper_base() throw();
326 * New frame available.
328 virtual void on_frame(struct framebuffer::raw
& _frame
, uint32_t fps_n
, uint32_t fps_d
) = 0;
330 * New sample available.
332 virtual void on_sample(short l
, short r
) = 0;
334 * Sample rate is changing.
336 virtual void on_rate_change(uint32_t n
, uint32_t d
) = 0;
338 * Gameinfo is changing.
340 virtual void on_gameinfo_change(const master_dumper::gameinfo
& gi
) = 0;
342 * Dump is being forcibly ended.
344 virtual void on_end() = 0;
346 * Render Lua HUD on video. samples_killed is incremented if needed.
348 * Parameter target: The target screen to render on.
349 * Parameter source: The source screen to read.
350 * Parameter fps_n: Fps numerator.
351 * Parameter fps_d: Fps denominator.
352 * Parameter hscl: The horizontal scale factor.
353 * Parameter vscl: The vertical scale factor.
354 * Parameter lgap: Left gap.
355 * Parameter tgap: Top gap.
356 * Parameter rgap: Right gap
357 * Parameter bgap: Bottom gap.
358 * Parameter fn: Function to call between running lua hooks and actually rendering.
359 * Returns: True if frame should be dumped, false if not.
361 template<bool X
> bool render_video_hud(struct framebuffer::fb
<X
>& target
, struct framebuffer::raw
& source
,
362 uint32_t fps_n
, uint32_t fps_d
, uint32_t hscl
, uint32_t vscl
, uint32_t lgap
, uint32_t tgap
,
363 uint32_t rgap
, uint32_t bgap
, std::function
<void()> fn
)
365 bool r
= mdumper
->render_video_hud(target
, source
, hscl
, vscl
, lgap
, tgap
, rgap
, bgap
, fn
);
367 samples_killed
+= mdumper
->killed_audio_length(fps_n
, fps_d
, akillfrac
);
371 friend class master_dumper
;
372 uint64_t samples_killed
;
373 master_dumper
* mdumper
;
374 dumper_factory_base
* fbase
;