Bluetooth: Audio: Remove bt_vcp from vol rend API
Remove the struct bt_vcp pointer from the volume renderer API, as there is only ever a single Volume Renderer instance on a device. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
c82af2885e
commit
ae11b5879b
5 changed files with 76 additions and 161 deletions
|
@ -173,8 +173,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
|
|||
&vcp_inst.srv.state, sizeof(vcp_inst.srv.state));
|
||||
|
||||
if (vcp_inst.srv.cb && vcp_inst.srv.cb->state) {
|
||||
vcp_inst.srv.cb->state(&vcp_inst, 0,
|
||||
vcp_inst.srv.state.volume,
|
||||
vcp_inst.srv.cb->state(0, vcp_inst.srv.state.volume,
|
||||
vcp_inst.srv.state.mute);
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +186,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
|
|||
&vcp_inst.srv.flags, sizeof(vcp_inst.srv.flags));
|
||||
|
||||
if (vcp_inst.srv.cb && vcp_inst.srv.cb->flags) {
|
||||
vcp_inst.srv.cb->flags(&vcp_inst, 0, vcp_inst.srv.flags);
|
||||
vcp_inst.srv.cb->flags(0, vcp_inst.srv.flags);
|
||||
}
|
||||
}
|
||||
return len;
|
||||
|
@ -320,8 +319,7 @@ static int prepare_aics_inst(struct bt_vcp_vol_rend_register_param *param)
|
|||
}
|
||||
|
||||
/****************************** PUBLIC API ******************************/
|
||||
int bt_vcp_vol_rend_register(struct bt_vcp_vol_rend_register_param *param,
|
||||
struct bt_vcp **vcp)
|
||||
int bt_vcp_vol_rend_register(struct bt_vcp_vol_rend_register_param *param)
|
||||
{
|
||||
static bool registered;
|
||||
int err;
|
||||
|
@ -342,7 +340,6 @@ int bt_vcp_vol_rend_register(struct bt_vcp_vol_rend_register_param *param,
|
|||
}
|
||||
|
||||
if (registered) {
|
||||
*vcp = &vcp_inst;
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
|
@ -377,28 +374,22 @@ int bt_vcp_vol_rend_register(struct bt_vcp_vol_rend_register_param *param,
|
|||
|
||||
vcp_inst.srv.cb = param->cb;
|
||||
|
||||
*vcp = &vcp_inst;
|
||||
registered = true;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_included_get(struct bt_vcp *vcp, struct bt_vcp_included *included)
|
||||
int bt_vcp_vol_rend_included_get(struct bt_vcp_included *included)
|
||||
{
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (included == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
included->vocs_cnt = ARRAY_SIZE(vcp->srv.vocs_insts);
|
||||
included->vocs = vcp->srv.vocs_insts;
|
||||
included->vocs_cnt = ARRAY_SIZE(vcp_inst.srv.vocs_insts);
|
||||
included->vocs = vcp_inst.srv.vocs_insts;
|
||||
|
||||
included->aics_cnt = ARRAY_SIZE(vcp->srv.aics_insts);
|
||||
included->aics = vcp->srv.aics_insts;
|
||||
included->aics_cnt = ARRAY_SIZE(vcp_inst.srv.aics_insts);
|
||||
included->aics = vcp_inst.srv.aics_insts;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -413,160 +404,114 @@ int bt_vcp_vol_rend_set_step(uint8_t volume_step)
|
|||
}
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_get_state(struct bt_vcp *vcp)
|
||||
int bt_vcp_vol_rend_get_state(void)
|
||||
{
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (vcp->srv.cb && vcp->srv.cb->state) {
|
||||
vcp->srv.cb->state(vcp, 0, vcp->srv.state.volume,
|
||||
vcp->srv.state.mute);
|
||||
if (vcp_inst.srv.cb && vcp_inst.srv.cb->state) {
|
||||
vcp_inst.srv.cb->state(0, vcp_inst.srv.state.volume,
|
||||
vcp_inst.srv.state.mute);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_get_flags(struct bt_vcp *vcp)
|
||||
int bt_vcp_vol_rend_get_flags(void)
|
||||
{
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (vcp->srv.cb && vcp->srv.cb->flags) {
|
||||
vcp->srv.cb->flags(vcp, 0, vcp->srv.flags);
|
||||
if (vcp_inst.srv.cb && vcp_inst.srv.cb->flags) {
|
||||
vcp_inst.srv.cb->flags(0, vcp_inst.srv.flags);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_vol_down(struct bt_vcp *vcp)
|
||||
int bt_vcp_vol_rend_vol_down(void)
|
||||
{
|
||||
const struct vcs_control cp = {
|
||||
.opcode = BT_VCP_OPCODE_REL_VOL_DOWN,
|
||||
.counter = vcp->srv.state.change_counter,
|
||||
.counter = vcp_inst.srv.state.change_counter,
|
||||
};
|
||||
int err;
|
||||
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
|
||||
|
||||
return err > 0 ? 0 : err;
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_vol_up(struct bt_vcp *vcp)
|
||||
int bt_vcp_vol_rend_vol_up(void)
|
||||
{
|
||||
const struct vcs_control cp = {
|
||||
.opcode = BT_VCP_OPCODE_REL_VOL_UP,
|
||||
.counter = vcp->srv.state.change_counter,
|
||||
.counter = vcp_inst.srv.state.change_counter,
|
||||
};
|
||||
int err;
|
||||
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
|
||||
|
||||
return err > 0 ? 0 : err;
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_unmute_vol_down(struct bt_vcp *vcp)
|
||||
int bt_vcp_vol_rend_unmute_vol_down(void)
|
||||
{
|
||||
const struct vcs_control cp = {
|
||||
.opcode = BT_VCP_OPCODE_UNMUTE_REL_VOL_DOWN,
|
||||
.counter = vcp->srv.state.change_counter,
|
||||
.counter = vcp_inst.srv.state.change_counter,
|
||||
};
|
||||
int err;
|
||||
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
|
||||
|
||||
return err > 0 ? 0 : err;
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_unmute_vol_up(struct bt_vcp *vcp)
|
||||
int bt_vcp_vol_rend_unmute_vol_up(void)
|
||||
{
|
||||
const struct vcs_control cp = {
|
||||
.opcode = BT_VCP_OPCODE_UNMUTE_REL_VOL_UP,
|
||||
.counter = vcp->srv.state.change_counter,
|
||||
.counter = vcp_inst.srv.state.change_counter,
|
||||
};
|
||||
int err;
|
||||
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
|
||||
|
||||
return err > 0 ? 0 : err;
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_set_vol(struct bt_vcp *vcp, uint8_t volume)
|
||||
int bt_vcp_vol_rend_set_vol(uint8_t volume)
|
||||
{
|
||||
|
||||
const struct vcs_control_vol cp = {
|
||||
.cp = {
|
||||
.opcode = BT_VCP_OPCODE_SET_ABS_VOL,
|
||||
.counter = vcp->srv.state.change_counter
|
||||
.counter = vcp_inst.srv.state.change_counter
|
||||
},
|
||||
.volume = volume
|
||||
};
|
||||
int err;
|
||||
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
|
||||
|
||||
return err > 0 ? 0 : err;
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_unmute(struct bt_vcp *vcp)
|
||||
int bt_vcp_vol_rend_unmute(void)
|
||||
{
|
||||
const struct vcs_control cp = {
|
||||
.opcode = BT_VCP_OPCODE_UNMUTE,
|
||||
.counter = vcp->srv.state.change_counter,
|
||||
.counter = vcp_inst.srv.state.change_counter,
|
||||
};
|
||||
int err;
|
||||
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
|
||||
|
||||
return err > 0 ? 0 : err;
|
||||
}
|
||||
|
||||
int bt_vcp_vol_rend_mute(struct bt_vcp *vcp)
|
||||
int bt_vcp_vol_rend_mute(void)
|
||||
{
|
||||
const struct vcs_control cp = {
|
||||
.opcode = BT_VCP_OPCODE_MUTE,
|
||||
.counter = vcp->srv.state.change_counter,
|
||||
.counter = vcp_inst.srv.state.change_counter,
|
||||
};
|
||||
int err;
|
||||
|
||||
CHECKIF(vcp == NULL) {
|
||||
LOG_DBG("NULL vcp instance");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
|
||||
|
||||
return err > 0 ? 0 : err;
|
||||
|
|
|
@ -17,11 +17,9 @@
|
|||
|
||||
#include "bt.h"
|
||||
|
||||
static struct bt_vcp *vcp;
|
||||
static struct bt_vcp_included vcp_included;
|
||||
|
||||
static void vcp_vol_rend_state_cb(struct bt_vcp *vcp, int err, uint8_t volume,
|
||||
uint8_t mute)
|
||||
static void vcp_vol_rend_state_cb(int err, uint8_t volume, uint8_t mute)
|
||||
{
|
||||
if (err) {
|
||||
shell_error(ctx_shell, "VCP state get failed (%d)", err);
|
||||
|
@ -30,7 +28,7 @@ static void vcp_vol_rend_state_cb(struct bt_vcp *vcp, int err, uint8_t volume,
|
|||
}
|
||||
}
|
||||
|
||||
static void vcp_vol_rend_flags_cb(struct bt_vcp *vcp, int err, uint8_t flags)
|
||||
static void vcp_vol_rend_flags_cb(int err, uint8_t flags)
|
||||
{
|
||||
if (err) {
|
||||
shell_error(ctx_shell, "VCP flags get failed (%d)", err);
|
||||
|
@ -229,13 +227,13 @@ static int cmd_vcp_vol_rend_init(const struct shell *sh, size_t argc,
|
|||
|
||||
vcp_register_param.cb = &vcp_vol_rend_cbs;
|
||||
|
||||
result = bt_vcp_vol_rend_register(&vcp_register_param, &vcp);
|
||||
result = bt_vcp_vol_rend_register(&vcp_register_param);
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
result = bt_vcp_vol_rend_included_get(vcp, &vcp_included);
|
||||
result = bt_vcp_vol_rend_included_get(&vcp_included);
|
||||
if (result != 0) {
|
||||
shell_error(sh, "Failed to get included services: %d", result);
|
||||
return result;
|
||||
|
@ -267,7 +265,7 @@ static int cmd_vcp_vol_rend_volume_step(const struct shell *sh, size_t argc,
|
|||
static int cmd_vcp_vol_rend_state_get(const struct shell *sh, size_t argc,
|
||||
char **argv)
|
||||
{
|
||||
int result = bt_vcp_vol_rend_get_state(vcp);
|
||||
int result = bt_vcp_vol_rend_get_state();
|
||||
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -279,7 +277,7 @@ static int cmd_vcp_vol_rend_state_get(const struct shell *sh, size_t argc,
|
|||
static int cmd_vcp_vol_rend_flags_get(const struct shell *sh, size_t argc,
|
||||
char **argv)
|
||||
{
|
||||
int result = bt_vcp_vol_rend_get_flags(vcp);
|
||||
int result = bt_vcp_vol_rend_get_flags();
|
||||
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -291,7 +289,7 @@ static int cmd_vcp_vol_rend_flags_get(const struct shell *sh, size_t argc,
|
|||
static int cmd_vcp_vol_rend_volume_down(const struct shell *sh, size_t argc,
|
||||
char **argv)
|
||||
{
|
||||
int result = bt_vcp_vol_rend_vol_down(vcp);
|
||||
int result = bt_vcp_vol_rend_vol_down();
|
||||
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -304,7 +302,7 @@ static int cmd_vcp_vol_rend_volume_up(const struct shell *sh, size_t argc,
|
|||
char **argv)
|
||||
|
||||
{
|
||||
int result = bt_vcp_vol_rend_vol_up(vcp);
|
||||
int result = bt_vcp_vol_rend_vol_up();
|
||||
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -316,7 +314,7 @@ static int cmd_vcp_vol_rend_volume_up(const struct shell *sh, size_t argc,
|
|||
static int cmd_vcp_vol_rend_unmute_volume_down(const struct shell *sh,
|
||||
size_t argc, char **argv)
|
||||
{
|
||||
int result = bt_vcp_vol_rend_unmute_vol_down(vcp);
|
||||
int result = bt_vcp_vol_rend_unmute_vol_down();
|
||||
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -328,7 +326,7 @@ static int cmd_vcp_vol_rend_unmute_volume_down(const struct shell *sh,
|
|||
static int cmd_vcp_vol_rend_unmute_volume_up(const struct shell *sh,
|
||||
size_t argc, char **argv)
|
||||
{
|
||||
int result = bt_vcp_vol_rend_unmute_vol_up(vcp);
|
||||
int result = bt_vcp_vol_rend_unmute_vol_up();
|
||||
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -349,7 +347,7 @@ static int cmd_vcp_vol_rend_volume_set(const struct shell *sh, size_t argc,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
result = bt_vcp_vol_rend_set_vol(vcp, volume);
|
||||
result = bt_vcp_vol_rend_set_vol(volume);
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
}
|
||||
|
@ -360,7 +358,7 @@ static int cmd_vcp_vol_rend_volume_set(const struct shell *sh, size_t argc,
|
|||
static int cmd_vcp_vol_rend_unmute(const struct shell *sh, size_t argc,
|
||||
char **argv)
|
||||
{
|
||||
int result = bt_vcp_vol_rend_unmute(vcp);
|
||||
int result = bt_vcp_vol_rend_unmute();
|
||||
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
@ -372,7 +370,7 @@ static int cmd_vcp_vol_rend_unmute(const struct shell *sh, size_t argc,
|
|||
static int cmd_vcp_vol_rend_mute(const struct shell *sh, size_t argc,
|
||||
char **argv)
|
||||
{
|
||||
int result = bt_vcp_vol_rend_mute(vcp);
|
||||
int result = bt_vcp_vol_rend_mute();
|
||||
|
||||
if (result) {
|
||||
shell_print(sh, "Fail: %d", result);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue