[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] 5 commits: backend-native: Fix indentation and whitespace style
PulseAudio Marge Bot (@pulseaudio-merge-bot)
gitlab at gitlab.freedesktop.org
Tue Aug 16 05:23:15 UTC 2022
PulseAudio Marge Bot pushed to branch master at PulseAudio / pulseaudio
Commits:
c6bd6656 by Marijn Suijten at 2022-08-16T08:13:46+03:00
backend-native: Fix indentation and whitespace style
Replace tabs with spaces, remove trailing whitespace, remove bracing
around single-line `if` blocks.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/740>
- - - - -
391dac58 by Marijn Suijten at 2022-08-16T08:16:15+03:00
backend-native: Add backend pointer to transport_data
This removes the inverse/recursive dependency of backend-native on the
`pa_bluetooth_discovery` struct, which is supposed to be opaque outside
of `bluez5-util` in favour of the many accessor functions defined in
`bluez5-util.h`.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/740>
- - - - -
6ec084e2 by Marijn Suijten at 2022-08-16T08:16:24+03:00
Revert "bluez5-util: move pa_bluetooth_discovery to header"
This reverts commit b05e34e092d5f40ff9a305fea181bd2308829824.
Now that backend-native uses a different way to get to its own
`native_backend` instance - without going through
`pa_bluetooth_discovery` - this patch can be reverted again, as nothing
outside bluez5-util is supposed to know the internals of this struct.
That's what the many functions are for which all take pointers to this
(at that point) opaque struct instead.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/740>
- - - - -
518ca030 by Marijn Suijten at 2022-08-16T08:16:24+03:00
backend-native: Update all CIND indicators
When `indicator` is initialized to `1`:
- it always succeeds the `indicator == CIND_CALL_INDICATOR` check;
- hence always calls `continue`;
- hence never reaches the end of the `while` loop where `indicator++` is
called;
- hence `indicator` never contains any other value than `1` meaning
`cind_enabled_indicators` is ever updated.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/740>
- - - - -
8188b49b by Marijn Suijten at 2022-08-16T08:16:24+03:00
backend-native: Remove uninformative "Profile unavailable" debug message
This message would print for all transports while not even conveying
the profile of the transport, and might be printed for non-`HFP_HF`
profiles which is the only transport-profile we're interested in.
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/740>
- - - - -
4 changed files:
- src/modules/bluetooth/backend-native.c
- src/modules/bluetooth/bluez5-util.c
- src/modules/bluetooth/bluez5-util.h
- src/modules/meson.build
Changes:
=====================================
src/modules/bluetooth/backend-native.c
=====================================
@@ -67,6 +67,7 @@ struct transport_data {
int sco_fd;
pa_io_event *sco_io;
pa_mainloop_api *mainloop;
+ pa_bluetooth_backend *backend;
};
struct hfp_config {
@@ -612,8 +613,9 @@ static pa_volume_t set_source_volume(pa_bluetooth_transport *t, pa_volume_t volu
static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf)
{
- struct pa_bluetooth_discovery *discovery = t->device->discovery;
struct hfp_config *c = t->config;
+ struct transport_data *trd = t->userdata;
+ pa_bluetooth_backend *b = trd->backend;
int indicator, mode, val;
char str[5];
const char *r;
@@ -635,13 +637,12 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
return true;
} else if (sscanf(buf, "AT+BIA=%s", str) == 1) {
/* Indicators start with index 1 and follow the order of the AT+CIND=? response */
- indicator = 1;
- while ((r = pa_split_in_place(str, ",", &len, &state))) {
- /* Ignore updates to mandantory indicators which are always ON */
- if (indicator == CIND_CALL_INDICATOR
+ for (indicator = 1; (r = pa_split_in_place(str, ",", &len, &state)); indicator++) {
+ /* Ignore updates to mandatory indicators which are always ON */
+ if (indicator == CIND_CALL_INDICATOR
|| indicator == CIND_CALL_SETUP_INDICATOR
- || indicator == CIND_CALL_HELD_INDICATOR)
+ || indicator == CIND_CALL_HELD_INDICATOR)
continue;
/* Indicators may have no value and should be skipped */
@@ -649,19 +650,17 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
continue;
if (len == 1 && r[0] == '1')
- discovery->native_backend->cind_enabled_indicators |= (1 << indicator);
+ b->cind_enabled_indicators |= (1 << indicator);
else if (len == 1 && r[0] == '0')
- discovery->native_backend->cind_enabled_indicators &= ~(1 << indicator);
- else {
+ b->cind_enabled_indicators &= ~(1 << indicator);
+ else {
pa_log_error("Unable to parse indicator of AT+BIA command: %s", buf);
rfcomm_write_response(fd, "ERROR");
- return false;
+ return false;
}
-
- indicator++;
}
- return true;
+ return true;
} else if (sscanf(buf, "AT+BAC=%3s", str) == 1) {
c->support_msbc = false;
@@ -686,38 +685,37 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
return true;
} else if (c->state == 1 && pa_startswith(buf, "AT+CIND=?")) {
/* UPower backend available, declare support for more indicators */
- if (discovery->native_backend->upower) {
+ if (b->upower) {
rfcomm_write_response(fd, "+CIND: "
- MANDATORY_CALL_INDICATORS ","
- "(\"service\",(0-1)),"
- "(\"battchg\",(0-5))");
+ MANDATORY_CALL_INDICATORS ","
+ "(\"service\",(0-1)),"
+ "(\"battchg\",(0-5))");
/* Minimal indicators supported without any additional backend */
} else {
rfcomm_write_response(fd, "+CIND: "
- MANDATORY_CALL_INDICATORS ","
- "(\"service\",(0-1))");
+ MANDATORY_CALL_INDICATORS ","
+ "(\"service\",(0-1))");
}
c->state = 2;
return true;
} else if (c->state == 2 && pa_startswith(buf, "AT+CIND?")) {
- if (discovery->native_backend->upower)
- rfcomm_write_response(fd, "+CIND: 0,0,0,0,%u", pa_upower_get_battery_level(discovery->native_backend->upower));
+ if (b->upower)
+ rfcomm_write_response(fd, "+CIND: 0,0,0,0,%u", pa_upower_get_battery_level(b->upower));
else
rfcomm_write_response(fd, "+CIND: 0,0,0,0");
c->state = 3;
return true;
} else if ((c->state == 2 || c->state == 3) && pa_startswith(buf, "AT+CMER=")) {
- if (sscanf(buf, "AT+CMER=%d,%*d,%*d,%d", &mode, &val) == 2) {
+ if (sscanf(buf, "AT+CMER=%d,%*d,%*d,%d", &mode, &val) == 2) {
/* Bluetooth HFP spec only defines mode == 3 */
- if (mode != 3) {
+ if (mode != 3)
pa_log_warn("Unexpected mode for AT+CMER: %d", mode);
- }
- /* Configure CMER event reporting */
- discovery->native_backend->cmer_indicator_reporting_enabled = !!val;
+ /* Configure CMER event reporting */
+ b->cmer_indicator_reporting_enabled = !!val;
pa_log_debug("Event indications enabled? %s", pa_yes_no(val));
@@ -726,7 +724,7 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
else {
pa_log_error("Unable to parse AT+CMER command: %s", buf);
rfcomm_write_response(fd, "ERROR");
- return false;
+ return false;
}
if (c->support_codec_negotiation) {
@@ -815,16 +813,15 @@ static bool hfp_rfcomm_handle(int fd, pa_bluetooth_transport *t, const char *buf
return true;
}
-static int get_rfcomm_fd (pa_bluetooth_discovery *discovery) {
+static int get_rfcomm_fd(pa_bluetooth_discovery *discovery) {
struct pa_bluetooth_transport *t;
struct transport_data *trd = NULL;
void *state = NULL;
/* Find RFCOMM transport by checking if a HSP or HFP profile transport is available */
- while ((t = pa_hashmap_iterate(discovery->transports, &state, NULL))) {
+ while ((t = pa_hashmap_iterate(pa_bluetooth_discovery_get_transports(discovery), &state, NULL))) {
/* Skip non-connected transports */
if (!t || t->state == PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED) {
- pa_log_debug("Profile disconnected or unavailable");
continue;
}
@@ -852,14 +849,14 @@ static pa_hook_result_t host_battery_level_changed_cb(pa_bluetooth_discovery *y,
pa_assert(b);
/* Get RFCOMM channel if available */
- rfcomm_fd = get_rfcomm_fd (y);
+ rfcomm_fd = get_rfcomm_fd(y);
if (rfcomm_fd < 0)
return PA_HOOK_OK;
/* Notify HF about AG battery level change over RFCOMM */
if (b->cmer_indicator_reporting_enabled && (b->cind_enabled_indicators & (1 << CIND_BATT_CHG_INDICATOR))) {
- rfcomm_write_response(rfcomm_fd, "+CIEV: %d,%d", CIND_BATT_CHG_INDICATOR, u->battery_level);
- pa_log_debug("HG notified of AG's battery level change");
+ rfcomm_write_response(rfcomm_fd, "+CIEV: %d,%d", CIND_BATT_CHG_INDICATOR, u->battery_level);
+ pa_log_debug("HG notified of AG's battery level change");
/* Skip notification if indicator is disabled or event reporting is completely disabled */
} else
pa_log_debug("Battery level change indicator disabled, skipping notification");
@@ -869,7 +866,8 @@ static pa_hook_result_t host_battery_level_changed_cb(pa_bluetooth_discovery *y,
static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_io_event_flags_t events, void *userdata) {
pa_bluetooth_transport *t = userdata;
- pa_bluetooth_discovery *discovery = t->device->discovery;
+ struct transport_data *trd = t->userdata;
+ pa_bluetooth_backend *b = trd->backend;
int i;
pa_assert(io);
@@ -992,9 +990,9 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
fail:
/* Service Connection lost, reset indicators and event reporting to default values */
- discovery->native_backend->cmer_indicator_reporting_enabled = false;
+ b->cmer_indicator_reporting_enabled = false;
for (i = 1; i < CIND_INDICATOR_MAX; i++)
- discovery->native_backend->cind_enabled_indicators |= (1 << i);
+ b->cind_enabled_indicators |= (1 << i);
pa_bluetooth_transport_unlink(t);
pa_bluetooth_transport_free(t);
@@ -1158,6 +1156,7 @@ static DBusMessage *profile_new_connection(DBusConnection *conn, DBusMessage *m,
trd = pa_xnew0(struct transport_data, 1);
trd->rfcomm_fd = fd;
trd->mainloop = b->core->mainloop;
+ trd->backend = b;
trd->rfcomm_io = trd->mainloop->io_new(b->core->mainloop, fd, PA_IO_EVENT_INPUT,
rfcomm_io_callback, t);
t->userdata = trd;
=====================================
src/modules/bluetooth/bluez5-util.c
=====================================
@@ -31,6 +31,7 @@
#include <pulsecore/core.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
+#include <pulsecore/dbus-shared.h>
#include <pulsecore/log.h>
#include <pulsecore/macro.h>
#include <pulsecore/refcnt.h>
@@ -127,6 +128,28 @@ static uint16_t volume_to_a2dp_gain(pa_volume_t volume) {
return gain;
}
+struct pa_bluetooth_discovery {
+ PA_REFCNT_DECLARE;
+
+ pa_core *core;
+ pa_dbus_connection *connection;
+ bool filter_added;
+ bool matches_added;
+ bool objects_listed;
+ pa_hook hooks[PA_BLUETOOTH_HOOK_MAX];
+ pa_hashmap *adapters;
+ pa_hashmap *devices;
+ pa_hashmap *transports;
+ pa_bluetooth_profile_status_t profiles_status[PA_BLUETOOTH_PROFILE_COUNT];
+
+ int headset_backend;
+ pa_bluetooth_backend *ofono_backend, *native_backend;
+ PA_LLIST_HEAD(pa_dbus_pending, pending);
+ bool enable_native_hsp_hs;
+ bool enable_native_hfp_hf;
+ bool enable_msbc;
+};
+
static pa_dbus_pending* send_and_add_to_pending(pa_bluetooth_discovery *y, DBusMessage *m,
DBusPendingCallNotifyFunction func, void *call_data) {
pa_dbus_pending *p;
@@ -1179,6 +1202,13 @@ bool pa_bluetooth_discovery_get_enable_msbc(pa_bluetooth_discovery *y)
return y->enable_msbc;
}
+pa_hashmap* pa_bluetooth_discovery_get_transports(pa_bluetooth_discovery *y) {
+ pa_assert(y);
+ pa_assert(PA_REFCNT_VALUE(y) > 0);
+
+ return y->transports;
+}
+
pa_bluetooth_device* pa_bluetooth_discovery_get_device_by_address(pa_bluetooth_discovery *y, const char *remote, const char *local) {
pa_bluetooth_device *d;
void *state = NULL;
=====================================
src/modules/bluetooth/bluez5-util.h
=====================================
@@ -22,7 +22,6 @@
***/
#include <pulsecore/core.h>
-#include <pulsecore/dbus-shared.h>
#include "a2dp-codec-util.h"
@@ -137,29 +136,6 @@ struct pa_bluetooth_transport {
void *userdata;
};
-struct pa_bluetooth_discovery {
- PA_REFCNT_DECLARE;
-
- pa_core *core;
- pa_dbus_connection *connection;
- bool filter_added;
- bool matches_added;
- bool objects_listed;
- pa_hook hooks[PA_BLUETOOTH_HOOK_MAX];
- pa_hashmap *adapters;
- pa_hashmap *devices;
- pa_hashmap *transports;
- pa_bluetooth_profile_status_t profiles_status[PA_BLUETOOTH_PROFILE_COUNT];
-
- int headset_backend;
- pa_bluetooth_backend *ofono_backend, *native_backend;
- PA_LLIST_HEAD(pa_dbus_pending, pending);
- bool enable_native_hsp_hs;
- bool enable_native_hfp_hf;
- bool enable_msbc;
-};
-
-
struct pa_bluetooth_device {
pa_bluetooth_discovery *discovery;
pa_bluetooth_adapter *adapter;
@@ -271,4 +247,5 @@ void pa_bluetooth_discovery_set_ofono_running(pa_bluetooth_discovery *y, bool is
bool pa_bluetooth_discovery_get_enable_native_hsp_hs(pa_bluetooth_discovery *y);
bool pa_bluetooth_discovery_get_enable_native_hfp_hf(pa_bluetooth_discovery *y);
bool pa_bluetooth_discovery_get_enable_msbc(pa_bluetooth_discovery *y);
+pa_hashmap* pa_bluetooth_discovery_get_transports(pa_bluetooth_discovery *y);
#endif
=====================================
src/modules/meson.build
=====================================
@@ -123,7 +123,7 @@ if cdata.has('HAVE_BLUEZ_5')
all_modules += [
[ 'module-bluetooth-discover', 'bluetooth/module-bluetooth-discover.c' ],
[ 'module-bluetooth-policy', 'bluetooth/module-bluetooth-policy.c', [], [], [dbus_dep] ],
- [ 'module-bluez5-device', 'bluetooth/module-bluez5-device.c', [], [], [dbus_dep], libbluez5_util ],
+ [ 'module-bluez5-device', 'bluetooth/module-bluez5-device.c', [], [], [], libbluez5_util ],
[ 'module-bluez5-discover', 'bluetooth/module-bluez5-discover.c', [], [], [dbus_dep], libbluez5_util ],
]
endif
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/de8b0c11242a49c335abdae292d0bb9f6d71d2dd...8188b49bed7be08e23abcf92b098f62c1fc5c2ec
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/de8b0c11242a49c335abdae292d0bb9f6d71d2dd...8188b49bed7be08e23abcf92b098f62c1fc5c2ec
You're receiving this email because of your account on gitlab.freedesktop.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20220816/d28312ef/attachment-0001.htm>
More information about the pulseaudio-commits
mailing list