Пример #1
0
    def parseTable(self, table_id, current_next, sections):

        msg = {
            "table_type": "PMT",
            "table_id": table_id,
            "current": current_next,
        }
        services = {}

        for (data, section_length) in sections:
            service_id = (ord(data[3]) << 8) + ord(data[4])
            service = {}

            service['pcr_pid'] = ((ord(data[8]) << 8) + ord(data[9])) & 0x1fff

            prog_info_length = ((ord(data[10]) << 8) + ord(data[11])) & 0x0fff
            i = 12
            prog_info_end = i + prog_info_length
            service['descriptors'] = []
            while i < prog_info_end:
                print(i, prog_info_end, len(data))
                descriptor, i = parseDescriptor(i, data)
                service['descriptors'].append(descriptor)

            service['streams'] = []
            while i < section_length + 3 - 4:
                stream = {}
                stream['type'] = ord(data[i])
                stream['pid'] = (
                    (ord(data[i + 1]) << 8) + ord(data[i + 2])) & 0x1fff

                es_info_length = (
                    (ord(data[i + 3]) << 8) + ord(data[i + 4])) & 0x0fff
                i = i + 5
                es_info_end = i + es_info_length
                stream['descriptors'] = []
                while i < es_info_end:
                    descriptor, i = parseDescriptor(i, data)
                    stream['descriptors'].append(descriptor)

                service['streams'].append(stream)

                # a little bit of simplification here:
                if stream['type'] in [3, 4] and 'audio_pid' not in service:
                    service['audio_pid'] = stream['pid']
                elif stream['type'] in [1, 2] and 'video_pid' not in service:
                    service['video_pid'] = stream['pid']

            services[service_id] = service
        msg['services'] = services

        return msg
 def parseTable(self, table_id, current_next, sections):
     
     msg = { "table_type"        : "PMT",
             "table_id"          : table_id,
             "current"           : current_next,
           }
     services = {}
     
     for (data,section_length) in sections:
         service_id = (ord(data[3])<<8) + ord(data[4])
         service = {}
         
         service['pcr_pid'] = ( (ord(data[8])<<8) + ord(data[9]) ) & 0x1fff
         
         prog_info_length = ( (ord(data[10])<<8) + ord(data[11]) ) & 0x0fff
         i=12
         prog_info_end = i+prog_info_length
         service['descriptors'] = []
         while i < prog_info_end:
             print i,prog_info_end, len(data)
             descriptor,i = parseDescriptor(i,data)
             service['descriptors'].append(descriptor)
             
         service['streams'] = []
         while i < section_length+3-4:
             stream = {}
             stream['type'] = ord(data[i])
             stream['pid'] = ( (ord(data[i+1])<<8) + ord(data[i+2]) ) & 0x1fff
             
             es_info_length = ( (ord(data[i+3])<<8) + ord(data[i+4]) ) & 0x0fff
             i=i+5
             es_info_end = i+es_info_length
             stream['descriptors'] = []
             while i < es_info_end:
                 descriptor,i = parseDescriptor(i,data)
                 stream['descriptors'].append(descriptor)
                 
             service['streams'].append(stream)
             
             # a little bit of simplification here:
             if   stream['type'] in [3,4] and 'audio_pid' not in service:
                 service['audio_pid'] = stream['pid']
             elif stream['type'] in [1,2] and 'video_pid' not in service:
                 service['video_pid'] = stream['pid']
         
         services[service_id] = service
     msg['services'] = services
     
     return  msg
Пример #3
0
    def parseTable(self, index, sections):
        (table_id, current_next, network_id) = index

        msg = {
            "table_type": "NIT",
            "table_id": table_id,
            "actual_other": self.acceptTables[table_id],
            "current": current_next,
            "network_id": network_id,
            "descriptors": [],
        }
        services = {}

        tss = []
        for (data, section_length) in sections:

            network_descriptors_length = (
                (ord(data[8]) << 8) + ord(data[9])) & 0x0fff
            i = 10
            network_descriptors_end = i + network_descriptors_length
            while i < network_descriptors_end:
                descriptor, i = parseDescriptor(i, data)
                msg['descriptors'].append(descriptor)

            ts_loop_length = ((ord(data[i]) << 8) + ord(data[i + 1])) & 0x0fff
            i = i + 2
            ts_loop_end = i + ts_loop_length
            while i < ts_loop_end:
                ts = {}
                ts['transport_stream_id'] = (ord(data[i]) << 8) + ord(
                    data[i + 1])
                ts['original_network_id'] = (ord(data[i + 2]) << 8) + ord(
                    data[i + 3])

                transport_descriptors_length = (
                    (ord(data[i + 4]) << 8) + ord(data[i + 5])) & 0x0fff
                i = i + 6
                transport_descriptors_end = i + transport_descriptors_length
                ts['descriptors'] = []
                while i < transport_descriptors_end:
                    descriptor, i = parseDescriptor(i, data)
                    ts['descriptors'].append(descriptor)
                tss.append(ts)

        msg['transport_streams'] = tss
        return msg
 def parseTable(self, index, sections):
     (table_id, current_next, network_id) = index
     
     msg = { "table_type"   : "NIT",
             "table_id"     : table_id,
             "actual_other" : self.acceptTables[table_id],
             "current"      : current_next,
             "network_id"   : network_id,
           }
     services = {}
     
     tss = []
     for (data,section_length) in sections:
         
         network_descriptors_length = ((ord(data[8])<<8) + ord(data[9])) & 0x0fff
         i=10
         network_descriptors_end = i+network_descriptors_length
         msg['descriptors'] = []
         while i < network_descriptors_end:
             descriptor, i = parseDescriptor(i,data)
             msg['descriptors'].append(descriptor)
         
         ts_loop_length = ((ord(data[i])<<8) + ord(data[i+1])) & 0x0fff
         i=i+2
         ts_loop_end = i+ts_loop_length
         while i < ts_loop_end:
             ts = {}
             ts['transport_stream_id'] = (ord(data[i])<<8) + ord(data[i+1])
             ts['original_network_id'] = (ord(data[i+2])<<8) + ord(data[i+3])
             
             transport_descriptors_length = ((ord(data[i+4])<<8) + ord(data[i+5])) & 0x0fff
             i=i+6
             transport_descriptors_end = i+transport_descriptors_length
             ts['descriptors'] = []
             while i < transport_descriptors_end:
                 descriptor,i = parseDescriptor(i,data)
                 ts['descriptors'].append(descriptor)
             tss.append(ts)
             
     msg['transport_streams'] = tss
     return  msg
