Example #1
0
    def do_RTP(self, session, event):
        '''
        Method called when an rtp data packet arrives.
        '''
        packet = common.make_rtp_packet(event.data)
        data = common.rtp_packet_getdata(packet)
        
        # require H261 as input
        if packet.pt != 31:
            common.free_rtp_packet(packet)
            return
                 
        # only forward selected source
        if self.selector:
            if not packet.ssrc == self.allowedSource:
                common.free_rtp_packet(packet)
                return

        pt = 31

        destination = None

        try:
            # Create a new source for each stream to send
            # to the multicast address. Each new source is
            # keeping track of its own timestamp.
            
            if self.sources.has_key(packet.ssrc):
                destination = self.sources[packet.ssrc]

            else:
                destination = common.Rtp(self.to_address, self.to_port,
                                         self.to_port, 127,
                                         64000.0, None)
                dest_ssrc = destination.my_ssrc()
                tool = "audiotest.py"
                name = "RTP Messer"
                destination.set_sdes(dest_ssrc, common.RTCP_SDES_TOOL,
                                          tool, len(tool))
                destination.set_sdes(dest_ssrc, common.RTCP_SDES_NAME,
                                          name, len(name))

                
                #destination.send_ctrl(0, None)
                self.sources[packet.ssrc] = destination
               
            # Send data
            ts = 0
            destination.send_data(ts, packet.pt, packet.m,
                                  packet.cc, packet.csrc,
                                  data, len(data),
                                  packet.extn, packet.extn_len,
                                  packet.extn_type)

            # Increment timestamp
                       
        except Exception, e:
            print "Exception sending data, ", e
Example #2
0
    def do_RTP(self, session, event):
        '''
        Method called when an rtp data packet arrives.
        '''
        packet = common.make_rtp_packet(event.data)
        data = common.rtp_packet_getdata(packet)

        # require H261 as input
        if packet.pt != 31:
            common.free_rtp_packet(packet)
            return

        # only forward selected source
        if self.selector:
            if not packet.ssrc == self.allowedSource:
                common.free_rtp_packet(packet)
                return

        pt = 31

        destination = None

        try:
            # Create a new source for each stream to send
            # to the multicast address. Each new source is
            # keeping track of its own timestamp.

            if self.sources.has_key(packet.ssrc):
                destination = self.sources[packet.ssrc]

            else:
                destination = common.Rtp(self.to_address, self.to_port,
                                         self.to_port, 127, 64000.0, None)
                dest_ssrc = destination.my_ssrc()
                tool = "audiotest.py"
                name = "RTP Messer"
                destination.set_sdes(dest_ssrc, common.RTCP_SDES_TOOL, tool,
                                     len(tool))
                destination.set_sdes(dest_ssrc, common.RTCP_SDES_NAME, name,
                                     len(name))

                #destination.send_ctrl(0, None)
                self.sources[packet.ssrc] = destination

            # Send data
            ts = 0
            destination.send_data(ts, packet.pt,
                                  packet.m, packet.cc, packet.csrc, data,
                                  len(data), packet.extn, packet.extn_len,
                                  packet.extn_type)

            # Increment timestamp

        except Exception, e:
            print "Exception sending data, ", e
