Back movie data off movie file structure
[lsnes.git] / include / core / moviefile.hpp
blobf3ca88047bcd62ee3b47bc56df27b0f67737de2c
1 #ifndef _moviefile__hpp__included__
2 #define _moviefile__hpp__included__
4 #include <string>
5 #include <vector>
6 #include <stdexcept>
7 #include <map>
8 #include "core/controllerframe.hpp"
9 #include "core/rom.hpp"
10 #include "core/subtitles.hpp"
11 #include "library/zip.hpp"
13 /**
14 * This structure gives parsed representationg of movie file, as result of decoding or for encoding.
16 struct moviefile
18 /**
19 * Brief information
21 struct brief_info
23 brief_info() { current_frame = 0; rerecords = 0; }
24 brief_info(const std::string& filename);
25 std::string sysregion;
26 std::string corename;
27 std::string projectid;
28 std::string hash[ROM_SLOT_COUNT];
29 std::string hashxml[ROM_SLOT_COUNT];
30 std::string hint[ROM_SLOT_COUNT];
31 uint64_t current_frame;
32 uint64_t rerecords;
33 private:
34 void binary_io(std::istream& s);
36 /**
37 * This constructor construct movie structure with default settings.
39 * throws std::bad_alloc: Not enough memory.
41 moviefile() throw(std::bad_alloc);
43 /**
44 * This constructor loads a movie/savestate file and fills structure accordingly.
46 * parameter filename: The file to load.
47 * parameter romtype: Type of ROM.
48 * throws std::bad_alloc: Not enough memory.
49 * throws std::runtime_error: Can't load the movie file
51 moviefile(const std::string& filename, core_type& romtype) throw(std::bad_alloc, std::runtime_error);
53 /**
54 * Reads this movie structure and saves it into file.
56 * parameter filename: The file to save to.
57 * parameter compression: The compression level 0-9. 0 is uncompressed.
58 * parameter binary: Save in binary form if true.
59 * throws std::bad_alloc: Not enough memory.
60 * throws std::runtime_error: Can't save the movie file.
62 void save(const std::string& filename, unsigned compression, bool binary) throw(std::bad_alloc,
63 std::runtime_error);
64 /**
65 * Reads this movie structure and saves it to stream (uncompressed ZIP).
67 void save(std::ostream& outstream) throw(std::bad_alloc, std::runtime_error);
68 /**
69 * Force loading as corrupt.
71 bool force_corrupt;
72 /**
73 * What is the ROM type and region?
75 core_sysregion* gametype;
76 /**
77 * Settings.
79 std::map<std::string, std::string> settings;
80 /**
81 * Emulator Core version string.
83 std::string coreversion;
84 /**
85 * Name of the game
87 std::string gamename;
88 /**
89 * Project ID (used to identify if two movies are from the same project).
91 std::string projectid;
92 /**
93 * Rerecord count (only saved).
95 std::string rerecords;
96 /**
97 * Rerecord count (memory saves only).
99 uint64_t rerecords_mem;
101 * SHA-256 of ROM (empty string if none).
103 std::string romimg_sha256[ROM_SLOT_COUNT];
105 * SHA-256 of ROM XML (empty string if none).
107 std::string romxml_sha256[ROM_SLOT_COUNT];
109 * ROM name hint (empty string if none).
111 std::string namehint[ROM_SLOT_COUNT];
113 * Authors of the run, first in each pair is full name, second is nickname.
115 std::vector<std::pair<std::string, std::string>> authors;
117 * Contents of SRAM on time of initial powerup.
119 std::map<std::string, std::vector<char>> movie_sram;
121 * Contents of RAM on time of initial powerup.
123 std::map<std::string, std::vector<char>> ramcontent;
125 * True if savestate, false if movie.
127 bool is_savestate;
129 * Contents of SRAM on time of savestate (if is_savestate is true).
131 std::map<std::string, std::vector<char>> sram;
133 * Core savestate (if is_savestate is true).
135 std::vector<char> savestate; //Savestate to load (if is_savestate is true).
137 * Anchoring core savestate (if not empty).
139 std::vector<char> anchor_savestate;
141 * Host memory (if is_savestate is true).
143 std::vector<char> host_memory;
145 * Screenshot (if is_savestate is true).
147 std::vector<char> screenshot;
149 * Current frame (if is_savestate is true).
151 uint64_t save_frame;
153 * Number of lagged frames (if is_savestate is true).
155 uint64_t lagged_frames;
157 * Poll counters (if is_savestate is true).
159 std::vector<uint32_t> pollcounters;
161 * Poll flag.
163 unsigned poll_flag;
165 * Compressed rrdata.
167 std::vector<char> c_rrdata;
169 * Input for each (sub)frame.
171 controller_frame_vector input; //Input for each frame.
173 * Current RTC second.
175 int64_t rtc_second;
177 * Current RTC subsecond.
179 int64_t rtc_subsecond;
181 * Movie starting RTC second.
183 int64_t movie_rtc_second;
185 * Movie starting RTC subsecond.
187 int64_t movie_rtc_subsecond;
189 * Start paused flag.
191 bool start_paused;
193 * Lazy project create flag.
195 bool lazy_project_create;
197 * Subtitles.
199 std::map<moviefile_subtiming, std::string> subtitles;
201 * Active macros at savestate.
203 std::map<std::string, uint64_t> active_macros;
205 * Get number of frames in movie.
207 * returns: Number of frames.
209 uint64_t get_frame_count() throw();
211 * Get length of the movie
213 * returns: Length of the movie in nanoseconds.
215 uint64_t get_movie_length() throw();
217 * Return reference to memory slot.
219 static moviefile& memref(const std::string& slot);
220 private:
221 void binary_io(std::ostream& stream) throw(std::bad_alloc, std::runtime_error);
222 void binary_io(std::istream& stream, struct core_type& romtype) throw(std::bad_alloc, std::runtime_error);
223 void save(zip::writer& w) throw(std::bad_alloc, std::runtime_error);
226 void emerg_save_movie(const moviefile& mv);
228 #endif