pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *p) { pa_context *c; pa_assert(mainloop); if (pa_detect_fork()) return NULL; pa_init_i18n(); c = pa_xnew0(pa_context, 1); PA_REFCNT_INIT(c); c->proplist = p ? pa_proplist_copy(p) : pa_proplist_new(); if (name) pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name); #ifdef HAVE_DBUS c->system_bus = c->session_bus = NULL; #endif c->mainloop = mainloop; c->playback_streams = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); c->record_streams = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); c->client_index = PA_INVALID_INDEX; c->use_rtclock = pa_mainloop_is_our_api(mainloop); PA_LLIST_HEAD_INIT(pa_stream, c->streams); PA_LLIST_HEAD_INIT(pa_operation, c->operations); c->error = PA_OK; c->state = PA_CONTEXT_UNCONNECTED; reset_callbacks(c); #ifndef MSG_NOSIGNAL #ifdef SIGPIPE pa_check_signal_is_blocked(SIGPIPE); #endif #endif c->conf = pa_client_conf_new(); pa_client_conf_load(c->conf, true, true); c->srb_template.readfd = -1; c->srb_template.writefd = -1; if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) { if (!c->conf->disable_shm) c->mempool = pa_mempool_new(false, c->conf->shm_size); if (!c->mempool) { context_free(c); return NULL; } } return c; }
int pa__init(pa_module *m) { pa_modargs *ma = NULL; struct userdata *u; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments"); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->cache = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); u->client_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CLIENT_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) client_new_cb, u); u->client_proplist_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], PA_HOOK_EARLY, (pa_hook_cb_t) client_proplist_changed_cb, u); pa_modargs_free(ma); return 0; fail: pa__done(m); if (ma) pa_modargs_free(ma); return -1; }
int pa__init(pa_module *m) { pa_modargs *ma = NULL; struct userdata *u; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments"); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; u->cork_state = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); u->sink_input_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_put_cb, u); u->sink_input_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_unlink_cb, u); u->sink_input_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_move_start_cb, u); u->sink_input_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_move_finish_cb, u); pa_modargs_free(ma); return 0; fail: pa__done(m); if (ma) pa_modargs_free(ma); return -1; }
static pa_autoload_entry* entry_new(pa_core *c, const char *name) { pa_autoload_entry *e = NULL; pa_core_assert_ref(c); pa_assert(name); if (c->autoload_hashmap && (e = pa_hashmap_get(c->autoload_hashmap, name))) return NULL; e = pa_xnew(pa_autoload_entry, 1); e->core = c; e->name = pa_xstrdup(name); e->module = e->argument = NULL; e->in_action = 0; if (!c->autoload_hashmap) c->autoload_hashmap = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); pa_assert(c->autoload_hashmap); pa_hashmap_put(c->autoload_hashmap, e->name, e); if (!c->autoload_idxset) c->autoload_idxset = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); pa_idxset_put(c->autoload_idxset, e, &e->index); pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_AUTOLOAD|PA_SUBSCRIPTION_EVENT_NEW, e->index); return e; }
int pa__init(pa_module*m) { pa_modargs *ma = NULL; struct userdata *u; uint32_t timeout = 5; uint32_t idx; pa_sink *sink; pa_source *source; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } if (pa_modargs_get_value_u32(ma, "timeout", &timeout) < 0) { pa_log("Failed to parse timeout value."); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; u->timeout = timeout; u->device_infos = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); PA_IDXSET_FOREACH(sink, m->core->sinks, idx) device_new_hook_cb(m->core, PA_OBJECT(sink), u); PA_IDXSET_FOREACH(source, m->core->sources, idx) device_new_hook_cb(m->core, PA_OBJECT(source), u); u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) device_new_hook_cb, u); u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) device_new_hook_cb, u); u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) device_unlink_hook_cb, u); u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) device_unlink_hook_cb, u); u->sink_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) device_state_changed_hook_cb, u); u->source_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) device_state_changed_hook_cb, u); u->sink_input_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_fixate_hook_cb, u); u->source_output_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_fixate_hook_cb, u); u->sink_input_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_unlink_hook_cb, u); u->source_output_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_UNLINK_POST], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_unlink_hook_cb, u); u->sink_input_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_move_start_hook_cb, u); u->source_output_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_move_start_hook_cb, u); u->sink_input_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_move_finish_hook_cb, u); u->source_output_move_finish_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_FINISH], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_move_finish_hook_cb, u); u->sink_input_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) sink_input_state_changed_hook_cb, u); u->source_output_state_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_STATE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) source_output_state_changed_hook_cb, u); pa_modargs_free(ma); return 0; fail: if (ma) pa_modargs_free(ma); return -1; }
int pa__init(pa_module*m) { pa_modargs *ma = NULL; struct userdata *u; pa_bool_t restore_device = TRUE, restore_volume = TRUE; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments"); goto fail; } u = pa_xnew(struct userdata, 1); u->core = m->core; u->hashmap = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); u->table_file = pa_xstrdup(pa_modargs_get_value(ma, "table", NULL)); u->modified = FALSE; u->subscription = NULL; u->sink_input_new_hook_slot = u->sink_input_fixate_hook_slot = u->source_output_new_hook_slot = NULL; u->save_time_event = NULL; m->userdata = u; if (pa_modargs_get_value_boolean(ma, "restore_device", &restore_device) < 0 || pa_modargs_get_value_boolean(ma, "restore_volume", &restore_volume) < 0) { pa_log("restore_volume= and restore_device= expect boolean arguments"); goto fail; } if (!(restore_device || restore_volume)) { pa_log("Both restrong the volume and restoring the device are disabled. There's no point in using this module at all then, failing."); goto fail; } if (load_rules(u) < 0) goto fail; u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u); if (restore_device) { u->sink_input_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], (pa_hook_cb_t) sink_input_new_hook_callback, u); u->source_output_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], (pa_hook_cb_t) source_output_new_hook_callback, u); } if (restore_volume) u->sink_input_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], (pa_hook_cb_t) sink_input_fixate_hook_callback, u); pa_modargs_free(ma); return 0; fail: pa__done(m); if (ma) pa_modargs_free(ma); return -1; }
pa_cond *pa_cond_new(void) { pa_cond *c; c = pa_xnew(pa_cond, 1); c->wait_events = pa_hashmap_new(NULL, NULL); assert(c->wait_events); return c; }
/* For receiving blocks from other nodes */ pa_memimport* pa_memimport_new(pa_mempool *p, pa_memimport_release_cb_t cb, void *userdata) { pa_memimport *i; pa_assert(p); pa_assert(cb); i = pa_xnew(pa_memimport, 1); i->mutex = pa_mutex_new(true, true); i->pool = p; i->segments = pa_hashmap_new(NULL, NULL); i->blocks = pa_hashmap_new(NULL, NULL); i->release_cb = cb; i->userdata = userdata; pa_mutex_lock(p->mutex); PA_LLIST_PREPEND(pa_memimport, p->imports, i); pa_mutex_unlock(p->mutex); return i; }
int pa__init(pa_module*m) { struct userdata *u; pa_modargs *ma = NULL; char *hn, *un; int error; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; u->module = m; u->native = pa_native_protocol_get(u->core); u->avahi_poll = pa_avahi_poll_new(m->core->mainloop); u->services = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); u->main_entry_group = NULL; un = pa_get_user_name_malloc(); hn = pa_get_host_name_malloc(); u->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s", un, hn), AVAHI_LABEL_MAX-1); pa_xfree(un); pa_xfree(hn); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { pa_log("avahi_client_new() failed: %s", avahi_strerror(error)); goto fail; } pa_modargs_free(ma); return 0; fail: pa__done(m); if (ma) pa_modargs_free(ma); return -1; }
int pa__init(pa_module*m) { struct userdata *u; pa_modargs *ma = NULL; char *hn, *un; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } m->userdata = u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; u->native = pa_native_protocol_get(u->core); u->services = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); un = pa_get_user_name_malloc(); hn = pa_get_host_name_malloc(); u->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s", un, hn), kDNSServiceMaxDomainName-1); pa_xfree(un); pa_xfree(hn); publish_all_services(u); pa_modargs_free(ma); return 0; fail: pa__done(m); if (ma) pa_modargs_free(ma); return -1; }
pa_device_port *pa_device_port_new(pa_core *c, const char *name, const char *description, size_t extra) { pa_device_port *p; pa_assert(name); p = PA_DEVICE_PORT(pa_object_new_internal(PA_ALIGN(sizeof(pa_device_port)) + extra, pa_device_port_type_id, pa_device_port_check_type)); p->parent.free = device_port_free; p->name = pa_xstrdup(name); p->description = pa_xstrdup(description); p->core = c; p->priority = 0; p->available = PA_PORT_AVAILABLE_UNKNOWN; p->profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); p->is_input = FALSE; p->is_output = FALSE; p->latency_offset = 0; p->proplist = pa_proplist_new(); return p; }
int pa__init(pa_module*m) { struct userdata *u; pa_modargs *ma = NULL; int error; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; u->module = m; u->sink_browser = u->source_browser = NULL; u->tunnels = pa_hashmap_new(tunnel_hash, tunnel_compare); u->avahi_poll = pa_avahi_poll_new(m->core->mainloop); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { pa_log("pa_avahi_client_new() failed: %s", avahi_strerror(error)); goto fail; } pa_modargs_free(ma); return 0; fail: pa__done(m); if (ma) pa_modargs_free(ma); return -1; }
static void devices_add(struct pa_classify_device **p_devices, const char *type, const char *prop, enum pa_classify_method method, const char *arg, pa_hashmap *ports, uint32_t flags) { struct pa_classify_device *devs; struct pa_classify_device_def *d; size_t newsize; const char *method_name; char *ports_string = NULL; /* Just for log output. */ pa_strbuf *buf; /* For building ports_string. */ pa_assert(p_devices); pa_assert_se((devs = *p_devices)); newsize = sizeof(*devs) + sizeof(devs->defs[0]) * (devs->ndef + 1); devs = *p_devices = pa_xrealloc(devs, newsize); d = devs->defs + devs->ndef; memset(d+1, 0, sizeof(devs->defs[0])); d->type = pa_xstrdup(type); d->prop = pa_xstrdup(prop); buf = pa_strbuf_new(); if (ports && !pa_hashmap_isempty(ports)) { struct pa_classify_port_entry *port; void *state; pa_bool_t first = TRUE; /* Copy the ports hashmap to d->data.ports. */ d->data.ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); PA_HASHMAP_FOREACH(port, ports, state) { struct pa_classify_port_entry *port_copy = pa_xnew(struct pa_classify_port_entry, 1); port_copy->device_name = pa_xstrdup(port->device_name); port_copy->port_name = pa_xstrdup(port->port_name); pa_hashmap_put(d->data.ports, port_copy->device_name, port_copy); if (!first) { pa_strbuf_putc(buf, ','); } first = FALSE; pa_strbuf_printf(buf, "%s:%s", port->device_name, port->port_name); } } d->data.flags = flags; switch (method) { case pa_method_equals: method_name = "equals"; d->method = pa_classify_method_equals; d->arg.string = pa_xstrdup(arg); break; case pa_method_startswith: method_name = "startswidth"; d->method = pa_classify_method_startswith; d->arg.string = pa_xstrdup(arg); break; case pa_method_matches: method_name = "matches"; if (regcomp(&d->arg.rexp, arg, 0) == 0) { d->method = pa_classify_method_matches; break; } /* intentional fall trough */ default: pa_log("%s: invalid device definition %s", __FUNCTION__, type); memset(d, 0, sizeof(*d)); pa_strbuf_free(buf); return; } devs->ndef++; ports_string = pa_strbuf_tostring_free(buf); pa_log_info("device '%s' added (%s|%s|%s|%s|0x%04x)", type, d->prop, method_name, arg, ports_string, d->data.flags); pa_xfree(ports_string); }
static struct entry* entry_new(void) { struct entry *r = pa_xnew0(struct entry, 1); r->version = ENTRY_VERSION; r->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); return r; }
pa_proplist* pa_proplist_new(void) { return MAKE_PROPLIST(pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func)); }
pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *p) { pa_context *c; pa_mem_type_t type; pa_assert(mainloop); if (pa_detect_fork()) return NULL; pa_init_i18n(); c = pa_xnew0(pa_context, 1); PA_REFCNT_INIT(c); c->proplist = p ? pa_proplist_copy(p) : pa_proplist_new(); if (name) pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name); #ifdef HAVE_DBUS c->system_bus = c->session_bus = NULL; #endif c->mainloop = mainloop; c->playback_streams = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); c->record_streams = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); c->client_index = PA_INVALID_INDEX; c->use_rtclock = pa_mainloop_is_our_api(mainloop); PA_LLIST_HEAD_INIT(pa_stream, c->streams); PA_LLIST_HEAD_INIT(pa_operation, c->operations); c->error = PA_OK; c->state = PA_CONTEXT_UNCONNECTED; reset_callbacks(c); #ifndef MSG_NOSIGNAL #ifdef SIGPIPE pa_check_signal_is_blocked(SIGPIPE); #endif #endif c->conf = pa_client_conf_new(); pa_client_conf_load(c->conf, true, true); c->srb_template.readfd = -1; c->srb_template.writefd = -1; c->memfd_on_local = (!c->conf->disable_memfd && pa_memfd_is_locally_supported()); type = (c->conf->disable_shm) ? PA_MEM_TYPE_PRIVATE : ((!c->memfd_on_local) ? PA_MEM_TYPE_SHARED_POSIX : PA_MEM_TYPE_SHARED_MEMFD); if (!(c->mempool = pa_mempool_new(type, c->conf->shm_size, true))) { if (!c->conf->disable_shm) { pa_log_warn("Failed to allocate shared memory pool. Falling back to a normal private one."); c->mempool = pa_mempool_new(PA_MEM_TYPE_PRIVATE, c->conf->shm_size, true); } if (!c->mempool) { context_free(c); return NULL; } } return c; }
if (!s->active_port || p->priority > s->active_port->priority) s->active_port = p; } s->save_volume = data->save_volume; s->save_muted = data->save_muted; pa_silence_memchunk_get( &core->silence_cache, core->mempool, &s->silence, &s->sample_spec, 0); s->thread_info.rtpoll = NULL; s->thread_info.outputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); s->thread_info.soft_volume = s->soft_volume; s->thread_info.soft_muted = s->muted; s->thread_info.state = s->state; s->thread_info.max_rewind = 0; s->thread_info.requested_latency_valid = FALSE; s->thread_info.requested_latency = 0; s->thread_info.min_latency = ABSOLUTE_MIN_LATENCY; s->thread_info.max_latency = ABSOLUTE_MAX_LATENCY; s->thread_info.fixed_latency = flags & PA_SOURCE_DYNAMIC_LATENCY ? 0 : DEFAULT_FIXED_LATENCY; pa_assert_se(pa_idxset_put(core->sources, s, &s->index) >= 0); if (s->card) pa_assert_se(pa_idxset_put(s->card->sources, s, NULL) >= 0);
pa_headerlist* pa_headerlist_new(void) { return MAKE_HEADERLIST(pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func)); }
void pa_property_init(pa_core *c) { pa_assert(c); c->properties = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); }
pa_core* pa_core_new(pa_mainloop_api *m, bool shared, size_t shm_size) { pa_core* c; pa_mempool *pool; int j; pa_assert(m); if (shared) { if (!(pool = pa_mempool_new(shared, shm_size))) { pa_log_warn("Failed to allocate shared memory pool. Falling back to a normal memory pool."); shared = false; } } if (!shared) { if (!(pool = pa_mempool_new(shared, shm_size))) { pa_log("pa_mempool_new() failed."); return NULL; } } c = pa_msgobject_new(pa_core); c->parent.parent.free = core_free; c->parent.process_msg = core_process_msg; c->state = PA_CORE_STARTUP; c->mainloop = m; c->clients = pa_idxset_new(NULL, NULL); c->cards = pa_idxset_new(NULL, NULL); c->sinks = pa_idxset_new(NULL, NULL); c->sources = pa_idxset_new(NULL, NULL); c->sink_inputs = pa_idxset_new(NULL, NULL); c->source_outputs = pa_idxset_new(NULL, NULL); c->modules = pa_idxset_new(NULL, NULL); c->scache = pa_idxset_new(NULL, NULL); c->namereg = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); c->shared = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); c->default_source = NULL; c->default_sink = NULL; c->default_sample_spec.format = PA_SAMPLE_S16NE; c->default_sample_spec.rate = 44100; c->default_sample_spec.channels = 2; pa_channel_map_init_extend(&c->default_channel_map, c->default_sample_spec.channels, PA_CHANNEL_MAP_DEFAULT); c->default_n_fragments = 4; c->default_fragment_size_msec = 25; c->deferred_volume_safety_margin_usec = 8000; c->deferred_volume_extra_delay_usec = 0; c->module_defer_unload_event = NULL; c->modules_pending_unload = pa_hashmap_new(NULL, NULL); c->subscription_defer_event = NULL; PA_LLIST_HEAD_INIT(pa_subscription, c->subscriptions); PA_LLIST_HEAD_INIT(pa_subscription_event, c->subscription_event_queue); c->subscription_event_last = NULL; c->mempool = pool; pa_silence_cache_init(&c->silence_cache); if (shared && !(c->rw_mempool = pa_mempool_new(shared, shm_size))) pa_log_warn("Failed to allocate shared writable memory pool."); if (c->rw_mempool) pa_mempool_set_is_remote_writable(c->rw_mempool, true); c->exit_event = NULL; c->scache_auto_unload_event = NULL; c->exit_idle_time = -1; c->scache_idle_time = 20; c->flat_volumes = true; c->disallow_module_loading = false; c->disallow_exit = false; c->running_as_daemon = false; c->realtime_scheduling = false; c->realtime_priority = 5; c->disable_remixing = false; c->disable_lfe_remixing = false; c->lfe_crossover_freq = 120; c->deferred_volume = true; c->resample_method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 1; for (j = 0; j < PA_CORE_HOOK_MAX; j++) pa_hook_init(&c->hooks[j], c); for (j = 0; j < PA_ACCESS_HOOK_MAX; j++) pa_hook_init(&c->access[j], c); pa_random(&c->cookie, sizeof(c->cookie)); #ifdef SIGPIPE pa_check_signal_is_blocked(SIGPIPE); #endif pa_core_check_idle(c); c->state = PA_CORE_RUNNING; return c; }
int pa__init(pa_module *m) { struct userdata *u = NULL; pa_modargs *ma; struct udev_enumerate *enumerate = NULL; struct udev_list_entry *item = NULL, *first = NULL; int fd; pa_bool_t use_tsched = TRUE, fixed_latency_range = FALSE, ignore_dB = FALSE, deferred_volume = m->core->deferred_volume; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments"); goto fail; } m->userdata = u = pa_xnew0(struct userdata, 1); u->core = m->core; u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); u->inotify_fd = -1; if (pa_modargs_get_value_boolean(ma, "tsched", &use_tsched) < 0) { pa_log("Failed to parse tsched= argument."); goto fail; } u->use_tsched = use_tsched; if (pa_modargs_get_value_boolean(ma, "fixed_latency_range", &fixed_latency_range) < 0) { pa_log("Failed to parse fixed_latency_range= argument."); goto fail; } u->fixed_latency_range = fixed_latency_range; if (pa_modargs_get_value_boolean(ma, "ignore_dB", &ignore_dB) < 0) { pa_log("Failed to parse ignore_dB= argument."); goto fail; } u->ignore_dB = ignore_dB; if (pa_modargs_get_value_boolean(ma, "deferred_volume", &deferred_volume) < 0) { pa_log("Failed to parse deferred_volume= argument."); goto fail; } u->deferred_volume = deferred_volume; if (!(u->udev = udev_new())) { pa_log("Failed to initialize udev library."); goto fail; } if (setup_inotify(u) < 0) goto fail; if (!(u->monitor = udev_monitor_new_from_netlink(u->udev, "udev"))) { pa_log("Failed to initialize monitor."); goto fail; } if (udev_monitor_filter_add_match_subsystem_devtype(u->monitor, "sound", NULL) < 0) { pa_log("Failed to subscribe to sound devices."); goto fail; } errno = 0; if (udev_monitor_enable_receiving(u->monitor) < 0) { pa_log("Failed to enable monitor: %s", pa_cstrerror(errno)); if (errno == EPERM) pa_log_info("Most likely your kernel is simply too old and " "allows only privileged processes to listen to device events. " "Please upgrade your kernel to at least 2.6.30."); goto fail; } if ((fd = udev_monitor_get_fd(u->monitor)) < 0) { pa_log("Failed to get udev monitor fd."); goto fail; } pa_assert_se(u->udev_io = u->core->mainloop->io_new(u->core->mainloop, fd, PA_IO_EVENT_INPUT, monitor_cb, u)); if (!(enumerate = udev_enumerate_new(u->udev))) { pa_log("Failed to initialize udev enumerator."); goto fail; } if (udev_enumerate_add_match_subsystem(enumerate, "sound") < 0) { pa_log("Failed to match to subsystem."); goto fail; } if (udev_enumerate_scan_devices(enumerate) < 0) { pa_log("Failed to scan for devices."); goto fail; } first = udev_enumerate_get_list_entry(enumerate); udev_list_entry_foreach(item, first) process_path(u, udev_list_entry_get_name(item)); udev_enumerate_unref(enumerate); pa_log_info("Found %u cards.", pa_hashmap_size(u->devices)); pa_modargs_free(ma); return 0; fail: if (enumerate) udev_enumerate_unref(enumerate); if (ma) pa_modargs_free(ma); pa__done(m); return -1; }