Skip to content

Commit 99396a7

Browse files
committed
applications: nrf_audio: Fix deadlock between MCS and streaming state
- Override MCS state if it doesn't match current streaming state - Add timeout to CAP procedures to capture disconnects during proc - OCT-3775 Signed-off-by: Alexander Svensen <alexander.svensen@nordicsemi.no>
1 parent 184c59a commit 99396a7

9 files changed

Lines changed: 334 additions & 112 deletions

File tree

applications/nrf_audio/src/bluetooth/bt_content_control/bt_content_ctrl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ int bt_content_ctrl_uuid_populate(struct net_buf_simple *uuid_buf)
131131
return 0;
132132
}
133133

134+
void bt_content_ctrl_state_override(bool playing)
135+
{
136+
if (IS_ENABLED(CONFIG_BT_MCS)) {
137+
bt_content_ctrl_media_state_override(playing);
138+
}
139+
}
140+
134141
int bt_content_ctrl_init(void)
135142
{
136143
int ret;

applications/nrf_audio/src/bluetooth/bt_content_control/bt_content_ctrl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ int bt_content_ctrl_uuid_populate(struct net_buf_simple *uuid_buf);
7070
*/
7171
bool bt_content_ctlr_media_state_playing(void);
7272

73+
/**
74+
* @brief Override the current state of the media player.
75+
*
76+
* @note This is needed if the media player state is not in sync with the actual state of
77+
* stream. This can happen if a device disconnects at the same time as a play/pause
78+
* command is sent.
79+
*
80+
* @param[in] playing Indicate whether the content should be in the playing state.
81+
*/
82+
void bt_content_ctrl_state_override(bool playing);
83+
7384
/**
7485
* @brief Initialize the content control module.
7586
*

applications/nrf_audio/src/bluetooth/bt_content_control/media/bt_content_ctrl_media.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ static int mpl_cmd_send(struct bt_conn *conn, struct mpl_cmd *cmd)
332332
return 0;
333333
}
334334

335+
void bt_content_ctrl_media_state_override(bool playing)
336+
{
337+
if (IS_ENABLED(CONFIG_BT_MCS)) {
338+
if (playing) {
339+
media_player_state = BT_MCS_MEDIA_STATE_PLAYING;
340+
} else {
341+
media_player_state = BT_MCS_MEDIA_STATE_PAUSED;
342+
}
343+
}
344+
}
345+
335346
int bt_content_ctrl_media_discover(struct bt_conn *conn)
336347
{
337348
int ret;

applications/nrf_audio/src/bluetooth/bt_content_control/media/bt_content_ctrl_media_internal.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
*/
1717
typedef void (*bt_content_ctrl_media_play_pause_cb)(bool play);
1818

19+
/**
20+
* @brief Override the current state of the media player.
21+
*
22+
* @note This is needed if the media player state is not in sync with the actual state of
23+
* stream. This can happen if a device disconnects at the same time as a play/pause
24+
* command is sent.
25+
*
26+
* @param[in] playing Indicate whether the media player should be in the playing state.
27+
*/
28+
void bt_content_ctrl_media_state_override(bool playing);
29+
1930
/**
2031
* @brief Discover Media Control Service and the included services.
2132
*

applications/nrf_audio/src/bluetooth/bt_stream/unicast/server_store.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,7 @@ int srv_store_all_ep_state_count(enum bt_bap_ep_state state, enum bt_audio_dir d
11511151
srv_idx, count);
11521152
return count;
11531153
}
1154+
11541155
count_total += count;
11551156
}
11561157

0 commit comments

Comments
 (0)