Beispiel #1
0
pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) {
    char cname[256];
    pa_cli *c;
    pa_client_new_data data;
    pa_client *client;

    pa_assert(io);

    pa_iochannel_socket_peer_to_string(io, cname, sizeof(cname));

    pa_client_new_data_init(&data);
    data.driver = __FILE__;
    data.module = m;
    pa_proplist_sets(data.proplist, PA_PROP_APPLICATION_NAME, cname);
    client = pa_client_new(core, &data);
    pa_client_new_data_done(&data);

    if (!client)
        return NULL;

    c = pa_xnew0(pa_cli, 1);
    c->core = core;
    c->client = client;
    pa_assert_se(c->line = pa_ioline_new(io));

    c->client->kill = client_kill;
    c->client->userdata = c;

    pa_ioline_set_callback(c->line, line_callback, c);

    return c;
}
static void on_connection(pa_socket_client *sc, pa_iochannel *io, void *userdata) {
    pa_rtsp_client *c = userdata;
    union {
        struct sockaddr sa;
        struct sockaddr_in in;
        struct sockaddr_in6 in6;
    } sa;
    socklen_t sa_len = sizeof(sa);

    pa_assert(sc);
    pa_assert(c);
    pa_assert(STATE_CONNECT == c->state);
    pa_assert(c->sc == sc);
    pa_socket_client_unref(c->sc);
    c->sc = NULL;

    if (!io) {
        pa_log("Connection failed: %s", pa_cstrerror(errno));
        return;
    }
    pa_assert(!c->ioline);

    c->ioline = pa_ioline_new(io);
    pa_ioline_set_callback(c->ioline, line_callback, c);

    /* Get the local IP address for use externally */
    if (0 == getsockname(pa_iochannel_get_recv_fd(io), &sa.sa, &sa_len)) {
        char buf[INET6_ADDRSTRLEN];
        const char *res = NULL;

        if (AF_INET == sa.sa.sa_family) {
            if ((res = inet_ntop(sa.sa.sa_family, &sa.in.sin_addr, buf, sizeof(buf)))) {
                c->localip = pa_xstrdup(res);
            }
        } else if (AF_INET6 == sa.sa.sa_family) {
            if ((res = inet_ntop(AF_INET6, &sa.in6.sin6_addr, buf, sizeof(buf)))) {
                c->localip = pa_sprintf_malloc("[%s]", res);
            }
        }
    }
    pa_log_debug("Established RTSP connection from local ip %s", c->localip);

    if (c->callback)
        c->callback(c, c->state, NULL, c->userdata);
}
Beispiel #3
0
pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) {
    char cname[256];
    pa_cli *c;
    pa_client_new_data data;
    pa_client *client;

    pa_assert(io);

    pa_iochannel_socket_peer_to_string(io, cname, sizeof(cname));

    pa_client_new_data_init(&data);
    data.driver = __FILE__;
    data.module = m;
    pa_proplist_sets(data.proplist, PA_PROP_APPLICATION_NAME, cname);
    client = pa_client_new(core, &data);
    pa_client_new_data_done(&data);

    if (!client)
        return NULL;

    c = pa_xnew(pa_cli, 1);
    c->core = core;
    c->client = client;
    pa_assert_se(c->line = pa_ioline_new(io));

    c->userdata = NULL;
    c->eof_callback = NULL;

    c->client->kill = client_kill;
    c->client->userdata = c;

    pa_ioline_set_callback(c->line, line_callback, c);
    pa_ioline_puts(c->line, "Welcome to PulseAudio! Use \"help\" for usage information.\n"PROMPT);

    c->fail = c->kill_requested = FALSE;
    c->defer_kill = 0;

    c->last_line = NULL;

    return c;
}