예제 #1
0
def create(client):
    """
    This function creates a new client in the clients structure
    based on the passed in client data
    :param client:  client to create in clients structure
    :return:        201 on success, 406 on client exists
    """
    c_api = ClientApi(bind=engine)
    c_api.open()
    len_clients = len(c_api.get_clients())
    c_api.close()

    if len_clients > CLIENT_LIMIT:
        abort(
            406,
            "Client list already at maximum capacity"
        )

    name = client.get("name", "")
    ip = client.get("ip", "")
    video_src_port = client.get("video_src_port", -1)
    video_sink_port = client.get("video_sink_port", -1)
    video_protocol = client.get("video_protocol", "jpeg")
    tuio_sink_port = client.get("tuio_sink_port", -1)
    mixing_mode = client.get("mixing_mode", "other")

    return create_client(name, video_src_port, ip, video_sink_port,
                         video_protocol, tuio_sink_port, mixing_mode)
예제 #2
0
def create_client(name, video_src_port, ip, video_sink_port, streaming_protocol, tuio_port, mixing_mode):
    """
    Helper function to create a client.
    :param name: name of the client
    :param ip: incoming stream ip
    :param video_src_port: incoming stream port
    :return: Returns the uuid and dict values of the created client.
    """
    c_api = ClientApi(bind=engine)
    c_api.open()
    num_clients = len(c_api.get_clients())

    new_uuid = create_uuid()
    ip = ip if len(ip) > 0 else "0.0.0.0"
    video_src_port = video_src_port if video_src_port > 0 else 5001 + 3 * num_clients + 1
    video_sink_port = video_sink_port if video_sink_port > 0 else video_src_port + 1
    tuio_port = tuio_port if tuio_port > 0 else video_sink_port + 1

    c = c_api.add_client(
        new_uuid, name, ip if len(ip) > 0 else "0.0.0.0",
        video_src_port, video_sink_port, streaming_protocol, tuio_port,
        mixing_mode
    )
    c_api.commit()
    res = c.as_dict()
    c_api.close()

    video_mixing.update_pipelines()
    return res
def forward_tuio_message(path, *lst):
    c_api = ClientApi(bind=engine)
    c_api.open()
    for c in c_api.get_clients():
        if c.tuio_sink_port is None or c.tuio_sink_port <= 0:
            continue
        tuio_sink = udp_client.SimpleUDPClient(c.ip, c.tuio_sink_port)
        tuio_sink.send_message(path, lst)
    c_api.close()
예제 #4
0
def read_all():
    """
    This function responds to a request for /api/clients
    with the complete lists of clients
    :return:        json string of list of clients
    """
    c_api = ClientApi(bind=engine)
    c_api.open()
    res = [c.as_dict() for c in c_api.get_clients()]
    c_api.close()
    return res
예제 #5
0
def update_pipelines():
    """
    Function to update current SurfaceStreams pipeline based on connected clients
    :return:
    """
    c_api = ClientApi(bind=engine)
    c_api.open()
    len_clients = len(c_api.get_clients())
    c_api.close()

    if len_clients == 0:
        clear_pipelines()
    else:
        create_multi_mixing_pipeline(mode="other" if len_clients > 1 else "all")

    return True
예제 #6
0
def create_multi_mixing_pipeline(mode="other"):
    """
    Creates a SurfaceStream video mixing pipeline.
    :param CLIENTS: client dicts denoting connection and stream descriptive data.
    :param mode: use 'other' to only merge streams of other clients connected for each client.
    use 'all' to merge alle streams.
    :return:
    """
    global MERGED_STREAM_WIDTH, MERGED_STREAM_HEIGHT

    clear_pipelines()
    _ensure_gtk_thread_running()

    c_api = ClientApi(bind=engine)
    c_api.open()
    clients = c_api.get_clients()
    print("################# CREATING MULTI MIXING PIPELINE")
    mixer = UdpVideoMixer(
        [c.as_dict() for c in clients],
        default_mode=mode,
        width=MERGED_STREAM_WIDTH,
        height=MERGED_STREAM_HEIGHT
    )
    i = 0
    uuid = ""
    for c in clients:
        mixer.set_in_port(c.video_src_port, i)
        mixer.set_out_address(c.ip, i)
        mixer.set_out_port(c.video_sink_port, i)
        uuid = c.uuid
        print("#### CLIENT "+ str(i))
        print(" > video_src_port" + str(c.video_src_port))
        print(" > ip" + str(c.ip))
        print(" > video_sink_port" + str(c.video_sink_port))
        i += 1
    PIPELINES[uuid] = mixer
    c_api.close()
    mixer.start()