mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-27 07:23:09 +02:00
Merge branch 'dvbsi++' of c00lstreamtech.de:cst-private-neutrino into includecleanup
Conflicts: src/eitd/SIlanguage.cpp src/eitd/SIsections.cpp src/eitd/dmx.cpp src/eitd/dmxapi.cpp
This commit is contained in:
@@ -1,27 +1,30 @@
|
||||
//
|
||||
// sectionsd.cpp (network daemon for SI-sections)
|
||||
// (dbox-II-project)
|
||||
//
|
||||
// Copyright (C) 2001 by fnbrd
|
||||
//
|
||||
// Homepage: http://dbox2.elxsi.de
|
||||
//
|
||||
// Copyright (C) 2008, 2009 Stefan Seyfried
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
/*
|
||||
* sectionsd.cpp (network daemon for SI-sections)
|
||||
* (dbox-II-project)
|
||||
*
|
||||
* Copyright (C) 2001 by fnbrd (fnbrd@gmx.de)
|
||||
* Homepage: http://dbox2.elxsi.de
|
||||
*
|
||||
* Copyright (C) 2008, 2009 Stefan Seyfried
|
||||
*
|
||||
* Copyright (C) 2011-2012 CoolStream International Ltd
|
||||
*
|
||||
* License: GPLv2
|
||||
*
|
||||
* 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;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <malloc.h>
|
||||
@@ -55,7 +58,6 @@
|
||||
#include <eventserver.h>
|
||||
#include <driver/abstime.h>
|
||||
|
||||
#include "dmxapi.h"
|
||||
#include "eitd.h"
|
||||
#include "edvbstring.h"
|
||||
#include "xmlutil.h"
|
||||
@@ -123,8 +125,6 @@ static t_channel_id messaging_current_servicekey = 0;
|
||||
static bool channel_is_blacklisted = false;
|
||||
|
||||
bool timeset = false;
|
||||
//pthread_cond_t timeIsSetCond = PTHREAD_COND_INITIALIZER;
|
||||
//pthread_mutex_t timeIsSetMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static int messaging_have_CN = 0x00; // 0x01 = CURRENT, 0x02 = NEXT
|
||||
static int messaging_got_CN = 0x00; // 0x01 = CURRENT, 0x02 = NEXT
|
||||
@@ -137,9 +137,6 @@ static CEventServer *eventServer;
|
||||
static pthread_rwlock_t servicesLock = PTHREAD_RWLOCK_INITIALIZER; // Unsere (fast-)mutex, damit nicht gleichzeitig in die Menge services geschrieben und gelesen wird
|
||||
static pthread_rwlock_t messagingLock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
|
||||
//static pthread_cond_t timeThreadSleepCond = PTHREAD_COND_INITIALIZER;
|
||||
//static pthread_mutex_t timeThreadSleepMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static CTimeThread threadTIME;
|
||||
static CEitThread threadEIT;
|
||||
static CCNThread threadCN;
|
||||
@@ -204,22 +201,6 @@ inline void unlockEvents(void)
|
||||
pthread_rwlock_unlock(&eventsLock);
|
||||
}
|
||||
|
||||
#if 0
|
||||
inline bool waitForTimeset(void)
|
||||
{
|
||||
pthread_mutex_lock(&timeIsSetMutex);
|
||||
while(!timeset)
|
||||
pthread_cond_wait(&timeIsSetCond, &timeIsSetMutex);
|
||||
pthread_mutex_unlock(&timeIsSetMutex);
|
||||
/* we have time synchronization issues, at least on kernel 2.4, so
|
||||
sometimes the time in the threads is still 1.1.1970, even after
|
||||
waitForTimeset() returns. Let's hope that we work around this issue
|
||||
with this sleep */
|
||||
sleep(1);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const SIevent nullEvt; // Null-Event
|
||||
|
||||
static MySIeventsOrderUniqueKey mySIeventsOrderUniqueKey;
|
||||
@@ -855,10 +836,10 @@ static void commandPauseScanning(int connfd, char *data, const unsigned dataLeng
|
||||
threadCN.request_pause();
|
||||
threadEIT.request_pause();
|
||||
#ifdef ENABLE_FREESATEPG
|
||||
dmxFSEIT.request_pause();
|
||||
threadFSEIT.request_pause();
|
||||
#endif
|
||||
#ifdef ENABLE_SDT
|
||||
dmxSDT.request_pause();
|
||||
threadSDT.request_pause();
|
||||
#endif
|
||||
#endif
|
||||
scanning = 0;
|
||||
@@ -869,10 +850,10 @@ static void commandPauseScanning(int connfd, char *data, const unsigned dataLeng
|
||||
threadCN.request_unpause();
|
||||
threadEIT.request_unpause();
|
||||
#ifdef ENABLE_FREESATEPG
|
||||
dmxFSEIT.request_unpause();
|
||||
threadFSEIT.request_unpause();
|
||||
#endif
|
||||
#ifdef ENABLE_SDT
|
||||
dmxSDT.request_unpause();
|
||||
threadSDT.request_unpause();
|
||||
#endif
|
||||
#endif
|
||||
writeLockEvents();
|
||||
@@ -888,20 +869,16 @@ static void commandPauseScanning(int connfd, char *data, const unsigned dataLeng
|
||||
unlockMessaging();
|
||||
|
||||
scanning = 1;
|
||||
if (!ntpenable) //FIXME flag if ntp update was good ?
|
||||
/* FIXME should we stop time updates if not scanning ? flag if ntp update was good ? */
|
||||
if (!ntpenable)
|
||||
{
|
||||
#if 0
|
||||
pthread_mutex_lock(&timeThreadSleepMutex);
|
||||
pthread_cond_broadcast(&timeThreadSleepCond);
|
||||
pthread_mutex_unlock(&timeThreadSleepMutex);
|
||||
#endif
|
||||
threadTIME.change(0);
|
||||
}
|
||||
|
||||
threadCN.change(0);
|
||||
threadEIT.change(0);
|
||||
#ifdef ENABLE_FREESATEPG
|
||||
dmxFSEIT.change(0);
|
||||
threadFSEIT.change(0);
|
||||
#endif
|
||||
#ifdef ENABLE_SDT
|
||||
threadSDT.change(0);
|
||||
@@ -921,12 +898,11 @@ static void commandserviceChanged(int connfd, char *data, const unsigned dataLen
|
||||
uniqueServiceKey = (((sectionsd::commandSetServiceChanged *)data)->channel_id);
|
||||
uniqueServiceKey &= 0xFFFFFFFFFFFFULL;
|
||||
|
||||
dprintf("[sectionsd] commandserviceChanged: Service changed to " PRINTF_CHANNEL_ID_TYPE "\n", uniqueServiceKey);
|
||||
xprintf("[sectionsd] commandserviceChanged: Service change to " PRINTF_CHANNEL_ID_TYPE "\n\n", uniqueServiceKey);
|
||||
xprintf("[sectionsd] commandserviceChanged: Service change to " PRINTF_CHANNEL_ID_TYPE "\n\n", uniqueServiceKey);
|
||||
|
||||
static t_channel_id time_trigger_last = 0;
|
||||
|
||||
if (uniqueServiceKey && messaging_current_servicekey != uniqueServiceKey) {
|
||||
if (messaging_current_servicekey != uniqueServiceKey) {
|
||||
dvb_time_update = !checkNoDVBTimelist(uniqueServiceKey);
|
||||
dprintf("[sectionsd] commandserviceChanged: DVB time update is %s\n", dvb_time_update ? "allowed" : "blocked!");
|
||||
|
||||
@@ -950,18 +926,13 @@ xprintf("[sectionsd] commandserviceChanged: Service change to " PRINTF_CHANNEL_I
|
||||
threadCN.setCurrentService(messaging_current_servicekey);
|
||||
threadEIT.setCurrentService(messaging_current_servicekey);
|
||||
#ifdef ENABLE_FREESATEPG
|
||||
dmxFSEIT.setCurrentService(messaging_current_servicekey);
|
||||
threadFSEIT.setCurrentService(messaging_current_servicekey);
|
||||
#endif
|
||||
#ifdef ENABLE_SDT
|
||||
threadSDT.setCurrentService(messaging_current_servicekey);
|
||||
#endif
|
||||
if (time_trigger_last != (messaging_current_servicekey & 0xFFFFFFFF0000ULL)) {
|
||||
time_trigger_last = messaging_current_servicekey & 0xFFFFFFFF0000ULL;
|
||||
#if 0
|
||||
pthread_mutex_lock(&timeThreadSleepMutex);
|
||||
pthread_cond_broadcast(&timeThreadSleepCond);
|
||||
pthread_mutex_unlock(&timeThreadSleepMutex);
|
||||
#endif
|
||||
threadTIME.setCurrentService(messaging_current_servicekey);
|
||||
}
|
||||
}
|
||||
@@ -970,7 +941,7 @@ xprintf("[sectionsd] commandserviceChanged: Service change to " PRINTF_CHANNEL_I
|
||||
|
||||
out:
|
||||
//sendEmptyResponse(connfd, NULL, 0);
|
||||
xprintf("[sectionsd] commandserviceChanged: Service changed to " PRINTF_CHANNEL_ID_TYPE "\n\n", uniqueServiceKey);
|
||||
xprintf("[sectionsd] commandserviceChanged: Service changed to " PRINTF_CHANNEL_ID_TYPE "\n\n", uniqueServiceKey);
|
||||
}
|
||||
|
||||
static void commandGetIsScanningActive(int connfd, char* /*data*/, const unsigned /*dataLength*/)
|
||||
@@ -1021,7 +992,6 @@ static void commandDumpStatusInformation(int /*connfd*/, char* /*data*/, const u
|
||||
char stati[MAX_SIZE_STATI];
|
||||
|
||||
snprintf(stati, MAX_SIZE_STATI,
|
||||
"$Id: sectionsd.cpp,v 1.305 2009/07/30 12:41:39 seife Exp $\n"
|
||||
"Current time: %s"
|
||||
"Hours to cache: %ld\n"
|
||||
"Hours to cache extended text: %ld\n"
|
||||
@@ -1117,20 +1087,11 @@ static void commandSetConfig(int connfd, char *data, const unsigned /*dataLength
|
||||
}
|
||||
|
||||
if (time_wakeup) {
|
||||
//pthread_mutex_lock(&timeThreadSleepMutex);
|
||||
|
||||
ntpserver = (std::string)&data[sizeof(struct sectionsd::commandSetConfig)];
|
||||
dprintf("new network_ntpserver = %s\n", ntpserver.c_str());
|
||||
ntp_system_cmd = ntp_system_cmd_prefix + ntpserver;
|
||||
ntprefresh = pmsg->network_ntprefresh;
|
||||
ntpenable = (pmsg->network_ntpenable == 1);
|
||||
#if 0
|
||||
if (timeset) {
|
||||
// wake up time thread
|
||||
pthread_cond_broadcast(&timeThreadSleepCond);
|
||||
}
|
||||
pthread_mutex_unlock(&timeThreadSleepMutex);
|
||||
#endif
|
||||
if(timeset)
|
||||
threadTIME.change(1);
|
||||
}
|
||||
@@ -1150,8 +1111,8 @@ static void deleteSIexceptEPG()
|
||||
threadSDT.change(0);
|
||||
#endif
|
||||
#ifdef ENABLE_FREESATEPG
|
||||
dmxFSEIT.setCurrentService(messaging_current_servicekey);
|
||||
dmxFSEIT.change(0);
|
||||
threadFSEIT.setCurrentService(messaging_current_servicekey);
|
||||
threadFSEIT.change(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1342,6 +1303,7 @@ CTimeThread::CTimeThread()
|
||||
|
||||
void CTimeThread::sendTimeEvent(bool ntp, time_t tim)
|
||||
{
|
||||
#if 0
|
||||
time_t actTime = time(NULL);
|
||||
if (!ntp) {
|
||||
struct tm *tmTime = localtime(&actTime);
|
||||
@@ -1350,6 +1312,9 @@ void CTimeThread::sendTimeEvent(bool ntp, time_t tim)
|
||||
actTime = tim;
|
||||
}
|
||||
eventServer->sendEvent(CSectionsdClient::EVT_TIMESET, CEventServer::INITID_SECTIONSD, &actTime, sizeof(actTime) );
|
||||
#endif
|
||||
if(ntp || tim) {}
|
||||
eventServer->sendEvent(CSectionsdClient::EVT_TIMESET, CEventServer::INITID_SECTIONSD, &timediff, sizeof(timediff));
|
||||
setTimeSet();
|
||||
}
|
||||
|
||||
@@ -1377,18 +1342,22 @@ void CTimeThread::setSystemTime(time_t tim)
|
||||
struct tm *tmTime = localtime(&now);
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
timediff = tim * (int64_t)1000000 - (tv.tv_usec + tv.tv_sec * (int64_t)1000000);
|
||||
timediff = (int64_t)tim * (int64_t)1000000 - (tv.tv_usec + tv.tv_sec * (int64_t)1000000);
|
||||
|
||||
xprintf("%s: timediff %lld, current: %02d.%02d.%04d %02d:%02d:%02d, dvb: %s", name.c_str(), timediff,
|
||||
tmTime->tm_mday, tmTime->tm_mon+1, tmTime->tm_year+1900,
|
||||
tmTime->tm_hour, tmTime->tm_min, tmTime->tm_sec, ctime(&tim));
|
||||
|
||||
if (!messaging_neutrino_sets_time) {
|
||||
tv.tv_sec = tim;
|
||||
tv.tv_usec = 0;
|
||||
if (settimeofday(&tv, NULL) < 0)
|
||||
perror("[sectionsd] settimeofday");
|
||||
/* if new time less than current for less than 1 second, ignore */
|
||||
if(timediff < 0 && timediff > (int64_t) -1000000) {
|
||||
timediff = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
tv.tv_sec = tim;
|
||||
tv.tv_usec = 0;
|
||||
if (settimeofday(&tv, NULL) < 0)
|
||||
perror("[sectionsd] settimeofday");
|
||||
}
|
||||
|
||||
void CTimeThread::addFilters()
|
||||
@@ -1411,12 +1380,15 @@ void CTimeThread::run()
|
||||
xprintf("%s: going to sleep %d seconds, running %d scanning %d\n",
|
||||
name.c_str(), sleep_time, running, scanning);
|
||||
#endif
|
||||
real_pause();
|
||||
int rs = Sleep();
|
||||
do {
|
||||
real_pause();
|
||||
int rs = Sleep();
|
||||
#ifdef DEBUG_TIME_THREAD
|
||||
xprintf("%s: wakeup, running %d scanning %d reason %d\n",
|
||||
name.c_str(), running, scanning, rs);
|
||||
xprintf("%s: wakeup, running %d scanning %d channel %llx reason %d\n",
|
||||
name.c_str(), running, scanning, current_service, rs);
|
||||
#endif
|
||||
} while (running && !scanning);
|
||||
|
||||
if (!running)
|
||||
break;
|
||||
}
|
||||
@@ -1434,9 +1406,9 @@ void CTimeThread::run()
|
||||
else
|
||||
change(0);
|
||||
|
||||
xprintf("timeThread: getting DVB time (isOpen %d)\n", isOpen());
|
||||
xprintf("%s: getting DVB time (isOpen %d)\n", name.c_str(), isOpen());
|
||||
int rc = dmx->Read(static_buf, MAX_SECTION_LENGTH, timeoutInMSeconds);
|
||||
xprintf("timeThread: getting DVB time done : %d messaging_neutrino_sets_time %d\n", rc, messaging_neutrino_sets_time);
|
||||
xprintf("%s: getting DVB time done : %d messaging_neutrino_sets_time %d\n", name.c_str(), rc, messaging_neutrino_sets_time);
|
||||
if (rc > 0) {
|
||||
SIsectionTIME st(static_buf);
|
||||
if (st.is_parsed()) {
|
||||
@@ -1465,60 +1437,8 @@ void CTimeThread::run()
|
||||
sleep_time = 1;
|
||||
}
|
||||
sendToSleepNow = true;
|
||||
|
||||
#if 0
|
||||
if (timeset && dvb_time_update) {
|
||||
if (!first_time)
|
||||
sleep_time = ntprefresh * 60;
|
||||
else
|
||||
sleep_time = 5; /* retry a second time immediately */
|
||||
|
||||
if (time_ntp) {
|
||||
xprintf("[%sThread] Time set via NTP, going to sleep for %d seconds.\n", "time", sleep_time);
|
||||
}
|
||||
else {
|
||||
xprintf("[%sThread] Time %sset via DVB(%s), going to sleep for %d seconds.\n",
|
||||
"time", success?"":"not ", first_time?"TDT":"TOT", sleep_time);
|
||||
}
|
||||
first_time = false;
|
||||
}
|
||||
else {
|
||||
if (!first_time) {
|
||||
/* time was already set, no need to do it again soon when DVB time-blocked channel is tuned */
|
||||
sleep_time = ntprefresh * 60;
|
||||
} else {
|
||||
sleep_time = 1;
|
||||
}
|
||||
if (!dvb_time_update && !first_time) {
|
||||
xprintf("[%sThread] Time NOT set via DVB due to blocked channel, going to sleep for %d seconds.\n", "time", sleep_time);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if 0
|
||||
if (sectionsd_stop)
|
||||
break;
|
||||
|
||||
xprintf("timeThread: going to sleep for %d sec\n\n", seconds);
|
||||
|
||||
struct timespec restartWait;
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
TIMEVAL_TO_TIMESPEC(&now, &restartWait);
|
||||
restartWait.tv_sec += seconds;
|
||||
pthread_mutex_lock( &timeThreadSleepMutex );
|
||||
int ret = pthread_cond_timedwait( &timeThreadSleepCond, &timeThreadSleepMutex, &restartWait );
|
||||
pthread_mutex_unlock( &timeThreadSleepMutex );
|
||||
if (ret == ETIMEDOUT)
|
||||
{
|
||||
dprintf("TDT-Thread sleeping is over - no signal received\n");
|
||||
}
|
||||
else if (ret == EINTR)
|
||||
{
|
||||
dprintf("TDT-Thread sleeping interrupted\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
delete[] static_buf;
|
||||
printf("[sectionsd] timeThread ended\n");
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
@@ -1732,7 +1652,6 @@ void CEitThread::addFilters()
|
||||
|
||||
void CEitThread::beforeSleep()
|
||||
{
|
||||
xprintf("%s: CScheduledThread::beforeSleep()\n", name.c_str());
|
||||
writeLockMessaging();
|
||||
messaging_zap_detected = false;
|
||||
unlockMessaging();
|
||||
@@ -2090,14 +2009,12 @@ static void *houseKeepingThread(void *)
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
//extern cDemux * dmxUTC;
|
||||
|
||||
void sectionsd_main_thread(void * /*data*/)
|
||||
{
|
||||
pthread_t /*threadTOT,*/ threadHouseKeeping;
|
||||
int rc;
|
||||
|
||||
printf("$Id: sectionsd.cpp,v 1.305 2009/07/30 12:41:39 seife Exp $\n");
|
||||
xprintf("[sectionsd] starting\n");
|
||||
printf("SIevent size: %d\n", sizeof(SIevent));
|
||||
|
||||
/* "export NO_SLOW_ADDEVENT=true" to disable this */
|
||||
@@ -2152,18 +2069,8 @@ printf("SIevent size: %d\n", sizeof(SIevent));
|
||||
|
||||
eventServer = new CEventServer;
|
||||
|
||||
#if 0
|
||||
// time-Thread starten
|
||||
rc = pthread_create(&threadTOT, 0, timeThread, 0);
|
||||
|
||||
if (rc) {
|
||||
fprintf(stderr, "[sectionsd] failed to create time-thread (rc=%d)\n", rc);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
threadTIME.Start();
|
||||
threadEIT.Start();
|
||||
|
||||
threadCN.Start();
|
||||
|
||||
#ifdef ENABLE_FREESATEPG
|
||||
@@ -2208,35 +2115,16 @@ printf("SIevent size: %d\n", sizeof(SIevent));
|
||||
threadTIME.StopRun();
|
||||
|
||||
xprintf("broadcasting...\n");
|
||||
#if 0
|
||||
timeset = true;
|
||||
pthread_mutex_lock(&timeIsSetMutex);
|
||||
pthread_cond_broadcast(&timeIsSetCond);
|
||||
pthread_mutex_unlock(&timeIsSetMutex);
|
||||
#endif
|
||||
|
||||
threadTIME.setTimeSet();
|
||||
#if 0
|
||||
pthread_mutex_lock(&timeThreadSleepMutex);
|
||||
pthread_cond_broadcast(&timeThreadSleepCond);
|
||||
pthread_mutex_unlock(&timeThreadSleepMutex);
|
||||
#endif
|
||||
|
||||
xprintf("pausing...\n");
|
||||
|
||||
pthread_cancel(threadHouseKeeping);
|
||||
|
||||
//if (dmxUTC) dmxUTC->Stop();
|
||||
|
||||
#if 0
|
||||
xprintf("cancel TOT\n");
|
||||
//threadTIME.cancel();
|
||||
//pthread_cancel(threadTOT);
|
||||
#endif
|
||||
xprintf("join TOT\n");
|
||||
//pthread_join(threadTOT, NULL);
|
||||
threadTIME.Stop();
|
||||
|
||||
//if (dmxUTC) delete dmxUTC;
|
||||
|
||||
xprintf("join EIT\n");
|
||||
threadEIT.Stop();
|
||||
|
||||
|
Reference in New Issue
Block a user