Пример #5
0
    def main(self):
        while not self.shutdown():

            while self.dataReady("inbox"):
                data = self.recv("inbox")

                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in range(0, 3)]

                table_id = e[0]
                if table_id != 0x73:
                    continue

                syntax = e[1] & 0x80
                if syntax:
                    continue

                section_length = ((e[1] << 8) + e[2]) & 0x0fff

                if not dvbcrc(data[:3 + section_length]):
                    continue

                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in range(0, 10)]

                timeNow = list(parseMJD((e[3] << 8) + e[4]))
                timeNow.extend([unBCD(e[5]), unBCD(e[6]), unBCD(e[7])])

                descriptors_length = ((e[8] << 8) + e[9]) & 0x0fff
                i = 10
                descriptors_end = i + descriptors_length
                while i < descriptors_end:
                    (dtype, descriptor), i = parseDescriptor(i, data)
                    if descriptor['type'] == "local_time_offset":
                        table = {
                            "table_type": "TOT",
                            "UTC_now": timeNow,
                            "offset": descriptor['offset'],
                            "next": {
                                "offset": descriptor['nextOffset'],
                                "when": descriptor['timeOfChange'],
                            },
                            "country": descriptor['country'],
                            "region": descriptor['region'],
                        }

                        self.send(table, "outbox")

            self.pause()
            yield 1
Пример #6
0
    def main(self):
        while not self.shutdown():

            while self.dataReady("inbox"):
                data = self.recv("inbox")

                # extract basic info from this PSI packet - enough to work
                # out what table it is; what section, and the version
                e = [ord(data[i]) for i in range(0,3) ]

                table_id = e[0]
                if table_id != 0x73:
                    continue

                syntax = e[1] & 0x80
                if syntax:
                    continue

                section_length = ((e[1]<<8) + e[2]) & 0x0fff

                if not dvbcrc(data[:3+section_length]):
                    continue
                
                # now were reasonably certain we've got a correct packet
                # we'll convert the rest of the packet
                e = [ord(data[i]) for i in range(0,10) ]
                
                timeNow = list( parseMJD((e[3]<<8) + e[4]) )
                timeNow.extend( [unBCD(e[5]), unBCD(e[6]), unBCD(e[7])] )
                
                descriptors_length = ((e[8]<<8) + e[9]) & 0x0fff
                i = 10
                descriptors_end = i + descriptors_length
                while i < descriptors_end:
                    (dtype,descriptor),i = parseDescriptor(i,data)
                    if descriptor['type'] == "local_time_offset":
                        table = { "table_type" : "TOT",
                                  "UTC_now"    : timeNow,
                                  "offset"     : descriptor['offset'],
                                  "next"       : { "offset" : descriptor['nextOffset'],
                                                   "when"   : descriptor['timeOfChange'],
                                                 },
                                  "country"    : descriptor['country'],
                                  "region"     : descriptor['region'],
                                }

                        self.send(table, "outbox")

            self.pause()
            yield 1
