Skip to content

Commit

Permalink
Add EDL support for recordings
Browse files Browse the repository at this point in the history
This required DMS 2.1.0.0 or higher

Fixes #25

Also do a bit more cleanup and make sure all settings get loaded.
Otherwise every settings changes triggers a PVR reload.
  • Loading branch information
manuelm committed Apr 21, 2018
1 parent 7936ba1 commit 70f8676
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Kodi Media Center language file
# Addon Name: DVBViewer Client
# Addon id: pvr.dvbviewer
# Addon Provider: A600, Manuel Mausz
# Addon Provider: Manuel Mausz
msgid ""
msgstr ""
"Project-Id-Version: KODI Main\n"
Expand Down Expand Up @@ -170,7 +170,21 @@ msgctxt "#30077"
msgid "Transcoding URL parameters"
msgstr ""

#empty strings from id 30078 to 30099
#empty strings from id 30078 to 30079

msgctxt "#30080"
msgid "Enable EDL support"
msgstr ""

msgctxt "#30081"
msgid "Start time padding"
msgstr ""

msgctxt "#30082"
msgid "Stop time padding"
msgstr ""

#empty strings from id 30083 to 30099
#sections

msgctxt "#30100"
Expand All @@ -189,7 +203,34 @@ msgctxt "#30103"
msgid "Live TV"
msgstr ""

#empty strings from id 30104 to 30399
msgctxt "#30103"
msgid "Live TV"
msgstr ""

#empty strings from id 30104 to 30109
#subsection labels

msgctxt "#30110"
msgid "Wake-on-LAN"
msgstr ""

msgctxt "#30111"
msgid "Favourites"
msgstr ""

msgctxt "#30112"
msgid "Timeshift"
msgstr ""

msgctxt "#30113"
msgid "Edit Decision List"
msgstr ""

msgctxt "#30114"
msgid "Transcoding"
msgstr ""

#empty strings from id 30115 to 30399
#timers

msgctxt "#30400"
Expand Down Expand Up @@ -266,3 +307,7 @@ msgstr ""
msgctxt "#30510"
msgid "The time period cannot span more than 24 hours"
msgstr ""

msgctxt "#30511"
msgid "EDL support requires DVBViewer Media Server %s or higher"
msgstr ""
52 changes: 46 additions & 6 deletions pvr.dvbviewer/resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</setting>
</group>

<group id="2" label="30002">
<group id="2" label="30110">
<setting id="usewol" type="boolean" label="30004">
<level>0</level>
<default>false</default>
Expand All @@ -61,7 +61,7 @@

<!-- live tv -->
<category id="livetv" label="30103">
<group id="1" label="30103">
<group id="1" label="30111">
<setting id="usefavourites" type="boolean" label="30010">
<level>0</level>
<default>false</default>
Expand Down Expand Up @@ -93,7 +93,7 @@
</setting>
</group>

<group id="2" label="30103">
<group id="2" label="30112">
<setting id="timeshift" type="integer" label="30020">
<level>0</level>
<default>0</default>
Expand Down Expand Up @@ -125,7 +125,7 @@

<!-- recordings -->
<category id="recordings" label="30102">
<group id="1" label="30102">
<group id="1" label="30100">
<setting id="grouprecordings" type="integer" label="30050">
<level>0</level>
<default>0</default>
Expand All @@ -143,11 +143,51 @@
<control type="list" format="integer" />
</setting>
</group>

<group id="2" label="30113">
<setting id="edl" type="boolean" label="30080">
<level>0</level>
<default>false</default>
<control type="toggle" />
</setting>
<setting id="edl_padding_start" type="integer" label="30081">
<level>0</level>
<default>0</default>
<constraints>
<minimum>-10000</minimum>
<step>500</step>
<maximum>10000</maximum>
</constraints>
<dependencies>
<dependency type="enable" setting="edl">true</dependency>
</dependencies>
<control type="slider" format="integer">
<popup>true</popup>
<formatlabel>14046</formatlabel>
</control>
</setting>
<setting id="edl_padding_stop" type="integer" label="30082">
<level>0</level>
<default>0</default>
<constraints>
<minimum>-10000</minimum>
<step>500</step>
<maximum>10000</maximum>
</constraints>
<dependencies>
<dependency type="enable" setting="edl">true</dependency>
</dependencies>
<control type="slider" format="integer">
<popup>true</popup>
<formatlabel>14046</formatlabel>
</control>
</setting>
</group>
</category>

<!-- advanced -->
<category id="advanced" label="30101">
<group id="1" label="30101">
<group id="1" label="30100">
<setting id="prependoutline" type="integer" label="30060">
<level>0</level>
<default>1</default>
Expand All @@ -168,7 +208,7 @@
</setting>
</group>

<group id="2" label="30101">
<group id="2" label="30114">
<setting id="transcoding" type="integer" label="30070">
<level>0</level>
<default>0</default>
Expand Down
120 changes: 104 additions & 16 deletions src/DvbData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,63 @@ RecordingReader *Dvb::OpenRecordedStream(const PVR_RECORDING &recinfo)
recinfo.strRecordingId), end);
}

