mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
spa: bluez: backend-native: use sscanf() for parsing AT commands
This commit is contained in:
parent
c24594a8ac
commit
2fb63f71c3
1 changed files with 5 additions and 25 deletions
|
|
@ -913,27 +913,18 @@ static bool rfcomm_hfp_ag(struct rfcomm *rfcomm, char* buf)
|
||||||
|
|
||||||
static bool rfcomm_hfp_hf(struct rfcomm *rfcomm, char* buf)
|
static bool rfcomm_hfp_hf(struct rfcomm *rfcomm, char* buf)
|
||||||
{
|
{
|
||||||
static const char separators[] = "\r\n:";
|
|
||||||
|
|
||||||
struct impl *backend = rfcomm->backend;
|
struct impl *backend = rfcomm->backend;
|
||||||
unsigned int features;
|
unsigned int features;
|
||||||
unsigned int gain;
|
unsigned int gain;
|
||||||
unsigned int selected_codec;
|
unsigned int selected_codec;
|
||||||
char* token;
|
char* token;
|
||||||
|
|
||||||
while ((token = strsep(&buf, separators))) {
|
while ((token = strsep(&buf, "\r\n"))) {
|
||||||
if (spa_strstartswith(token, "+BRSF")) {
|
if (sscanf(token, "+BRSF:%u", &features) == 1) {
|
||||||
/* get next token */
|
|
||||||
token = strsep(&buf, separators);
|
|
||||||
features = atoi(token);
|
|
||||||
if (((features & (SPA_BT_HFP_AG_FEATURE_CODEC_NEGOTIATION)) != 0) &&
|
if (((features & (SPA_BT_HFP_AG_FEATURE_CODEC_NEGOTIATION)) != 0) &&
|
||||||
rfcomm->msbc_supported_by_hfp)
|
rfcomm->msbc_supported_by_hfp)
|
||||||
rfcomm->codec_negotiation_supported = true;
|
rfcomm->codec_negotiation_supported = true;
|
||||||
} else if (spa_strstartswith(token, "+BCS") && rfcomm->codec_negotiation_supported) {
|
} else if (sscanf(token, "+BCS:%u", &selected_codec) == 1 && rfcomm->codec_negotiation_supported) {
|
||||||
/* get next token */
|
|
||||||
token = strsep(&buf, separators);
|
|
||||||
selected_codec = atoi(token);
|
|
||||||
|
|
||||||
if (selected_codec != HFP_AUDIO_CODEC_CVSD && selected_codec != HFP_AUDIO_CODEC_MSBC) {
|
if (selected_codec != HFP_AUDIO_CODEC_CVSD && selected_codec != HFP_AUDIO_CODEC_MSBC) {
|
||||||
spa_log_warn(backend->log, "unsupported codec negotiation: %d", selected_codec);
|
spa_log_warn(backend->log, "unsupported codec negotiation: %d", selected_codec);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -958,24 +949,13 @@ static bool rfcomm_hfp_hf(struct rfcomm *rfcomm, char* buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (spa_strstartswith(token, "+CIND")) {
|
} else if (sscanf(token, "+VGM:%u", &gain) == 1) {
|
||||||
/* get next token and discard it */
|
|
||||||
token = strsep(&buf, separators);
|
|
||||||
} else if (spa_strstartswith(token, "+VGM")) {
|
|
||||||
/* get next token */
|
|
||||||
token = strsep(&buf, separators);
|
|
||||||
gain = atoi(token);
|
|
||||||
|
|
||||||
if (gain <= SPA_BT_VOLUME_HS_MAX) {
|
if (gain <= SPA_BT_VOLUME_HS_MAX) {
|
||||||
rfcomm_emit_volume_changed(rfcomm, SPA_BT_VOLUME_ID_TX, gain);
|
rfcomm_emit_volume_changed(rfcomm, SPA_BT_VOLUME_ID_TX, gain);
|
||||||
} else {
|
} else {
|
||||||
spa_log_debug(backend->log, "RFCOMM receive unsupported VGM gain: %s", token);
|
spa_log_debug(backend->log, "RFCOMM receive unsupported VGM gain: %s", token);
|
||||||
}
|
}
|
||||||
} else if (spa_strstartswith(token, "+VGS")) {
|
} else if (sscanf(token, "+VGS:%u", &gain) == 1) {
|
||||||
/* get next token */
|
|
||||||
token = strsep(&buf, separators);
|
|
||||||
gain = atoi(token);
|
|
||||||
|
|
||||||
if (gain <= SPA_BT_VOLUME_HS_MAX) {
|
if (gain <= SPA_BT_VOLUME_HS_MAX) {
|
||||||
rfcomm_emit_volume_changed(rfcomm, SPA_BT_VOLUME_ID_RX, gain);
|
rfcomm_emit_volume_changed(rfcomm, SPA_BT_VOLUME_ID_RX, gain);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue