static void sink_get_volume_cb(pa_sink *s) {
struct userdata *u = s->userdata;
pa_cvolume r;
- char vol_str_pcnt[PA_CVOLUME_SNPRINT_MAX];
+ char volume_buf[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
pa_assert(u);
pa_assert(u->mixer_path);
/* Shift down by the base volume, so that 0dB becomes maximum volume */
pa_sw_cvolume_multiply_scalar(&r, &r, s->base_volume);
- pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &r));
-
- if (u->mixer_path->has_dB) {
- char vol_str_db[PA_SW_CVOLUME_SNPRINT_DB_MAX];
-
- pa_log_debug(" in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &r));
- }
+ pa_log_debug("Read hardware volume: %s",
+ pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &r, &s->channel_map, u->mixer_path->has_dB));
if (pa_cvolume_equal(&u->hardware_volume, &r))
return;
static void sink_set_volume_cb(pa_sink *s) {
struct userdata *u = s->userdata;
pa_cvolume r;
- char vol_str_pcnt[PA_CVOLUME_SNPRINT_MAX];
+ char volume_buf[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
bool deferred_volume = !!(s->flags & PA_SINK_DEFERRED_VOLUME);
pa_assert(u);
if (u->mixer_path->has_dB) {
pa_cvolume new_soft_volume;
bool accurate_enough;
- char vol_str_db[PA_SW_CVOLUME_SNPRINT_DB_MAX];
/* Match exactly what the user requested by software */
pa_sw_cvolume_divide(&new_soft_volume, &s->real_volume, &u->hardware_volume);
(pa_cvolume_min(&new_soft_volume) >= (PA_VOLUME_NORM - VOLUME_ACCURACY)) &&
(pa_cvolume_max(&new_soft_volume) <= (PA_VOLUME_NORM + VOLUME_ACCURACY));
- pa_log_debug("Requested volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &s->real_volume));
- pa_log_debug(" in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &s->real_volume));
- pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &u->hardware_volume));
- pa_log_debug(" in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &u->hardware_volume));
+ pa_log_debug("Requested volume: %s",
+ pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &s->real_volume, &s->channel_map, true));
+ pa_log_debug("Got hardware volume: %s",
+ pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &u->hardware_volume, &s->channel_map, true));
pa_log_debug("Calculated software volume: %s (accurate-enough=%s)",
- pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &new_soft_volume),
+ pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &new_soft_volume, &s->channel_map, true),
pa_yes_no(accurate_enough));
- pa_log_debug(" in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &new_soft_volume));
if (!accurate_enough)
s->soft_volume = new_soft_volume;
} else {
- pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &r));
+ pa_log_debug("Wrote hardware volume: %s",
+ pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &r, &s->channel_map, false));
/* We can't match exactly what the user requested, hence let's
* at least tell the user about it */
(pa_cvolume_max(&tmp_vol) <= (PA_VOLUME_NORM + VOLUME_ACCURACY));
if (!accurate_enough) {
- union {
- char db[2][PA_SW_CVOLUME_SNPRINT_DB_MAX];
- char pcnt[2][PA_CVOLUME_SNPRINT_MAX];
- } vol;
+ char volume_buf[2][PA_CVOLUME_SNPRINT_VERBOSE_MAX];
pa_log_debug("Written HW volume did not match with the request: %s (request) != %s",
- pa_cvolume_snprint(vol.pcnt[0], sizeof(vol.pcnt[0]), &s->thread_info.current_hw_volume),
- pa_cvolume_snprint(vol.pcnt[1], sizeof(vol.pcnt[1]), &hw_vol));
- pa_log_debug(" in dB: %s (request) != %s",
- pa_sw_cvolume_snprint_dB(vol.db[0], sizeof(vol.db[0]), &s->thread_info.current_hw_volume),
- pa_sw_cvolume_snprint_dB(vol.db[1], sizeof(vol.db[1]), &hw_vol));
+ pa_cvolume_snprint_verbose(volume_buf[0],
+ sizeof(volume_buf[0]),
+ &s->thread_info.current_hw_volume,
+ &s->channel_map,
+ true),
+ pa_cvolume_snprint_verbose(volume_buf[1], sizeof(volume_buf[1]), &hw_vol, &s->channel_map, true));
}
}
}
-static void sink_get_mute_cb(pa_sink *s) {
+static int sink_get_mute_cb(pa_sink *s, bool *mute) {
struct userdata *u = s->userdata;
- bool b;
pa_assert(u);
pa_assert(u->mixer_path);
pa_assert(u->mixer_handle);
- if (pa_alsa_path_get_mute(u->mixer_path, u->mixer_handle, &b) < 0)
- return;
+ if (pa_alsa_path_get_mute(u->mixer_path, u->mixer_handle, mute) < 0)
+ return -1;
- s->muted = b;
+ return 0;
}
static void sink_set_mute_cb(pa_sink *s) {
static pa_idxset* sink_get_formats(pa_sink *s) {
struct userdata *u = s->userdata;
- pa_idxset *ret = pa_idxset_new(NULL, NULL);
- pa_format_info *f;
- uint32_t idx;
pa_assert(u);
- PA_IDXSET_FOREACH(f, u->formats, idx) {
- pa_idxset_put(ret, pa_format_info_copy(f), NULL);
- }
-
- return ret;
+ return pa_idxset_copy(u->formats, (pa_copy_func_t) pa_format_info_copy);
}
static bool sink_set_formats(pa_sink *s, pa_idxset *formats) {
return true;
}
-static bool sink_update_rate_cb(pa_sink *s, uint32_t rate) {
+static int sink_update_rate_cb(pa_sink *s, uint32_t rate) {
struct userdata *u = s->userdata;
int i;
bool supported = false;
if (!supported) {
pa_log_info("Sink does not support sample rate of %d Hz", rate);
- return false;
+ return -1;
}
if (!PA_SINK_IS_OPENED(s->state)) {
pa_log_info("Updating rate for device %s, new rate is %d",u->device_name, rate);
u->sink->sample_spec.rate = rate;
- return true;
+ return 0;
}
- return false;
+ return -1;
}
static int process_rewind(struct userdata *u) {
ss = m->core->default_sample_spec;
map = m->core->default_channel_map;
+
+ /* Pick sample spec overrides from the mapping, if any */
+ if (mapping) {
+ if (mapping->sample_spec.format != PA_SAMPLE_INVALID)
+ ss.format = mapping->sample_spec.format;
+ if (mapping->sample_spec.rate != 0)
+ ss.rate = mapping->sample_spec.rate;
+ if (mapping->sample_spec.channels != 0) {
+ ss.channels = mapping->sample_spec.channels;
+ if (pa_channel_map_valid(&mapping->channel_map))
+ pa_assert(pa_channel_map_compatible(&mapping->channel_map, &ss));
+ }
+ }
+
+ /* Override with modargs if provided */
if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {
pa_log("Failed to parse sample specification and channel map");
goto fail;
pa_proplist_sets(data.proplist, key, pa_proplist_gets(mapping->proplist, key));
}
- pa_alsa_init_description(data.proplist);
+ pa_alsa_init_description(data.proplist, card);
if (u->control_device)
pa_alsa_init_proplist_ctl(data.proplist, u->control_device);
if (u->sink->set_mute)
u->sink->set_mute(u->sink);
} else {
- if (u->sink->get_mute)
- u->sink->get_mute(u->sink);
+ if (u->sink->get_mute) {
+ bool mute;
+
+ if (u->sink->get_mute(u->sink, &mute) >= 0)
+ pa_sink_set_mute(u->sink, mute, false);
+ }
}
if ((data.volume_is_set || data.muted_is_set) && u->sink->write_volume)