Пример #1
0
    def handleSdp(self, data):
        """ Called with SDP Response data
        Uses the SDP response to construct the file header """
        sdp = Sdpplin(data)
        header = rmff_header_t()
        try: abstract = sdp['Abstract']
        except KeyError: abstract = ''
        header.fileheader = rmff_fileheader_t(4 + sdp['StreamCount'])
        try: title = sdp['Title']
        except KeyError: title = ''
        try: author = sdp['Author']
        except KeyError: author = ''
        try: copyright = sdp['Copyright']
        except KeyError: copyright = ''
        header.cont = rmff_cont_t(title, author,
                                  copyright, abstract)
        header.data = rmff_data_t(0, 0)

        duration = 0
        max_bit_rate = 0
        avg_bit_rate = 0
        max_packet_size = 0
        avg_packet_size = None
        
        self.streammatches = {}
        
        # the rulebook is sometimes truncated and spread across the streams
        # not sure if this is common, or even the correct way to handle it
        rulebook = ''.join([s['ASMRuleBook'] for s in sdp.streams])
        symbols = {'Bandwidth':self.factory.bandwidth,'OldPNMPlayer':'0'}
        rulematches, symbols = Asmrp.asmrp_match(rulebook, symbols)
        # Avg packet size seems off
        
        for s in sdp.streams:
            self.streammatches[s['streamid']] = rulematches
            mlti = self.select_mlti_data(s['OpaqueData'], rulematches[0])
            
            # some streams don't have the starttime, but do have endtime
            # and other meta data
            try: start_time = s['StartTime']
            except: start_time = 0
            
            mdpr = rmff_mdpr_t(s['streamid'], s['MaxBitRate'],
                               s['AvgBitRate'], s['MaxPacketSize'],
                               s['AvgPacketSize'], start_time,
                               s['Preroll'], s.duration,
                               s['StreamName'], s['mimetype'], mlti)
            header.streams.append(mdpr)
            if s.duration > duration:
                duration = s.duration
            if mdpr.max_packet_size > max_packet_size:
                max_packet_size = mdpr.max_packet_size
            max_bit_rate += mdpr.max_bit_rate
            avg_bit_rate += mdpr.avg_bit_rate
            if avg_packet_size is None:
                avg_packet_size = mdpr.avg_packet_size
            else:
                avg_packet_size = (avg_packet_size + mdpr.avg_packet_size)/2
        header.prop = rmff_prop_t(max_bit_rate, avg_bit_rate,
                                  max_packet_size, avg_packet_size,
                                  0, duration, 0, 0, 0, sdp['StreamCount'],
                                  sdp['Flags'])
        return header