bool Dvb::GetRecordingEdl(const PVR_RECORDING &recinfo, PVR_EDL_ENTRY edl[],
int *count)
{
int max_entries = *count;
*count = 0;

if (m_backendVersion < DMS_VERSION_NUM(2, 1, 0, 0))
{
XBMC->Log(LOG_ERROR, "Backend server is too old. Disabling EDL support.");
XBMC->QueueNotification(QUEUE_ERROR, XBMC->GetLocalizedString(30511),
DMS_VERSION_STR(2, 1, 0, 0));
g_edl.enabled = false;
return false;
}

const httpResponse &res = OpenFromAPI("api/sideload.html?rec=1&file=.edl"
"&fileid=%s", recinfo.strRecordingId);
if (res.error)
return true;

int idx = 0;
size_t lineNumber = 0;
char buffer[2048];
while(XBMC->ReadFileString(res.file, buffer, 2048))
{
float start = 0.0f, stop = 0.0f;
PVR_EDL_TYPE type = PVR_EDL_TYPE_CUT;
++lineNumber;
if (sscanf(buffer, "%f %f %u", &start, &stop, &type) < 2)
{
XBMC->Log(LOG_NOTICE, "Unable to parse EDL entry at line %zu. Skipping.",
lineNumber);
continue;
}

start += g_edl.padding_start / 1000.0f;
stop += g_edl.padding_stop / 1000.0f;

start = std::max(start, 0.0f);
stop = std::max(stop, 0.0f);
start = std::min(start, stop);
stop = std::max(start, stop);

XBMC->Log(LOG_DEBUG, "edl line=%zu start=%f stop=%f type=%d", lineNumber,
start, stop, type);

edl[idx].start = static_cast<int64_t>(start * 1000.0f);
edl[idx].end = static_cast<int64_t>(stop * 1000.0f);
edl[idx].type = type;
++idx;
}

*count = idx;
XBMC->CloseFile(res.file);
return true;
}

/***************************************************************************
* Livestream
**************************************************************************/
Expand Down Expand Up @@ -679,11 +736,11 @@ void *Dvb::Process()
XBMC->Log(LOG_ERROR, "Error sending WoL packet to %s", g_mac.c_str());
}

XBMC->Log(LOG_INFO, "Trying to connect to the backend service...");
XBMC->Log(LOG_INFO, "Trying to connect to the backend server...");

if (CheckBackendVersion() && UpdateBackendStatus(true) && LoadChannels())
{
XBMC->Log(LOG_INFO, "Connection to the backend service successful.");
XBMC->Log(LOG_INFO, "Connection to the backend server successful.");
SetConnectionState(PVR_CONNECTION_STATE_CONNECTED);

TimerUpdates();
Expand All @@ -692,7 +749,7 @@ void *Dvb::Process()
}
else
{
XBMC->Log(LOG_INFO, "Connection to the backend service failed."
XBMC->Log(LOG_INFO, "Connection to the backend server failed."
" Retrying in 10 seconds...");
Sleep(10000);
}
Expand Down Expand Up @@ -737,16 +794,13 @@ void *Dvb::Process()
return nullptr;
}

Dvb::httpResponse Dvb::GetFromAPI(const char* format, ...)
Dvb::httpResponse Dvb::OpenFromAPI(const char* format, va_list args)
{
static const std::string baseUrl = StringUtils::Format("http://%s:%u/",
g_hostname.c_str(), g_webPort);
va_list argList;
va_start(argList, format);
std::string url = baseUrl + StringUtils::FormatV(format, argList);
va_end(argList);
std::string url = baseUrl + StringUtils::FormatV(format, args);

httpResponse res = { true, 0, "" };
httpResponse res = { nullptr, true, 0, "" };
void *file = XBMC->CURLCreate(url.c_str());
if (!file)
{
Expand Down Expand Up @@ -789,17 +843,51 @@ Dvb::httpResponse Dvb::GetFromAPI(const char* format, ...)
if (!ss.good())
{
XBMC->Log(LOG_ERROR, "Endpoint %s returned an invalid status line: ",
url.c_str(), status);
url.c_str(), status);
XBMC->CloseFile(file);
SetConnectionState(PVR_CONNECTION_STATE_SERVER_UNREACHABLE);
return res;
}

res.error = (res.code >= 300);
char buffer[1024];
while (int bytesRead = XBMC->ReadFile(file, buffer, 1024))
res.content.append(buffer, bytesRead);
XBMC->CloseFile(file);
// everything non 2xx is an error
// NOTE: this doesn't work for now. see above
if (res.code >= 300)
{
XBMC->Log(LOG_NOTICE, "Endpoint %s returned non-successful status code %hu",
url.c_str(), res.code);
XBMC->CloseFile(file);
return res;
}

res.file = file;
res.error = false;
return res;
}

Dvb::httpResponse Dvb::OpenFromAPI(const char* format, ...)
{
va_list args;
va_start(args, format);
httpResponse &&res = OpenFromAPI(format, args);
va_end(args);
return res;
}

Dvb::httpResponse Dvb::GetFromAPI(const char* format, ...)
{
va_list args;
va_start(args, format);
httpResponse &&res = OpenFromAPI(format, args);
va_end(args);

if (res.file)
{
char buffer[1024];
while (int bytesRead = XBMC->ReadFile(res.file, buffer, 1024))
res.content.append(buffer, bytesRead);
XBMC->CloseFile(res.file);
res.file = nullptr;
}
return res;
}

Expand Down Expand Up @@ -1130,7 +1218,7 @@ bool Dvb::CheckBackendVersion()
doc.Parse(res.content.c_str());
if (doc.Error())
{
XBMC->Log(LOG_ERROR, "Unable to connect to the backend service. Error: %s",
XBMC->Log(LOG_ERROR, "Unable to connect to the backend server. Error: %s",
doc.ErrorDesc());
SetConnectionState(PVR_CONNECTION_STATE_SERVER_MISMATCH);
return false;
Expand Down
Loading

0 comments on commit 70f8676

Please sign in to comment.