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); }
void pa_dbus_sync_pending_list(pa_dbus_pending **p) { pa_assert(p); while (*p && dbus_connection_read_write_dispatch((*p)->connection, -1)) ; }
int pa__init(pa_module*m) { struct userdata *u = NULL; pa_sample_spec ss; pa_channel_map map; pa_modargs *ma = NULL; pa_sink_new_data data; size_t nbytes; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } ss = m->core->default_sample_spec; map = m->core->default_channel_map; if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { pa_log("Invalid sample format specification or channel map"); goto fail; } m->userdata = u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); pa_sink_new_data_init(&data); data.driver = __FILE__; data.module = m; pa_sink_new_data_set_name(&data, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME)); pa_sink_new_data_set_sample_spec(&data, &ss); pa_sink_new_data_set_channel_map(&data, &map); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, _("Null Output")); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "abstract"); if (pa_modargs_get_proplist(ma, "sink_properties", data.proplist, PA_UPDATE_REPLACE) < 0) { pa_log("Invalid properties"); pa_sink_new_data_done(&data); goto fail; } u->sink = pa_sink_new(m->core, &data, PA_SINK_LATENCY|PA_SINK_DYNAMIC_LATENCY); pa_sink_new_data_done(&data); if (!u->sink) { pa_log("Failed to create sink object."); goto fail; } u->sink->parent.process_msg = sink_process_msg; u->sink->update_requested_latency = sink_update_requested_latency_cb; u->sink->userdata = u; pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); pa_sink_set_rtpoll(u->sink, u->rtpoll); u->block_usec = BLOCK_USEC; nbytes = pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec); pa_sink_set_max_rewind(u->sink, nbytes); pa_sink_set_max_request(u->sink, nbytes); if (!(u->thread = pa_thread_new("null-sink", thread_func, u))) { pa_log("Failed to create thread."); goto fail; } pa_sink_set_latency_range(u->sink, 0, BLOCK_USEC); pa_sink_put(u->sink); pa_modargs_free(ma); return 0; fail: if (ma) pa_modargs_free(ma); pa__done(m); return -1; }
pa_hook* pa_reserve_wrapper_hook(pa_reserve_wrapper *r) { pa_assert(r); pa_assert(PA_REFCNT_VALUE(r) >= 1); return &r->hook; }
pa_hook* pa_reserve_monitor_wrapper_hook(pa_reserve_monitor_wrapper *w) { pa_assert(w); pa_assert(PA_REFCNT_VALUE(w) >= 1); return &w->hook; }
void pa_source_new_data_set_muted(pa_source_new_data *data, pa_bool_t mute) { pa_assert(data); data->muted_is_set = TRUE; data->muted = !!mute; }
pa_source *pa_droid_source_new(pa_module *m, pa_modargs *ma, const char *driver, pa_droid_card_data *card_data, pa_droid_mapping *am, pa_card *card) { struct userdata *u = NULL; char *thread_name = NULL; pa_source_new_data data; const char *module_id = NULL; /* const char *tmp; */ uint32_t sample_rate; uint32_t alternate_sample_rate; audio_devices_t dev_in; pa_sample_spec sample_spec; pa_channel_map channel_map; bool namereg_fail = false; pa_droid_config_audio *config = NULL; /* Only used when source is created without card */ uint32_t source_buffer = 0; char audio_source[32]; int ret; audio_format_t hal_audio_format = 0; audio_channel_mask_t hal_channel_mask = 0; pa_assert(m); pa_assert(ma); pa_assert(driver); /* When running under card use hw module name for source by default. */ if (card && ma) module_id = am->input->module->name; else module_id = pa_modargs_get_value(ma, "module_id", DEFAULT_MODULE_ID); sample_spec = m->core->default_sample_spec; channel_map = m->core->default_channel_map; if (pa_modargs_get_sample_spec_and_channel_map(ma, &sample_spec, &channel_map, PA_CHANNEL_MAP_AIFF) < 0) { pa_log("Failed to parse sample specification and channel map."); goto fail; } alternate_sample_rate = m->core->alternate_sample_rate; if (pa_modargs_get_alternate_sample_rate(ma, &alternate_sample_rate) < 0) { pa_log("Failed to parse alternate sample rate."); goto fail; } if (pa_modargs_get_value_u32(ma, "source_buffer", &source_buffer) < 0) { pa_log("Failed to parse source_buffer. Needs to be integer >= 0."); goto fail; } u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; u->card = card; u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); /* Enabled routing changes by default. */ u->routing_changes_enabled = true; if (card_data) { pa_assert(card); u->card_data = card_data; pa_assert_se((u->hw_module = pa_droid_hw_module_get(u->core, NULL, card_data->module_id))); } else { /* Stand-alone source */ if (!(config = pa_droid_config_load(ma))) goto fail; /* Ownership of config transfers to hw_module if opening of hw module succeeds. */ if (!(u->hw_module = pa_droid_hw_module_get(u->core, config, module_id))) goto fail; } if (!pa_convert_format(sample_spec.format, CONV_FROM_PA, &hal_audio_format)) { pa_log("Sample spec format %u not supported.", sample_spec.format); goto fail; } for (int i = 0; i < channel_map.channels; i++) { audio_channel_mask_t c; if (!pa_convert_input_channel(channel_map.map[i], CONV_FROM_PA, &c)) { pa_log("Failed to convert channel map."); goto fail; } hal_channel_mask |= c; } struct audio_config config_in = { .sample_rate = sample_spec.rate, .channel_mask = hal_channel_mask, .format = hal_audio_format }; /* Default routing */ /* FIXME So while setting routing through stream with HALv2 API fails, creation of stream * requires HALv2 style device to work properly. So until that oddity is resolved we always * set AUDIO_DEVICE_IN_BUILTIN_MIC as initial device here. */ #if 0 pa_assert_se(pa_string_convert_input_device_str_to_num("AUDIO_DEVICE_IN_BUILTIN_MIC", &dev_in)); if ((tmp = pa_modargs_get_value(ma, "input_devices", NULL))) { audio_devices_t tmp_dev; if (parse_device_list(tmp, &tmp_dev) && tmp_dev) dev_in = tmp_dev; pa_log_debug("Set initial devices %s", tmp); } #else pa_log_info("FIXME: Setting AUDIO_DEVICE_IN_BUILTIN_MIC as initial device."); dev_in = AUDIO_DEVICE_IN_BUILTIN_MIC; #endif pa_droid_hw_module_lock(u->hw_module); ret = u->hw_module->device->open_input_stream(u->hw_module->device, u->hw_module->stream_in_id, dev_in, &config_in, &u->stream); /* On some devices the first call will fail if the config parameters are * not supported, but it'll automatically set the right ones, expecting * the caller to call it again, so let's try at least one more time */ if (!u->stream) ret = u->hw_module->device->open_input_stream(u->hw_module->device, u->hw_module->stream_in_id, dev_in, &config_in, &u->stream); u->hw_module->stream_in_id++; pa_droid_hw_module_unlock(u->hw_module); if (ret < 0) { pa_log("Failed to open input stream."); goto fail; } if ((sample_rate = u->stream->common.get_sample_rate(&u->stream->common)) != sample_spec.rate) { pa_log_warn("Requested sample rate %u but got %u instead.", sample_spec.rate, sample_rate); sample_spec.rate = sample_rate; } u->buffer_size = u->stream->common.get_buffer_size(&u->stream->common); if (source_buffer) { if (source_buffer < u->buffer_size) pa_log_warn("Requested buffer size %u less than HAL reported buffer size (%u).", source_buffer, u->buffer_size); else if (source_buffer % u->buffer_size) { uint32_t trunc = (source_buffer / u->buffer_size) * u->buffer_size; pa_log_warn("Requested buffer size %u not multiple of HAL buffer size (%u). Using buffer size %u", source_buffer, u->buffer_size, trunc); u->buffer_size = trunc; } else { pa_log_info("Using requested buffer size %u.", source_buffer); u->buffer_size = source_buffer; } } pa_log_info("Created Android stream with device: %u sample rate: %u channel mask: %u format: %u buffer size: %u", dev_in, sample_rate, config_in.channel_mask, config_in.format, u->buffer_size); /* Setting audio source to MIC by default */ pa_snprintf(audio_source, sizeof(audio_source), "%s=%u", AUDIO_PARAMETER_STREAM_INPUT_SOURCE, AUDIO_SOURCE_MIC); u->stream->common.set_parameters(&u->stream->common, audio_source); pa_log_debug("Setting audio source to AUDIO_SOURCE_MIC by default"); pa_source_new_data_init(&data); data.driver = driver; data.module = m; data.card = card; source_set_name(ma, &data, module_id); /* We need to give pa_modargs_get_value_boolean() a pointer to a local * variable instead of using &data.namereg_fail directly, because * data.namereg_fail is a bitfield and taking the address of a bitfield * variable is impossible. */ namereg_fail = data.namereg_fail; if (pa_modargs_get_value_boolean(ma, "namereg_fail", &namereg_fail) < 0) { pa_log("Failed to parse namereg_fail argument."); pa_source_new_data_done(&data); goto fail; } data.namereg_fail = namereg_fail; pa_source_new_data_set_sample_spec(&data, &sample_spec); pa_source_new_data_set_channel_map(&data, &channel_map); pa_source_new_data_set_alternate_sample_rate(&data, alternate_sample_rate); if (am) pa_droid_add_ports(data.ports, am, card); u->source = pa_source_new(m->core, &data, PA_SOURCE_HARDWARE); pa_source_new_data_done(&data); if (!u->source) { pa_log("Failed to create source."); goto fail; } u->source->userdata = u; u->source->parent.process_msg = source_process_msg; source_set_mute_control(u); u->source->set_port = source_set_port_cb; pa_source_set_asyncmsgq(u->source, u->thread_mq.inq); pa_source_set_rtpoll(u->source, u->rtpoll); /* Disable rewind for droid source */ pa_source_set_max_rewind(u->source, 0); thread_name = pa_sprintf_malloc("droid-source-%s", module_id); if (!(u->thread = pa_thread_new(thread_name, thread_func, u))) { pa_log("Failed to create thread."); goto fail; } pa_xfree(thread_name); thread_name = NULL; pa_source_set_fixed_latency(u->source, pa_bytes_to_usec(u->buffer_size, &sample_spec)); pa_log_debug("Set fixed latency %" PRIu64 " usec", pa_bytes_to_usec(u->buffer_size, &sample_spec)); if (u->source->active_port) source_set_port_cb(u->source, u->source->active_port); pa_source_put(u->source); return u->source; fail: pa_xfree(thread_name); if (config) pa_xfree(config); if (u) userdata_free(u); return NULL; } void pa_droid_source_free(pa_source *s) { struct userdata *u; pa_source_assert_ref(s); pa_assert_se(u = s->userdata); userdata_free(u); } static void userdata_free(struct userdata *u) { if (u->source) pa_source_unlink(u->source); if (u->thread) { pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL); pa_thread_free(u->thread); } pa_thread_mq_done(&u->thread_mq); if (u->source) pa_source_unref(u->source); if (u->memchunk.memblock) pa_memblock_unref(u->memchunk.memblock); if (u->hw_module && u->stream) { pa_droid_hw_module_lock(u->hw_module); u->hw_module->device->close_input_stream(u->hw_module->device, u->stream); pa_droid_hw_module_unlock(u->hw_module); } // Stand alone source if (u->hw_module) pa_droid_hw_module_unref(u->hw_module); pa_xfree(u); }
void pa_format_info_set_prop_int(pa_format_info *f, const char *key, int value) { pa_assert(f); pa_assert(key); pa_proplist_setf(f->plist, key, "%d", value); }
void pa_format_info_set_prop_string(pa_format_info *f, const char *key, const char *value) { pa_assert(f); pa_assert(key); pa_proplist_setf(f->plist, key, "\"%s\"", value); }
static void thread_func(void *userdata) { struct userdata *u = userdata; int read_type = 0; pa_assert(u); pa_log_debug("Thread starting up"); pa_thread_mq_install(&u->thread_mq); for (;;) { int ret; struct pollfd *pollfd; pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); /* Try to read some data and pass it on to the source driver */ if (u->source->thread_info.state == PA_SOURCE_RUNNING && pollfd->revents) { ssize_t l; void *p; if (!u->memchunk.memblock) { u->memchunk.memblock = pa_memblock_new(u->core->mempool, pa_pipe_buf(u->fd)); u->memchunk.index = u->memchunk.length = 0; } pa_assert(pa_memblock_get_length(u->memchunk.memblock) > u->memchunk.index); p = pa_memblock_acquire(u->memchunk.memblock); l = pa_read(u->fd, (uint8_t*) p + u->memchunk.index, pa_memblock_get_length(u->memchunk.memblock) - u->memchunk.index, &read_type); pa_memblock_release(u->memchunk.memblock); pa_assert(l != 0); /* EOF cannot happen, since we opened the fifo for both reading and writing */ if (l < 0) { if (errno == EINTR) continue; else if (errno != EAGAIN) { pa_log("Faile to read data from FIFO: %s", pa_cstrerror(errno)); goto fail; } } else { u->memchunk.length = (size_t) l; pa_source_post(u->source, &u->memchunk); u->memchunk.index += (size_t) l; if (u->memchunk.index >= pa_memblock_get_length(u->memchunk.memblock)) { pa_memblock_unref(u->memchunk.memblock); pa_memchunk_reset(&u->memchunk); } pollfd->revents = 0; } } /* Hmm, nothing to do. Let's sleep */ pollfd->events = (short) (u->source->thread_info.state == PA_SOURCE_RUNNING ? POLLIN : 0); if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) goto fail; if (ret == 0) goto finish; pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); if (pollfd->revents & ~POLLIN) { pa_log("FIFO shutdown."); goto fail; } } fail: /* If this was no regular exit from the loop we have to continue * processing messages until we received PA_MESSAGE_SHUTDOWN */ pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL); pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN); finish: pa_log_debug("Thread shutting down"); }
pa_prop_type_t pa_format_info_get_prop_type(const pa_format_info *f, const char *key) { const char *str; pa_json_object *o; const pa_json_object *o1; pa_prop_type_t type; pa_assert(f); pa_assert(key); str = pa_proplist_gets(f->plist, key); if (!str) return PA_PROP_TYPE_INVALID; o = pa_json_parse(str); if (!o) return PA_PROP_TYPE_INVALID; switch (pa_json_object_get_type(o)) { case PA_JSON_TYPE_INT: type = PA_PROP_TYPE_INT; break; case PA_JSON_TYPE_STRING: type = PA_PROP_TYPE_STRING; break; case PA_JSON_TYPE_ARRAY: if (pa_json_object_get_array_length(o) == 0) { /* Unlikely, but let's account for this anyway. We need at * least one element to figure out the array type. */ type = PA_PROP_TYPE_INVALID; break; } o1 = pa_json_object_get_array_member(o, 0); if (pa_json_object_get_type(o1) == PA_JSON_TYPE_INT) type = PA_PROP_TYPE_INT_ARRAY; else if (pa_json_object_get_type(o1) == PA_JSON_TYPE_STRING) type = PA_PROP_TYPE_STRING_ARRAY; else type = PA_PROP_TYPE_INVALID; break; case PA_JSON_TYPE_OBJECT: /* We actually know at this point that it's a int range, but let's * confirm. */ if (!pa_json_object_get_object_member(o, PA_JSON_MIN_KEY)) { type = PA_PROP_TYPE_INVALID; break; } if (!pa_json_object_get_object_member(o, PA_JSON_MAX_KEY)) { type = PA_PROP_TYPE_INVALID; break; } type = PA_PROP_TYPE_INT_RANGE; break; default: type = PA_PROP_TYPE_INVALID; break; } pa_json_object_free(o); return type; }
int pa__init(pa_module*m) { struct userdata *u = NULL; pa_sample_spec ss; pa_channel_map map; pa_modargs *ma = NULL; pa_source_new_data data; uint32_t latency_time = DEFAULT_LATENCY_TIME; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } ss = m->core->default_sample_spec; map = m->core->default_channel_map; if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { pa_log("Invalid sample format specification or channel map"); goto fail; } m->userdata = u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); pa_source_new_data_init(&data); data.driver = __FILE__; data.module = m; pa_source_new_data_set_name(&data, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME)); pa_source_new_data_set_sample_spec(&data, &ss); pa_source_new_data_set_channel_map(&data, &map); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, pa_modargs_get_value(ma, "description", "Null Input")); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "abstract"); u->source = pa_source_new(m->core, &data, PA_SOURCE_LATENCY | PA_SOURCE_DYNAMIC_LATENCY); pa_source_new_data_done(&data); if (!u->source) { pa_log("Failed to create source object."); goto fail; } u->latency_time = DEFAULT_LATENCY_TIME; if (pa_modargs_get_value_u32(ma, "latency_time", &latency_time) < 0) { pa_log("Failed to parse latency_time value."); goto fail; } u->latency_time = latency_time; u->source->parent.process_msg = source_process_msg; u->source->update_requested_latency = source_update_requested_latency_cb; u->source->userdata = u; pa_source_set_asyncmsgq(u->source, u->thread_mq.inq); pa_source_set_rtpoll(u->source, u->rtpoll); pa_source_set_latency_range(u->source, 0, MAX_LATENCY_USEC); u->block_usec = u->source->thread_info.max_latency; u->source->thread_info.max_rewind = pa_usec_to_bytes(u->block_usec, &u->source->sample_spec); if (!(u->thread = pa_thread_new("null-source", thread_func, u))) { pa_log("Failed to create thread."); goto fail; } pa_source_put(u->source); pa_modargs_free(ma); return 0; fail: if (ma) pa_modargs_free(ma); pa__done(m); return -1; }
static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void*userdata) { struct userdata *u = userdata; char *name = NULL, *code = NULL; pa_assert(io); pa_assert(u); if (events & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) { pa_log("Lost connection to LIRC daemon."); goto fail; } if (events & PA_IO_EVENT_INPUT) { char *c; if (lirc_nextcode(&code) != 0 || !code) { pa_log("lirc_nextcode() failed."); goto fail; } c = pa_xstrdup(code); c[strcspn(c, "\n\r")] = 0; pa_log_debug("Raw IR code '%s'", c); pa_xfree(c); while (lirc_code2char(u->config, code, &name) == 0 && name) { enum { INVALID, UP, DOWN, MUTE, RESET, MUTE_TOGGLE } volchange = INVALID; pa_log_info("Translated IR code '%s'", name); if (strcasecmp(name, "volume-up") == 0) volchange = UP; else if (strcasecmp(name, "volume-down") == 0) volchange = DOWN; else if (strcasecmp(name, "mute") == 0) volchange = MUTE; else if (strcasecmp(name, "mute-toggle") == 0) volchange = MUTE_TOGGLE; else if (strcasecmp(name, "reset") == 0) volchange = RESET; if (volchange == INVALID) pa_log_warn("Received unknown IR code '%s'", name); else { pa_sink *s; if (!(s = pa_namereg_get(u->module->core, u->sink_name, PA_NAMEREG_SINK))) pa_log("Failed to get sink '%s'", u->sink_name); else { pa_cvolume cv = *pa_sink_get_volume(s, false); switch (volchange) { case UP: pa_cvolume_inc_clamp(&cv, u->volume_step, u->volume_limit); pa_sink_set_volume(s, &cv, true, true); break; case DOWN: pa_cvolume_dec(&cv, u->volume_step); pa_sink_set_volume(s, &cv, true, true); break; case MUTE: pa_sink_set_mute(s, true, true); break; case RESET: pa_sink_set_mute(s, false, true); break; case MUTE_TOGGLE: pa_sink_set_mute(s, !pa_sink_get_mute(s, false), true); break; case INVALID: pa_assert_not_reached(); } } } } } pa_xfree(code); return; fail: u->module->core->mainloop->io_free(u->io); u->io = NULL; pa_module_unload_request(u->module, true); pa_xfree(code); }
/* Free a property object */ static void property_free(pa_property *p) { pa_assert(p); pa_xfree(p->name); pa_xfree(p); }
void pa_source_new_data_set_channel_map(pa_source_new_data *data, const pa_channel_map *map) { pa_assert(data); if ((data->channel_map_is_set = !!map)) data->channel_map = *map; }
void pa_format_info_free(pa_format_info *f) { pa_assert(f); pa_proplist_free(f->plist); pa_xfree(f); }
void pa_source_new_data_set_volume(pa_source_new_data *data, const pa_cvolume *volume) { pa_assert(data); if ((data->volume_is_set = !!volume)) data->volume = *volume; }
int pa__init(pa_module *m) { struct userdata *u; struct stat st; pa_sample_spec ss; pa_channel_map map; pa_modargs *ma; struct pollfd *pollfd; pa_sink_new_data data; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } ss = m->core->default_sample_spec; map = m->core->default_channel_map; if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { pa_log("Invalid sample format specification or channel map"); goto fail; } u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; m->userdata = u; pa_memchunk_reset(&u->memchunk); u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); u->write_type = 0; u->filename = pa_runtime_path(pa_modargs_get_value(ma, "file", DEFAULT_FILE_NAME)); if (mkfifo(u->filename, 0666) < 0) { pa_log("mkfifo('%s'): %s", u->filename, pa_cstrerror(errno)); goto fail; } if ((u->fd = pa_open_cloexec(u->filename, O_RDWR, 0)) < 0) { pa_log("open('%s'): %s", u->filename, pa_cstrerror(errno)); goto fail; } pa_make_fd_nonblock(u->fd); if (fstat(u->fd, &st) < 0) { pa_log("fstat('%s'): %s", u->filename, pa_cstrerror(errno)); goto fail; } if (!S_ISFIFO(st.st_mode)) { pa_log("'%s' is not a FIFO.", u->filename); goto fail; } pa_sink_new_data_init(&data); data.driver = __FILE__; data.module = m; pa_sink_new_data_set_name(&data, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME)); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->filename); pa_proplist_setf(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Unix FIFO sink %s", u->filename); pa_sink_new_data_set_sample_spec(&data, &ss); pa_sink_new_data_set_channel_map(&data, &map); if (pa_modargs_get_proplist(ma, "sink_properties", data.proplist, PA_UPDATE_REPLACE) < 0) { pa_log("Invalid properties"); pa_sink_new_data_done(&data); goto fail; } u->sink = pa_sink_new(m->core, &data, PA_SINK_LATENCY); pa_sink_new_data_done(&data); if (!u->sink) { pa_log("Failed to create sink."); goto fail; } u->sink->parent.process_msg = sink_process_msg; u->sink->userdata = u; pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); pa_sink_set_rtpoll(u->sink, u->rtpoll); pa_sink_set_max_request(u->sink, pa_frame_align(pa_pipe_buf(u->fd), &u->sink->sample_spec)); pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(pa_pipe_buf(u->fd), &u->sink->sample_spec)); u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1); pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL); pollfd->fd = u->fd; pollfd->events = pollfd->revents = 0; if (!(u->thread = pa_thread_new("pipe-sink", thread_func, u))) { pa_log("Failed to create thread."); goto fail; } pa_sink_put(u->sink); pa_modargs_free(ma); return 0; fail: if (ma) pa_modargs_free(ma); pa__done(m); return -1; }
void pa_source_new_data_set_port(pa_source_new_data *data, const char *port) { pa_assert(data); pa_xfree(data->active_port); data->active_port = pa_xstrdup(port); }
static int load_rules(struct userdata *u) { FILE *f; int n = 0; int ret = -1; char buf_name[256], buf_volume[256], buf_sink[256], buf_source[256]; char *ln = buf_name; f = u->table_file ? fopen(u->table_file, "r") : pa_open_config_file(NULL, DEFAULT_VOLUME_TABLE_FILE, NULL, &u->table_file, "r"); if (!f) { if (errno == ENOENT) { pa_log_info("starting with empty ruleset."); ret = 0; } else pa_log("failed to open file '%s': %s", u->table_file, pa_cstrerror(errno)); goto finish; } pa_lock_fd(fileno(f), 1); while (!feof(f)) { struct rule *rule; pa_cvolume v; pa_bool_t v_is_set; if (!fgets(ln, sizeof(buf_name), f)) break; n++; pa_strip_nl(ln); if (ln[0] == '#') continue; if (ln == buf_name) { ln = buf_volume; continue; } if (ln == buf_volume) { ln = buf_sink; continue; } if (ln == buf_sink) { ln = buf_source; continue; } pa_assert(ln == buf_source); if (buf_volume[0]) { if (!parse_volume(buf_volume, &v)) { pa_log("parse failure in %s:%u, stopping parsing", u->table_file, n); goto finish; } v_is_set = TRUE; } else v_is_set = FALSE; ln = buf_name; if (pa_hashmap_get(u->hashmap, buf_name)) { pa_log("double entry in %s:%u, ignoring", u->table_file, n); continue; } rule = pa_xnew(struct rule, 1); rule->name = pa_xstrdup(buf_name); if ((rule->volume_is_set = v_is_set)) rule->volume = v; rule->sink = buf_sink[0] ? pa_xstrdup(buf_sink) : NULL; rule->source = buf_source[0] ? pa_xstrdup(buf_source) : NULL; pa_hashmap_put(u->hashmap, rule->name, rule); } if (ln != buf_name) { pa_log("invalid number of lines in %s.", u->table_file); goto finish; } ret = 0; finish: if (f) { pa_lock_fd(fileno(f), 0); fclose(f); } return ret; }
pa_reserve_wrapper* pa_reserve_wrapper_get(pa_core *c, const char *device_name) { pa_reserve_wrapper *r; int k; char *t; #ifdef HAVE_DBUS DBusError error; dbus_error_init(&error); #endif pa_assert(c); pa_assert(device_name); t = pa_sprintf_malloc("reserve-wrapper@%s", device_name); if ((r = pa_shared_get(c, t))) { pa_xfree(t); pa_assert(PA_REFCNT_VALUE(r) >= 1); PA_REFCNT_INC(r); return r; } r = pa_xnew0(pa_reserve_wrapper, 1); PA_REFCNT_INIT(r); r->core = c; pa_hook_init(&r->hook, r); r->shared_name = t; pa_assert_se(pa_shared_set(c, r->shared_name, r) >= 0); #ifdef HAVE_DBUS if (!(r->connection = pa_dbus_bus_get(c, DBUS_BUS_SESSION, &error)) || dbus_error_is_set(&error)) { pa_log_debug("Unable to contact D-Bus session bus: %s: %s", error.name, error.message); /* We don't treat this as error here because we want allow PA * to run even when no session bus is available. */ return r; } if ((k = rd_acquire( &r->device, pa_dbus_connection_get(r->connection), device_name, _("PulseAudio Sound Server"), 0, request_cb, NULL)) < 0) { if (k == -EBUSY) { pa_log_debug("Device '%s' already locked.", device_name); goto fail; } else { pa_log_debug("Failed to acquire reservation lock on device '%s': %s", device_name, pa_cstrerror(-k)); return r; } } pa_log_debug("Successfully acquired reservation lock on device '%s'", device_name); rd_set_userdata(r->device, r); return r; fail: dbus_error_free(&error); reserve_wrapper_free(r); return NULL; #else return r; #endif }
static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) { struct userdata *u = userdata; pa_sink_input *si = NULL; pa_source_output *so = NULL; struct rule *r; char *name; pa_assert(c); pa_assert(u); if (t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW) && t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE) && t != (PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_NEW) && t != (PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE)) return; if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK_INPUT) { if (!(si = pa_idxset_get_by_index(c->sink_inputs, idx))) return; if (!si->client || !(name = client_name(si->client))) return; } else { pa_assert((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT); if (!(so = pa_idxset_get_by_index(c->source_outputs, idx))) return; if (!so->client || !(name = client_name(so->client))) return; } if ((r = pa_hashmap_get(u->hashmap, name))) { pa_xfree(name); if (si) { if (!r->volume_is_set || !pa_cvolume_equal(pa_sink_input_get_volume(si), &r->volume)) { pa_log_info("Saving volume for <%s>", r->name); r->volume = *pa_sink_input_get_volume(si); r->volume_is_set = TRUE; u->modified = TRUE; } if (!r->sink || strcmp(si->sink->name, r->sink) != 0) { pa_log_info("Saving sink for <%s>", r->name); pa_xfree(r->sink); r->sink = pa_xstrdup(si->sink->name); u->modified = TRUE; } } else { pa_assert(so); if (!r->source || strcmp(so->source->name, r->source) != 0) { pa_log_info("Saving source for <%s>", r->name); pa_xfree(r->source); r->source = pa_xstrdup(so->source->name); u->modified = TRUE; } } } else { pa_log_info("Creating new entry for <%s>", name); r = pa_xnew(struct rule, 1); r->name = name; if (si) { r->volume = *pa_sink_input_get_volume(si); r->volume_is_set = TRUE; r->sink = pa_xstrdup(si->sink->name); r->source = NULL; } else { pa_assert(so); r->volume_is_set = FALSE; r->sink = NULL; r->source = pa_xstrdup(so->source->name); } pa_hashmap_put(u->hashmap, r->name, r); u->modified = TRUE; } if (u->modified && !u->save_time_event) { struct timeval tv; pa_gettimeofday(&tv); tv.tv_sec += SAVE_INTERVAL; u->save_time_event = u->core->mainloop->time_new(u->core->mainloop, &tv, save_time_callback, u); } }
pa_reserve_monitor_wrapper* pa_reserve_monitor_wrapper_get(pa_core *c, const char *device_name) { pa_reserve_monitor_wrapper *w; int k; char *t; #ifdef HAVE_DBUS DBusError error; dbus_error_init(&error); #endif pa_assert(c); pa_assert(device_name); t = pa_sprintf_malloc("reserve-monitor-wrapper@%s", device_name); if ((w = pa_shared_get(c, t))) { pa_xfree(t); pa_assert(PA_REFCNT_VALUE(w) >= 1); PA_REFCNT_INC(w); return w; } w = pa_xnew0(pa_reserve_monitor_wrapper, 1); PA_REFCNT_INIT(w); w->core = c; pa_hook_init(&w->hook, w); w->shared_name = t; pa_assert_se(pa_shared_set(c, w->shared_name, w) >= 0); #ifdef HAVE_DBUS if (!(w->connection = pa_dbus_bus_get(c, DBUS_BUS_SESSION, &error)) || dbus_error_is_set(&error)) { pa_log_debug("Unable to contact D-Bus session bus: %s: %s", error.name, error.message); /* We don't treat this as error here because we want allow PA * to run even when no session bus is available. */ return w; } if ((k = rm_watch( &w->monitor, pa_dbus_connection_get(w->connection), device_name, change_cb, NULL)) < 0) { pa_log_debug("Failed to create watch on device '%s': %s", device_name, pa_cstrerror(-k)); goto fail; } pa_log_debug("Successfully create reservation lock monitor for device '%s'", device_name); rm_set_userdata(w->monitor, w); return w; fail: dbus_error_free(&error); reserve_monitor_wrapper_free(w); return NULL; #else return w; #endif }
/* Called from main context */ pa_source* pa_source_new( pa_core *core, pa_source_new_data *data, pa_source_flags_t flags) { pa_source *s; const char *name; char st[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; char *pt; pa_assert(core); pa_assert(data); pa_assert(data->name); pa_assert_ctl_context(); s = pa_msgobject_new(pa_source); if (!(name = pa_namereg_register(core, data->name, PA_NAMEREG_SOURCE, s, data->namereg_fail))) { pa_log_debug("Failed to register name %s.", data->name); pa_xfree(s); return NULL; } pa_source_new_data_set_name(data, name); if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_NEW], data) < 0) { pa_xfree(s); pa_namereg_unregister(core, name); return NULL; } /* FIXME, need to free s here on failure */ pa_return_null_if_fail(!data->driver || pa_utf8_valid(data->driver)); pa_return_null_if_fail(data->name && pa_utf8_valid(data->name) && data->name[0]); pa_return_null_if_fail(data->sample_spec_is_set && pa_sample_spec_valid(&data->sample_spec)); if (!data->channel_map_is_set) pa_return_null_if_fail(pa_channel_map_init_auto(&data->channel_map, data->sample_spec.channels, PA_CHANNEL_MAP_DEFAULT)); pa_return_null_if_fail(pa_channel_map_valid(&data->channel_map)); pa_return_null_if_fail(data->channel_map.channels == data->sample_spec.channels); if (!data->volume_is_set) pa_cvolume_reset(&data->volume, data->sample_spec.channels); pa_return_null_if_fail(pa_cvolume_valid(&data->volume)); pa_return_null_if_fail(pa_cvolume_compatible(&data->volume, &data->sample_spec)); if (!data->muted_is_set) data->muted = FALSE; if (data->card) pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->card->proplist); pa_device_init_description(data->proplist); pa_device_init_icon(data->proplist, FALSE); pa_device_init_intended_roles(data->proplist); if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_FIXATE], data) < 0) { pa_xfree(s); pa_namereg_unregister(core, name); return NULL; } s->parent.parent.free = source_free; s->parent.process_msg = pa_source_process_msg; s->core = core; s->state = PA_SOURCE_INIT; s->flags = flags; s->priority = 0; s->suspend_cause = 0; s->name = pa_xstrdup(name); s->proplist = pa_proplist_copy(data->proplist); s->driver = pa_xstrdup(pa_path_get_filename(data->driver)); s->module = data->module; s->card = data->card; s->priority = pa_device_init_priority(s->proplist); s->sample_spec = data->sample_spec; s->channel_map = data->channel_map; s->outputs = pa_idxset_new(NULL, NULL); s->n_corked = 0; s->monitor_of = NULL; s->output_from_master = NULL; s->volume = data->volume; pa_cvolume_reset(&s->soft_volume, s->sample_spec.channels); s->base_volume = PA_VOLUME_NORM; s->n_volume_steps = PA_VOLUME_NORM+1; s->muted = data->muted; s->refresh_volume = s->refresh_muted = FALSE; reset_callbacks(s); s->userdata = NULL; s->asyncmsgq = NULL; /* As a minor optimization we just steal the list instead of * copying it here */ s->ports = data->ports; data->ports = NULL; s->active_port = NULL; s->save_port = FALSE; if (data->active_port && s->ports) if ((s->active_port = pa_hashmap_get(s->ports, data->active_port))) s->save_port = data->save_port; if (!s->active_port && s->ports) { void *state; pa_device_port *p; PA_HASHMAP_FOREACH(p, s->ports, state) if (!s->active_port || p->priority > s->active_port->priority) s->active_port = p; }
DBusConnection* pa_dbus_wrap_connection_get(pa_dbus_wrap_connection *c) { pa_assert(c); pa_assert(c->connection); return c->connection; }
void pa_source_new_data_set_name(pa_source_new_data *data, const char *name) { pa_assert(data); pa_xfree(data->name); data->name = pa_xstrdup(name); }
int pa__init(pa_module*m) { struct userdata *u; pa_sample_spec ss; pa_channel_map map; pa_modargs *ma; char *t; pa_sink *master; pa_sink_input_new_data sink_input_data; pa_sink_new_data sink_data; const char *plugin, *label, *input_ladspaport_map, *output_ladspaport_map; LADSPA_Descriptor_Function descriptor_func; unsigned long input_ladspaport[PA_CHANNELS_MAX], output_ladspaport[PA_CHANNELS_MAX]; const char *e, *cdata; const LADSPA_Descriptor *d; unsigned long p, h, j, n_control, c; pa_bool_t *use_default = NULL; pa_assert(m); pa_assert_cc(sizeof(LADSPA_Data) == sizeof(float)); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } if (!(master = pa_namereg_get(m->core, pa_modargs_get_value(ma, "master", NULL), PA_NAMEREG_SINK))) { pa_log("Master sink not found"); goto fail; } ss = master->sample_spec; ss.format = PA_SAMPLE_FLOAT32; map = master->channel_map; if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { pa_log("Invalid sample format specification or channel map"); goto fail; } if (!(plugin = pa_modargs_get_value(ma, "plugin", NULL))) { pa_log("Missing LADSPA plugin name"); goto fail; } if (!(label = pa_modargs_get_value(ma, "label", NULL))) { pa_log("Missing LADSPA plugin label"); goto fail; } if (!(input_ladspaport_map = pa_modargs_get_value(ma, "input_ladspaport_map", NULL))) pa_log_debug("Using default input ladspa port mapping"); if (!(output_ladspaport_map = pa_modargs_get_value(ma, "output_ladspaport_map", NULL))) pa_log_debug("Using default output ladspa port mapping"); cdata = pa_modargs_get_value(ma, "control", NULL); u = pa_xnew0(struct userdata, 1); u->module = m; m->userdata = u; u->memblockq = pa_memblockq_new(0, MEMBLOCKQ_MAXLENGTH, 0, pa_frame_size(&ss), 1, 1, 0, NULL); u->max_ladspaport_count = 1; /*to avoid division by zero etc. in pa__done when failing before this value has been set*/ u->channels = 0; u->input = NULL; u->output = NULL; if (!(e = getenv("LADSPA_PATH"))) e = LADSPA_PATH; /* FIXME: This is not exactly thread safe */ t = pa_xstrdup(lt_dlgetsearchpath()); lt_dlsetsearchpath(e); m->dl = lt_dlopenext(plugin); lt_dlsetsearchpath(t); pa_xfree(t); if (!m->dl) { pa_log("Failed to load LADSPA plugin: %s", lt_dlerror()); goto fail; } if (!(descriptor_func = (LADSPA_Descriptor_Function) pa_load_sym(m->dl, NULL, "ladspa_descriptor"))) { pa_log("LADSPA module lacks ladspa_descriptor() symbol."); goto fail; } for (j = 0;; j++) { if (!(d = descriptor_func(j))) { pa_log("Failed to find plugin label '%s' in plugin '%s'.", label, plugin); goto fail; } if (strcmp(d->Label, label) == 0) break; } u->descriptor = d; pa_log_debug("Module: %s", plugin); pa_log_debug("Label: %s", d->Label); pa_log_debug("Unique ID: %lu", d->UniqueID); pa_log_debug("Name: %s", d->Name); pa_log_debug("Maker: %s", d->Maker); pa_log_debug("Copyright: %s", d->Copyright); n_control = 0; u->channels = ss.channels; /* * Enumerate ladspa ports * Default mapping is in order given by the plugin */ for (p = 0; p < d->PortCount; p++) { if (LADSPA_IS_PORT_AUDIO(d->PortDescriptors[p])) { if (LADSPA_IS_PORT_INPUT(d->PortDescriptors[p])) { pa_log_debug("Port %lu is input: %s", p, d->PortNames[p]); input_ladspaport[u->input_count] = p; u->input_count++; } else if (LADSPA_IS_PORT_OUTPUT(d->PortDescriptors[p])) { pa_log_debug("Port %lu is output: %s", p, d->PortNames[p]); output_ladspaport[u->output_count] = p; u->output_count++; } } else if (LADSPA_IS_PORT_CONTROL(d->PortDescriptors[p]) && LADSPA_IS_PORT_INPUT(d->PortDescriptors[p])) { pa_log_debug("Port %lu is control: %s", p, d->PortNames[p]); n_control++; } else pa_log_debug("Ignored port %s", d->PortNames[p]); /* XXX: Has anyone ever seen an in-place plugin with non-equal number of input and output ports? */ /* Could be if the plugin is for up-mixing stereo to 5.1 channels */ /* Or if the plugin is down-mixing 5.1 to two channel stereo or binaural encoded signal */ if (u->input_count > u->max_ladspaport_count) u->max_ladspaport_count = u->input_count; else u->max_ladspaport_count = u->output_count; } if (u->channels % u->max_ladspaport_count) { pa_log("Cannot handle non-integral number of plugins required for given number of channels"); goto fail; } pa_log_debug("Will run %lu plugin instances", u->channels / u->max_ladspaport_count); /* Parse data for input ladspa port map */ if (input_ladspaport_map) { const char *state = NULL; char *pname; c = 0; while ((pname = pa_split(input_ladspaport_map, ",", &state))) { if (c == u->input_count) { pa_log("Too many ports in input ladspa port map"); goto fail; } for (p = 0; p < d->PortCount; p++) { if (strcmp(d->PortNames[p], pname) == 0) { if (LADSPA_IS_PORT_AUDIO(d->PortDescriptors[p]) && LADSPA_IS_PORT_INPUT(d->PortDescriptors[p])) { input_ladspaport[c] = p; } else { pa_log("Port %s is not an audio input ladspa port", pname); pa_xfree(pname); goto fail; } } } c++; pa_xfree(pname); } } /* Parse data for output port map */ if (output_ladspaport_map) { const char *state = NULL; char *pname; c = 0; while ((pname = pa_split(output_ladspaport_map, ",", &state))) { if (c == u->output_count) { pa_log("Too many ports in output ladspa port map"); goto fail; } for (p = 0; p < d->PortCount; p++) { if (strcmp(d->PortNames[p], pname) == 0) { if (LADSPA_IS_PORT_AUDIO(d->PortDescriptors[p]) && LADSPA_IS_PORT_OUTPUT(d->PortDescriptors[p])) { output_ladspaport[c] = p; } else { pa_log("Port %s is not an output ladspa port", pname); pa_xfree(pname); goto fail; } } } c++; pa_xfree(pname); } } u->block_size = pa_frame_align(pa_mempool_block_size_max(m->core->mempool), &ss); /* Create buffers */ if (LADSPA_IS_INPLACE_BROKEN(d->Properties)) { u->input = (LADSPA_Data**) pa_xnew(LADSPA_Data*, (unsigned) u->input_count); for (c = 0; c < u->input_count; c++) u->input[c] = (LADSPA_Data*) pa_xnew(uint8_t, (unsigned) u->block_size); u->output = (LADSPA_Data**) pa_xnew(LADSPA_Data*, (unsigned) u->output_count); for (c = 0; c < u->output_count; c++) u->output[c] = (LADSPA_Data*) pa_xnew(uint8_t, (unsigned) u->block_size); } else {
void pa_source_new_data_set_sample_spec(pa_source_new_data *data, const pa_sample_spec *spec) { pa_assert(data); if ((data->sample_spec_is_set = !!spec)) data->sample_spec = *spec; }
int pa__init (pa_module *m) { struct userdata *u; pa_channel_map map; pa_sample_spec ss; pa_modargs *ma = NULL; pa_sink_new_data data; size_t nbytes; pa_assert(m); ma = pa_modargs_new(m->argument, valid_modargs); if (!ma) { pa_log ("failed to parse module arguments."); goto fail; } ss = m->core->default_sample_spec; map = m->core->default_channel_map; m->userdata = u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; u->rtpoll = pa_rtpoll_new(); /* Init message queueu */ pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); pa_sink_new_data_init(&data); data.driver = __FILE__; data.module = m; pa_sink_new_data_set_name(&data, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME)); pa_sink_new_data_set_sample_spec(&data, &ss); pa_sink_new_data_set_channel_map(&data, &map); u->sink = pa_sink_new(m->core, &data, PA_SINK_LATENCY); pa_sink_new_data_done(&data); if (!u->sink) { pa_log("Failed to create sink"); goto fail; } u->sink->parent.process_msg = sink_process_msg; u->sink->userdata = u; /* set message queue and rtopoll to sink */ pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); pa_sink_set_rtpoll(u->sink, u->rtpoll); u->block_usec = BLOCK_USEC; nbytes = pa_usec_to_bytes(u->block_usec, &u->sink->sample_spec); pa_sink_set_max_rewind(u->sink, nbytes); pa_sink_set_max_request(u->sink, nbytes); u->thread = pa_thread_new("awesome-sink", thread_func, u); if (!u->thread) { pa_log ("Failed to create thread"); goto fail; } /* this called only when sink latency is set to dynamic */ //pa_sink_set_latency_range(u->sink, 0, BLOCK_USEC); pa_sink_put(u->sink); /* sink given to core */ pa_modargs_free(ma); return 0; fail: return -1; }
int pa_scache_play_item(pa_core *c, const char *name, pa_sink *sink, pa_volume_t volume, pa_proplist *p, uint32_t *sink_input_idx) { pa_scache_entry *e; pa_cvolume r; pa_proplist *merged; pa_bool_t pass_volume; pa_assert(c); pa_assert(name); pa_assert(sink); if (!(e = pa_namereg_get(c, name, PA_NAMEREG_SAMPLE))) return -1; merged = pa_proplist_new(); pa_proplist_sets(merged, PA_PROP_MEDIA_NAME, name); pa_proplist_sets(merged, PA_PROP_EVENT_ID, name); if (e->lazy && !e->memchunk.memblock) { pa_channel_map old_channel_map = e->channel_map; if (pa_sound_file_load(c->mempool, e->filename, &e->sample_spec, &e->channel_map, &e->memchunk, merged) < 0) goto fail; pa_subscription_post(c, PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE|PA_SUBSCRIPTION_EVENT_CHANGE, e->index); if (e->volume_is_set) { if (pa_cvolume_valid(&e->volume)) pa_cvolume_remap(&e->volume, &old_channel_map, &e->channel_map); else pa_cvolume_reset(&e->volume, e->sample_spec.channels); } } if (!e->memchunk.memblock) goto fail; pa_log_debug("Playing sample \"%s\" on \"%s\"", name, sink->name); pass_volume = TRUE; if (e->volume_is_set && volume != PA_VOLUME_INVALID) { pa_cvolume_set(&r, e->sample_spec.channels, volume); pa_sw_cvolume_multiply(&r, &r, &e->volume); } else if (e->volume_is_set) r = e->volume; else if (volume != PA_VOLUME_INVALID) pa_cvolume_set(&r, e->sample_spec.channels, volume); else pass_volume = FALSE; pa_proplist_update(merged, PA_UPDATE_REPLACE, e->proplist); if (p) pa_proplist_update(merged, PA_UPDATE_REPLACE, p); if (pa_play_memchunk(sink, &e->sample_spec, &e->channel_map, &e->memchunk, pass_volume ? &r : NULL, merged, PA_SINK_INPUT_NO_CREATE_ON_SUSPEND|PA_SINK_INPUT_KILL_ON_SUSPEND, sink_input_idx) < 0) goto fail; pa_proplist_free(merged); if (e->lazy) time(&e->last_used_time); return 0; fail: pa_proplist_free(merged); return -1; }