summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarijn Suijten <marijns95@gmail.com>2020-06-07 17:07:20 +0200
committerMarijn Suijten <marijns95@gmail.com>2021-03-16 00:19:45 +0100
commitd84ca030800d0c2d61d57aeedc5be8c377378247 (patch)
treefea05d994fd7301cedba462691e2ca58174fcd78 /src
parentbfb3aeac1cd968954627e3f5a7b3d62a58e9a45e (diff)
downloadpulseaudio-d84ca030800d0c2d61d57aeedc5be8c377378247.tar.gz
bluetooth: Generalize speaker/microphone naming to sink/source
Sink and source naming is more generic when dealing with audio that is directional in the sense that it either goes to or comes from the other device, but not necessarily a microphone or speaker. A concrete example is the swapped meaning when the current device is in the HeadSet profile. The incoming audio can come from any source, not necessarily a microphone. Likewise, audio captured by the microphone of the headset is not necessarily played back by a speaker on the AG, it is merely acting as a sink for the data: further handling is irrelevant to the naming. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/521>
Diffstat (limited to 'src')
-rw-r--r--src/modules/bluetooth/backend-native.c24
-rw-r--r--src/modules/bluetooth/bluez5-util.h21
-rw-r--r--src/modules/bluetooth/module-bluez5-device.c36
3 files changed, 40 insertions, 41 deletions
diff --git a/src/modules/bluetooth/backend-native.c b/src/modules/bluetooth/backend-native.c
index dc3a01df8..126cec552 100644
--- a/src/modules/bluetooth/backend-native.c
+++ b/src/modules/bluetooth/backend-native.c
@@ -540,13 +540,13 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
* RING: Sent by AG to HS to notify of an incoming call. It can safely be ignored because
* it does not expect a reply. */
if (sscanf(buf, "AT+VGS=%d", &gain) == 1 || sscanf(buf, "\r\n+VGM=%d\r\n", &gain) == 1) {
- t->speaker_volume = hsp_gain_to_volume(gain);
- pa_hook_fire(pa_bluetooth_discovery_hook(t->device->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_SPEAKER_VOLUME_CHANGED), t);
+ t->sink_volume = hsp_gain_to_volume(gain);
+ pa_hook_fire(pa_bluetooth_discovery_hook(t->device->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_SINK_VOLUME_CHANGED), t);
do_reply = true;
} else if (sscanf(buf, "AT+VGM=%d", &gain) == 1 || sscanf(buf, "\r\n+VGS=%d\r\n", &gain) == 1) {
- t->microphone_volume = hsp_gain_to_volume(gain);
- pa_hook_fire(pa_bluetooth_discovery_hook(t->device->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_MICROPHONE_VOLUME_CHANGED), t);
+ t->source_volume = hsp_gain_to_volume(gain);
+ pa_hook_fire(pa_bluetooth_discovery_hook(t->device->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_SOURCE_VOLUME_CHANGED), t);
do_reply = true;
} else if (sscanf(buf, "AT+CKPD=%d", &dummy) == 1) {
do_reply = true;
@@ -583,17 +583,17 @@ static void transport_destroy(pa_bluetooth_transport *t) {
pa_xfree(trd);
}
-static pa_volume_t set_speaker_volume(pa_bluetooth_transport *t, pa_volume_t volume) {
+static pa_volume_t set_sink_volume(pa_bluetooth_transport *t, pa_volume_t volume) {
struct transport_data *trd = t->userdata;
uint16_t gain = volume_to_hsp_gain(volume);
/* Propagate rounding and bound checks */
volume = hsp_gain_to_volume(gain);
- if (t->speaker_volume == volume)
+ if (t->sink_volume == volume)
return volume;
- t->speaker_volume = volume;
+ t->sink_volume = volume;
/* If we are in the AG role, we send a command to the head set to change
* the speaker gain. In the HS role, source and sink are swapped, so
@@ -607,17 +607,17 @@ static pa_volume_t set_speaker_volume(pa_bluetooth_transport *t, pa_volume_t vol
return volume;
}
-static pa_volume_t set_microphone_volume(pa_bluetooth_transport *t, pa_volume_t volume) {
+static pa_volume_t set_source_volume(pa_bluetooth_transport *t, pa_volume_t volume) {
struct transport_data *trd = t->userdata;
uint16_t gain = volume_to_hsp_gain(volume);
/* Propagate rounding and bound checks */
volume = hsp_gain_to_volume(gain);
- if (t->microphone_volume == volume)
+ if (t->source_volume == volume)
return volume;
- t->microphone_volume = volume;
+ t->source_volume = volume;
/* If we are in the AG role, we send a command to the head set to change
* the microphone gain. In the HS role, source and sink are swapped, so
@@ -698,8 +698,8 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, DBusMessage *m,
t->acquire = sco_acquire_cb;
t->release = sco_release_cb;
t->destroy = transport_destroy;
- t->set_speaker_volume = set_speaker_volume;
- t->set_microphone_volume = set_microphone_volume;
+ t->set_sink_volume = set_sink_volume;
+ t->set_source_volume = set_source_volume;
trd = pa_xnew0(struct transport_data, 1);
trd->rfcomm_fd = fd;
diff --git a/src/modules/bluetooth/bluez5-util.h b/src/modules/bluetooth/bluez5-util.h
index d717aa397..f56c4d2a5 100644
--- a/src/modules/bluetooth/bluez5-util.h
+++ b/src/modules/bluetooth/bluez5-util.h
@@ -59,11 +59,11 @@ typedef struct pa_bluetooth_discovery pa_bluetooth_discovery;
typedef struct pa_bluetooth_backend pa_bluetooth_backend;
typedef enum pa_bluetooth_hook {
- PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED, /* Call data: pa_bluetooth_device */
- PA_BLUETOOTH_HOOK_DEVICE_UNLINK, /* Call data: pa_bluetooth_device */
- PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED, /* Call data: pa_bluetooth_transport */
- PA_BLUETOOTH_HOOK_TRANSPORT_MICROPHONE_VOLUME_CHANGED, /* Call data: pa_bluetooth_transport */
- PA_BLUETOOTH_HOOK_TRANSPORT_SPEAKER_VOLUME_CHANGED, /* Call data: pa_bluetooth_transport */
+ PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED, /* Call data: pa_bluetooth_device */
+ PA_BLUETOOTH_HOOK_DEVICE_UNLINK, /* Call data: pa_bluetooth_device */
+ PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED, /* Call data: pa_bluetooth_transport */
+ PA_BLUETOOTH_HOOK_TRANSPORT_SOURCE_VOLUME_CHANGED, /* Call data: pa_bluetooth_transport */
+ PA_BLUETOOTH_HOOK_TRANSPORT_SINK_VOLUME_CHANGED, /* Call data: pa_bluetooth_transport */
PA_BLUETOOTH_HOOK_MAX
} pa_bluetooth_hook_t;
@@ -87,8 +87,7 @@ typedef enum pa_bluetooth_transport_state {
typedef int (*pa_bluetooth_transport_acquire_cb)(pa_bluetooth_transport *t, bool optional, size_t *imtu, size_t *omtu);
typedef void (*pa_bluetooth_transport_release_cb)(pa_bluetooth_transport *t);
typedef void (*pa_bluetooth_transport_destroy_cb)(pa_bluetooth_transport *t);
-typedef pa_volume_t (*pa_bluetooth_transport_set_speaker_volume_cb)(pa_bluetooth_transport *t, pa_volume_t volume);
-typedef pa_volume_t (*pa_bluetooth_transport_set_microphone_volume_cb)(pa_bluetooth_transport *t, pa_volume_t volume);
+typedef pa_volume_t (*pa_bluetooth_transport_set_volume_cb)(pa_bluetooth_transport *t, pa_volume_t volume);
struct pa_bluetooth_transport {
pa_bluetooth_device *device;
@@ -103,16 +102,16 @@ struct pa_bluetooth_transport {
const pa_a2dp_codec *a2dp_codec;
- pa_volume_t microphone_volume;
- pa_volume_t speaker_volume;
+ pa_volume_t source_volume;
+ pa_volume_t sink_volume;
pa_bluetooth_transport_state_t state;
pa_bluetooth_transport_acquire_cb acquire;
pa_bluetooth_transport_release_cb release;
pa_bluetooth_transport_destroy_cb destroy;
- pa_bluetooth_transport_set_speaker_volume_cb set_speaker_volume;
- pa_bluetooth_transport_set_microphone_volume_cb set_microphone_volume;
+ pa_bluetooth_transport_set_volume_cb set_sink_volume;
+ pa_bluetooth_transport_set_volume_cb set_source_volume;
void *userdata;
};
diff --git a/src/modules/bluetooth/module-bluez5-device.c b/src/modules/bluetooth/module-bluez5-device.c
index 6813169a9..7874f6828 100644
--- a/src/modules/bluetooth/module-bluez5-device.c
+++ b/src/modules/bluetooth/module-bluez5-device.c
@@ -102,8 +102,8 @@ struct userdata {
pa_hook_slot *device_connection_changed_slot;
pa_hook_slot *transport_state_changed_slot;
- pa_hook_slot *transport_speaker_volume_changed_slot;
- pa_hook_slot *transport_microphone_volume_changed_slot;
+ pa_hook_slot *transport_sink_volume_changed_slot;
+ pa_hook_slot *transport_source_volume_changed_slot;
pa_bluetooth_discovery *discovery;
pa_bluetooth_device *device;
@@ -971,13 +971,13 @@ static void source_set_volume_cb(pa_source *s) {
pa_assert(u);
pa_assert(u->source == s);
- if (u->transport->set_microphone_volume == NULL)
+ if (u->transport->set_source_volume == NULL)
return;
/* If we are in the AG role, we send a command to the head set to change
* the microphone gain. In the HS role, source and sink are swapped, so
* in this case we notify the AG that the speaker gain has changed */
- volume = u->transport->set_microphone_volume(u->transport, pa_cvolume_max(&s->real_volume));
+ volume = u->transport->set_source_volume(u->transport, pa_cvolume_max(&s->real_volume));
pa_cvolume_set(&s->real_volume, u->decoder_sample_spec.channels, volume);
@@ -1151,13 +1151,13 @@ static void sink_set_volume_cb(pa_sink *s) {
pa_assert(u);
pa_assert(u->sink == s);
- if (u->transport->set_speaker_volume == NULL)
+ if (u->transport->set_sink_volume == NULL)
return;
/* If we are in the AG role, we send a command to the head set to change
* the speaker gain. In the HS role, source and sink are swapped, so
* in this case we notify the AG that the microphone gain has changed */
- volume = u->transport->set_speaker_volume(u->transport, pa_cvolume_max(&s->real_volume));
+ volume = u->transport->set_sink_volume(u->transport, pa_cvolume_max(&s->real_volume));
pa_cvolume_set(&s->real_volume, u->encoder_sample_spec.channels, volume);
@@ -2244,7 +2244,7 @@ static pa_hook_result_t transport_state_changed_cb(pa_bluetooth_discovery *y, pa
return PA_HOOK_OK;
}
-static pa_hook_result_t transport_speaker_volume_changed_cb(pa_bluetooth_discovery *y, pa_bluetooth_transport *t, struct userdata *u) {
+static pa_hook_result_t transport_sink_volume_changed_cb(pa_bluetooth_discovery *y, pa_bluetooth_transport *t, struct userdata *u) {
pa_volume_t volume;
pa_cvolume v;
@@ -2254,7 +2254,7 @@ static pa_hook_result_t transport_speaker_volume_changed_cb(pa_bluetooth_discove
if (t != u->transport)
return PA_HOOK_OK;
- volume = t->speaker_volume;
+ volume = t->sink_volume;
pa_cvolume_set(&v, u->encoder_sample_spec.channels, volume);
if (t->profile == PA_BLUETOOTH_PROFILE_HSP_HS || t->profile == PA_BLUETOOTH_PROFILE_HFP_HF)
@@ -2265,7 +2265,7 @@ static pa_hook_result_t transport_speaker_volume_changed_cb(pa_bluetooth_discove
return PA_HOOK_OK;
}
-static pa_hook_result_t transport_microphone_volume_changed_cb(pa_bluetooth_discovery *y, pa_bluetooth_transport *t, struct userdata *u) {
+static pa_hook_result_t transport_source_volume_changed_cb(pa_bluetooth_discovery *y, pa_bluetooth_transport *t, struct userdata *u) {
pa_volume_t volume;
pa_cvolume v;
@@ -2275,7 +2275,7 @@ static pa_hook_result_t transport_microphone_volume_changed_cb(pa_bluetooth_disc
if (t != u->transport)
return PA_HOOK_OK;
- volume = t->microphone_volume;
+ volume = t->source_volume;
pa_cvolume_set(&v, u->decoder_sample_spec.channels, volume);
@@ -2582,11 +2582,11 @@ int pa__init(pa_module* m) {
pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED),
PA_HOOK_NORMAL, (pa_hook_cb_t) transport_state_changed_cb, u);
- u->transport_speaker_volume_changed_slot =
- pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_SPEAKER_VOLUME_CHANGED), PA_HOOK_NORMAL, (pa_hook_cb_t) transport_speaker_volume_changed_cb, u);
+ u->transport_sink_volume_changed_slot =
+ pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_SINK_VOLUME_CHANGED), PA_HOOK_NORMAL, (pa_hook_cb_t) transport_sink_volume_changed_cb, u);
- u->transport_microphone_volume_changed_slot =
- pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_MICROPHONE_VOLUME_CHANGED), PA_HOOK_NORMAL, (pa_hook_cb_t) transport_microphone_volume_changed_cb, u);
+ u->transport_source_volume_changed_slot =
+ pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_SOURCE_VOLUME_CHANGED), PA_HOOK_NORMAL, (pa_hook_cb_t) transport_source_volume_changed_cb, u);
if (add_card(u) < 0)
goto fail;
@@ -2657,11 +2657,11 @@ void pa__done(pa_module *m) {
if (u->transport_state_changed_slot)
pa_hook_slot_free(u->transport_state_changed_slot);
- if (u->transport_speaker_volume_changed_slot)
- pa_hook_slot_free(u->transport_speaker_volume_changed_slot);
+ if (u->transport_sink_volume_changed_slot)
+ pa_hook_slot_free(u->transport_sink_volume_changed_slot);
- if (u->transport_microphone_volume_changed_slot)
- pa_hook_slot_free(u->transport_microphone_volume_changed_slot);
+ if (u->transport_source_volume_changed_slot)
+ pa_hook_slot_free(u->transport_source_volume_changed_slot);
if (u->encoder_buffer)
pa_xfree(u->encoder_buffer);