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

Commit 4f2dbcec authored by David Duarte's avatar David Duarte
Browse files

BlueberryServer: Send grpc error on AudioTrack errors

Test: atest pts-bot
Change-Id: I5a0515718c5f70e3ccd1bdaef0699f2b1f463cc9
parent 92531dd2
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -265,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.
@@ -280,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())