def readPMT(self, bits, pos): ''' Method decode next PMT packet :param bits: Packet data in bits format :param pos: Position in packet :return: None ''' try: if self.leng['actual'] + 184 > self.leng['total']: pos.setMinPos((self.leng['total'] - self.leng['actual']) * 8) pos.setCrc() else: self.leng['actual'] = self.leng['actual'] + 184 while True: if self.pmtItem['stream_type'] == None: self.pmtItem['stream_type'] = getBits(bits, pos, 4) if self.pmtItem['reserved_1'] == None: self.pmtItem['reserved_1'] = getBits(bits, pos, 4) if self.pmtItem['elementary_PID'] == None: self.pmtItem['elementary_PID'] = getBits(bits, pos, 12) if self.pmtItem['reserved_2'] == None: self.pmtItem['reserved_2'] = getBits(bits, pos, 4) if self.pmtItem['ES_info_length'] == None: self.pmtItem['ES_info_length'] = getBits(bits, pos, 12) getBits(bits, pos, self.pmtItem['ES_info_length'] * 8) getBits(bits, pos, 4) self.pmtData['data'].append(self.pmtItem) self.pmtItem = self.getClearPmtItem() except CRC: if self.pmtData['crc_32'] == None: self.pmtData['crc_32'] = getBits(bits, pos, 32, True) except PositionZero: return
def DVBDescriptorTagDecoder(self, bits, pos): ''' DVB deskriptor tag Decoder :param bits: Data in bits format :param pos: position in packet :return: ''' item = { 'DVB_descriptor_tag': None, 'descriptor_length': None, 'data': None } item['DVB_descriptor_tag'] = getBits(bits, pos, 8) item['descriptor_length'] = getBits(bits, pos, 8) if item['DVB_descriptor_tag'] == 74: #linkage deskroptor item['data'] = self.linkageDescriptor(bits, pos) elif item[ 'DVB_descriptor_tag'] == 90: #terrestrial_delivery_system_descriptor item['data'] = self.terrestrialDeliverySystemDescriptor(bits, pos) elif item['DVB_descriptor_tag'] == 98: #frequency_list_descriptor pos.addMin(item['descriptor_length'] * 8) item['data'] = self.frequencyListDescriptor(bits, pos) elif item['DVB_descriptor_tag'] == 64: pos.addMin(item['descriptor_length'] * 8) item['data'] = self.networkNameDescriptor(bits, pos) else: return None return item
def readPAT(self, bits,pos): ''' Method decode next PAT packet :param bits: Packet data in bits format :param pos: Position in packet :return: None ''' try: if self.leng['actual']+184 > self.leng['total']: pos.setMinPos((self.leng['total']-self.leng['actual'])*8) pos.setCrc() else: self.leng['actual']=self.leng['actual']+184 while True: if self.patItem['program_number'] == None: self.patItem['program_number'] = getBits(bits,pos,16) if self.patItem['reserved'] == None: self.patItem['reserved'] = getBits(bits,pos,3) if self.patItem['program_number'] == 0: if self.patItem['network_PID'] == None: self.patItem['network_PID'] = getBits(bits,pos,13) else: if self.patItem['program_map_pid'] == None: self.patItem['program_map_pid'] = getBits(bits,pos,13) self.patData['data'].append(self.patItem) self.patItem = self.getClearPatItem() except CRC: if self.patData['crc_32'] == None: self.patData['crc_32'] = getBits(bits,pos,32,True) except PositionZero: return()
def readHeader(self, bits): ''' Method read header of ts file :param bits: header bits :return: header structure ''' pos = Position(32) sync_byte = getBits(bits,pos,8) transport_error_indicator = getBits(bits,pos,1) payload_unit_start_indicator = getBits(bits,pos,1) transport_priority = getBits(bits,pos,1) pid = getBits(bits,pos,13) if not pid in self.pidDict.keys(): self.pidDict[pid] = {'count':0, 'byterate':0} else: self.pidDict[pid]['count'] = self.pidDict[pid]['count'] + 1 transport_scrambling_control = getBits(bits,pos,2) adaptation_field_control = getBits(bits,pos,1) payload_flag = getBits(bits,pos,1) continuity_counter = getBits(bits,pos,4) return({'sync_byte':sync_byte,'transport_error_indicator':transport_error_indicator ,'payload_unit_start_indicator':payload_unit_start_indicator, 'transport_priority':transport_priority,'pid':pid, 'transport_scrambling_control':transport_scrambling_control, 'adaptation_field_control':adaptation_field_control, 'payload_flag':payload_flag,'continuity_counter':continuity_counter})
def frequencyListDescriptor(self, bits, pos): ''' Method decode frequency list descriptor :param bits: Data in bits format :param pos: position in packet :return: ''' item = { 'reserved_future_use': None, 'coding_type': None, 'centre_frequency': [] } item['reserved_future_use'] = getBits(bits, pos, 6) item['coding_type'] = getBits(bits, pos, 2) try: while True: item['centre_frequency'].append(getBits(bits, pos, 32)) except: return item
def streamType3(self, bits, pos): ''' Method decode stream type 3 :param bits: Packet data in bits format :param pos: Position in packet :return: None ''' if self.pmtItem['MPEG_DescriptorTag'] == None: self.pmtItem['MPEG_DescriptorTag'] = getBits(bits, pos, 8) if self.pmtItem['descriptor_length'] == None: self.pmtItem['descriptor_length'] = getBits(bits, pos, 8) if self.pmtItem['descriptor_length'] > 0: pos.addMin(self.pmtItem['descriptor_length'] * 8) try: while True: if self.pmtItem['ISO639_language_code'] == None: self.pmtItem['ISO639_language_code'] = self.pmtItem[ 'ISO639_language_code'] + getBits(bits, pos, 8) except MinimalPosition: pass if self.pmtItem['Audio_type'] == None: self.pmtItem['Audio_type'] = getBits(bits, pos, 8)
def networkNameDescriptor(self, bits, pos): ''' Method read network name descriptor :param bits: Data in bits format :param pos: position in packet :return: string with Network name descriptor ''' Network_name = '' try: while True: data = getBits(bits, pos, 8) Network_name = Network_name + chr(data) except MinimalPosition: return Network_name
def streamType2(self, bits, pos): ''' Method decode stream type 2 :param bits: Packet data in bits format :param pos: Position in packet :return: None ''' if self.pmtItem['MPEG_DescriptorTag'] == None: self.pmtItem['MPEG_DescriptorTag'] = getBits(bits, pos, 8) if self.pmtItem['descriptor_length'] == None: self.pmtItem['descriptor_length'] = getBits(bits, pos, 8) if self.pmtItem['multiple_frame_rate_flag'] == None: self.pmtItem['multiple_frame_rate_flag'] = getBits(bits, pos, 1) if self.pmtItem['frame_rate_code'] == None: self.pmtItem['frame_rate_code'] = getBits(bits, pos, 4) if self.pmtItem['MPEG_1_only_flag'] == None: self.pmtItem['MPEG_1_only_flag'] = getBits(bits, pos, 1) if self.pmtItem['constrained_parameter_flag'] == None: self.pmtItem['constrained_parameter_flag'] = getBits(bits, pos, 1) if self.pmtItem['still_picture_flag'] == None: self.pmtItem['still_picture_flag'] = getBits(bits, pos, 1)
def linkageDescriptor(self, bits, pos): ''' Method decode linkage descriptor :param bits: Data in bits format :param pos: position in packet :return: ''' item = { 'transport_stream_ID': None, 'original_network_ID': None, 'service_ID': None, 'linkage_type': None, 'OUI_data_length': None, 'OUI': None, 'selector_length': None } item['transport_stream_ID'] = getBits(bits, pos, 16) item['original_network_ID'] = getBits(bits, pos, 16) item['service_ID'] = getBits(bits, pos, 16) item['linkage_type'] = getBits(bits, pos, 8) item['OUI_data_length'] = getBits(bits, pos, 8) item['OUI'] = getBits(bits, pos, 24) item['selector_length'] = getBits(bits, pos, 8) return item
def readNIT(self, bits, pos): ''' Method read nit packet :param bits: Packet data in bits format :param pos: Position in packet :return: ''' try: self.nitData['table_id'] = getBits(bits, pos, 8) self.nitData['section_syntax_indicator'] = getBits(bits, pos, 1) self.nitData['reserved_1'] = getBits(bits, pos, 1) self.nitData['reserved_2'] = getBits(bits, pos, 2) self.nitData['section_length'] = getBits(bits, pos, 12) pos.setMinPos(self.nitData['section_length'] * 8) self.nitData['network_id'] = getBits(bits, pos, 16) self.nitData['reserved_3'] = getBits(bits, pos, 2) self.nitData['version_number'] = getBits(bits, pos, 5) self.nitData['current_next_indicator'] = getBits(bits, pos, 1) self.nitData['section_number'] = getBits(bits, pos, 8) self.nitData['last_section_number'] = getBits(bits, pos, 8) self.nitData['reserved_4'] = getBits(bits, pos, 4) self.nitData['network_descriptors_length'] = getBits(bits, pos, 12) pos.addMin(self.nitData['network_descriptors_length'] * 8) try: while True: self.nitData['DVBDescriptorTags'].append( self.DVBDescriptorTagDecoder(bits, pos)) except MinimalPosition: pass self.nitData['reserved_5'] = getBits(bits, pos, 4) self.nitData['transport_stream_loop_length'] = getBits( bits, pos, 12) pos.addMin(self.nitData['transport_stream_loop_length'] * 8) try: while True: item = { 'transport_stream_ID': None, 'original_network_ID': None, 'reserved': None, 'transport_descriptors_length': None, 'DVBDescriptorTags': [] } item['transport_stream_ID'] = getBits(bits, pos, 16) self.nitData['transport_stream_loop'].append(item) item['original_network_ID'] = getBits(bits, pos, 16) item['reserved'] = getBits(bits, pos, 4) item['transport_descriptors_length'] = getBits( bits, pos, 12) pos.addMin(item['transport_descriptors_length'] * 8) try: while True: item['DVBDescriptorTags'].append( self.DVBDescriptorTagDecoder(bits, pos)) except MinimalPosition: pass except MinimalPosition: pass except CRC: self.nitData['CRC_32'] = getBits(bits, pos, 32, True)
def terrestrialDeliverySystemDescriptor(self, bits, pos): ''' Method decode terrestrial delivery system descriptor :param bits: Data in bits format :param pos: position in packet :return: ''' item = { 'center_frequency': None, 'brandwidth': None, 'brandwidthValue': None, 'priority': None, 'time_slicing_indicator': None, 'MPE_FEC_indicator': None, 'reserved_1': None, 'constellation': None, 'constellationValue': None, 'hierarchy_information': None, 'Code_rate_HP_stream': None, 'Code_rate_LP_stream': None, 'code_rateValue': None, 'guard_interval': None, 'guard_intervalValue': None, 'transmission_mode': None, 'other_frequency_flag': None, 'reserved_future_use': None } item['center_frequency'] = getBits(bits, pos, 32) item['brandwidth'] = getBits(bits, pos, 3) item['brandwidthValue'] = self.getBrandwitchValue(item['brandwidth']) item['priority'] = getBits(bits, pos, 1) item['time_slicing_indicator'] = getBits(bits, pos, 1) item['MPE_FEC_indicator'] = getBits(bits, pos, 1) item['reserved_1'] = getBits(bits, pos, 2) item['constellation'] = getBits(bits, pos, 2) item['constellationValue'] = self.getConstellationValue( item['constellation']) item['hierarchy_information'] = getBits(bits, pos, 3) item['Code_rate_HP_stream'] = getBits(bits, pos, 3) item['code_rateValue'] = self.getCodeRateValue( item['Code_rate_HP_stream']) item['Code_rate_LP_stream'] = getBits(bits, pos, 3) item['guard_interval'] = getBits(bits, pos, 2) item['guard_intervalValue'] = self.getGuardIntervalValue( item['guard_interval']) item['transmission_mode'] = getBits(bits, pos, 2) item['other_frequency_flag'] = getBits(bits, pos, 1) item['reserved_future_use'] = getBits(bits, pos, 32) return item
def readHeader(self, bits, pos): ''' Method read PMT header :param bits: Packet data in bits format :param pos: Position in packet :return: None ''' header = { 'table_id': None, 'section_syntax_indicator': None, 'fixed': None, 'reserved_1': None, 'section_length': None, 'program_number': None, 'reserved_2': None, 'version_number': None, 'current_next_indicator': None, 'section_number': None, 'last_section_number': None, 'reserved_3': None, 'PCR_PID': None, 'reserved_4': None, 'program_info_length': None } getBits(bits, pos, 8) header['table_id'] = getBits(bits, pos, 8) header['section_syntax_indicator'] = getBits(bits, pos, 1) header['fixed'] = getBits(bits, pos, 1) header['reserved_1'] = getBits(bits, pos, 2) header['section_length'] = getBits(bits, pos, 12) self.leng['total'] = header['section_length'] header['program_number'] = getBits(bits, pos, 16) header['reserved_2'] = getBits(bits, pos, 2) header['version_number'] = getBits(bits, pos, 5) header['current_next_indicator'] = getBits(bits, pos, 1) header['section_number'] = getBits(bits, pos, 8) header['last_section_number'] = getBits(bits, pos, 8) header['reserved_3'] = getBits(bits, pos, 4) header['PCR_PID'] = getBits(bits, pos, 12) header['reserved_4'] = getBits(bits, pos, 4) header['program_info_length'] = getBits(bits, pos, 16) return header
def readHeader(self,bits,pos): ''' Method read header of nit packet :param bits: Packet data in bits format :param pos: Position in packet :return: None ''' getBits(bits,pos,8) header = {'table_id':None,'section_syntax_indicator':None,'fixed':None,'reserved_1':None,'section_length':None ,'transport_stream_id':None,'reserved_2':None,'version_number':None,'current_next_indicator':None ,'section_number':None,'last_section_number':None} header['table_id'] = getBits(bits,pos,8) header['section_syntax_indicator'] = getBits(bits,pos,1) header['fixed'] = getBits(bits,pos,1) header['reserved_1'] = getBits(bits,pos,2) header['section_length'] = getBits(bits,pos,12) self.leng['total'] = header['section_length'] header['transport_stream_id'] = getBits(bits,pos,16) header['reserved_2'] = getBits(bits,pos,2) header['version_number'] = getBits(bits,pos,5) header['current_next_indicator'] = getBits(bits,pos,1) header['section_number'] = getBits(bits,pos,8) header['last_section_number'] = getBits(bits,pos,8) return header