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

Commit 631ffd4f authored by Sandeep Samdaria's avatar Sandeep Samdaria
Browse files

Alternating packets queued in the audio buffer

Problem: BTIF a2dp sink receives the media data and enqueues the
audio packet.It's possible that the audio buffer can become full
before being flushed. Once, the buffer is full the enqueue_buffer
the stack starts dropping the old packets. However, it doesn't
queue the incoming packet. This results in the packet to be
dropped alternatively and degrading the audio quality.

Solution: First queue up the incoming packet. Once the queue is
full, drop the last packet to make space for the next packet.
This will ensure there is always a space in the next incoming
packet and alternate packets are not dropped.

Bug: 279956598
Test: m seahawk-userdebug. Tested on the seahawk device by queueing the packet.
Tag: #stability
Change-Id: Ie2377ee47de56ee2fa601f85ab363c02ea02e61c
parent b9b157e9
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -669,13 +669,6 @@ uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_pkt) {
  if (btif_a2dp_sink_cb.rx_flush) /* Flush enabled, do not enqueue */
    return fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue);

  if (fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue) ==
      MAX_INPUT_A2DP_FRAME_QUEUE_SZ) {
    uint8_t ret = fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue);
    osi_free(fixed_queue_try_dequeue(btif_a2dp_sink_cb.rx_audio_queue));
    return ret;
  }

  BTIF_TRACE_VERBOSE("%s +", __func__);
  /* Allocate and queue this buffer */
  BT_HDR* p_msg =
@@ -684,6 +677,14 @@ uint8_t btif_a2dp_sink_enqueue_buf(BT_HDR* p_pkt) {
  p_msg->offset = 0;
  memcpy(p_msg->data, p_pkt->data + p_pkt->offset, p_pkt->len);
  fixed_queue_enqueue(btif_a2dp_sink_cb.rx_audio_queue, p_msg);

  if (fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue) ==
      MAX_INPUT_A2DP_FRAME_QUEUE_SZ) {
    osi_free(fixed_queue_try_dequeue(btif_a2dp_sink_cb.rx_audio_queue));
    uint8_t ret = fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue);
    return ret;
  }

  // Avoid other checks if alarm has already been initialized.
  if (btif_a2dp_sink_cb.decode_alarm == nullptr &&
      fixed_queue_length(btif_a2dp_sink_cb.rx_audio_queue) >=