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; }
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; }
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; }