From 4a4f19f3249c40b05926754107a2622c7bf9076f Mon Sep 17 00:00:00 2001 From: phunkyfish Date: Mon, 27 May 2019 22:06:10 +0100 Subject: [PATCH] Support setting progam number in stream properties for MPTS streams, closes #195, cloases #208, close #219 --- src/Enigma2.cpp | 18 ++++++++++++++++++ src/Enigma2.h | 2 ++ src/client.cpp | 31 ++++++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/Enigma2.cpp b/src/Enigma2.cpp index c607873c..0e27c30c 100755 --- a/src/Enigma2.cpp +++ b/src/Enigma2.cpp @@ -483,6 +483,24 @@ const std::string Enigma2::GetLiveStreamURL(const PVR_CHANNEL &channelinfo) return m_channels.GetChannel(channelinfo.iUniqueId)->GetStreamURL(); } +const int Enigma2::GetChannelStreamProgramNumber(const PVR_CHANNEL &channelinfo) +{ + return m_channels.GetChannel(channelinfo.iUniqueId)->GetStreamProgramNumber(); +} + +const bool Enigma2::GetLiveStreamRequiresProgramNumber(const PVR_CHANNEL &channelinfo) +{ + const std::string strM3U = WebUtils::GetHttpXML(m_channels.GetChannel(channelinfo.iUniqueId)->GetM3uURL()); + std::istringstream streamM3U(strM3U); + std::string m3uLine = ""; + while (std::getline(streamM3U, m3uLine)) + { + if (StringUtils::StartsWith(m3uLine, "#EXTVLCOPT:program=")) + return true; + }; + + return false; +} /** * GetStreamURL() reads out a stream-URL from a M3U-file. diff --git a/src/Enigma2.h b/src/Enigma2.h index 4b4024c6..691d3696 100644 --- a/src/Enigma2.h +++ b/src/Enigma2.h @@ -83,6 +83,8 @@ class Enigma2 : public P8PLATFORM::CThread, public enigma2::IConnectionListener bool OpenLiveStream(const PVR_CHANNEL &channelinfo); void CloseLiveStream(); const std::string GetLiveStreamURL(const PVR_CHANNEL &channelinfo); + const bool GetLiveStreamRequiresProgramNumber(const PVR_CHANNEL &channelinfo); + const int GetChannelStreamProgramNumber(const PVR_CHANNEL &channelinfo); unsigned int GetRecordingsAmount(); PVR_ERROR GetRecordings(ADDON_HANDLE handle); PVR_ERROR DeleteRecording(const PVR_RECORDING &recinfo); diff --git a/src/client.cpp b/src/client.cpp index 691398b9..ded85112 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -338,6 +338,36 @@ PVR_ERROR GetChannels(ADDON_HANDLE handle, bool bRadio) * Live Streams **************************************************************************/ +PVR_ERROR GetChannelStreamProperties(const PVR_CHANNEL* channel, PVR_NAMED_VALUE* properties, unsigned int* iPropertiesCount) +{ + // + // We only use this function to set the program number which comes with every Enigma2 channel. For providers that + // use MPTS it allows the FFMPEG Demux to identify the correct Program/PID. + // + + if (!channel || !properties || !iPropertiesCount) + return PVR_ERROR_SERVER_ERROR; + + if (*iPropertiesCount < 1) + return PVR_ERROR_INVALID_PARAMETERS; + + if (!enigma || !enigma->IsConnected()) + return PVR_ERROR_SERVER_ERROR; + + if (enigma->GetLiveStreamRequiresProgramNumber(*channel)) + { + std::string strStreamProgramNumber = std::to_string(enigma->GetChannelStreamProgramNumber(*channel)); + + Logger::Log(LEVEL_NOTICE, "%s - for channel: %s, set Stream Program Number to %s - %s", __FUNCTION__, channel->strChannelName, strStreamProgramNumber.c_str(), enigma->GetLiveStreamURL(*channel).c_str()); + + strncpy(properties[0].strName, "program", sizeof(properties[0].strName) - 1); + strncpy(properties[0].strValue, strStreamProgramNumber.c_str(), sizeof(properties[0].strValue) - 1); + *iPropertiesCount = 1; + } + + return PVR_ERROR_NO_ERROR; +} + PVR_ERROR GetStreamReadChunkSize(int* chunksize) { if (!chunksize) @@ -639,7 +669,6 @@ PVR_ERROR UpdateTimer(const PVR_TIMER &timer) /** UNUSED API FUNCTIONS */ PVR_ERROR GetStreamProperties(PVR_STREAM_PROPERTIES* pProperties) { return PVR_ERROR_NOT_IMPLEMENTED; } -PVR_ERROR GetChannelStreamProperties(const PVR_CHANNEL*, PVR_NAMED_VALUE*, unsigned int*) { return PVR_ERROR_NOT_IMPLEMENTED; } void DemuxAbort(void) { return; } DemuxPacket* DemuxRead(void) { return nullptr; } PVR_ERROR OpenDialogChannelScan(void) { return PVR_ERROR_NOT_IMPLEMENTED; }