2000-09-03 11:40:00 +02:00
|
|
|
/***************************************************************************
|
|
|
|
eit.c - description
|
|
|
|
-------------------
|
|
|
|
begin : Fri Aug 25 2000
|
|
|
|
copyright : (C) 2000 by Robert Schneider
|
|
|
|
email : Robert.Schneider@web.de
|
2001-08-15 13:56:11 +02:00
|
|
|
|
|
|
|
2001-08-15: Adapted to 'libdtv' by Rolf Hakenes <hakenes@hippomi.de>
|
|
|
|
|
2000-09-03 11:40:00 +02:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
2002-10-11 13:23:44 +02:00
|
|
|
* $Id: eit.c 1.56 2002/10/11 13:14:57 kls Exp $
|
2000-09-03 11:40:00 +02:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "eit.h"
|
2000-10-29 13:17:22 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <fcntl.h>
|
2001-06-02 10:47:40 +02:00
|
|
|
#include <limits.h>
|
2002-08-10 14:58:25 +02:00
|
|
|
#ifdef NEWSTRUCT
|
|
|
|
#include <linux/dvb/dmx.h>
|
|
|
|
#else
|
2002-06-16 12:57:31 +02:00
|
|
|
#include <ost/dmx.h>
|
2002-08-10 14:58:25 +02:00
|
|
|
#endif
|
2000-09-03 11:40:00 +02:00
|
|
|
#include <stdio.h>
|
2000-10-29 13:17:22 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-09-03 11:40:00 +02:00
|
|
|
#include <sys/ioctl.h>
|
2000-10-29 13:17:22 +01:00
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
2002-10-06 10:25:42 +02:00
|
|
|
#include "channels.h"
|
2000-11-26 15:23:39 +01:00
|
|
|
#include "config.h"
|
2001-08-15 13:56:11 +02:00
|
|
|
#include "libdtv/libdtv.h"
|
2000-11-26 15:23:39 +01:00
|
|
|
#include "videodir.h"
|
2000-10-29 13:17:22 +01:00
|
|
|
|
|
|
|
// --- cMJD ------------------------------------------------------------------
|
|
|
|
|
|
|
|
class cMJD {
|
2001-03-31 15:04:37 +02:00
|
|
|
public:
|
|
|
|
cMJD();
|
|
|
|
cMJD(u_char date_hi, u_char date_lo);
|
|
|
|
cMJD(u_char date_hi, u_char date_lo, u_char timehr, u_char timemi, u_char timese);
|
|
|
|
~cMJD();
|
2000-10-29 13:17:22 +01:00
|
|
|
/** */
|
|
|
|
void ConvertToTime();
|
|
|
|
/** */
|
|
|
|
bool SetSystemTime();
|
|
|
|
/** */
|
|
|
|
time_t GetTime_t();
|
|
|
|
protected: // Protected attributes
|
|
|
|
/** */
|
|
|
|
time_t mjdtime;
|
|
|
|
protected: // Protected attributes
|
|
|
|
/** */
|
|
|
|
u_char time_second;
|
|
|
|
protected: // Protected attributes
|
|
|
|
/** */
|
|
|
|
u_char time_minute;
|
|
|
|
protected: // Protected attributes
|
|
|
|
/** */
|
|
|
|
u_char time_hour;
|
|
|
|
protected: // Protected attributes
|
|
|
|
/** */
|
|
|
|
u_short mjd;
|
|
|
|
};
|
|
|
|
|
|
|
|
cMJD::cMJD()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cMJD::cMJD(u_char date_hi, u_char date_lo)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
mjd = date_hi << 8 | date_lo;
|
|
|
|
time_hour = time_minute = time_second = 0;
|
|
|
|
ConvertToTime();
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cMJD::cMJD(u_char date_hi, u_char date_lo, u_char timehr, u_char timemi, u_char timese)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
mjd = date_hi << 8 | date_lo;
|
|
|
|
time_hour = timehr;
|
|
|
|
time_minute = timemi;
|
|
|
|
time_second = timese;
|
|
|
|
ConvertToTime();
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cMJD::~cMJD()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
void cMJD::ConvertToTime()
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
struct tm t;
|
|
|
|
|
|
|
|
t.tm_sec = time_second;
|
|
|
|
t.tm_min = time_minute;
|
|
|
|
t.tm_hour = time_hour;
|
|
|
|
int k;
|
|
|
|
|
|
|
|
t.tm_year = (int) ((mjd - 15078.2) / 365.25);
|
|
|
|
t.tm_mon = (int) ((mjd - 14956.1 - (int)(t.tm_year * 365.25)) / 30.6001);
|
|
|
|
t.tm_mday = (int) (mjd - 14956 - (int)(t.tm_year * 365.25) - (int)(t.tm_mon * 30.6001));
|
|
|
|
k = (t.tm_mon == 14 || t.tm_mon == 15) ? 1 : 0;
|
|
|
|
t.tm_year = t.tm_year + k;
|
|
|
|
t.tm_mon = t.tm_mon - 1 - k * 12;
|
|
|
|
t.tm_mon--;
|
|
|
|
|
|
|
|
t.tm_isdst = -1;
|
|
|
|
t.tm_gmtoff = 0;
|
|
|
|
|
|
|
|
mjdtime = timegm(&t);
|
|
|
|
|
2002-05-13 16:35:49 +02:00
|
|
|
//isyslog("Time parsed = %s\n", ctime(&mjdtime));
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
bool cMJD::SetSystemTime()
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
struct tm *ptm;
|
|
|
|
time_t loctim;
|
|
|
|
|
2001-10-19 13:22:24 +02:00
|
|
|
struct tm tm_r;
|
|
|
|
ptm = localtime_r(&mjdtime, &tm_r);
|
2001-03-31 15:04:37 +02:00
|
|
|
loctim = time(NULL);
|
|
|
|
|
|
|
|
if (abs(mjdtime - loctim) > 2)
|
|
|
|
{
|
2002-05-13 16:35:49 +02:00
|
|
|
isyslog("System Time = %s (%ld)\n", ctime(&loctim), loctim);
|
|
|
|
isyslog("Local Time = %s (%ld)\n", ctime(&mjdtime), mjdtime);
|
2001-03-31 15:04:37 +02:00
|
|
|
if (stime(&mjdtime) < 0)
|
2002-05-13 16:35:49 +02:00
|
|
|
esyslog("ERROR while setting system time: %m");
|
2001-03-31 15:04:37 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
time_t cMJD::GetTime_t()
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return mjdtime;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- cTDT ------------------------------------------------------------------
|
2000-09-03 11:40:00 +02:00
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
class cTDT {
|
2001-03-31 15:04:37 +02:00
|
|
|
public:
|
|
|
|
cTDT(tdt_t *ptdt);
|
|
|
|
~cTDT();
|
2000-10-29 13:17:22 +01:00
|
|
|
/** */
|
|
|
|
bool SetSystemTime();
|
|
|
|
protected: // Protected attributes
|
|
|
|
/** */
|
|
|
|
tdt_t tdt;
|
|
|
|
/** */
|
2001-03-03 13:23:39 +01:00
|
|
|
cMJD mjd; // kls 2001-03-02: made this a member instead of a pointer (it wasn't deleted in the destructor!)
|
2000-10-29 13:17:22 +01:00
|
|
|
};
|
|
|
|
|
2001-08-15 13:56:11 +02:00
|
|
|
#define BCD2DEC(b) (((b >> 4) & 0x0F) * 10 + (b & 0x0F))
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
cTDT::cTDT(tdt_t *ptdt)
|
2001-03-03 13:23:39 +01:00
|
|
|
:tdt(*ptdt)
|
2001-08-15 13:56:11 +02:00
|
|
|
,mjd(tdt.utc_mjd_hi, tdt.utc_mjd_lo, BCD2DEC(tdt.utc_time_h), BCD2DEC(tdt.utc_time_m), BCD2DEC(tdt.utc_time_s))
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cTDT::~cTDT()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/** */
|
|
|
|
bool cTDT::SetSystemTime()
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return mjd.SetSystemTime();
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- cEventInfo ------------------------------------------------------------
|
|
|
|
|
|
|
|
cEventInfo::cEventInfo(unsigned short serviceid, unsigned short eventid)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
pTitle = NULL;
|
|
|
|
pSubtitle = NULL;
|
|
|
|
pExtendedDescription = NULL;
|
|
|
|
bIsPresent = bIsFollowing = false;
|
|
|
|
lDuration = 0;
|
|
|
|
tTime = 0;
|
2001-10-28 13:53:44 +01:00
|
|
|
uTableID = 0;
|
2001-03-31 15:04:37 +02:00
|
|
|
uEventID = eventid;
|
|
|
|
uServiceID = serviceid;
|
2000-10-29 13:17:22 +01:00
|
|
|
nChannelNumber = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cEventInfo::~cEventInfo()
|
|
|
|
{
|
2002-08-11 13:32:23 +02:00
|
|
|
free(pTitle);
|
|
|
|
free(pSubtitle);
|
|
|
|
free(pExtendedDescription);
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
const char * cEventInfo::GetTitle() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return pTitle;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
const char * cEventInfo::GetSubtitle() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return pSubtitle;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
const char * cEventInfo::GetExtendedDescription() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return pExtendedDescription;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
bool cEventInfo::IsPresent() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return bIsPresent;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
void cEventInfo::SetPresent(bool pres)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
bIsPresent = pres;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
bool cEventInfo::IsFollowing() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return bIsFollowing;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
2001-10-28 13:53:44 +01:00
|
|
|
|
|
|
|
void cEventInfo::SetTableID(unsigned char tableid)
|
|
|
|
{
|
|
|
|
uTableID = tableid;
|
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
/** */
|
|
|
|
void cEventInfo::SetFollowing(bool foll)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
bIsFollowing = foll;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
const char * cEventInfo::GetDate() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
static char szDate[25];
|
2000-10-29 13:17:22 +01:00
|
|
|
|
2001-10-19 13:22:24 +02:00
|
|
|
struct tm tm_r;
|
|
|
|
strftime(szDate, sizeof(szDate), "%d.%m.%Y", localtime_r(&tTime, &tm_r));
|
2000-10-29 13:17:22 +01:00
|
|
|
|
2001-03-31 15:04:37 +02:00
|
|
|
return szDate;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
2001-10-28 13:53:44 +01:00
|
|
|
|
|
|
|
const unsigned char cEventInfo::GetTableID(void) const
|
|
|
|
{
|
|
|
|
return uTableID;
|
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
/** */
|
|
|
|
const char * cEventInfo::GetTimeString() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
static char szTime[25];
|
|
|
|
|
2001-10-19 13:22:24 +02:00
|
|
|
struct tm tm_r;
|
|
|
|
strftime(szTime, sizeof(szTime), "%R", localtime_r(&tTime, &tm_r));
|
2001-03-31 15:04:37 +02:00
|
|
|
|
|
|
|
return szTime;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
const char * cEventInfo::GetEndTimeString() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
static char szEndTime[25];
|
2000-10-29 13:17:22 +01:00
|
|
|
time_t tEndTime = tTime + lDuration;
|
2001-03-31 15:04:37 +02:00
|
|
|
|
2001-10-19 13:22:24 +02:00
|
|
|
struct tm tm_r;
|
|
|
|
strftime(szEndTime, sizeof(szEndTime), "%R", localtime_r(&tEndTime, &tm_r));
|
2001-03-31 15:04:37 +02:00
|
|
|
|
|
|
|
return szEndTime;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
time_t cEventInfo::GetTime() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return tTime;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
long cEventInfo::GetDuration() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return lDuration;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
unsigned short cEventInfo::GetEventID() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return uEventID;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
2001-09-22 13:07:43 +02:00
|
|
|
void cEventInfo::SetTitle(const char *string)
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2001-09-22 13:07:43 +02:00
|
|
|
pTitle = strcpyrealloc(pTitle, string);
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
2001-09-22 13:07:43 +02:00
|
|
|
void cEventInfo::SetSubtitle(const char *string)
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2001-09-22 13:07:43 +02:00
|
|
|
pSubtitle = strcpyrealloc(pSubtitle, string);
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
2001-09-22 13:07:43 +02:00
|
|
|
void cEventInfo::SetExtendedDescription(const char *string)
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2001-09-22 13:07:43 +02:00
|
|
|
pExtendedDescription = strcpyrealloc(pExtendedDescription, string);
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
void cEventInfo::SetTime(time_t t)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
tTime = t;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
void cEventInfo::SetDuration(long l)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
lDuration = l;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
void cEventInfo::SetEventID(unsigned short evid)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
uEventID = evid;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
void cEventInfo::SetServiceID(unsigned short servid)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
uServiceID = servid;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
unsigned short cEventInfo::GetServiceID() const
|
|
|
|
{
|
|
|
|
return uServiceID;
|
|
|
|
}
|
|
|
|
|
2000-11-26 15:23:39 +01:00
|
|
|
/** */
|
2001-04-01 15:40:43 +02:00
|
|
|
void cEventInfo::Dump(FILE *f, const char *Prefix) const
|
2000-11-26 15:23:39 +01:00
|
|
|
{
|
|
|
|
if (tTime + lDuration >= time(NULL)) {
|
2002-02-23 17:11:19 +01:00
|
|
|
fprintf(f, "%sE %u %ld %ld %X\n", Prefix, uEventID, tTime, lDuration, uTableID);
|
2000-11-26 15:23:39 +01:00
|
|
|
if (!isempty(pTitle))
|
2001-04-01 15:40:43 +02:00
|
|
|
fprintf(f, "%sT %s\n", Prefix, pTitle);
|
2000-11-26 15:23:39 +01:00
|
|
|
if (!isempty(pSubtitle))
|
2001-04-01 15:40:43 +02:00
|
|
|
fprintf(f, "%sS %s\n", Prefix, pSubtitle);
|
2000-11-26 15:23:39 +01:00
|
|
|
if (!isempty(pExtendedDescription))
|
2001-04-01 15:40:43 +02:00
|
|
|
fprintf(f, "%sD %s\n", Prefix, pExtendedDescription);
|
|
|
|
fprintf(f, "%se\n", Prefix);
|
2000-11-26 15:23:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-23 17:11:19 +01:00
|
|
|
bool cEventInfo::Read(FILE *f, cSchedule *Schedule)
|
|
|
|
{
|
|
|
|
if (Schedule) {
|
|
|
|
cEventInfo *pEvent = NULL;
|
|
|
|
char *s;
|
|
|
|
while ((s = readline(f)) != NULL) {
|
|
|
|
char *t = skipspace(s + 1);
|
|
|
|
switch (*s) {
|
|
|
|
case 'E': if (!pEvent) {
|
|
|
|
unsigned int uEventID;
|
|
|
|
time_t tTime;
|
|
|
|
long lDuration;
|
|
|
|
unsigned int uTableID = 0;
|
|
|
|
int n = sscanf(t, "%u %ld %ld %X", &uEventID, &tTime, &lDuration, &uTableID);
|
|
|
|
if (n == 3 || n == 4) {
|
|
|
|
pEvent = (cEventInfo *)Schedule->GetEvent(uEventID, tTime);
|
|
|
|
if (!pEvent)
|
|
|
|
pEvent = Schedule->AddEvent(new cEventInfo(Schedule->GetServiceID(), uEventID));
|
|
|
|
if (pEvent) {
|
|
|
|
pEvent->SetTableID(uTableID);
|
|
|
|
pEvent->SetTime(tTime);
|
|
|
|
pEvent->SetDuration(lDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'T': if (pEvent)
|
|
|
|
pEvent->SetTitle(t);
|
|
|
|
break;
|
|
|
|
case 'S': if (pEvent)
|
|
|
|
pEvent->SetSubtitle(t);
|
|
|
|
break;
|
|
|
|
case 'D': if (pEvent)
|
|
|
|
pEvent->SetExtendedDescription(t);
|
|
|
|
break;
|
|
|
|
case 'e': pEvent = NULL;
|
|
|
|
break;
|
|
|
|
case 'c': // to keep things simple we react on 'c' here
|
2002-04-06 14:02:41 +02:00
|
|
|
return true;
|
2002-05-13 16:35:49 +02:00
|
|
|
default: esyslog("ERROR: unexpected tag while reading EPG data: %s", s);
|
2002-02-23 17:11:19 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2002-05-13 16:35:49 +02:00
|
|
|
esyslog("ERROR: unexpected end of file while reading EPG data");
|
2002-02-23 17:11:19 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-09-15 14:35:32 +02:00
|
|
|
#define MAXEPGBUGFIXSTATS 6
|
2002-02-02 12:13:35 +01:00
|
|
|
#define MAXEPGBUGFIXCHANS 50
|
|
|
|
struct tEpgBugFixStats {
|
|
|
|
int hits;
|
|
|
|
int n;
|
|
|
|
unsigned short serviceIDs[MAXEPGBUGFIXCHANS];
|
|
|
|
tEpgBugFixStats(void) { hits = n = 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
tEpgBugFixStats EpgBugFixStats[MAXEPGBUGFIXSTATS];
|
|
|
|
|
|
|
|
static void EpgBugFixStat(int Number, unsigned int ServiceID)
|
|
|
|
{
|
|
|
|
if (0 <= Number && Number < MAXEPGBUGFIXSTATS) {
|
|
|
|
tEpgBugFixStats *p = &EpgBugFixStats[Number];
|
|
|
|
p->hits++;
|
|
|
|
int i = 0;
|
|
|
|
for (; i < p->n; i++) {
|
|
|
|
if (p->serviceIDs[i] == ServiceID)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == p->n && p->n < MAXEPGBUGFIXCHANS)
|
|
|
|
p->serviceIDs[p->n++] = ServiceID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReportEpgBugFixStats(bool Reset = false)
|
|
|
|
{
|
|
|
|
if (Setup.EPGBugfixLevel > 0) {
|
2002-02-09 14:50:05 +01:00
|
|
|
bool GotHits = false;
|
2002-02-02 12:13:35 +01:00
|
|
|
char buffer[1024];
|
|
|
|
for (int i = 0; i < MAXEPGBUGFIXSTATS; i++) {
|
|
|
|
const char *delim = "\t";
|
|
|
|
tEpgBugFixStats *p = &EpgBugFixStats[i];
|
2002-02-09 14:50:05 +01:00
|
|
|
if (p->hits) {
|
|
|
|
if (!GotHits) {
|
2002-05-13 16:35:49 +02:00
|
|
|
dsyslog("=====================");
|
|
|
|
dsyslog("EPG bugfix statistics");
|
|
|
|
dsyslog("=====================");
|
|
|
|
dsyslog("IF SOMEBODY WHO IS IN CHARGE OF THE EPG DATA FOR ONE OF THE LISTED");
|
|
|
|
dsyslog("CHANNELS READS THIS: PLEASE TAKE A LOOK AT THE FUNCTION cEventInfo::FixEpgBugs()");
|
|
|
|
dsyslog("IN VDR/eit.c TO LEARN WHAT'S WRONG WITH YOUR DATA, AND FIX IT!");
|
|
|
|
dsyslog("=====================");
|
|
|
|
dsyslog("Fix\tHits\tChannels");
|
2002-02-09 14:50:05 +01:00
|
|
|
GotHits = true;
|
|
|
|
}
|
|
|
|
char *q = buffer;
|
|
|
|
q += snprintf(q, sizeof(buffer) - (q - buffer), "%d\t%d", i, p->hits);
|
|
|
|
for (int c = 0; c < p->n; c++) {
|
|
|
|
cChannel *channel = Channels.GetByServiceID(p->serviceIDs[c]);
|
|
|
|
if (channel) {
|
2002-10-06 10:25:42 +02:00
|
|
|
q += snprintf(q, sizeof(buffer) - (q - buffer), "%s%s", delim, channel->Name());
|
2002-02-09 14:50:05 +01:00
|
|
|
delim = ", ";
|
|
|
|
}
|
2002-02-02 12:13:35 +01:00
|
|
|
}
|
2002-05-13 16:35:49 +02:00
|
|
|
dsyslog("%s", buffer);
|
2002-02-09 14:50:05 +01:00
|
|
|
}
|
2002-02-02 12:13:35 +01:00
|
|
|
if (Reset)
|
|
|
|
p->hits = p->n = 0;
|
|
|
|
}
|
2002-02-09 14:50:05 +01:00
|
|
|
if (GotHits)
|
2002-05-13 16:35:49 +02:00
|
|
|
dsyslog("=====================");
|
2002-02-02 12:13:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-17 13:19:10 +02:00
|
|
|
void cEventInfo::FixEpgBugs(void)
|
|
|
|
{
|
2001-10-07 14:02:19 +02:00
|
|
|
// VDR can't usefully handle newline characters in the EPG data, so let's
|
|
|
|
// always convert them to blanks (independent of the setting of EPGBugfixLevel):
|
|
|
|
strreplace(pTitle, '\n', ' ');
|
|
|
|
strreplace(pSubtitle, '\n', ' ');
|
|
|
|
strreplace(pExtendedDescription, '\n', ' ');
|
|
|
|
|
2001-08-17 13:19:10 +02:00
|
|
|
if (Setup.EPGBugfixLevel == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Some TV stations apparently have their own idea about how to fill in the
|
|
|
|
// EPG data. Let's fix their bugs as good as we can:
|
|
|
|
if (pTitle) {
|
|
|
|
|
2002-09-15 14:35:32 +02:00
|
|
|
// VOX puts too much information into the Subtitle and leaves the Extended
|
|
|
|
// Description empty:
|
|
|
|
//
|
|
|
|
// Title
|
|
|
|
// (NAT, Year Min')[ ["Subtitle". ]Extended Description]
|
|
|
|
//
|
|
|
|
if (pSubtitle && !pExtendedDescription) {
|
|
|
|
if (*pSubtitle == '(') {
|
|
|
|
char *e = strchr(pSubtitle + 1, ')');
|
|
|
|
if (e) {
|
|
|
|
if (*(e + 1)) {
|
|
|
|
if (*++e == ' ')
|
|
|
|
if (*(e + 1) == '"')
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
e = NULL;
|
|
|
|
char *s = e ? strdup(e) : NULL;
|
|
|
|
free(pSubtitle);
|
|
|
|
pSubtitle = s;
|
|
|
|
EpgBugFixStat(0, GetServiceID());
|
|
|
|
// now the fixes #1 and #2 below will handle the rest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-17 13:19:10 +02:00
|
|
|
// VOX and VIVA put the Subtitle in quotes and use either the Subtitle
|
|
|
|
// or the Extended Description field, depending on how long the string is:
|
|
|
|
//
|
|
|
|
// Title
|
|
|
|
// "Subtitle". Extended Description
|
|
|
|
//
|
|
|
|
if ((pSubtitle == NULL) != (pExtendedDescription == NULL)) {
|
|
|
|
char *p = pSubtitle ? pSubtitle : pExtendedDescription;
|
|
|
|
if (*p == '"') {
|
|
|
|
const char *delim = "\".";
|
|
|
|
char *e = strstr(p + 1, delim);
|
|
|
|
if (e) {
|
|
|
|
*e = 0;
|
|
|
|
char *s = strdup(p + 1);
|
|
|
|
char *d = strdup(e + strlen(delim));
|
2002-08-11 13:32:23 +02:00
|
|
|
free(pSubtitle);
|
|
|
|
free(pExtendedDescription);
|
2001-08-17 13:19:10 +02:00
|
|
|
pSubtitle = s;
|
|
|
|
pExtendedDescription = d;
|
2002-09-15 14:35:32 +02:00
|
|
|
EpgBugFixStat(1, GetServiceID());
|
2001-08-17 13:19:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// VOX and VIVA put the Extended Description into the Subtitle (preceeded
|
|
|
|
// by a blank) if there is no actual Subtitle and the Extended Description
|
|
|
|
// is short enough:
|
|
|
|
//
|
|
|
|
// Title
|
|
|
|
// Extended Description
|
|
|
|
//
|
|
|
|
if (pSubtitle && !pExtendedDescription) {
|
|
|
|
if (*pSubtitle == ' ') {
|
|
|
|
memmove(pSubtitle, pSubtitle + 1, strlen(pSubtitle));
|
|
|
|
pExtendedDescription = pSubtitle;
|
|
|
|
pSubtitle = NULL;
|
2002-09-15 14:35:32 +02:00
|
|
|
EpgBugFixStat(2, GetServiceID());
|
2001-08-17 13:19:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pro7 sometimes repeats the Title in the Subtitle:
|
|
|
|
//
|
|
|
|
// Title
|
|
|
|
// Title
|
|
|
|
//
|
|
|
|
if (pSubtitle && strcmp(pTitle, pSubtitle) == 0) {
|
2002-08-11 13:32:23 +02:00
|
|
|
free(pSubtitle);
|
2001-08-17 13:19:10 +02:00
|
|
|
pSubtitle = NULL;
|
2002-09-15 14:35:32 +02:00
|
|
|
EpgBugFixStat(3, GetServiceID());
|
2001-08-17 13:19:10 +02:00
|
|
|
}
|
|
|
|
|
2001-09-22 10:28:33 +02:00
|
|
|
// ZDF.info puts the Subtitle between double quotes, which is nothing
|
|
|
|
// but annoying (some even put a '.' after the closing '"'):
|
|
|
|
//
|
|
|
|
// Title
|
|
|
|
// "Subtitle"[.]
|
|
|
|
//
|
|
|
|
if (pSubtitle && *pSubtitle == '"') {
|
|
|
|
int l = strlen(pSubtitle);
|
|
|
|
if (l > 2 && (pSubtitle[l - 1] == '"' || (pSubtitle[l - 1] == '.' && pSubtitle[l - 2] == '"'))) {
|
|
|
|
memmove(pSubtitle, pSubtitle + 1, l);
|
|
|
|
char *p = strrchr(pSubtitle, '"');
|
|
|
|
if (p)
|
|
|
|
*p = 0;
|
2002-09-15 14:35:32 +02:00
|
|
|
EpgBugFixStat(4, GetServiceID());
|
2001-09-22 10:28:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-17 13:19:10 +02:00
|
|
|
if (Setup.EPGBugfixLevel <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Some channels apparently try to do some formatting in the texts,
|
|
|
|
// which is a bad idea because they have no way of knowing the width
|
|
|
|
// of the window that will actually display the text.
|
|
|
|
// Remove excess whitespace:
|
|
|
|
pTitle = compactspace(pTitle);
|
|
|
|
pSubtitle = compactspace(pSubtitle);
|
|
|
|
pExtendedDescription = compactspace(pExtendedDescription);
|
|
|
|
// Remove superfluous hyphens:
|
|
|
|
if (pExtendedDescription) {
|
2002-04-01 13:01:27 +02:00
|
|
|
char *p = pExtendedDescription;
|
|
|
|
while (*p && *(p + 1) && *(p + 2)) {
|
2001-08-17 13:19:10 +02:00
|
|
|
if (*p == '-' && *(p + 1) == ' ' && *(p + 2) && islower(*(p - 1)) && islower(*(p + 2))) {
|
2002-02-02 12:13:35 +01:00
|
|
|
if (!startswith(p + 2, "und ")) { // special case in German, as in "Lach- und Sachgeschichten"
|
2001-08-17 13:19:10 +02:00
|
|
|
memmove(p, p + 2, strlen(p + 2) + 1);
|
2002-09-15 14:35:32 +02:00
|
|
|
EpgBugFixStat(5, GetServiceID());
|
2002-02-02 12:13:35 +01:00
|
|
|
}
|
2001-08-17 13:19:10 +02:00
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-07 14:13:29 +02:00
|
|
|
// Some channels use the ` ("backtick") character, where a ' (single quote)
|
|
|
|
// would be normally used. Actually, "backticks" in normal text don't make
|
|
|
|
// much sense, so let's replace them:
|
|
|
|
strreplace(pTitle, '`', '\'');
|
|
|
|
strreplace(pSubtitle, '`', '\'');
|
|
|
|
strreplace(pExtendedDescription, '`', '\'');
|
2001-10-07 14:35:25 +02:00
|
|
|
}
|
2001-08-17 13:19:10 +02:00
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
// --- cSchedule -------------------------------------------------------------
|
|
|
|
|
|
|
|
cSchedule::cSchedule(unsigned short servid)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
pPresent = pFollowing = NULL;
|
|
|
|
uServiceID = servid;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cSchedule::~cSchedule()
|
|
|
|
{
|
|
|
|
}
|
2002-02-23 17:11:19 +01:00
|
|
|
|
|
|
|
cEventInfo *cSchedule::AddEvent(cEventInfo *EventInfo)
|
|
|
|
{
|
|
|
|
Events.Add(EventInfo);
|
|
|
|
return EventInfo;
|
|
|
|
}
|
|
|
|
|
2002-10-07 16:24:04 +02:00
|
|
|
const cEventInfo *cSchedule::GetPresentEvent(void) const
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2002-10-07 16:24:04 +02:00
|
|
|
return GetEventAround(time(NULL));
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
2002-10-07 16:24:04 +02:00
|
|
|
|
|
|
|
const cEventInfo *cSchedule::GetFollowingEvent(void) const
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2002-10-07 16:24:04 +02:00
|
|
|
const cEventInfo *pe = NULL;
|
|
|
|
time_t now = time(NULL);
|
|
|
|
time_t delta = INT_MAX;
|
|
|
|
for (cEventInfo *p = Events.First(); p; p = Events.Next(p)) {
|
|
|
|
time_t dt = p->GetTime() - now;
|
|
|
|
if (dt > 0 && dt < delta) {
|
|
|
|
delta = dt;
|
|
|
|
pe = p;
|
2000-11-01 15:53:00 +01:00
|
|
|
}
|
|
|
|
}
|
2002-10-07 16:24:04 +02:00
|
|
|
return pe;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
2002-10-07 16:24:04 +02:00
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
void cSchedule::SetServiceID(unsigned short servid)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
uServiceID = servid;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
unsigned short cSchedule::GetServiceID() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return uServiceID;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
2001-10-28 13:53:44 +01:00
|
|
|
const cEventInfo * cSchedule::GetEvent(unsigned short uEventID, time_t tTime) const
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2001-10-28 13:53:44 +01:00
|
|
|
// Returns either the event info with the given uEventID or, if that one can't
|
|
|
|
// be found, the one with the given tTime (or NULL if neither can be found)
|
2001-03-31 15:04:37 +02:00
|
|
|
cEventInfo *pe = Events.First();
|
2001-10-28 13:53:44 +01:00
|
|
|
cEventInfo *pt = NULL;
|
2001-03-31 15:04:37 +02:00
|
|
|
while (pe != NULL)
|
|
|
|
{
|
|
|
|
if (pe->GetEventID() == uEventID)
|
|
|
|
return pe;
|
2001-10-28 13:53:44 +01:00
|
|
|
if (tTime > 0 && pe->GetTime() == tTime) // 'tTime < 0' is apparently used with NVOD channels
|
|
|
|
pt = pe;
|
2001-03-31 15:04:37 +02:00
|
|
|
|
|
|
|
pe = Events.Next(pe);
|
|
|
|
}
|
|
|
|
|
2001-10-28 13:53:44 +01:00
|
|
|
return pt;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
2001-03-31 15:04:37 +02:00
|
|
|
|
2002-10-07 16:24:04 +02:00
|
|
|
const cEventInfo *cSchedule::GetEventAround(time_t Time) const
|
|
|
|
{
|
|
|
|
const cEventInfo *pe = NULL;
|
|
|
|
time_t delta = INT_MAX;
|
|
|
|
for (cEventInfo *p = Events.First(); p; p = Events.Next(p)) {
|
|
|
|
time_t dt = Time - p->GetTime();
|
|
|
|
if (dt >= 0 && dt < delta && p->GetTime() + p->GetDuration() >= Time) {
|
|
|
|
delta = dt;
|
|
|
|
pe = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pe;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
2002-10-07 16:24:04 +02:00
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
bool cSchedule::SetPresentEvent(cEventInfo *pEvent)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
if (pPresent != NULL)
|
|
|
|
pPresent->SetPresent(false);
|
|
|
|
pPresent = pEvent;
|
|
|
|
pPresent->SetPresent(true);
|
|
|
|
|
|
|
|
return true;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
bool cSchedule::SetFollowingEvent(cEventInfo *pEvent)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
if (pFollowing != NULL)
|
|
|
|
pFollowing->SetFollowing(false);
|
|
|
|
pFollowing = pEvent;
|
|
|
|
pFollowing->SetFollowing(true);
|
|
|
|
|
|
|
|
return true;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
void cSchedule::Cleanup()
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
Cleanup(time(NULL));
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
void cSchedule::Cleanup(time_t tTime)
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
cEventInfo *pEvent;
|
|
|
|
for (int a = 0; true ; a++)
|
|
|
|
{
|
|
|
|
pEvent = Events.Get(a);
|
|
|
|
if (pEvent == NULL)
|
|
|
|
break;
|
2001-08-19 14:45:31 +02:00
|
|
|
if (pEvent->GetTime() + pEvent->GetDuration() + 3600 < tTime) // adding one hour for safety
|
2001-03-31 15:04:37 +02:00
|
|
|
{
|
|
|
|
Events.Del(pEvent);
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
}
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
2000-11-26 15:23:39 +01:00
|
|
|
/** */
|
2001-04-01 15:40:43 +02:00
|
|
|
void cSchedule::Dump(FILE *f, const char *Prefix) const
|
2000-11-26 15:23:39 +01:00
|
|
|
{
|
|
|
|
cChannel *channel = Channels.GetByServiceID(uServiceID);
|
|
|
|
if (channel)
|
|
|
|
{
|
2002-10-06 10:25:42 +02:00
|
|
|
fprintf(f, "%sC %u %s\n", Prefix, uServiceID, channel->Name());
|
2000-11-26 15:23:39 +01:00
|
|
|
for (cEventInfo *p = Events.First(); p; p = Events.Next(p))
|
2001-04-01 15:40:43 +02:00
|
|
|
p->Dump(f, Prefix);
|
|
|
|
fprintf(f, "%sc\n", Prefix);
|
2000-11-26 15:23:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-23 17:11:19 +01:00
|
|
|
bool cSchedule::Read(FILE *f, cSchedules *Schedules)
|
|
|
|
{
|
|
|
|
if (Schedules) {
|
|
|
|
char *s;
|
|
|
|
while ((s = readline(f)) != NULL) {
|
|
|
|
if (*s == 'C') {
|
|
|
|
unsigned int uServiceID;
|
|
|
|
if (1 == sscanf(s + 1, "%u", &uServiceID)) {
|
|
|
|
cSchedule *p = (cSchedule *)Schedules->SetCurrentServiceID(uServiceID);
|
|
|
|
if (p) {
|
2002-04-06 14:02:41 +02:00
|
|
|
if (!cEventInfo::Read(f, p))
|
|
|
|
return false;
|
2002-02-23 17:11:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-05-13 16:35:49 +02:00
|
|
|
esyslog("ERROR: unexpected tag while reading EPG data: %s", s);
|
2002-02-23 17:11:19 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
// --- cSchedules ------------------------------------------------------------
|
|
|
|
|
|
|
|
cSchedules::cSchedules()
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
pCurrentSchedule = NULL;
|
|
|
|
uCurrentServiceID = 0;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cSchedules::~cSchedules()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/** */
|
2002-02-23 17:11:19 +01:00
|
|
|
const cSchedule *cSchedules::SetCurrentServiceID(unsigned short servid)
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
pCurrentSchedule = GetSchedule(servid);
|
|
|
|
if (pCurrentSchedule == NULL)
|
|
|
|
{
|
|
|
|
Add(new cSchedule(servid));
|
|
|
|
pCurrentSchedule = GetSchedule(servid);
|
|
|
|
if (pCurrentSchedule == NULL)
|
2002-02-23 17:11:19 +01:00
|
|
|
return NULL;
|
2001-03-31 15:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uCurrentServiceID = servid;
|
|
|
|
|
2002-02-23 17:11:19 +01:00
|
|
|
return pCurrentSchedule;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
const cSchedule * cSchedules::GetSchedule() const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
return pCurrentSchedule;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
/** */
|
|
|
|
const cSchedule * cSchedules::GetSchedule(unsigned short servid) const
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
cSchedule *p;
|
|
|
|
|
|
|
|
p = First();
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
if (p->GetServiceID() == servid)
|
|
|
|
return p;
|
|
|
|
p = Next(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
|
|
|
void cSchedules::Cleanup()
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
cSchedule *p;
|
|
|
|
|
|
|
|
p = First();
|
|
|
|
while (p != NULL)
|
|
|
|
{
|
|
|
|
p->Cleanup(time(NULL));
|
|
|
|
p = Next(p);
|
|
|
|
}
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
2000-11-26 15:23:39 +01:00
|
|
|
/** */
|
2001-04-01 15:40:43 +02:00
|
|
|
void cSchedules::Dump(FILE *f, const char *Prefix) const
|
2000-11-26 15:23:39 +01:00
|
|
|
{
|
|
|
|
for (cSchedule *p = First(); p; p = Next(p))
|
2001-04-01 15:40:43 +02:00
|
|
|
p->Dump(f, Prefix);
|
2000-11-26 15:23:39 +01:00
|
|
|
}
|
|
|
|
|
2002-02-23 17:11:19 +01:00
|
|
|
/** */
|
|
|
|
bool cSchedules::Read(FILE *f)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock;
|
|
|
|
return cSchedule::Read(f, (cSchedules *)cSIProcessor::Schedules(MutexLock));
|
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
// --- cEIT ------------------------------------------------------------------
|
|
|
|
|
|
|
|
class cEIT {
|
|
|
|
private:
|
|
|
|
cSchedules *schedules;
|
2001-03-31 15:04:37 +02:00
|
|
|
public:
|
2001-08-15 13:56:11 +02:00
|
|
|
cEIT(unsigned char *buf, int length, cSchedules *Schedules);
|
2001-03-31 15:04:37 +02:00
|
|
|
~cEIT();
|
2000-10-29 13:17:22 +01:00
|
|
|
/** */
|
2001-08-15 13:56:11 +02:00
|
|
|
int ProcessEIT(unsigned char *buffer);
|
2000-09-03 11:40:00 +02:00
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
protected: // Protected methods
|
|
|
|
/** returns true if this EIT covers a
|
|
|
|
present/following information, false if it's
|
|
|
|
schedule information */
|
|
|
|
bool IsPresentFollowing();
|
|
|
|
protected: // Protected attributes
|
|
|
|
/** Table ID of this EIT struct */
|
|
|
|
u_char tid;
|
|
|
|
};
|
2000-09-03 11:40:00 +02:00
|
|
|
|
2001-08-15 13:56:11 +02:00
|
|
|
cEIT::cEIT(unsigned char * buf, int length, cSchedules *Schedules)
|
2000-09-03 11:40:00 +02:00
|
|
|
{
|
2001-08-15 13:56:11 +02:00
|
|
|
tid = buf[0];
|
2000-10-29 13:17:22 +01:00
|
|
|
schedules = Schedules;
|
2000-09-03 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cEIT::~cEIT()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
2001-08-15 13:56:11 +02:00
|
|
|
int cEIT::ProcessEIT(unsigned char *buffer)
|
|
|
|
{
|
|
|
|
cEventInfo *pEvent, *rEvent = NULL;
|
|
|
|
cSchedule *pSchedule, *rSchedule = NULL;
|
|
|
|
struct LIST *VdrProgramInfos;
|
|
|
|
struct VdrProgramInfo *VdrProgramInfo;
|
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
VdrProgramInfos = createVdrProgramInfos(buffer);
|
|
|
|
|
|
|
|
if (VdrProgramInfos) {
|
|
|
|
for (VdrProgramInfo = (struct VdrProgramInfo *) VdrProgramInfos->Head; VdrProgramInfo; VdrProgramInfo = (struct VdrProgramInfo *) xSucc (VdrProgramInfo)) {
|
2002-09-15 13:05:57 +02:00
|
|
|
// Drop events that belong to an "other TS" and are very long (some stations broadcast bogus data for "other" channels):
|
|
|
|
if (VdrProgramInfo->Duration >= 86400 && (tid == 0x4F || tid == 0x60 || tid == 0x61))
|
|
|
|
continue;
|
2001-08-15 13:56:11 +02:00
|
|
|
pSchedule = (cSchedule *)schedules->GetSchedule(VdrProgramInfo->ServiceID);
|
|
|
|
if (!pSchedule) {
|
|
|
|
schedules->Add(new cSchedule(VdrProgramInfo->ServiceID));
|
|
|
|
pSchedule = (cSchedule *)schedules->GetSchedule(VdrProgramInfo->ServiceID);
|
|
|
|
if (!pSchedule)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (VdrProgramInfo->ReferenceServiceID) {
|
|
|
|
rSchedule = (cSchedule *)schedules->GetSchedule(VdrProgramInfo->ReferenceServiceID);
|
|
|
|
if (!rSchedule)
|
|
|
|
break;
|
|
|
|
rEvent = (cEventInfo *)rSchedule->GetEvent((unsigned short)VdrProgramInfo->ReferenceEventID);
|
|
|
|
if (!rEvent)
|
|
|
|
break;
|
|
|
|
}
|
2001-10-28 13:53:44 +01:00
|
|
|
pEvent = (cEventInfo *)pSchedule->GetEvent((unsigned short)VdrProgramInfo->EventID, VdrProgramInfo->StartTime);
|
2001-08-15 13:56:11 +02:00
|
|
|
if (!pEvent) {
|
2001-09-22 13:07:43 +02:00
|
|
|
// If we don't have that event ID yet, we create a new one.
|
|
|
|
// Otherwise we copy the information into the existing event anyway, because the data might have changed.
|
2002-02-23 17:11:19 +01:00
|
|
|
pEvent = pSchedule->AddEvent(new cEventInfo(VdrProgramInfo->ServiceID, VdrProgramInfo->EventID));
|
2001-08-15 13:56:11 +02:00
|
|
|
if (!pEvent)
|
|
|
|
break;
|
2001-10-28 13:53:44 +01:00
|
|
|
pEvent->SetTableID(tid);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We have found an existing event, either through its event ID or its start time.
|
2002-02-23 17:11:19 +01:00
|
|
|
// If the existing event has a zero table ID it was defined externally and shall
|
|
|
|
// not be overwritten.
|
|
|
|
if (pEvent->GetTableID() == 0x00)
|
|
|
|
continue;
|
2001-10-28 13:53:44 +01:00
|
|
|
// If the new event comes from a table that belongs to an "other TS" and the existing
|
2002-02-23 17:11:19 +01:00
|
|
|
// one comes from an "actual TS" table, lets skip it.
|
2002-02-15 14:01:01 +01:00
|
|
|
if ((tid == 0x4F || tid == 0x60 || tid == 0x61) && (pEvent->GetTableID() == 0x4E || pEvent->GetTableID() == 0x50 || pEvent->GetTableID() == 0x51))
|
2001-10-28 13:53:44 +01:00
|
|
|
continue;
|
2001-08-15 13:56:11 +02:00
|
|
|
}
|
2001-09-22 13:07:43 +02:00
|
|
|
if (rEvent) {
|
|
|
|
pEvent->SetTitle(rEvent->GetTitle());
|
|
|
|
pEvent->SetSubtitle(rEvent->GetSubtitle());
|
|
|
|
pEvent->SetExtendedDescription(rEvent->GetExtendedDescription());
|
|
|
|
}
|
|
|
|
else {
|
2001-10-28 13:53:44 +01:00
|
|
|
pEvent->SetTableID(tid);
|
2001-09-22 13:07:43 +02:00
|
|
|
pEvent->SetTitle(VdrProgramInfo->ShortName);
|
|
|
|
pEvent->SetSubtitle(VdrProgramInfo->ShortText);
|
|
|
|
pEvent->SetExtendedDescription(VdrProgramInfo->ExtendedName);
|
|
|
|
//XXX kls 2001-09-22:
|
|
|
|
//XXX apparently this never occurred, so I have simpified ExtendedDescription handling
|
|
|
|
//XXX pEvent->AddExtendedDescription(VdrProgramInfo->ExtendedText);
|
|
|
|
}
|
|
|
|
pEvent->SetTime(VdrProgramInfo->StartTime);
|
|
|
|
pEvent->SetDuration(VdrProgramInfo->Duration);
|
|
|
|
pEvent->FixEpgBugs();
|
2001-08-15 13:56:11 +02:00
|
|
|
if (IsPresentFollowing()) {
|
|
|
|
if ((GetRunningStatus(VdrProgramInfo->Status) == RUNNING_STATUS_PAUSING) || (GetRunningStatus(VdrProgramInfo->Status) == RUNNING_STATUS_RUNNING))
|
|
|
|
pSchedule->SetPresentEvent(pEvent);
|
|
|
|
else if (GetRunningStatus(VdrProgramInfo->Status) == RUNNING_STATUS_AWAITING)
|
|
|
|
pSchedule->SetFollowingEvent(pEvent);
|
|
|
|
}
|
|
|
|
}
|
2001-03-31 15:04:37 +02:00
|
|
|
}
|
|
|
|
|
2001-08-15 13:56:11 +02:00
|
|
|
xMemFreeAll(NULL);
|
2001-03-31 15:04:37 +02:00
|
|
|
return 0;
|
2000-09-03 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
/** returns true if this EIT covers a
|
|
|
|
present/following information, false if it's
|
|
|
|
schedule information */
|
|
|
|
bool cEIT::IsPresentFollowing()
|
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
if (tid == 0x4e || tid == 0x4f)
|
|
|
|
return true;
|
2000-09-03 11:40:00 +02:00
|
|
|
|
2001-03-31 15:04:37 +02:00
|
|
|
return false;
|
2000-09-03 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
// --- cSIProcessor ----------------------------------------------------------
|
|
|
|
|
|
|
|
#define MAX_FILTERS 20
|
2001-08-11 09:38:12 +02:00
|
|
|
#define EPGDATAFILENAME "epg.data"
|
2000-10-29 13:17:22 +01:00
|
|
|
|
2000-11-18 13:57:32 +01:00
|
|
|
int cSIProcessor::numSIProcessors = 0;
|
|
|
|
cSchedules *cSIProcessor::schedules = NULL;
|
|
|
|
cMutex cSIProcessor::schedulesMutex;
|
2001-08-11 09:38:12 +02:00
|
|
|
const char *cSIProcessor::epgDataFileName = EPGDATAFILENAME;
|
2000-11-18 13:57:32 +01:00
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
/** */
|
|
|
|
cSIProcessor::cSIProcessor(const char *FileName)
|
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
fileName = strdup(FileName);
|
2000-11-18 13:57:32 +01:00
|
|
|
masterSIProcessor = numSIProcessors == 0; // the first one becomes the 'master'
|
2000-10-29 13:17:22 +01:00
|
|
|
filters = NULL;
|
2001-06-02 10:47:40 +02:00
|
|
|
if (!numSIProcessors++) // the first one creates it
|
|
|
|
schedules = new cSchedules;
|
|
|
|
filters = (SIP_FILTER *)calloc(MAX_FILTERS, sizeof(SIP_FILTER));
|
|
|
|
SetStatus(true);
|
|
|
|
Start();
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cSIProcessor::~cSIProcessor()
|
|
|
|
{
|
2002-02-02 12:13:35 +01:00
|
|
|
if (masterSIProcessor)
|
|
|
|
ReportEpgBugFixStats();
|
2001-06-02 10:47:40 +02:00
|
|
|
active = false;
|
|
|
|
Cancel(3);
|
|
|
|
ShutDownFilters();
|
2002-08-11 13:32:23 +02:00
|
|
|
free(filters);
|
2001-06-02 10:47:40 +02:00
|
|
|
if (!--numSIProcessors) // the last one deletes it
|
|
|
|
delete schedules;
|
2002-08-11 13:32:23 +02:00
|
|
|
free(fileName);
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
|
|
|
|
2002-02-23 13:55:57 +01:00
|
|
|
const cSchedules *cSIProcessor::Schedules(cMutexLock &MutexLock)
|
|
|
|
{
|
|
|
|
if (MutexLock.Lock(&schedulesMutex))
|
|
|
|
return schedules;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-02-23 17:11:19 +01:00
|
|
|
bool cSIProcessor::Read(FILE *f)
|
|
|
|
{
|
|
|
|
bool OwnFile = f == NULL;
|
|
|
|
if (OwnFile) {
|
|
|
|
const char *FileName = GetEpgDataFileName();
|
|
|
|
if (access(FileName, R_OK) == 0) {
|
2002-05-13 16:35:49 +02:00
|
|
|
dsyslog("reading EPG data from %s", FileName);
|
2002-02-23 17:11:19 +01:00
|
|
|
if ((f = fopen(FileName, "r")) == NULL) {
|
|
|
|
LOG_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2002-02-25 16:32:34 +01:00
|
|
|
else
|
|
|
|
return false;
|
2002-02-23 17:11:19 +01:00
|
|
|
}
|
|
|
|
bool result = cSchedules::Read(f);
|
|
|
|
if (OwnFile)
|
|
|
|
fclose(f);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-08-25 10:49:02 +02:00
|
|
|
void cSIProcessor::Clear(void)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&schedulesMutex);
|
|
|
|
delete schedules;
|
|
|
|
schedules = new cSchedules;
|
|
|
|
}
|
|
|
|
|
2001-08-11 09:38:12 +02:00
|
|
|
void cSIProcessor::SetEpgDataFileName(const char *FileName)
|
|
|
|
{
|
|
|
|
epgDataFileName = NULL;
|
|
|
|
if (FileName)
|
|
|
|
epgDataFileName = strdup(DirectoryOk(FileName) ? AddDirectory(FileName, EPGDATAFILENAME) : FileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *cSIProcessor::GetEpgDataFileName(void)
|
|
|
|
{
|
2001-08-11 14:51:28 +02:00
|
|
|
if (epgDataFileName)
|
|
|
|
return *epgDataFileName == '/' ? epgDataFileName : AddDirectory(VideoDirectory, epgDataFileName);
|
|
|
|
return NULL;
|
2001-08-11 09:38:12 +02:00
|
|
|
}
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
void cSIProcessor::SetStatus(bool On)
|
|
|
|
{
|
|
|
|
ShutDownFilters();
|
|
|
|
if (On)
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
AddFilter(0x14, 0x70); // TDT
|
|
|
|
AddFilter(0x14, 0x73); // TOT
|
|
|
|
AddFilter(0x12, 0x4e); // event info, actual TS, present/following
|
|
|
|
AddFilter(0x12, 0x4f); // event info, other TS, present/following
|
|
|
|
AddFilter(0x12, 0x50); // event info, actual TS, schedule
|
|
|
|
AddFilter(0x12, 0x60); // event info, other TS, schedule
|
2002-02-15 14:01:01 +01:00
|
|
|
AddFilter(0x12, 0x51); // event info, actual TS, schedule for another 4 days
|
|
|
|
AddFilter(0x12, 0x61); // event info, other TS, schedule for another 4 days
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** use the vbi device to parse all relevant SI
|
|
|
|
information and let the classes corresponding
|
|
|
|
to the tables write their information to the disk */
|
|
|
|
void cSIProcessor::Action()
|
|
|
|
{
|
2002-05-13 16:35:49 +02:00
|
|
|
dsyslog("EIT processing thread started (pid=%d)%s", getpid(), masterSIProcessor ? " - master" : "");
|
2001-03-31 15:04:37 +02:00
|
|
|
|
2000-11-01 15:53:00 +01:00
|
|
|
time_t lastCleanup = time(NULL);
|
2000-11-26 15:23:39 +01:00
|
|
|
time_t lastDump = time(NULL);
|
2001-03-31 15:04:37 +02:00
|
|
|
|
|
|
|
active = true;
|
|
|
|
|
|
|
|
while(active)
|
|
|
|
{
|
2000-11-18 13:57:32 +01:00
|
|
|
if (masterSIProcessor)
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2000-11-18 13:57:32 +01:00
|
|
|
time_t now = time(NULL);
|
2001-10-19 13:22:24 +02:00
|
|
|
struct tm tm_r;
|
|
|
|
struct tm *ptm = localtime_r(&now, &tm_r);
|
2000-11-18 13:57:32 +01:00
|
|
|
if (now - lastCleanup > 3600 && ptm->tm_hour == 5)
|
|
|
|
{
|
2002-03-02 09:37:56 +01:00
|
|
|
cMutexLock MutexLock(&schedulesMutex);
|
2002-05-13 16:35:49 +02:00
|
|
|
isyslog("cleaning up schedules data");
|
2000-11-18 13:57:32 +01:00
|
|
|
schedules->Cleanup();
|
|
|
|
lastCleanup = now;
|
2002-02-02 12:13:35 +01:00
|
|
|
ReportEpgBugFixStats(true);
|
2000-11-18 13:57:32 +01:00
|
|
|
}
|
2001-08-11 09:38:12 +02:00
|
|
|
if (epgDataFileName && now - lastDump > 600)
|
2000-11-26 15:23:39 +01:00
|
|
|
{
|
2002-03-02 09:37:56 +01:00
|
|
|
cMutexLock MutexLock(&schedulesMutex);
|
2002-04-06 11:49:04 +02:00
|
|
|
cSafeFile f(GetEpgDataFileName());
|
|
|
|
if (f.Open()) {
|
2000-11-26 15:23:39 +01:00
|
|
|
schedules->Dump(f);
|
2002-04-06 11:49:04 +02:00
|
|
|
f.Close();
|
2000-11-26 15:23:39 +01:00
|
|
|
}
|
2001-08-11 09:38:12 +02:00
|
|
|
else
|
|
|
|
LOG_ERROR;
|
2000-11-26 15:23:39 +01:00
|
|
|
lastDump = now;
|
|
|
|
}
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
// set up pfd structures for all active filter
|
|
|
|
pollfd pfd[MAX_FILTERS];
|
|
|
|
int NumUsedFilters = 0;
|
|
|
|
for (int a = 0; a < MAX_FILTERS ; a++)
|
2001-03-31 15:04:37 +02:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
if (filters[a].inuse)
|
|
|
|
{
|
|
|
|
pfd[NumUsedFilters].fd = filters[a].handle;
|
|
|
|
pfd[NumUsedFilters].events = POLLIN;
|
|
|
|
NumUsedFilters++;
|
|
|
|
}
|
|
|
|
}
|
2001-03-31 15:04:37 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
// wait until data becomes ready from the bitfilter
|
|
|
|
if (poll(pfd, NumUsedFilters, 1000) != 0)
|
|
|
|
{
|
|
|
|
for (int a = 0; a < NumUsedFilters ; a++)
|
2001-03-31 15:04:37 +02:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
if (pfd[a].revents & POLLIN)
|
|
|
|
{
|
|
|
|
/* read section */
|
|
|
|
unsigned char buf[4096+1]; // max. allowed size for any EIT section (+1 for safety ;-)
|
2001-08-12 15:22:48 +02:00
|
|
|
if (safe_read(filters[a].handle, buf, 3) == 3)
|
2001-03-31 15:04:37 +02:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
int seclen = ((buf[1] & 0x0F) << 8) | (buf[2] & 0xFF);
|
|
|
|
int pid = filters[a].pid;
|
2001-08-12 15:22:48 +02:00
|
|
|
int n = safe_read(filters[a].handle, buf + 3, seclen);
|
2001-06-02 10:47:40 +02:00
|
|
|
if (n == seclen)
|
2000-10-29 13:17:22 +01:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
seclen += 3;
|
2002-05-13 16:35:49 +02:00
|
|
|
//dsyslog("Received pid 0x%02x with table ID 0x%02x and length of %04d\n", pid, buf[0], seclen);
|
2001-06-02 10:47:40 +02:00
|
|
|
switch (pid)
|
|
|
|
{
|
|
|
|
case 0x14:
|
|
|
|
if (buf[0] == 0x70)
|
|
|
|
{
|
2002-03-17 14:24:11 +01:00
|
|
|
if (Setup.SetSystemTime && Setup.TimeTransponder && ISTRANSPONDER(currentTransponder, Setup.TimeTransponder))
|
2001-06-02 10:47:40 +02:00
|
|
|
{
|
|
|
|
cTDT ctdt((tdt_t *)buf);
|
|
|
|
ctdt.SetSystemTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*XXX this comes pretty often:
|
|
|
|
else
|
2002-05-13 16:35:49 +02:00
|
|
|
dsyslog("Time packet was not 0x70 but 0x%02x\n", (int)buf[0]);
|
2001-06-02 10:47:40 +02:00
|
|
|
XXX*/
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x12:
|
|
|
|
if (buf[0] != 0x72)
|
|
|
|
{
|
2002-03-02 09:37:56 +01:00
|
|
|
cMutexLock MutexLock(&schedulesMutex);
|
2001-06-02 10:47:40 +02:00
|
|
|
cEIT ceit(buf, seclen, schedules);
|
2001-08-15 13:56:11 +02:00
|
|
|
ceit.ProcessEIT(buf);
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
|
|
|
else
|
2002-05-13 16:35:49 +02:00
|
|
|
dsyslog("Received stuffing section in EIT\n");
|
2001-06-02 10:47:40 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
2001-12-01 14:34:03 +01:00
|
|
|
/*XXX this just fills up the log file - shouldn't we rather try to re-sync?
|
2001-06-02 10:47:40 +02:00
|
|
|
else
|
2002-05-13 16:35:49 +02:00
|
|
|
dsyslog("read incomplete section - seclen = %d, n = %d", seclen, n);
|
2001-12-01 14:34:03 +01:00
|
|
|
XXX*/
|
2001-03-31 15:04:37 +02:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
2001-03-31 15:04:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2002-05-13 16:35:49 +02:00
|
|
|
dsyslog("EIT processing thread ended (pid=%d)%s", getpid(), masterSIProcessor ? " - master" : "");
|
2000-09-03 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
/** Add a filter with packet identifier pid and
|
|
|
|
table identifer tid */
|
|
|
|
bool cSIProcessor::AddFilter(u_char pid, u_char tid)
|
2000-09-03 11:40:00 +02:00
|
|
|
{
|
2002-10-11 13:23:44 +02:00
|
|
|
#ifdef NEWSTRUCT
|
|
|
|
dmx_sct_filter_params sctFilterParams;
|
|
|
|
#else
|
2001-06-02 10:47:40 +02:00
|
|
|
dmxSctFilterParams sctFilterParams;
|
2002-10-11 13:23:44 +02:00
|
|
|
#endif
|
2002-09-21 08:34:25 +02:00
|
|
|
memset(&sctFilterParams, 0, sizeof(sctFilterParams));
|
2001-06-02 10:47:40 +02:00
|
|
|
sctFilterParams.pid = pid;
|
|
|
|
sctFilterParams.timeout = 0;
|
|
|
|
sctFilterParams.flags = DMX_IMMEDIATE_START;
|
|
|
|
sctFilterParams.filter.filter[0] = tid;
|
|
|
|
sctFilterParams.filter.mask[0] = 0xFF;
|
2001-03-31 15:04:37 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < MAX_FILTERS; a++)
|
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
if (!filters[a].inuse)
|
2001-03-31 15:04:37 +02:00
|
|
|
{
|
|
|
|
filters[a].pid = pid;
|
|
|
|
filters[a].tid = tid;
|
2001-06-02 10:47:40 +02:00
|
|
|
if ((filters[a].handle = open(fileName, O_RDWR | O_NONBLOCK)) >= 0)
|
|
|
|
{
|
|
|
|
if (ioctl(filters[a].handle, DMX_SET_FILTER, &sctFilterParams) >= 0)
|
|
|
|
filters[a].inuse = true;
|
|
|
|
else
|
|
|
|
{
|
2002-05-13 16:35:49 +02:00
|
|
|
esyslog("ERROR: can't set filter");
|
2001-06-02 10:47:40 +02:00
|
|
|
close(filters[a].handle);
|
|
|
|
return false;
|
|
|
|
}
|
2002-05-13 16:35:49 +02:00
|
|
|
// dsyslog("Registered filter handle %04x, pid = %02d, tid = %02d", filters[a].handle, filters[a].pid, filters[a].tid);
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-05-13 16:35:49 +02:00
|
|
|
esyslog("ERROR: can't open filter handle");
|
2001-06-02 10:47:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
2001-03-31 15:04:37 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2002-05-13 16:35:49 +02:00
|
|
|
esyslog("ERROR: too many filters");
|
2001-03-31 15:04:37 +02:00
|
|
|
|
|
|
|
return false;
|
2000-09-03 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
/** */
|
2001-06-02 10:47:40 +02:00
|
|
|
bool cSIProcessor::ShutDownFilters(void)
|
2000-09-03 11:40:00 +02:00
|
|
|
{
|
2001-03-31 15:04:37 +02:00
|
|
|
for (int a = 0; a < MAX_FILTERS; a++)
|
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
if (filters[a].inuse)
|
2001-03-31 15:04:37 +02:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
close(filters[a].handle);
|
2002-05-13 16:35:49 +02:00
|
|
|
// dsyslog("Deregistered filter handle %04x, pid = %02d, tid = %02d", filters[a].handle, filters[a].pid, filters[a].tid);
|
2001-03-31 15:04:37 +02:00
|
|
|
filters[a].inuse = false;
|
|
|
|
}
|
|
|
|
}
|
2000-10-29 13:17:22 +01:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
return true; // there's no real 'boolean' to return here...
|
2000-09-03 11:40:00 +02:00
|
|
|
}
|
|
|
|
|
2002-03-10 12:45:58 +01:00
|
|
|
/** */
|
|
|
|
void cSIProcessor::SetCurrentTransponder(int CurrentTransponder)
|
|
|
|
{
|
|
|
|
currentTransponder = CurrentTransponder;
|
|
|
|
}
|
|
|
|
|
2000-10-29 13:17:22 +01:00
|
|
|
/** */
|
|
|
|
bool cSIProcessor::SetCurrentServiceID(unsigned short servid)
|
2000-09-03 11:40:00 +02:00
|
|
|
{
|
2002-03-02 09:37:56 +01:00
|
|
|
cMutexLock MutexLock(&schedulesMutex);
|
2000-10-29 13:17:22 +01:00
|
|
|
return schedules ? schedules->SetCurrentServiceID(servid) : false;
|
2000-09-03 11:40:00 +02:00
|
|
|
}
|