/***************************************************************************** * dvbpsi_pmt_sections_decode ***************************************************************************** * PMT decoder. *****************************************************************************/ void dvbpsi_pmt_sections_decode( dvbpsi_pmt_t* p_pmt, dvbpsi_psi_section_t* p_section ) { uint8_t* p_byte, * p_end; /* sum: e0 67 f0 00 1b e0 6d f0 00 03 e0 70 f0 00 */ while ( p_section ) { /* - PMT descriptors */ /* ... e0 67 f0 00 1b ... */ p_byte = p_section->p_payload_start + 4;// 0x1b (p_payload_start is start 0x02 pos to + 8Byte) p_end = p_byte + ( ( (uint16_t) (p_section->p_payload_start[2] & 0x0f) << 8)// 0xf0 | p_section->p_payload_start[3]);// 0x00 --->0x1b+0 // DEBUG("p_section->p_payload_start :%p",p_section->p_payload_start); //int n; //for(n = 0; n< 100;n++){ // DEBUG(" %x",p_section->p_payload_start[n]); //} while ( p_byte + 2 <= p_end ) { uint8_t i_tag = p_byte[0]; uint8_t i_length = p_byte[1]; if ( i_length + 2 <= p_end - p_byte ) dvbpsi_pmt_descriptor_add( p_pmt, i_tag, i_length, p_byte + 2 );// p_byte += 2 + i_length; } /* - ESs */ /* p_byte = p_end = 0x1b */ int i =0; for ( p_byte = p_end; p_byte + 5 <= p_section->p_payload_end; ) {/* p_byte->[1b e0 6d f0 00 03 e0 70 f0 00] */ uint8_t i_type = p_byte[0];// 1)1b uint16_t i_pid = ( (uint16_t) (p_byte[1] & 0x1f) << 8) | p_byte[2];// 1)0x6d = 109 uint16_t i_es_length = ( (uint16_t) (p_byte[3] & 0x0f) << 8) | p_byte[4];// = 0x00 printf(" | type @ elementary_PID\n"); printf(" | 0x%02x @ 0x%x (%d) byte[%d] i_es_length =%d \n",i_type, i_pid, i_pid,++i,i_es_length); dvbpsi_pmt_es_t * p_es = dvbpsi_pmt_es_add( p_pmt, i_type, i_pid ); /* - ES descriptors */ p_byte += 5;/* 03 e0 70 f0 00 */ p_end = p_byte + i_es_length;// 1)(p_byte += 5) + 0) if ( p_end > p_section->p_payload_end ) { p_end = p_section->p_payload_end; } while ( p_byte + 2 <= p_end ) { uint8_t i_tag = p_byte[0];// 0x03 uint8_t i_length = p_byte[1];// 0xe0 if ( i_length + 2 <= p_end - p_byte )// dvbpsi_pmt_es_descriptor_add( p_es, i_tag, i_length, p_byte + 2 ); p_byte += 2 + i_length; } } p_section = p_section->p_next; } }
/***************************************************************************** * dvbpsi_pmt_sections_decode ***************************************************************************** * PMT decoder. *****************************************************************************/ void dvbpsi_pmt_sections_decode(dvbpsi_pmt_t* p_pmt, dvbpsi_psi_section_t* p_section) { uint8_t* p_byte, * p_end; while (p_section) { /* - PMT descriptors */ p_byte = p_section->p_payload_start + 4; p_end = p_byte + ( ((uint16_t)(p_section->p_payload_start[2] & 0x0f) << 8) | p_section->p_payload_start[3]); while (p_byte + 2 <= p_end) { uint8_t i_tag = p_byte[0]; uint8_t i_length = p_byte[1]; if (i_length + 2 <= p_end - p_byte) dvbpsi_pmt_descriptor_add(p_pmt, i_tag, i_length, p_byte + 2); p_byte += 2 + i_length; } /* - ESs */ for (p_byte = p_end; p_byte + 5 <= p_section->p_payload_end;) { uint8_t i_type = p_byte[0]; uint16_t i_pid = ((uint16_t)(p_byte[1] & 0x1f) << 8) | p_byte[2]; uint16_t i_es_length = ((uint16_t)(p_byte[3] & 0x0f) << 8) | p_byte[4]; dvbpsi_pmt_es_t* p_es = dvbpsi_pmt_es_add(p_pmt, i_type, i_pid); /* - ES descriptors */ p_byte += 5; p_end = p_byte + i_es_length; if (p_end > p_section->p_payload_end) { p_end = p_section->p_payload_end; } while (p_byte + 2 <= p_end) { uint8_t i_tag = p_byte[0]; uint8_t i_length = p_byte[1]; if (i_length + 2 <= p_end - p_byte) dvbpsi_pmt_es_descriptor_add(p_es, i_tag, i_length, p_byte + 2); p_byte += 2 + i_length; } } p_section = p_section->p_next; } }