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

Commit e8b59af9 authored by Andre Eisenbach's avatar Andre Eisenbach
Browse files

A2DP: Lowering maximum PCM frame limit to avoid audio breaks

Some car kits (notably Renesas car kits used in Nissan/Infiniti models)
will throttle incoming A2DP frames if too many frames are sent at once.
This patch lowers the maximum number of frames sent per tick to not
overwhelm the remote device.

Bug: 17880920
Change-Id: I7bfbba625405c96159d1c94eebd8dc498f100daa
parent f01246d8
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ static UINT32 a2dp_media_task_stack[(A2DP_MEDIA_TASK_STACK_SIZE + 3) / 4];
/* 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
#define A2DP_PACKET_COUNT_LOW_WATERMARK 5
#define MAX_PCM_FRAME_NUM_PER_TICK     20
#define MAX_PCM_FRAME_NUM_PER_TICK     10
#define RESET_RATE_COUNTER_THRESHOLD_MS    2000

//#define BTIF_MEDIA_VERBOSE_ENABLED
@@ -2476,16 +2476,17 @@ static UINT8 btif_get_num_aa_frame(void)
                }
                /* calculate nbr of frames pending for this media tick */
                result = btif_media_cb.media_feeding_state.pcm.counter/pcm_bytes_per_frame;
                if (result > MAX_PCM_FRAME_NUM_PER_TICK) result = MAX_PCM_FRAME_NUM_PER_TICK;
                if (result > MAX_PCM_FRAME_NUM_PER_TICK)
                {
                    APPL_TRACE_ERROR("%s() - Limiting frames to be sent from %d to %d"
                        , __FUNCTION__, result, MAX_PCM_FRAME_NUM_PER_TICK);
                    result = MAX_PCM_FRAME_NUM_PER_TICK;
                }
                btif_media_cb.media_feeding_state.pcm.counter -= result*pcm_bytes_per_frame;
            } else {
                result = 0;
            }

            /* smooth out the compensation over time to minimize burstiness towards UIPC */
            if (result > MAX_PCM_FRAME_NUM_PER_TICK)
                result = MAX_PCM_FRAME_NUM_PER_TICK;

            VERBOSE("WRITE %d FRAMES", result);
        }
        break;