Пример #7
0
    def parseTableSection(self, index, section):
        (table_id, service_id, current_next, transport_stream_id,
         original_network_id) = index
        msg = {
            "table_type": "EIT",
            "table_id": table_id,
            "actual_other": self.acceptTables[table_id][0],
            "is_present_following": self.acceptTables[table_id][1],
            "current": current_next,
            "transport_stream_id": transport_stream_id,
            "original_network_id": original_network_id,
            "events": [],
        }

        (data, section_length) = section

        service_id = (ord(data[3]) << 8) + ord(data[4])

        i = 14
        while i < section_length + 3 - 4:
            e = [ord(data[x]) for x in range(i + 0, i + 12)]

            event = {"service_id": service_id}

            event["event_id"] = (e[0] << 8) + e[1]
            # ( Y,M,D, HH,MM,SS )
            event["starttime"] = list(parseMJD((e[2] << 8) + e[3]))
            event["starttime"].extend([unBCD(e[4]), unBCD(e[5]), unBCD(e[6])])
            event["duration"] = unBCD(e[7]), unBCD(e[8]), unBCD(e[9])
            event["running_status"] = (e[10] >> 5) & 0x07
            event["free_CA_mode"] = e[10] & 0x10

            descriptors_length = ((e[10] << 8) + e[11]) & 0x0fff
            event["descriptors"] = []
            i = i + 12
            descriptors_end = i + descriptors_length
            while i < descriptors_end:
                descriptor, i = parseDescriptor(i, data)
                event['descriptors'].append(descriptor)

            msg["events"].append(event)

        return msg
 def parseTableSection(self, index, section):
     (table_id, service_id, current_next, transport_stream_id, original_network_id) = index
     msg = { "table_type"          : "EIT",
             "table_id"            : table_id,
             "actual_other"        : self.acceptTables[table_id][0],
             "is_present_following": self.acceptTables[table_id][1],
             "current"             : current_next,
             "transport_stream_id" : transport_stream_id,
             "original_network_id" : original_network_id,
             "events"              : [],
           }
     
     (data,section_length) = section
         
     service_id = (ord(data[3])<<8) + ord(data[4])
         
     i=14
     while i < section_length+3-4:
         e = [ord(data[x]) for x in range(i+0,i+12)]
         
         event = { "service_id" : service_id }
         
         event["event_id"] = (e[0]<<8) + e[1]
         # ( Y,M,D, HH,MM,SS )
         event["starttime"] = list( parseMJD((e[2]<<8) + e[3]) )
         event["starttime"].extend( [unBCD(e[4]), unBCD(e[5]), unBCD(e[6])] )
         event["duration"] = unBCD(e[7]), unBCD(e[8]), unBCD(e[9])
         event["running_status"] = (e[10] >> 5) & 0x07
         event["free_CA_mode"] = e[10] & 0x10
         
         descriptors_length = ((e[10]<<8) + e[11]) & 0x0fff
         event["descriptors"] = []
         i=i+12
         descriptors_end = i + descriptors_length
         while i < descriptors_end:
             descriptor,i = parseDescriptor(i,data)
             event['descriptors'].append(descriptor)
             
         msg["events"].append(event)
     
     return  msg
Пример #9
0
    def parseTable(self, index, sections):
        (table_id, current_next, transport_stream_id,
         original_network_id) = index

        msg = {
            "table_type": "SDT",
            "table_id": table_id,
            "actual_other": self.acceptTables[table_id],
            "current": current_next,
            "transport_stream_id": transport_stream_id,
            "original_network_id": original_network_id,
        }
        services = {}

        for (data, section_length) in sections:

            i = 11
            while i < section_length + 3 - 4:
                service_id = (ord(data[i]) << 8) + ord(data[i + 1])
                service = {}

                lo = ord(data[i + 2])
                service['eit_schedule'] = lo & 0x02
                service['eit_present_following'] = lo & 0x01
                hi = ord(data[i + 3])
                service['running_status'] = hi >> 5
                service['free_CA_mode'] = hi & 0x10

                descriptors_length = ((hi << 8) + ord(data[i + 4])) & 0x0fff
                i = i + 5
                descriptors_end = i + descriptors_length
                service['descriptors'] = []
                while i < descriptors_end:
                    descriptor, i = parseDescriptor(i, data)
                    service['descriptors'].append(descriptor)

                services[service_id] = service

        msg['services'] = services

        return msg
 def parseTable(self, index, sections):
     (table_id, current_next, transport_stream_id, original_network_id) = index
     
     msg = { "table_type"          : "SDT",
             "table_id"            : table_id,
             "actual_other"        : self.acceptTables[table_id],
             "current"             : current_next,
             "transport_stream_id" : transport_stream_id,
             "original_network_id" : original_network_id,
           }
     services = {}
     
     for (data,section_length) in sections:
         
         i=11
         while i < section_length+3-4:
             service_id = (ord(data[i])<<8) + ord(data[i+1])
             service = {}
             
             lo = ord(data[i+2])
             service['eit_schedule']          = lo & 0x02
             service['eit_present_following'] = lo & 0x01
             hi = ord(data[i+3])
             service['running_status']        = hi >> 5
             service['free_CA_mode']          = hi & 0x10
             
             descriptors_length = ((hi<<8) + ord(data[i+4])) & 0x0fff
             i = i + 5
             descriptors_end = i + descriptors_length
             service['descriptors'] = []
             while i < descriptors_end:
                 descriptor,i = parseDescriptor(i,data)
                 service['descriptors'].append(descriptor)
                 
             services[service_id] = service
         
     msg['services'] = services
     
     return  msg