From a16e2859ad6195d951147194bde0e9c30ceb65b2 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Thu, 1 Sep 2011 12:17:33 +0000 Subject: [PATCH] zapit converted to CZapit class. * new class to monitor SDT changes - saving current services xml moved to CServiceManager git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-beta@1647 e54a6e83-5905-42d5-8d5c-058d10e6a962 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/6cf95ce637c819bf231abe5b36958e2cae874d0f Author: [CST] Focus Date: 2011-09-01 (Thu, 01 Sep 2011) Origin message was: ------------------ * zapit converted to CZapit class. * new class to monitor SDT changes - saving current services xml moved to CServiceManager git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-beta@1647 e54a6e83-5905-42d5-8d5c-058d10e6a962 --- src/zapit/include/zapit/zapit.h | 166 +++- src/zapit/src/zapit.cpp | 1522 ++++++++++++------------------- 2 files changed, 746 insertions(+), 942 deletions(-) diff --git a/src/zapit/include/zapit/zapit.h b/src/zapit/include/zapit/zapit.h index fd8cb8cdd..351cf5d48 100644 --- a/src/zapit/include/zapit/zapit.h +++ b/src/zapit/include/zapit/zapit.h @@ -5,35 +5,151 @@ #ifndef __zapit_h__ #define __zapit_h__ +#include +#include +#include +#include +#include +#include + #include "client/zapitclient.h" -#include "bouquets.h" - -void save_settings (bool write); -void *start_scanthread(void *); -int start_scan(bool scan_mode); - -/**************************************************************/ -/* functions for new command handling via CZapitClient */ -/* these functions should be encapsulated in a class CZapit */ -/**************************************************************/ - -void addChannelToBouquet (const unsigned int bouquet, const t_channel_id channel_id); -void sendBouquets (int connfd, const bool emptyBouquetsToo, CZapitClient::channelsMode mode = CZapitClient::MODE_CURRENT); -void internalSendChannels(int connfd, ZapitChannelList* channels, bool nonames); -void sendBouquetChannels (int connfd, const unsigned int bouquet, CZapitClient::channelsMode mode = CZapitClient::MODE_CURRENT, bool nonames = false); -void sendChannels (int connfd, const CZapitClient::channelsMode mode = CZapitClient::MODE_CURRENT, const CZapitClient::channelsOrder order = CZapitClient::SORT_BOUQUET); -int startPlayBack(CZapitChannel *); -int stopPlayBack(bool stop_camd); -unsigned int zapTo(const unsigned int channel); -unsigned int zapTo(const unsigned int bouquet, const unsigned int channel); -unsigned int zapTo_ChannelID(const t_channel_id channel_id, const bool isSubService); -void sendAPIDs(int connfd); -void enterStandby(void); -void leaveStandby(void); -void setVideoSystem_t(int video_system); +#include +#include #define PAL 0 #define NTSC 1 +#define AUDIO_CONFIG_FILE "/var/tuxbox/config/zapit/audio.conf" +typedef std::map audio_map_t; +typedef audio_map_t::iterator audio_map_iterator_t; +typedef std::map sdt_tp_map_t; + +class CZapitSdtMonitor : public OpenThreads::Thread +{ + private: + bool started; + bool sdt_wakeup; + + sdt_tp_map_t sdt_tp; + + void run(); + + public: + CZapitSdtMonitor(); + ~CZapitSdtMonitor(); + bool Start(); + bool Stop(); + void Wakeup(); +}; + +class CZapit : public OpenThreads::Thread +{ + private: + enum { + TV_MODE = 0x01, + RADIO_MODE = 0x02, + RECORD_MODE = 0x04 + }; + + bool started; + bool event_mode; + + int audio_mode; + int def_audio_mode; + int aspectratio; + int mode43; + unsigned int volume_left; + unsigned int volume_right; + unsigned int def_volume_left; + unsigned int def_volume_right; + + int currentMode; + bool playbackStopForced; + diseqc_t diseqcType; + + int video_mode; + Zapit_config config; + CConfigFile configfile; + CEventServer *eventServer; + CZapitChannel * current_channel; + +#if 0 //FIXME still globals + t_channel_id live_channel_id; +#endif + audio_map_t audio_map; + bool current_is_nvod; + bool standby; + uint32_t lastChannelRadio; + uint32_t lastChannelTV; + int abort_zapit; + int pmt_update_fd; + + void LoadAudioMap(); + void SaveSettings(bool write_conf, bool write_audio); + void SaveChannelPids(CZapitChannel* channel); + void RestoreChannelPids(CZapitChannel* channel); + + bool TuneChannel(CZapitChannel * channel, bool &transponder_change); + bool ParsePatPmt(CZapitChannel * channel); + + bool send_data_count(int connfd, int data_count); + void sendAPIDs(int connfd); + void internalSendChannels(int connfd, ZapitChannelList* channels, const unsigned int first_channel_nr, bool nonames); + void sendBouquets(int connfd, const bool emptyBouquetsToo, CZapitClient::channelsMode mode); + void sendBouquetChannels(int connfd, const unsigned int bouquet, const CZapitClient::channelsMode mode, bool nonames); + void sendChannels(int connfd, const CZapitClient::channelsMode mode, const CZapitClient::channelsOrder order); + void SendConfig(int connfd); + + bool StartPlayBack(CZapitChannel *thisChannel); + bool StopPlayBack(bool send_pmt); + void SendPMT(bool forupdate = false); + void SetAudioStreamType(CZapitAudioChannel::ZapitAudioChannelType audioChannelType); + + void enterStandby(); + void leaveStandby(); + unsigned int ZapTo(const unsigned int bouquet, const unsigned int pchannel); + unsigned int ZapTo(t_channel_id channel_id, bool isSubService = false); + unsigned int ZapTo(const unsigned int pchannel); + void PrepareScan(); + + CZapitSdtMonitor SdtMonitor; + + static CZapit * zapit; + void run(); + CZapit(); + public: + ~CZapit(); + static CZapit * getInstance(); + + void LoadSettings(); + bool Start(Z_start_arg* ZapStart_arg); + bool Stop(); + bool ParseCommand(CBasicMessage::Header &rmsg, int connfd); + bool ZapIt(const t_channel_id channel_id, bool for_update = false, bool startplayback = true); + bool ZapForRecord(const t_channel_id channel_id); + bool ChangeAudioPid(uint8_t index); + void SetRadioMode(); + void SetTVMode(); + void SetRecordMode(bool enable); + int getMode(); + + bool PrepareChannels(); + bool StartScan(int scan_mode); + bool StartFastScan(int scan_mode, int opid); + + void addChannelToBouquet(const unsigned int bouquet, const t_channel_id channel_id); + void SetConfig(Zapit_config * Cfg); + void GetConfig(Zapit_config &Cfg); + + void SendEvent(const unsigned int eventID, const void* eventbody = NULL, const unsigned int eventbodysize = 0); + + audio_map_set_t * GetSavedPids(const t_channel_id channel_id); + + /* inlines */ + void Abort() { abort_zapit = 1; }; + bool Recording() { return currentMode & RECORD_MODE; }; + bool makeRemainingChannelsBouquet() { return config.makeRemainingChannelsBouquet; }; + bool scanSDT() { return config.scanSDT; }; +}; #endif /* __zapit_h__ */ diff --git a/src/zapit/src/zapit.cpp b/src/zapit/src/zapit.cpp index 84eb4ffb7..22025371e 100644 --- a/src/zapit/src/zapit.cpp +++ b/src/zapit/src/zapit.cpp @@ -22,7 +22,6 @@ */ /* system headers */ -#include #include #include #include @@ -36,10 +35,6 @@ #include #endif -/* tuxbox headers */ -#include -#include - /* zapit headers */ #include #include @@ -76,36 +71,15 @@ /* globals */ int zapit_ready; -int abort_zapit; -cCA *ca = NULL; -//cDvbCiSlot *one, *two; -extern cDemux * pmtDemux; - -#define AUDIO_CONFIG_FILE "/var/tuxbox/config/zapit/audio.conf" -map audio_map; -map::iterator audio_map_it; -unsigned int volume_left = 0, volume_right = 0; -unsigned int def_volume_left = 0, def_volume_right = 0; -int audio_mode = 0; -int aspectratio=0; -int mode43=0; -int def_audio_mode = 0; t_channel_id live_channel_id; t_channel_id rec_channel_id; -int rezapTimeout; + int feTimeout = 40; -bool fastZap; -bool sortNames; -bool mcemode = false; -bool sortlist = false; int scan_pids = false; bool highVoltage = false; -bool voltageOff = false; -bool event_mode = true; bool firstzap = true; bool playing = false; -char pipzap = 0; bool g_list_changed = false; // flag to indicate, allchans was changed int sig_delay = 2; // seconds between signal check @@ -116,30 +90,22 @@ int cam_ci = 2; // CA_INIT_SC 0 or CA_INIT_CI 1 or CA_INIT_BOTH 2 double gotoXXLatitude, gotoXXLongitude; int gotoXXLaDirection, gotoXXLoDirection, useGotoXX; -int scanSDT; +//int scanSDT; int repeatUsals; -int change_audio_pid(uint8_t index); // SDT -void * monitor_thread(void * arg); void * sdt_thread(void * arg); -void SaveServices(bool tocopy); -pthread_t tmon, tsdt; +pthread_t tsdt; pthread_mutex_t chan_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; -bool sdt_wakeup; +//bool sdt_wakeup; -/* the conditional access module */ -/* the configuration file */ -CConfigFile config(',', false); -/* the event server */ -CEventServer *eventServer = NULL; /* the current channel */ CZapitChannel *g_current_channel = NULL; -/* the transponder scan xml input */ -xmlDocPtr scanInputParser = NULL; /* the bouquet manager */ CBouquetManager *g_bouquetManager = NULL; +cCA *ca = NULL; +extern cDemux * pmtDemux; extern cVideo *videoDecoder; extern cAudio *audioDecoder; extern cDemux *audioDemux; @@ -150,53 +116,68 @@ cDemux *pcrDemux = NULL; /* the map which stores the wanted cable/satellites */ scan_list_t scanProviders; -/* current zapit mode */ -enum { - TV_MODE = 0x01, - RADIO_MODE = 0x02, - RECORD_MODE = 0x04 -}; - -int currentMode; -bool playbackStopForced = false; int zapit_debug = 0; int motorRotationSpeed = 0; //in 0.1 degrees per second -diseqc_t diseqcType; - -/* near video on demand */ -tallchans nvodchannels; // tallchans defined in "bouquets.h" -//std::string nvodname; -bool current_is_nvod = false; - -/* list of all channels (services) */ -tallchans allchans; // tallchans defined in "bouquets.h" -tallchans curchans; // tallchans defined in "bouquets.h" +//diseqc_t diseqcType; /* transponder scan */ transponder_list_t transponders; pthread_t scan_thread; + +#if 0 +//FIXME move reset to scan ? extern int found_transponders; extern int processed_transponders; extern int found_channels; extern short curr_sat; -extern short scan_runs; -extern short abort_scan; +#endif CZapitClient::bouquetMode bouquetMode = CZapitClient::BM_UPDATEBOUQUETS; CZapitClient::scanType scanType = CZapitClient::ST_TVRADIO; -void scan_clean(); -bool standby = true; -void * scan_transponder(void * arg); -void mergeServices(); static TP_params TP; -uint32_t lastChannelRadio; -uint32_t lastChannelTV; -void setZapitConfig(Zapit_config * Cfg); -void sendConfig(int connfd); +//uint32_t lastChannelRadio; +//uint32_t lastChannelTV; -void saveZapitSettings(bool write, bool write_a) +static bool update_pmt = true; +/******************************************************************************/ +CZapit * CZapit::zapit = NULL; +CZapit::CZapit() + : configfile(',', false) +{ + started = false; + pmt_update_fd = -1; + volume_left = 0, volume_right = 0; + def_volume_left = 0, def_volume_right = 0; + audio_mode = 0; + aspectratio=0; + mode43=0; + def_audio_mode = 0; + playbackStopForced = false; + standby = true; + event_mode = true; +} + +CZapit::~CZapit() +{ + Stop(); +} + +CZapit * CZapit::getInstance() +{ + if(zapit == NULL) + zapit = new CZapit(); + return zapit; +} + +void CZapit::SendEvent(const unsigned int eventID, const void* eventbody, const unsigned int eventbodysize) +{ + if(event_mode) + eventServer->sendEvent(eventID, CEventServer::INITID_ZAPIT, eventbody, eventbodysize); +} + +void CZapit::SaveSettings(bool write, bool write_a) { if (g_current_channel) { // now save the lowest channel number with the current channel_id @@ -211,141 +192,148 @@ void saveZapitSettings(bool write, bool write_a) } if (write) { - if (config.getBool("saveLastChannel", true)) { - config.setInt32("lastChannelMode", (currentMode & RADIO_MODE) ? 1 : 0); - config.setInt32("lastChannelRadio", lastChannelRadio); - config.setInt32("lastChannelTV", lastChannelTV); - config.setInt64("lastChannel", live_channel_id); + configfile.setBool("saveLastChannel", config.saveLastChannel); + if (config.saveLastChannel) { + configfile.setInt32("lastChannelMode", (currentMode & RADIO_MODE) ? 1 : 0); + configfile.setInt32("lastChannelRadio", lastChannelRadio); + configfile.setInt32("lastChannelTV", lastChannelTV); + configfile.setInt64("lastChannel", live_channel_id); } - config.setInt32("lastSatellitePosition", CFrontend::getInstance()->getCurrentSatellitePosition()); - config.setInt32("diseqcRepeats", CFrontend::getInstance()->getDiseqcRepeats()); - config.setInt32("diseqcType", CFrontend::getInstance()->getDiseqcType()); - config.setInt32("feTimeout", feTimeout); + configfile.setInt32("lastSatellitePosition", CFrontend::getInstance()->getCurrentSatellitePosition()); + configfile.setInt32("diseqcRepeats", CFrontend::getInstance()->getDiseqcRepeats()); + configfile.setInt32("diseqcType", CFrontend::getInstance()->getDiseqcType()); - config.setInt32("rezapTimeout", rezapTimeout); - config.setBool("fastZap", fastZap); - config.setBool("sortNames", sortNames); - config.setBool("scanPids", scan_pids); - config.setBool("highVoltage", highVoltage); + configfile.setInt32("motorRotationSpeed", config.motorRotationSpeed); + configfile.setBool("writeChannelsNames", config.writeChannelsNames); + configfile.setBool("makeRemainingChannelsBouquet", config.makeRemainingChannelsBouquet); + configfile.setInt32("feTimeout", config.feTimeout); + + configfile.setInt32("rezapTimeout", config.rezapTimeout); + configfile.setBool("scanPids", config.scanPids); + configfile.setBool("highVoltage", config.highVoltage); char tempd[12]; - sprintf(tempd, "%3.6f", gotoXXLatitude); - config.setString("gotoXXLatitude", tempd); - sprintf(tempd, "%3.6f", gotoXXLongitude); - config.setString("gotoXXLongitude", tempd); - config.setInt32("gotoXXLaDirection", gotoXXLaDirection); - config.setInt32("gotoXXLoDirection", gotoXXLoDirection); - //config.setInt32("useGotoXX", useGotoXX); - config.setInt32("repeatUsals", repeatUsals); + sprintf(tempd, "%3.6f", config.gotoXXLatitude); + configfile.setString("gotoXXLatitude", tempd); + sprintf(tempd, "%3.6f", config.gotoXXLongitude); + configfile.setString("gotoXXLongitude", tempd); + configfile.setInt32("gotoXXLaDirection", config.gotoXXLaDirection); + configfile.setInt32("gotoXXLoDirection", config.gotoXXLoDirection); + configfile.setInt32("repeatUsals", config.repeatUsals); + configfile.setInt32("scanSDT", config.scanSDT); - config.setInt32("uni_scr", uni_scr); - config.setInt32("uni_qrg", uni_qrg); + configfile.setInt32("uni_scr", uni_scr); + configfile.setInt32("uni_qrg", uni_qrg); - config.setInt32("cam_ci", cam_ci); + configfile.setInt32("cam_ci", cam_ci); - config.setInt32("scanSDT", scanSDT); - if (config.getModifiedFlag()) - config.saveConfig(CONFIGFILE); +#if 0 // unused + configfile.setBool("fastZap", config.fastZap); + configfile.setBool("sortNames", config.sortNames); + config.setInt32("useGotoXX", config.useGotoXX); +#endif + if (configfile.getModifiedFlag()) + configfile.saveConfig(CONFIGFILE); } if (write_a) { FILE *audio_config_file = fopen(AUDIO_CONFIG_FILE, "w"); if (audio_config_file) { - for (audio_map_it = audio_map.begin(); audio_map_it != audio_map.end(); audio_map_it++) { + for (audio_map_iterator_t audio_map_it = audio_map.begin(); audio_map_it != audio_map.end(); audio_map_it++) { fprintf(audio_config_file, "%llx %d %d %d %d %d %d\n", (uint64_t) audio_map_it->first, (int) audio_map_it->second.apid, (int) audio_map_it->second.mode, (int) audio_map_it->second.volume, (int) audio_map_it->second.subpid, (int) audio_map_it->second.ttxpid, (int) audio_map_it->second.ttxpage); } fdatasync(fileno(audio_config_file)); fclose(audio_config_file); - } + } else + perror(AUDIO_CONFIG_FILE); } } -void load_audio_map() +void CZapit::LoadAudioMap() { - FILE *audio_config_file = fopen(AUDIO_CONFIG_FILE, "r"); + FILE *audio_config_file = fopen(AUDIO_CONFIG_FILE, "r"); audio_map.clear(); - if (audio_config_file) { - t_channel_id chan; - int apid = 0, subpid = 0, ttxpid = 0, ttxpage = 0; - int mode = 0; - int volume = 0; - char s[1000]; - while (fgets(s, 1000, audio_config_file)) { - sscanf(s, "%llx %d %d %d %d %d %d", &chan, &apid, &mode, &volume, &subpid, &ttxpid, &ttxpage); -//printf("**** Old channelinfo: %llx %d\n", chan, apid); - audio_map[chan].apid = apid; - audio_map[chan].subpid = subpid; - audio_map[chan].mode = mode; - audio_map[chan].volume = volume; - audio_map[chan].ttxpid = ttxpid; - audio_map[chan].ttxpage = ttxpage; - } - fclose(audio_config_file); - } + if (audio_config_file) { + t_channel_id chan; + int apid = 0, subpid = 0, ttxpid = 0, ttxpage = 0; + int mode = 0; + int volume = 0; + char s[1000]; + while (fgets(s, 1000, audio_config_file)) { + sscanf(s, "%llx %d %d %d %d %d %d", &chan, &apid, &mode, &volume, &subpid, &ttxpid, &ttxpage); + audio_map[chan].apid = apid; + audio_map[chan].subpid = subpid; + audio_map[chan].mode = mode; + audio_map[chan].volume = volume; + audio_map[chan].ttxpid = ttxpid; + audio_map[chan].ttxpage = ttxpage; + } + fclose(audio_config_file); + } else + perror(AUDIO_CONFIG_FILE); } -void loadZapitSettings() +void CZapit::LoadSettings() { - if (!config.loadConfig(CONFIGFILE)) + if (!configfile.loadConfig(CONFIGFILE)) WARN("%s not found", CONFIGFILE); - live_channel_id = config.getInt64("lastChannel", 0); - lastChannelRadio = config.getInt32("lastChannelRadio", 0); - lastChannelTV = config.getInt32("lastChannelTV", 0); - rezapTimeout = config.getInt32("rezapTimeout", 1); - feTimeout = config.getInt32("feTimeout", 40); - fastZap = config.getBool("fastZap", 1); - sortNames = config.getBool("sortNames", 0); - sortlist = sortNames; - scan_pids = config.getBool("scanPids", 0); + live_channel_id = configfile.getInt64("lastChannel", 0); + lastChannelRadio = configfile.getInt32("lastChannelRadio", 0); + lastChannelTV = configfile.getInt32("lastChannelTV", 0); - highVoltage = config.getBool("highVoltage", 0); - voltageOff = config.getBool("voltageOff", 0); +#if 0 //unused + config.useGotoXX = configfile.getInt32("useGotoXX", 0); + config.fastZap = configfile.getBool("fastZap", 1); + config.sortNames = configfile.getBool("sortNames", 0); + voltageOff = configfile.getBool("voltageOff", 0); +#endif + config.saveLastChannel = configfile.getBool("saveLastChannel", true); + config.rezapTimeout = configfile.getInt32("rezapTimeout", 1); + config.feTimeout = configfile.getInt32("feTimeout", 40); + config.scanPids = configfile.getBool("scanPids", 0); - useGotoXX = config.getInt32("useGotoXX", 0); - gotoXXLatitude = strtod(config.getString("gotoXXLatitude", "0.0").c_str(), NULL); - gotoXXLongitude = strtod(config.getString("gotoXXLongitude", "0.0").c_str(), NULL); - gotoXXLaDirection = config.getInt32("gotoXXLaDirection", 1); - gotoXXLoDirection = config.getInt32("gotoXXLoDirection", 0); - repeatUsals = config.getInt32("repeatUsals", 0); + config.highVoltage = configfile.getBool("highVoltage", 0); - scanSDT = config.getInt32("scanSDT", 0); + config.gotoXXLatitude = strtod(configfile.getString("gotoXXLatitude", "0.0").c_str(), NULL); + config.gotoXXLongitude = strtod(configfile.getString("gotoXXLongitude", "0.0").c_str(), NULL); + config.gotoXXLaDirection = configfile.getInt32("gotoXXLaDirection", 1); + config.gotoXXLoDirection = configfile.getInt32("gotoXXLoDirection", 0); + config.repeatUsals = configfile.getInt32("repeatUsals", 0); - uni_scr = config.getInt32("uni_scr", -1); - uni_qrg = config.getInt32("uni_qrg", 0); + config.scanSDT = configfile.getInt32("scanSDT", 0); - cam_ci = config.getInt32("cam_ci", 2); + uni_scr = configfile.getInt32("uni_scr", -1); + uni_qrg = configfile.getInt32("uni_qrg", 0); - diseqcType = (diseqc_t)config.getInt32("diseqcType", NO_DISEQC); - motorRotationSpeed = config.getInt32("motorRotationSpeed", 18); // default: 1.8 degrees per second + cam_ci = configfile.getInt32("cam_ci", 2); - CFrontend::getInstance()->setDiseqcRepeats(config.getInt32("diseqcRepeats", 0)); - CFrontend::getInstance()->setCurrentSatellitePosition(config.getInt32("lastSatellitePosition", 0)); + diseqcType = (diseqc_t)configfile.getInt32("diseqcType", NO_DISEQC); + config.motorRotationSpeed = configfile.getInt32("motorRotationSpeed", 18); // default: 1.8 degrees per second + + CFrontend::getInstance()->setDiseqcRepeats(configfile.getInt32("diseqcRepeats", 0)); + CFrontend::getInstance()->setCurrentSatellitePosition(configfile.getInt32("lastSatellitePosition", 0)); CFrontend::getInstance()->setDiseqcType(diseqcType); + //FIXME globals ! + scan_pids = config.scanPids; + //scanSDT = config.scanSDT; + motorRotationSpeed = config.motorRotationSpeed; + highVoltage = config.highVoltage; + feTimeout = config.feTimeout; + gotoXXLaDirection = config.gotoXXLaDirection; + gotoXXLoDirection = config.gotoXXLoDirection; + gotoXXLatitude = config.gotoXXLatitude; + gotoXXLongitude = config.gotoXXLongitude; + repeatUsals = config.repeatUsals; + printf("[zapit.cpp] diseqc type = %d\n", diseqcType); - load_audio_map(); + LoadAudioMap(); } -CZapitClient::responseGetLastChannel load_settings(void) -{ - CZapitClient::responseGetLastChannel lastchannel; - - //if (config.getInt32("lastChannelMode", 0)) - if (currentMode & RADIO_MODE) - lastchannel.mode = 'r'; - else - lastchannel.mode = 't'; - - lastchannel.channelNumber = (currentMode & RADIO_MODE) ? lastChannelRadio : lastChannelTV; - //lastchannel.channelNumber = config.getInt32((currentMode & RADIO_MODE) ? "lastChannelRadio" : "lastChannelTV", 0); -//printf("GET LAST CHAN:: %d !!!!!!!\n\n\n", lastchannel.channelNumber); - return lastchannel; -} - -void start_camd(bool forupdate = false) +void CZapit::SendPMT(bool forupdate) { if(!g_current_channel) return; @@ -356,10 +344,7 @@ void start_camd(bool forupdate = false) ca->SendPMT(DEMUX_SOURCE_0, pmt, len); } -static int pmt_update_fd = -1; -static bool update_pmt = true; - -static void save_channel_pids(CZapitChannel* channel) +void CZapit::SaveChannelPids(CZapitChannel* channel) { if(channel == NULL) return; @@ -372,67 +357,76 @@ static void save_channel_pids(CZapitChannel* channel) tuxtx_subtitle_running(&audio_map[channel->getChannelID()].ttxpid, &audio_map[channel->getChannelID()].ttxpage, NULL); } -static CZapitChannel* find_channel_tozap(const t_channel_id channel_id, bool in_nvod) +void CZapit::RestoreChannelPids(CZapitChannel * channel) { - tallchans_iterator cit; - if (in_nvod) { - current_is_nvod = true; + audio_map_set_t * pidmap = GetSavedPids(channel->getChannelID()); + if(pidmap) { + printf("[zapit] channel found, audio pid %x, subtitle pid %x mode %d volume %d\n", + pidmap->apid, pidmap->subpid, pidmap->mode, pidmap->volume); - cit = nvodchannels.find(channel_id); - - if (cit == nvodchannels.end()) { - DBG("channel_id " PRINTF_CHANNEL_ID_TYPE " not found", channel_id); - return false; - } - } else { - current_is_nvod = false; - - cit = allchans.find(channel_id); - -#if 0 // allow zap for recording without changing mode - if (currentMode & RADIO_MODE) { - if ((cit == allchans.end()) || (cit->second.getServiceType() != ST_DIGITAL_RADIO_SOUND_SERVICE)) { - DBG("channel_id " PRINTF_CHANNEL_ID_TYPE " not found", channel_id); - return NULL; - } - } else { - if (cit == allchans.end() || (cit->second.getServiceType() == ST_DIGITAL_RADIO_SOUND_SERVICE)) { - DBG("channel_id " PRINTF_CHANNEL_ID_TYPE " not found", channel_id); - // in case neutrino zap without nvod=true - cit = nvodchannels.find(channel_id); - if (cit == nvodchannels.end()) { - DBG("channel_id " PRINTF_CHANNEL_ID_TYPE " AS NVOD not found", channel_id); - return NULL; + if(channel->getAudioChannelCount() > 1) { + for (int i = 0; i < channel->getAudioChannelCount(); i++) { + if (channel->getAudioChannel(i)->pid == pidmap->apid ) { + DBG("***** Setting audio!\n"); + channel->setAudioChannel(i); +#if 0 + if(we_playing && (channel->getAudioChannel(i)->audioChannelType != CZapitAudioChannel::MPEG)) + ChangeAudioPid(i); +#endif } - current_is_nvod = true; } } -#else - if (cit == allchans.end()) { - cit = nvodchannels.find(channel_id); - if (cit == nvodchannels.end()) { - DBG("channel_id " PRINTF_CHANNEL_ID_TYPE " AS NVOD not found", channel_id); - return NULL; - } - current_is_nvod = true; +#if 0 // to restore saved volume per channel if needed. after first zap its done by neutrino + if(firstzap) { + audioDecoder->setVolume(audio_map_it->second.volume, audio_map_it->second.volume); } #endif + volume_left = volume_right = pidmap->volume; + audio_mode = pidmap->mode; + + dvbsub_setpid(pidmap->subpid); + + std::string tmplang; + for (int i = 0 ; i < (int)channel->getSubtitleCount() ; ++i) { + CZapitAbsSub* s = channel->getChannelSub(i); + if(s->pId == pidmap->ttxpid) { + tmplang = s->ISO639_language_code; + break; + } + } + if(tmplang.empty()) + tuxtx_set_pid(pidmap->ttxpid, pidmap->ttxpage, (char *) channel->getTeletextLang()); + else + tuxtx_set_pid(pidmap->ttxpid, pidmap->ttxpage, (char *) tmplang.c_str()); + } else { + volume_left = volume_right = def_volume_left; + audio_mode = def_audio_mode; + tuxtx_set_pid(0, 0, (char *) channel->getTeletextLang()); } - return &cit->second; + /* restore saved stereo / left / right channel mode */ + //audioDecoder->setVolume(volume_left, volume_right); + audioDecoder->setChannel(audio_mode); } -static bool tune_to_channel(CZapitChannel * channel, bool &transponder_change) +audio_map_set_t * CZapit::GetSavedPids(const t_channel_id channel_id) { - int waitForMotor = 0; + audio_map_iterator_t audio_map_it = audio_map.find(channel_id); + if(audio_map_it != audio_map.end()) + return &audio_map_it->second; + return NULL; +} + +bool CZapit::TuneChannel(CZapitChannel * channel, bool &transponder_change) +{ transponder_change = false; if (!(currentMode & RECORD_MODE)) { transponder_change = CFrontend::getInstance()->setInput(channel, current_is_nvod); if(transponder_change && !current_is_nvod) { - waitForMotor = CFrontend::getInstance()->driveToSatellitePosition(channel->getSatellitePosition()); + int waitForMotor = CFrontend::getInstance()->driveToSatellitePosition(channel->getSatellitePosition()); if(waitForMotor > 0) { printf("[zapit] waiting %d seconds for motor to turn satellite dish.\n", waitForMotor); - eventServer->sendEvent(CZapitClient::EVT_ZAP_MOTOR, CEventServer::INITID_ZAPIT, &waitForMotor, sizeof(waitForMotor)); + SendEvent(CZapitClient::EVT_ZAP_MOTOR, &waitForMotor, sizeof(waitForMotor)); for(int i = 0; i < waitForMotor; i++) { sleep(1); if(abort_zapit) { @@ -455,7 +449,7 @@ static bool tune_to_channel(CZapitChannel * channel, bool &transponder_change) return true; } -static bool parse_channel_pat_pmt(CZapitChannel * channel) +bool CZapit::ParsePatPmt(CZapitChannel * channel) { DBG("looking up pids for channel_id " PRINTF_CHANNEL_ID_TYPE "\n", channel->getChannelID()); /* get program map table pid from program association table */ @@ -482,73 +476,23 @@ static bool parse_channel_pat_pmt(CZapitChannel * channel) return true; } -static void restore_channel_pids(CZapitChannel * channel) -{ - audio_map_it = audio_map.find(live_channel_id); - if((audio_map_it != audio_map.end()) ) { - printf("[zapit] channel found, audio pid %x, subtitle pid %x mode %d volume %d\n", - audio_map_it->second.apid, audio_map_it->second.subpid, audio_map_it->second.mode, audio_map_it->second.volume); - if(channel->getAudioChannelCount() > 1) { - for (int i = 0; i < channel->getAudioChannelCount(); i++) { - if (channel->getAudioChannel(i)->pid == audio_map_it->second.apid ) { - DBG("***** Setting audio!\n"); - channel->setAudioChannel(i); -#if 0 - if(we_playing && (channel->getAudioChannel(i)->audioChannelType != CZapitAudioChannel::MPEG)) - change_audio_pid(i); -#endif - } - } - } -#if 0 // to restore saved volume per channel if needed. after first zap its done by neutrino - if(firstzap) { - audioDecoder->setVolume(audio_map_it->second.volume, audio_map_it->second.volume); - } -#endif - volume_left = volume_right = audio_map_it->second.volume; - audio_mode = audio_map_it->second.mode; - - dvbsub_setpid(audio_map_it->second.subpid); - - std::string tmplang; - for (int i = 0 ; i < (int)channel->getSubtitleCount() ; ++i) { - CZapitAbsSub* s = channel->getChannelSub(i); - if(s->pId == audio_map_it->second.ttxpid) { - tmplang = s->ISO639_language_code; - break; - } - } - if(tmplang.empty()) - tuxtx_set_pid(audio_map_it->second.ttxpid, audio_map_it->second.ttxpage, (char *) channel->getTeletextLang()); - else - tuxtx_set_pid(audio_map_it->second.ttxpid, audio_map_it->second.ttxpage, (char *) tmplang.c_str()); - } else { - volume_left = volume_right = def_volume_left; - audio_mode = def_audio_mode; - tuxtx_set_pid(0, 0, (char *) channel->getTeletextLang()); - } - /* restore saved stereo / left / right channel mode */ - //audioDecoder->setVolume(volume_left, volume_right); - audioDecoder->setChannel(audio_mode); -} - -int zapit(const t_channel_id channel_id, bool in_nvod, bool forupdate = 0, bool startplayback = true) +bool CZapit::ZapIt(const t_channel_id channel_id, bool forupdate, bool startplayback) { bool transponder_change = false; - tallchans_iterator cit; bool failed = false; CZapitChannel* newchannel; - DBG("[zapit] zapto channel id %llx diseqcType %d nvod %d\n", channel_id, diseqcType, in_nvod); + DBG("[zapit] zapto channel id %llx diseqcType %d\n", channel_id, diseqcType); - if((newchannel = find_channel_tozap(channel_id, in_nvod)) == NULL) { + abort_zapit = 0; + if((newchannel = CServiceManager::getInstance()->FindChannel(channel_id, ¤t_is_nvod)) == NULL) { DBG("channel_id " PRINTF_CHANNEL_ID_TYPE " not found", channel_id); - return -1; + return false; } sig_delay = 2; if (!firstzap && g_current_channel) - save_channel_pids(g_current_channel); + SaveChannelPids(g_current_channel); /* firstzap right now does nothing but control saving the audio channel */ firstzap = false; @@ -556,7 +500,7 @@ int zapit(const t_channel_id channel_id, bool in_nvod, bool forupdate = 0, bool pmt_stop_update_filter(&pmt_update_fd); ca->SendPMT(0, (unsigned char*) "", 0, CA_SLOT_TYPE_CI); - stopPlayBack(!forupdate); + StopPlayBack(!forupdate); if(!forupdate && g_current_channel) g_current_channel->resetPids(); @@ -564,16 +508,16 @@ int zapit(const t_channel_id channel_id, bool in_nvod, bool forupdate = 0, bool g_current_channel = newchannel; live_channel_id = g_current_channel->getChannelID(); - saveZapitSettings(false, false); + SaveSettings(false, false); printf("[zapit] zap to %s (%llx)\n", g_current_channel->getName().c_str(), live_channel_id); - if(!tune_to_channel(newchannel, transponder_change)) - return -1; + if(!TuneChannel(newchannel, transponder_change)) + return false; if (g_current_channel->getServiceType() == ST_NVOD_REFERENCE_SERVICE) { current_is_nvod = true; - return 0; + return true; } #if 0 //FIXME improve or remove ? this is to start playback before pmt //bool we_playing = scan_pids && channel->getPidsFlag();//FIXME: this starts playback before pmt @@ -586,11 +530,11 @@ int zapit(const t_channel_id channel_id, bool in_nvod, bool forupdate = 0, bool std::string desc = "Preset"; g_current_channel->addAudioChannel(g_current_channel->getPreAudioPid(), CZapitAudioChannel::MPEG, desc, 0xFF); } - startPlayBack(g_current_channel); + StartPlayBack(g_current_channel); } #endif - failed = !parse_channel_pat_pmt(g_current_channel); + failed = !ParsePatPmt(g_current_channel); if ((!failed) && (g_current_channel->getAudioPid() == 0) && (g_current_channel->getVideoPid() == 0)) { printf("[zapit] neither audio nor video pid found\n"); @@ -600,62 +544,94 @@ int zapit(const t_channel_id channel_id, bool in_nvod, bool forupdate = 0, bool /* start sdt scan even if the service was not found in pat or pmt * if the frontend did not tune, we don't get here, so this is fine */ if (transponder_change) - sdt_wakeup = true; + SdtMonitor.Wakeup(); if (failed) - return -1; + return false; g_current_channel->getCaPmt()->ca_pmt_list_management = transponder_change ? 0x03 : 0x04; - restore_channel_pids(g_current_channel); + RestoreChannelPids(g_current_channel); if (startplayback /* && !we_playing*/) - startPlayBack(g_current_channel); + StartPlayBack(g_current_channel); printf("[zapit] sending capmt....\n"); - start_camd(forupdate); + SendPMT(forupdate); //play: int caid = 1; - if(event_mode) eventServer->sendEvent(CZapitClient::EVT_ZAP_CA_ID, CEventServer::INITID_ZAPIT, &caid, sizeof(int)); + SendEvent(CZapitClient::EVT_ZAP_CA_ID, &caid, sizeof(int)); if (update_pmt) pmt_set_update_filter(g_current_channel, &pmt_update_fd); - return 0; + return true; } -int zapit_to_record(const t_channel_id channel_id) +bool CZapit::ZapForRecord(const t_channel_id channel_id) { CZapitChannel* newchannel; bool transponder_change; - if((newchannel = find_channel_tozap(channel_id, false)) == NULL) { + if((newchannel = CServiceManager::getInstance()->FindChannel(channel_id)) == NULL) { printf("zapit_to_record: channel_id " PRINTF_CHANNEL_ID_TYPE " not found", channel_id); - return -1; + return false; } printf("%s: %s (%llx)\n", __FUNCTION__, newchannel->getName().c_str(), channel_id); - if(!tune_to_channel(newchannel, transponder_change)) - return -1; + if(!TuneChannel(newchannel, transponder_change)) + return false; - if(!parse_channel_pat_pmt(newchannel)) - return -1; + if(!ParsePatPmt(newchannel)) + return false; - return 0; + return true; } -int change_audio_pid(uint8_t index) +void CZapit::SetAudioStreamType(CZapitAudioChannel::ZapitAudioChannelType audioChannelType) +{ + const char *audioStr = "UNKNOWN"; + switch (audioChannelType) { + case CZapitAudioChannel::AC3: + audioStr = "AC3"; + audioDecoder->SetStreamType(AUDIO_FMT_DOLBY_DIGITAL); + break; + case CZapitAudioChannel::MPEG: + audioStr = "MPEG2"; + audioDecoder->SetStreamType(AUDIO_FMT_MPEG); + break; + case CZapitAudioChannel::AAC: + audioStr = "AAC"; + audioDecoder->SetStreamType(AUDIO_FMT_AAC); + break; + case CZapitAudioChannel::AACPLUS: + audioStr = "AAC-PLUS"; + audioDecoder->SetStreamType(AUDIO_FMT_AAC_PLUS); + break; + case CZapitAudioChannel::DTS: + audioStr = "DTS"; + audioDecoder->SetStreamType(AUDIO_FMT_DTS); + break; + default: + printf("[zapit] unknown audio channel type 0x%x\n", audioChannelType); + break; + } + + printf("[zapit] starting %s audio\n", audioStr); +} + +bool CZapit::ChangeAudioPid(uint8_t index) { if (!g_current_channel) - return -1; + return false; /* stop demux filter */ if (audioDemux->Stop() < 0) - return -1; + return false; /* stop audio playback */ if (audioDecoder->Stop() < 0) - return -1; + return false; /* update current channel */ g_current_channel->setAudioChannel(index); @@ -665,60 +641,40 @@ int change_audio_pid(uint8_t index) if (!currentAudioChannel) { WARN("No current audio channel"); - return -1; - } - - switch (currentAudioChannel->audioChannelType) { - case CZapitAudioChannel::AC3: - audioDecoder->SetStreamType(AUDIO_FMT_DOLBY_DIGITAL); - break; - case CZapitAudioChannel::MPEG: - audioDecoder->SetStreamType(AUDIO_FMT_MPEG); - break; - case CZapitAudioChannel::AAC: - audioDecoder->SetStreamType(AUDIO_FMT_AAC); - break; - case CZapitAudioChannel::AACPLUS: - audioDecoder->SetStreamType(AUDIO_FMT_AAC_PLUS); - break; - case CZapitAudioChannel::DTS: - audioDecoder->SetStreamType(AUDIO_FMT_DTS); - break; - default: - printf("[zapit] unknown audio channel type 0x%x\n", currentAudioChannel->audioChannelType); - break; + return false; } printf("[zapit] change apid to 0x%x\n", g_current_channel->getAudioPid()); + SetAudioStreamType(currentAudioChannel->audioChannelType); + /* set demux filter */ if (audioDemux->pesFilter(g_current_channel->getAudioPid()) < 0) - return -1; + return false; /* start demux filter */ if (audioDemux->Start() < 0) - return -1; + return false; /* start audio playback */ if (audioDecoder->Start() < 0) - return -1; + return false; - return 0; + return true; } -void setRadioMode(void) +void CZapit::SetRadioMode(void) { currentMode |= RADIO_MODE; currentMode &= ~TV_MODE; - //stopPlayBack(true);//FIXME why this needed ? to test! } -void setTVMode(void) +void CZapit::SetTVMode(void) { currentMode |= TV_MODE; currentMode &= ~RADIO_MODE; } -int getMode(void) +int CZapit::getMode(void) { int mode = currentMode & (~RECORD_MODE); return mode; @@ -730,110 +686,68 @@ int getMode(void) return 0; } -void setRecordMode(void) +void CZapit::SetRecordMode(bool enable) { - if(currentMode & RECORD_MODE) return; - currentMode |= RECORD_MODE; - if(event_mode) eventServer->sendEvent(CZapitClient::EVT_RECORDMODE_ACTIVATED, CEventServer::INITID_ZAPIT ); - rec_channel_id = live_channel_id; -} + unsigned int event; + bool mode = currentMode & RECORD_MODE; -void unsetRecordMode(void) -{ - if(!(currentMode & RECORD_MODE)) + if(mode == enable) return; - currentMode &= ~RECORD_MODE; + if(enable) { + currentMode |= RECORD_MODE; + rec_channel_id = live_channel_id; + event = CZapitClient::EVT_RECORDMODE_ACTIVATED; + } else { + currentMode &= ~RECORD_MODE; + rec_channel_id = 0; - if(event_mode) eventServer->sendEvent(CZapitClient::EVT_RECORDMODE_DEACTIVATED, CEventServer::INITID_ZAPIT ); - - ca->SendPMT(DEMUX_SOURCE_2, (unsigned char*) "", 0, CA_SLOT_TYPE_SMARTCARD); - rec_channel_id = 0; + ca->SendPMT(DEMUX_SOURCE_2, (unsigned char*) "", 0, CA_SLOT_TYPE_SMARTCARD); + event = CZapitClient::EVT_RECORDMODE_DEACTIVATED; + } + SendEvent(event); } -int prepare_channels(fe_type_t frontendType, diseqc_t pdiseqcType) +bool CZapit::PrepareChannels() { g_current_channel = 0; - transponders.clear(); - g_bouquetManager->clearAll(); - allchans.clear(); // <- this invalidates all bouquets, too! - if(scanInputParser) { - delete scanInputParser; - scanInputParser = NULL; - } - if (LoadServices(frontendType, pdiseqcType, false) < 0) - return -1; + if (!CServiceManager::getInstance()->LoadServices(false)) + return false; INFO("LoadServices: success"); g_bouquetManager->loadBouquets(); - return 0; + return true; } -void parseScanInputXml(void) +void CZapit::PrepareScan() { - switch (CFrontend::getInstance()->getInfo()->type) { - case FE_QPSK: - scanInputParser = parseXmlFile(SATELLITES_XML); - break; - - case FE_QAM: - scanInputParser = parseXmlFile(CABLES_XML); - break; - - default: - WARN("Unknown type %d", CFrontend::getInstance()->getInfo()->type); - return; - } -} - -int start_scan(int scan_mode) -{ - if (!scanInputParser) { - parseScanInputXml(); - if (!scanInputParser) { - WARN("scan not configured"); - return -1; - } - } - - scan_runs = 1; - stopPlayBack(true); + StopPlayBack(true); pmt_stop_update_filter(&pmt_update_fd); - - found_transponders = 0; - found_channels = 0; - - if (pthread_create(&scan_thread, 0, start_scanthread, (void*)scan_mode)) { - ERROR("pthread_create"); - scan_runs = 0; - return -1; - } - return 0; } -int start_fast_scan(int scan_mode, int opid) +bool CZapit::StartScan(int scan_mode) +{ + PrepareScan(); + + CServiceScan::getInstance()->Start(CServiceScan::SCAN_PROVIDER, (void *) scan_mode); + return true; +} + +bool CZapit::StartFastScan(int scan_mode, int opid) { fast_scan_type_t scant; scant.type = scan_mode; scant.op = (fs_operator_t) opid; - scan_runs = 1; - stopPlayBack(true); - pmt_stop_update_filter(&pmt_update_fd); + PrepareScan(); - found_transponders = 0; - found_channels = 0; - if (pthread_create(&scan_thread, 0, start_fast_scan, (void*)&scant)) { - ERROR("pthread_create"); - scan_runs = 0; - return -1; - } - return 0; + CServiceScan::getInstance()->Start(CServiceScan::SCAN_FAST, (void *) &scant); + return true; } -bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) +bool CZapit::ParseCommand(CBasicMessage::Header &rmsg, int connfd) { CZapitMessages::responseCmd response; DBG("cmd %d (version %d) received\n", rmsg.cmd, rmsg.version); @@ -854,14 +768,14 @@ bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) { CZapitMessages::commandZapto msgZapto; CBasicServer::receive_data(connfd, &msgZapto, sizeof(msgZapto)); // bouquet & channel number are already starting at 0! - zapTo(msgZapto.bouquet, msgZapto.channel); + ZapTo(msgZapto.bouquet, msgZapto.channel); break; } case CZapitMessages::CMD_ZAPTO_CHANNELNR: { CZapitMessages::commandZaptoChannelNr msgZaptoChannelNr; CBasicServer::receive_data(connfd, &msgZaptoChannelNr, sizeof(msgZaptoChannelNr)); // bouquet & channel number are already starting at 0! - zapTo(msgZaptoChannelNr.channel); + ZapTo(msgZaptoChannelNr.channel); break; } @@ -871,9 +785,9 @@ bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) CZapitMessages::responseZapComplete msgResponseZapComplete; CBasicServer::receive_data(connfd, &msgZaptoServiceID, sizeof(msgZaptoServiceID)); if(msgZaptoServiceID.record) { - msgResponseZapComplete.zapStatus = zapit_to_record(msgZaptoServiceID.channel_id); + msgResponseZapComplete.zapStatus = ZapForRecord(msgZaptoServiceID.channel_id); } else { - msgResponseZapComplete.zapStatus = zapTo_ChannelID(msgZaptoServiceID.channel_id, (rmsg.cmd == CZapitMessages::CMD_ZAPTO_SUBSERVICEID)); + msgResponseZapComplete.zapStatus = ZapTo(msgZaptoServiceID.channel_id, (rmsg.cmd == CZapitMessages::CMD_ZAPTO_SUBSERVICEID)); } CBasicServer::send_data(connfd, &msgResponseZapComplete, sizeof(msgResponseZapComplete)); break; @@ -883,14 +797,15 @@ bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) case CZapitMessages::CMD_ZAPTO_SUBSERVICEID_NOWAIT: { CZapitMessages::commandZaptoServiceID msgZaptoServiceID; CBasicServer::receive_data(connfd, &msgZaptoServiceID, sizeof(msgZaptoServiceID)); - zapTo_ChannelID(msgZaptoServiceID.channel_id, (rmsg.cmd == CZapitMessages::CMD_ZAPTO_SUBSERVICEID_NOWAIT)); + ZapTo(msgZaptoServiceID.channel_id, (rmsg.cmd == CZapitMessages::CMD_ZAPTO_SUBSERVICEID_NOWAIT)); break; } case CZapitMessages::CMD_GET_LAST_CHANNEL: { - CZapitClient::responseGetLastChannel responseGetLastChannel; - responseGetLastChannel = load_settings(); - CBasicServer::send_data(connfd, &responseGetLastChannel, sizeof(responseGetLastChannel)); // bouquet & channel number are already starting at 0! + CZapitClient::responseGetLastChannel lastchannel; + lastchannel.channelNumber = (currentMode & RADIO_MODE) ? lastChannelRadio : lastChannelTV; + lastchannel.mode = (currentMode & RADIO_MODE) ? 'r' : 't'; + CBasicServer::send_data(connfd, &lastchannel, sizeof(lastchannel)); // bouquet & channel number are already starting at 0! break; } @@ -903,7 +818,7 @@ bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) case CZapitMessages::CMD_SET_AUDIOCHAN: { CZapitMessages::commandSetAudioChannel msgSetAudioChannel; CBasicServer::receive_data(connfd, &msgSetAudioChannel, sizeof(msgSetAudioChannel)); - change_audio_pid(msgSetAudioChannel.channel); + ChangeAudioPid(msgSetAudioChannel.channel); break; } @@ -911,9 +826,9 @@ bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) CZapitMessages::commandSetMode msgSetMode; CBasicServer::receive_data(connfd, &msgSetMode, sizeof(msgSetMode)); if (msgSetMode.mode == CZapitClient::MODE_TV) - setTVMode(); + SetTVMode(); else if (msgSetMode.mode == CZapitClient::MODE_RADIO) - setRadioMode(); + SetRadioMode(); break; } @@ -1012,19 +927,18 @@ bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) t_channel_id requested_channel_id; CZapitMessages::responseGetChannelName _response; CBasicServer::receive_data(connfd, &requested_channel_id, sizeof(requested_channel_id)); + _response.name[0] = 0; if(requested_channel_id == 0) { if(g_current_channel) { strncpy(_response.name, g_current_channel->getName().c_str(), CHANNEL_NAME_SIZE); _response.name[CHANNEL_NAME_SIZE-1] = 0; - } else - _response.name[0] = 0; + } } else { - tallchans_iterator it = allchans.find(requested_channel_id); - if (it == allchans.end()) - _response.name[0] = 0; - else - strncpy(_response.name, it->second.getName().c_str(), CHANNEL_NAME_SIZE); - _response.name[CHANNEL_NAME_SIZE-1] = 0; + CZapitChannel * channel = CServiceManager::getInstance()->FindChannel(requested_channel_id); + if(channel) { + strncpy(_response.name, channel->getName().c_str(), CHANNEL_NAME_SIZE); + _response.name[CHANNEL_NAME_SIZE-1] = 0; + } } CBasicServer::send_data(connfd, &_response, sizeof(_response)); break; @@ -1034,27 +948,22 @@ bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) t_channel_id requested_channel_id; CZapitMessages::responseGeneralTrueFalse _response; CBasicServer::receive_data(connfd, &requested_channel_id, sizeof(requested_channel_id)); - tallchans_iterator it = allchans.find(requested_channel_id); - if (it == allchans.end()) { - it = nvodchannels.find(requested_channel_id); - /* if in doubt (i.e. unknown channel) answer yes */ - if (it == nvodchannels.end()) - _response.status = true; - else - /* FIXME: the following check is no even remotely accurate */ - _response.status = (it->second.getServiceType() != ST_DIGITAL_RADIO_SOUND_SERVICE); - } else - /* FIXME: the following check is no even remotely accurate */ - _response.status = (it->second.getServiceType() != ST_DIGITAL_RADIO_SOUND_SERVICE); - CBasicServer::send_data(connfd, &_response, sizeof(_response)); - break; - } + /* if in doubt (i.e. unknown channel) answer yes */ + _response.status = true; + CZapitChannel * channel = CServiceManager::getInstance()->FindChannel(requested_channel_id); + if(channel) + /* FIXME: the following check is no even remotely accurate */ + _response.status = (channel->getServiceType() != ST_DIGITAL_RADIO_SOUND_SERVICE); + + CBasicServer::send_data(connfd, &_response, sizeof(_response)); + break; + } case CZapitMessages::CMD_BQ_RESTORE: { //2004.08.02 g_bouquetManager->restoreBouquets(); if(g_list_changed) { - prepare_channels(CFrontend::getInstance()->getInfo()->type, diseqcType); + PrepareChannels(); g_list_changed = 0; } else { g_bouquetManager->clearAll(); @@ -1069,62 +978,54 @@ bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) // Houdini: save actual channel to restore it later, old version's channel was set to scans.conf initial channel t_channel_id cid= g_current_channel ? g_current_channel->getChannelID() : 0; - prepare_channels(CFrontend::getInstance()->getInfo()->type, diseqcType); + PrepareChannels(); - tallchans_iterator cit = allchans.find(cid); - if (cit != allchans.end()) - g_current_channel = &(cit->second); + g_current_channel = CServiceManager::getInstance()->FindChannel(cid); response.cmd = CZapitMessages::CMD_READY; CBasicServer::send_data(connfd, &response, sizeof(response)); - eventServer->sendEvent(CZapitClient::EVT_SERVICES_CHANGED, CEventServer::INITID_ZAPIT); + SendEvent(CZapitClient::EVT_SERVICES_CHANGED); break; } case CZapitMessages::CMD_RELOAD_CURRENTSERVICES: { response.cmd = CZapitMessages::CMD_READY; CBasicServer::send_data(connfd, &response, sizeof(response)); -DBG("[zapit] sending EVT_SERVICES_CHANGED\n"); + DBG("[zapit] sending EVT_SERVICES_CHANGED\n"); CFrontend::getInstance()->setTsidOnid(0); - zapit(live_channel_id, current_is_nvod); - eventServer->sendEvent(CZapitClient::EVT_SERVICES_CHANGED, CEventServer::INITID_ZAPIT); - //eventServer->sendEvent(CZapitClient::EVT_BOUQUETS_CHANGED, CEventServer::INITID_ZAPIT); + ZapIt(live_channel_id, current_is_nvod); + SendEvent(CZapitClient::EVT_SERVICES_CHANGED); + //SendEvent(CZapitClient::EVT_BOUQUETS_CHANGED); break; } case CZapitMessages::CMD_SCANSTART: { int scan_mode; CBasicServer::receive_data(connfd, &scan_mode, sizeof(scan_mode)); - if (start_scan(scan_mode) == -1) - eventServer->sendEvent(CZapitClient::EVT_SCAN_FAILED, CEventServer::INITID_ZAPIT); + if (!StartScan(scan_mode)) + SendEvent(CZapitClient::EVT_SCAN_FAILED); break; } - case CZapitMessages::CMD_SCANSTOP: { - if(scan_runs) { - //pthread_cancel(scan_thread); - abort_scan = 1; - pthread_join(scan_thread, NULL); - abort_scan = 0; - scan_runs = 0; - } + case CZapitMessages::CMD_SCANSTOP: + CServiceScan::getInstance()->Abort(); + CServiceScan::getInstance()->Stop(); break; - } case CZapitMessages::CMD_SETCONFIG: Zapit_config Cfg; CBasicServer::receive_data(connfd, &Cfg, sizeof(Cfg)); - setZapitConfig(&Cfg); + SetConfig(&Cfg); break; case CZapitMessages::CMD_GETCONFIG: - sendConfig(connfd); + SendConfig(connfd); break; case CZapitMessages::CMD_REZAP: if (currentMode & RECORD_MODE) break; - if(rezapTimeout > 0) - sleep(rezapTimeout); + if(config.rezapTimeout > 0) + sleep(config.rezapTimeout); if(g_current_channel) - zapit(g_current_channel->getChannelID(), current_is_nvod); + ZapIt(g_current_channel->getChannelID()); break; case CZapitMessages::CMD_TUNE_TP: { CBasicServer::receive_data(connfd, &TP, sizeof(TP)); @@ -1189,28 +1090,20 @@ printf("[zapit] TP_id %d freq %d rate %d fec %d pol %d\n", TP.TP_id, TP.feparams //if(satellitePositions.find(g_current_channel->getSatellitePosition()) != satellitePositions.end()) g_current_channel = 0; } - stopPlayBack(true); - pmt_stop_update_filter(&pmt_update_fd); - scan_runs = 1; - if (pthread_create(&scan_thread, 0, scan_transponder, (void*) &TP)) { - ERROR("pthread_create"); - scan_runs = 0; - } - //else - // pthread_detach(scan_thread); + PrepareScan(); + CServiceScan::getInstance()->Start(CServiceScan::SCAN_TRANSPONDER, (void *) &TP); break; } case CZapitMessages::CMD_SCANREADY: { CZapitMessages::responseIsScanReady msgResponseIsScanReady; +#if 0 //FIXME used only when scanning done using pzapit client, is it really needed ? msgResponseIsScanReady.satellite = curr_sat; msgResponseIsScanReady.transponder = found_transponders; msgResponseIsScanReady.processed_transponder = processed_transponders; msgResponseIsScanReady.services = found_channels; - if (scan_runs > 0) - msgResponseIsScanReady.scanReady = false; - else - msgResponseIsScanReady.scanReady = true; + msgResponseIsScanReady.scanReady = !CServiceScan::getInstance()->Scanning(); +#endif CBasicServer::send_data(connfd, &msgResponseIsScanReady, sizeof(msgResponseIsScanReady)); break; } @@ -1237,27 +1130,15 @@ printf("[zapit] TP_id %d freq %d rate %d fec %d pol %d\n", TP.TP_id, TP.feparams case CZapitMessages::CMD_SCANSETSCANSATLIST: { CZapitClient::commandSetScanSatelliteList sat; scanProviders.clear(); -//printf("[zapit] SETSCANSATLIST\n"); while (CBasicServer::receive_data(connfd, &sat, sizeof(sat))) { -printf("[zapit] adding to scan %s (position %d)\n", sat.satName, sat.position); + printf("[zapit] adding to scan %s (position %d)\n", sat.satName, sat.position); scanProviders[sat.position] = sat.satName; } break; } case CZapitMessages::CMD_SCANSETSCANMOTORPOSLIST: { -#if 0 // absolute - CZapitClient::commandSetScanMotorPosList pos; - bool changed = false; - while (CBasicServer::receive_data(connfd, &pos, sizeof(pos))) { - //printf("adding %d (motorPos %d)\n", pos.satPosition, pos.motorPos); - changed |= (motorPositions[pos.satPosition] != pos.motorPos); - motorPositions[pos.satPosition] = pos.motorPos; - } - - if (changed) - SaveMotorPositions(); -#endif + // absolute break; } @@ -1288,22 +1169,15 @@ printf("[zapit] adding to scan %s (position %d)\n", sat.satName, sat.position); case CZapitMessages::CMD_SET_EVENT_MODE: { CZapitMessages::commandSetRecordMode msgSetRecordMode; CBasicServer::receive_data(connfd, &msgSetRecordMode, sizeof(msgSetRecordMode)); -//printf("[zapit] event mode: %d\n", msgSetRecordMode.activate);fflush(stdout); + //printf("[zapit] event mode: %d\n", msgSetRecordMode.activate);fflush(stdout); event_mode = msgSetRecordMode.activate; - if(event_mode) - pipzap = 0; - else if(!standby) - pipzap = 1; break; } case CZapitMessages::CMD_SET_RECORD_MODE: { CZapitMessages::commandSetRecordMode msgSetRecordMode; CBasicServer::receive_data(connfd, &msgSetRecordMode, sizeof(msgSetRecordMode)); -printf("[zapit] recording mode: %d\n", msgSetRecordMode.activate);fflush(stdout); - if (msgSetRecordMode.activate) - setRecordMode(); - else - unsetRecordMode(); + printf("[zapit] recording mode: %d\n", msgSetRecordMode.activate);fflush(stdout); + SetRecordMode(msgSetRecordMode.activate); break; } @@ -1399,7 +1273,7 @@ printf("[zapit] recording mode: %d\n", msgSetRecordMode.activate);fflush(stdout) break; } if(!status) { - allchans.erase(msgRemoveChannelFromBouquet.channel_id); + CServiceManager::getInstance()->RemoveChannel(msgRemoveChannelFromBouquet.channel_id); g_current_channel = 0; g_list_changed = 1; } @@ -1447,17 +1321,17 @@ printf("[zapit] recording mode: %d\n", msgSetRecordMode.activate);fflush(stdout) #if 0 //if (msgBoolean.truefalse) if(g_list_changed) { - eventServer->sendEvent(CZapitClient::EVT_SERVICES_CHANGED, CEventServer::INITID_ZAPIT); + SendEvent(CZapitClient::EVT_SERVICES_CHANGED); } else - eventServer->sendEvent(CZapitClient::EVT_BOUQUETS_CHANGED, CEventServer::INITID_ZAPIT); + SendEvent(CZapitClient::EVT_BOUQUETS_CHANGED); #endif g_bouquetManager->saveBouquets(); g_bouquetManager->saveUBouquets(); g_bouquetManager->renumServices(); - //eventServer->sendEvent(CZapitClient::EVT_SERVICES_CHANGED, CEventServer::INITID_ZAPIT); - eventServer->sendEvent(CZapitClient::EVT_BOUQUETS_CHANGED, CEventServer::INITID_ZAPIT); + //SendEvent(CZapitClient::EVT_SERVICES_CHANGED); + SendEvent(CZapitClient::EVT_BOUQUETS_CHANGED); if(g_list_changed) { - SaveServices(true); + CServiceManager::getInstance()->SaveServices(true); g_list_changed = 0; } break; @@ -1477,11 +1351,11 @@ printf("[zapit] recording mode: %d\n", msgSetRecordMode.activate);fflush(stdout) case CZapitMessages::CMD_SB_START_PLAYBACK: //playbackStopForced = false; - startPlayBack(g_current_channel); + StartPlayBack(g_current_channel); break; case CZapitMessages::CMD_SB_STOP_PLAYBACK: - stopPlayBack(false); + StopPlayBack(false); response.cmd = CZapitMessages::CMD_READY; CBasicServer::send_data(connfd, &response, sizeof(response)); break; @@ -1489,7 +1363,7 @@ printf("[zapit] recording mode: %d\n", msgSetRecordMode.activate);fflush(stdout) case CZapitMessages::CMD_SB_LOCK_PLAYBACK: /* hack. if standby true, dont blank video */ standby = true; - stopPlayBack(true); + StopPlayBack(true); standby = false; playbackStopForced = true; response.cmd = CZapitMessages::CMD_READY; @@ -1497,8 +1371,8 @@ printf("[zapit] recording mode: %d\n", msgSetRecordMode.activate);fflush(stdout) break; case CZapitMessages::CMD_SB_UNLOCK_PLAYBACK: playbackStopForced = false; - startPlayBack(g_current_channel); - start_camd(); + StartPlayBack(g_current_channel); + SendPMT(); response.cmd = CZapitMessages::CMD_READY; CBasicServer::send_data(connfd, &response, sizeof(response)); break; @@ -1585,36 +1459,46 @@ printf("[zapit] recording mode: %d\n", msgSetRecordMode.activate);fflush(stdout) response_FEsig.ber = CFrontend::getInstance()->getBitErrorRate(); CBasicServer::send_data(connfd, &response_FEsig, sizeof(CZapitClient::responseFESignal)); - //sendAPIDs(connfd); break; } case CZapitMessages::CMD_SETSUBSERVICES: { CZapitClient::commandAddSubServices msgAddSubService; + t_satellite_position satellitePosition = g_current_channel ? g_current_channel->getSatellitePosition() : 0; while (CBasicServer::receive_data(connfd, &msgAddSubService, sizeof(msgAddSubService))) { +#if 0 t_original_network_id original_network_id = msgAddSubService.original_network_id; t_service_id service_id = msgAddSubService.service_id; - - t_satellite_position satellitePosition = g_current_channel ? g_current_channel->getSatellitePosition() : 0; t_channel_id sub_channel_id = ((uint64_t) ( satellitePosition >= 0 ? satellitePosition : (uint64_t)(0xF000+ abs(satellitePosition))) << 48) | (uint64_t) CREATE_CHANNEL_ID_FROM_SERVICE_ORIGINALNETWORK_TRANSPORTSTREAM_ID(msgAddSubService.service_id, msgAddSubService.original_network_id, msgAddSubService.transport_stream_id); DBG("NVOD insert %llx\n", sub_channel_id); nvodchannels.insert ( - std::pair ( - sub_channel_id, - CZapitChannel ( - "NVOD", - service_id, - msgAddSubService.transport_stream_id, - original_network_id, - 1, - satellitePosition, - 0 - ) - ) - ); + std::pair ( + sub_channel_id, + CZapitChannel ( + "NVOD", + service_id, + msgAddSubService.transport_stream_id, + original_network_id, + 1, + satellitePosition, + 0 + ) + ) + ); +#endif + CZapitChannel * channel = new CZapitChannel ( + "NVOD", + msgAddSubService.service_id, + msgAddSubService.transport_stream_id, + msgAddSubService.original_network_id, + ST_DIGITAL_TELEVISION_SERVICE, + satellitePosition, + 0 + ); + CServiceManager::getInstance()->AddNVODChannel(channel); } current_is_nvod = true; @@ -1701,16 +1585,11 @@ printf("[zapit] recording mode: %d\n", msgSetRecordMode.activate);fflush(stdout) return true; } -/****************************************************************/ -/* functions for new command handling via CZapitClient */ -/* these functions should be encapsulated in a class CZapit */ -/****************************************************************/ - -void addChannelToBouquet(const unsigned int bouquet, const t_channel_id channel_id) +void CZapit::addChannelToBouquet(const unsigned int bouquet, const t_channel_id channel_id) { //DBG("addChannelToBouquet(%d, %d)\n", bouquet, channel_id); - CZapitChannel* chan = g_bouquetManager->findChannelByChannelID(channel_id); + CZapitChannel* chan = CServiceManager::getInstance()->FindChannel(channel_id); if (chan != NULL) if (bouquet < g_bouquetManager->Bouquets.size()) @@ -1721,7 +1600,7 @@ void addChannelToBouquet(const unsigned int bouquet, const t_channel_id channel_ WARN("channel_id not found in channellist"); } -bool send_data_count(int connfd, int data_count) +bool CZapit::send_data_count(int connfd, int data_count) { CZapitMessages::responseGeneralInteger responseInteger; responseInteger.number = data_count; @@ -1732,7 +1611,7 @@ bool send_data_count(int connfd, int data_count) return true; } -void sendAPIDs(int connfd) +void CZapit::sendAPIDs(int connfd) { if (!send_data_count(connfd, g_current_channel->getAudioChannelCount())) return; @@ -1755,7 +1634,7 @@ void sendAPIDs(int connfd) } } -void internalSendChannels(int connfd, ZapitChannelList* channels, const unsigned int first_channel_nr, bool nonames) +void CZapit::internalSendChannels(int connfd, ZapitChannelList* channels, const unsigned int first_channel_nr, bool nonames) { int data_count = channels->size(); #if RECORD_RESEND // old, before tv/radio resend @@ -1806,7 +1685,7 @@ DBG("current: %d name %s total %d\n", i, response.name, data_count); } } -void sendBouquets(int connfd, const bool emptyBouquetsToo, CZapitClient::channelsMode mode) +void CZapit::sendBouquets(int connfd, const bool emptyBouquetsToo, CZapitClient::channelsMode mode) { CZapitClient::responseGetBouquets msgBouquet; int curMode; @@ -1856,7 +1735,7 @@ void sendBouquets(int connfd, const bool emptyBouquetsToo, CZapitClient::channel } } -void sendBouquetChannels(int connfd, const unsigned int bouquet, const CZapitClient::channelsMode mode, bool nonames) +void CZapit::sendBouquetChannels(int connfd, const unsigned int bouquet, const CZapitClient::channelsMode mode, bool nonames) { if (bouquet >= g_bouquetManager->Bouquets.size()) { WARN("invalid bouquet number: %d", bouquet); @@ -1869,7 +1748,7 @@ void sendBouquetChannels(int connfd, const unsigned int bouquet, const CZapitCli internalSendChannels(connfd, &(g_bouquetManager->Bouquets[bouquet]->tvChannels), g_bouquetManager->tvChannelsBegin().getNrofFirstChannelofBouquet(bouquet), nonames); } -void sendChannels(int connfd, const CZapitClient::channelsMode mode, const CZapitClient::channelsOrder order) +void CZapit::sendChannels(int connfd, const CZapitClient::channelsMode mode, const CZapitClient::channelsOrder order) { ZapitChannelList channels; @@ -1878,16 +1757,13 @@ void sendChannels(int connfd, const CZapitClient::channelsMode mode, const CZapi for (; !(cit.EndOfChannels()); cit++) channels.push_back(*cit); } - else if (order == CZapitClient::SORT_ALPHA) // ATTENTION: in this case response.nr does not return the actual number of the channel for zapping! + else if (order == CZapitClient::SORT_ALPHA) { - if (((currentMode & RADIO_MODE) && (mode == CZapitClient::MODE_CURRENT)) || (mode==CZapitClient::MODE_RADIO)) { - for (tallchans_iterator it = allchans.begin(); it != allchans.end(); it++) - if (it->second.getServiceType() == ST_DIGITAL_RADIO_SOUND_SERVICE) - channels.push_back(&(it->second)); + // ATTENTION: in this case response.nr does not return the actual number of the channel for zapping! + if (((currentMode & RADIO_MODE) && (mode == CZapitClient::MODE_CURRENT)) || (mode == CZapitClient::MODE_RADIO)) { + CServiceManager::getInstance()->GetAllRadioChannels(channels); } else { - for (tallchans_iterator it = allchans.begin(); it != allchans.end(); it++) - if (it->second.getServiceType() != ST_DIGITAL_RADIO_SOUND_SERVICE) - channels.push_back(&(it->second)); + CServiceManager::getInstance()->GetAllTvChannels(channels); } sort(channels.begin(), channels.end(), CmpChannelByChName()); } @@ -1895,7 +1771,7 @@ void sendChannels(int connfd, const CZapitClient::channelsMode mode, const CZapi internalSendChannels(connfd, &channels, 0, false); } -int startPlayBack(CZapitChannel *thisChannel) +bool CZapit::StartPlayBack(CZapitChannel *thisChannel) { bool have_pcr = false; bool have_audio = false; @@ -1905,12 +1781,12 @@ int startPlayBack(CZapitChannel *thisChannel) if(!thisChannel) thisChannel = g_current_channel; if ((playbackStopForced == true) || (!thisChannel) || playing) - return -1; + return false; printf("[zapit] vpid %X apid %X pcr %X\n", thisChannel->getVideoPid(), thisChannel->getAudioPid(), thisChannel->getPcrPid()); if(standby) { CFrontend::getInstance()->Open(); - return 0; + return true; } if (thisChannel->getPcrPid() != 0) @@ -1923,7 +1799,7 @@ int startPlayBack(CZapitChannel *thisChannel) have_teletext = true; if ((!have_audio) && (!have_video) && (!have_teletext)) - return -1; + return false; #if 1 if(have_video && (thisChannel->getPcrPid() == 0x1FFF)) { //FIXME thisChannel->setPcrPid(thisChannel->getVideoPid()); @@ -1958,34 +1834,7 @@ int startPlayBack(CZapitChannel *thisChannel) /* select audio output and start audio */ if (have_audio) { - const char *audioStr = "UNKNOWN"; - switch (thisChannel->getAudioChannel()->audioChannelType) { - case CZapitAudioChannel::AC3: - audioStr = "AC3"; - audioDecoder->SetStreamType(AUDIO_FMT_DOLBY_DIGITAL); - break; - case CZapitAudioChannel::MPEG: - audioStr = "MPEG2"; - audioDecoder->SetStreamType(AUDIO_FMT_MPEG); - break; - case CZapitAudioChannel::AAC: - audioStr = "AAC"; - audioDecoder->SetStreamType(AUDIO_FMT_AAC); - break; - case CZapitAudioChannel::AACPLUS: - audioStr = "AAC-PLUS"; - audioDecoder->SetStreamType(AUDIO_FMT_AAC_PLUS); - break; - case CZapitAudioChannel::DTS: - audioStr = "DTS"; - audioDecoder->SetStreamType(AUDIO_FMT_DTS); - break; - default: - printf("[zapit] unknown audio channel type 0x%x\n", thisChannel->getAudioChannel()->audioChannelType); - break; - } - - printf("[zapit] starting %s audio\n", audioStr); + SetAudioStreamType(thisChannel->getAudioChannel()->audioChannelType); audioDemux->Start(); audioDecoder->Start(); } @@ -2001,26 +1850,23 @@ int startPlayBack(CZapitChannel *thisChannel) #endif playing = true; - return 0; + return true; } -int stopPlayBack(bool stop_camd) +bool CZapit::StopPlayBack(bool send_pmt) { - if(stop_camd) { - if(!(currentMode & RECORD_MODE)) - unlink("/tmp/pmt.tmp"); - + if(send_pmt) { CCamManager::getInstance()->Stop(live_channel_id, CCamManager::PLAY); ca->SendPMT(0, (unsigned char*) "", 0, CA_SLOT_TYPE_SMARTCARD); } - printf("stopPlayBack: standby %d forced %d\n", standby, playbackStopForced); + printf("StopPlayBack: standby %d forced %d\n", standby, playbackStopForced); if (!playing) - return 0; + return true; if (playbackStopForced) - return -1; + return false; videoDemux->Stop(); audioDemux->Stop(); @@ -2040,48 +1886,47 @@ int stopPlayBack(bool stop_camd) else dvbsub_stop(); - return 0; + return true; } -void enterStandby(void) +void CZapit::enterStandby(void) { if (standby) return; standby = true; - saveZapitSettings(true, true); - stopPlayBack(true); + SaveSettings(true, true); + StopPlayBack(true); if(!(currentMode & RECORD_MODE)) { CFrontend::getInstance()->Close(); - rename("/tmp/pmt.tmp", "/tmp/pmt.tmp.off"); } } -void leaveStandby(void) +void CZapit::leaveStandby(void) { - if(!standby) return; + if(!standby) + return; printf("[zapit] diseqc type = %d\n", diseqcType); - CFrontend::getInstance()->setDiseqcRepeats(config.getInt32("diseqcRepeats", 0)); - CFrontend::getInstance()->setCurrentSatellitePosition(config.getInt32("lastSatellitePosition", 0)); + CFrontend::getInstance()->setDiseqcRepeats(configfile.getInt32("diseqcRepeats", 0)); + CFrontend::getInstance()->setCurrentSatellitePosition(configfile.getInt32("lastSatellitePosition", 0)); CFrontend::getInstance()->setDiseqcType(diseqcType); if(!(currentMode & RECORD_MODE)) { CFrontend::getInstance()->Open(); CFrontend::getInstance()->setTsidOnid(0); CFrontend::getInstance()->setDiseqcType(diseqcType); - rename("/tmp/pmt.tmp.off", "/tmp/pmt.tmp"); } standby = false; if (g_current_channel) /* tune channel, with stopped playback to not bypass the parental PIN check */ - zapit(live_channel_id, current_is_nvod, false, false); + ZapIt(live_channel_id, false, false); } -unsigned zapTo(const unsigned int bouquet, const unsigned int pchannel) +unsigned CZapit::ZapTo(const unsigned int bouquet, const unsigned int pchannel) { if (bouquet >= g_bouquetManager->Bouquets.size()) { WARN("Invalid bouquet %d", bouquet); @@ -2100,100 +1945,89 @@ unsigned zapTo(const unsigned int bouquet, const unsigned int pchannel) return CZapitClient::ZAP_INVALID_PARAM; } - return zapTo_ChannelID((*channels)[pchannel]->getChannelID(), false); + return ZapTo((*channels)[pchannel]->getChannelID(), false); } -unsigned int zapTo_ChannelID(t_channel_id channel_id, bool isSubService) +unsigned int CZapit::ZapTo(t_channel_id channel_id, bool isSubService) { unsigned int result = 0; - if (zapit(channel_id, isSubService) < 0) { -DBG("[zapit] zapit failed, chid %llx\n", channel_id); - if(event_mode) eventServer->sendEvent((isSubService ? CZapitClient::EVT_ZAP_SUB_FAILED : CZapitClient::EVT_ZAP_FAILED), CEventServer::INITID_ZAPIT, &channel_id, sizeof(channel_id)); + if (!ZapIt(channel_id)) { + DBG("[zapit] zapit failed, chid %llx\n", channel_id); + SendEvent((isSubService ? CZapitClient::EVT_ZAP_SUB_FAILED : CZapitClient::EVT_ZAP_FAILED), &channel_id, sizeof(channel_id)); return result; } result |= CZapitClient::ZAP_OK; -DBG("[zapit] zapit OK, chid %llx\n", channel_id); + DBG("[zapit] zapit OK, chid %llx\n", channel_id); if (isSubService) { -DBG("[zapit] isSubService chid %llx\n", channel_id); - if(event_mode) eventServer->sendEvent(CZapitClient::EVT_ZAP_SUB_COMPLETE, CEventServer::INITID_ZAPIT, &channel_id, sizeof(channel_id)); + DBG("[zapit] isSubService chid %llx\n", channel_id); + SendEvent(CZapitClient::EVT_ZAP_SUB_COMPLETE, &channel_id, sizeof(channel_id)); } else if (current_is_nvod) { -DBG("[zapit] NVOD chid %llx\n", channel_id); - if(event_mode) eventServer->sendEvent(CZapitClient::EVT_ZAP_COMPLETE_IS_NVOD, CEventServer::INITID_ZAPIT, &channel_id, sizeof(channel_id)); + DBG("[zapit] NVOD chid %llx\n", channel_id); + SendEvent(CZapitClient::EVT_ZAP_COMPLETE_IS_NVOD, &channel_id, sizeof(channel_id)); result |= CZapitClient::ZAP_IS_NVOD; } else - if(event_mode) eventServer->sendEvent(CZapitClient::EVT_ZAP_COMPLETE, CEventServer::INITID_ZAPIT, &channel_id, sizeof(channel_id)); + SendEvent(CZapitClient::EVT_ZAP_COMPLETE, &channel_id, sizeof(channel_id)); return result; } -unsigned zapTo(const unsigned int pchannel) +unsigned CZapit::ZapTo(const unsigned int pchannel) { CBouquetManager::ChannelIterator cit = ((currentMode & RADIO_MODE) ? g_bouquetManager->radioChannelsBegin() : g_bouquetManager->tvChannelsBegin()).FindChannelNr(pchannel); if (!(cit.EndOfChannels())) - return zapTo_ChannelID((*cit)->getChannelID(), false); + return ZapTo((*cit)->getChannelID(), false); else return 0; } -void signal_handler(int signum) +bool CZapit::Start(Z_start_arg *ZapStart_arg) { - signal (signum, SIG_IGN); - printf("signal %d received\n", signum); fflush(stdout); - switch (signum) { - case SIGUSR1: - zapit_debug = !zapit_debug; - break; - default: - CZapitClient zapit; - zapit.shutdown(); - break; - } -} + if(started) + return false; -int zapit_main_thread(void *data) -{ - Z_start_arg *ZapStart_arg = (Z_start_arg *) data; - int video_mode = ZapStart_arg->video_mode; + /* load configuration or set defaults if no configuration file exists */ + video_mode = ZapStart_arg->video_mode; - time_t stime; - printf("[zapit] starting... tid %ld\n", syscall(__NR_gettid)); - abort_zapit = 0; - - pcrDemux = new cDemux(); videoDemux = new cDemux(); videoDemux->Open(DMX_VIDEO_CHANNEL); + pcrDemux = new cDemux(); pcrDemux->Open(DMX_PCR_ONLY_CHANNEL, videoDemux->getBuffer()); -#if 0 - videoDecoder = new cVideo(VIDEO_STD_PAL, videoDemux->getChannel(), videoDemux->getBuffer());//PAL - videoDecoder->Standby(false); - videoDecoder->SetVideoSystem(video_mode); -#else - videoDecoder = new cVideo(video_mode, videoDemux->getChannel(), videoDemux->getBuffer()); - videoDecoder->Standby(false); -#endif audioDemux = new cDemux(); audioDemux->Open(DMX_AUDIO_CHANNEL); + videoDecoder = new cVideo(video_mode, videoDemux->getChannel(), videoDemux->getBuffer()); + videoDecoder->Standby(false); + audioDecoder = new cAudio(audioDemux->getBuffer(), videoDecoder->GetTVEnc(), NULL /*videoDecoder->GetTVEncSD()*/); videoDecoder->SetAudioHandle(audioDecoder->GetHandle()); + #ifdef USE_VBI videoDecoder->OpenVBI(1); #endif ca = cCA::GetInstance(); - scan_runs = 0; - found_channels = 0; - curr_sat = 0; + LoadSettings(); - /* load configuration or set defaults if no configuration file exists */ - loadZapitSettings(); + /* create bouquet manager */ + g_bouquetManager = new CBouquetManager(); + + if (configfile.getInt32("lastChannelMode", 0)) + SetRadioMode(); + else + SetTVMode(); + + if(ZapStart_arg->uselastchannel == 0){ + live_channel_id = (currentMode & RADIO_MODE) ? ZapStart_arg->startchannelradio_id : ZapStart_arg->startchanneltv_id ; + lastChannelRadio = ZapStart_arg->startchannelradio_nr; + lastChannelTV = ZapStart_arg->startchanneltv_nr; + } /* CA_INIT_CI or CA_INIT_SC or CA_INIT_BOTH */ switch(cam_ci){ @@ -2212,49 +2046,60 @@ int zapit_main_thread(void *data) } ca->Start(); - /* create bouquet manager */ - g_bouquetManager = new CBouquetManager(); + eventServer = new CEventServer; - if (config.getInt32("lastChannelMode", 0)){ - setRadioMode(); - } - else{ - setTVMode(); - } - if(ZapStart_arg->uselastchannel == 0){ - live_channel_id = (currentMode & RADIO_MODE) ? ZapStart_arg->startchannelradio_id : ZapStart_arg->startchanneltv_id ; - lastChannelRadio = ZapStart_arg->startchannelradio_nr; - lastChannelTV = ZapStart_arg->startchanneltv_nr; - } - - if (prepare_channels(CFrontend::getInstance()->getInfo()->type, diseqcType) < 0) + if (!PrepareChannels()) WARN("error parsing services"); else INFO("channels have been loaded succesfully"); - CBasicServer zapit_server; + g_current_channel = CServiceManager::getInstance()->FindChannel(live_channel_id); - if (!zapit_server.prepare(ZAPIT_UDS_NAME)) - return -1; - - eventServer = new CEventServer; - - tallchans_iterator cit; - cit = allchans.find(live_channel_id); - if(cit != allchans.end()) - g_current_channel = &(cit->second); - - zapit_ready = 1; // some older? hw needs this sleep. e.g. my hd-1c. // if sleep is not set -> blackscreen after boot. // sleep(1) is ok here. (striper) sleep(1); leaveStandby(); - //firstzap = false; - stime = time(0); - //time_t curtime; - pthread_create (&tsdt, NULL, sdt_thread, (void *) NULL); - while (zapit_server.run(zapit_parse_command, CZapitMessages::ACTVERSION, true)) { + + started = true; + int ret = start(); + return (ret == 0); +} + +bool CZapit::Stop() +{ + started = false; + int ret = join(); + return (ret == 0); +} + +static bool zapit_parse_command(CBasicMessage::Header &rmsg, int connfd) +{ + return CZapit::getInstance()->ParseCommand(rmsg, connfd); +} + +void CZapit::run() +{ +#if 0 + time_t stime = time(0); + time_t curtime; +#endif + printf("[zapit] starting... tid %ld\n", syscall(__NR_gettid)); + + abort_zapit = 0; + + CBasicServer zapit_server; + + if (!zapit_server.prepare(ZAPIT_UDS_NAME)) { + perror(ZAPIT_UDS_NAME); + return; + } + + zapit_ready = 1; + //pthread_create (&tsdt, NULL, sdt_thread, (void *) NULL); + SdtMonitor.Start(); + while (started && zapit_server.run(zapit_parse_command, CZapitMessages::ACTVERSION, true)) + { if (pmt_update_fd != -1) { unsigned char buf[4096]; int ret = pmtDemux->Read(buf, 4095, 10); @@ -2266,20 +2111,19 @@ int zapit_main_thread(void *data) int vpid = g_current_channel->getVideoPid(); parse_pmt(g_current_channel); if(vpid != g_current_channel->getVideoPid()) { - zapit(g_current_channel->getChannelID(), current_is_nvod, true); + ZapIt(g_current_channel->getChannelID(), true); } else { - start_camd(true); + SendPMT(true); pmt_set_update_filter(g_current_channel, &pmt_update_fd); } - if(event_mode) - eventServer->sendEvent(CZapitClient::EVT_PMT_CHANGED, CEventServer::INITID_ZAPIT, &channel_id, sizeof(channel_id)); + SendEvent(CZapitClient::EVT_PMT_CHANGED, &channel_id, sizeof(channel_id)); } } } /* yuck, don't waste that much cpu time :) */ usleep(0); #if 0 - if(!standby && !scan_runs &&g_current_channel) { + if(!standby && !CServiceScan::getInstance()->Scanning() &&g_current_channel) { curtime = time(0); if(sig_delay && (curtime - stime) > sig_delay) { stime = curtime; @@ -2294,16 +2138,18 @@ int zapit_main_thread(void *data) #endif } - save_channel_pids(g_current_channel); - saveZapitSettings(true, true); - stopPlayBack(true); -// enterStandby(); + SaveChannelPids(g_current_channel); + SaveSettings(true, true); + StopPlayBack(true); - SaveMotorPositions(); + CServiceManager::getInstance()->SaveMotorPositions(); +#if 0 pthread_cancel(tsdt); zapit_ready = 0; pthread_join (tsdt, NULL); +#endif + SdtMonitor.Stop(); INFO("shutdown started"); #ifdef USE_VBI videoDecoder->CloseVBI(); @@ -2327,84 +2173,73 @@ int zapit_main_thread(void *data) delete ca; } INFO("shutdown complete"); - return 0; + return; } -void setZapitConfig(Zapit_config * Cfg) +void CZapit::SetConfig(Zapit_config * Cfg) { printf("[zapit] %s...\n", __FUNCTION__); - motorRotationSpeed = Cfg->motorRotationSpeed; - config.setInt32("motorRotationSpeed", motorRotationSpeed); - config.setBool("writeChannelsNames", Cfg->writeChannelsNames); - config.setBool("makeRemainingChannelsBouquet", Cfg->makeRemainingChannelsBouquet); - config.setBool("saveLastChannel", Cfg->saveLastChannel); - fastZap = Cfg->fastZap; - sortNames = Cfg->sortNames; - sortlist = sortNames; - highVoltage = Cfg->highVoltage; - scan_pids = Cfg->scanPids; - rezapTimeout = Cfg->rezapTimeout; - feTimeout = Cfg->feTimeout; - useGotoXX = Cfg->useGotoXX; - gotoXXLaDirection = Cfg->gotoXXLaDirection; - gotoXXLoDirection = Cfg->gotoXXLoDirection; - gotoXXLatitude = Cfg->gotoXXLatitude; - gotoXXLongitude = Cfg->gotoXXLongitude; - repeatUsals = Cfg->repeatUsals; - scanSDT = Cfg->scanSDT; - saveZapitSettings(true, false); + config = *Cfg; + + //FIXME globals! + scan_pids = config.scanPids; + //scanSDT = config.scanSDT; + motorRotationSpeed = config.motorRotationSpeed; + highVoltage = config.highVoltage; + feTimeout = config.feTimeout; + gotoXXLaDirection = config.gotoXXLaDirection; + gotoXXLoDirection = config.gotoXXLoDirection; + gotoXXLatitude = config.gotoXXLatitude; + gotoXXLongitude = config.gotoXXLongitude; + repeatUsals = config.repeatUsals; + + SaveSettings(true, false); } -void sendConfig(int connfd) -{ - Zapit_config Cfg; - printf("[zapit] %s...\n", __FUNCTION__); - Cfg.motorRotationSpeed = motorRotationSpeed; - Cfg.writeChannelsNames = config.getBool("writeChannelsNames", true); - Cfg.makeRemainingChannelsBouquet = config.getBool("makeRemainingChannelsBouquet", true); - Cfg.saveLastChannel = config.getBool("saveLastChannel", true); - Cfg.fastZap = fastZap; - Cfg.sortNames = sortNames; - Cfg.highVoltage = highVoltage; - Cfg.scanPids = scan_pids; - Cfg.rezapTimeout = rezapTimeout; - Cfg.feTimeout = feTimeout; - Cfg.scanSDT = scanSDT; - Cfg.useGotoXX = useGotoXX; - Cfg.gotoXXLaDirection = gotoXXLaDirection; - Cfg.gotoXXLoDirection = gotoXXLoDirection; - Cfg.gotoXXLatitude = gotoXXLatitude; - Cfg.gotoXXLongitude = gotoXXLongitude; - Cfg.repeatUsals = repeatUsals; - - CBasicServer::send_data(connfd, &Cfg, sizeof(Cfg)); -} - -void getZapitConfig(Zapit_config *Cfg) +void CZapit::SendConfig(int connfd) { printf("[zapit] %s...\n", __FUNCTION__); - Cfg->motorRotationSpeed = motorRotationSpeed; - Cfg->writeChannelsNames = config.getBool("writeChannelsNames", true); - Cfg->makeRemainingChannelsBouquet = config.getBool("makeRemainingChannelsBouquet", true); - Cfg->saveLastChannel = config.getBool("saveLastChannel", true); - Cfg->fastZap = fastZap; - Cfg->sortNames = sortNames; - Cfg->highVoltage = highVoltage; - Cfg->scanPids = scan_pids; - Cfg->rezapTimeout = rezapTimeout; - Cfg->feTimeout = feTimeout; - Cfg->scanSDT = scanSDT; - Cfg->useGotoXX = useGotoXX; - Cfg->gotoXXLaDirection = gotoXXLaDirection; - Cfg->gotoXXLoDirection = gotoXXLoDirection; - Cfg->gotoXXLatitude = gotoXXLatitude; - Cfg->gotoXXLongitude = gotoXXLongitude; - Cfg->repeatUsals = repeatUsals; + CBasicServer::send_data(connfd, &config, sizeof(config)); } -sdt_tp_t sdt_tp; -void * sdt_thread(void * /*arg*/) +void CZapit::GetConfig(Zapit_config &Cfg) +{ + printf("[zapit] %s...\n", __FUNCTION__); + Cfg = config; +} + +CZapitSdtMonitor::CZapitSdtMonitor() +{ + sdt_wakeup = false; + started = false; +} + +CZapitSdtMonitor::~CZapitSdtMonitor() +{ + Stop(); +} + +void CZapitSdtMonitor::Wakeup() +{ + sdt_wakeup = true; +} + +bool CZapitSdtMonitor::Start() +{ + started = true; + int ret = start(); + return (ret == 0); +} + +bool CZapitSdtMonitor::Stop() +{ + started = false; + int ret = join(); + return (ret == 0); +} + +void CZapitSdtMonitor::run() { time_t tstart, tcur, wtime = 0; int ret; @@ -2413,15 +2248,12 @@ void * sdt_thread(void * /*arg*/) t_satellite_position satellitePosition = 0; freq_id_t freq = 0; transponder_id_t tpid = 0; - FILE * fd = 0; - FILE * fd1 = 0; - bool updated = 0; tcur = time(0); tstart = time(0); sdt_tp.clear(); -printf("[zapit] sdt monitor started\n"); - while(zapit_ready) { + printf("[zapit] sdt monitor started\n"); + while(started) { sleep(1); if(sdt_wakeup) { sdt_wakeup = 0; @@ -2434,192 +2266,48 @@ printf("[zapit] sdt monitor started\n"); tpid = g_current_channel->getTransponderId(); } } - if(!scanSDT) + if(!CZapit::getInstance()->scanSDT()) continue; tcur = time(0); if(wtime && ((tcur - wtime) > 2) && !sdt_wakeup) { -printf("[sdt monitor] wakeup...\n"); + printf("[sdt monitor] wakeup...\n"); wtime = 0; - if(scan_runs || (currentMode & RECORD_MODE)) + if(CServiceScan::getInstance()->Scanning() || CZapit::getInstance()->Recording()) continue; - updated = 0; - tallchans_iterator ccI; - tallchans_iterator dI; - transponder_list_t::iterator tI; - sdt_tp_t::iterator stI; - char tpstr[256]; - char satstr[256]; - bool tpdone = 0; - bool satfound = 0; - - tI = transponders.find(tpid); + transponder_list_t::iterator tI = transponders.find(tpid); if(tI == transponders.end()) { printf("[sdt monitor] tp not found ?!\n"); continue; } - stI = sdt_tp.find(tpid); + sdt_tp_map_t::iterator stI = sdt_tp.find(tpid); if ((stI != sdt_tp.end()) && ((time_monotonic() - stI->second) < 3600)) { printf("[sdt monitor] TP already updated less than an hour ago.\n"); continue; } - if(!curchans.empty()) - curchans.clear(); + + CServiceManager::getInstance()->RemoveCurrentChannels(); ret = parse_current_sdt(transport_stream_id, original_network_id, satellitePosition, freq); - if(ret){ + if(ret) { if(ret == -1) printf("[sdt monitor] scanSDT broken ?\n"); continue; } sdt_tp.insert(std::pair (tpid, time_monotonic())); - char buffer[256]; - fd = fopen(CURRENTSERVICES_TMP, "w"); - if(!fd) { - printf("[sdt monitor] " CURRENTSERVICES_TMP ": cant open!\n"); - continue; - } -#if 0 - std::map::iterator spos_it; - for (spos_it = satellitePositions.begin(); spos_it != satellitePositions.end(); spos_it++) { - if(spos_it->second == satellitePosition) - break; - } -#endif - sat_iterator_t spos_it = satellitePositions.find(satellitePosition); - if(spos_it == satellitePositions.end()) - continue; + bool updated = CServiceManager::getInstance()->SaveCurrentServices(tpid); - switch (CFrontend::getInstance()->getInfo()->type) { - case FE_QPSK: /* satellite */ - sprintf(satstr, "\t<%s name=\"%s\" position=\"%hd\">\n", "sat", spos_it->second.name.c_str(), satellitePosition); - sprintf(tpstr, "\t\t\n", - tI->second.transport_stream_id, tI->second.original_network_id, - tI->second.feparams.frequency, tI->second.feparams.inversion, - tI->second.feparams.u.qpsk.symbol_rate, tI->second.feparams.u.qpsk.fec_inner, - tI->second.polarization); - break; - case FE_QAM: /* cable */ - sprintf(satstr, "\t<%s name=\"%s\"\n", "cable", spos_it->second.name.c_str()); - sprintf(tpstr, "\t\t\n", - tI->second.transport_stream_id, tI->second.original_network_id, - tI->second.feparams.frequency, tI->second.feparams.inversion, - tI->second.feparams.u.qam.symbol_rate, tI->second.feparams.u.qam.fec_inner, - tI->second.feparams.u.qam.modulation); - break; - case FE_OFDM: - default: - break; - } - fd1 = fopen(CURRENTSERVICES_XML, "r"); - if(!fd1) { - fprintf(fd, "\n\n"); - } else { - fgets(buffer, 255, fd1); - while(!feof(fd1) && !strstr(buffer, satfound ? "" : "")) { - if(!satfound && !strcmp(buffer, satstr)) - satfound = 1; - fputs(buffer, fd); - fgets(buffer, 255, fd1); - } - //fclose(fd1); - } - for (tallchans_iterator cI = curchans.begin(); cI != curchans.end(); cI++) { - ccI = allchans.find(cI->second.getChannelID()); - if(ccI == allchans.end()) { - if(!tpdone) { - if(!satfound) - fprintf(fd, "%s", satstr); - fprintf(fd, "%s", tpstr); - tpdone = 1; - } - updated = 1; -#if 0 - fprintf(fd, "\t\t\t\n", - cI->second.getServiceId(), convert_UTF8_To_UTF8_XML(cI->second.getName().c_str()).c_str(), - abs(cI->second.getSatellitePosition())/10, cI->second.getSatellitePosition() > 0 ? 'E' : 'W', - cI->second.getServiceType()); -#endif - fprintf(fd, "\t\t\t\n", - cI->second.getServiceId(), convert_UTF8_To_UTF8_XML(cI->second.getName().c_str()).c_str(), - cI->second.getServiceType(), cI->second.scrambled); - } else { - if(strcmp(cI->second.getName().c_str(), ccI->second.getName().c_str()) || cI->second.scrambled != ccI->second.scrambled) { - if(!tpdone) { - if(!satfound) - fprintf(fd, "%s", satstr); - fprintf(fd, "%s", tpstr); - tpdone = 1; - } - updated = 1; - fprintf(fd, "\t\t\t\n", - cI->second.getServiceId(), convert_UTF8_To_UTF8_XML(cI->second.getName().c_str()).c_str(), - cI->second.getServiceType(), cI->second.scrambled); - } -#if 0 - char newname[128]; - sprintf(newname, "%s [%d%c]", cI->second.getName().c_str(), abs(cI->second.getSatellitePosition())/10, cI->second.getSatellitePosition() > 0 ? 'E' : 'W'); - if(strcmp(newname, ccI->second.getName().c_str())) { - if(!tpdone) { - if(!satfound) - fprintf(fd, "%s", satstr); - fprintf(fd, "%s", tpstr); - tpdone = 1; - } - updated = 1; - fprintf(fd, "\t\t\t\n", - cI->second.getServiceId(), convert_UTF8_To_UTF8_XML(cI->second.getName().c_str()).c_str(), - abs(cI->second.getSatellitePosition())/10, cI->second.getSatellitePosition() > 0 ? 'E' : 'W', - cI->second.getServiceType()); - } -#endif - } - } - for (ccI = allchans.begin(); ccI != allchans.end(); ccI++) { - if(ccI->second.getTransponderId() == tpid) { - dI = curchans.find(ccI->second.getChannelID()); - if(dI == curchans.end()) { - if(!tpdone) { - if(!satfound) - fprintf(fd, "%s", satstr); - fprintf(fd, "%s", tpstr); - tpdone = 1; - } - updated = 1; - fprintf(fd, "\t\t\t\n", - ccI->second.getServiceId(), convert_UTF8_To_UTF8_XML(ccI->second.getName().c_str()).c_str(), - ccI->second.getServiceType()); - } - } - } - if(tpdone) { - fprintf(fd, "\t\t\n"); - fprintf(fd, "\t\n"); - } else if(satfound) - fprintf(fd, "\t\n"); - if(fd1) { - fgets(buffer, 255, fd1); - while(!feof(fd1)) { - fputs(buffer, fd); - fgets(buffer, 255, fd1); - } - if(!satfound) fprintf(fd, "\n"); - fclose(fd1); - } else - fprintf(fd, "\n"); - fclose(fd); - rename(CURRENTSERVICES_TMP, CURRENTSERVICES_XML); - if(updated && event_mode && (scanSDT == 1)) - eventServer->sendEvent(CZapitClient::EVT_SDT_CHANGED, CEventServer::INITID_ZAPIT); + if(updated && (CZapit::getInstance()->scanSDT() == 1)) + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SDT_CHANGED); if(!updated) printf("[sdt monitor] no changes.\n"); else printf("[sdt monitor] found changes.\n"); } } - return 0; + return; }