Skip to content

Commit

Permalink
Support setting progam number in stream properties for MPTS streams, c…
Browse files Browse the repository at this point in the history
…loses kodi-pvr#195, cloases kodi-pvr#208, close kodi-pvr#219
  • Loading branch information
phunkyfish committed Jun 6, 2019
1 parent acc7b3a commit c104c7f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Enigma2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/Enigma2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 30 additions & 1 deletion src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -634,7 +664,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; }
void FillBuffer(bool mode) {}
Expand Down

0 comments on commit c104c7f

Please sign in to comment.