Beispiel #1
0
class RawVideoHandler(object):
    """
    relays a udp stream to a tcp stream
    """

    def __init__(self,server,udp_host_port,target_host_port):

        self.udp_host_port = udp_host_port
        self.target_host_port = target_host_port

        # setup a handler to read in the udp
        self.udp_in_handler = SocketHandler(self.udp_host_port, tcp=False)

        # setup a handler to write out the tcp
        self.tcp_out_handler = SocketHandler(self.target_host_port,
                                             connect_out=True)

        # relay the udp data coming in to the tcp going out
        self.udp_in_handler.on('receive',self.tcp_out_handler.push)

        # when one closes, close the other
        self.tcp_out_handler.on('close',self.udp_in_handler.close)
        self.udp_in_handler.on('close',self.tcp_out_handler.close)

        # when the udp port closes release it as available
        self.udp_in_handler.on('close',
                               partial(server.handle_udp_close,
                                       udp_host_port[1]))
Beispiel #2
0
class ConversionHandler(object):
    def __init__(self, server, vformat, in_host_port, out_host_port):

        self.in_host_port = in_host_port
        self.out_host_port = out_host_port
        self.vformat = vformat

        # setup our stream handlers
        self.in_handler = SocketHandler(in_host_port)
        self.out_handler = SocketHandler(out_host_port)

        # create a process for handling the conversion
        self.converter = VideoConverter(vformat)

        # data comes in, gets converted, and goes out
        self.in_handler.on('receive', self.converter.write)
        self.converter.on('read', self.out_handler.push)
Beispiel #3
0
    def __init__(self, server, stream_id, host_port):

        # the save path is our path to a disk
        self.save_path = None
        # the open file handler for the save path
        self.save_fh = None
        self.host_port = host_port
        self.stream_id = stream_id
        self.server = server

        # figure out where we are saving this stream
        self.setup_save_point()

        # setup the file handler to write to
        self.setup_file_handler()

        # setup a stream handler for the data coming in
        self.in_handler = SocketHandler(self.host_port)

        # whenever the in handler gets data we want to handle it
        self.in_handler.on('receive',self.handle_data)

        # when the stream closes we want to close our file handler
        self.in_handler.on('close',self.handle_stop)
Beispiel #4
0
class StoreHandler(object):
    """
    listens on given port storing the data down as it comes in
    """

    def __init__(self, server, stream_id, host_port):

        # the save path is our path to a disk
        self.save_path = None
        # the open file handler for the save path
        self.save_fh = None
        self.host_port = host_port
        self.stream_id = stream_id
        self.server = server

        # figure out where we are saving this stream
        self.setup_save_point()

        # setup the file handler to write to
        self.setup_file_handler()

        # setup a stream handler for the data coming in
        self.in_handler = SocketHandler(self.host_port)

        # whenever the in handler gets data we want to handle it
        self.in_handler.on('receive',self.handle_data)

        # when the stream closes we want to close our file handler
        self.in_handler.on('close',self.handle_stop)


    def setup_save_point(self):
        """
        sets up a file for us to write to
        """

        # figure out the rel path we should save down
        n = datetime.datetime.now()
        r_path = os.sep.join([n.year,n.month,n.day, self.stream_id,
                              n.hour,n.minute])

        # get our full path
        save_root = self.server.config.get('stream_save_root')
        out_path = os.path.join(save_root,r_path)


        # keep it around
        self.save_path = out_path

    def setup_file_handler(self):
        # we should already know where we are saving out to
        # just setup an appending file handler for there

        fh = open(self.save_path,'ab')

    def handle_data(self, d):
        """
        receives chunks of the data, appends it to the file
        """

        # write the data to our file handler
        self.save_fh.write(d)

    def handle_stop(self):
        """
        closes the save file handler
        """
        if self.save_fh:
            self.save_fh.close()