spacebox/src/Recorder.hpp

74 lines
1.6 KiB
C++
Raw Normal View History

2019-05-07 03:33:54 -04:00
#ifndef Recorder_h_
#define Recorder_h_
#include <sstream>
#include <string>
2019-05-19 05:55:46 -04:00
#include <thread>
#include <functional>
2019-05-22 04:27:15 -04:00
#include <cstdlib>
#include <fstream>
2019-05-07 03:33:54 -04:00
#include "SDL.h"
#include "SDL_mixer.h"
2019-05-07 03:33:54 -04:00
#define GLM_ENABLE_EXPERIMENTAL
#include "glm/ext.hpp"
#include "json/json.hpp"
#include "filesystem.hpp"
#include "Node.hpp"
2019-05-16 03:51:36 -04:00
#include "Animation.hpp"
2019-05-07 03:33:54 -04:00
#include "extension.hpp"
struct Stash
{
std::vector<unsigned char*> pixel_buffers;
2019-06-16 03:05:02 -04:00
std::vector<bool> flipped;
2019-06-04 03:20:13 -04:00
std::vector<Uint8*> audio_buffers;
std::vector<int> audio_buffer_lengths;
int frame_offset;
Stash(int frame_offset = 0) : frame_offset(frame_offset) {}
};
2019-05-07 03:33:54 -04:00
struct Recorder : Node
{
2019-05-31 02:54:31 -04:00
Stash current_stash = Stash();
Stash most_recent_stash;
std::list<Stash> in_game_stashes;
std::list<Stash> video_stashes;
2019-06-04 03:20:13 -04:00
fs::path current_video_directory, current_audio_path;
Animation animation = Animation(&Recorder::add_frame, this);
2019-05-31 02:54:31 -04:00
bool is_recording = false, writing_recording = false, writing_most_recent = false;
2019-06-04 03:20:13 -04:00
std::ofstream audio_file;
2019-05-16 03:51:36 -04:00
2019-05-07 03:33:54 -04:00
Recorder(Node*);
2019-05-22 04:27:15 -04:00
float get_frame_length();
2019-05-07 03:33:54 -04:00
void respond(SDL_Event&);
void capture_screen();
2019-05-31 02:54:31 -04:00
void grab_stash();
void write_most_recent_frames();
2019-05-16 03:51:36 -04:00
void start_recording();
2019-06-04 03:20:13 -04:00
void open_audio_file();
void add_frame();
int get_memory_size();
2019-06-04 03:20:13 -04:00
void make_directory();
void write_stash_frames(Stash*);
void keep_stash();
2019-05-16 03:51:36 -04:00
void end_recording();
void finish_writing_video();
2019-05-31 02:54:31 -04:00
void write_mp4();
2019-06-04 03:20:13 -04:00
void write_audio(Uint8*, int);
2019-05-16 03:51:36 -04:00
void update();
std::string get_class_name() { return "Recorder"; }
2019-05-07 03:33:54 -04:00
};
2019-06-04 03:20:13 -04:00
void process_audio(void*, Uint8*, int);
#include "Game.hpp"
2019-05-07 03:33:54 -04:00
#endif