Skip to content

Commit

Permalink
Wakeup improvements (#236)
Browse files Browse the repository at this point in the history
* Add channel error return

Add return error if core requests channels while not connected.  Will occur after wake.

* Wake connection improvement

After wake network and local server may not be available try fast poll to speed up connection

* Fanart changes

Default recording request to fanart.  Override default EPG art request to landscape.
  • Loading branch information
emveepee authored Jun 7, 2023
1 parent 3cb5341 commit 4237431
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pvr.nextpvr/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.nextpvr"
version="21.0.0"
version="21.0.1"
name="NextPVR PVR Client"
provider-name="Graeme Blackley">
<requires>@ADDON_DEPENDS@
Expand Down
5 changes: 5 additions & 0 deletions pvr.nextpvr/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v21.0.1
- Return error if channel calls are made when not connected
- Fast poll for servers after returning from sleep
- Changes to backend art delivery, request fanart if possible

v21.0.0
- Connection change, start in connnecting state, defer unreachable state.

Expand Down
5 changes: 4 additions & 1 deletion src/BackendRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,18 @@ namespace NextPVR
// return is same on timeout or http return ie 404, 500.
tinyxml2::XMLError retError = tinyxml2::XML_ERROR_FILE_NOT_FOUND;
std::unique_lock<std::mutex> lock(m_mutexRequest);
// build request string, adding SID if requred
// build request string, adding SID if required
std::string URL;

if (IsActiveSID())
URL = kodi::tools::StringUtils::Format("%s/service?method=%s&sid=%s", m_settings->m_urlBase, resource.c_str(), GetSID());
else if (kodi::tools::StringUtils::StartsWith(resource, "session"))
URL = kodi::tools::StringUtils::Format("%s/service?method=%s", m_settings->m_urlBase, resource.c_str());
else
{
kodi::Log(ADDON_LOG_ERROR, "%s called before session.login", resource.c_str());
return tinyxml2::XML_ERROR_FILE_COULD_NOT_BE_OPENED;
}

if (!compressed)
URL += "|Accept-Encoding=identity";
Expand Down
25 changes: 20 additions & 5 deletions src/Channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ PVR_ERROR Channels::GetChannels(bool radio, kodi::addon::PVRChannelsResultSet& r
{
if (radio && !m_settings->m_showRadio)
return PVR_ERROR_NO_ERROR;

PVR_ERROR returnValue = PVR_ERROR_NO_ERROR;
std::string stream;
std::map<int, std::pair<bool, bool>>::iterator itr = m_channelDetails.begin();
while (itr != m_channelDetails.end())
Expand Down Expand Up @@ -160,9 +160,14 @@ PVR_ERROR Channels::GetChannels(bool radio, kodi::addon::PVRChannelsResultSet& r
results.Add(tag);
}
}
return PVR_ERROR_NO_ERROR;
else
{
returnValue = PVR_ERROR_SERVER_ERROR;
}
return returnValue;
}


/************************************************************/
/** Channel group handling **/

Expand All @@ -187,6 +192,7 @@ PVR_ERROR Channels::GetChannelGroups(bool radio, kodi::addon::PVRChannelGroupsRe
if (radio && !m_settings->m_showRadio)
return PVR_ERROR_NO_ERROR;

PVR_ERROR returnValue = PVR_ERROR_NO_ERROR;
int priority = 1;

std::unordered_set<std::string>& selectedGroups = radio ? m_radioGroups : m_tvGroups;
Expand Down Expand Up @@ -235,6 +241,10 @@ PVR_ERROR Channels::GetChannelGroups(bool radio, kodi::addon::PVRChannelGroupsRe
}
}
}
else
{
return PVR_ERROR_SERVER_ERROR;
}

// Many users won't have radio groups
if (selectedGroups.size() == 0)
Expand Down Expand Up @@ -265,14 +275,15 @@ PVR_ERROR Channels::GetChannelGroups(bool radio, kodi::addon::PVRChannelGroupsRe
else
{
kodi::Log(ADDON_LOG_DEBUG, "No Channel Group");
returnValue = PVR_ERROR_SERVER_ERROR;
}

return PVR_ERROR_NO_ERROR;
return returnValue;
}

PVR_ERROR Channels::GetChannelGroupMembers(const kodi::addon::PVRChannelGroup& group, kodi::addon::PVRChannelGroupMembersResultSet& results)
{
std::string request;
PVR_ERROR returnValue = PVR_ERROR_SERVER_ERROR;

if (group.GetGroupName() == GetAllChannelsGroupName(group.GetIsRadio()))
{
Expand Down Expand Up @@ -304,7 +315,11 @@ PVR_ERROR Channels::GetChannelGroupMembers(const kodi::addon::PVRChannelGroup& g
}
}
}
return PVR_ERROR_NO_ERROR;
else
{
returnValue = PVR_ERROR_SERVER_ERROR;
}
return returnValue;
}

