Skip to content

Commit

Permalink
[PVR] PVRManager: Factor out playback state functionality into its ow…
Browse files Browse the repository at this point in the history
…n class.
  • Loading branch information
ksooo committed Oct 2, 2019
1 parent a1b36fd commit 992bf7b
Show file tree
Hide file tree
Showing 21 changed files with 683 additions and 538 deletions.
5 changes: 3 additions & 2 deletions xbmc/interfaces/json-rpc/PVROperations.cpp
Expand Up @@ -11,6 +11,7 @@
#include "ServiceBroker.h"
#include "pvr/PVRGUIActions.h"
#include "pvr/PVRManager.h"
#include "pvr/PVRPlaybackState.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/channels/PVRChannelGroups.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
Expand Down Expand Up @@ -199,7 +200,7 @@ JSONRPC_STATUS CPVROperations::Record(const std::string &method, ITransportLayer
CVariant channel = parameterObject["channel"];
if (channel.isString() && channel.asString() == "current")
{
pChannel = CServiceBroker::GetPVRManager().GetPlayingChannel();
pChannel = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
if (!pChannel)
return InternalError;
}
Expand Down Expand Up @@ -252,7 +253,7 @@ JSONRPC_STATUS CPVROperations::GetPropertyValue(const std::string &property, CVa
else if (property == "recording")
{
if (started)
result = CServiceBroker::GetPVRManager().IsRecording();
result = CServiceBroker::GetPVRManager().PlaybackState()->IsRecording();
else
result = false;
}
Expand Down
26 changes: 16 additions & 10 deletions xbmc/interfaces/json-rpc/PlayerOperations.cpp
Expand Up @@ -28,6 +28,7 @@
#include "pictures/GUIWindowSlideShow.h"
#include "pvr/PVRGUIActions.h"
#include "pvr/PVRManager.h"
#include "pvr/PVRPlaybackState.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "pvr/epg/EpgInfoTag.h"
Expand Down Expand Up @@ -149,12 +150,12 @@ JSONRPC_STATUS CPlayerOperations::GetItem(const std::string &method, ITransportL
case Video:
case Audio:
{
fileItem = CFileItemPtr(new CFileItem(g_application.CurrentFileItem()));
fileItem = std::make_shared<CFileItem>(g_application.CurrentFileItem());
if (IsPVRChannel())
{
std::shared_ptr<CPVRChannel> currentChannel(CServiceBroker::GetPVRManager().GetPlayingChannel());
const std::shared_ptr<CPVRChannel> currentChannel = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
if (currentChannel)
fileItem = CFileItemPtr(new CFileItem(currentChannel));
fileItem = std::make_shared<CFileItem>(currentChannel);
}
else if (player == Video)
{
Expand Down Expand Up @@ -1198,9 +1199,12 @@ int CPlayerOperations::GetActivePlayers()
{
int activePlayers = 0;

if (g_application.GetAppPlayer().IsPlayingVideo() || CServiceBroker::GetPVRManager().IsPlayingTV() || CServiceBroker::GetPVRManager().IsPlayingRecording())
if (g_application.GetAppPlayer().IsPlayingVideo() ||
CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingTV() ||
CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingRecording())
activePlayers |= Video;
if (g_application.GetAppPlayer().IsPlayingAudio() || CServiceBroker::GetPVRManager().IsPlayingRadio())
if (g_application.GetAppPlayer().IsPlayingAudio() ||
CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingRadio())
activePlayers |= Audio;
if (CServiceBroker::GetGUI()->GetWindowManager().IsWindowActive(WINDOW_SLIDESHOW))
activePlayers |= Picture;
Expand Down Expand Up @@ -1895,17 +1899,19 @@ double CPlayerOperations::ParseTimeInSeconds(const CVariant &time)

bool CPlayerOperations::IsPVRChannel()
{
return CServiceBroker::GetPVRManager().IsPlayingTV() || CServiceBroker::GetPVRManager().IsPlayingRadio();
const std::shared_ptr<CPVRPlaybackState> state = CServiceBroker::GetPVRManager().PlaybackState();
return state->IsPlayingTV() || state->IsPlayingRadio();
}

std::shared_ptr<CPVREpgInfoTag> CPlayerOperations::GetCurrentEpg()
{
if (!CServiceBroker::GetPVRManager().IsPlayingTV() && !CServiceBroker::GetPVRManager().IsPlayingRadio())
return std::shared_ptr<CPVREpgInfoTag>();
const std::shared_ptr<CPVRPlaybackState> state = CServiceBroker::GetPVRManager().PlaybackState();
if (!state->IsPlayingTV() && !state->IsPlayingRadio())
return {};

std::shared_ptr<CPVRChannel> currentChannel(CServiceBroker::GetPVRManager().GetPlayingChannel());
const std::shared_ptr<CPVRChannel> currentChannel = state->GetPlayingChannel();
if (!currentChannel)
return std::shared_ptr<CPVREpgInfoTag>();
return {};

return currentChannel->GetEPGNow();
}
2 changes: 2 additions & 0 deletions xbmc/pvr/CMakeLists.txt
Expand Up @@ -15,6 +15,7 @@ set(SOURCES PVRActionListener.cpp
PVRGUITimerInfo.cpp
PVRGUITimesInfo.cpp
PVRStreamProperties.cpp
PVRPlaybackState.cpp
PVRThumbLoader.cpp)

set(HEADERS PVRActionListener.h
Expand All @@ -34,6 +35,7 @@ set(HEADERS PVRActionListener.h
PVRGUITimerInfo.h
PVRGUITimesInfo.h
PVRStreamProperties.h
PVRPlaybackState.h
PVRThumbLoader.h)

core_add_library(pvr)
7 changes: 4 additions & 3 deletions xbmc/pvr/PVRActionListener.cpp
Expand Up @@ -19,6 +19,7 @@
#include "messaging/ApplicationMessenger.h"
#include "pvr/PVRGUIActions.h"
#include "pvr/PVRManager.h"
#include "pvr/PVRPlaybackState.h"
#include "pvr/addons/PVRClients.h"
#include "pvr/channels/PVRChannel.h"
#include "pvr/channels/PVRChannelGroup.h"
Expand Down Expand Up @@ -90,8 +91,8 @@ ChannelSwitchMode CPVRActionListener::GetChannelSwitchMode(int iAction)
bool CPVRActionListener::OnAction(const CAction& action)
{
bool bIsJumpSMS = false;
bool bIsPlayingPVR(CServiceBroker::GetPVRManager().IsPlaying() &&
g_application.CurrentFileItem().HasPVRChannelInfoTag());
bool bIsPlayingPVR = CServiceBroker::GetPVRManager().PlaybackState()->IsPlaying() &&
g_application.CurrentFileItem().HasPVRChannelInfoTag();

switch (action.GetID())
{
Expand Down Expand Up @@ -244,7 +245,7 @@ bool CPVRActionListener::OnAction(const CAction& action)
int iChannelNumber = static_cast<int>(action.GetAmount(0));
int iSubChannelNumber = static_cast<int>(action.GetAmount(1));

const std::shared_ptr<CPVRChannel> currentChannel = CServiceBroker::GetPVRManager().GetPlayingChannel();
const std::shared_ptr<CPVRChannel> currentChannel = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
const std::shared_ptr<CPVRChannelGroup> selectedGroup = CServiceBroker::GetPVRManager().ChannelGroups()->Get(currentChannel->IsRadio())->GetSelectedGroup();
const std::shared_ptr<CPVRChannel> channel = selectedGroup->GetByChannelNumber(CPVRChannelNumber(iChannelNumber, iSubChannelNumber));

Expand Down
49 changes: 25 additions & 24 deletions xbmc/pvr/PVRGUIActions.cpp
Expand Up @@ -35,6 +35,7 @@
#include "pvr/PVREventLogJob.h"
#include "pvr/PVRItem.h"
#include "pvr/PVRManager.h"
#include "pvr/PVRPlaybackState.h"
#include "pvr/PVRStreamProperties.h"
#include "pvr/addons/PVRClients.h"
#include "pvr/channels/PVRChannel.h"
Expand Down Expand Up @@ -592,7 +593,7 @@ namespace PVR

bool CPVRGUIActions::ToggleRecordingOnPlayingChannel()
{
const std::shared_ptr<CPVRChannel> channel = CServiceBroker::GetPVRManager().GetPlayingChannel();
const std::shared_ptr<CPVRChannel> channel = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
if (channel && channel->CanRecord())
return SetRecordingOnChannel(channel, !CServiceBroker::GetPVRManager().Timers()->IsRecordingOnChannel(*channel));

Expand Down Expand Up @@ -1252,7 +1253,7 @@ namespace PVR
if (!recording)
return false;

if (CServiceBroker::GetPVRManager().IsPlayingRecording(recording))
if (CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingRecording(recording))
{
CGUIMessage msg(GUI_MSG_FULLSCREEN, 0, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow());
CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg);
Expand All @@ -1274,7 +1275,7 @@ namespace PVR
if (!epgTag)
return false;

if (CServiceBroker::GetPVRManager().IsPlayingEpgTag(epgTag))
if (CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingEpgTag(epgTag))
{
CGUIMessage msg(GUI_MSG_FULLSCREEN, 0, CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow());
CServiceBroker::GetGUI()->GetWindowManager().SendMessage(msg);
Expand All @@ -1294,12 +1295,12 @@ namespace PVR
const std::shared_ptr<CPVRChannel> channel(CPVRItem(item).GetChannel());
if (channel)
{
bool bSwitchToFullscreen = CServiceBroker::GetPVRManager().IsPlayingChannel(channel);
bool bSwitchToFullscreen = CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingChannel(channel);

if (!bSwitchToFullscreen)
{
recording = CServiceBroker::GetPVRManager().Recordings()->GetRecordingForEpgTag(channel->GetEPGNow());
bSwitchToFullscreen = recording && CServiceBroker::GetPVRManager().IsPlayingRecording(recording);
bSwitchToFullscreen = recording && CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingRecording(recording);
}

if (bSwitchToFullscreen)
Expand Down Expand Up @@ -1363,7 +1364,7 @@ namespace PVR
{
case PlaybackTypeRadio:
{
if (CServiceBroker::GetPVRManager().IsPlayingRadio())
if (CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingRadio())
return true;

const std::shared_ptr<CPVRChannelGroup> allGroup = CServiceBroker::GetPVRManager().ChannelGroups()->GetGroupAllRadio();
Expand All @@ -1375,7 +1376,7 @@ namespace PVR
}
case PlaybackTypeTV:
{
if (CServiceBroker::GetPVRManager().IsPlayingTV())
if (CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingTV())
return true;

const std::shared_ptr<CPVRChannelGroup> allGroup = CServiceBroker::GetPVRManager().ChannelGroups()->GetGroupAllTV();
Expand All @@ -1385,7 +1386,7 @@ namespace PVR
break;
}
default:
if (CServiceBroker::GetPVRManager().IsPlaying())
if (CServiceBroker::GetPVRManager().PlaybackState()->IsPlaying())
return true;

channel = CServiceBroker::GetPVRManager().ChannelGroups()->GetLastPlayedChannel();
Expand All @@ -1400,7 +1401,7 @@ namespace PVR
else
{
// if we don't, find the active channel group of the demanded type and play it's first channel
const std::shared_ptr<CPVRChannelGroup> channelGroup(CServiceBroker::GetPVRManager().GetPlayingGroup(bIsRadio));
const std::shared_ptr<CPVRChannelGroup> channelGroup = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingGroup(bIsRadio);
if (channelGroup)
{
// try to start playback of first channel in this group
Expand Down Expand Up @@ -1449,7 +1450,7 @@ namespace PVR
}

CLog::Log(LOGNOTICE, "PVR is starting playback of channel '%s'", channel->ChannelName().c_str());
CServiceBroker::GetPVRManager().SetPlayingGroup(group);
CServiceBroker::GetPVRManager().PlaybackState()->SetPlayingGroup(group);
return SwitchToChannel(std::make_shared<CFileItem>(channel), true);
}

Expand Down Expand Up @@ -1650,7 +1651,7 @@ namespace PVR
pDlgProgress->Open();
pDlgProgress->Progress();

if (CServiceBroker::GetPVRManager().IsPlaying())
if (CServiceBroker::GetPVRManager().PlaybackState()->IsPlaying())
{
CLog::Log(LOGNOTICE, "PVR is stopping playback for %s database reset", bResetEPGOnly ? "EPG" : "PVR and EPG");
CApplicationMessenger::GetInstance().SendMsg(TMSG_MEDIA_STOP);
Expand Down Expand Up @@ -1981,7 +1982,7 @@ namespace PVR
return;
}

if (CServiceBroker::GetPVRManager().IsPlayingChannel(timer->Channel()))
if (CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingChannel(timer->Channel()))
{
// no need for an announcement. channel in question is already playing.
return;
Expand Down Expand Up @@ -2122,7 +2123,7 @@ namespace PVR
if (m_settings.GetBoolValue(CSettings::SETTING_PVRMANAGER_PRESELECTPLAYINGCHANNEL))
{
// if preselect playing channel is activated, return the path of the playing channel, if any.
const std::shared_ptr<CPVRChannel> playingChannel(CServiceBroker::GetPVRManager().GetPlayingChannel());
const std::shared_ptr<CPVRChannel> playingChannel = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
if (playingChannel && playingChannel->IsRadio() == bRadio)
return playingChannel->Path();
}
Expand All @@ -2136,7 +2137,7 @@ namespace PVR
time_t playbackStartTime = CServiceBroker::GetDataCacheCore().GetStartTime();
if (playbackStartTime > 0)
{
const std::shared_ptr<CPVRChannel> playingChannel = CServiceBroker::GetPVRManager().GetPlayingChannel();
const std::shared_ptr<CPVRChannel> playingChannel = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
if (playingChannel)
{
time_t nextTime = 0;
Expand Down Expand Up @@ -2173,7 +2174,7 @@ namespace PVR
time_t playbackStartTime = CServiceBroker::GetDataCacheCore().GetStartTime();
if (playbackStartTime > 0)
{
const std::shared_ptr<CPVRChannel> playingChannel = CServiceBroker::GetPVRManager().GetPlayingChannel();
const std::shared_ptr<CPVRChannel> playingChannel = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
if (playingChannel)
{
time_t prevTime = 0;
Expand Down Expand Up @@ -2258,7 +2259,7 @@ namespace PVR
void CPVRChannelSwitchingInputHandler::GetChannelNumbers(std::vector<std::string>& channelNumbers)
{
CPVRManager& pvrMgr = CServiceBroker::GetPVRManager();
const std::shared_ptr<CPVRChannel> playingChannel = pvrMgr.GetPlayingChannel();
const std::shared_ptr<CPVRChannel> playingChannel = pvrMgr.PlaybackState()->GetPlayingChannel();
if (playingChannel)
{
const std::shared_ptr<CPVRChannelGroup> group = pvrMgr.ChannelGroups()->GetGroupAll(playingChannel->IsRadio());
Expand All @@ -2276,16 +2277,16 @@ namespace PVR

void CPVRChannelSwitchingInputHandler::SwitchToChannel(const CPVRChannelNumber& channelNumber)
{
if (channelNumber.IsValid() && CServiceBroker::GetPVRManager().IsPlaying())
if (channelNumber.IsValid() && CServiceBroker::GetPVRManager().PlaybackState()->IsPlaying())
{
const std::shared_ptr<CPVRChannel> playingChannel(CServiceBroker::GetPVRManager().GetPlayingChannel());
const std::shared_ptr<CPVRChannel> playingChannel = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
if (playingChannel)
{
if (channelNumber != playingChannel->ChannelNumber())
{
// channel number present in playing group?
bool bRadio = playingChannel->IsRadio();
const std::shared_ptr<CPVRChannelGroup> group = CServiceBroker::GetPVRManager().GetPlayingGroup(bRadio);
const std::shared_ptr<CPVRChannelGroup> group = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingGroup(bRadio);
std::shared_ptr<CPVRChannel> channel = group->GetByChannelNumber(channelNumber);

if (!channel)
Expand All @@ -2299,7 +2300,7 @@ namespace PVR
if (channel)
{
// switch channel group
CServiceBroker::GetPVRManager().SetPlayingGroup(currentGroup);
CServiceBroker::GetPVRManager().PlaybackState()->SetPlayingGroup(currentGroup);
break;
}
}
Expand All @@ -2320,15 +2321,15 @@ namespace PVR

void CPVRChannelSwitchingInputHandler::SwitchToPreviousChannel()
{
if (CServiceBroker::GetPVRManager().IsPlaying())
if (CServiceBroker::GetPVRManager().PlaybackState()->IsPlaying())
{
const std::shared_ptr<CPVRChannel> playingChannel(CServiceBroker::GetPVRManager().GetPlayingChannel());
const std::shared_ptr<CPVRChannel> playingChannel = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
if (playingChannel)
{
const std::shared_ptr<CPVRChannelGroup> group(CServiceBroker::GetPVRManager().ChannelGroups()->GetPreviousPlayedGroup());
const std::shared_ptr<CPVRChannelGroup> group = CServiceBroker::GetPVRManager().ChannelGroups()->GetPreviousPlayedGroup();
if (group)
{
CServiceBroker::GetPVRManager().SetPlayingGroup(group);
CServiceBroker::GetPVRManager().PlaybackState()->SetPlayingGroup(group);
const std::shared_ptr<CPVRChannel> channel = group->GetLastPlayedChannel(playingChannel->ChannelID());
if (channel)
{
Expand Down
7 changes: 4 additions & 3 deletions xbmc/pvr/PVRGUIChannelNavigator.cpp
Expand Up @@ -14,6 +14,7 @@
#include "guilib/GUIComponent.h"
#include "pvr/PVRGUIActions.h"
#include "pvr/PVRManager.h"
#include "pvr/PVRPlaybackState.h"
#include "pvr/channels/PVRChannelGroup.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
Expand Down Expand Up @@ -117,12 +118,12 @@ namespace PVR

std::shared_ptr<CPVRChannel> CPVRGUIChannelNavigator::GetNextOrPrevChannel(bool bNext)
{
const bool bPlayingRadio = CServiceBroker::GetPVRManager().IsPlayingRadio();
const bool bPlayingTV = CServiceBroker::GetPVRManager().IsPlayingTV();
const bool bPlayingRadio = CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingRadio();
const bool bPlayingTV = CServiceBroker::GetPVRManager().PlaybackState()->IsPlayingTV();

if (bPlayingTV || bPlayingRadio)
{
const std::shared_ptr<CPVRChannelGroup> group = CServiceBroker::GetPVRManager().GetPlayingGroup(bPlayingRadio);
const std::shared_ptr<CPVRChannelGroup> group = CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingGroup(bPlayingRadio);
if (group)
{
CSingleLock lock(m_critSection);
Expand Down

0 comments on commit 992bf7b

Please sign in to comment.