| 1 | #pragma once |
| 2 | |
| 3 | #include <fstream> |
| 4 | #include <mutex> |
| 5 | #include <thread> |
| 6 | |
| 7 | #include <simgear/props/props.hxx> |
| 8 | |
| 9 | #include "replay-internal.hxx" |
| 10 | |
| 11 | |
| 12 | struct Continuous : SGPropertyChangeListener { |
| 13 | explicit Continuous(std::shared_ptr<FGFlightRecorder> flight_recorder); |
| 14 | |
| 15 | /* Callback for SGPropertyChangeListener. */ |
| 16 | void valueChanged(SGPropertyNode* node) override; |
| 17 | |
| 18 | std::shared_ptr<FGFlightRecorder> m_flight_recorder; |
| 19 | |
| 20 | std::ifstream m_in; |
| 21 | bool m_in_multiplayer = false; |
| 22 | bool m_in_extra_properties = false; |
| 23 | std::mutex m_in_time_to_frameinfo_lock; |
| 24 | std::map<double, FGFrameInfo> m_in_time_to_frameinfo; |
| 25 | SGPropertyNode_ptr m_in_config; |
| 26 | double m_in_time_last = 0; |
| 27 | double m_in_frame_time_last = 0; |
| 28 | std::map<size_t, std::shared_ptr<FGReplayData>> |
| 29 | m_in_pos_to_frame; |
| 30 | |
| 31 | std::ifstream m_indexing_in; |
| 32 | std::streampos m_indexing_pos; |
| 33 | |
| 34 | bool m_replay_create_video = false; |
| 35 | double m_replay_fixed_dt = -1; |
| 36 | double m_replay_fixed_dt_prev = -1; |
| 37 | |
| 38 | // Only used for gathering statistics that are then written into |
| 39 | // properties. |
| 40 | // |
| 41 | int m_num_frames_extra_properties = 0; |
| 42 | int m_num_frames_multiplayer = 0; |
| 43 | |
| 44 | // For writing Continuous fgtape file. |
| 45 | SGPropertyNode_ptr m_out_config; |
| 46 | std::ofstream m_out; |
| 47 | int m_out_compression = 0; |
| 48 | int m_in_compression = 0; |
| 49 | }; |
| 50 | |
| 51 | /* Attempts to load Continuous recording header properties into |
| 52 | <properties>. If in is null we use internal std::fstream, otherwise we use *in. |
| 53 | |
| 54 | Returns 0 on success, +1 if we may succeed after further download, or -1 if |
| 55 | recording is not a Continuous recording. */ |
| 56 | int loadContinuousHeader(const std::string& path, std::istream* in, SGPropertyNode* properties); |
| 57 | |
| 58 | |
| 59 | /* Writes one frame of continuous record information. */ |
| 60 | bool continuousWriteFrame( |
| 61 | Continuous& continuous, |
| 62 | FGReplayData* r, |
| 63 | std::ostream& out, |
| 64 | SGPropertyNode_ptr config, |
| 65 | FGTapeType tape_type); |
| 66 | |
| 67 | /* Opens continuous recording file and writes header. |
| 68 | |
| 69 | If MetaData is unset, we initialise it by calling saveSetup(). Otherwise should |
| 70 | be already set up. |
| 71 | |
| 72 | If Config is unset, we make it point to a new node populated by |
| 73 | m_pRecorder->getConfig(). Otherwise it should be already set up to point to |
| 74 | such information. |
| 75 | |
| 76 | If path_override is not "", we use it as the path (instead of the path |
| 77 | determined by saveSetup(). */ |
| 78 | SGPropertyNode_ptr continuousWriteHeader( |
| 79 | Continuous& continuous, |
| 80 | FGFlightRecorder* m_pRecorder, |
| 81 | std::ofstream& out, |
| 82 | const SGPath& path, |
| 83 | FGTapeType tape_type); |
| 84 | |
| 85 | /* Replays one frame from Continuous recording. |
| 86 | |
| 87 | Returns true on success, otherwise we failed to read from Continuous recording. |
| 88 | */ |
| 89 | bool replayContinuous(FGReplayInternal& self, double time); |
| 90 | |
| 91 | /* Stops any video recording that was started because of |
| 92 | continuous->m_replay_create_video. */ |
| 93 | void continuous_replay_video_end(Continuous& continuous); |