This should make it slightly easier to copy code between BlueZ 4 and BlueZ 5. --- src/modules/bluetooth/bluez4-util.c | 22 ++++---- src/modules/bluetooth/bluez4-util.h | 6 +-- src/modules/bluetooth/module-bluez4-device.c | 78 ++++++++++++++-------------- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/modules/bluetooth/bluez4-util.c b/src/modules/bluetooth/bluez4-util.c index a30e438..baf3aea 100644 --- a/src/modules/bluetooth/bluez4-util.c +++ b/src/modules/bluetooth/bluez4-util.c @@ -95,13 +95,13 @@ static pa_bluez4_audio_state_t audio_state_from_string(const char* value) { const char *pa_bluez4_profile_to_string(pa_bluez4_profile_t profile) { switch(profile) { - case PA_BLUEZ4_PROFILE_A2DP: + case PA_BLUEZ4_PROFILE_A2DP_SINK: return "a2dp"; case PA_BLUEZ4_PROFILE_A2DP_SOURCE: return "a2dp_source"; - case PA_BLUEZ4_PROFILE_HSP: + case PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT: return "hsp"; - case PA_BLUEZ4_PROFILE_HFGW: + case PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY: return "hfgw"; case PA_BLUEZ4_PROFILE_OFF: pa_assert_not_reached(); @@ -115,16 +115,16 @@ static int profile_from_interface(const char *interface, pa_bluez4_profile_t *p) pa_assert(p); if (pa_streq(interface, "org.bluez.AudioSink")) { - *p = PA_BLUEZ4_PROFILE_A2DP; + *p = PA_BLUEZ4_PROFILE_A2DP_SINK; return 0; } else if (pa_streq(interface, "org.bluez.AudioSource")) { *p = PA_BLUEZ4_PROFILE_A2DP_SOURCE; return 0; } else if (pa_streq(interface, "org.bluez.Headset")) { - *p = PA_BLUEZ4_PROFILE_HSP; + *p = PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT; return 0; } else if (pa_streq(interface, "org.bluez.HandsfreeGateway")) { - *p = PA_BLUEZ4_PROFILE_HFGW; + *p = PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY; return 0; } @@ -1197,7 +1197,7 @@ void pa_bluez4_transport_set_microphone_gain(pa_bluez4_transport *t, uint16_t va dbus_uint16_t gain = PA_MIN(value, HSP_MAX_GAIN); pa_assert(t); - pa_assert(t->profile == PA_BLUEZ4_PROFILE_HSP); + pa_assert(t->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT); set_property(t->device->discovery, "org.bluez", t->device->path, "org.bluez.Headset", "MicrophoneGain", DBUS_TYPE_UINT16, &gain); @@ -1207,7 +1207,7 @@ void pa_bluez4_transport_set_speaker_gain(pa_bluez4_transport *t, uint16_t value dbus_uint16_t gain = PA_MIN(value, HSP_MAX_GAIN); pa_assert(t); - pa_assert(t->profile == PA_BLUEZ4_PROFILE_HSP); + pa_assert(t->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT); set_property(t->device->discovery, "org.bluez", t->device->path, "org.bluez.Headset", "SpeakerGain", DBUS_TYPE_UINT16, &gain); @@ -1327,11 +1327,11 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, DBusMessage goto fail; if (dbus_message_has_path(m, ENDPOINT_PATH_HFP_AG)) - p = PA_BLUEZ4_PROFILE_HSP; + p = PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT; else if (dbus_message_has_path(m, ENDPOINT_PATH_HFP_HS)) - p = PA_BLUEZ4_PROFILE_HFGW; + p = PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY; else if (dbus_message_has_path(m, ENDPOINT_PATH_A2DP_SOURCE)) - p = PA_BLUEZ4_PROFILE_A2DP; + p = PA_BLUEZ4_PROFILE_A2DP_SINK; else p = PA_BLUEZ4_PROFILE_A2DP_SOURCE; diff --git a/src/modules/bluetooth/bluez4-util.h b/src/modules/bluetooth/bluez4-util.h index abbbfab..ed588f1 100644 --- a/src/modules/bluetooth/bluez4-util.h +++ b/src/modules/bluetooth/bluez4-util.h @@ -43,10 +43,10 @@ typedef struct pa_bluez4_transport pa_bluez4_transport; struct userdata; typedef enum pa_bluez4_profile { - PA_BLUEZ4_PROFILE_A2DP, + PA_BLUEZ4_PROFILE_A2DP_SINK, PA_BLUEZ4_PROFILE_A2DP_SOURCE, - PA_BLUEZ4_PROFILE_HSP, - PA_BLUEZ4_PROFILE_HFGW, + PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT, + PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY, PA_BLUEZ4_PROFILE_OFF } pa_bluez4_profile_t; diff --git a/src/modules/bluetooth/module-bluez4-device.c b/src/modules/bluetooth/module-bluez4-device.c index bae4e45..0c561d1 100644 --- a/src/modules/bluetooth/module-bluez4-device.c +++ b/src/modules/bluetooth/module-bluez4-device.c @@ -198,7 +198,7 @@ enum { #define MAX_PLAYBACK_CATCH_UP_USEC (100*PA_USEC_PER_MSEC) -#define USE_SCO_OVER_PCM(u) (u->profile == PA_BLUEZ4_PROFILE_HSP && (u->hsp.sco_sink && u->hsp.sco_source)) +#define USE_SCO_OVER_PCM(u) (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT && (u->hsp.sco_sink && u->hsp.sco_source)) static int init_profile(struct userdata *u); @@ -241,7 +241,7 @@ static void a2dp_set_bitpool(struct userdata *u, uint8_t bitpool) { /* from IO thread, except in SCO over PCM */ static void bt_transport_config_mtu(struct userdata *u) { /* Calculate block sizes */ - if (u->profile == PA_BLUEZ4_PROFILE_HSP || u->profile == PA_BLUEZ4_PROFILE_HFGW) { + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT || u->profile == PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY) { u->read_block_size = u->read_link_mtu; u->write_block_size = u->write_link_mtu; } else { @@ -260,7 +260,7 @@ static void bt_transport_config_mtu(struct userdata *u) { if (u->sink) { pa_sink_set_max_request_within_thread(u->sink, u->write_block_size); pa_sink_set_fixed_latency_within_thread(u->sink, - (u->profile == PA_BLUEZ4_PROFILE_A2DP ? + (u->profile == PA_BLUEZ4_PROFILE_A2DP_SINK ? FIXED_LATENCY_PLAYBACK_A2DP : FIXED_LATENCY_PLAYBACK_HSP) + pa_bytes_to_usec(u->write_block_size, &u->sample_spec)); } @@ -291,7 +291,7 @@ static void setup_stream(struct userdata *u) { pa_log_debug("Stream properly set up, we're ready to roll!"); - if (u->profile == PA_BLUEZ4_PROFILE_A2DP) + if (u->profile == PA_BLUEZ4_PROFILE_A2DP_SINK) a2dp_set_bitpool(u, u->a2dp.max_bitpool); u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1); @@ -550,7 +550,7 @@ static int hsp_process_render(struct userdata *u) { int ret = 0; pa_assert(u); - pa_assert(u->profile == PA_BLUEZ4_PROFILE_HSP || u->profile == PA_BLUEZ4_PROFILE_HFGW); + pa_assert(u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT || u->profile == PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY); pa_assert(u->sink); /* First, render some data */ @@ -615,7 +615,7 @@ static int hsp_process_push(struct userdata *u) { pa_memchunk memchunk; pa_assert(u); - pa_assert(u->profile == PA_BLUEZ4_PROFILE_HSP || u->profile == PA_BLUEZ4_PROFILE_HFGW); + pa_assert(u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT || u->profile == PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY); pa_assert(u->source); pa_assert(u->read_smoother); @@ -733,7 +733,7 @@ static int a2dp_process_render(struct userdata *u) { int ret = 0; pa_assert(u); - pa_assert(u->profile == PA_BLUEZ4_PROFILE_A2DP); + pa_assert(u->profile == PA_BLUEZ4_PROFILE_A2DP_SINK); pa_assert(u->sink); /* First, render some data */ @@ -1028,7 +1028,7 @@ static void thread_func(void *userdata) { if (pollfd && (pollfd->revents & POLLIN)) { int n_read; - if (u->profile == PA_BLUEZ4_PROFILE_HSP || u->profile == PA_BLUEZ4_PROFILE_HFGW) + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT || u->profile == PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY) n_read = hsp_process_push(u); else n_read = a2dp_process_push(u); @@ -1086,7 +1086,7 @@ static void thread_func(void *userdata) { pa_memblock_unref(tmp.memblock); u->write_index += skip_bytes; - if (u->profile == PA_BLUEZ4_PROFILE_A2DP) + if (u->profile == PA_BLUEZ4_PROFILE_A2DP_SINK) a2dp_reduce_bitpool(u); } } @@ -1102,7 +1102,7 @@ static void thread_func(void *userdata) { if (u->write_index <= 0) u->started_at = pa_rtclock_now(); - if (u->profile == PA_BLUEZ4_PROFILE_A2DP) { + if (u->profile == PA_BLUEZ4_PROFILE_A2DP_SINK) { if ((n_written = a2dp_process_render(u)) < 0) goto io_fail; } else { @@ -1202,10 +1202,10 @@ static pa_available_t transport_state_to_availability(pa_bluez4_transport_state_ static pa_direction_t get_profile_direction(pa_bluez4_profile_t p) { static const pa_direction_t profile_direction[] = { - [PA_BLUEZ4_PROFILE_A2DP] = PA_DIRECTION_OUTPUT, + [PA_BLUEZ4_PROFILE_A2DP_SINK] = PA_DIRECTION_OUTPUT, [PA_BLUEZ4_PROFILE_A2DP_SOURCE] = PA_DIRECTION_INPUT, - [PA_BLUEZ4_PROFILE_HSP] = PA_DIRECTION_INPUT | PA_DIRECTION_OUTPUT, - [PA_BLUEZ4_PROFILE_HFGW] = PA_DIRECTION_INPUT | PA_DIRECTION_OUTPUT, + [PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT] = PA_DIRECTION_INPUT | PA_DIRECTION_OUTPUT, + [PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY] = PA_DIRECTION_INPUT | PA_DIRECTION_OUTPUT, [PA_BLUEZ4_PROFILE_OFF] = 0 }; @@ -1327,7 +1327,7 @@ static void sink_set_volume_cb(pa_sink *s) { pa_assert(u); pa_assert(u->sink == s); - pa_assert(u->profile == PA_BLUEZ4_PROFILE_HSP); + pa_assert(u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT); pa_assert(u->transport); gain = (dbus_uint16_t) round((double) pa_cvolume_max(&s->real_volume) * HSP_MAX_GAIN / PA_VOLUME_NORM); @@ -1354,7 +1354,7 @@ static void source_set_volume_cb(pa_source *s) { pa_assert(u); pa_assert(u->source == s); - pa_assert(u->profile == PA_BLUEZ4_PROFILE_HSP); + pa_assert(u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT); pa_assert(u->transport); gain = (dbus_uint16_t) round((double) pa_cvolume_max(&s->real_volume) * HSP_MAX_GAIN / PA_VOLUME_NORM); @@ -1562,7 +1562,7 @@ static int add_sink(struct userdata *u) { data.module = u->module; pa_sink_new_data_set_sample_spec(&data, &u->sample_spec); pa_proplist_sets(data.proplist, "bluetooth.protocol", pa_bluez4_profile_to_string(u->profile)); - if (u->profile == PA_BLUEZ4_PROFILE_HSP) + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT) pa_proplist_sets(data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone"); data.card = u->card; data.name = get_name("sink", u->modargs, u->address, pa_bluez4_profile_to_string(u->profile), &b); @@ -1577,11 +1577,11 @@ static int add_sink(struct userdata *u) { if (!u->transport_acquired) switch (u->profile) { - case PA_BLUEZ4_PROFILE_A2DP: - case PA_BLUEZ4_PROFILE_HSP: + case PA_BLUEZ4_PROFILE_A2DP_SINK: + case PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT: pa_assert_not_reached(); /* Profile switch should have failed */ break; - case PA_BLUEZ4_PROFILE_HFGW: + case PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY: data.suspend_cause = PA_SUSPEND_USER; break; case PA_BLUEZ4_PROFILE_A2DP_SOURCE: @@ -1602,7 +1602,7 @@ static int add_sink(struct userdata *u) { u->sink->set_port = sink_set_port_cb; } - if (u->profile == PA_BLUEZ4_PROFILE_HSP) { + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT) { pa_sink_set_set_volume_callback(u->sink, sink_set_volume_cb); u->sink->n_volume_steps = 16; @@ -1632,7 +1632,7 @@ static int add_source(struct userdata *u) { data.module = u->module; pa_source_new_data_set_sample_spec(&data, &u->sample_spec); pa_proplist_sets(data.proplist, "bluetooth.protocol", pa_bluez4_profile_to_string(u->profile)); - if (u->profile == PA_BLUEZ4_PROFILE_HSP) + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT) pa_proplist_sets(data.proplist, PA_PROP_DEVICE_INTENDED_ROLES, "phone"); data.card = u->card; @@ -1649,14 +1649,14 @@ static int add_source(struct userdata *u) { if (!u->transport_acquired) switch (u->profile) { - case PA_BLUEZ4_PROFILE_HSP: + case PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT: pa_assert_not_reached(); /* Profile switch should have failed */ break; case PA_BLUEZ4_PROFILE_A2DP_SOURCE: - case PA_BLUEZ4_PROFILE_HFGW: + case PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY: data.suspend_cause = PA_SUSPEND_USER; break; - case PA_BLUEZ4_PROFILE_A2DP: + case PA_BLUEZ4_PROFILE_A2DP_SINK: case PA_BLUEZ4_PROFILE_OFF: pa_assert_not_reached(); } @@ -1674,12 +1674,12 @@ static int add_source(struct userdata *u) { u->source->set_port = source_set_port_cb; } - if ((u->profile == PA_BLUEZ4_PROFILE_HSP) || (u->profile == PA_BLUEZ4_PROFILE_HFGW)) { + if ((u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT) || (u->profile == PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY)) { pa_bluez4_transport *t = u->transport; pa_proplist_sets(u->source->proplist, "bluetooth.nrec", t->nrec ? "1" : "0"); } - if (u->profile == PA_BLUEZ4_PROFILE_HSP) { + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT) { pa_source_set_set_volume_callback(u->source, source_set_volume_cb); u->source->n_volume_steps = 16; @@ -1794,7 +1794,7 @@ static void bt_transport_config_a2dp(struct userdata *u) { a2dp->max_bitpool = config->max_bitpool; /* Set minimum bitpool for source to get the maximum possible block_size */ - a2dp->sbc.bitpool = u->profile == PA_BLUEZ4_PROFILE_A2DP ? a2dp->max_bitpool : a2dp->min_bitpool; + a2dp->sbc.bitpool = u->profile == PA_BLUEZ4_PROFILE_A2DP_SINK ? a2dp->max_bitpool : a2dp->min_bitpool; a2dp->codesize = sbc_get_codesize(&a2dp->sbc); a2dp->frame_length = sbc_get_frame_length(&a2dp->sbc); @@ -1803,7 +1803,7 @@ static void bt_transport_config_a2dp(struct userdata *u) { } static void bt_transport_config(struct userdata *u) { - if (u->profile == PA_BLUEZ4_PROFILE_HSP || u->profile == PA_BLUEZ4_PROFILE_HFGW) { + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT || u->profile == PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY) { u->sample_spec.format = PA_SAMPLE_S16LE; u->sample_spec.channels = 1; u->sample_spec.rate = 8000; @@ -1842,7 +1842,7 @@ static int setup_transport(struct userdata *u) { u->transport = t; - if (u->profile == PA_BLUEZ4_PROFILE_A2DP_SOURCE || u->profile == PA_BLUEZ4_PROFILE_HFGW) + if (u->profile == PA_BLUEZ4_PROFILE_A2DP_SOURCE || u->profile == PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY) bt_transport_acquire(u, true); /* In case of error, the sink/sources will be created suspended */ else if (bt_transport_acquire(u, false) < 0) return -1; /* We need to fail here until the interactions with module-suspend-on-idle and alike get improved */ @@ -1863,15 +1863,15 @@ static int init_profile(struct userdata *u) { pa_assert(u->transport); - if (u->profile == PA_BLUEZ4_PROFILE_A2DP || - u->profile == PA_BLUEZ4_PROFILE_HSP || - u->profile == PA_BLUEZ4_PROFILE_HFGW) + if (u->profile == PA_BLUEZ4_PROFILE_A2DP_SINK || + u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT || + u->profile == PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY) if (add_sink(u) < 0) r = -1; - if (u->profile == PA_BLUEZ4_PROFILE_HSP || + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT || u->profile == PA_BLUEZ4_PROFILE_A2DP_SOURCE || - u->profile == PA_BLUEZ4_PROFILE_HFGW) + u->profile == PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY) if (add_source(u) < 0) r = -1; @@ -1914,7 +1914,7 @@ static void stop_thread(struct userdata *u) { } if (u->sink) { - if (u->profile == PA_BLUEZ4_PROFILE_HSP) { + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT) { k = pa_sprintf_malloc("bluetooth-device@%p", (void*) u->sink); pa_shared_remove(u->core, k); pa_xfree(k); @@ -1925,7 +1925,7 @@ static void stop_thread(struct userdata *u) { } if (u->source) { - if (u->profile == PA_BLUEZ4_PROFILE_HSP) { + if (u->profile == PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT) { k = pa_sprintf_malloc("bluetooth-device@%p", (void*) u->source); pa_shared_remove(u->core, k); pa_xfree(k); @@ -2182,7 +2182,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid pa_hashmap_put(output_port->profiles, p->name, p); d = PA_CARD_PROFILE_DATA(p); - *d = PA_BLUEZ4_PROFILE_A2DP; + *d = PA_BLUEZ4_PROFILE_A2DP_SINK; } else if (pa_streq(uuid, PA_BLUEZ4_UUID_A2DP_SOURCE)) { p = pa_card_profile_new("a2dp_source", _("High Fidelity Capture (A2DP)"), sizeof(pa_bluez4_profile_t)); p->priority = 10; @@ -2205,7 +2205,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid pa_hashmap_put(output_port->profiles, p->name, p); d = PA_CARD_PROFILE_DATA(p); - *d = PA_BLUEZ4_PROFILE_HSP; + *d = PA_BLUEZ4_PROFILE_HEADSET_HEAD_UNIT; } else if (pa_streq(uuid, PA_BLUEZ4_UUID_HFP_AG)) { p = pa_card_profile_new("hfgw", _("Handsfree Gateway"), sizeof(pa_bluez4_profile_t)); p->priority = 20; @@ -2217,7 +2217,7 @@ static pa_card_profile *create_card_profile(struct userdata *u, const char *uuid pa_hashmap_put(output_port->profiles, p->name, p); d = PA_CARD_PROFILE_DATA(p); - *d = PA_BLUEZ4_PROFILE_HFGW; + *d = PA_BLUEZ4_PROFILE_HEADSET_AUDIO_GATEWAY; } if (p) { -- 2.8.1