Ejemplo n.º 1
0
char *pa_module_list_to_string(pa_core *c) {
    pa_strbuf *s;
    pa_module *m;
    uint32_t idx = PA_IDXSET_INVALID;
    pa_assert(c);

    s = pa_strbuf_new();

    pa_strbuf_printf(s, "%u module(s) loaded.\n", pa_idxset_size(c->modules));

    for (m = pa_idxset_first(c->modules, &idx); m; m = pa_idxset_next(c->modules, &idx)) {
        char *t;

        pa_strbuf_printf(s, "    index: %u\n"
                         "\tname: <%s>\n"
                         "\targument: <%s>\n"
                         "\tused: %i\n"
                         "\tload once: %s\n",
                         m->index,
                         m->name,
                         pa_strempty(m->argument),
                         pa_module_get_n_used(m),
                         pa_yes_no(m->load_once));

        t = pa_proplist_to_string_sep(m->proplist, "\n\t\t");
        pa_strbuf_printf(s, "\tproperties:\n\t\t%s\n", t);
        pa_xfree(t);
    }

    return pa_strbuf_tostring_free(s);
}
Ejemplo n.º 2
0
void on_set_common(pa_proplist* p, pa_tagstruct* t, pa_core* c)
{
    pa_log_info("on_set_common");

    const char* attribute = pa_proplist_gets(p, PROPLIST_KEY_ATTRIBUTE);
    if (!attribute) {
        pa_log_error("on_set_common: attribute not found!");
        return;
    }

    if (!strcmp(attribute, PROPLIST_VALUE_GET_INFO)) {
        const char* str_device = pa_proplist_gets(p, PROPLIST_KEY_DEVICE);
        if (!str_device) {
            pa_log_error("on_set_common device not specific!");
            return;
        }

        int device_id = atoi(str_device);
        pa_sink* sink = NULL;
        pa_source* source = NULL;

        sink = find_sink(c, device_id);
        if (!sink) {
            source = find_source(c, device_id);
        }

        if (!sink && !source) {
            pa_log_error("do not find any sink or source of device %d", device_id);
            return;
        }

        int n_used = 0;
        if (sink) {
            n_used = pa_module_get_n_used(sink->module);
        }
        else {
            n_used = pa_module_get_n_used(source->module);
        }

        char value[32];
        snprintf(value, sizeof(value), "%d", n_used);
        pa_proplist* replyp = pa_proplist_new();
        pa_proplist_sets(replyp, PROPLIST_KEY_VALUE, value);
        pa_tagstruct_put_proplist(t, replyp);
        pa_proplist_free(replyp);
    }
    else if (!strcmp(attribute, PROPLIST_VALUE_REMOTE_SINK)) {
#ifdef HAVE_WEB_SOCKET
        extern void start_web_socket();
        start_web_socket();
#endif
        on_set_debug(c, p, EAUDIO_STREAM_DEVICE_VIRTUALOUPUT_REMOTE, NULL);
    }
    else if (!strcmp(attribute, PROPLIST_VALUE_FILE_SINK)) {
        const char* str_path = pa_proplist_gets(p, PROPLIST_VALUE_PATH);
        char args[64] = { 0 };
        if (str_path) {
            snprintf(args, sizeof(args), "path=%s", str_path);
        }
        on_set_debug(c, p, EAUDIO_STREAM_DEVICE_VIRTUALOUPUT_FILE, str_path ? args : NULL);
    }
    else if (!strcmp(attribute, PROPLIST_VALUE_ALSA_BUFFER)) {
        const char* str_device = pa_proplist_gets(p, PROPLIST_KEY_DEVICE);
        if (!str_device) {
            pa_log_error("on_set_common alsa-buffer device not specific!");
            return;
        }

        int device = atoi(str_device);
        pa_sink* s = find_sink(c, device);
        if (!s) {
            pa_log_error("sink not found %d", device);
            return;
        }

        pa_usec_t left_to_play = pa_sink_get_left_to_play(s);
        pa_proplist* replyp = pa_proplist_new();
        pa_proplist_set(replyp, PROPLIST_KEY_COMMAND_RESULT, &left_to_play, sizeof(left_to_play));
        pa_tagstruct_put_proplist(t, replyp);
        pa_proplist_free(replyp);
    }
    else if (!strcmp(attribute, PROPLIST_VALUE_STOP_TEST)) {
        pthread_t tid_stop;
        int err = pthread_create(&tid_stop, NULL, stop_thread, NULL);
        if (err != 0) {
            pa_log_error("can't create thread: %s\n", strerror(err));
            return;
        }
    }
#ifdef HAVE_WEB_SOCKET
        else if (!strcmp(attribute, "web-start")) {
            extern void start_web_socket();
            start_web_socket();
        }
        else if (!strcmp(attribute, "web-stop")) {
            extern void stop_web_socket();
            stop_web_socket();
        }
#endif
}