const std::string Channels::GetAllChannelsGroupName(bool radio)
Expand Down
3 changes: 3 additions & 0 deletions src/EPG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ PVR_ERROR EPG::GetEPGForChannel(int channelUid, time_t start, time_t end, kodi::
artworkPath = kodi::tools::StringUtils::Format("%s/service?method=channel.show.artwork&sid=%s&name=%s", m_settings->m_urlBase, m_request.GetSID(), UriEncode(title).c_str());
else
artworkPath = kodi::tools::StringUtils::Format("%s/service?method=channel.show.artwork&name=%s", m_settings->m_urlBase, UriEncode(title).c_str());

if (m_settings->m_guideArtPortrait)
artworkPath += "&prefer=poster";
else
artworkPath += "&prefer=landscape";
broadcast.SetIconPath(artworkPath);
}
std::string sGenre;
Expand Down
5 changes: 2 additions & 3 deletions src/Recordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,8 @@ bool Recordings::UpdatePvrRecording(const tinyxml2::XMLNode* pRecordingNode, kod
artworkPath = kodi::tools::StringUtils::Format("%s/service?method=channel.show.artwork&sid=%s&name=%s", m_settings->m_urlBase, m_request.GetSID(), name.c_str());
else
artworkPath = kodi::tools::StringUtils::Format("%s/service?method=channel.show.artwork&name=%s", m_settings->m_urlBase, name.c_str());
tag.SetFanartPath(artworkPath);
artworkPath += "&prefer=poster";
tag.SetThumbnailPath(artworkPath);
tag.SetFanartPath(artworkPath + "&prefer=fanart");
tag.SetThumbnailPath(artworkPath + "&prefer=poster");
}
if (XMLUtils::GetAdditiveString(pRecordingNode->FirstChildElement("genres"), "genre", EPG_STRING_TOKEN_SEPARATOR, buffer, true))
{
Expand Down
28 changes: 19 additions & 9 deletions src/pvrclient-nextpvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,8 @@ bool cPVRClientNextPVR::IsUp()
{
if (time(nullptr) > m_nextServerCheck)
{
UpdateServerCheck();
Connect(false);
if (m_coreState == PVR_CONNECTION_STATE_CONNECTING && (time(nullptr) > m_firstSessionInitiate + FAST_SLOW_POLL_TRANSITION))
if (m_coreState == PVR_CONNECTION_STATE_CONNECTING || m_coreState == PVR_CONNECTION_STATE_DISCONNECTED && (time(nullptr) > m_firstSessionInitiate + FAST_SLOW_POLL_TRANSITION))
SetConnectionState(PVR_CONNECTION_STATE_SERVER_UNREACHABLE);
}
}
Expand Down Expand Up @@ -454,30 +453,29 @@ PVR_ERROR cPVRClientNextPVR::OnSystemSleep()

PVR_ERROR cPVRClientNextPVR::OnSystemWake()
{
m_firstSessionInitiate = 0;
m_firstSessionInitiate = time(nullptr);
m_nextServerCheck = m_firstSessionInitiate + FAST_SLOW_POLL_TRANSITION;
kodi::Log(ADDON_LOG_DEBUG, "NextPVR wake");
// allow time for core to reset
m_lastRecordingUpdateTime = time(nullptr) + SLOW_CONNECT_POLL;

// don't trigger updates core does it

if (m_request.IsActiveSID() && m_request.PingBackend())
{
m_connectionState = PVR_CONNECTION_STATE_CONNECTED;
m_bConnected = true;
return PVR_ERROR_NO_ERROR;
}
m_nextServerCheck = 0;

SetConnectionState(PVR_CONNECTION_STATE_CONNECTING);
// Core only allows PVR_CONNECTION_STATE_CONNECTING once
SetConnectionState(PVR_CONNECTION_STATE_DISCONNECTED);
m_connectionState = PVR_CONNECTION_STATE_CONNECTING;

if (Connect() != ADDON_STATUS_OK)
{
SetConnectionState(PVR_CONNECTION_STATE_ACCESS_DENIED);
return PVR_ERROR_SERVER_ERROR;
}

kodi::Log(ADDON_LOG_INFO, "On NextPVR Wake %d", m_bConnected, m_connectionState);
kodi::Log(ADDON_LOG_INFO, "On NextPVR Wake %d %d", m_bConnected, m_connectionState);
return PVR_ERROR_NO_ERROR;
}

Expand Down Expand Up @@ -895,6 +893,12 @@ PVR_ERROR cPVRClientNextPVR::GetEPGForChannel(int channelUid, time_t start, time
/** PVR Channel Functions **/
PVR_ERROR cPVRClientNextPVR::GetChannelsAmount(int& amount)
{
if (m_connectionState != PVR_CONNECTION_STATE_CONNECTED)
{
kodi::Log(ADDON_LOG_ERROR, "GetChannelsAmount called while disconnected");
return PVR_ERROR_SERVER_ERROR;
}

amount = m_channels.GetNumChannels();
return PVR_ERROR_NO_ERROR;
}
Expand All @@ -910,6 +914,12 @@ PVR_ERROR cPVRClientNextPVR::GetChannels(bool radio, kodi::addon::PVRChannelsRes

PVR_ERROR cPVRClientNextPVR::GetChannelGroupsAmount(int& amount)
{
if (m_connectionState != PVR_CONNECTION_STATE_CONNECTED)
{
kodi::Log(ADDON_LOG_ERROR, "GetChannelGroupsAmount called while disconnected");
return PVR_ERROR_SERVER_ERROR;
}

m_channels.GetChannelGroupsAmount(amount);
return PVR_ERROR_NO_ERROR;
}
Expand Down

0 comments on commit 4237431

Please sign in to comment.