Пример #2
0
    def handleSdp(self, data):
        """ Called with SDP Response data
        Uses the SDP response to construct the file header """
        sdp = Sdpplin(data)
        header = rmff_header_t()
        try:
            abstract = sdp['Abstract']
        except KeyError:
            abstract = ''
        header.fileheader = rmff_fileheader_t(4 + sdp['StreamCount'])
        try:
            title = sdp['Title']
        except KeyError:
            title = ''
        try:
            author = sdp['Author']
        except KeyError:
            author = ''
        try:
            copyright = sdp['Copyright']
        except KeyError:
            copyright = ''
        header.cont = rmff_cont_t(title, author, copyright, abstract)
        header.data = rmff_data_t(0, 0)

        duration = 0
        max_bit_rate = 0
        avg_bit_rate = 0
        max_packet_size = 0
        avg_packet_size = None

        self.streammatches = {}

        # the rulebook is sometimes truncated and spread across the streams
        # not sure if this is common, or even the correct way to handle it
        rulebook = ''.join([s['ASMRuleBook'] for s in sdp.streams])
        symbols = {'Bandwidth': self.factory.bandwidth, 'OldPNMPlayer': '0'}
        rulematches, symbols = Asmrp.asmrp_match(rulebook, symbols)
        # Avg packet size seems off

        for s in sdp.streams:
            self.streammatches[s['streamid']] = rulematches
            mlti = self.select_mlti_data(s['OpaqueData'], rulematches[0])

            # some streams don't have the starttime, but do have endtime
            # and other meta data
            try:
                start_time = s['StartTime']
            except:
                start_time = 0

            mdpr = rmff_mdpr_t(s['streamid'], s['MaxBitRate'], s['AvgBitRate'],
                               s['MaxPacketSize'], s['AvgPacketSize'],
                               start_time, s['Preroll'], s.duration,
                               s['StreamName'], s['mimetype'], mlti)
            header.streams.append(mdpr)
            if s.duration > duration:
                duration = s.duration
            if mdpr.max_packet_size > max_packet_size:
                max_packet_size = mdpr.max_packet_size
            max_bit_rate += mdpr.max_bit_rate
            avg_bit_rate += mdpr.avg_bit_rate
            if avg_packet_size is None:
                avg_packet_size = mdpr.avg_packet_size
            else:
                avg_packet_size = (avg_packet_size + mdpr.avg_packet_size) / 2
        header.prop = rmff_prop_t(max_bit_rate, avg_bit_rate, max_packet_size,
                                  avg_packet_size, 0, duration, 0, 0, 0,
                                  sdp['StreamCount'], sdp['Flags'])
        return header
Пример #3
0
 def test_equal_lots_of_whitespace(self):
     rulestring = '#    (   10   ==   10   )   ,   result   =   1'
     symbols = {'result':'0'}
     rulematches, symbols = Asmrp.asmrp_match(rulestring, symbols)
     self.assertEqual(symbols['result'], '1')
Пример #4
0
 def test_equal_multiple_assignments_whitespace(self):
     rulestring = '#  (  10  ==  10  )  ,  res  =  2  ,  result  =  1  ;'
     symbols = {'result':'0','res':'0'}
     rulematches, symbols = Asmrp.asmrp_match(rulestring, symbols)
     self.assertEqual(symbols['result'], '1')
     self.assertEqual(symbols['res'], '2')
Пример #5
0
 def test_equal_no_semicolon(self):
     rulestring = '#(10 == 10),result=1'
     symbols = {'result':'0'}
     rulematches, symbols = Asmrp.asmrp_match(rulestring, symbols)
     self.assertEqual(symbols['result'], '1')
Пример #6
0
 def test_equal_fail(self):
     rulestring = '#(10 == 1000),result=1;'
     symbols = {'result':'0'}
     rulematches, symbols = Asmrp.asmrp_match(rulestring, symbols)
     self.assertEqual(symbols['result'], '0')
Пример #7
0
 def test_lessthan(self):
     rulestring = '#(10 < 1000),result=1;'
     symbols = {'result':'0'}
     rulematches, symbols = Asmrp.asmrp_match(rulestring, symbols)
     self.assertEqual(symbols['result'], '1')
Пример #8
0
 def test_greaterthan(self):
     rulestring = '#(50 > 5),result=1;'
     symbols = {'result':'0'}
     rulematches, symbols = Asmrp.asmrp_match(rulestring, symbols)
     self.assertEqual(symbols['result'], '1')
Пример #9
0
 def test_actual(self):
     rulestring = '#($Bandwidth < 41556),TimestampDelivery=T,DropByN=T,priority=9;#($Bandwidth >= 41556) && ($Bandwidth < 84000),AverageBandwidth=41556,Priority=9;#($Bandwidth >= 41556) && ($Bandwidth < 84000),AverageBandwidth=0,Priority=5,OnDepend=\"1\";#($Bandwidth >= 84000),AverageBandwidth=84000,Priority=9;#($Bandwidth >= 84000),AverageBandwidth=0,Priority=5,OnDepend=\"3\";'
     symbols = {'Bandwidth':85000}
     rulematches, symbols = Asmrp.asmrp_match(rulestring,symbols)
     self.assertEqual(rulematches, [3,4])