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

Commit d24786ac authored by Thomas Girardier's avatar Thomas Girardier Committed by Automerger Merge Worker
Browse files

Merge changes I5a051571,Icbda534f,I67d81723 am: efd7b58a

parents 503bbfc4 efd7b58a
Loading
Loading
Loading
Loading
+24 −13
Original line number Diff line number Diff line
@@ -168,17 +168,18 @@ class A2dp(val context: Context) : A2DPImplBase() {
        throw Status.UNKNOWN.asException()
      }

      audioTrack.play()

      // If A2dp is not already playing, wait for it
      if (!bluetoothA2dp.isA2dpPlaying(device)) {
        val a2dpPlayingStateFlow =
        flow
          .filter { it.getAction() == BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED }
          .filter {
            it.getParcelableExtra<BluetoothDevice>(BluetoothDevice.EXTRA_DEVICE).address == address
          }
          .map { it.getIntExtra(BluetoothA2dp.EXTRA_STATE, BluetoothAdapter.ERROR) }

        audioTrack.play()
        a2dpPlayingStateFlow.filter { it == BluetoothA2dp.STATE_PLAYING }.first()
          .filter { it == BluetoothA2dp.STATE_PLAYING }
          .first()
      }
      StartResponse.getDefaultInstance()
    }
@@ -264,6 +265,10 @@ class A2dp(val context: Context) : A2DPImplBase() {
  ): StreamObserver<PlaybackAudioRequest> {
    Log.i(TAG, "playbackAudio")

    if (audioTrack.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) {
      responseObserver.onError(Status.UNKNOWN.withDescription("AudioTrack is not started").asException())
    }

    // Volume is maxed out to avoid any amplitude modification of the provided audio data,
    // enabling the test runner to do comparisons between input and output audio signal.
    // Any volume modification should be done before providing the audio data.
@@ -279,10 +284,16 @@ class A2dp(val context: Context) : A2DPImplBase() {
        )
      }
    }

    return object : StreamObserver<PlaybackAudioRequest> {
      override fun onNext(request: PlaybackAudioRequest) {
        val data = request.data.toByteArray()
        audioTrack.write(data, 0, data.size)
        val written = audioTrack.write(data, 0, data.size)
        if (written != data.size) {
          responseObserver.onError(
            Status.UNKNOWN.withDescription("AudioTrack write failed").asException()
          )
        }
      }
      override fun onError(t: Throwable?) {
        Log.e(TAG, t.toString())