mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	udev: allow passing of ignore_dB= parameter to alsa modules
This commit is contained in:
		
							parent
							
								
									24e582808c
								
							
						
					
					
						commit
						d6f598ab3e
					
				
					 4 changed files with 49 additions and 23 deletions
				
			
		| 
						 | 
					@ -68,6 +68,8 @@
 | 
				
			||||||
#define TSCHED_MIN_SLEEP_USEC (10*PA_USEC_PER_MSEC)               /* 10ms -- Sleep at least 10ms on each iteration */
 | 
					#define TSCHED_MIN_SLEEP_USEC (10*PA_USEC_PER_MSEC)               /* 10ms -- Sleep at least 10ms on each iteration */
 | 
				
			||||||
#define TSCHED_MIN_WAKEUP_USEC (4*PA_USEC_PER_MSEC)               /* 4ms  -- Wakeup at least this long before the buffer runs empty*/
 | 
					#define TSCHED_MIN_WAKEUP_USEC (4*PA_USEC_PER_MSEC)               /* 4ms  -- Wakeup at least this long before the buffer runs empty*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define VOLUME_ACCURACY (PA_VOLUME_NORM/100)  /* don't require volume adjustments to be perfectly correct. don't necessarily extend granularity in software unless the differences get greater than this level */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct userdata {
 | 
					struct userdata {
 | 
				
			||||||
    pa_core *core;
 | 
					    pa_core *core;
 | 
				
			||||||
    pa_module *module;
 | 
					    pa_module *module;
 | 
				
			||||||
| 
						 | 
					@ -1034,15 +1036,11 @@ static void sink_get_volume_cb(pa_sink *s) {
 | 
				
			||||||
    if (pa_cvolume_equal(&u->hardware_volume, &r))
 | 
					    if (pa_cvolume_equal(&u->hardware_volume, &r))
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    s->virtual_volume = u->hardware_volume = r;
 | 
					    s->real_volume = u->hardware_volume = r;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (u->mixer_path->has_dB) {
 | 
					 | 
				
			||||||
        pa_cvolume reset;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Hmm, so the hardware volume changed, let's reset our software volume */
 | 
					    /* Hmm, so the hardware volume changed, let's reset our software volume */
 | 
				
			||||||
        pa_cvolume_reset(&reset, s->sample_spec.channels);
 | 
					    if (u->mixer_path->has_dB)
 | 
				
			||||||
        pa_sink_set_soft_volume(s, &reset);
 | 
					        pa_sink_set_soft_volume(s, NULL);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void sink_set_volume_cb(pa_sink *s) {
 | 
					static void sink_set_volume_cb(pa_sink *s) {
 | 
				
			||||||
| 
						 | 
					@ -1055,7 +1053,7 @@ static void sink_set_volume_cb(pa_sink *s) {
 | 
				
			||||||
    pa_assert(u->mixer_handle);
 | 
					    pa_assert(u->mixer_handle);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Shift up by the base volume */
 | 
					    /* Shift up by the base volume */
 | 
				
			||||||
    pa_sw_cvolume_divide_scalar(&r, &s->virtual_volume, s->base_volume);
 | 
					    pa_sw_cvolume_divide_scalar(&r, &s->real_volume, s->base_volume);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
 | 
					    if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &r) < 0)
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
| 
						 | 
					@ -1066,13 +1064,26 @@ static void sink_set_volume_cb(pa_sink *s) {
 | 
				
			||||||
    u->hardware_volume = r;
 | 
					    u->hardware_volume = r;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (u->mixer_path->has_dB) {
 | 
					    if (u->mixer_path->has_dB) {
 | 
				
			||||||
 | 
					        pa_cvolume new_soft_volume;
 | 
				
			||||||
 | 
					        pa_bool_t accurate_enough;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Match exactly what the user requested by software */
 | 
					        /* Match exactly what the user requested by software */
 | 
				
			||||||
        pa_sw_cvolume_divide(&s->soft_volume, &s->virtual_volume, &u->hardware_volume);
 | 
					        pa_sw_cvolume_divide(&new_soft_volume, &s->real_volume, &u->hardware_volume);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->virtual_volume));
 | 
					        /* If the adjustment to do in software is only minimal we
 | 
				
			||||||
 | 
					         * can skip it. That saves us CPU at the expense of a bit of
 | 
				
			||||||
 | 
					         * accuracy */
 | 
				
			||||||
 | 
					        accurate_enough =
 | 
				
			||||||
 | 
					            (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(t, sizeof(t), &s->real_volume));
 | 
				
			||||||
        pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume));
 | 
					        pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &u->hardware_volume));
 | 
				
			||||||
        pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->soft_volume));
 | 
					        pa_log_debug("Calculated software volume: %s (accurate-enough=%s)", pa_cvolume_snprint(t, sizeof(t), &new_soft_volume),
 | 
				
			||||||
 | 
					                     pa_yes_no(accurate_enough));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!accurate_enough)
 | 
				
			||||||
 | 
					            s->soft_volume = new_soft_volume;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
 | 
					        pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &r));
 | 
				
			||||||
