From 0708f61d9a0f6406f8440b669c7400fb0309526d Mon Sep 17 00:00:00 2001 From: satbaby Date: Mon, 25 Oct 2010 07:03:32 +0000 Subject: [PATCH] -add pmt parse to scanSDT git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@860 e54a6e83-5905-42d5-8d5c-058d10e6a962 --- src/zapit/include/zapit/pat.h | 3 +- src/zapit/include/zapit/pmt.h | 1 + src/zapit/src/pat.cpp | 41 +++++++++++++++++++ src/zapit/src/pmt.cpp | 77 +++++++++++++++++++++++++++++++++++ src/zapit/src/sdt.cpp | 22 ++++++++-- src/zapit/src/zapit.cpp | 3 +- 6 files changed, 140 insertions(+), 7 deletions(-) diff --git a/src/zapit/include/zapit/pat.h b/src/zapit/include/zapit/pat.h index b4491c828..6d42f2c67 100644 --- a/src/zapit/include/zapit/pat.h +++ b/src/zapit/include/zapit/pat.h @@ -21,9 +21,8 @@ #ifndef __zapit_pat_h__ #define __zapit_pat_h__ - #include "channel.h" - int parse_pat(CZapitChannel * const channel); +int scan_parse_pat( std::vector > &sidpmt ); #endif /* __zapit_pat_h__ */ diff --git a/src/zapit/include/zapit/pmt.h b/src/zapit/include/zapit/pmt.h index b7c97aea5..d858a5ce3 100644 --- a/src/zapit/include/zapit/pmt.h +++ b/src/zapit/include/zapit/pmt.h @@ -28,5 +28,6 @@ int parse_pmt(CZapitChannel * const channel); int pmt_set_update_filter(CZapitChannel * const channel, int * fd); int pmt_stop_update_filter(int * fd); +int scan_parse_pmt(int pmtpid, int service_id ); #endif /* __zapit_pmt_h__ */ diff --git a/src/zapit/src/pat.cpp b/src/zapit/src/pat.cpp index f19f657f4..8bcc0458e 100644 --- a/src/zapit/src/pat.cpp +++ b/src/zapit/src/pat.cpp @@ -76,6 +76,47 @@ if(buffer[7]) printf("[PAT] **************************************************** return -1; } +int scan_parse_pat( std::vector > &sidpmt ) +{ + + cDemux * dmx = new cDemux(); + dmx->Open(DMX_PSI_CHANNEL); + + /* buffer for program association table */ + unsigned char buffer[PAT_SIZE]; + + /* current positon in buffer */ + unsigned short i; + + unsigned char filter[DMX_FILTER_SIZE]; + unsigned char mask[DMX_FILTER_SIZE]; + + memset(filter, 0x00, DMX_FILTER_SIZE); + memset(mask, 0x00, DMX_FILTER_SIZE); + + mask[0] = 0xFF; + mask[4] = 0xFF; + + do { + /* set filter for program association section */ + /* read section */ + if ((dmx->sectionFilter(0, filter, mask, 5) < 0) || (i = dmx->Read(buffer, PAT_SIZE) < 0)) + { + delete dmx; + printf("[%s] dmx read failed\n",__FILE__); + return -1; + } + dmx->Stop(); + for (i = 8; i < (((buffer[1] & 0x0F) << 8) | buffer[2]) + 3; i += 4) { + int service_id = ((buffer[i] << 8) | buffer[i+1]); + if (service_id != 0) + sidpmt.push_back(std::make_pair( service_id , (((buffer[i+2] & 0x1F) << 8) | buffer[i+3]) ) ); + } + } while (filter[4]++ != buffer[7]); + delete dmx; + return -1; +} + static unsigned char pbuffer[PAT_SIZE]; int parse_pat() { diff --git a/src/zapit/src/pmt.cpp b/src/zapit/src/pmt.cpp index 06238bb79..85cef1c47 100644 --- a/src/zapit/src/pmt.cpp +++ b/src/zapit/src/pmt.cpp @@ -589,6 +589,83 @@ int parse_pmt(CZapitChannel * const channel) return 0; } + +int scan_parse_pmt(int pmtpid, int service_id ) +{ + if(pmtpid < 1 ) + return -1; + if(curpmtpid == pmtpid ){ + for(int i=0;i<11;i++){ + if(pmt_caids[0][i] > 0) + return 1; + } + return 0; + } + + int pmtlen; + int ia, dpmtlen, pos; + unsigned char descriptor_length=0; + const short pmt_size = 1024; + + unsigned char buffer[pmt_size]; + + unsigned char filter[DMX_FILTER_SIZE]; + unsigned char mask[DMX_FILTER_SIZE]; + + cDemux * dmx = new cDemux(); + dmx->Open(DMX_PSI_CHANNEL); + + memset(filter, 0x00, DMX_FILTER_SIZE); + memset(mask, 0x00, DMX_FILTER_SIZE); + + filter[0] = 0x02; /* table_id */ + filter[1] = service_id >> 8; + filter[2] = service_id; + filter[3] = 0x01; /* current_next_indicator */ + filter[4] = 0x00; /* section_number */ + mask[0] = 0xFF; + mask[1] = 0xFF; + mask[2] = 0xFF; + mask[3] = 0x01; + mask[4] = 0xFF; + + if ((dmx->sectionFilter(pmtpid, filter, mask, 5) < 0) || (dmx->Read(buffer, pmt_size) < 0)) { + delete dmx; + return -1; + } + delete dmx; + pmtlen= ((buffer[1]&0xf)<<8) + buffer[2] +3; + + dpmtlen=0; + pos=10; + + while(pos+20) { + switch(buffer[ia+2]) { + case 0x06: + case 0x17: + case 0x01: + case 0x05: + case 0x18: + case 0x0B: + case 0x0D: + case 0x09: + case 0x26: + case 0x4a: + case 0x0E: + return 1; + } //switch + } // if + } // for + pos+=dpmtlen+5; + } // while + return 0; + +} #ifndef DMX_SET_NEGFILTER_MASK #define DMX_SET_NEGFILTER_MASK _IOW('o',48,uint8_t *) #endif diff --git a/src/zapit/src/sdt.cpp b/src/zapit/src/sdt.cpp index d3f16c3f1..6aaf33f56 100644 --- a/src/zapit/src/sdt.cpp +++ b/src/zapit/src/sdt.cpp @@ -26,6 +26,9 @@ #include #include #include +#include +#include + #include // DEMUX_DEVICE #include #include @@ -367,7 +370,6 @@ _repeat: return 0; } -extern tallchans curchans; int parse_current_sdt( const t_transport_stream_id p_transport_stream_id, const t_original_network_id p_original_network_id, t_satellite_position satellitePosition, freq_id_t freq) { @@ -392,11 +394,10 @@ int parse_current_sdt( const t_transport_stream_id p_transport_stream_id, const bool EIT_schedule_flag; bool EIT_present_following_flag; bool free_CA_mode; - + int tmp_free_CA_mode = -1; unsigned char filter[DMX_FILTER_SIZE]; unsigned char mask[DMX_FILTER_SIZE]; - curchans.clear(); filter[0] = 0x42; filter[1] = (p_transport_stream_id >> 8) & 0xff; filter[2] = p_transport_stream_id & 0xff; @@ -417,6 +418,9 @@ int parse_current_sdt( const t_transport_stream_id p_transport_stream_id, const mask[7] = 0xFF; memset(&mask[8], 0x00, 8); + std::vector > sidpmt; + scan_parse_pat( sidpmt ); + do { if ((dmx->sectionFilter(0x11, filter, mask, 8) < 0) || (dmx->Read(buffer, SDT_SIZE) < 0)) { delete dmx; @@ -433,7 +437,16 @@ int parse_current_sdt( const t_transport_stream_id p_transport_stream_id, const EIT_schedule_flag = buffer[pos + 2] & 0x02; EIT_present_following_flag = buffer[pos + 2] & 0x01; running_status = buffer [pos + 3] & 0xE0; - free_CA_mode = buffer [pos + 3] & 0x10; + for (unsigned short i=0; i