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

Commit bca4f8f4 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

leaudio: Notify new configuration only when streaming starts

Without this patch CodecConfigurationChanged will be sent to java also when
UpdateMatadata is finished or when late connect happens.
LeAudioService then notifies Audio Framework which triggers Audio Framework to
read configuration. This operation cause reduntat audio pause.
This issue happens only when flag
leaudio_codec_config_callback_order_fix is set.

Bug: 336453376
Bug: 326442537
Test: atest bluetooth_leaudio_client_test
Change-Id: I465ba452e74a5811c62904a94a4441da37fb6919
parent 35ddefcd
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -5662,12 +5662,23 @@ class LeAudioClientImpl : public LeAudioClient {
                      weak_factory_.GetWeakPtr(), std::placeholders::_1,
                      std::placeholders::_2));

        if (audio_sender_state_ == AudioState::READY_TO_START)
        /* When at least one direction is started we can assume new
         * configuration here */
        bool new_configuration = false;
        if (audio_sender_state_ == AudioState::READY_TO_START) {
          StartSendingAudio(group_id);
        if (audio_receiver_state_ == AudioState::READY_TO_START)
          new_configuration = true;
        }

        if (audio_receiver_state_ == AudioState::READY_TO_START) {
          StartReceivingAudio(group_id);
          new_configuration = true;
        }

        if (new_configuration) {
          /* Notify Java about new configuration */
          SendAudioGroupCurrentCodecConfigChanged(group);
        }
        break;
      }
      case GroupStreamStatus::SUSPENDED:
+65 −0
Original line number Diff line number Diff line
@@ -5017,6 +5017,71 @@ TEST_F(UnicastTest, ChangeAvailableContextTypeWhenInCodecConfigured) {
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
}

TEST_F(UnicastTest, TestUpdateConfigurationCallbackWhileStreaming) {
  const RawAddress test_address0 = GetTestAddress(0);
  int group_id = bluetooth::groups::kGroupUnknown;

  SetSampleDatabaseEarbudsValid(
      1, test_address0, codec_spec_conf::kLeAudioLocationStereo,
      codec_spec_conf::kLeAudioLocationStereo, default_channel_cnt,
      default_channel_cnt, 0x0004,
      /* source sample freq 16khz */ false /*add_csis*/, true /*add_cas*/,
      true /*add_pacs*/, default_ase_cnt /*add_ascs_cnt*/, 1 /*set_size*/,
      0 /*rank*/);
  EXPECT_CALL(mock_audio_hal_client_callbacks_,
              OnConnectionState(ConnectionState::CONNECTED, test_address0))
      .Times(1);
  EXPECT_CALL(mock_audio_hal_client_callbacks_,
              OnGroupNodeStatus(test_address0, _, GroupNodeStatus::ADDED))
      .WillOnce(DoAll(SaveArg<1>(&group_id)));

  ConnectLeAudio(test_address0);
  ASSERT_NE(group_id, bluetooth::groups::kGroupUnknown);

  // Start streaming
  LeAudioClient::Get()->GroupSetActive(group_id);
  SyncOnMainLoop();

  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, _)).Times(1);
  EXPECT_CALL(mock_audio_hal_client_callbacks_,
              OnAudioGroupCurrentCodecConf(group_id, _, _))
      .Times(1);
  StartStreaming(AUDIO_USAGE_MEDIA, AUDIO_CONTENT_TYPE_MUSIC, group_id);

  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
  Mock::VerifyAndClearExpectations(&mock_state_machine_);
  SyncOnMainLoop();

  // When metadata update happen, there should be no configuration change
  // callback sent
  EXPECT_CALL(mock_audio_hal_client_callbacks_,
              OnAudioGroupCurrentCodecConf(group_id, _, _))
      .Times(0);

  EXPECT_CALL(mock_state_machine_, StartStream(_, _, _, _)).Times(1);
  UpdateLocalSourceMetadata(AUDIO_USAGE_ALARM, AUDIO_CONTENT_TYPE_UNKNOWN);

  // Inject STREAMING Status from state machine.
  auto group = streaming_groups.at(group_id);
  do_in_main_thread(
      FROM_HERE,
      base::BindOnce(
          [](int group_id,
             bluetooth::le_audio::LeAudioGroupStateMachine::Callbacks*
                 state_machine_callbacks,
             LeAudioDeviceGroup* group) {
            state_machine_callbacks->StatusReportCb(
                group_id, GroupStreamStatus::STREAMING);
          },
          group_id, base::Unretained(this->state_machine_callbacks_),
          std::move(group)));

  SyncOnMainLoop();
  Mock::VerifyAndClearExpectations(&mock_state_machine_);
  Mock::VerifyAndClearExpectations(&mock_audio_hal_client_callbacks_);
}

TEST_F(UnicastTest, RemoveNodeWhileStreaming) {
  const RawAddress test_address0 = GetTestAddress(0);
  int group_id = bluetooth::groups::kGroupUnknown;