Skip to content

Commit

Permalink
Add custom timeout setting for livetv connections and timeshift
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelm committed May 13, 2018
1 parent 98d7170 commit f9298c3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
Expand Up @@ -86,6 +86,10 @@ msgctxt "#30040"
msgid "Enable low performance mode (disables logos & thumbnails)"
msgstr ""

msgctxt "#30041"
msgid "Custom Live TV timeout (0 to use default)"
msgstr ""

#empty strings from id 30041 to 30049

msgctxt "#30050"
Expand Down
13 changes: 13 additions & 0 deletions pvr.dvbviewer/resources/settings.xml
Expand Up @@ -188,6 +188,19 @@
<!-- advanced -->
<category id="advanced" label="30101">
<group id="1" label="30100">
<setting id="readtimeout" type="integer" label="30041">
<level>0</level>
<default>0</default>
<constraints>
<minimum>0</minimum>
<step>1</step>
<maximum>60</maximum>
</constraints>
<control type="slider" format="integer">
<popup>true</popup>
<formatlabel>14045</formatlabel>
</control>
</setting>
<setting id="prependoutline" type="integer" label="30060">
<level>0</level>
<default>1</default>
Expand Down
8 changes: 6 additions & 2 deletions src/StreamReader.cpp
Expand Up @@ -6,7 +6,11 @@ using namespace ADDON;
StreamReader::StreamReader(const std::string &streamURL)
: m_start(time(nullptr))
{
m_streamHandle = XBMC->OpenFile(streamURL.c_str(), XFILE::READ_NO_CACHE);
m_streamHandle = XBMC->CURLCreate(streamURL.c_str());
if (g_readTimeout)
XBMC->CURLAddOption(m_streamHandle, XFILE::CURL_OPTION_PROTOCOL,
"connection-timeout", std::to_string(g_readTimeout).c_str());

XBMC->Log(LOG_DEBUG, "StreamReader: Started; url=%s", streamURL.c_str());
}

Expand All @@ -19,7 +23,7 @@ StreamReader::~StreamReader(void)

bool StreamReader::Start()
{
return (m_streamHandle != nullptr);
return XBMC->CURLOpen(m_streamHandle, XFILE::READ_NO_CACHE);
}

ssize_t StreamReader::ReadData(unsigned char *buffer, unsigned int size)
Expand Down
21 changes: 12 additions & 9 deletions src/TimeshiftBuffer.cpp
Expand Up @@ -3,17 +3,20 @@
#include "client.h"
#include "p8-platform/util/util.h"

#define STREAM_READ_BUFFER_SIZE 32768
#define BUFFER_READ_TIMEOUT 10000
#define BUFFER_READ_WAITTIME 50
#define BUFFER_SIZE 32 * 1024
#define DEFAULT_READ_TIMEOUT 10 * 1000
#define READ_WAITTIME 50

using namespace ADDON;

