xbmc
RetroPlayer.h
1 /*
2  * Copyright (C) 2012-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 "RetroPlayerAutoSave.h"
12 #include "cores/IPlayer.h"
13 #include "cores/RetroPlayer/guibridge/IGameCallback.h"
14 #include "cores/RetroPlayer/playback/IPlaybackControl.h"
15 #include "games/GameTypes.h"
16 #include "guilib/DispResource.h"
17 #include "threads/CriticalSection.h"
18 
19 #include <memory>
20 
21 namespace KODI
22 {
23 namespace GAME
24 {
25 class CGameServices;
26 }
27 
28 namespace RETRO
29 {
30 class CCheevos;
31 class CGUIGameMessenger;
32 class CRetroPlayerInput;
33 class CRPProcessInfo;
34 class CRPRenderManager;
35 class CRPStreamManager;
36 class IPlayback;
37 
38 class CRetroPlayer : public IPlayer,
39  public IRenderLoop,
40  public IGameCallback,
41  public IPlaybackCallback,
42  public IAutoSaveCallback
43 {
44 public:
45  explicit CRetroPlayer(IPlayerCallback& callback);
46  ~CRetroPlayer() override;
47 
48  // implementation of IPlayer
49  bool OpenFile(const CFileItem& file, const CPlayerOptions& options) override;
50  bool CloseFile(bool reopen = false) override;
51  bool IsPlaying() const override;
52  bool CanPause() const override;
53  void Pause() override;
54  bool HasVideo() const override { return true; }
55  bool HasAudio() const override { return true; }
56  bool HasGame() const override { return true; }
57  bool CanSeek() const override;
58  void Seek(bool bPlus = true, bool bLargeStep = false, bool bChapterOverride = false) override;
59  void SeekPercentage(float fPercent = 0) override;
60  float GetCachePercentage() const override;
61  void SetMute(bool bOnOff) override;
62  void SeekTime(int64_t iTime = 0) override;
63  bool SeekTimeRelative(int64_t iTime) override;
64  void SetSpeed(float speed) override;
65  bool OnAction(const CAction& action) override;
66  std::string GetPlayerState() override;
67  bool SetPlayerState(const std::string& state) override;
68  void FrameMove() override;
69  void Render(bool clear, uint32_t alpha = 255, bool gui = true) override;
70  bool IsRenderingVideo() const override;
71  bool HasGameAgent() const override;
72 
73  // Implementation of IGameCallback
74  std::string GameClientID() const override;
75  std::string GetPlayingGame() const override;
76  std::string CreateSavestate(bool autosave) override;
77  bool UpdateSavestate(const std::string& savestatePath) override;
78  bool LoadSavestate(const std::string& savestatePath) override;
79  void FreeSavestateResources(const std::string& savestatePath) override;
80  void CloseOSDCallback() override;
81 
82  // Implementation of IPlaybackCallback
83  void SetPlaybackSpeed(double speed) override;
84  void EnableInput(bool bEnable) override;
85 
86  // Implementation of IAutoSaveCallback
87  bool IsAutoSaveEnabled() const override;
88  std::string CreateAutosave() override;
89 
90 private:
91  void SetSpeedInternal(double speed);
92 
97  void OnSpeedChange(double newSpeed);
98 
99  // Playback functions
100  void CreatePlayback(const std::string& savestatePath);
101  void ResetPlayback();
102 
106  void OpenOSD();
107 
111  void CloseOSD();
112 
113  void RegisterWindowCallbacks();
114  void UnregisterWindowCallbacks();
115 
119  void PrintGameInfo(const CFileItem& file) const;
120 
121  uint64_t GetTime();
122  uint64_t GetTotalTime();
123 
124  // Construction parameters
125  GAME::CGameServices& m_gameServices;
126 
127  // Subsystems
128  std::unique_ptr<CRPProcessInfo> m_processInfo;
129  std::unique_ptr<CGUIGameMessenger> m_guiMessenger;
130  std::unique_ptr<CRPRenderManager> m_renderManager;
131  std::unique_ptr<CRPStreamManager> m_streamManager;
132  std::unique_ptr<CRetroPlayerInput> m_input;
133  std::unique_ptr<IPlayback> m_playback;
134  std::unique_ptr<IPlaybackControl> m_playbackControl;
135  std::unique_ptr<CRetroPlayerAutoSave> m_autoSave;
136  std::shared_ptr<CCheevos> m_cheevos;
137 
138  // Game parameters
139  GAME::GameClientPtr m_gameClient;
140 
141  // Synchronization parameters
142  CCriticalSection m_mutex;
143 };
144 } // namespace RETRO
145 } // namespace KODI
Definition: DispResource.h:26
Definition: IGameCallback.h:19
Definition: GameServices.h:37
The playback client being controlled.
Definition: IPlaybackControl.h:18
Definition: IPlayer.h:87
class encapsulating information regarding a particular user action to be sent to windows and controls...
Definition: Action.h:22
Controller configuration window.
Definition: AudioDecoder.h:18
Definition: IPlayerCallback.h:18
Definition: RetroPlayerAutoSave.h:25
Definition: RetroPlayer.h:38
Definition: IPlayer.h:31
Represents a file on a share.
Definition: FileItem.h:102