From 32811ee6cc5c6b60d448e1d472ee835d3e05ca68 Mon Sep 17 00:00:00 2001 From: koukou Date: Sat, 26 Feb 2011 13:14:06 +0900 Subject: [PATCH 1/1] =?utf8?q?TS=E5=88=86=E9=9B=A2=E7=94=A8=E3=83=86?= =?utf8?q?=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89=E3=81=AE=E5=89=8A?= =?utf8?q?=E9=99=A4=E3=81=AA=E3=81=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/ARIB/si.cpp | 322 +++++++++++++++++++++++++------------------------- src/TS/descriptor.cpp | 145 ++++++++++++----------- src/tsparser.cpp | 225 ++++++++++------------------------- 3 files changed, 298 insertions(+), 394 deletions(-) diff --git a/src/ARIB/si.cpp b/src/ARIB/si.cpp index 349a645..3463483 100644 --- a/src/ARIB/si.cpp +++ b/src/ARIB/si.cpp @@ -1,4 +1,4 @@ - + #include #include "si.h" @@ -145,48 +145,48 @@ void NIT::clearNIT() SDT::SDT( DescriptorParser *des_parser) : ServiceInformation( -1, des_parser) { - original_network_id = 0x00; - reserved_future_use = 0x00; -} - -SDT::~SDT() + original_network_id = 0x00; + reserved_future_use = 0x00; +} + +SDT::~SDT() { - clearSDT(); + clearSDT(); } void SDT::clear() { clearSDT(); ServiceInformation::clear(); -} - -SDT::STATUS SDT::parse( SectionBuffer &sec) +} + +SDT::STATUS SDT::parse( SectionBuffer &sec) { - int32_t size = 0; + int32_t size = 0; SERVICE s; - clearSDT(); - - STATUS state = ServiceInformation::parse( sec); - if( state != SUCCESS) { - return state; - } + clearSDT(); + + STATUS state = ServiceInformation::parse( sec); + if( state != SUCCESS) { + return state; + } if( sec.length() < SD_PARSE_SIZE) { return ERROR_PARSE_SECTION; } original_network_id = (sec[ 0] << 8) + sec[ 1]; - reserved_future_use = sec[ 2]; + reserved_future_use = sec[ 2]; sec += SD_PARSE_SIZE; - - while( sec.length() >= SERVICE_HEADER_SIZE) { - s.service_id = (sec[ 0] << 8) + sec[ 1]; - s.reserved_future_use = (sec[ 2] >> 5) & 0x07; - s.EIT_user_defined_flags = (sec[ 2] >> 2) & 0x07; - s.EIT_schedule_flag = (sec[ 2] >> 1) & 0x01; - s.EIT_present_following_flag = (sec[ 2] >> 0) & 0x01; - s.running_status = (sec[ 3] >> 5) & 0x07; - s.free_CA_mode = (sec[ 3] >> 4) & 0x01; + + while( sec.length() >= SERVICE_HEADER_SIZE) { + s.service_id = (sec[ 0] << 8) + sec[ 1]; + s.reserved_future_use = (sec[ 2] >> 5) & 0x07; + s.EIT_user_defined_flags = (sec[ 2] >> 2) & 0x07; + s.EIT_schedule_flag = (sec[ 2] >> 1) & 0x01; + s.EIT_present_following_flag = (sec[ 2] >> 0) & 0x01; + s.running_status = (sec[ 3] >> 5) & 0x07; + s.free_CA_mode = (sec[ 3] >> 4) & 0x01; s.descriptors_loop_length = ((sec[ 3] & 0x0f) << 8) + sec[ 4]; sec += SERVICE_HEADER_SIZE; if( sec.length() < s.descriptors_loop_length) { @@ -197,12 +197,12 @@ SDT::STATUS SDT::parse( SectionBuffer &sec) if( size == -1) { return ERROR_PARSE_SECTION; } - sec += size; + sec += size; services.push_back( s); - } - - erase_buffer = true; - return SUCCESS; + } + + erase_buffer = true; + return SUCCESS; } bool SDT::checkID( uint8_t id) @@ -230,50 +230,50 @@ void SDT::clearSDT() EIT::EIT( DescriptorParser *des_parser) : ServiceInformation( -1, des_parser) { - transport_stream_id = 0x00; - original_network_id = 0x00; - segment_last_section_number = 0x00; - last_table_id = 0x00; -} - -EIT::~EIT() + transport_stream_id = 0x00; + original_network_id = 0x00; + segment_last_section_number = 0x00; + last_table_id = 0x00; +} + +EIT::~EIT() { - clearEIT(); + clearEIT(); } void EIT::clear() { clearEIT(); ServiceInformation::clear(); -} - -EIT::STATUS EIT::parse( SectionBuffer &sec) +} + +EIT::STATUS EIT::parse( SectionBuffer &sec) { - int32_t size = 0; + int32_t size = 0; EVENT e; - clearEIT(); - - STATUS state = ServiceInformation::parse( sec); - if( state != SUCCESS) { - return state; - } + clearEIT(); + + STATUS state = ServiceInformation::parse( sec); + if( state != SUCCESS) { + return state; + } if( sec.length() < EI_PARSE_SIZE) { return ERROR_PARSE_SECTION; - } - transport_stream_id = (sec[ 0] << 8) + sec[ 1]; - original_network_id = (sec[ 2] << 8) + sec[ 3]; - segment_last_section_number = sec[ 4]; - last_table_id = sec[ 5]; + } + transport_stream_id = (sec[ 0] << 8) + sec[ 1]; + original_network_id = (sec[ 2] << 8) + sec[ 3]; + segment_last_section_number = sec[ 4]; + last_table_id = sec[ 5]; sec += EI_PARSE_SIZE; - - while( sec.length() >= EVENT_HEADER_SIZE) { - e.event_id = (sec[ 0] << 8) + sec[ 1]; - e.start_time = Converter::date( &sec[ 2]); - e.duration = Converter::time( &sec[ 7]); - e.running_status = (sec[ 10] >> 5) & 0x07; - e.free_CA_mode = (sec[ 10] >> 4) & 0x01; + + while( sec.length() >= EVENT_HEADER_SIZE) { + e.event_id = (sec[ 0] << 8) + sec[ 1]; + e.start_time = Converter::date( &sec[ 2]); + e.duration = Converter::time( &sec[ 7]); + e.running_status = (sec[ 10] >> 5) & 0x07; + e.free_CA_mode = (sec[ 10] >> 4) & 0x01; e.descriptors_loop_length = ((sec[ 10] & 0x0f) << 8) + sec[ 11]; sec += EVENT_HEADER_SIZE; if( sec.length() < e.descriptors_loop_length) { @@ -284,12 +284,12 @@ EIT::STATUS EIT::parse( SectionBuffer &sec) if( size == -1) { return ERROR_PARSE_SECTION; } - sec += size; + sec += size; events.push_back( e); - } - - erase_buffer = true; - return SUCCESS; + } + + erase_buffer = true; + return SUCCESS; } bool EIT::checkID( uint8_t id) @@ -310,91 +310,91 @@ void EIT::clearEIT() clearDescriptors( &i->descriptors); } events.clear(); -} - - - -TDT::TDT( DescriptorParser *des_parser) - : Section( -1, des_parser) -{ -} - -TDT::~TDT() -{ -} - -TDT::STATUS TDT::parse( SectionBuffer &sec) -{ - int32_t size = 0; - - if( sec.length() < TD_PARSE_SIZE) { - return ERROR_PARSE_SECTION; - } - - JST_time = Converter::date( &sec[ 0]); - sec += TD_PARSE_SIZE; - - erase_buffer = true; - return SUCCESS; -} - -bool TDT::checkID( uint8_t id) -{ - return (id == TDT_ID); -} - - - - -TOT::TOT( DescriptorParser *des_parser) - : TDT( des_parser) -{ -} - -TOT::~TOT() -{ - clearTOT(); -} - -void TOT::clear() -{ - clearTOT(); - Section::clear(); -} - -TOT::STATUS TOT::parse( SectionBuffer &sec) -{ - int32_t size = 0; - - clearTOT(); - - STATUS state = TDT::parse( sec); - if( state != SUCCESS) { - return state; - } - if( table_id == TDT_ID) { - return SUCCESS; - } - - if( sec.length() < TO_PARSE_SIZE) { - return ERROR_PARSE_SECTION; - } - - reserved_2 = (sec[ 0] >> 4) & 0x0f; - descriptors_loop_length = ((sec[ 0] & 0x0f) << 8) + sec[ 1]; - sec += TO_PARSE_SIZE; - - size = parseDescriptors( sec, descriptors_loop_length, &descriptors); - if( size == -1) { - return ERROR_PARSE_SECTION; - } - sec += size; - - erase_buffer = true; - return SUCCESS; -} - -bool TOT::checkID( uint8_t id) +} + + + +TDT::TDT( DescriptorParser *des_parser) + : Section( -1, des_parser) +{ +} + +TDT::~TDT() +{ +} + +TDT::STATUS TDT::parse( SectionBuffer &sec) +{ + int32_t size = 0; + + if( sec.length() < TD_PARSE_SIZE) { + return ERROR_PARSE_SECTION; + } + + JST_time = Converter::date( &sec[ 0]); + sec += TD_PARSE_SIZE; + + erase_buffer = true; + return SUCCESS; +} + +bool TDT::checkID( uint8_t id) +{ + return (id == TDT_ID); +} + + + + +TOT::TOT( DescriptorParser *des_parser) + : TDT( des_parser) +{ +} + +TOT::~TOT() +{ + clearTOT(); +} + +void TOT::clear() +{ + clearTOT(); + Section::clear(); +} + +TOT::STATUS TOT::parse( SectionBuffer &sec) +{ + int32_t size = 0; + + clearTOT(); + + STATUS state = TDT::parse( sec); + if( state != SUCCESS) { + return state; + } + if( table_id == TDT_ID) { + return SUCCESS; + } + + if( sec.length() < TO_PARSE_SIZE) { + return ERROR_PARSE_SECTION; + } + + reserved_2 = (sec[ 0] >> 4) & 0x0f; + descriptors_loop_length = ((sec[ 0] & 0x0f) << 8) + sec[ 1]; + sec += TO_PARSE_SIZE; + + size = parseDescriptors( sec, descriptors_loop_length, &descriptors); + if( size == -1) { + return ERROR_PARSE_SECTION; + } + sec += size; + + erase_buffer = true; + return SUCCESS; +} + +bool TOT::checkID( uint8_t id) { if( TDT::checkID( id)) { return true; @@ -402,13 +402,13 @@ bool TOT::checkID( uint8_t id) else if( id == TOT_ID) { return true; } - else { + else { return false; - } -} - -void TOT::clearTOT() -{ - clearDescriptors( &descriptors); -} - + } +} + +void TOT::clearTOT() +{ + clearDescriptors( &descriptors); +} + diff --git a/src/TS/descriptor.cpp b/src/TS/descriptor.cpp index 839d6ae..12ee987 100644 --- a/src/TS/descriptor.cpp +++ b/src/TS/descriptor.cpp @@ -1,7 +1,7 @@ - -#include -#include "descriptor.h" - + +#include +#include "descriptor.h" + using namespace TS::Description; Descriptor* DescriptorParser::parse( const uint8_t *data, const uint16_t len, uint16_t *parse_size) @@ -30,7 +30,7 @@ Descriptor* DescriptorParser::parse( const uint8_t *data, const uint16_t len, ui } ret = p->parse( &data[ index], len - index); - if( ret < 0) { + if( ret < 0) { fprintf( stderr, "Descriptor parse error tag = 0x%02X, len = %d\n", des_tag, des_length); delete p; p = NULL; @@ -52,30 +52,30 @@ Descriptor* DescriptorParser::parse( const uint8_t *data, const uint16_t len, ui } return p; -} - -Descriptor* DescriptorParser::clone( const Descriptor *des) -{ - int16_t ret; - Descriptor *p = NULL; - - p = create( des->descriptor_tag, des->descriptor_length); - if( !p) { - return p; - } - - ret = p->parse( des->descriptor.begin(), des->descriptor.size()); - if( ret < 0) { - fprintf( stderr, "Descriptor clone error tag = 0x%02X", des->descriptor_tag); - delete p; - p = NULL; - } - else if( ret != des->descriptor_length) { - fprintf( stderr, "clone des overflow tag = 0x%02X, len = %d, ret = %d\n", des->descriptor_tag, des->descriptor_length, ret); - delete p; - p = NULL; - } - return p; +} + +Descriptor* DescriptorParser::clone( const Descriptor *des) +{ + int16_t ret; + Descriptor *p = NULL; + + p = create( des->descriptor_tag, des->descriptor_length); + if( !p) { + return p; + } + + ret = p->parse( des->descriptor.begin(), des->descriptor.size()); + if( ret < 0) { + fprintf( stderr, "Descriptor clone error tag = 0x%02X", des->descriptor_tag); + delete p; + p = NULL; + } + else if( ret != des->descriptor_length) { + fprintf( stderr, "clone des overflow tag = 0x%02X, len = %d, ret = %d\n", des->descriptor_tag, des->descriptor_length, ret); + delete p; + p = NULL; + } + return p; } Descriptor* DescriptorParser::create( const uint8_t tag, const uint8_t length) @@ -93,46 +93,46 @@ Descriptor* DescriptorParser::create( const uint8_t tag, const uint8_t length) return p; } - - + + Descriptor::Descriptor( const uint8_t tag, const uint8_t length) - : descriptor_tag( tag), descriptor_length( length) -{ - descriptor.clear(); -} - -Descriptor::~Descriptor() -{ - descriptor.clear(); -} - -int16_t Descriptor::parse( const uint8_t *data, const uint16_t len) -{ - if( !descriptor.create( descriptor_length)) { - return -1; - } - descriptor.append( data, descriptor_length); - return descriptor_length; -} - -int16_t Descriptor::getBytes( TS::SectionBuffer &buf) -{ - if( descriptor.size() != descriptor_length) { - return -1; - } - - if( !buf.append( descriptor_tag)) { - return -1; - } - if( !buf.append( descriptor_length)) { - return -1; - } - if( !buf.append( descriptor.begin(), descriptor.size())) { - return -1; - } - buf += descriptor.size() + 2; - - return descriptor.size() + 2; + : descriptor_tag( tag), descriptor_length( length) +{ + descriptor.clear(); +} + +Descriptor::~Descriptor() +{ + descriptor.clear(); +} + +int16_t Descriptor::parse( const uint8_t *data, const uint16_t len) +{ + if( !descriptor.create( descriptor_length)) { + return -1; + } + descriptor.append( data, descriptor_length); + return descriptor_length; +} + +int16_t Descriptor::getBytes( TS::SectionBuffer &buf) +{ + if( descriptor.size() != descriptor_length) { + return -1; + } + + if( !buf.append( descriptor_tag)) { + return -1; + } + if( !buf.append( descriptor_length)) { + return -1; + } + if( !buf.append( descriptor.begin(), descriptor.size())) { + return -1; + } + buf += descriptor.size() + 2; + + return descriptor.size() + 2; } @@ -142,15 +142,16 @@ ConditionalAccess::ConditionalAccess( const uint8_t length) } ConditionalAccess::~ConditionalAccess() -{ +{ private_data.clear(); } const TS::SectionBuffer* ConditionalAccess::getPrivateData() { return &private_data; -} - int16_t ConditionalAccess::parse( const uint8_t *data, const uint16_t len) +} + +int16_t ConditionalAccess::parse( const uint8_t *data, const uint16_t len) { int16_t index = 0; @@ -164,7 +165,7 @@ const TS::SectionBuffer* ConditionalAccess::getPrivateData() } private_data.append( &data[ index], descriptor_length - index); index = descriptor_length; - + return Descriptor::parse( data, len); // return index; } diff --git a/src/tsparser.cpp b/src/tsparser.cpp index 2d70cff..a035628 100644 --- a/src/tsparser.cpp +++ b/src/tsparser.cpp @@ -28,7 +28,7 @@ void printPAT( Section *sec) PAT *pat = (PAT *)sec; fprintf( stdout, "\n[ PAT ]\n"); - fprintf( stdout, "table id = %5u\n", pat->table_id); + fprintf( stdout, "table id = 0x%02X\n", pat->table_id); fprintf( stdout, "section syntax indicator = %5u\n", pat->section_syntax_indicator); fprintf( stdout, "section length = %5u\n", pat->section_length); fprintf( stdout, "transport stream id = %5u\n", pat->psi_id.transport_stream_id); @@ -49,7 +49,7 @@ void printCAT( Section *sec) CAT *cat = (CAT *)sec; fprintf( stdout, "\n[ CAT ]\n"); - fprintf( stdout, "table id = %5u\n", cat->table_id); + fprintf( stdout, "table id = 0x%02X\n", cat->table_id); fprintf( stdout, "section syntax indicator = %5u\n", cat->section_syntax_indicator); fprintf( stdout, "section length = %5u\n", cat->section_length); fprintf( stdout, "version number = %5u\n", cat->version_number); @@ -69,7 +69,7 @@ void printTSDT( Section *sec) TSDT *tsdt = (TSDT *)sec; fprintf( stdout, "\n[ TSDT ]\n"); - fprintf( stdout, "table id = %5u\n", tsdt->table_id); + fprintf( stdout, "table id = 0x%02X\n", tsdt->table_id); fprintf( stdout, "section syntax indicator = %5u\n", tsdt->section_syntax_indicator); fprintf( stdout, "section length = %5u\n", tsdt->section_length); fprintf( stdout, "version number = %5u\n", tsdt->version_number); @@ -90,7 +90,7 @@ void printPMT( Section *sec) PMT::DESCRIPTORS::iterator d; fprintf( stdout, "\n[ PMT ]\n"); - fprintf( stdout, "table id = %5u\n", pmt->table_id); + fprintf( stdout, "table id = 0x%02X\n", pmt->table_id); fprintf( stdout, "section syntax indicator = %5u\n", pmt->section_syntax_indicator); fprintf( stdout, "section length = %5u\n", pmt->section_length); fprintf( stdout, "program number = %5u\n", pmt->psi_id.program_number); @@ -352,6 +352,33 @@ void printSDT( Section *sec) } } +void printTOT( Section *sec) +{ + TOT *tot = (TOT *)sec; + + if( tot->table_id == TDT::TDT_ID) { + fprintf( stdout, "\n[ TDT ]\n"); + } + else { + fprintf( stdout, "\n[ TOT ]\n"); + } + fprintf( stdout, "table id = 0x%02X\n", tot->table_id); + fprintf( stdout, "section syntax indicator = %5u\n", tot->section_syntax_indicator); + fprintf( stdout, "section length = %5u\n", tot->section_length); + fprintf( stdout, "JST_time = %s", asctime( localtime( &tot->JST_time))); + + if( tot->table_id == TOT::TOT_ID) { + fprintf( stdout, "descriptors_loop_length = %5u\n", tot->descriptors_loop_length); + + TOT::DESCRIPTORS::iterator d; + for( d = tot->descriptors.begin(); d != tot->descriptors.end(); d++) { + fprintf( stdout, " descriptor_tag = 0x%02X\n", (*d)->descriptor_tag); + fprintf( stdout, " descriptor_length = %5u\n", (*d)->descriptor_length); + } + } +} + + int main( int argc, char **argv) { @@ -366,7 +393,6 @@ int main( int argc, char **argv) uint32_t read_len; uint32_t offset = 0; ssize_t file_read_size; - bool output_ts = false; TSPacket *ts = NULL; Section::STATUS status; @@ -383,11 +409,6 @@ int main( int argc, char **argv) } filename = argv[ 1]; -#if 0 - if( argc >= 3) { - output_ts = true; - } -#endif if( strcmp( filename, "-") == 0) { fd = 0; @@ -396,33 +417,21 @@ int main( int argc, char **argv) fd = open( filename, O_RDONLY); } if( fd == -1) { - fprintf( stderr, "%s is not opened.\n", filename); + fprintf( stderr, "%s is not open.\n", filename); return 1; } - secs[ 0x0000] = new PAT( &des_parser); - secs[ 0x0001] = new CAT( &des_parser); - secs[ 0x0002] = new TSDT( &des_parser); - secs[ 0x0010] = new NIT( &des_parser); - secs[ 0x0011] = new SDT( &des_parser); - secs[ 0x0012] = new EIT( &des_parser); - secs[ 0x0026] = new EIT( &des_parser); - secs[ 0x0027] = new EIT( &des_parser); - - int32_t t_err_pid; - - int ofd = -1; - uint8_t write_buf[ 1024]; - bool save_flag = false; - uint16_t pmt_pid = 0; - uint8_t pat_counter = 0; - uint8_t pmt_counter = 0; - std::set< uint16_t> save_pid; - - save_pid.insert( 0x0000); - save_pid.insert( 0x0001); - save_pid.insert( 0x0010); - save_pid.insert( 0x0011); + secs[ PID_PAT ] = new PAT( &des_parser); + secs[ PID_CAT ] = new CAT( &des_parser); + secs[ PID_TSDT] = new TSDT( &des_parser); + secs[ PID_NIT ] = new NIT( &des_parser); + secs[ PID_SDT ] = new SDT( &des_parser); + secs[ PID_EIT ] = new EIT( &des_parser); + secs[ PID_TOT ] = new TOT( &des_parser); + secs[ PID_EIT1] = new EIT( &des_parser); + secs[ PID_EIT2] = new EIT( &des_parser); + + std::set< uint16_t> pcr_pid; while( (file_read_size = read( fd, buf + offset, buf_size - offset) + offset) > 0 ) { index = 0; @@ -437,61 +446,52 @@ int main( int argc, char **argv) index += TS::TSPacket::TS_PACKET_SIZE; continue; } -// index += read_len; pid = ts->getPID(); +#if 0 + if( pcr_pid.find( pid) != pcr_pid.end()) { + uint64_t pcr = ts->getAdaptationField()->getProgramClockReference(); + fprintf( stdout, "***** PCR = %lu, PID = 0x%04X *****\n", pcr, pid); + } +#endif sec_it = secs.find( pid); if( sec_it != secs.end()) { payload_index = 0; do { status = sec_it->second->append( ts, &payload_index); if( status == Section::SUCCESS || status == Section::INCLUDE_NEW_SECTION) { - if( sec_it->first == 0x0000) { + if( sec_it->first == PID_PAT) { //printPAT( sec_it->second); PAT *pat = (PAT *)sec_it->second; PAT::PROGRAM_MAP::iterator it; SECTIONS::iterator pmt; -#if 0 + for( it = pat->program_map_PID.begin(); it != pat->program_map_PID.end(); it++) { pmt = secs.find( it->second); if( pmt == secs.end()) { secs[ it->second] = new PMT( &des_parser); - save_pid.insert( it->second); fprintf( stderr, "new pid 0x%04X, program number %u\n", it->second, it->first); - if( pmt_pid == 0) { - pmt_pid = it->second; - } } } -#else - save_pid.insert( pat->network_PID); - it = pat->program_map_PID.begin(); - std::advance( it, 1); - pat->program_map_PID.erase( it, pat->program_map_PID.end()); - it = pat->program_map_PID.begin(); - if( secs.find( it->second) == secs.end()) { - secs[ it->second] = new PMT( &des_parser); - save_pid.insert( it->second); - fprintf( stderr, "new pid 0x%04X, program number %u\n", it->second, it->first); - pmt_pid = it->second; - } -#endif } - else if( sec_it->first == 0x0001) { + else if( sec_it->first == PID_CAT) { //printCAT( sec_it->second); } - else if( sec_it->first == 0x0002) { + else if( sec_it->first == PID_TSDT) { //printTSDT( sec_it->second); } - else if( sec_it->first == 0x0010) { + else if( sec_it->first == PID_NIT) { //printNIT( sec_it->second); } - else if( sec_it->first == 0x0011) { - ///printSDT( sec_it->second); + else if( sec_it->first == PID_SDT) { + //printSDT( sec_it->second); } - else if( (sec_it->first == 0x0012 || sec_it->first == 0x0026 || sec_it->first == 0x0027)) { + else if( (sec_it->first == PID_EIT || sec_it->first == PID_EIT1 || sec_it->first == PID_EIT2)) { printEIT( sec_it->second); } + else if( sec_it->first == PID_TOT) { + //printTOT( sec_it->second); + } else { if( sec_it->second->table_id == PMT::ID) { //printPMT( sec_it->second); @@ -500,48 +500,9 @@ int main( int argc, char **argv) PMT::DESCRIPTORS::iterator d; PMT::ELEMENTS::iterator e; - //if( pmt_pid == sec_it->first) { - if( save_pid.find( pmt->PCR_PID) == save_pid.end()) { - save_pid.insert( pmt->PCR_PID); - fprintf( stderr, "new pid 0x%04X, PCR, cur pid 0x%04X\n", pmt->PCR_PID, sec_it->first); - } - - for( d = pmt->program_info_descriptors.begin(); d != pmt->program_info_descriptors.end(); d++) { - if( (*d)->descriptor_tag == ConditionalAccess::TAG) { - ConditionalAccess *ca = (ConditionalAccess *)*d; - if( save_pid.find( ca->CA_PID) == save_pid.end()) { - //secs[ ca->CA_PID] = new CAT( &des_parser); - if( ca->CA_PID != 0x1FFF) { - save_pid.insert( ca->CA_PID); - fprintf( stderr, "new pid 0x%04X, CA ID %u, cur pid 0x%04X\n", ca->CA_PID, ca->CA_system_ID, sec_it->first); - } - } - } - } - - pmt->eraseElement( 0x0D); - - for( e = pmt->elements.begin(); e != pmt->elements.end(); e++) { - if( save_pid.find( e->elementary_PID) == save_pid.end()) { - save_pid.insert( e->elementary_PID); - fprintf( stderr, "new pid 0x%04X, stream_type 0x%02X, cur pid 0x%04X\n", e->elementary_PID, e->stream_type, sec_it->first); - } - - for( d = e->descriptors.begin(); d != e->descriptors.end(); d++) { - if( (*d)->descriptor_tag == ConditionalAccess::TAG) { - ConditionalAccess *ca = (ConditionalAccess *)*d; - if( save_pid.find( ca->CA_PID) == save_pid.end()) { - //secs[ ca->CA_PID] = new CAT( &des_parser); - if( ca->CA_PID != 0x1FFF) { - save_pid.insert( ca->CA_PID); - fprintf( stderr, "new pid 0x%04X, CA ID %u, cur pid 0x%04X\n", ca->CA_PID, ca->CA_system_ID, sec_it->first); - } - } - } - } - } - save_flag = true; - //} + if( pcr_pid.find( pmt->PCR_PID) == pcr_pid.end()) { + pcr_pid.insert( pmt->PCR_PID); + } } } } @@ -550,62 +511,7 @@ int main( int argc, char **argv) } } while( status == Section::INCLUDE_NEW_SECTION); } -#if 0 - if( ofd == -1 && output_ts) { - ofd = open( "output.ts", O_WRONLY | O_CREAT | O_TRUNC, 0644); - } - - if( ofd > 0) { - if( ts->getPID() == 0x0000) { - PAT *pat = (PAT *)secs[ 0x0000]; - if( pat->finish()) { - TSPacket *tmp_ts; - status = pat->getTSPacket( &tmp_ts, &pat_counter, ts->getAdaptationField()); - if( status != Section::SUCCESS) { - fprintf( stderr, "PAT TS Packet rebuild error: %d\n", status); - } - else { - int w = tmp_ts->getBytes( write_buf, 1024); - if( w > 0) { - ::write( ofd, &write_buf, w); - } - } - } - } - else if( ts->getPID() == pmt_pid) { - PMT *pmt = (PMT *)secs[ pmt_pid]; - if( pmt->finish()) { - TSPacket *tmp_ts; - status = pmt->getTSPacket( &tmp_ts, &pmt_counter, ts->getAdaptationField()); - if( status != Section::SUCCESS) { - fprintf( stderr, "PMT TS Packet rebuild error: %d\n", status); - } - else { - int w = tmp_ts->getBytes( write_buf, 1024); - if( w > 0) { - ::write( ofd, &write_buf, w); - } - } - } - } - else if( save_pid.find( ts->getPID()) != save_pid.end()) { - int w = ts->getBytes( write_buf, 1024); - if( memcmp( write_buf, &buf[ index], w) != 0) { - fprintf( stderr, "TS Packet rebuild error: PID = 0x%04X\n", ts->getPID()); - int i; - for( i = 0; i < w; i++) { - if( write_buf[ i] != buf[ index + i]) { - fprintf( stderr, "TS Packet rebuild error index = %d\n", i); - break; - } - } - } - if( w > 0) { - ::write( ofd, &write_buf, w); - } - } - } -#endif + index += read_len; } offset = file_read_size - index; @@ -616,9 +522,6 @@ EXIT: if( fd > 0) { close( fd); } - if( ofd > 0) { - close( ofd); - } for( sec_it = secs.begin(); sec_it != secs.end(); sec_it++) { delete sec_it->second; -- 2.11.0