Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 17d9ebbd authored by Andre Eisenbach's avatar Andre Eisenbach
Browse files

Avoid race condition in SBC encoder initialization

In the A2DP media task, btif_a2dp_encoder_update() relies on the fact
that btif_a2dp_encoder_init() is called beforehand. Otherwise division
by zero errors will occur.

Since _init() called after the audio stream is opened, and _update() is
called in resonse the the audio stream being opened, a race condition
could ensue where _update() was called before open.

This patch changes the A2DP stream start sequence to ensure the SBC
encoder is initialized before the updated parameters are calculated.

Bug: 17339248
Change-Id: I6ed36a7fff0e4aa672a8866727030681eb4b3dfc
parent b6e34436
Loading
Loading
Loading
Loading
+2 −7
Original line number Diff line number Diff line
@@ -562,12 +562,7 @@ static BOOLEAN btif_av_state_opened_handler(btif_sm_event_t event, void *p_data)
            break;

        case BTIF_AV_START_STREAM_REQ_EVT:
            if (btif_av_cb.peer_sep == AVDT_TSEP_SRC)
            {
                BTA_AvStart();
                btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
                break;
            }
            if (btif_av_cb.peer_sep != AVDT_TSEP_SRC)
                btif_a2dp_setup_codec();
            BTA_AvStart();
            btif_av_cb.flags |= BTIF_AV_FLAG_PENDING_START;
+5 −2
Original line number Diff line number Diff line
@@ -510,8 +510,11 @@ static void btif_recv_ctrl_data(void)

                /* post start event and wait for audio path to open */
                btif_dispatch_sm_event(BTIF_AV_START_STREAM_REQ_EVT, NULL, 0);
//FIXME

#if (BTA_AV_SINK_INCLUDED == TRUE)
                if (btif_media_cb.peer_sep == AVDT_TSEP_SRC)
                    a2dp_cmd_acknowledge(A2DP_CTRL_ACK_SUCCESS);
#endif
            }
            else if (btif_av_stream_started_ready())
            {