[WASAPI] set stream audio category
[xbmc.git] / xbmc / cores / RetroPlayer / guiplayback / GUIPlaybackControl.cpp
blob054454fee08c3627d36a48d625bfd18e92ba729e
1 /*
2 * Copyright (C) 2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIPlaybackControl.h"
11 #include "ServiceBroker.h"
12 #include "games/dialogs/osd/DialogGameOSD.h"
13 #include "guilib/GUIComponent.h"
14 #include "guilib/GUIWindowManager.h"
16 using namespace KODI;
17 using namespace RETRO;
19 CGUIPlaybackControl::CGUIPlaybackControl(IPlaybackCallback& callback) : m_callback(callback)
23 CGUIPlaybackControl::~CGUIPlaybackControl() = default;
25 void CGUIPlaybackControl::FrameMove()
27 CGUIComponent* gui = CServiceBroker::GetGUI();
28 if (gui == nullptr)
29 return;
31 const int windowId = gui->GetWindowManager().GetActiveWindow();
32 const int dialogId = gui->GetWindowManager().GetActiveWindowOrDialog();
34 // Check if game has entered fullscreen yet
35 const bool bFullscreen = (windowId == WINDOW_FULLSCREEN_GAME);
37 // Check if game is in the OSD dialog
38 const bool bInMenu = (dialogId != WINDOW_FULLSCREEN_GAME);
40 // Check if game should play in the background of dialog
41 const bool bInBackground = GAME::CDialogGameOSD::PlayInBackground(dialogId);
43 GuiState nextState = NextState(bFullscreen, bInMenu, bInBackground);
44 if (nextState != m_state)
46 m_state = nextState;
48 double targetSpeed = GetTargetSpeed(m_state);
49 if (m_previousSpeed != targetSpeed)
51 m_previousSpeed = targetSpeed;
52 m_callback.SetPlaybackSpeed(targetSpeed);
55 m_callback.EnableInput(AcceptsInput(m_state));
59 CGUIPlaybackControl::GuiState CGUIPlaybackControl::NextState(bool bFullscreen,
60 bool bInMenu,
61 bool bInBackground)
63 GuiState newState = m_state;
65 switch (m_state)
67 case GuiState::UNKNOWN:
69 // Wait for game to enter fullscreen
70 if (bFullscreen)
71 newState = GuiState::FULLSCREEN;
72 break;
74 case GuiState::FULLSCREEN:
76 if (bInMenu)
78 if (bInBackground)
79 newState = GuiState::MENU_PLAYING;
80 else
81 newState = GuiState::MENU_PAUSED;
83 break;
85 case GuiState::MENU_PAUSED:
87 if (!bInMenu)
88 newState = GuiState::FULLSCREEN;
89 else if (bInBackground)
90 newState = GuiState::MENU_PLAYING;
91 break;
93 case GuiState::MENU_PLAYING:
95 if (!bInBackground)
97 if (!bInMenu)
98 newState = GuiState::FULLSCREEN;
99 else
100 newState = GuiState::MENU_PAUSED;
102 break;
104 default:
105 break;
108 return newState;
111 double CGUIPlaybackControl::GetTargetSpeed(GuiState state)
113 double targetSpeed = 0.0;
115 switch (state)
117 case GuiState::FULLSCREEN:
119 targetSpeed = 1.0;
120 break;
122 case GuiState::MENU_PAUSED:
124 targetSpeed = 0.0;
125 break;
127 case GuiState::MENU_PLAYING:
129 targetSpeed = 1.0;
130 break;
132 default:
133 break;
136 return targetSpeed;
139 bool CGUIPlaybackControl::AcceptsInput(GuiState state)
141 bool bEnableInput = false;
143 switch (state)
145 case GuiState::FULLSCREEN:
147 bEnableInput = true;
148 break;
150 default:
151 break;
154 return bEnableInput;