Пример #1
0
    def test_packet_with_recovery(self):
        midi_list = [[[128, 10, 0], 1000], [[144, 32, 110], 1000]]

        recovery_journal_system = RecoveryJournal()
        seq = 12

        #midi session part (sending)
        packet = OldPacket(seq, midi_list, 0)

        midi_list_formated, length = MidiCommand().encode_midi_commands(
            midi_list)
        header = MidiCommand().header(0, 1, 0, 0, length)

        #Building Chunk

        recovery_journal_system.update(packet)
        recovery_journal = recovery_journal_system.content

        chunk = header + midi_list_formated + recovery_journal
        #protocol part
        packet = RTPPacket(424242, seq, 10, chunk, 96, marker=1)

        bytes = packet.netbytes()
        packet = parse_rtppacket(bytes)

        #midisession part (receiving)
        marker_b, marker_j, marker_z, marker_p, length = MidiCommand(
        ).parse_header(packet.data[0])
        if marker_p:
            #silent packet with recovery
            midi_list = []

        else:
            #normal packet
            #Extract Midi Note (length en nb notes)
            print "test 1:", len(packet.data[1:length * 7 + 1])
            midi_list = packet.data[1:length * 7 + 1]

            #Decoding midi commands
            midi_list = MidiCommand().decode_midi_commands(midi_list, length)

            #Saving feed history
            packet_to_save = OldPacket(seq, midi_list, 0)

        #Extract Midi Recovery Journal if is present in the packet and
        #the previous packet has been lost
        if marker_j:
            print "recovery journal"
            print len(packet.data[length * 7 + 1:])
            journal = packet.data[length * 7 + 1:]

            #Parse Recovery journal
            r_journal = recovery_journal_system.parse(journal)
Пример #2
0
    def test_packet_with_recovery(self):
	midi_list = [[[128, 10, 0], 1000],
                     [[144, 32, 110], 1000]]

	recovery_journal_system = RecoveryJournal()
	seq = 12

	#midi session part (sending)
	packet = OldPacket(seq, midi_list, 0)

	midi_list_formated, length = MidiCommand().encode_midi_commands(midi_list)
	header = MidiCommand().header(0, 1, 0, 0, length)

        #Building Chunk

	recovery_journal_system.update(packet)
	recovery_journal = recovery_journal_system.content

	chunk = header + midi_list_formated + recovery_journal
	#protocol part
	packet = RTPPacket(424242, seq, 10, chunk, 96, marker=1)

	bytes = packet.netbytes()
	packet = parse_rtppacket(bytes)

	#midisession part (receiving)
	marker_b, marker_j, marker_z, marker_p, length = MidiCommand().parse_header(packet.data[0])
	if marker_p :
            #silent packet with recovery
            midi_list = []

        else:
            #normal packet
            #Extract Midi Note (length en nb notes)
	    print "test 1:", len(packet.data[1:length*7+1])
            midi_list = packet.data[1:length*7+1]

            #Decoding midi commands
            midi_list =  MidiCommand().decode_midi_commands(midi_list, length)

            #Saving feed history
            packet_to_save = OldPacket(seq, midi_list, 0)

	#Extract Midi Recovery Journal if is present in the packet and
        #the previous packet has been lost
        if marker_j:
	    print "recovery journal"
	    print len(packet.data[length*7+1:])
            journal = packet.data[length*7+1:]

            #Parse Recovery journal
            r_journal = recovery_journal_system.parse(journal)
Пример #3
0
    def datagramReceived(self, datagram, addr, t=time):
        """Handle packets arriving"""
        if self.rport == 0:
            return
        if not self.checksum(datagram):
            if VERBOSE:
                print "Warning: Packet received with wrong checksum RTP"
            return
        #parse the packet
        packet = parse_rtppacket(datagram)
        #Checking SSRC
        ssrc = packet.header.ssrc
        if ssrc in self.RTCP.members_table:
            cname = self.RTCP.members_table[ssrc]['cname']
        else:
            cname = ""
        if not self.RTCP.check_ssrc(ssrc, addr, "DATA", cname):
            if VERBOSE:
                print "Warning: Bad SSRC leaving packet on the floor"
            return
        else:
            #Update last_seq and lastreceivetime
            self.RTCP.members_table[ssrc]['total_received_bytes'] += len(
                datagram)
            self.RTCP.members_table[ssrc]['total_received_packets'] += 1
            self.RTCP.members_table[ssrc]['last_rtp_receive'] = time()

            if self.RTCP.members_table[ssrc]['last_seq'] != 0:
                if packet.data == "p":
                    #Silent without recovery
                    if DEBUG:
                        print "silent packet received"
                    #self.RTCP.members_table[ssrc]['last_seq'] += 1
                    return
                #Testing payload type TODO erase this test
                if packet.header.pt == self.payload:
                    if DEBUG:
                        print "payload of packet accepted"
                    #Getting stats
                    last_ts = self.RTCP.members_table[ssrc]['last_ts']
                    last_time = self.RTCP.members_table[ssrc]['last_time']
                    jitter = self.RTCP.members_table[ssrc]['jitter']
                    #Jitter calculation (rfc 3550 6.4.1)
                    #S = RTP Timestamp and R is time of arrival
                    if (last_ts == 0 and last_time == 0) \
                            or ( (int(time()*1000 - self.init_time) \
                                      - last_time) > JITTER_CALC_TIME_OUT ):
                        last_ts = packet.header.ts
                        last_time = int(time() * 1000 - self.init_time)
                    else:
                        arrival_time = int(time() * 1000 - self.init_time)
                        timestamp = packet.header.ts
                        delta = float(( arrival_time - last_time ) \
                                      - ( timestamp - last_ts ))
                        jitter = jitter \
                            + ( abs(delta) - jitter ) / 16
                        self.RTCP.members_table[ssrc]['last_ts'] = timestamp
                        last_time = self.RTCP.members_table[ssrc][
                            'last_time'] = arrival_time
                        self.RTCP.members_table[ssrc]['jitter_values'].to_list(
                            jitter)
                        self.RTCP.members_table[ssrc]['jitter'] = jitter
                    if self.RTCP.members_table[ssrc][
                            'total_received_packets'] % CHECK_FREQ == 0:
                        if DEBUG:
                            print "Estimate jitter time"
                        jitter_average = self.RTCP.members_table[ssrc][
                            'jitter_values'].average()
                        total_received = self.RTCP.members_table[ssrc][
                            'total_received_packets']
                        #Lost rate estimation
                        lost = self.RTCP.members_table[ssrc]['lost']
                        lost_rate = (lost / float(total_received + lost)) * 100
                        #Keep this ?
                        if lost_rate > MAX_LOST_RATE:
                            if VERBOSE:
                                line = "Loosing too much packet !!"
                                print line
                        #Adjusting latency (based on round trip time/jitter)
                        #self.test_jitter()
                        #self.test_delay()

                    #Adding packet to the jitter buffer
                    if DEBUG:
                        print "Adding packet to jitter buffer"
                    self.jitter_buffer.add([packet, time() * 1000])
                else:
                    if VERBOSE:
                        print "Incompatible payload type"
            else:
                #this is the first packet
                if VERBOSE:
                    line = "First RTP packet received from " + str(addr)
                    print line
                self.RTCP.members_table[ssrc]['last_seq'] = packet.header.seq