TimeshiftBuffer::TimeshiftBuffer(IStreamReader *strReader,
const std::string &bufferPath)
: m_strReader(strReader), m_bufferPath(bufferPath), m_start(0)
: m_strReader(strReader), m_bufferPath(bufferPath + "/tsbuffer.ts"),
m_start(0), m_readTimeout(DEFAULT_READ_TIMEOUT)
{
m_bufferPath += "/tsbuffer.ts";
if (g_readTimeout)
m_readTimeout = g_readTimeout * 1000;

m_filebufferWriteHandle = XBMC->OpenFileForWrite(m_bufferPath.c_str(), true);
#ifndef TARGET_POSIX
m_writePos = 0;
Expand Down Expand Up @@ -57,7 +60,7 @@ bool TimeshiftBuffer::Start()
void *TimeshiftBuffer::Process()
{
XBMC->Log(LOG_DEBUG, "Timeshift: Thread started");
uint8_t buffer[STREAM_READ_BUFFER_SIZE];
uint8_t buffer[BUFFER_SIZE];

m_strReader->Start();
while (!IsStopped())
Expand Down Expand Up @@ -113,13 +116,13 @@ ssize_t TimeshiftBuffer::ReadData(unsigned char *buffer, unsigned int size)
unsigned int timeWaited = 0;
while (readPos + size > Length())
{
if (timeWaited > BUFFER_READ_TIMEOUT)
if (timeWaited > m_readTimeout)
{
XBMC->Log(LOG_DEBUG, "Timeshift: Read timed out; waited %u", timeWaited);
return -1;
}
Sleep(BUFFER_READ_WAITTIME);
timeWaited += BUFFER_READ_WAITTIME;
Sleep(READ_WAITTIME);
timeWaited += READ_WAITTIME;
}

return XBMC->ReadFile(m_filebufferReadHandle, buffer, size);
Expand Down
1 change: 1 addition & 0 deletions src/TimeshiftBuffer.h
Expand Up @@ -30,6 +30,7 @@ class TimeshiftBuffer
void *m_filebufferReadHandle;
void *m_filebufferWriteHandle;
time_t m_start;
int m_readTimeout;
#ifndef TARGET_POSIX
P8PLATFORM::CMutex m_mutex;
uint64_t m_writePos;
Expand Down
10 changes: 10 additions & 0 deletions src/client.cpp
Expand Up @@ -47,6 +47,7 @@ Timeshift g_timeshift = Timeshift::OFF;
std::string g_timeshiftBufferPath = DEFAULT_TSBUFFERPATH;
DvbRecording::Grouping g_groupRecordings = DvbRecording::Grouping::DISABLED;
EdlSettings g_edl = { false, 0, 0 };
int g_readTimeout = 0;
PrependOutline g_prependOutline = PrependOutline::IN_EPG;
bool g_lowPerformance = false;
Transcoding g_transcoding = Transcoding::OFF;
Expand Down Expand Up @@ -101,6 +102,9 @@ void ADDON_ReadSettings(void)
if (XBMC->GetSetting("timeshiftpath", buffer) && !std::string(buffer).empty())
g_timeshiftBufferPath = buffer;

if (!XBMC->GetSetting("readtimeout", &g_readTimeout))
g_readTimeout = 0;

if (!XBMC->GetSetting("prependoutline", &g_prependOutline))
g_prependOutline = PrependOutline::IN_EPG;

Expand Down Expand Up @@ -151,6 +155,8 @@ void ADDON_ReadSettings(void)
g_edl.padding_start, g_edl.padding_stop);

/* advanced tab */
if (g_readTimeout)
XBMC->Log(LOG_DEBUG, "Custom connection/read timeout: %d", g_readTimeout);
if (g_prependOutline != PrependOutline::NEVER)
XBMC->Log(LOG_DEBUG, "Prepend outline: %d", g_prependOutline);
XBMC->Log(LOG_DEBUG, "Low performance mode: %s", (g_lowPerformance) ? "yes" : "no");
Expand Down Expand Up @@ -292,6 +298,10 @@ ADDON_STATUS ADDON_SetSetting(const char *settingName, const void *settingValue)
if (g_useFavouritesFile != *(bool *)settingValue)
return ADDON_STATUS_NEED_RESTART;
}
else if (sname == "readtimeout")
{
g_readTimeout = *(int *)settingValue;
}
else if (sname == "prependoutline")
{
PrependOutline newValue = *(const PrependOutline *)settingValue;
Expand Down
1 change: 1 addition & 0 deletions src/client.h
Expand Up @@ -91,6 +91,7 @@ extern Timeshift g_timeshift;
extern std::string g_timeshiftBufferPath;
extern DvbRecording::Grouping g_groupRecordings;
extern EdlSettings g_edl;
extern int g_readTimeout;
extern PrependOutline g_prependOutline;
extern bool g_lowPerformance;
extern Transcoding g_transcoding;
Expand Down

0 comments on commit f9298c3

Please sign in to comment.