summaryrefslogtreecommitdiffstats
path: root/xbmc/cores/RetroPlayer/RetroPlayer.h
blob: fc383c90783f581f4b068bd77d1e4dd93af00fdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 *  Copyright (C) 2012-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "RetroPlayerAutoSave.h"
#include "cores/IPlayer.h"
#include "cores/RetroPlayer/guibridge/IGameCallback.h"
#include "cores/RetroPlayer/playback/IPlaybackControl.h"
#include "games/GameTypes.h"
#include "guilib/DispResource.h"
#include "threads/CriticalSection.h"

#include <memory>

namespace KODI
{
namespace GAME
{
class CGameServices;
}

namespace RETRO
{
class CCheevos;
class CGUIGameMessenger;
class CRetroPlayerInput;
class CRPProcessInfo;
class CRPRenderManager;
class CRPStreamManager;
class IPlayback;

class CRetroPlayer : public IPlayer,
                     public IRenderLoop,
                     public IGameCallback,
                     public IPlaybackCallback,
                     public IAutoSaveCallback
{
public:
  explicit CRetroPlayer(IPlayerCallback& callback);
  ~CRetroPlayer() override;

  // implementation of IPlayer
  bool OpenFile(const CFileItem& file, const CPlayerOptions& options) override;
  bool CloseFile(bool reopen = false) override;
  bool IsPlaying() const override;
  bool CanPause() const override;
  void Pause() override;
  bool HasVideo() const override { return true; }
  bool HasAudio() const override { return true; }
  bool HasGame() const override { return true; }
  bool CanSeek() const override;
  void Seek(bool bPlus = true, bool bLargeStep = false, bool bChapterOverride = false) override;
  void SeekPercentage(float fPercent = 0) override;
  float GetCachePercentage() const override;
  void SetMute(bool bOnOff) override;
  void SeekTime(int64_t iTime = 0) override;
  bool SeekTimeRelative(int64_t iTime) override;
  void SetSpeed(float speed) override;
  bool OnAction(const CAction& action) override;
  std::string GetPlayerState() override;
  bool SetPlayerState(const std::string& state) override;
  void FrameMove() override;
  void Render(bool clear, uint32_t alpha = 255, bool gui = true) override;
  bool IsRenderingVideo() const override;
  bool HasGameAgent() const override;

  // Implementation of IGameCallback
  std::string GameClientID() const override;
  std::string GetPlayingGame() const override;
  std::string CreateSavestate(bool autosave) override;
  bool UpdateSavestate(const std::string& savestatePath) override;
  bool LoadSavestate(const std::string& savestatePath) override;
  void FreeSavestateResources(const std::string& savestatePath) override;
  void CloseOSDCallback() override;

  // Implementation of IPlaybackCallback
  void SetPlaybackSpeed(double speed) override;
  void EnableInput(bool bEnable) override;

  // Implementation of IAutoSaveCallback
  bool IsAutoSaveEnabled() const override;
  std::string CreateAutosave() override;

private:
  void SetSpeedInternal(double speed);

  /*!
   * \brief Called when the speed changes
   * \param newSpeed The new speed, possibly equal to the previous speed
   */
  void OnSpeedChange(double newSpeed);

  // Playback functions
  void CreatePlayback(const std::string& savestatePath);
  void ResetPlayback();

  /*!
   * \brief Opens the OSD
   */
  void OpenOSD();

  /*!
   * \brief Closes the OSD and shows the FullscreenGame window
   */
  void CloseOSD();

  void RegisterWindowCallbacks();
  void UnregisterWindowCallbacks();

  /**
   * \brief Dump game information (if any) to the debug log.
   */
  void PrintGameInfo(const CFileItem& file) const;

  uint64_t GetTime();
  uint64_t GetTotalTime();

  // Construction parameters
  GAME::CGameServices& m_gameServices;

  // Subsystems
  std::unique_ptr<CRPProcessInfo> m_processInfo;
  std::unique_ptr<CGUIGameMessenger> m_guiMessenger;
  std::unique_ptr<CRPRenderManager> m_renderManager;
  std::unique_ptr<CRPStreamManager> m_streamManager;
  std::unique_ptr<CRetroPlayerInput> m_input;
  std::unique_ptr<IPlayback> m_playback;
  std::unique_ptr<IPlaybackControl> m_playbackControl;
  std::unique_ptr<CRetroPlayerAutoSave> m_autoSave;
  std::shared_ptr<CCheevos> m_cheevos;

  // Game parameters
  GAME::GameClientPtr m_gameClient;

  // Synchronization parameters
  CCriticalSection m_mutex;
};
} // namespace RETRO
} // namespace KODI