From b51b6125119a37862ad40acb089c17917abcbad3 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Thu, 1 Sep 2011 12:11:50 +0000 Subject: [PATCH] CServiceScan class for service scan tasks. git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-beta@1645 e54a6e83-5905-42d5-8d5c-058d10e6a962 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/ab64d31da315cc8105063a93f386ed519b70df2d Author: [CST] Focus Date: 2011-09-01 (Thu, 01 Sep 2011) --- src/zapit/include/zapit/fastscan.h | 5 - src/zapit/include/zapit/scan.h | 86 ++++- src/zapit/src/fastscan.cpp | 154 ++++----- src/zapit/src/scan.cpp | 482 +++++++++++++++-------------- 4 files changed, 381 insertions(+), 346 deletions(-) diff --git a/src/zapit/include/zapit/fastscan.h b/src/zapit/include/zapit/fastscan.h index 4e36e3d6b..40867ca57 100644 --- a/src/zapit/include/zapit/fastscan.h +++ b/src/zapit/include/zapit/fastscan.h @@ -1,8 +1,6 @@ #ifndef _FASTSCAN_H_ #define _FASTSCAN_H_ -void * start_fast_scan(void * arg); - typedef enum fs_operator { OPERATOR_CD, OPERATOR_TVV, @@ -31,8 +29,5 @@ typedef struct fast_scan_type { } fast_scan_type_t; extern fast_scan_operator_t fast_scan_operators [OPERATOR_MAX]; -int parse_fst(unsigned short pid, fast_scan_operator_t * op); -int parse_fnt(unsigned short pid, unsigned short operator_id); - #endif diff --git a/src/zapit/include/zapit/scan.h b/src/zapit/include/zapit/scan.h index 248ea616a..0320a36f4 100644 --- a/src/zapit/include/zapit/scan.h +++ b/src/zapit/include/zapit/scan.h @@ -8,14 +8,96 @@ #include #include - #include #include +#include +#include +#include #include "bouquets.h" +#include extern CBouquetManager* scanBouquetManager; -char * getFrontendName(); +class CServiceScan : public OpenThreads::Thread +{ + public: + typedef enum scan_type { + SCAN_PROVIDER, + SCAN_TRANSPONDER, + SCAN_FAST + } scan_type_t; + + private: + bool started; + bool running; + bool cable; + bool abort_scan; + scan_type_t scan_mode; + bool scan_nit; + void * scan_arg; + + uint32_t fake_tid, fake_nid; + uint32_t found_transponders; + uint32_t processed_transponders; + uint32_t found_channels; + uint32_t found_tv_chans; + uint32_t found_radio_chans; + uint32_t found_data_chans; + uint32_t failed_transponders; + + short curr_sat; + + std::map scantransponders; // TP list to scan + std::map scanedtransponders; // TP list for current scan + std::map nittransponders; + std::map service_types; + + bool AddTransponder(xmlNodePtr transponder, uint8_t diseqc_pos, t_satellite_position satellitePosition); + bool ScanProvider(xmlNodePtr search, t_satellite_position satellitePosition, uint8_t diseqc_pos); + void Cleanup(const bool success); + bool tuneFrequency(FrontendParameters *feparams, uint8_t polarization, t_satellite_position satellitePosition); + bool ReadNitSdt(t_satellite_position satellitePosition); + void FixServiceTypes(); + + bool ScanTransponder(); + bool ScanProviders(); + + /* fast scan */ + std::map fast_services_sat; + std::map fast_services_freq; + std::map fast_services_number; + + void InitFastscanLnb(int id); + bool ParseFst(unsigned short pid, fast_scan_operator_t * op); + bool ParseFnt(unsigned short pid, unsigned short operator_id); + void process_logical_service_descriptor(const unsigned char * const buffer, const t_transport_stream_id transport_stream_id, const t_original_network_id original_network_id, t_satellite_position satellitePosition, freq_id_t freq); + void process_service_list_descriptor(const unsigned char * const buffer, const t_transport_stream_id transport_stream_id, const t_original_network_id original_network_id, t_satellite_position satellitePosition, freq_id_t freq); + void process_satellite_delivery_system_descriptor(const unsigned char * const buffer, FrontendParameters * feparams, uint8_t * polarization, t_satellite_position * satellitePosition); + bool ScanFast(); + + void run(); + + static CServiceScan * scan; + CServiceScan(); + + public: + ~CServiceScan(); + static CServiceScan * getInstance(); + + bool Start(scan_type_t mode, void * arg); + bool Stop(); + + bool AddTransponder(transponder_id_t TsidOnid, FrontendParameters *feparams, uint8_t polarity, bool fromnit = false); + void ChannelFound(uint8_t service_type, std::string providerName, std::string serviceName); + void AddServiceType(t_channel_id channel_id, uint8_t service_type); + + bool Scanning() { return running; }; + void Abort() { abort_scan = 1; }; + bool Aborted() { return abort_scan; }; + + uint32_t & FoundTransponders() { return found_transponders; }; + uint32_t & FoundChannels() { return found_channels; }; +}; #endif /* __scan_h__ */ diff --git a/src/zapit/src/fastscan.cpp b/src/zapit/src/fastscan.cpp index f2a5d4522..d988e6348 100644 --- a/src/zapit/src/fastscan.cpp +++ b/src/zapit/src/fastscan.cpp @@ -1,20 +1,19 @@ #include #include -#include #include #include #include #include #include #include -#include #include #include #include #include #include #include +#include #include #include #include @@ -27,40 +26,20 @@ fast_scan_operator_t fast_scan_operators [OPERATOR_MAX] = { { TELESAT_OPERATOR_ID, 920, 921 , (char *) "TéléSAT" } }; -extern bool tuneFrequency(FrontendParameters *feparams, uint8_t polarization, t_satellite_position satellitePosition); -extern void stop_scan(const bool success); -extern CEventServer *eventServer; - extern CBouquetManager *g_bouquetManager; extern CBouquetManager* scanBouquetManager; extern CZapitClient::bouquetMode bouquetMode; extern transponder_list_t transponders; // defined in zapit.cpp -extern tallchans allchans; // defined in zapit.cpp -extern int found_transponders; -extern int found_channels; -extern uint32_t found_tv_chans; -extern uint32_t found_radio_chans; -extern uint32_t found_data_chans; -extern int zapit(const t_channel_id channel_id, bool in_nvod, bool forupdate = 0, bool nowait = 0); + extern t_channel_id live_channel_id; extern CZapitChannel *g_current_channel; -int process_satellite_delivery_system_descriptor(const unsigned char * const buffer, FrontendParameters * feparams, uint8_t * polarization, t_satellite_position * satellitePosition); -void process_service_list_descriptor(const unsigned char * const buffer, const t_transport_stream_id transport_stream_id, const t_original_network_id original_network_id, t_satellite_position satellitePosition, freq_id_t freq); -void process_logical_service_descriptor(const unsigned char * const buffer, const t_transport_stream_id transport_stream_id, const t_original_network_id original_network_id, t_satellite_position satellitePosition, freq_id_t freq); - -std::map fast_services_sat; -std::map fast_services_freq; -std::map fast_services_number; - -extern void init_sat(t_satellite_position position); - -void init_fastscan_lnb(int id) +void CServiceScan::InitFastscanLnb(int id) { - init_sat(192); - init_sat(235); - init_sat(282); - init_sat(130); + CServiceManager::getInstance()->InitSatPosition(192); + CServiceManager::getInstance()->InitSatPosition(235); + CServiceManager::getInstance()->InitSatPosition(282); + CServiceManager::getInstance()->InitSatPosition(130); switch(id) { default: case CD_OPERATOR_ID: @@ -79,12 +58,12 @@ void init_fastscan_lnb(int id) } } -void * start_fast_scan(void * arg) +bool CServiceScan::ScanFast() { - fast_scan_type_t * scan = (fast_scan_type_t *) arg; + fast_scan_type_t * fast_type = (fast_scan_type_t *) scan_arg; fast_scan_operator_t * op; - fs_operator_t num = scan->op; - int type = scan->type; + fs_operator_t num = fast_type->op; + int type = fast_type->type; uint8_t polarization; FrontendParameters feparams; int res; @@ -108,9 +87,9 @@ void * start_fast_scan(void * arg) feparams.u.qpsk.fec_inner = FEC_5_6; polarization = 0; - eventServer->sendEvent(CZapitClient::EVT_SCAN_SATELLITE, CEventServer::INITID_ZAPIT, op->name, strlen(op->name)+1); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SATELLITE, op->name, strlen(op->name)+1); - init_fastscan_lnb(op->id); + InitFastscanLnb(op->id); if(!tuneFrequency(&feparams, polarization, 192)) { printf("[fast scan] tune failed\n"); goto _err; @@ -123,32 +102,32 @@ void * start_fast_scan(void * arg) fast_services_number.clear(); if(type & FAST_SCAN_SD) { - res = parse_fnt(op->sd_pid, op->id); + res = ParseFnt(op->sd_pid, op->id); if(res == 0) - parse_fst(op->sd_pid, op); + ParseFst(op->sd_pid, op); printf("[fast scan] pid %d (SD) scan done, found %d transponders and %d services\n", op->sd_pid, found_transponders, found_channels); } if(type & FAST_SCAN_HD) { - res = parse_fnt(op->hd_pid, op->id); + res = ParseFnt(op->hd_pid, op->id); if(res == 0) - res = parse_fst(op->hd_pid, op); + res = ParseFst(op->hd_pid, op); printf("[fast scan] pid %d (HD) scan done, found %d transponders and %d services\n", op->hd_pid, found_transponders, found_channels); } if(found_channels) { CZapitClient myZapitClient; - SaveServices(true); + CServiceManager::getInstance()->SaveServices(true); scanBouquetManager->saveBouquets(bouquetMode, ""); g_bouquetManager->saveBouquets(); g_bouquetManager->saveUBouquets(); - g_bouquetManager->clearAll(); + //g_bouquetManager->clearAll(); g_bouquetManager->loadBouquets(); - stop_scan(true); + Cleanup(true); myZapitClient.reloadCurrentServices(); } else { - stop_scan(false); + Cleanup(false); CFrontend::getInstance()->setTsidOnid(0); //zapit(live_channel_id, 0); } @@ -157,22 +136,13 @@ void * start_fast_scan(void * arg) fast_services_number.clear(); printf("[fast scan] fast scan done, found %d transponders and %d services\n", found_transponders, found_channels); - return NULL; + return true; _err: - stop_scan(false); - return NULL; + Cleanup(false); + return false; } -struct CmpChannelByNum: public binary_function -{ - bool operator() (const CZapitChannel * const c1, const CZapitChannel * const c2) - { - return c1->number < c2->number; -; - }; -}; - -int parse_fst(unsigned short pid, fast_scan_operator_t * op) +bool CServiceScan::ParseFst(unsigned short pid, fast_scan_operator_t * op) { int secdone[255]; int sectotal = -1; @@ -216,17 +186,17 @@ int parse_fst(unsigned short pid, fast_scan_operator_t * op) if (dmx->sectionFilter(pid, filter, mask, 3) < 0) { delete dmx; - return -1; + return false; } g_current_channel = 0; g_bouquetManager->clearAll(); - allchans.clear(); + CServiceManager::getInstance()->RemoveAllChannels(); do { if (dmx->Read(buffer, SEC_SIZE) < 0) { delete dmx; - return -1; + return false; } if(buffer[0] != 0xBD) printf("[FST] ******************************************* Bogus section received: 0x%x\n", buffer[0]); @@ -293,20 +263,20 @@ int parse_fst(unsigned short pid, fast_scan_operator_t * op) std::string providerName = convertDVBUTF8((const char*)&(dbuf[4]), service_provider_name_length, 1, 1); std::string serviceName = convertDVBUTF8((const char*)&(dbuf[4 + service_provider_name_length + 1]), service_name_length, 1, 1); - eventServer->sendEvent(CZapitClient::EVT_SCAN_PROVIDER, CEventServer::INITID_ZAPIT, (void *) providerName.c_str(), providerName.length() + 1); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_PROVIDER, (void *) providerName.c_str(), providerName.length() + 1); #ifdef SCAN_DEBUG printf("[FST] #%04d at %04d: net %04x tp %04x sid %04x v %04x a %04x pcr %04x frq %05d type %d prov [%s] name [%s]\n", num, satellitePosition, original_network_id, transport_stream_id, service_id, video_pid, audio_pid, pcr_pid, freq, service_type, providerName.c_str(), serviceName.c_str()); #endif found_channels ++; - eventServer->sendEvent ( CZapitClient::EVT_SCAN_NUM_CHANNELS, CEventServer::INITID_ZAPIT, &found_channels, sizeof(found_channels)); + CZapit::getInstance()->SendEvent ( CZapitClient::EVT_SCAN_NUM_CHANNELS, &found_channels, sizeof(found_channels)); switch (service_type) { case ST_DIGITAL_TELEVISION_SERVICE: found_tv_chans++; - eventServer->sendEvent(CZapitClient::EVT_SCAN_FOUND_TV_CHAN, CEventServer::INITID_ZAPIT, &found_tv_chans, sizeof(found_tv_chans)); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_FOUND_TV_CHAN, &found_tv_chans, sizeof(found_tv_chans)); break; case ST_DIGITAL_RADIO_SOUND_SERVICE: found_radio_chans++; - eventServer->sendEvent(CZapitClient::EVT_SCAN_FOUND_RADIO_CHAN, CEventServer::INITID_ZAPIT, &found_radio_chans, sizeof(found_radio_chans)); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_FOUND_RADIO_CHAN, &found_radio_chans, sizeof(found_radio_chans)); break; case ST_NVOD_REFERENCE_SERVICE: case ST_NVOD_TIME_SHIFTED_SERVICE: @@ -315,35 +285,26 @@ int parse_fst(unsigned short pid, fast_scan_operator_t * op) case ST_RCS_FLS: default: found_data_chans++; - eventServer->sendEvent(CZapitClient::EVT_SCAN_FOUND_DATA_CHAN, CEventServer::INITID_ZAPIT, &found_data_chans, sizeof(found_data_chans)); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_FOUND_DATA_CHAN, &found_data_chans, sizeof(found_data_chans)); break; } - eventServer->sendEvent(CZapitClient::EVT_SCAN_SERVICENAME, CEventServer::INITID_ZAPIT, (void *) serviceName.c_str(), serviceName.length() + 1); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SERVICENAME, (void *) serviceName.c_str(), serviceName.length() + 1); channel_id = CREATE_CHANNEL_ID64; CZapitChannel * newchannel; - tallchans_iterator I = allchans.find(channel_id); - if (I != allchans.end()) { - newchannel = &I->second; - - } else { - pair::iterator,bool> ret; - ret = allchans.insert ( - std::pair ( - channel_id, - CZapitChannel ( - serviceName, - service_id, - transport_stream_id, - original_network_id, - service_type, - satellitePosition, - freq - ) - ) + newchannel = CServiceManager::getInstance()->FindChannel(channel_id); + if(newchannel == NULL) { + newchannel = new CZapitChannel ( + serviceName, + service_id, + transport_stream_id, + original_network_id, + service_type, + satellitePosition, + freq ); - newchannel = &ret.first->second; + CServiceManager::getInstance()->AddChannel(newchannel); } newchannel->setName(serviceName); newchannel->setServiceType(service_type); @@ -390,17 +351,14 @@ int parse_fst(unsigned short pid, fast_scan_operator_t * op) delete dmx; bouquetId = g_bouquetManager->existsUBouquet(op->name); - if (bouquetId >= 0) { - bouquet = g_bouquetManager->Bouquets[bouquetId]; - sort(bouquet->tvChannels.begin(), bouquet->tvChannels.end(), CmpChannelByNum()); - sort(bouquet->radioChannels.begin(), bouquet->radioChannels.end(), CmpChannelByNum()); - } + if (bouquetId >= 0) + g_bouquetManager->Bouquets[bouquetId]->sortBouquetByNumber(); printf("[FST] done\n\n"); - return 0; + return true; } -int parse_fnt(unsigned short pid, unsigned short operator_id) +bool CServiceScan::ParseFnt(unsigned short pid, unsigned short operator_id) { int ret = 0; int secdone[255]; @@ -533,10 +491,10 @@ int parse_fnt(unsigned short pid, unsigned short operator_id) ); } found_transponders++; - //eventServer->sendEvent(CZapitClient::EVT_SCAN_NUM_TRANSPONDERS, CEventServer::INITID_ZAPIT, + //CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_NUM_TRANSPONDERS, // &found_transponders, sizeof(found_transponders)); uint32_t actual_freq = freq; - eventServer->sendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCY,CEventServer::INITID_ZAPIT, + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCY, &actual_freq, sizeof(actual_freq)); //satellite_delivery_system_descriptor(buffer + pos2, transport_stream_id, original_network_id, satellitePosition, freq); } @@ -565,7 +523,7 @@ int parse_fnt(unsigned short pid, unsigned short operator_id) if(fIt->second == 0) fIt->second = freq; } - eventServer->sendEvent(CZapitClient::EVT_SCAN_NUM_TRANSPONDERS, CEventServer::INITID_ZAPIT, + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_NUM_TRANSPONDERS, &found_transponders, sizeof(found_transponders)); } while(sectotal < buffer[7]); @@ -575,7 +533,7 @@ int parse_fnt(unsigned short pid, unsigned short operator_id) return ret; } -void process_logical_service_descriptor(const unsigned char * const buffer, const t_transport_stream_id transport_stream_id, const t_original_network_id original_network_id, t_satellite_position satellitePosition, freq_id_t freq) +void CServiceScan::process_logical_service_descriptor(const unsigned char * const buffer, const t_transport_stream_id transport_stream_id, const t_original_network_id original_network_id, t_satellite_position satellitePosition, freq_id_t freq) { for (int i = 0; i < buffer[1]; i += 4) { t_service_id service_id = buffer[i + 2] << 8 | buffer[i + 3]; @@ -585,7 +543,7 @@ void process_logical_service_descriptor(const unsigned char * const buffer, cons } } -void process_service_list_descriptor(const unsigned char * const buffer, const t_transport_stream_id transport_stream_id, const t_original_network_id original_network_id, t_satellite_position satellitePosition, freq_id_t freq) +void CServiceScan::process_service_list_descriptor(const unsigned char * const buffer, const t_transport_stream_id transport_stream_id, const t_original_network_id original_network_id, t_satellite_position satellitePosition, freq_id_t freq) { for (int i = 0; i < buffer[1]; i += 3) { t_service_id service_id = buffer[i + 2] << 8 | buffer[i + 3]; @@ -600,7 +558,7 @@ void process_service_list_descriptor(const unsigned char * const buffer, const t } } -int process_satellite_delivery_system_descriptor(const unsigned char * const buffer, FrontendParameters * feparams, uint8_t * polarization, t_satellite_position * satellitePosition) +void CServiceScan::process_satellite_delivery_system_descriptor(const unsigned char * const buffer, FrontendParameters * feparams, uint8_t * polarization, t_satellite_position * satellitePosition) { stiterator tI; int modulationSystem, modulationType, rollOff, fec_inner; @@ -657,6 +615,4 @@ int process_satellite_delivery_system_descriptor(const unsigned char * const buf #ifdef SCAN_DEBUG printf("[FNT] new TP: sat %d freq %d SR %d fec %d pol %d\n", *satellitePosition, feparams->frequency, feparams->u.qpsk.symbol_rate, fec_inner, * polarization); #endif - - return 0; } diff --git a/src/zapit/src/scan.cpp b/src/zapit/src/scan.cpp index b5d5e7d0a..67e4f0ccf 100644 --- a/src/zapit/src/scan.cpp +++ b/src/zapit/src/scan.cpp @@ -24,10 +24,6 @@ #include #include -/* libevent */ -#include - -#include #include #include #include @@ -37,64 +33,107 @@ #include #include #include +#include #include +#define NIT_THREAD + extern CBouquetManager *g_bouquetManager; extern transponder_list_t transponders; // defined in zapit.cpp -extern tallchans allchans; // defined in zapit.cpp -extern int found_transponders; -extern int found_channels; -extern std::map service_types; -extern uint32_t found_tv_chans; -extern uint32_t found_radio_chans; -extern uint32_t found_data_chans; extern t_channel_id live_channel_id; extern CZapitClient::bouquetMode bouquetMode; -extern CEventServer *eventServer; -extern diseqc_t diseqcType; -extern int useGotoXX; extern int motorRotationSpeed; -extern xmlDocPtr scanInputParser; -void SaveServices(bool tocopy); -int zapit(const t_channel_id channel_id, bool in_nvod, bool forupdate = 0, bool nowait = 0); void *nit_thread(void * data); -static int prov_found; -static bool cable = false; -short abort_scan; -short scan_runs; -short curr_sat; -static int status = 0; -uint32_t processed_transponders; -uint32_t failed_transponders; -uint32_t actual_freq; -uint32_t actual_polarisation; -int scan_mode = 0; /* 0 = NIT, 1 = fast */ -int scan_sat_mode = 0; +//int scan_mode = 0; /* 0 = NIT, 1 = fast */ + CBouquetManager* scanBouquetManager; -std::map scantransponders;// TP list to scan -std::map scanedtransponders;// global TP list for current scan -std::map nittransponders; +CServiceScan * CServiceScan::scan = NULL; -#define TIMER_START() \ - static struct timeval tv, tv2; \ - static unsigned int msec; \ - gettimeofday(&tv, NULL) +CServiceScan * CServiceScan::getInstance() +{ + if(scan == NULL) + scan = new CServiceScan(); + return scan; +} -#define TIMER_STOP(label) \ - gettimeofday(&tv2, NULL); \ - msec = tv2.tv_sec - tv.tv_sec; \ - printf("%s: %d sec\n", label, msec) +CServiceScan::CServiceScan() +{ + started = false; + scan_nit = false; + running = false; +} -bool tuneFrequency(FrontendParameters *feparams, uint8_t polarization, t_satellite_position satellitePosition) +CServiceScan::~CServiceScan() +{ +} + +bool CServiceScan::Start(scan_type_t mode, void * arg) +{ + if(started) + return false; + + scan_mode = mode; + scan_arg = arg; + abort_scan = false; + + started = true; + int ret = start(); + return (ret == 0); +} + +bool CServiceScan::Stop() +{ + if(!started) + return false; + + started = false; + int ret = join(); + return (ret == 0); +} + +void CServiceScan::run() +{ + running = true; + + scantransponders.clear(); + scanedtransponders.clear(); + nittransponders.clear(); + service_types.clear(); + + found_transponders = 0; + processed_transponders = 0; + found_channels = 0; + found_tv_chans = 0; + found_radio_chans = 0; + found_data_chans = 0; + failed_transponders = 0; + fake_tid = fake_nid = 0; + + switch(scan_mode) { + case SCAN_PROVIDER: + ScanProviders(); + break; + case SCAN_TRANSPONDER: + ScanTransponder(); + break; + case SCAN_FAST: + ScanFast(); + break; + default: + break; + } +} + +bool CServiceScan::tuneFrequency(FrontendParameters *feparams, uint8_t polarization, t_satellite_position satellitePosition) { CFrontend::getInstance()->setInput(satellitePosition, feparams->frequency, polarization); int ret = CFrontend::getInstance()->driveToSatellitePosition(satellitePosition, false); //true); if(ret > 0) { printf("[scan] waiting %d seconds for motor to turn satellite dish.\n", ret); - eventServer->sendEvent(CZapitClient::EVT_SCAN_PROVIDER, CEventServer::INITID_ZAPIT, (void *) "moving rotor", 13); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_PROVIDER, (void *) "moving rotor", 13); for(int i = 0; i < ret; i++) { sleep(1); if(abort_scan) @@ -104,10 +143,10 @@ bool tuneFrequency(FrontendParameters *feparams, uint8_t polarization, t_satelli return CFrontend::getInstance()->tuneFrequency(feparams, polarization, false); } -int add_to_scan(transponder_id_t TsidOnid, FrontendParameters *feparams, uint8_t polarity, bool fromnit = 0) +bool CServiceScan::AddTransponder(transponder_id_t TsidOnid, FrontendParameters *feparams, uint8_t polarity, bool fromnit) { - DBG("add_to_scan: freq %d pol %d tpid %llx\n", feparams->frequency, polarity, TsidOnid); -//if(fromnit) printf("add_to_scan: freq %d pol %d tpid %llx\n", feparams->frequency, polarity, TsidOnid); + DBG("AddTransponder: freq %d pol %d tpid %llx\n", feparams->frequency, polarity, TsidOnid); +//if(fromnit) printf("AddTransponder: freq %d pol %d tpid %llx\n", feparams->frequency, polarity, TsidOnid); freq_id_t freq; if(cable) freq = feparams->frequency/100; @@ -128,6 +167,7 @@ int add_to_scan(transponder_id_t TsidOnid, FrontendParameters *feparams, uint8_t t_transport_stream_id transport_stream_id = tI->second.transport_stream_id; t_original_network_id original_network_id = tI->second.original_network_id; uint16_t freq1 = GET_FREQ_FROM_TPID(tI->first); + //FIXME simplify/change GET_SATELLITEPOSITION_FROM_TRANSPONDER_ID t_satellite_position satellitePosition = GET_SATELLITEPOSITION_FROM_TRANSPONDER_ID(tI->first) & 0xFFF; if(GET_SATELLITEPOSITION_FROM_TRANSPONDER_ID(tI->first) & 0xF000) satellitePosition = -satellitePosition; @@ -135,7 +175,7 @@ int add_to_scan(transponder_id_t TsidOnid, FrontendParameters *feparams, uint8_t freq1++; TsidOnid = CREATE_TRANSPONDER_ID_FROM_SATELLITEPOSITION_ORIGINALNETWORK_TRANSPORTSTREAM_ID( freq1, satellitePosition, original_network_id, transport_stream_id); - printf("[scan] add_to_scan: SAME freq %d pol1 %d pol2 %d tpid %llx\n", feparams->frequency, poltmp1, poltmp2, TsidOnid); + printf("[scan] AddTransponder: SAME freq %d pol1 %d pol2 %d tpid %llx\n", feparams->frequency, poltmp1, poltmp2, TsidOnid); feparams->frequency = feparams->frequency+1000; tI = scanedtransponders.find(TsidOnid); } @@ -169,39 +209,18 @@ int add_to_scan(transponder_id_t TsidOnid, FrontendParameters *feparams, uint8_t TsidOnid, transponder ( (TsidOnid >> 16) &0xFFFF, TsidOnid &0xFFFF, *feparams, polarity))); } - return 0; + return true; } else tI->second.feparams.u.qpsk.fec_inner = feparams->u.qpsk.fec_inner; - return 1; + + return false; } -static uint32_t fake_tid, fake_nid; -int build_bf_transponder(FrontendParameters *feparams, t_satellite_position satellitePosition) -{ -DBG("[scan] freq= %d, rate= %d, position %d\n", feparams->frequency, feparams->u.qam.symbol_rate, satellitePosition); - freq_id_t freq; - if(cable) - freq = feparams->frequency/100; - else - freq = feparams->frequency/1000; - - if(scan_mode) { - fake_tid++; fake_nid++; - return add_to_scan( - CREATE_TRANSPONDER_ID_FROM_SATELLITEPOSITION_ORIGINALNETWORK_TRANSPORTSTREAM_ID(freq /*feparams->frequency/1000*/, satellitePosition, fake_nid, fake_tid), - feparams, 0); - } else { - if (!tuneFrequency(feparams, 0, 0)) - return -1; - - return add_to_scan(get_sdt_TsidOnid(satellitePosition, freq /*0, feparams->frequency/1000*/), feparams, 0); - } -} - -#define NIT_THREAD -int get_sdts(t_satellite_position satellitePosition) +bool CServiceScan::ReadNitSdt(t_satellite_position satellitePosition) { + uint32_t actual_freq; + uint32_t actual_polarisation; transponder_id_t TsidOnid = 0; stiterator tI; stiterator stI; @@ -211,13 +230,8 @@ int get_sdts(t_satellite_position satellitePosition) _repeat: for (tI = scantransponders.begin(); tI != scantransponders.end(); tI++) { if(abort_scan) - return 0; + return false; -#if 0 - sT = scanedtransponders.find(tI->first); - if(sT != scanedtransponders.end()) - continue; -#endif printf("[scan] scanning: %llx\n", tI->first); if(cable) @@ -226,14 +240,14 @@ _repeat: actual_freq = tI->second.feparams.frequency/1000; processed_transponders++; - eventServer->sendEvent(CZapitClient::EVT_SCAN_REPORT_NUM_SCANNED_TRANSPONDERS, CEventServer::INITID_ZAPIT, &processed_transponders, sizeof(processed_transponders)); - eventServer->sendEvent(CZapitClient::EVT_SCAN_PROVIDER, CEventServer::INITID_ZAPIT, (void *) " ", 2); - eventServer->sendEvent(CZapitClient::EVT_SCAN_SERVICENAME, CEventServer::INITID_ZAPIT, (void *) " ", 2); - eventServer->sendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCY,CEventServer::INITID_ZAPIT, &actual_freq,sizeof(actual_freq)); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_NUM_SCANNED_TRANSPONDERS, &processed_transponders, sizeof(processed_transponders)); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_PROVIDER, (void *) " ", 2); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SERVICENAME, (void *) " ", 2); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCY, &actual_freq,sizeof(actual_freq)); if (!cable) { actual_polarisation = ((tI->second.feparams.u.qpsk.symbol_rate/1000) << 16) | (tI->second.feparams.u.qpsk.fec_inner << 8) | (uint)tI->second.polarization; - eventServer->sendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCYP,CEventServer::INITID_ZAPIT,&actual_polarisation,sizeof(actual_polarisation)); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_FREQUENCYP, &actual_polarisation,sizeof(actual_polarisation)); } if (!tuneFrequency(&(tI->second.feparams), tI->second.polarization, satellitePosition)) { @@ -241,25 +255,11 @@ _repeat: continue; } if(abort_scan) - return 0; - -#if 0 - if(scan_mode) { - TsidOnid = get_sdt_TsidOnid(satellitePosition, tI->second.feparams.frequency/1000); - DBG("[scan] actual tp-id %llx\n", TsidOnid); - if(!TsidOnid) - continue; - - tI->second.transport_stream_id = (TsidOnid >> 16)&0xFFFF; - tI->second.original_network_id = TsidOnid &0xFFFF; - } -#endif - if(abort_scan) - return 0; + return false; #ifdef NIT_THREAD pthread_t nthread; - if(!scan_mode) + if(scan_nit) if(pthread_create(&nthread, 0, nit_thread, (void*)satellitePosition)) { ERROR("pthread_create"); nthread = 0; @@ -271,7 +271,7 @@ _repeat: else freq = tI->second.feparams.frequency/1000; //INFO("parsing SDT (tsid:onid %04x:%04x)", tI->second.transport_stream_id, tI->second.original_network_id); - status = parse_sdt(&tI->second.transport_stream_id, &tI->second.original_network_id, satellitePosition, freq /*tI->second.feparams.frequency/1000*/); + int status = parse_sdt(&tI->second.transport_stream_id, &tI->second.original_network_id, satellitePosition, freq /*tI->second.feparams.frequency/1000*/); if(status < 0) { printf("[scan] SDT failed !\n"); continue; @@ -300,39 +300,39 @@ _repeat: stI->second.feparams.u.qpsk.fec_inner = tI->second.feparams.u.qpsk.fec_inner; #ifdef NIT_THREAD - if(!scan_mode && nthread) { + if(scan_nit && nthread) { if(pthread_join(nthread, NULL)) perror("pthread_join !!!!!!!!!"); } #else - if(!scan_mode) { + if(scan_nit) { printf("[scan] trying to parse NIT\n"); - status = parse_nit(satellitePosition, freq /*tI->second.feparams.frequency/1000*/); + int status = parse_nit(satellitePosition, freq /*tI->second.feparams.frequency/1000*/); if(status < 0) printf("[scan] NIT failed !\n"); } #endif printf("[scan] tpid ready: %llx\n", TsidOnid); } - if(!scan_mode) { + if(scan_nit) { printf("[scan] found %d transponders (%d failed) and %d channels\n", found_transponders, failed_transponders, found_channels); scantransponders.clear(); for (tI = nittransponders.begin(); tI != nittransponders.end(); tI++) { -//int add_to_scan(transponder_id_t TsidOnid, FrontendParameters *feparams, uint8_t polarity, bool fromnit = 0) - add_to_scan(tI->first, &tI->second.feparams, tI->second.polarization, false); +//int AddTransponder(transponder_id_t TsidOnid, FrontendParameters *feparams, uint8_t polarity, bool fromnit = 0) + AddTransponder(tI->first, &tI->second.feparams, tI->second.polarization, false); } nittransponders.clear(); printf("\n\n[scan] found %d additional transponders from nit\n", scantransponders.size()); if(scantransponders.size()) { - eventServer->sendEvent ( CZapitClient::EVT_SCAN_NUM_TRANSPONDERS, CEventServer::INITID_ZAPIT, + CZapit::getInstance()->SendEvent ( CZapitClient::EVT_SCAN_NUM_TRANSPONDERS, &found_transponders, sizeof(found_transponders)); goto _repeat; } } - return 0; + return true; } -int scan_transponder(xmlNodePtr transponder, uint8_t diseqc_pos, t_satellite_position satellitePosition, bool /*satfeed*/) +bool CServiceScan::AddTransponder(xmlNodePtr transponder, uint8_t diseqc_pos, t_satellite_position satellitePosition) { uint8_t polarization = 0; uint8_t system = 0, modulation = 1; @@ -343,15 +343,15 @@ int scan_transponder(xmlNodePtr transponder, uint8_t diseqc_pos, t_satellite_pos feparams.frequency = xmlGetNumericAttribute(transponder, "frequency", 0); freq_id_t freq; - if(cable) { - if (feparams.frequency > 1000*1000) - feparams.frequency = feparams.frequency/1000; //transponderlist was read from tuxbox - //feparams.frequency = (int) 1000 * (int) round ((double) feparams.frequency / (double) 1000); - freq = feparams.frequency/100; - } - else { + if(cable) { + if (feparams.frequency > 1000*1000) + feparams.frequency = feparams.frequency/1000; //transponderlist was read from tuxbox + //feparams.frequency = (int) 1000 * (int) round ((double) feparams.frequency / (double) 1000); + freq = feparams.frequency/100; + } + else { feparams.frequency = (int) 1000 * (int) round ((double) feparams.frequency / (double) 1000); - freq = feparams.frequency/1000; + freq = feparams.frequency/1000; } feparams.inversion = INVERSION_AUTO; @@ -373,23 +373,38 @@ int scan_transponder(xmlNodePtr transponder, uint8_t diseqc_pos, t_satellite_pos xml_fec += 9; feparams.u.qpsk.fec_inner = (fe_code_rate_t) xml_fec; } -#if 0 - if (cable && satfeed) { - /* build special transponder for cable with satfeed */ - status = build_bf_transponder(&feparams, satellitePosition); - } else -#endif - { - /* read network information table */ - fake_tid++; fake_nid++; - status = add_to_scan( + /* read network information table */ + fake_tid++; fake_nid++; + AddTransponder( CREATE_TRANSPONDER_ID_FROM_SATELLITEPOSITION_ORIGINALNETWORK_TRANSPORTSTREAM_ID(freq /*feparams.frequency/1000*/, satellitePosition, fake_nid, fake_tid), &feparams, polarization); - } - return 0; + return true; } -void scan_provider(xmlNodePtr search, t_satellite_position satellitePosition, uint8_t diseqc_pos, bool satfeed) +void CServiceScan::FixServiceTypes() +{ + std::map ::iterator stI; + for (stI = service_types.begin(); stI != service_types.end(); stI++) { + CZapitChannel * channel = CServiceManager::getInstance()->FindChannel(stI->first); + if (channel) { + if (channel->getServiceType() != stI->second) { + switch (channel->getServiceType()) { + case ST_DIGITAL_TELEVISION_SERVICE: + case ST_DIGITAL_RADIO_SOUND_SERVICE: + case ST_NVOD_REFERENCE_SERVICE: + case ST_NVOD_TIME_SHIFTED_SERVICE: + break; + default: + INFO("setting service_type of channel_id " PRINTF_CHANNEL_ID_TYPE " %s from %02x to %02x", stI->first, channel->getName().c_str(), channel->getServiceType(), stI->second); + channel->setServiceType(stI->second); + break; + } + } + } + } +} + +bool CServiceScan::ScanProvider(xmlNodePtr search, t_satellite_position satellitePosition, uint8_t diseqc_pos) { xmlNodePtr tps = NULL; transponder_list_t::iterator tI; @@ -400,98 +415,73 @@ void scan_provider(xmlNodePtr search, t_satellite_position satellitePosition, ui sat_iterator_t sit = satellitePositions.find(satellitePosition); if(sit == satellitePositions.end()) { printf("[zapit] WARNING satellite position %d not found!\n", satellitePosition); - return; + return false; } - eventServer->sendEvent(CZapitClient::EVT_SCAN_REPORT_NUM_SCANNED_TRANSPONDERS, CEventServer::INITID_ZAPIT, &processed_transponders, sizeof(processed_transponders)); - eventServer->sendEvent(CZapitClient::EVT_SCAN_SATELLITE, CEventServer::INITID_ZAPIT, sit->second.name.c_str(), sit->second.name.size() + 1); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_REPORT_NUM_SCANNED_TRANSPONDERS, &processed_transponders, sizeof(processed_transponders)); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SATELLITE, sit->second.name.c_str(), sit->second.name.size() + 1); tps = search->xmlChildrenNode; /* TPs from current service list */ for(tI = transponders.begin(); tI != transponders.end(); tI++) { if(abort_scan) - return; + return false; t_satellite_position satpos = GET_SATELLITEPOSITION_FROM_TRANSPONDER_ID(tI->first) & 0xFFF; if(GET_SATELLITEPOSITION_FROM_TRANSPONDER_ID(tI->first) & 0xF000) satpos = -satpos; if(satpos != satellitePosition) continue; - add_to_scan(tI->first, &tI->second.feparams, tI->second.polarization); + AddTransponder(tI->first, &tI->second.feparams, tI->second.polarization); } /* read all transponders */ while ((tps = xmlGetNextOccurence(tps, "transponder")) != NULL) { if(abort_scan) - return; - scan_transponder(tps, diseqc_pos, satellitePosition, satfeed); + return false; + AddTransponder(tps, diseqc_pos, satellitePosition); /* next transponder */ tps = tps->xmlNextNode; } - eventServer->sendEvent ( CZapitClient::EVT_SCAN_NUM_TRANSPONDERS, CEventServer::INITID_ZAPIT, + CZapit::getInstance()->SendEvent ( CZapitClient::EVT_SCAN_NUM_TRANSPONDERS, &found_transponders, sizeof(found_transponders)); - status = get_sdts(satellitePosition); + ReadNitSdt(satellitePosition); /* channels from PAT do not have service_type set. * some channels set the service_type in the BAT or the NIT. * should the NIT be parsed on every transponder? */ - std::map ::iterator stI; - for (stI = service_types.begin(); stI != service_types.end(); stI++) { - tallchans_iterator scI = allchans.find(stI->first); + FixServiceTypes(); - if (scI != allchans.end()) { - if (scI->second.getServiceType() != stI->second) { - switch (scI->second.getServiceType()) { - case ST_DIGITAL_TELEVISION_SERVICE: - case ST_DIGITAL_RADIO_SOUND_SERVICE: - case ST_NVOD_REFERENCE_SERVICE: - case ST_NVOD_TIME_SHIFTED_SERVICE: - break; - default: - INFO("setting service_type of channel_id " PRINTF_CHANNEL_ID_TYPE " from %02x to %02x", stI->first, scI->second.getServiceType(), stI->second); - DBG("setting service_type of channel_id " PRINTF_CHANNEL_ID_TYPE " %s from %02x to %02x", stI->first, scI->second.getName().c_str(), scI->second.getServiceType(), stI->second); - scI->second.setServiceType(stI->second); - break; - } - } - } - } - TIMER_STOP("[scan] scanning took"); + TIMER_STOP_SEC("[scan] scanning took"); + return true; } -void stop_scan(const bool success) +void CServiceScan::Cleanup(const bool success) { + running = false; /* notify client about end of scan */ - scan_runs = 0; - eventServer->sendEvent(success ? CZapitClient::EVT_SCAN_COMPLETE : CZapitClient::EVT_SCAN_FAILED, CEventServer::INITID_ZAPIT); + CZapit::getInstance()->SendEvent(success ? CZapitClient::EVT_SCAN_COMPLETE : CZapitClient::EVT_SCAN_FAILED); if (scanBouquetManager) { scanBouquetManager->clearAll(); delete scanBouquetManager; scanBouquetManager = NULL; } + scantransponders.clear(); + scanedtransponders.clear(); + nittransponders.clear(); + service_types.clear(); } -void *start_scanthread(void *scanmode) +bool CServiceScan::ScanProviders() { scan_list_iterator_t spI; char providerName[80] = ""; const char *frontendType; uint8_t diseqc_pos = 0; scanBouquetManager = new CBouquetManager(); - processed_transponders = 0; - failed_transponders = 0; - found_transponders = 0; - found_tv_chans = 0; - found_radio_chans = 0; - found_data_chans = 0; - found_channels = 0; bool satfeed = false; - int mode = (int) scanmode; - abort_scan = 0; + int mode = (int) scan_arg; curr_sat = 0; - scantransponders.clear(); - scanedtransponders.clear(); - nittransponders.clear(); cable = (CFrontend::getInstance()->getInfo()->type == FE_QAM); if (cable) @@ -499,15 +489,15 @@ void *start_scanthread(void *scanmode) else frontendType = "sat"; - scan_mode = mode & 0xFF;// NIT (0) or fast (1) - scan_sat_mode = mode & 0xFF00; // single = 0, all = 1 + scan_nit = (mode & 0xFF) == 0; // NIT (0) or fast (1) + int scan_sat_mode = mode & 0xFF00; // single = 0, all = 1 - printf("[zapit] scan mode %s, satellites %s\n", scan_mode ? "fast" : "NIT", scan_sat_mode ? "all" : "single"); + printf("[zapit] scan mode %s, satellites %s\n", scan_nit ? "fast" : "NIT", scan_sat_mode ? "all" : "single"); CZapitClient myZapitClient; - fake_tid = fake_nid = 0; /* get first child */ - xmlNodePtr search = xmlDocGetRootElement(scanInputParser)->xmlChildrenNode; + //xmlNodePtr search = xmlDocGetRootElement(scanInputParser)->xmlChildrenNode; + xmlNodePtr search = xmlDocGetRootElement(CServiceManager::getInstance()->ScanXml())->xmlChildrenNode; /* read all sat or cable sections */ while ((search = xmlGetNextOccurence(search, frontendType)) != NULL) { @@ -545,7 +535,7 @@ void *start_scanthread(void *scanmode) nittransponders.clear(); printf("[scan] scanning %s at %d bouquetMode %d\n", providerName, position, bouquetMode); - scan_provider(search, position, diseqc_pos, satfeed); + ScanProvider(search, position, diseqc_pos); if(abort_scan) { found_channels = 0; break; @@ -564,109 +554,121 @@ void *start_scanthread(void *scanmode) printf("[scan] found %d transponders (%d failed) and %d channels\n", found_transponders, failed_transponders, found_channels); if (found_channels) { - SaveServices(true); + CServiceManager::getInstance()->SaveServices(true); printf("[scan] save services done\n"); fflush(stdout); g_bouquetManager->saveBouquets(); //g_bouquetManager->sortBouquets(); //g_bouquetManager->renumServices(); - g_bouquetManager->clearAll(); + //g_bouquetManager->clearAll(); g_bouquetManager->loadBouquets(); printf("[scan] save bouquets done\n"); - stop_scan(true); + Cleanup(true); myZapitClient.reloadCurrentServices(); } else { - stop_scan(false); + Cleanup(false); CFrontend::getInstance()->setTsidOnid(0); - zapit(live_channel_id, 0); + CZapit::getInstance()->ZapIt(live_channel_id, false); } - scantransponders.clear(); - scanedtransponders.clear(); - nittransponders.clear(); - - pthread_exit(0); + return (found_channels != 0); } -void * scan_transponder(void * arg) +bool CServiceScan::ScanTransponder() { - TP_params *TP = (TP_params *) arg; + TP_params *TP = (TP_params *) scan_arg; char providerName[32] = ""; t_satellite_position satellitePosition = 0; - prov_found = 0; - found_transponders = 0; - found_channels = 0; - processed_transponders = 0; - found_tv_chans = 0; - found_radio_chans = 0; - found_data_chans = 0; - fake_tid = fake_nid = 0; scanBouquetManager = new CBouquetManager(); - scantransponders.clear(); - scanedtransponders.clear(); - nittransponders.clear(); + cable = (CFrontend::getInstance()->getInfo()->type == FE_QAM); strcpy(providerName, scanProviders.size() > 0 ? scanProviders.begin()->second.c_str() : "unknown provider"); satellitePosition = scanProviders.begin()->first; printf("[scan_transponder] scanning sat %s position %d\n", providerName, satellitePosition); - eventServer->sendEvent(CZapitClient::EVT_SCAN_SATELLITE, CEventServer::INITID_ZAPIT, providerName, strlen(providerName) + 1); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SATELLITE, providerName, strlen(providerName) + 1); + + scan_nit = TP->scan_mode; - scan_mode = TP->scan_mode; TP->feparams.inversion = INVERSION_AUTO; if (!cable) { - printf("[scan_transponder] freq %d rate %d fec %d pol %d NIT %s\n", TP->feparams.frequency, TP->feparams.u.qpsk.symbol_rate, TP->feparams.u.qpsk.fec_inner, TP->polarization, scan_mode ? "no" : "yes"); + printf("[scan_transponder] freq %d rate %d fec %d pol %d NIT %s\n", TP->feparams.frequency, TP->feparams.u.qpsk.symbol_rate, TP->feparams.u.qpsk.fec_inner, TP->polarization, scan_nit ? "no" : "yes"); } else printf("[scan_transponder] freq %d rate %d fec %d mod %d\n", TP->feparams.frequency, TP->feparams.u.qam.symbol_rate, TP->feparams.u.qam.fec_inner, TP->feparams.u.qam.modulation); -#if 0 - if (cable) { - /* build special transponder for cable with satfeed */ - build_bf_transponder(&(TP->feparams), satellitePosition); - } else -#endif - { - freq_id_t freq; - if(cable) - freq = TP->feparams.frequency/100; - else - freq = TP->feparams.frequency/1000; - /* read network information table */ - fake_tid++; fake_nid++; - status = add_to_scan( - CREATE_TRANSPONDER_ID_FROM_SATELLITEPOSITION_ORIGINALNETWORK_TRANSPORTSTREAM_ID(freq /*TP->feparams.frequency/1000*/, satellitePosition, fake_nid, fake_tid), + + freq_id_t freq; + if(cable) + freq = TP->feparams.frequency/100; + else + freq = TP->feparams.frequency/1000; + /* read network information table */ + fake_tid++; fake_nid++; + AddTransponder( + CREATE_TRANSPONDER_ID_FROM_SATELLITEPOSITION_ORIGINALNETWORK_TRANSPORTSTREAM_ID(freq, satellitePosition, fake_nid, fake_tid), &TP->feparams, TP->polarization); - } - get_sdts(satellitePosition); + ReadNitSdt(satellitePosition); if(abort_scan) found_channels = 0; CZapitClient myZapitClient; if(found_channels) { - SaveServices(true); + CServiceManager::getInstance()->SaveServices(true); scanBouquetManager->saveBouquets(bouquetMode, providerName); - g_bouquetManager->saveBouquets(); - //g_bouquetManager->sortBouquets(); - //g_bouquetManager->renumServices(); - g_bouquetManager->clearAll(); + g_bouquetManager->saveBouquets(); + //g_bouquetManager->sortBouquets(); + //g_bouquetManager->renumServices(); + //g_bouquetManager->clearAll(); g_bouquetManager->loadBouquets(); - stop_scan(true); + Cleanup(true); myZapitClient.reloadCurrentServices(); } else { - stop_scan(false); + Cleanup(false); CFrontend::getInstance()->setTsidOnid(0); - zapit(live_channel_id, 0); + CZapit::getInstance()->ZapIt(live_channel_id, false); } - scantransponders.clear(); - scanedtransponders.clear(); - nittransponders.clear(); if(cable) DBG("[scan_transponder] done scan freq %d rate %d fec %d mod %d\n", TP->feparams.frequency, TP->feparams.u.qam.symbol_rate, TP->feparams.u.qam.fec_inner,TP->feparams.u.qam.modulation); else DBG("[scan_transponder] done scan freq %d rate %d fec %d pol %d\n", TP->feparams.frequency, TP->feparams.u.qpsk.symbol_rate, TP->feparams.u.qpsk.fec_inner, TP->polarization); - - pthread_exit(0); + return (found_channels != 0); +} + +void CServiceScan::ChannelFound(uint8_t service_type, std::string providerName, std::string serviceName) +{ + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_PROVIDER, (void *) providerName.c_str(), providerName.length() + 1); + + found_channels++; + CZapit::getInstance()->SendEvent( CZapitClient::EVT_SCAN_NUM_CHANNELS, &found_channels, sizeof(found_channels)); + + switch (service_type) { + case ST_DIGITAL_TELEVISION_SERVICE: + found_tv_chans++; + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_FOUND_TV_CHAN, &found_tv_chans, sizeof(found_tv_chans)); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SERVICENAME, (void *) serviceName.c_str(), serviceName.length() + 1); + break; + case ST_DIGITAL_RADIO_SOUND_SERVICE: + found_radio_chans++; + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_FOUND_RADIO_CHAN, &found_radio_chans, sizeof(found_radio_chans)); + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SERVICENAME, (void *) serviceName.c_str(), serviceName.length() + 1); + break; + case ST_NVOD_REFERENCE_SERVICE: + case ST_NVOD_TIME_SHIFTED_SERVICE: + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_SERVICENAME, (void *) serviceName.c_str(), serviceName.length() + 1); + case ST_DATA_BROADCAST_SERVICE: + case ST_RCS_MAP: + case ST_RCS_FLS: + default: + found_data_chans++; + CZapit::getInstance()->SendEvent(CZapitClient::EVT_SCAN_FOUND_DATA_CHAN, &found_data_chans, sizeof(found_data_chans)); + break; + } +} + +void CServiceScan::AddServiceType(t_channel_id channel_id, uint8_t service_type) +{ + service_types[channel_id] = service_type; }