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

Commit 9dc709df authored by Andre Eisenbach's avatar Andre Eisenbach
Browse files

A2DP media task: Flush full TX queue on congestion

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
parent a293e605
Loading
Loading
Loading
Loading
+12 −13
Original line number Original line Diff line number Diff line
@@ -176,7 +176,7 @@ enum {
#define USEC_PER_SEC 1000000L
#define USEC_PER_SEC 1000000L
#define TPUT_STATS_INTERVAL_US (3000*1000)
#define TPUT_STATS_INTERVAL_US (3000*1000)


/*
/**
 * CONGESTION COMPENSATION CTRL ::
 * CONGESTION COMPENSATION CTRL ::
 *
 *
 * Thus setting controls how many buffers we will hold in media task
 * 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
 * jitterbuffer runlevel including any intermediate buffers on the way
 * towards the sinks codec.
 * 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
#ifndef MAX_PCM_FRAME_NUM_PER_TICK
#define MAX_PCM_FRAME_NUM_PER_TICK     14
#define MAX_PCM_FRAME_NUM_PER_TICK     14
#endif
#endif
#define MAX_PCM_ITER_NUM_PER_TICK      3
#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*/
/* In case of A2DP SINK, we will delay start by 5 AVDTP Packets*/
#define MAX_A2DP_DELAYED_START_FRAME_COUNT 5
#define MAX_A2DP_DELAYED_START_FRAME_COUNT 5
#define PACKET_PLAYED_PER_TICK_48 8
#define PACKET_PLAYED_PER_TICK_48 8
@@ -3099,12 +3098,12 @@ static void btif_media_aa_prep_2_send(UINT8 nb_frame, uint64_t timestamp_us)
                           MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame);
                           MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ - nb_frame);
        btif_media_cb.stats.tx_queue_dropouts++;
        btif_media_cb.stats.tx_queue_dropouts++;
        btif_media_cb.stats.tx_queue_last_dropouts_us = timestamp_us;
        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)) {
        while (fixed_queue_length(btif_media_cb.TxAaQ)) {
            btif_media_cb.stats.tx_queue_total_dropped_messages++;
            btif_media_cb.stats.tx_queue_total_dropped_messages++;
            osi_free(fixed_queue_try_dequeue(btif_media_cb.TxAaQ));
            osi_free(fixed_queue_try_dequeue(btif_media_cb.TxAaQ));
        }
        }
    }


    // Transcode frame
    // Transcode frame