OSDN Git Service

A2DP media task: Flush full TX queue on congestion
authorAndre Eisenbach <eisenbach@google.com>
Thu, 23 Jun 2016 23:14:53 +0000 (16:14 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Fri, 24 Jun 2016 23:43:22 +0000 (23:43 +0000)
Currently, our TX queue does not allow for quick recovery of minor
congestion. As we only clear as much room in the queue as is needed to
fix the news frames needed for a given timer tick, any minor congestion
on the TX path can result in single frames to be dropped over an
excessively long amount of time.

From the "just rip the band-aid off" school of thought, drop the whole
queue instead to cause a single drop-out on congestion and catch up to
the live stream immediately, hoping that the stream recovers...

Bug: 29601962
Change-Id: I482c3cfef6d8b51143e54733eb2da5f70663636f

btif/src/btif_media_task.c

index d903072..08af577 100644 (file)
@@ -176,7 +176,7 @@ enum {
 #define USEC_PER_SEC 1000000L
 #define TPUT_STATS_INTERVAL_US (3000*1000)
 
-/*
+/**
  * CONGESTION COMPENSATION CTRL ::
  *
  * Thus setting controls how many buffers we will hold in media task
@@ -188,19 +188,18 @@ enum {
  * jitterbuffer runlevel including any intermediate buffers on the way
  * towards the sinks codec.
  */
-
-/* fixme -- define this in pcm time instead of buffer count */
-
-/* The typical runlevel of the tx queue size is ~1 buffer
-   but due to link flow control or thread preemption in lower
-   layers we might need to temporarily buffer up data */
-/* 18 frames is equivalent to 6.89*18*2.9 ~= 360 ms @ 44.1 khz, 20 ms mediatick */
-#define MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ 18
 #ifndef MAX_PCM_FRAME_NUM_PER_TICK
 #define MAX_PCM_FRAME_NUM_PER_TICK     14
 #endif
 #define MAX_PCM_ITER_NUM_PER_TICK      3
 
+/**
+ * The typical runlevel of the tx queue size is ~1 buffer
+ * but due to link flow control or thread preemption in lower
+ * layers we might need to temporarily buffer up data.
+ */
+#define MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ (MAX_PCM_FRAME_NUM_PER_TICK * 2)
+
 /* In case of A2DP SINK, we will delay start by 5 AVDTP Packets*/
 #define MAX_A2DP_DELAYED_START_FRAME_COUNT 5
 #define PACKET_PLAYED_PER_TICK_48 8
@@ -3099,11 +3098,11 @@ static void btif_media_aa_prep_2_send(UINT8 nb_frame, uint64_t timestamp_us)
                            MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame);
         btif_media_cb.stats.tx_queue_dropouts++;
         btif_media_cb.stats.tx_queue_last_dropouts_us = timestamp_us;
-    }
 
-    while (fixed_queue_length(btif_media_cb.TxAaQ) > (MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame)) {
-        btif_media_cb.stats.tx_queue_total_dropped_messages++;
-        osi_free(fixed_queue_try_dequeue(btif_media_cb.TxAaQ));
+        while (fixed_queue_length(btif_media_cb.TxAaQ)) {
+            btif_media_cb.stats.tx_queue_total_dropped_messages++;
+            osi_free(fixed_queue_try_dequeue(btif_media_cb.TxAaQ));
+        }
     }
 
     // Transcode frame