Example #3
0
    def do_RTP(self, session, event):
        '''
        Method called when an rtp data packet arrives.
        '''
        packet = common.make_rtp_packet(event.data)
        data = common.rtp_packet_getdata(packet)

        # require l16-16k mono as input
        if packet.pt != 112:
            common.free_rtp_packet(packet)
            return

        # only forward selected source
        if self.selector:
            if not packet.ssrc == self.allowedSource:
                common.free_rtp_packet(packet)
                return

        # down sample the data
        args = []
        fmt = '%dh' % (len(data) / 4)
        s = struct.unpack('%dh' % (len(data) / 2), data)
        args.append(fmt)
        for i in range(0, len(s), 2):
            args.append(s[i])

        sdata = apply(struct.pack, args)

        # buffer the data
        if self.buffers.has_key(packet.ssrc) and self.buffers[packet.ssrc]:
            packets = self.buffers[packet.ssrc]
            packets = self.buffers[packet.ssrc] + sdata
            self.buffers[packet.ssrc] = packets

        else:
            self.buffers[packet.ssrc] = sdata
            common.free_rtp_packet(event.data)
            return

        # L16 - 8kHz
        pt = 122

        destination = None

        try:
            data = self.buffers[packet.ssrc]

            # Create a new source for each stream to send
            # to the multicast address. Each new source is
            # keeping track of its own timestamp.

            if self.sources.has_key(packet.ssrc):
                destination = self.sources[packet.ssrc]

            else:
                destination = common.Rtp(self.to_address, self.to_port,
                                         self.to_port, 127, 64000.0, None)
                dest_ssrc = destination.my_ssrc()
                tool = "audiotest.py"
                name = "RTP Messer"
                destination.set_sdes(dest_ssrc, common.RTCP_SDES_TOOL, tool,
                                     len(tool))
                destination.set_sdes(dest_ssrc, common.RTCP_SDES_NAME, name,
                                     len(name))
                destination.send_ctrl(0, None)
                self.sources[packet.ssrc] = destination

            # Each source keeps track of its own timestamp.
            if self.timeStamps.has_key(packet.ssrc):
                ts = self.timeStamps[packet.ssrc]
            else:
                self.timeStamps[packet.ssrc] = 0
                ts = 0

            # Send data
            destination.send_data(ts, pt,
                                  packet.m, packet.cc, packet.csrc, data,
                                  len(data), packet.extn, packet.extn_len,
                                  packet.extn_type)

            # Increment timestamp
            self.timeStamps[packet.ssrc] = ts + 160

        except Exception, e:
            print "Exception sending data, ", e
    def do_RTP(self, session, event):
        '''
        Method called when an rtp data packet arrives.
        '''
        packet = common.make_rtp_packet(event.data)
        data = common.rtp_packet_getdata(packet)
        
        # require l16-16k mono as input
        if packet.pt != 112:
            common.free_rtp_packet(packet)
            return
         
        # only forward selected source
        if self.selector:
            if not packet.ssrc == self.allowedSource:
                common.free_rtp_packet(packet)
                return

        # down sample the data
        args = []
        fmt = '%dh' % (len(data)/4)
        s = struct.unpack('%dh' % (len(data)/2) , data)
        args.append(fmt)
        for i in range(0, len(s), 2):
            args.append(s[i])
            
        sdata = apply(struct.pack,args)

        # buffer the data
        if self.buffers.has_key(packet.ssrc) and self.buffers[packet.ssrc]:
            packets = self.buffers[packet.ssrc]
            packets = self.buffers[packet.ssrc] + sdata
            self.buffers[packet.ssrc] = packets
            
        else:
            self.buffers[packet.ssrc] = sdata
            common.free_rtp_packet(event.data)
            return

        # L16 - 8kHz
        pt = 122

        destination = None

        try:
            data = self.buffers[packet.ssrc]
            
            # Create a new source for each stream to send
            # to the multicast address. Each new source is
            # keeping track of its own timestamp.
            
            if self.sources.has_key(packet.ssrc):
                destination = self.sources[packet.ssrc]

            else:
                destination = common.Rtp(self.to_address, self.to_port,
                                         self.to_port, 127,
                                         64000.0, None)
                dest_ssrc = destination.my_ssrc()
                tool = "audiotest.py"
                name = "RTP Messer"
                destination.set_sdes(dest_ssrc, common.RTCP_SDES_TOOL,
                                          tool, len(tool))
                destination.set_sdes(dest_ssrc, common.RTCP_SDES_NAME,
                                          name, len(name))
                destination.send_ctrl(0, None)
                self.sources[packet.ssrc] = destination
               

            # Each source keeps track of its own timestamp.
            if self.timeStamps.has_key(packet.ssrc):
                ts = self.timeStamps[packet.ssrc]
            else:
                self.timeStamps[packet.ssrc] = 0
                ts = 0

            # Send data
            destination.send_data(ts, pt, packet.m,
                                  packet.cc, packet.csrc,
                                  data, len(data),
                                  packet.extn, packet.extn_len,
                                  packet.extn_type)

            # Increment timestamp
            self.timeStamps[packet.ssrc] = ts + 160

           
        except Exception, e:
            print "Exception sending data, ", e