kodi
SavestateFlatBuffer.h
1 /*
2  * Copyright (C) 2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "ISavestate.h"
12 
13 #include <memory>
14 
15 #include <flatbuffers/flatbuffers.h>
16 
17 namespace KODI
18 {
19 namespace RETRO
20 {
21 struct Savestate;
22 struct SavestateBuilder;
23 
25 {
26 public:
28  ~CSavestateFlatBuffer() override;
29 
30  // Implementation of ISavestate
31  void Reset() override;
32  bool Serialize(const uint8_t*& data, size_t& size) const override;
33  SAVE_TYPE Type() const override;
34  uint8_t Slot() const override;
35  std::string Label() const override;
36  std::string Caption() const override;
37  CDateTime Created() const override;
38  std::string GameFileName() const override;
39  uint64_t TimestampFrames() const override;
40  double TimestampWallClock() const override;
41  std::string GameClientID() const override;
42  std::string GameClientVersion() const override;
43  AVPixelFormat GetPixelFormat() const override;
44  unsigned int GetNominalWidth() const override;
45  unsigned int GetNominalHeight() const override;
46  unsigned int GetMaxWidth() const override;
47  unsigned int GetMaxHeight() const override;
48  float GetPixelAspectRatio() const override;
49  const uint8_t* GetVideoData() const override;
50  size_t GetVideoSize() const override;
51  unsigned int GetVideoWidth() const override;
52  unsigned int GetVideoHeight() const override;
53  unsigned int GetRotationDegCCW() const override;
54  const uint8_t* GetMemoryData() const override;
55  size_t GetMemorySize() const override;
56  void SetType(SAVE_TYPE type) override;
57  void SetSlot(uint8_t slot) override;
58  void SetLabel(const std::string& label) override;
59  void SetCaption(const std::string& caption) override;
60  void SetCreated(const CDateTime& createdUTC) override;
61  void SetGameFileName(const std::string& gameFileName) override;
62  void SetTimestampFrames(uint64_t timestampFrames) override;
63  void SetTimestampWallClock(double timestampWallClock) override;
64  void SetGameClientID(const std::string& gameClient) override;
65  void SetGameClientVersion(const std::string& gameClient) override;
66  void SetPixelFormat(AVPixelFormat pixelFormat) override;
67  void SetNominalWidth(unsigned int nominalWidth) override;
68  void SetNominalHeight(unsigned int nominalHeight) override;
69  void SetMaxWidth(unsigned int maxWidth) override;
70  void SetMaxHeight(unsigned int maxHeight) override;
71  void SetPixelAspectRatio(float pixelAspectRatio) override;
72  uint8_t* GetVideoBuffer(size_t size) override;
73  void SetVideoWidth(unsigned int videoWidth) override;
74  void SetVideoHeight(unsigned int videoHeight) override;
75  void SetRotationDegCCW(unsigned int rotationCCW) override;
76  uint8_t* GetMemoryBuffer(size_t size) override;
77  void Finalize() override;
78  bool Deserialize(std::vector<uint8_t> data) override;
79 
80 private:
86  std::unique_ptr<flatbuffers::FlatBufferBuilder> m_builder;
87 
93  std::vector<uint8_t> m_data;
94 
98  const Savestate* m_savestate = nullptr;
99 
100  using StringOffset = flatbuffers::Offset<flatbuffers::String>;
101  using VectorOffset = flatbuffers::Offset<flatbuffers::Vector<uint8_t>>;
102 
103  // Temporary deserialization variables
104  SAVE_TYPE m_type = SAVE_TYPE::UNKNOWN;
105  uint8_t m_slot = 0;
106  std::unique_ptr<StringOffset> m_labelOffset;
107  std::unique_ptr<StringOffset> m_captionOffset;
108  std::unique_ptr<StringOffset> m_createdOffset;
109  std::unique_ptr<StringOffset> m_gameFileNameOffset;
110  uint64_t m_timestampFrames = 0;
111  double m_timestampWallClock = 0.0;
112  std::unique_ptr<StringOffset> m_emulatorAddonIdOffset;
113  std::unique_ptr<StringOffset> m_emulatorVersionOffset;
114  AVPixelFormat m_pixelFormat{AV_PIX_FMT_NONE};
115  unsigned int m_nominalWidth{0};
116  unsigned int m_nominalHeight{0};
117  unsigned int m_maxWidth{0};
118  unsigned int m_maxHeight{0};
119  float m_pixelAspectRatio{0.0f};
120  std::unique_ptr<VectorOffset> m_videoDataOffset;
121  unsigned int m_videoWidth{0};
122  unsigned int m_videoHeight{0};
123  unsigned int m_rotationCCW{0};
124  std::unique_ptr<VectorOffset> m_memoryDataOffset;
125 };
126 } // namespace RETRO
127 } // namespace KODI
uint8_t Slot() const override
The slot this savestate was saved into, or 0 for no slot.
Definition: SavestateFlatBuffer.cpp:232
Definition: SavestateFlatBuffer.h:24
unsigned int GetVideoWidth() const override
The width of the video frame, in pixels.
Definition: SavestateFlatBuffer.cpp:464
unsigned int GetRotationDegCCW() const override
The rotation of the video frame, in degrees counter-clockwise.
Definition: SavestateFlatBuffer.cpp:490
uint64_t TimestampFrames() const override
The number of frames in the entire gameplay history.
Definition: SavestateFlatBuffer.cpp:306
Definition: ISavestate.h:28
SAVE_TYPE Type() const override
The type of save action that created this savestate, either manual or automatic.
Definition: SavestateFlatBuffer.cpp:219
CDateTime Created() const override
The timestamp of this savestate&#39;s creation.
Definition: SavestateFlatBuffer.cpp:275
std::string GameClientID() const override
The game client add-on ID that created this savestate.
Definition: SavestateFlatBuffer.cpp:329
void Reset() override
Reset to the initial state.
Definition: SavestateFlatBuffer.cpp:195
std::string Caption() const override
A caption that describes the state of the game for this savestate.
Definition: SavestateFlatBuffer.cpp:260
unsigned int GetVideoHeight() const override
The height of the video frame, in pixels.
Definition: SavestateFlatBuffer.cpp:477
AVPixelFormat GetPixelFormat() const override
The pixel format of the video stream.
Definition: SavestateFlatBuffer.cpp:360
unsigned int GetMaxHeight() const override
The maximum height of the video stream, in pixels.
Definition: SavestateFlatBuffer.cpp:412
size_t GetVideoSize() const override
The size of the frame&#39;s video data, in bytes.
Definition: SavestateFlatBuffer.cpp:446
Definition: AudioDecoder.h:18
const uint8_t * GetVideoData() const override
A pointer to the frame&#39;s video data (pixels)
Definition: SavestateFlatBuffer.cpp:438
std::string GameFileName() const override
The name of the file belonging to this savestate&#39;s game.
Definition: SavestateFlatBuffer.cpp:291
unsigned int GetMaxWidth() const override
The maximum width of the video stream, in pixels.
Definition: SavestateFlatBuffer.cpp:399
DateTime class, which uses FileTime as it&#39;s base.
Definition: XBDateTime.h:63
double TimestampWallClock() const override
The duration of the entire gameplay history as seen by a wall clock.
Definition: SavestateFlatBuffer.cpp:316
bool Serialize(const uint8_t *&data, size_t &size) const override
Definition: SavestateFlatBuffer.cpp:202
bool Deserialize(std::vector< uint8_t > data) override
}
Definition: SavestateFlatBuffer.cpp:618
unsigned int GetNominalWidth() const override
The nominal width of the video stream, a good guess for subsequent frames.
Definition: SavestateFlatBuffer.cpp:373
const uint8_t * GetMemoryData() const override
A pointer to the internal memory (SRAM) of the frame.
Definition: SavestateFlatBuffer.cpp:503
std::string Label() const override
The label shown in the GUI for this savestate.
Definition: SavestateFlatBuffer.cpp:245
float GetPixelAspectRatio() const override
The pixel aspect ratio of the video stream.
Definition: SavestateFlatBuffer.cpp:425
size_t GetMemorySize() const override
The size of the memory region returned by GetMemoryData()
Definition: SavestateFlatBuffer.cpp:511
unsigned int GetNominalHeight() const override
The nominal height of the video stream, a good guess for subsequent frames.
Definition: SavestateFlatBuffer.cpp:386
std::string GameClientVersion() const override
The semantic version of the game client.
Definition: SavestateFlatBuffer.cpp:344