| 
						 | 
					@ -1080,7 +1091,7 @@ static void sink_set_volume_cb(pa_sink *s) {
 | 
				
			||||||
        /* We can't match exactly what the user requested, hence let's
 | 
					        /* We can't match exactly what the user requested, hence let's
 | 
				
			||||||
         * at least tell the user about it */
 | 
					         * at least tell the user about it */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        s->virtual_volume = r;
 | 
					        s->real_volume = r;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1476,12 +1476,12 @@ static void sink_set_volume_cb(pa_sink *s) {
 | 
				
			||||||
    if (u->profile != PROFILE_HSP)
 | 
					    if (u->profile != PROFILE_HSP)
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gain = (pa_cvolume_max(&s->virtual_volume) * 15) / PA_VOLUME_NORM;
 | 
					    gain = (pa_cvolume_max(&s->real_volume) * 15) / PA_VOLUME_NORM;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (gain > 15)
 | 
					    if (gain > 15)
 | 
				
			||||||
        gain = 15;
 | 
					        gain = 15;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_cvolume_set(&s->virtual_volume, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
 | 
					    pa_cvolume_set(&s->real_volume, u->sample_spec.channels, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert_se(m = dbus_message_new_method_call("org.bluez", u->path, "org.bluez.Headset", "SetSpeakerGain"));
 | 
					    pa_assert_se(m = dbus_message_new_method_call("org.bluez", u->path, "org.bluez.Headset", "SetSpeakerGain"));
 | 
				
			||||||
    pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_UINT16, &gain, DBUS_TYPE_INVALID));
 | 
					    pa_assert_se(dbus_message_append_args(m, DBUS_TYPE_UINT16, &gain, DBUS_TYPE_INVALID));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -133,7 +133,7 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
 | 
				
			||||||
                                    cv.values[i] = PA_VOLUME_MAX;
 | 
					                                    cv.values[i] = PA_VOLUME_MAX;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
 | 
					                            pa_sink_set_volume(s, &cv, TRUE, TRUE);
 | 
				
			||||||
                            break;
 | 
					                            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        case DOWN:
 | 
					                        case DOWN:
 | 
				
			||||||
| 
						 | 
					@ -144,7 +144,7 @@ static void io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event
 | 
				
			||||||
                                    cv.values[i] = PA_VOLUME_MUTED;
 | 
					                                    cv.values[i] = PA_VOLUME_MUTED;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            pa_sink_set_volume(s, &cv, TRUE, TRUE, TRUE, TRUE);
 | 
					                            pa_sink_set_volume(s, &cv, TRUE, TRUE);
 | 
				
			||||||
                            break;
 | 
					                            break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        case MUTE:
 | 
					                        case MUTE:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,6 +39,9 @@ PA_MODULE_AUTHOR("Lennart Poettering");
 | 
				
			||||||
PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers");
 | 
					PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers");
 | 
				
			||||||
PA_MODULE_VERSION(PACKAGE_VERSION);
 | 
					PA_MODULE_VERSION(PACKAGE_VERSION);
 | 
				
			||||||
PA_MODULE_LOAD_ONCE(TRUE);
 | 
					PA_MODULE_LOAD_ONCE(TRUE);
 | 
				
			||||||
 | 
					PA_MODULE_USAGE(
 | 
				
			||||||
 | 
					        "tsched=<enable system timer based scheduling mode?> "
 | 
				
			||||||
 | 
					        "ignore_dB=<ignore dB information from the device?>");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct device {
 | 
					struct device {
 | 
				
			||||||
    char *path;
 | 
					    char *path;
 | 
				
			||||||
| 
						 | 
					@ -50,7 +53,9 @@ struct device {
 | 
				
			||||||
struct userdata {
 | 
					struct userdata {
 | 
				
			||||||
    pa_core *core;
 | 
					    pa_core *core;
 | 
				
			||||||
    pa_hashmap *devices;
 | 
					    pa_hashmap *devices;
 | 
				
			||||||
    pa_bool_t use_tsched;
 | 
					
 | 
				
			||||||
 | 
					    pa_bool_t use_tsched:1;
 | 
				
			||||||
 | 
					    pa_bool_t ignore_dB:1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct udev* udev;
 | 
					    struct udev* udev;
 | 
				
			||||||
    struct udev_monitor *monitor;
 | 
					    struct udev_monitor *monitor;
 | 
				
			||||||
| 
						 | 
					@ -62,6 +67,7 @@ struct userdata {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char* const valid_modargs[] = {
 | 
					static const char* const valid_modargs[] = {
 | 
				
			||||||
    "tsched",
 | 
					    "tsched",
 | 
				
			||||||
 | 
					    "ignore_dB",
 | 
				
			||||||
    NULL
 | 
					    NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -140,12 +146,14 @@ static void card_changed(struct userdata *u, struct udev_device *dev) {
 | 
				
			||||||
    args = pa_sprintf_malloc("device_id=\"%s\" "
 | 
					    args = pa_sprintf_malloc("device_id=\"%s\" "
 | 
				
			||||||
                             "name=\"%s\" "
 | 
					                             "name=\"%s\" "
 | 
				
			||||||
                             "card_name=\"%s\" "
 | 
					                             "card_name=\"%s\" "
 | 
				
			||||||
                             "tsched=%i "
 | 
					                             "tsched=%s "
 | 
				
			||||||
 | 
					                             "ignore_dB=%s "
 | 
				
			||||||
                             "card_properties=\"module-udev-detect.discovered=1\"",
 | 
					                             "card_properties=\"module-udev-detect.discovered=1\"",
 | 
				
			||||||
                             path_get_card_id(path),
 | 
					                             path_get_card_id(path),
 | 
				
			||||||
                             n,
 | 
					                             n,
 | 
				
			||||||
                             card_name,
 | 
					                             card_name,
 | 
				
			||||||
                             (int) u->use_tsched);
 | 
					                             pa_yes_no(u->use_tsched),
 | 
				
			||||||
 | 
					                             pa_yes_no(u->ignore_dB));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_log_debug("Loading module-alsa-card with arguments '%s'", args);
 | 
					    pa_log_debug("Loading module-alsa-card with arguments '%s'", args);
 | 
				
			||||||
    m = pa_module_load(u->core, "module-alsa-card", args);
 | 
					    m = pa_module_load(u->core, "module-alsa-card", args);
 | 
				
			||||||
| 
						 | 
					@ -364,6 +372,7 @@ int pa__init(pa_module *m) {
 | 
				
			||||||
    struct udev_enumerate *enumerate = NULL;
 | 
					    struct udev_enumerate *enumerate = NULL;
 | 
				
			||||||
    struct udev_list_entry *item = NULL, *first = NULL;
 | 
					    struct udev_list_entry *item = NULL, *first = NULL;
 | 
				
			||||||
    int fd;
 | 
					    int fd;
 | 
				
			||||||
 | 
					    pa_bool_t use_tsched = TRUE, ignore_dB = FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(m);
 | 
					    pa_assert(m);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -375,13 +384,19 @@ int pa__init(pa_module *m) {
 | 
				
			||||||
    m->userdata = u = pa_xnew0(struct userdata, 1);
 | 
					    m->userdata = u = pa_xnew0(struct userdata, 1);
 | 
				
			||||||
    u->core = m->core;
 | 
					    u->core = m->core;
 | 
				
			||||||
    u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
 | 
					    u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
 | 
				
			||||||
    u->use_tsched = TRUE;
 | 
					 | 
				
			||||||
    u->inotify_fd = -1;
 | 
					    u->inotify_fd = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (pa_modargs_get_value_boolean(ma, "tsched", &u->use_tsched) < 0) {
 | 
					    if (pa_modargs_get_value_boolean(ma, "tsched", &use_tsched) < 0) {
 | 
				
			||||||
        pa_log("Failed to parse tsched argument.");
 | 
					        pa_log("Failed to parse tsched= argument.");
 | 
				
			||||||
        goto fail;
 | 
					        goto fail;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    u->use_tsched = use_tsched;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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 (!(u->udev = udev_new())) {
 | 
					    if (!(u->udev = udev_new())) {
 | 
				
			||||||
        pa_log("Failed to initialize udev library.");
 | 
					        pa_log("Failed to initialize udev library.");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue