From 7b4a536f62d4658c1f14a186a0719e1244f1e3fa Mon Sep 17 00:00:00 2001 From: TangoCash Date: Wed, 22 Sep 2021 21:07:08 +0200 Subject: [PATCH] add ait scan (hbbtvurls) to /tmp/ait.txt for now --- src/zapit/include/zapit/channel.h | 3 + src/zapit/include/zapit/scanait.h | 61 ++++++++ src/zapit/src/Makefile.am | 1 + src/zapit/src/channel.cpp | 1 + src/zapit/src/scanait.cpp | 239 ++++++++++++++++++++++++++++++ src/zapit/src/scanpmt.cpp | 16 ++ src/zapit/src/zapit.cpp | 6 + 7 files changed, 327 insertions(+) create mode 100644 src/zapit/include/zapit/scanait.h create mode 100644 src/zapit/src/scanait.cpp diff --git a/src/zapit/include/zapit/channel.h b/src/zapit/include/zapit/channel.h index 65ece9c45..3a280295e 100644 --- a/src/zapit/include/zapit/channel.h +++ b/src/zapit/include/zapit/channel.h @@ -142,6 +142,7 @@ class CZapitChannel unsigned short pcrPid; unsigned short pmtPid; + unsigned short aitPid; unsigned short teletextPid; unsigned short videoPid; unsigned short audioPid; @@ -243,6 +244,7 @@ class CZapitChannel unsigned char getAudioChannelCount(void) { return (unsigned char) audioChannels.size(); } unsigned short getPcrPid(void) { return pcrPid; } unsigned short getPmtPid(void) { return pmtPid; } + unsigned short getAitPid(void) { return aitPid; } unsigned short getTeletextPid(void) { return teletextPid; } const char * getTeletextLang(void) { return ttx_language_code.c_str(); } unsigned short getVideoPid(void) { return videoPid; } @@ -266,6 +268,7 @@ class CZapitChannel void setAudioChannel(unsigned char pAudioChannel) { if (pAudioChannel < audioChannels.size()) currentAudioChannel = pAudioChannel; } void setPcrPid(unsigned short pPcrPid) { pcrPid = pPcrPid; } void setPmtPid(unsigned short pPmtPid) { pmtPid = pPmtPid; } + void setAitPid(unsigned short pAitPid) { aitPid = pAitPid; } void setTeletextPid(unsigned short pTeletextPid) { teletextPid = pTeletextPid; } void setTeletextLang(std::string lang) { ttx_language_code = lang; }; void setVideoPid(unsigned short pVideoPid) { videoPid = pVideoPid; } diff --git a/src/zapit/include/zapit/scanait.h b/src/zapit/include/zapit/scanait.h new file mode 100644 index 000000000..58b8292d5 --- /dev/null +++ b/src/zapit/include/zapit/scanait.h @@ -0,0 +1,61 @@ +/* + * Neutrino-GUI - DBoxII-Project + * + * Copyright (C) 2011 CoolStream International Ltd + * + * License: GPLv2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef __zapit_scan_ait_h__ +#define __zapit_scan_ait_h__ + +#include +#include + +#include +#include +#include +#include + +#define AIT_SECTION_SIZE 4096 +#define PACK_VERSION(major,minor,micro) (((major) << 16) + ((minor) << 8) + (micro)) +#define UNPACK_VERSION(version,major,minor,micro) { \ + major = (version)&0xff; \ + minor = (version>>8)&0xff; \ + micro = (version>>16)&0xff; \ +} + +class CAit : public OpenThreads::Thread +{ +private: + int dmxnum; + unsigned short pid; + std::string name; + ApplicationInformationSectionList sections; + void run(); + bool Read(); + +public: + CAit(int dnum = 0); + ~CAit(); + bool Start(); + bool Stop(); + bool Parse(); + bool Parse(CZapitChannel * const channel); +}; + +#endif diff --git a/src/zapit/src/Makefile.am b/src/zapit/src/Makefile.am index 2e6427d32..a9848fc5e 100644 --- a/src/zapit/src/Makefile.am +++ b/src/zapit/src/Makefile.am @@ -25,6 +25,7 @@ libzapit_a_SOURCES = \ frontend.cpp \ getservices.cpp \ pat.cpp \ + scanait.cpp \ scanbat.cpp \ scan.cpp \ scannit.cpp \ diff --git a/src/zapit/src/channel.cpp b/src/zapit/src/channel.cpp index 2b35ffca5..e62e0c878 100644 --- a/src/zapit/src/channel.cpp +++ b/src/zapit/src/channel.cpp @@ -114,6 +114,7 @@ void CZapitChannel::Init() bUseCI = false; altlogo = ""; epgmapper = ""; + aitPid = 0; } CZapitChannel::~CZapitChannel(void) diff --git a/src/zapit/src/scanait.cpp b/src/zapit/src/scanait.cpp new file mode 100644 index 000000000..9291af7c5 --- /dev/null +++ b/src/zapit/src/scanait.cpp @@ -0,0 +1,239 @@ +/* + * Copyright (C) 2011 CoolStream International Ltd + * + * License: GPLv2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG_AIT +#define DEBUG_AIT_UNUSED +#define DEBUG_LCN + +CAit::CAit(int dnum) +{ + dmxnum = dnum; + pid = 0; +} + +bool CAit::Start() +{ + int ret = start(); + return (ret == 0); +} + +bool CAit::Stop() +{ + int ret = join(); + return (ret == 0); +} + +void CAit::run() +{ + set_threadname("zap:ait"); + if(Parse()) + printf("[scan] AIT finished.\n"); + else + printf("[scan] AIT failed !\n"); +} + +CAit::~CAit() +{ +} + +bool CAit::Read() +{ + bool ret = true; + + cDemux * dmx = new cDemux(dmxnum); + dmx->Open(DMX_PSI_CHANNEL); + + unsigned char buffer[AIT_SECTION_SIZE]; + + unsigned char filter[DMX_FILTER_SIZE]; + unsigned char mask[DMX_FILTER_SIZE]; + + memset(filter, 0x00, DMX_FILTER_SIZE); + memset(mask, 0x00, DMX_FILTER_SIZE); + + int flen = 1; + filter[0] = 0x74; + mask[0] = 0xFF; + + if ((!dmx->sectionFilter(pid, filter, mask, flen)) || (dmx->Read(buffer, AIT_SECTION_SIZE) < 0)) + { + printf("CAit::Read: pid %x failed\n", pid); + ret = false; + } + else + { + printf("CAit::Read: pid %x found\n", pid); + ApplicationInformationSection * ait = new ApplicationInformationSection(buffer); + sections.push_back(ait); + } + dmx->Stop(); + delete dmx; + return ret; +} + +bool CAit::Parse() +{ + printf("[ait] trying to parse AIT\n"); + + if(!Read()) + return false; + + FILE * pFile = fopen ("/tmp/ait.txt","w"); + if (pFile) + fprintf(pFile, "Channel: %s\n", name.c_str()); + short int profilecode = 0; + int orgid = 0, appid = 0, profileVersion = 0; + + int sectionLength = 0; + ApplicationInformationSectionConstIterator sit; + for (sit = sections.begin(); sit != sections.end(); ++sit) + { + + if (CServiceScan::getInstance()->Aborted()) + return false; + + std::list::const_iterator i = (*sit)->getApplicationInformation()->begin(); + sectionLength = (*sit)->getSectionLength() + 3; + + for (; i != (*sit)->getApplicationInformation()->end(); ++i) + { + std::string hbbtvUrl = "", applicationName = ""; + std::string TPDescPath = "", SALDescPath = ""; + int controlCode = (*i)->getApplicationControlCode(); + ApplicationIdentifier * applicationIdentifier = (ApplicationIdentifier *)(*i)->getApplicationIdentifier(); + profilecode = 0; + orgid = applicationIdentifier->getOrganisationId(); + appid = applicationIdentifier->getApplicationId(); + //printf("[ait] found applicaions ids (pid : 0x%x) : orgid : %d, appid : %d\n", pid, orgid, appid); + if (controlCode == 1 || controlCode == 2) /* 1:AUTOSTART, 2:PRESENT */ + { + for (DescriptorConstIterator desc = (*i)->getDescriptors()->begin(); + desc != (*i)->getDescriptors()->end(); ++desc) + { + switch ((*desc)->getTag()) + { + case APPLICATION_DESCRIPTOR: + { + ApplicationDescriptor* applicationDescriptor = (ApplicationDescriptor*)(*desc); + const ApplicationProfileList* applicationProfiles = applicationDescriptor->getApplicationProfiles(); + ApplicationProfileConstIterator interactionit = applicationProfiles->begin(); + for(; interactionit != applicationProfiles->end(); ++interactionit) + { + profilecode = (*interactionit)->getApplicationProfile(); + profileVersion = PACK_VERSION( + (*interactionit)->getVersionMajor(), + (*interactionit)->getVersionMinor(), + (*interactionit)->getVersionMicro() + ); + } + break; + } + case APPLICATION_NAME_DESCRIPTOR: + { + ApplicationNameDescriptor *nameDescriptor = (ApplicationNameDescriptor*)(*desc); + ApplicationNameConstIterator interactionit = nameDescriptor->getApplicationNames()->begin(); + for(; interactionit != nameDescriptor->getApplicationNames()->end(); ++interactionit) + { + applicationName = (*interactionit)->getApplicationName(); + //if(controlCode == 1) printf("[ait] applicationname: %s\n", applicationName.c_str()); + break; + } + break; + } + case TRANSPORT_PROTOCOL_DESCRIPTOR: + { + TransportProtocolDescriptor *transport = (TransportProtocolDescriptor*)(*desc); + switch (transport->getProtocolId()) + { + case 1: /* object carousel */ + break; + case 2: /* ip */ + break; + case 3: /* interaction */ + { + InterActionTransportConstIterator interactionit = transport->getInteractionTransports()->begin(); + for(; interactionit != transport->getInteractionTransports()->end(); ++interactionit) + { + TPDescPath = (*interactionit)->getUrlBase()->getUrl(); + break; + } + break; + } + } + break; + } + case GRAPHICS_CONSTRAINTS_DESCRIPTOR: + break; + case SIMPLE_APPLICATION_LOCATION_DESCRIPTOR: + { + SimpleApplicationLocationDescriptor *applicationlocation = (SimpleApplicationLocationDescriptor*)(*desc); + SALDescPath = applicationlocation->getInitialPath(); + break; + } + case APPLICATION_USAGE_DESCRIPTOR: + break; + case SIMPLE_APPLICATION_BOUNDARY_DESCRIPTOR: + break; + } + } + hbbtvUrl = TPDescPath + SALDescPath; + } + if(!hbbtvUrl.empty()) + { + printf("[ait] detected AppID: %d, AppName: %s, Url: %s\n", appid, applicationName.c_str(), hbbtvUrl.c_str()); + if (pFile) + { + fprintf(pFile, "AppID: %d, AppName: %s, Url: %s\n", appid, applicationName.c_str(), hbbtvUrl.c_str()); + } + } + } + } + if (pFile) + fclose(pFile); + return true; +} + +bool CAit::Parse(CZapitChannel * const channel) +{ + pid = channel->getAitPid(); + name = channel->getName(); + unlink("/tmp/ait.txt"); + if(pid > 0) + { + Parse(); + return true; + } + return false; +} diff --git a/src/zapit/src/scanpmt.cpp b/src/zapit/src/scanpmt.cpp index b7e06f152..bf255af24 100644 --- a/src/zapit/src/scanpmt.cpp +++ b/src/zapit/src/scanpmt.cpp @@ -38,6 +38,10 @@ #include #include #include +#include +#include +#include +#include #define DEBUG_PMT //#define DEBUG_PMT_UNUSED @@ -331,6 +335,18 @@ bool CPmt::ParseEsInfo(ElementaryStreamInfo *esinfo, CZapitChannel * const chann audio_type = CZapitAudioChannel::EAC3; audio = true; break; + case STREAM_TYPE_PRIVATE_SECTION: + for (DescriptorConstIterator desc = esinfo->getDescriptors()->begin(); desc != esinfo->getDescriptors()->end(); ++desc) + { + switch ((*desc)->getTag()) + { + case APPLICATION_SIGNALLING_DESCRIPTOR: + channel->setAitPid(esinfo->getPid()); + printf("[pmt] found aitpid: 0x%x\n", esinfo->getPid()); + break; + } + } + break; default: #ifdef DEBUG_PMT_UNUSED printf("PMT: pid %04x stream_type: %02x\n", esinfo->getPid(), stream_type); diff --git a/src/zapit/src/zapit.cpp b/src/zapit/src/zapit.cpp index a996676a2..91d29169d 100644 --- a/src/zapit/src/zapit.cpp +++ b/src/zapit/src/zapit.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include //#include #include @@ -489,6 +490,7 @@ bool CZapit::ParsePatPmt(CZapitChannel * channel) CPat pat(channel->getRecordDemux()); CPmt pmt(channel->getRecordDemux()); + CAit ait(channel->getRecordDemux()); DBG("looking up pids for channel_id " PRINTF_CHANNEL_ID_TYPE "\n", channel->getChannelID()); if(!pat.Parse(channel)) { @@ -499,6 +501,10 @@ bool CZapit::ParsePatPmt(CZapitChannel * channel) printf("[zapit] pmt parsing failed\n"); return false; } + if (channel == current_channel) + if(!ait.Parse(channel)) { + printf("[zapit] ait parsing failed\n"); + } return true; }