Пример #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
Пример #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
Пример #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
Пример #4
0
class L16_to_L8(RTPSensor):
    '''
    Class for down-sampling L16-16kHz to L16-8kHz audio. 
    '''
    def __init__(self,
                 from_address,
                 from_port,
                 to_address,
                 to_port,
                 selector=0):
        RTPSensor.__init__(self, from_address, from_port)
        self.handlerDict[0] = self.do_RTP
        self.handlerDict[3] = self.do_SDES
        self.buffers = {}
        self.sources = {}
        self.sdes = {}
        self.selector = selector
        self.timeStamps = {}
        self.to_address = to_address
        self.to_port = to_port
        self.allowedSource = None

    # Access methods
    def GetSources(self):
        return self.sdes

    def SetAllowedSource(self, ssrc):
        self.allowedSource = ssrc

    def do_SDES(self, session, event):
        sdestype, sdes = common.make_sdes_item(event.data)
        ssrc = event.ssrc

        if self.sdes.has_key(ssrc):
            if sdestype == 2:
                self.sdes[ssrc] = sdes
        else:
            if ((sdestype == 1) or (sdestype == 2)):
                self.sdes[ssrc] = sdes

    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

        # Send control packet
        destination.send_ctrl(self.timeStamps[packet.ssrc], None)
        destination.update()

        common.free_rtp_packet(event.data)

        # Clear the buffer
        self.buffers[packet.ssrc] = None
Пример #5
0
class VideoSelector(RTPSensor):
    '''
    Class for down-sampling L16-16kHz to L16-8kHz audio. 
    '''
    def __init__(self,
                 from_address,
                 from_port,
                 to_address,
                 to_port,
                 selector=0):
        RTPSensor.__init__(self, from_address, from_port)
        self.handlerDict[0] = self.do_RTP
        self.handlerDict[3] = self.do_SDES
        self.buffers = {}
        self.sources = {}
        self.sdes = {}
        self.selector = selector
        self.to_address = to_address
        self.to_port = to_port
        self.allowedSource = None

    # Access methods
    def GetSources(self):
        return self.sdes

    def SetAllowedSource(self, ssrc):
        self.allowedSource = ssrc

    def do_SDES(self, session, event):
        sdestype, sdes = common.make_sdes_item(event.data)
        ssrc = event.ssrc

        if self.sdes.has_key(ssrc):
            if sdestype == 2:
                self.sdes[ssrc] = sdes
        else:
            if ((sdestype == 1) or (sdestype == 2)):
                self.sdes[ssrc] = sdes

    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

        # Send control packet
        destination.send_ctrl(0, None)
        destination.update()

        common.free_rtp_packet(event.data)
Пример #6
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