Пример #4
0
    def datagramReceived(self, datagram, addr, t=time):
        """Handle packets arriving"""
        if self.rport == 0:
            return
        if not self.checksum(datagram):
            if VERBOSE:
                print "Warning: Packet received with wrong checksum RTP"
            return
        #parse the packet
        packet = parse_rtppacket(datagram)
        #Checking SSRC
        ssrc = packet.header.ssrc
        if ssrc in self.RTCP.members_table:
            cname = self.RTCP.members_table[ssrc]['cname']
        else:
            cname = ""
        if not self.RTCP.check_ssrc(ssrc, addr, "DATA", cname):
            if VERBOSE:
                print "Warning: Bad SSRC leaving packet on the floor"
            return
        else:
            #Update last_seq and lastreceivetime
            self.RTCP.members_table[ssrc]['total_received_bytes'] += len(datagram)
            self.RTCP.members_table[ssrc]['total_received_packets'] += 1
            self.RTCP.members_table[ssrc]['last_rtp_receive'] = time()

            if self.RTCP.members_table[ssrc]['last_seq'] != 0 :
                if packet.data == "p":
                    #Silent without recovery
                    if DEBUG :
                        print "silent packet received"
                    #self.RTCP.members_table[ssrc]['last_seq'] += 1
                    return
                #Testing payload type TODO erase this test
                if packet.header.pt == self.payload:
                    if DEBUG:
                        print "payload of packet accepted"
                    #Getting stats
                    last_ts = self.RTCP.members_table[ssrc]['last_ts']
                    last_time = self.RTCP.members_table[ssrc]['last_time']
                    jitter = self.RTCP.members_table[ssrc]['jitter']
                    #Jitter calculation (rfc 3550 6.4.1)
                    #S = RTP Timestamp and R is time of arrival
                    if (last_ts == 0 and last_time == 0) \
                            or ( (int(time()*1000 - self.init_time) \
                                      - last_time) > JITTER_CALC_TIME_OUT ):
                        last_ts = packet.header.ts
                        last_time = int(time()*1000 - self.init_time)
                    else:
                        arrival_time = int(time()*1000 - self.init_time)
                        timestamp = packet.header.ts
                        delta = float(( arrival_time - last_time ) \
                                      - ( timestamp - last_ts ))
                        jitter = jitter \
                            + ( abs(delta) - jitter ) / 16
                        self.RTCP.members_table[ssrc]['last_ts'] = timestamp
                        last_time = self.RTCP.members_table[ssrc]['last_time'] = arrival_time
                        self.RTCP.members_table[ssrc]['jitter_values'].to_list(jitter)
                        self.RTCP.members_table[ssrc]['jitter'] = jitter
                    if self.RTCP.members_table[ssrc]['total_received_packets'] % CHECK_FREQ == 0:
                        if DEBUG:
                            print "Estimate jitter time"
                        jitter_average = self.RTCP.members_table[ssrc]['jitter_values'].average()
                        total_received = self.RTCP.members_table[ssrc]['total_received_packets']
                        #Lost rate estimation
                        lost = self.RTCP.members_table[ssrc]['lost']
                        lost_rate = (lost / float(total_received + lost)) * 100
                        #Keep this ?
                        if lost_rate > MAX_LOST_RATE :
                            if VERBOSE:
                                line = "Loosing too much packet !!"
                                print line
                        #Adjusting latency (based on round trip time/jitter)
                        #self.test_jitter()
                        #self.test_delay()

                    #Adding packet to the jitter buffer
                    if DEBUG:
                        print "Adding packet to jitter buffer"
                    self.jitter_buffer.add([packet, time()*1000])
                else:
                    if VERBOSE:
                        print "Incompatible payload type"
            else:
                #this is the first packet
                if VERBOSE:
                    line = "First RTP packet received from " + str(addr)
                    print line
                self.RTCP.members_table[ssrc]['last_seq'] = packet.header.seq