Skip to content

Commit

Permalink
Implement proper timerec and autorec update methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glenn-1990 committed Dec 18, 2015
1 parent c40b722 commit 4bbad66
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 2 deletions.
100 changes: 99 additions & 1 deletion src/AutoRecordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,104 @@ PVR_ERROR AutoRecordings::SendAutorecAdd(const PVR_TIMER &timer)

PVR_ERROR AutoRecordings::SendAutorecUpdate(const PVR_TIMER &timer)
{
/* Note: there is no "updateAutorec" htsp method, thus delete + add. */
if (m_conn.GetProtocol() >= 25)
{
uint32_t u32;
std::string strId;

for (auto tit = m_autoRecordings.begin(); tit != m_autoRecordings.end(); ++tit)
{
if (tit->second.GetId() == timer.iClientIndex)
{
strId = tit->second.GetStringId();
break;
}
}

/* Build message */
htsmsg_t *m = htsmsg_create_map();
htsmsg_add_str(m, "id", strId.c_str()); // Autorec DVR Entry ID (string!)
htsmsg_add_str(m, "name", timer.strTitle);
htsmsg_add_str(m, "title", timer.strEpgSearchString);
htsmsg_add_u32(m, "fulltext", timer.bFullTextEpgSearch ? 1 : 0);
htsmsg_add_s64(m, "startExtra", timer.iMarginStart > 0 ? timer.iMarginStart : 1); // 0 not supported by tvheadend
htsmsg_add_s64(m, "stopExtra", timer.iMarginEnd > 0 ? timer.iMarginEnd : 1); // 0 not supported by tvheadend
htsmsg_add_u32(m, "removal", timer.iLifetime);
htsmsg_add_u32(m, "daysOfWeek", timer.iWeekdays);
htsmsg_add_u32(m, "dupDetect", timer.iPreventDuplicateEpisodes);
htsmsg_add_u32(m, "priority", timer.iPriority);
htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1);
htsmsg_add_s64(m, "channelId", timer.iClientChannelUid);

if (strcmp(timer.strDirectory, "/") != 0)
htsmsg_add_str(m, "directory", timer.strDirectory);

const Settings &settings = Settings::GetInstance();
if (settings.GetAutorecApproxTime())
{
if (timer.startTime > 0 && !timer.bStartAnyTime)
{
struct tm *tm_start = localtime(&timer.startTime);
int32_t startWindowBegin = tm_start->tm_hour * 60 + tm_start->tm_min - settings.GetAutorecMaxDiff();
int32_t startWindowEnd = tm_start->tm_hour * 60 + tm_start->tm_min + settings.GetAutorecMaxDiff();

/* Past midnight correction */
if (startWindowBegin < 0)
startWindowBegin += (24 * 60);
if (startWindowEnd > (24 * 60))
startWindowEnd -= (24 * 60);

htsmsg_add_s32(m, "start", startWindowBegin);
htsmsg_add_s32(m, "startWindow", startWindowEnd);
}
else
{
htsmsg_add_s32(m, "start", -1); // -1 = any
htsmsg_add_s32(m, "startWindow", -1); // -1 = any
}
}
else
{
if (timer.startTime > 0 && !timer.bStartAnyTime)
{
/* Exact start time (minutes from midnight). */
struct tm *tm_start = localtime(&timer.startTime);
htsmsg_add_s32(m, "start", tm_start->tm_hour * 60 + tm_start->tm_min);
}
else
htsmsg_add_s32(m, "start", -1); // -1 = any

if (timer.endTime > 0 && !timer.bEndAnyTime)
{
/* Exact stop time (minutes from midnight). */
struct tm *tm_stop = localtime(&timer.endTime);
htsmsg_add_s32(m, "startWindow", tm_stop->tm_hour * 60 + tm_stop->tm_min);
}
else
htsmsg_add_s32(m, "startWindow", -1); // -1 = any
}

/* Send and Wait */
{
CLockObject lock(m_conn.Mutex());
m = m_conn.SendAndWait("updateAutorecEntry", m);
}

if (m == NULL)
return PVR_ERROR_SERVER_ERROR;

/* Check for error */
if (htsmsg_get_u32(m, "success", &u32))
{
tvherror("malformed updateAutorecEntry response: 'success' missing");
u32 = PVR_ERROR_FAILED;
}
htsmsg_destroy(m);

return u32 == 1 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED;
}

