Skip to content

Commit

Permalink
Merge pull request #823 from phunkyfish/startup-conn-mgr
Browse files Browse the repository at this point in the history
Add connection manager support to wait for a valid M3U file before starting the add-on instance
  • Loading branch information
phunkyfish committed Jan 4, 2024
2 parents 0d0f22e + 35071a5 commit cc885d2
Show file tree
Hide file tree
Showing 15 changed files with 431 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(IPTV_SOURCES src/addon.cpp
src/iptvsimple/CatchupController.cpp
src/iptvsimple/Channels.cpp
src/iptvsimple/ChannelGroups.cpp
src/iptvsimple/ConnectionManager.cpp
src/iptvsimple/Epg.cpp
src/iptvsimple/InstanceSettings.cpp
src/iptvsimple/Media.cpp
Expand All @@ -52,7 +53,9 @@ set(IPTV_HEADERS src/addon.h
src/iptvsimple/CatchupController.h
src/iptvsimple/Channels.h
src/iptvsimple/ChannelGroups.h
src/iptvsimple/ConnectionManager.h
src/iptvsimple/Epg.h
src/iptvsimple/IConnectionListener.h
src/iptvsimple/InstanceSettings.h
src/iptvsimple/Media.h
src/iptvsimple/PlaylistLoader.h
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ General settings required for the addon to function.
- `Once per day` - Refresh the files once per day.
* **Refresh interval**: If auto refresh mode is `Repeated refresh` refresh the files every time this number of minutes passes. Max 120 minutes.
* **Refresh hour (24h)**: If auto refresh mode is `Once per day` refresh the files every time this hour of the day is reached.
* **M3U Check Interval**: When checking for a valid M3U file, the length of time to wait between attempts. Note that a valid file will only be checked for on startup and once a valid file is found all checks stop.
* **M3U Check Timeout**: When checking for a valid M3U file, the length of time to wait before timing out the attempt.
* **Default provider name**: If provided this value will be used as the provider name if one was not provided in the M3U. It can be used in combination with the provider mapping file which can supply type, icon path, country code and language code fields.
* **Enable provider mapping**: If enabled any provider name read from the M3U or the default provider name will be used to read further metadata from the mapping file. The metadata includes custom name, type, icon path, country code and language code.
* **Provider name mapping file**: The config file to map provider names received from the M3U or the default provider name to custom name, icons etc. The default file is `providerMappings.xml`.
Expand Down
2 changes: 1 addition & 1 deletion pvr.iptvsimple/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.iptvsimple"
version="21.6.0"
version="21.7.0"
name="IPTV Simple Client"
provider-name="nightik and Ross Nicholson">
<requires>@ADDON_DEPENDS@
Expand Down
4 changes: 4 additions & 0 deletions pvr.iptvsimple/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v21.7.0
- Add connection manager support to wait for a valid M3U file before starting the add-on instance
- The minimum refresh interval for the M3U should be 1 minutes and not zero, as that would be infinite refresh

v21.6.0
- Only reset channel group list when a channel URL is read from M3U Playlist
- Modify EXTGRP behaviour so it is a begin directive for channels groups, i.e. it carries across channels unless reset by an empty EXTGRP directive or any group-title tag for a EXTINF channel directive
Expand Down
33 changes: 31 additions & 2 deletions pvr.iptvsimple/resources/instance-settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<level>1</level>
<default>60</default>
<constraints>
<minimum>0</minimum>
<minimum>1</minimum>
<step>10</step>
<maximum>120</maximum>
</constraints>
Expand Down Expand Up @@ -106,7 +106,36 @@
</setting>
</group>

<group id="3" label="30006">
<group id="3" label="30078">
<setting id="connectioncheckinterval" type="integer" label="30080" help="30629">
<level>1</level>
<default>10</default>
<constraints>
<minimum>1</minimum>
<step>1</step>
<maximum>60</maximum>
</constraints>
<control type="slider" format="integer">
<popup>true</popup>
<formatlabel>14045</formatlabel>
</control>
</setting>
<setting id="connectionchecktimeout" type="integer" label="30079" help="30628">
<level>2</level>
<default>20</default>
<constraints>
<minimum>1</minimum>
<step>1</step>
<maximum>60</maximum>
</constraints>
<control type="slider" format="integer">
<popup>true</popup>
<formatlabel>14045</formatlabel>
</control>
</setting>
</group>

<group id="4" label="30006">
<setting id="defaultProviderName" type="string" label="30007" help="30740">
<level>2</level>
<default></default>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,22 @@ msgctxt "#30077"
msgid "Ignore Case for EPG Channel IDs"
msgstr ""

#empty strings from id 30078 to 30099
#. label-group: General - M3U Startup Check
msgctxt "#30078"
msgid "M3U Startup Check"
msgstr ""

#. label: Catchup - connectCheckTimoutSecs
msgctxt "#30079"
msgid "Timeout for check"
msgstr ""

#. label: Catchup - connectCheckIntervalSecs
msgctxt "#30080"
msgid "Interval for check"
msgstr ""

#empty strings from id 30081 to 30099

#. label-category: catchup
#. label-group: Catchup - Catchup
Expand Down Expand Up @@ -828,7 +843,17 @@ msgctxt "#30627"
msgid "Ignore Case for EPG Channel IDs, also known as tvg-id's, when matching channels to EPG entries. If disabled, only case senitive matching will be used."
msgstr ""

#empty strings from id 30628 to 30639
#. help: EPG Settings - connectionCheckTimeoutSecs
msgctxt "#30628"
msgid "When checking for a valid M3U file, the length of time to wait before timing out the attempt."
msgstr ""

#. help: EPG Settings - connectionCheckIntervalSecs
msgctxt "#30629"
msgid "When checking for a valid M3U file, the length of time to wait between attempts. Note that a valid file will only be checked for on startup and once a valid file is found all checks stop."
msgstr ""

#empty strings from id 30630 to 30639

#. help info - Channel Logos

Expand Down
63 changes: 47 additions & 16 deletions src/IptvSimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,45 @@ using namespace iptvsimple::data;
using namespace iptvsimple::utilities;
using namespace kodi::tools;

IptvSimple::IptvSimple(const kodi::addon::IInstanceInfo& instance) : kodi::addon::CInstancePVRClient(instance), m_settings(new InstanceSettings(*this, instance))
IptvSimple::IptvSimple(const kodi::addon::IInstanceInfo& instance) : iptvsimple::IConnectionListener(instance), m_settings(new InstanceSettings(*this, instance))
{
m_channels.Clear();
m_channelGroups.Clear();
m_providers.Clear();
m_epg.Clear();
m_media.Clear();
connectionManager = new ConnectionManager(*this, m_settings);
}

bool IptvSimple::Initialise()
IptvSimple::~IptvSimple()
{
Logger::Log(LEVEL_DEBUG, "%s Stopping update thread...", __FUNCTION__);
m_running = false;
if (m_thread.joinable())
m_thread.join();

std::lock_guard<std::mutex> lock(m_mutex);
m_channels.Clear();
m_channelGroups.Clear();
m_providers.Clear();
m_epg.Clear();

if (connectionManager)
connectionManager->Stop();
delete connectionManager;
}

/* **************************************************************************
* Connection
* *************************************************************************/

void IptvSimple::ConnectionLost()
{
Logger::Log(LEVEL_INFO, "%s Could not validiate M3U after startup, but ignoring as startup is all we care about.", __func__);
}

void IptvSimple::ConnectionEstablished()
{
m_channels.Init();
m_channelGroups.Init();
m_providers.Init();
Expand All @@ -50,10 +76,29 @@ bool IptvSimple::Initialise()

m_running = true;
m_thread = std::thread([&] { Process(); });
}

bool IptvSimple::Initialise()
{
std::lock_guard<std::mutex> lock(m_mutex);

connectionManager->Start();

return true;
}

PVR_ERROR IptvSimple::OnSystemSleep()
{
connectionManager->OnSleep();
return PVR_ERROR_NO_ERROR;
}

PVR_ERROR IptvSimple::OnSystemWake()
{
connectionManager->OnWake();
return PVR_ERROR_NO_ERROR;
}

PVR_ERROR IptvSimple::GetCapabilities(kodi::addon::PVRCapabilities& capabilities)
{
capabilities.SetSupportsEPG(true);
Expand Down Expand Up @@ -126,20 +171,6 @@ void IptvSimple::Process()
}
}

IptvSimple::~IptvSimple()
{
Logger::Log(LEVEL_DEBUG, "%s Stopping update thread...", __FUNCTION__);
m_running = false;
if (m_thread.joinable())
m_thread.join();

std::lock_guard<std::mutex> lock(m_mutex);
m_channels.Clear();
m_channelGroups.Clear();
m_providers.Clear();
m_epg.Clear();
}

/***************************************************************************
* Providers
**************************************************************************/
Expand Down
13 changes: 10 additions & 3 deletions src/IptvSimple.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include "iptvsimple/CatchupController.h"
#include "iptvsimple/Channels.h"
#include "iptvsimple/ChannelGroups.h"
#include "iptvsimple/ConnectionManager.h"
#include "iptvsimple/Providers.h"
#include "iptvsimple/Epg.h"
#include "iptvsimple/IConnectionListener.h"
#include "iptvsimple/Media.h"
#include "iptvsimple/PlaylistLoader.h"
#include "iptvsimple/data/Channel.h"
Expand All @@ -22,12 +24,16 @@

#include <kodi/addon-instance/PVR.h>

class ATTR_DLL_LOCAL IptvSimple : public kodi::addon::CInstancePVRClient
class ATTR_DLL_LOCAL IptvSimple : public iptvsimple::IConnectionListener
{
public:
IptvSimple(const kodi::addon::IInstanceInfo& instance);
~IptvSimple() override;

// IConnectionListener implementation
void ConnectionLost() override;
void ConnectionEstablished() override;

bool Initialise();

// kodi::addon::CInstancePVRClient -> kodi::addon::IAddonInstance overrides
Expand All @@ -41,8 +47,8 @@ class ATTR_DLL_LOCAL IptvSimple : public kodi::addon::CInstancePVRClient
PVR_ERROR GetBackendVersion(std::string& version) override;
PVR_ERROR GetConnectionString(std::string& connection) override;

PVR_ERROR OnSystemSleep() override { return PVR_ERROR_NO_ERROR; }
PVR_ERROR OnSystemWake() override { return PVR_ERROR_NO_ERROR; }
PVR_ERROR OnSystemSleep() override;
PVR_ERROR OnSystemWake() override;
PVR_ERROR OnPowerSavingActivated() override { return PVR_ERROR_NO_ERROR; }
PVR_ERROR OnPowerSavingDeactivated() override { return PVR_ERROR_NO_ERROR; }

Expand Down Expand Up @@ -96,6 +102,7 @@ class ATTR_DLL_LOCAL IptvSimple : public kodi::addon::CInstancePVRClient
iptvsimple::PlaylistLoader m_playlistLoader{this, m_channels, m_channelGroups, m_providers, m_media, m_settings};
iptvsimple::Epg m_epg{this, m_channels, m_media, m_settings};
iptvsimple::CatchupController m_catchupController{m_epg, &m_mutex, m_settings};
iptvsimple::ConnectionManager* connectionManager;

std::atomic<bool> m_running{false};
std::thread m_thread;
Expand Down
Loading

0 comments on commit cc885d2

Please sign in to comment.