/* Note: there is no "updateAutorec" htsp method for htsp version < 25, thus delete + add. */
PVR_ERROR error = SendAutorecDelete(timer);

if (error == PVR_ERROR_NO_ERROR)
Expand Down Expand Up @@ -455,6 +551,8 @@ bool AutoRecordings::ParseAutorecAddOrUpdate(htsmsg_t *msg, bool bAdd)
{
rec.SetChannel(u32);
}
else
rec.SetChannel(PVR_TIMER_ANY_CHANNEL);

if (!htsmsg_get_u32(msg, "fulltext", &u32))
{
Expand Down
59 changes: 58 additions & 1 deletion src/TimeRecordings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,63 @@ PVR_ERROR TimeRecordings::SendTimerecAdd(const PVR_TIMER &timer)

PVR_ERROR TimeRecordings::SendTimerecUpdate(const PVR_TIMER &timer)
{
/* Note: there is no "updateTimerec" htsp method, thus delete + add. */
if (m_conn.GetProtocol() >= 25)
{
uint32_t u32;
std::string strId;

for (auto tit = m_timeRecordings.begin(); tit != m_timeRecordings.end(); ++tit)
{
if (tit->second.GetId() == timer.iClientIndex)
{
strId = tit->second.GetStringId();
break;
}
}

char title[PVR_ADDON_NAME_STRING_LENGTH+6];
const char *titleExt = "%F-%R"; // timerec title should contain the pattern (e.g. %F-%R) for the generated recording files. Scary...
snprintf(title, sizeof(title), "%s-%s", timer.strTitle, titleExt);

/* Build message */
htsmsg_t *m = htsmsg_create_map();
htsmsg_add_str(m, "id", strId.c_str()); // Timerec DVR Entry ID (string!)
htsmsg_add_str(m, "name", timer.strTitle);
htsmsg_add_str(m, "title", title);
struct tm *tm_start = localtime(&timer.startTime);
htsmsg_add_u32(m, "start", tm_start->tm_hour * 60 + tm_start->tm_min); // start time in minutes from midnight
struct tm *tm_stop = localtime(&timer.endTime);
htsmsg_add_u32(m, "stop", tm_stop->tm_hour * 60 + tm_stop->tm_min); // end time in minutes from midnight
htsmsg_add_s32(m, "channelId", timer.iClientChannelUid);
htsmsg_add_u32(m, "removal", timer.iLifetime);
htsmsg_add_u32(m, "daysOfWeek", timer.iWeekdays);
htsmsg_add_u32(m, "priority", timer.iPriority);
htsmsg_add_u32(m, "enabled", timer.state == PVR_TIMER_STATE_DISABLED ? 0 : 1);

if (strcmp(timer.strDirectory, "/") != 0)
htsmsg_add_str(m, "directory", timer.strDirectory);

/* Send and Wait */
{
CLockObject lock(m_conn.Mutex());
m = m_conn.SendAndWait("updateTimerecEntry", m);
}

if (m == NULL)
return PVR_ERROR_SERVER_ERROR;

/* Check for error */
if (htsmsg_get_u32(m, "success", &u32))
{
tvherror("malformed updateTimerecEntry response: 'success' missing");
u32 = PVR_ERROR_FAILED;
}
htsmsg_destroy(m);

return u32 == 1 ? PVR_ERROR_NO_ERROR : PVR_ERROR_FAILED;
}

/* Note: there is no "updateTimerec" htsp method for htsp version < 25, thus delete + add. */
PVR_ERROR error = SendTimerecDelete(timer);

if (error == PVR_ERROR_NO_ERROR)
Expand Down Expand Up @@ -340,6 +395,8 @@ bool TimeRecordings::ParseTimerecAddOrUpdate(htsmsg_t *msg, bool bAdd)
{
rec.SetChannel(u32);
}
else
rec.SetChannel(PVR_TIMER_ANY_CHANNEL);

return true;
}
Expand Down

0 comments on commit 4bbad66

Please sign in to comment.