History log of /system/bt/btif/src/btif_media_task.c
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
ade5776f2b292c4dcb367aaf542d3e5d7956c4cd 29-Jun-2016 Andre Eisenbach <eisenbach@google.com> Log RSSI when A2DP buffers are flushed

To add another datapoint and potentially narrow down *why* we had to
flush the buffers, add RSSI logging to keep track of signal strength
during audio drop-out events.

Change-Id: Ie52f56290951130165a9f375a898a9bacf459d55
/system/bt/btif/src/btif_media_task.c
d881c4b46776fe03a5861a3021bbe739b1f3cc58 24-Jun-2016 Andre Eisenbach <eisenbach@google.com> 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
/system/bt/btif/src/btif_media_task.c
470aee234664fd75094c16dd2c70313ee28354c1 24-Jun-2016 Andre Eisenbach <eisenbach@google.com> Remove SBC frame scrambling

Bug: 29601962
Change-Id: I30ce09f1c7550a1be9fd1c8ed70745f9aa0cdb44
/system/bt/btif/src/btif_media_task.c
8bbbee165d2c8bb17353b11de1a3e74e089eff73 11-Nov-2013 Ayan Ghosh <abghosh@codeaurora.org> Limit number of SBC frames to fit into single MTU

- Calculate number of SBC frames to fit into single MTU for EDR capable
remote devices. This makes sure the maximum utilization of the
available bandwidth, keeping the bitrate at high quality.
- This change helps to address the discrepancy seen with a few available
2 Mbps headsets which set the AVDTP media MTU size greater than the
2DH5 packet payload size which eventually forces AVDTP packets to get
fragmented in the controller. This change ensures packing of the SBC
frames in a way that AVDTP packet size fits within the 2DH5 payload
size.
- As packet size is restricted to meet the required bit rate more than
one AVDTP packet can be sent to the controller in a given iteration
based on the bit rate requirement.

Bug: 24875861
Change-Id: Icae7656ad563bbbdef65ecbfa15a89b26cf9edb2
/system/bt/btif/src/btif_media_task.c
aee67ece726e9b5d0e2e02562fe013ae85c46d63 18-May-2016 Pavlin Radoslavov <pavlin@google.com> Add error log messages for A2DP commands

Bug: 28823662
Change-Id: Ifa9950dd2277b444bedd5108beff2db029a5ed93
/system/bt/btif/src/btif_media_task.c
97253ccb9e6706d9db1333ba44f4c868398dfa25 22-Apr-2016 Sridhar Vashist <svashist@motorola.com> Make default SBC bitrate configurable by device. am: 5f308397b7
am: b2019873c6

* commit 'b2019873c6253f29026b473ad92e417796c7a166':
Make default SBC bitrate configurable by device.

Change-Id: I2257bf7a4f6e24d1995f93469268021476c1f829
38487b9f71842a294b9a56843efcfa3a3d672822 08-Apr-2016 Sanket Agarwal <sanketa@google.com> Allow A2DP SNK audio track focus gain interface.

In order to duck music we need to adjust the gain of the audio track
handled by A2DP SNK. Since SNK is implemented in native we need to add
interface to adjust the gain.

Bug: b/28065071

Change-Id: I60634cfadb502e276596bcb3aafc62ef81d9023a
/system/bt/btif/src/btif_media_task.c
4a58ac919bcd03a825a811ac1c799ccd22a857da 05-Apr-2016 Pavlin Radoslavov <pavlin@google.com> Updated the A2DP statistics

* Added "Frame expected" and "Frames limited" statistics in the
bugreport about expected and limited number of frames per tick.
Also, added corresponding "Counts (expected/limited)":

A2DP State:
TxQueue:
Counts (enqueue/dequeue/readbuf) : 386 / 386 / 768
Last update time ago in ms (enqueue/dequeue/readbuf) : 12644 / 12643 / 12600
Frames expected (total/max/ave) : 2632 / 8 / 6
Frames limited (total/max/ave) : 0 / 0 / 0
Counts (expected/limited) : 382 / 0
Frames per packet (total/max/ave) : 2618 / 7 / 6
...

* Renamed "tx_queue_max_frames" to "tx_queue_max_frames_per_packet"

* Fixed the computation of actual transmitted frames:
tx_queue_total_frames, tx_queue_max_frames_per_packet

* Computed / added buffer_overruns_max_count and
buffer_underruns_average to the Protobuf stats.

Bug: 27500656
Change-Id: Id58cfb0b5de2296742c84aa0b743e0eed398f41f
/system/bt/btif/src/btif_media_task.c
968265f3f4408ee5edb08628a1fccb8a995ba87e 30-Mar-2016 Sanket Agarwal <sanketa@google.com> A2DP_SINK: initialize track handle to null

- initialize track handle to null
- prevent invoking audiotrack API in case handle is null

Bug: 27613411

Change-Id: I1a8637fd2cbb3012b29c1930f978100e7f0c58d8
/system/bt/btif/src/btif_media_task.c
d14f97c87685e480ee1a88829497651bccf2b358 03-Mar-2016 Ayan Ghosh <abghosh@codeaurora.org> Process AV HAL start only when previous instance is cleaned up

Bug: 27852645
Change-Id: Iee232dacd3b79e6e94d26c73fb3e563fddced75c
/system/bt/btif/src/btif_media_task.c
597ce3bd08533c24cd61be0ef4ad8a237571770f 08-Mar-2016 Dimitry Ivanov <dimitry@google.com> Fix the build

Change-Id: Ib226f087a76ddd426e40f4d6d94f2ed758660c36
/system/bt/btif/src/btif_media_task.c
547b7b52578fddbd9e42ce1cc7e7bba9dded1d7d 11-Feb-2016 Sanket Agarwal <sanketa@google.com> Move focus handling entirely to component calling fluoride.

Audio focus handling for A2DP sink currently split between Fluoride and
the component sitting on top of it. Since this is not the best place to
decide policies, we move all such decisions to the upper layer.

Bug: b/26928143

Change-Id: I67a1a2a50782289e7e31447b01ee29a21bc8dac2
/system/bt/btif/src/btif_media_task.c
cb090050e3f45905a33f595cee9e12b3e2c66e86 01-Mar-2016 Pavlin Radoslavov <pavlin@google.com> Reset queue pointer to NULL after fixed_queue_free()

Add missing reset of queue pointers to NULL affter
fixed_queue_free() calls.

Bug: 26742590
Change-Id: Ib9035d58c0f98a47ce2935e073c6f288ae03ac92
/system/bt/btif/src/btif_media_task.c
8efca14b7f6570659d5e7a73327e2288cc544922 22-Feb-2016 Ajay Panicker <apanicke@google.com> Clean A2DP dump output

Before:
TxQueue:
Counts (enqueue/dequeue/readbuf) : 0 / 0 / 0
Last update time ago in ms (enqueue/dequeue/readbuf) : 0 / 0 / 0
Frames per packet (total/max/ave) : 0 / 0 / 0
Counts (flushed/dropped/dropouts) : 0 / 0 / 0
Last update time ago in ms (flushed/dropped) : 0 / 0
Counts (underflow/underrun) : 0 / 0
Bytes (underflow/underrun) : 0 / 0
Last update time ago in ms (underflow/underrun) : 0 / 0
Enqueue deviation counts (overdue/premature) : 0 / 0
Enqueue overdue scheduling time in ms (total/max/ave) : 0 / 0 / 0
Enqueue premature scheduling time in ms (total/max/ave) : 0 / 0 / 0
Dequeue deviation counts (overdue/premature) : 0 / 0
Dequeue overdue scheduling time in ms (total/max/ave) : 0 / 0 / 0
Dequeue premature scheduling time in ms (total/max/ave) : 0 / 0 / 0

After:
TxQueue:
Counts (enqueue/dequeue/readbuf) : 0 / 0 / 0
Last update time ago in ms (enqueue/dequeue/readbuf) : 0 / 0 / 0
Frames per packet (total/max/ave) : 0 / 0 / 0
Counts (flushed/dropped/dropouts) : 0 / 0 / 0
Last update time ago in ms (flushed/dropped) : 0 / 0
Counts (underflow/underrun) : 0 / 0
Bytes (underflow/underrun) : 0 / 0
Last update time ago in ms (underflow/underrun) : 0 / 0
Enqueue deviation counts (overdue/premature) : 0 / 0
Enqueue overdue scheduling time in ms (total/max/ave) : 0 / 0 / 0
Enqueue premature scheduling time in ms (total/max/ave) : 0 / 0 / 0
Dequeue deviation counts (overdue/premature) : 0 / 0
Dequeue overdue scheduling time in ms (total/max/ave) : 0 / 0 / 0
Dequeue premature scheduling time in ms (total/max/ave) : 0 / 0 / 0

Bug: 27294154
Change-Id: I2952ceed7b02db0d8497b67de0f57e4f9128e5bf
/system/bt/btif/src/btif_media_task.c
4e6b1c82b78aa17c887376c14cf323bed02e1fd4 18-Feb-2016 Pavlin Radoslavov <pavlin@google.com> Add support for collecting A2DP Protobuf metrics

* Add new function metrics_a2dp_session() to
connect A2DP metrics into Protobuf

* Add new function btif_update_a2dp_metrics()
that is called when the metrics should be
callected

* Add few more statistics to the BTIF media stats.

Change-Id: I5862ac82e55b3546dc1fbde0c78cb4683e40d19e
/system/bt/btif/src/btif_media_task.c
5fe6f0cf6b223e3ed6be4912d55b3ed5b41ce0cd 06-Feb-2016 Pavlin Radoslavov <pavlin@google.com> Removed checks for NULL returns after osi_calloc() / osi_malloc()

Removed explicit checks for NULL pointer returns after calls
to osi_calloc() and osi_malloc(), because those are not needed.
If the memory allocation fails, osi_calloc() and osi_malloc()
will trigger an assert.

Bug: 27048759
Change-Id: I2791eb2f69c08f991f8fcdef10e101a41568cd95
/system/bt/btif/src/btif_media_task.c
abd70abb5e42c9431df94fe9d2c4a78a0d8d9af9 05-Feb-2016 Pavlin Radoslavov <pavlin@google.com> Replaced osi_getbuf()/osi_freebuf() with osi_malloc()/osi_free()

Removed the alternative buffer allocation osi_getbuf() / osi_freebuf()
and use instead osi_malloc() / osi_free().

Correspondingly, replaced usage of osi_freebuf_and_reset()
with osi_free_and_reset().

Bug: 24914560
Change-Id: I7a9599ba7fa900321f087da684428133eb0ddd6b
/system/bt/btif/src/btif_media_task.c
ffba52aeef45451226991d9443c4442a33a7f231 14-Jan-2016 Pavlin Radoslavov <pavlin@google.com> Added metrics for A2DP transmission queue

Collect and display A2DP metrics related to the A2DP transmission queue.
The result can be displayed by "adb shell dumpsys bluetooth_manager":

A2DP State:

TxQueue:
Counts (enqueue/dequeue/readbuf) : 1767 / 1767 / 3504
Last update time ago in ms (enqueue/dequeue/readbuf) : 3 / 3 / 3
Frames per packet (total/max/ave) : 12210 / 11 / 6
Counts (flushed/dropped/dropouts) : 0 / 0 / 0
Last update time ago in ms (flushed/dropped) : 0 / 0
Counts (underflow/underrun) : 0 / 0
Bytes (underflow/underrun) : 0 / 0
Last update time ago in ms (underflow/underrun) : 0 / 0
Enqueue deviation counts (overdue/premature) : 893 / 871
Enqueue overdue scheduling time in ms (total/max/ave) : 242 / 12 / 0
Enqueue premature scheduling time in ms (total/max/ave) : 842 / 20 / 0
Dequeue deviation counts (overdue/premature) : 869 / 897
Dequeue overdue scheduling time in ms (total/max/ave) : 604 / 11 / 0
Dequeue premature scheduling time in ms (total/max/ave) : 1204 / 19 / 1

Change-Id: I75c8f24a26cf9ce7a4164a142d4ac286ff17f322
/system/bt/btif/src/btif_media_task.c
78bcff79e1b1f0efce436b33bdd6da88745bfc8a 05-Dec-2015 Pavlin Radoslavov <pavlin@google.com> Refactor the Bluetooth timers

* Updated the alarm API:
- Existing API alarm_new() is modified to take an alarm name
as an argument.
- New API alarm_new_periodic() is used to create a periodic
alarm.
- Added new API alarm_is_scheduled() to test whether an alarm is
scheduled.
- Existing API alarm_set_periodic() is removed: a periodic
alarm is created by alarm_new_periodic().
- Added new API alarm_set_on_queue() to set an alarm whose
callback is executed on a specific queue.
- Added new API alarm_register_processing_queue() and
alarm_unregister_processing_queue() to register/unregister
a queue and the corresponding thread for alarm processing.
- Added corresponding unit tests.

* Updated the alarm internals:
- Added alarm_info_t for collecting alarm-related information
and statistics.
- Collect and store alarm-related statistics into alarm_info_t
per alarm.
- Include the alarm-related statistics and info into the native
dumpsys output for Bluetooth.
- Once an alarm expires, the alarm execution is scheduled for
processing on another internal alarm-specific thread, not
on the thread that is maintaining the alarms.
- Implemented callback execution ordering guarantee among
timers on the same thread with exactly same timeout values.

* Refactor some of the usage of alarm_set() and simplify the
code by using alarm_set_on_queue() instead.

* Removed the non_repeating timers wrapper, and use directly
the alarm mechanism / API.

* Refactored all timer_entry_t timers and replaced them with alarm_t
timers:
- Replaced the btu_start_timer() / btu_stop_timer() /
btu_start_quick_timer() / btu_stop_quick_timer() /
btu_oneshot_alarm() mechanism with alarm_set_on_queue() and
alarm_cancel()
- Removed the whole mechanism around the BTU_TTYPE_* timers.

* Fixed a bug when processing the GATT indication confirmation timer
expiration (timer tGATT_TCB.conf_timer: b/26610829).

* Renamed and/or split misc. timeout functions, fields, and timers

* Renamed time-related constants and changed the values from seconds
to milliseconds

* Replaced timer tAVDT_CCB.timer_entry with three mutually exclusive timers:
idle_ccb_timer, ret_ccb_timer, rsp_ccb_timer
The reason we are using three timers, is because in the original code
function avdt_ccb_chk_timer() used the timer type in its logic: it
would stop the timer only if the type is "idle".

* Removed btm_ble_timeout() and replaced it with multiple timeout
callback functions (per timer)

* Fix the actual value of the global constant BT_1SEC_TIMEOUT and
rename it to BT_1SEC_TIMEOUT_MS

* Removed btu_cb and associated timers and events, because they are
never used.

* Removed unused timers, functions, struct and declarations that are
not used / needed.

Bug: 26611369
Bug: 26610829

Change-Id: I812c8c31710a5daefc58b01fcf35c353768f390f
/system/bt/btif/src/btif_media_task.c
6b84f291c4edce7e4102efd8d4052a63bcb4b9dc 05-May-2015 Anubhav Gupta <anubhavg@codeaurora.org> Support for A2DP Sink and Proper initialization of profiles

- Register SDP and SEP (Stream End Point) for the profile
whose init is called. We achieve this by making registration
api aware of profile id being called.
- Register A2DP Src + Avrcp Target + Avrcp Controller. We need
to support Absolute Volume as well, so Avrcp Controller is
required here.
- Register A2DP Sink + Avrcp Controller. In this case we do not
support absolute volume. Support would be added in AVRCP
controller change
- Adapter property is updated with profile ID for which init is
called.This is required to make changes in btService for Profile
initialization
- Start listening for incoming AVRCP connection if we have
only AVRCP Controller
- Update default peer_features based on feature mask. In case
of incoming AVRCP connection, SDP will be done later.
In such a scenario default peer features sent to btif should
be based on features-set selected during initialization.
- Drop Control, Meta and Browse commands when TG is not up.
- Not to call AVRCP app callbacks when mentioned service is down.
- Close audio socket on suspend

A2DP Sink: Support for AudioTrack

- implemetation for audiotrack to take care of audio rendering
- support for audio focus state in bluedroid

Bluetooth: Support for Avrcp 1.3 Controller

- support for SDP registration
- support for sending vendor dependant commands
- support for abs vol
- support for receiving vendor dependant response
- serialization of connection and rc_features callback

Avrcp_Ctrl: handling of commands and events for AVRCP Controller

- support of parsing cmd and event pdus
- timeout handling

Change-Id: I1e8d49b087eff6301373e1e90e8d868f15847c34
/system/bt/btif/src/btif_media_task.c
e04dbb3707806be965f5669d3213263c0178ef26 06-Jan-2016 Ajay Panicker <apanicke@google.com> A2DP task media alarm non-null protection

Prevent the alarm from being started multiple times.

Bug: 26277592
Change-Id: I764f93bab5490bf5f3942a1beb706457197d3ec1
/system/bt/btif/src/btif_media_task.c
47b4310e6aa9a508b47e6cd4631327c53b464440 19-May-2015 Abhijit Adsule <abhijit@motorola.com> A2DP SRC offload support

bluedroid changes to support A2DP SRC offload to BT FW.
add functionality to relay a2dp offload requests and responses
between AudioHAL & the BT vendor library.

Change-Id: Ie4e5992c48e95b0efb372a405e8537e4fd3ea071
Signed-off-by: Sridhar Vashist <svashist@motorola.com>
/system/bt/btif/src/btif_media_task.c
5f308397b7fe8a8da3f88b0f8910c3863ed1ec0b 15-Oct-2015 Sridhar Vashist <svashist@motorola.com> Make default SBC bitrate configurable by device.

Configurable default SBC bitrate so that audio quality can be maintained
for sampling rates other than 44.1kHz

Change-Id: Ia4197c0a500088cfa48a8ba821e9738a16c3fc6e
Signed-off-by: Sridhar Vashist <svashist@motorola.com>
/system/bt/btif/src/btif_media_task.c
6ff83ab9dd38bdefc5d252325f0cfbd3f1754d78 19-May-2015 Abhijit Adsule <abhijit@motorola.com> A2DP SRC offload support

bluedroid changes to support A2DP SRC offload to BT FW.
add functionality to relay a2dp offload requests and responses
between AudioHAL & the BT vendor library.

Change-Id: Ie4e5992c48e95b0efb372a405e8537e4fd3ea071
Signed-off-by: Sridhar Vashist <svashist@motorola.com>

Conflicts:
audio_a2dp_hw/audio_a2dp_hw.h
bta/Android.mk
bta/av/bta_av_aact.c
btif/include/btif_media.h
btif/src/btif_av.c
btif/src/btif_media_task.c
hci/Android.mk
hci/src/vendor.c
include/bt_target.h
stack/include/l2c_api.h
/system/bt/btif/src/btif_media_task.c
258c2538e3b62a8cdb403f2730c45d721e5292b4 28-Sep-2015 Pavlin Radoslavov <pavlin@google.com> GKI cleanup - moved GKI buffer allocation wrappers to OSI

* Moved the following GKI buffer allocation functions to OSI:
- GKI_getbuf() -> osi_getbuf()
- GKI_freebuf() -> osi_freebuf()
- GKI_get_buf_size() -> osi_get_buf_size()

For now we need the osi_getbuf() / osi_freebuf() allocation wrapper,
because we need to be able to call osi_get_buf_size() on the allocated
buffer.
In the future those should be replaced with osi_malloc() / osi_free().
Currently, the osi_malloc() buffer size internal allocation tracker
does not always track the size, hence we need the osi_getbuf() wrapper.

* Replaced GKI_MAX_BUF_SIZE with BT_DEFAULT_BUFFER_SIZE

* Added new file include/bt_common.h that can be usee to include
few files that should be included alost everywhere (e.g. bt_target.h"
NOTE: This file might be removed in the future and we should include
everywhere the right set of header files.

* Removed some of the GKI-related references

* Removed file include/gki_target.h

Change-Id: Ie87830e73143de200746d54235aa99f228a95024
/system/bt/btif/src/btif_media_task.c
1a3844f933bd63c8a381371dabfb35c6a0249e3e 25-Sep-2015 Pavlin Radoslavov <pavlin@google.com> GKI cleanup - Replaced usage of GKI queue with OSI fixed_queue

* Added new functions to OSI:
- fixed_queue_init()
- fixed_queue_length()
- fixed_queue_try_remove_from_queue()
- fixed_queue_try_peek_last()

* Renamed fixed_queue_try_peek() to fixed_queue_try_peek_first()

* Replaced usage of GKI queue functions with OSI fixed_queue functions:
- GKI_init_q() -> fixed_queue_new(SIZE_MAX)
NOTE: unlike GKI_init_q(), fixed_queue_new() allocates memory /
state that needs to be released by calling fixed_queue_free()
- GKI_enqueue() -> fixed_queue_enqueue()
- GKI_dequeue() -> fixed_queue_try_dequeue()
NOTE: fixed_queue_try_dequeue() is non-blocking
- GKI_queue_length() -> fixed_queue_length()
- GKI_queue_is_empty() -> fixed_queue_is_empty()
- GKI_getfirst() -> fixed_queue_try_peek_first()
- GKI_getlast() -> fixed_queue_try_peek_last()
- GKI_remove_from_queue() -> fixed_queue_try_remove_from_queue()
- Queue elements iteration.
In the fixed_queue implementation we have to use the underlying
list_t mechanism to iterate over the elements.
OLD:
p = GKI_getfirst(queue);
...
while ((p = GKI_getnext(p) != NULL) {
...
}
NEW:
list_t *list = fixed_queue_get_list(queue);
for (const list_node_t *node = list_begin(list);
node != list_end(list); node = list_next(node)) {
p = list_node(node);
}

* Remove initialization of the GKI module, because it is not needed
anymore

* Removed unused files in GKI:
gki/common/gki_common.h
gki/ulinux/gki_int.h
gki/ulinux/gki_ulinux.c

Change-Id: I3ff9464db75252d6faf7476a9ca67c88e535c51c
/system/bt/btif/src/btif_media_task.c
1eb1ea0cf2da992a3193506806e571dcbe3ec947 25-Sep-2015 Pavlin Radoslavov <pavlin@google.com> GKI cleanup - Moved functions GKI_disable() and GKI_enable() to OSI

Added new functions mutex_global_lock() and mutex_global_unlock()
within the OSI module, and replaced GKI_disable() and GKI_enable()
with those functions.

Also, minor cleanup in the gki.h header file.

Change-Id: I5f410e3174541224fcf30f37e1524ef099c25193
/system/bt/btif/src/btif_media_task.c
70ae7de9451e3dc074a048ba98b672a6ba3a4551 23-Sep-2015 Pavlin Radoslavov <pavlin@google.com> GKI cleanup - Remove GKI pool related defines

* Removed pool ID related defines
* Updated / renamed / cleanup buffer size related defines
* Added new #define BT_DEFAULT_BUFFER_SIZE
* Removed unused defines

Change-Id: Ib1fbf463d1e6fda2c71631347de0c365a37ba5ce
/system/bt/btif/src/btif_media_task.c
2e3d006b96eafb0651fe7f78d28250faf89405de 18-Sep-2015 Pavlin Radoslavov <pavlin@google.com> GKI cleanup - Eliminate usage of pool buffers

* Replace usage of function GKI_getpoolbuf() with GKI_getbuf()
* Remove usage of function GKI_poolutilization()
* Remove usage of function GKI_poolfreecount()

Change-Id: Ide938192b878bbfb4912642c903fce548f2b5368
/system/bt/btif/src/btif_media_task.c
61d666852fc7f4982d73c5d1ec3f2f512e0a02da 04-Aug-2015 Pavlin Radoslavov <pavlin@google.com> am caaa00f5: Fix a crash for a race condition during Bluetooth shutdown

* commit 'caaa00f5ede96461e11de866ac15f5224442d1eb':
Fix a crash for a race condition during Bluetooth shutdown
caaa00f5ede96461e11de866ac15f5224442d1eb 04-Aug-2015 Pavlin Radoslavov <pavlin@google.com> Fix a crash for a race condition during Bluetooth shutdown

This is same race condition observed in btif_media_task_aa_tx_flush_req()
because btif_media_task_aa_tx_flush_req() and btif_media_task_stop_aa_req()
are called back-to-bach.

This race condition is triggered when A2DP audio is streaming on shutdown:
"btif_a2dp_on_stopped() -> btif_media_task_stop_aa_req()" is called
to stop the particular audio stream, and this happens right after
the "cleanup() -> btif_a2dp_stop_media_task()" processing during
the shutdown of the Bluetooth stack.

Bug: 22700411
Change-Id: Ia0c98d44a108cf0f57731ac8129e4d76c9934542
/system/bt/btif/src/btif_media_task.c
ff6bf3f0797ad255352c6d2eb931e3a5d059bea3 24-Jul-2015 Andre Eisenbach <eisenbach@google.com> am 196413f5: Fix TX queue overflow detection

* commit '196413f5ca088ef97866092f02bb7571d2a44390':
Fix TX queue overflow detection
196413f5ca088ef97866092f02bb7571d2a44390 22-Jul-2015 Andre Eisenbach <eisenbach@google.com> Fix TX queue overflow detection

- Prevent possible endless loop if |nb_frame| is too high
- Remove off-by-one calculation before sending frames
- Remove log spam and add better debug info

Bug: 22658329
Change-Id: I374ee980aec48763beb49b4f6f8b076124cadf40
/system/bt/btif/src/btif_media_task.c
551714190f58ccfab196c9adc3ffe462ecf2280e 22-Jul-2015 Pavlin Radoslavov <pavlin@google.com> am 197ee685: Fix a crash for a race condition during Bluetooth shutdown

* commit '197ee6856b43d8eea137a7f37798ee2a012ce518':
Fix a crash for a race condition during Bluetooth shutdown
197ee6856b43d8eea137a7f37798ee2a012ce518 22-Jul-2015 Pavlin Radoslavov <pavlin@google.com> Fix a crash for a race condition during Bluetooth shutdown

This race condition is triggered when A2DP audio is streaming on shutdown:
"btif_a2dp_on_stopped() -> btif_media_task_aa_tx_flush_req()" is called
to stop the particular audio stream, and this happens right after
the "cleanup() -> btif_a2dp_stop_media_task()" processing during
the shutdown of the Bluetooth stack.

Bug: 22602117
Change-Id: I5de6a8f15b6a2771dde2e299a5b60554063696a2
/system/bt/btif/src/btif_media_task.c
9a78e8d25416325308fa700bb38459817eeb5c7a 08-Jul-2015 Marie Janssen <jamuraa@google.com> am 49120dc8: build: Fix LOG_TAG define breakage, macro usage

* commit '49120dc867c7818511b5afec461dfc97d17eef58':
build: Fix LOG_TAG define breakage, macro usage
49120dc867c7818511b5afec461dfc97d17eef58 08-Jul-2015 Marie Janssen <jamuraa@google.com> build: Fix LOG_TAG define breakage, macro usage

Fixes build breakages related to r.android.com/156982

Change-Id: Ib1143c41fe05a17c296226998afdb41a8cb6294a
/system/bt/btif/src/btif_media_task.c
d33e39f14834ddfcfad27b9bef5ffb87919a8644 07-Jul-2015 Marie Janssen <jamuraa@google.com> am db554581: build: Update osi log functions, use consistently

* commit 'db554581079863974af8e1289646f5deea6fc044':
build: Update osi log functions, use consistently
9c5d0727dd4cd09e44c032506c28ab4120ad3b88 27-Jul-2013 Anubhav Gupta <anubhavg@codeaurora.org> Override remote suspend flag on local play state changes

- Remote device may initiate AVDTP Suspend within 3s of AVRCP pause,
which sets remote suspend flag. Later on resumption of local playback
A2DP packets can not be processed further as Remote suspend flag
remains set. current change overrides remote suspend flag if local
suspend is triggered later.
- This change covers the usecase where play is pressed from DUT UI
before local suspend triggers in such scenarios current change takes
care of resetitng remote suspend flag on AVRCP play state change event.
- Moreover this change will drop A2DP packets when the setparameter
is called with A2dpSuspended=true and resumes when the mentioned parameter
is reset.

This change along with corresponding app change helps mitigating
issues reported due to A2Dp, HFP synchronizations and local and remote
device initiated AVDTP suspend handling.

Bug: 22028876
Change-Id: I3bb334373414170254744d9233cbd2e66219bfa0
/system/bt/btif/src/btif_media_task.c
db554581079863974af8e1289646f5deea6fc044 26-Jun-2015 Marie Janssen <jamuraa@google.com> build: Update osi log functions, use consistently

Update the LOG_* functions to take a tag argument which makes them more
consistent with the Android Log.*(TAG, s) common syntax and removes
some #define-dependency with osi/include/log.h.

Also update to never use Android log functions directly.

Also contains minor cleanup of some header includes.

Bug: 21569831
Change-Id: If07385cafbea062232ecdbc7c673f908d5ef8921
/system/bt/btif/src/btif_media_task.c
1f293a50abf0bd37d149604c674ae5a6dbab7750 01-May-2015 Nitin Arora <niarora@codeaurora.org> Stop media task alarm when task is exiting

Bug: 20717705
Change-Id: I76e76cf33d7c9f4366f921daf2230e4f681098f7
/system/bt/btif/src/btif_media_task.c
aea27ef29bd0be1d9faa5dcf94588107e9b6a51d 03-Apr-2015 Rakesh Iyer <rni@google.com> Fix build in BT AV_SINK.

Change-Id: Ie20165ee69597e3287283322d14773ac3699c323
/system/bt/btif/src/btif_media_task.c
e1a9e52ff59d36bd1bb5b7b3a02fafba6394edfe 31-Mar-2015 Etan Cohen <etancohen@google.com> Merge commit 'f7f839985b3931682363d2ef3b7c5cae55a842ee' into merge

Change-Id: Iaaec1ea0bf3009b7e32a9a60f697631a3f56e889
f8027005333c88a2f097cfd70d15c3d54c7764ae 12-Mar-2015 Chris Manton <cmanton@google.com> Demote, cleanup and extend observed logging
/system/bt/btif/src/btif_media_task.c
0f9b91e150e153229235c163861198e23600e636 12-Mar-2015 Sharvil Nanavati <sharvil@google.com> Use fully qualified path for OSI includes.
/system/bt/btif/src/btif_media_task.c
71864f490d4dc31857df0b31924cd62a337e9f1a 11-Mar-2015 Zach Johnson <zachoverflow@google.com> Add ability to set periodic alarms

Adds alarm_set_periodic so the alarm code can have more
contextual information when rescheduling alarms.

Problem: A2DP would stream for a few seconds and then
stop working.

Cause: The Java garbage collector. Bluedroid reaches out
to javaland to acquire and release the wake lock. Alarm was
always reaching out to get the wake lock when it scheduled a
short timeout. If GC kicked in during that call out to make
sure we have the wake lock, it could take more than 100ms to
get back us. That would screw over the alarm implementation
particularly for small 20ms timers.

So now if the wake lock was already acquired, we don't try to
reacquire it.

Cool. But we still have thrashing. Why? Because the alarm code
doesn't know the alarm is actually being used in a periodic way.

Here's what used to happen:

alarm expires
alarm is removed
reschedule
alarm callback is called
alarm callback sets the alarm again
alarm is added
reschedule

The problem is the first reschedule will get rid of the wake lock
if the next alarm is too far out or doesn't exist, meaning the next
reschedule needs to get the wake lock again.

With the extra periodicity information we can eliminate the
unnecessary intermediate reschedule, meaning no thrashing on the
wake lock. yay!
/system/bt/btif/src/btif_media_task.c
e13fbfafe2105d264357ac41133f0ac0e054429c 28-Dec-2014 Sharvil Nanavati <sharvil@google.com> Remove more GKI code.

This change removes all remaining GKI task remnants as well as
a few timer and buffer bits.
/system/bt/btif/src/btif_media_task.c
23e561a1f374557d6030b497337a1c96e9bb6aa4 03-Mar-2015 Sharvil Nanavati <sharvil@google.com> Remove dependency on GKI tasks from BTIF media task.

The previous code started a thread and posted a long-running function
to the thread's event loop. In essence, it created a thread and ran
a custom thread main that did its own event handling using GKI_wait.

The new code doesn't use GKI_wait or GKI_send_event at all. Instead,
it uses thread_post and the thread's reactor to enqueue and dispatch
events.
/system/bt/btif/src/btif_media_task.c
c0a87fe60f79ddf41595a30e75a77f43c19cd323 02-Mar-2015 Sharvil Nanavati <sharvil@google.com> Remove GKI timers
/system/bt/btif/src/btif_media_task.c
753173dee0b92efdbdc0eb4d44338cd1a84dbdb2 26-Sep-2014 Chris Manton <cmanton@google.com> Replace bt media GKI task with thread_t
/system/bt/btif/src/btif_media_task.c
8d9d02862b1e00d27681846e3de9c4cf4f6634fc 07-Sep-2014 Sharvil Nanavati <sharvil@google.com> GKI task entry points should have a consistent signature.

Previously, GKI task entry points had inconsistent signatures. For
example, we had:

int btif_media_task(void *p)
void btif_task(UINT32 params)
void btu_task (UINT32 param)

The single argument was universally ignored and the caller always
set it to 0. This change consolidates all of that and defines the
entry point as having 0 arity and no return value.
/system/bt/btif/src/btif_media_task.c
0d5de78354b5f7c819950fc5680a6cfd0052f78a 07-Sep-2014 Sharvil Nanavati <sharvil@google.com> Eliminate unused 'stack' concept for GKI tasks.

This change also fixes the type for task names: should be a const
string, not a mutable INT8*.
/system/bt/btif/src/btif_media_task.c
860a9af89f8dbf8ef65785d5db960c1fa488d2ba 27-Aug-2014 Chris Manton <cmanton@google.com> Replace mailboxes with fixed queues.

Also refactored btu_task a bit.
/system/bt/btif/src/btif_media_task.c
fe7216ca12f91baae733e7c93063db73121af308 06-May-2014 Chris Manton <cmanton@google.com> Enforce GKI API buffer usage

Also add another API GKI_queue_length(BUFFER_Q *)
/system/bt/btif/src/btif_media_task.c
fb17c122b09171492d99b208c1fdd6b76d2c431c 16-Jan-2015 Andre Eisenbach <eisenbach@google.com> am 335bc32b: Merge "Relax max PCM frames per tick a bit" into lmp-mr1-dev

* commit '335bc32bc7dae893358bde20557927e6ed6ad58c':
Relax max PCM frames per tick a bit
26e80aad86fae4e468a330d64ee02291f3a1980e 07-Jan-2015 Andre Eisenbach <eisenbach@google.com> Relax max PCM frames per tick a bit

Also made the value overwrite-able in bt_target.h.

Bug: 18913091
Change-Id: I64bbe453b35fdce6f127b3c23c0552b14d4ac49b
/system/bt/btif/src/btif_media_task.c
11cf5ccd5cd6dd1568bf69e4b6cbc27c95f5026d 11-Dec-2014 Chih-Hung Hsieh <chh@google.com> resolved conflicts for merge of ed0bdd42 to lmp-mr1-dev-plus-aosp

Change-Id: Ife8b72d3688ed78a95ccb8d5e0b60f40e7fec9e9
104e3f238f500cacdb8afaccdc672dfc34eae7ee 12-Nov-2014 Bernhard Rosenkränzer <Bernhard.Rosenkranzer@linaro.org> Cleanups needed to make clang happy

This patch removes a slew of unused variables and some unused functions,
fixes some incomplete initializations of structs and an sprintf
parameter mismatching the format string.

Change-Id: I35f22fdccc8350f885cd357d3685b869224fa433
Signed-off-by: Bernhard Rosenkränzer <Bernhard.Rosenkranzer@linaro.org>
/system/bt/btif/src/btif_media_task.c
c5916e97384f07ec5a2e061e6af24f70107c74a2 08-Nov-2014 Andre Eisenbach <eisenbach@google.com> Remove overflow rate limiting when reading A2DP frames

A2DP now supports adjusting the number of A2DP frames sent per timer
tick to adjust for timer drift and missed media task ticks. When the
signal to the headset/speakers becomes interrupted, the number of
packets to be read can queue up and rate limiting will not allow for the
queue to be cleared.

The overflow mechanism introduced in commit 4aebca4 will cause the media
task to stop sending packets completely, which can underflow the jutter
buffer on the remote device and lead to audio drop-outs.

This patch removes the overflow mechanism and also adds code do discard
audio frames that could not be sent to the remote device (weak signal
etc) to allow the device to stay in sync and not build up audio delays.

Also added additional debug logging and changed the UIPC flush mechanism
to address an issue where reading byte by byte causes an endless flush
loop if remote UIPC producer writes data faster than the flush loop
consumes it.

Bug: 18326405
Change-Id: I9a424984806bb2a464877399804b3355b2c439c3
/system/bt/btif/src/btif_media_task.c
01d102b3b187ab0d24050c1e12f96e6ee1ce50be 17-Oct-2014 Andre Eisenbach <eisenbach@google.com> 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
/system/bt/btif/src/btif_media_task.c
f061e74b81863771b174d1717a6165034dbad8e5 09-Oct-2014 Mattias Agren <magren@broadcom.com> Added missing A2DP priority on java alarm service

Running GKI timer engine via JAVA alarm service was causing severe
timer preemption at times which affects A2DP media task timer. This in
turn was stressing the compensation logic towards UIPC resulting in
very bursty reads of up to 40 UIPC frames at a time. This led to
instabilities on the UIPC pipe and trickled upwards in audio framework.
Inclusion of java alarm thread in A2DP high priority thread list results
in a much smoother data flow for entire A2DP data path and improved
audio quality.

Bug: 17520043
Change-Id: I7cea6ec64aa5b973b5fff767389a8827e681619e
/system/bt/btif/src/btif_media_task.c
ae13ec986e188d66eaad3c69bb916ea18c142fef 03-Sep-2014 Andre Eisenbach <eisenbach@google.com> Avoid race condition in SBC encoder initialization

In the A2DP media task, btif_a2dp_encoder_update() relies on the fact
that btif_a2dp_encoder_init() is called beforehand. Otherwise division
by zero errors will occur.

Since _init() called after the audio stream is opened, and _update() is
called in resonse the the audio stream being opened, a race condition
could ensue where _update() was called before open.

This patch changes the A2DP stream start sequence to ensure the SBC
encoder is initialized before the updated parameters are calculated.

Bug: 17339248
Change-Id: I6ed36a7fff0e4aa672a8866727030681eb4b3dfc
/system/bt/btif/src/btif_media_task.c
a391bf1d4f4250e27b6f157a1a8d2493c36934dc 09-Aug-2014 Andre Eisenbach <eisenbach@google.com> A2DP: Protect against division-by-zero error in bitpool calculation

If the encoder parameters have not been configured correctly before the
SBC encoder is initialized, a division-by-zero can occur resulting in a
SIGFPE.

Bug: 16902125
Change-Id: Ie4c6715b6b374a2d62fcfa0a1a99d40c689d0e2a
/system/bt/btif/src/btif_media_task.c
25067c0afc4d3ed95181b91801d3d638d9aa3f8f 22-Jul-2014 Andre Eisenbach <eisenbach@google.com> Fix integer overflow in GKI timer calculation

Fix an integer overflow in the GKI timer elapsed time calculation that
would cause Bluetooth Stereo Audio (A2DP) playback to stop suddenly
after a period of INT32_MAX microseconds (about 35 minutes) of
continuous uptime of the phone/tablet.

Bug: 16412377
Change-Id: I28cd3155a23444e41b26b3f3b8424cc2a3c5bf91
/system/bt/btif/src/btif_media_task.c
f13db8a534adf5281ee915c4b73b3141957ed17b 12-Jul-2014 Andre Eisenbach <eisenbach@google.com> Calculate A2DP frames to send based on elapsed time

This patch is aimed at improving A2DP audio quality by sending the
correct number of frames based on the actual time elapes between "ticks"
in order to account for timer drift.

Change-Id: If5b7cde90f5eb10b926ad247f51cff0eb60bbff7
/system/bt/btif/src/btif_media_task.c
0317a401142e927be82a0259f54cfa10a686e0fe 09-Jul-2014 Andre Eisenbach <eisenbach@google.com> Merge "Prevent A2DP bit pool calculation endless loops."
4e3593a9a1c596904a844286fbe704e969e7230e 08-Jul-2014 Andre Eisenbach <eisenbach@google.com> Prevent A2DP bit pool calculation endless loops.

This prevents log spam and endless loops in the A2DP bit pool
calculation. Protecting against the endless loop with prevent battery
draining issues and phone unresponsiveness.

This patch addresses the symptom. A separate patch will be submitted
once root cause is determined to address the problem.

Change-Id: I045b724c1c1638551b9333249f39eee109fa9ba1
/system/bt/btif/src/btif_media_task.c
6718c6d9fcfe373a679a529aca003d32062f81dc 02-Jul-2014 lungtsai_lin <lungtsai_lin@htc.com> Bluetooth: Rename BTA_AVK_INCLUDED flag to BTA_AV_SINK_INCLUDED (bt_target.h)

Now OEM could enable/disable A2DP SINK role

Change-Id: I62cf17b0397a86c5f886a2c1ca724ca77a7f9bd4
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
/system/bt/btif/src/btif_media_task.c
afa6e1abbedaad8fe854b0f43999b8aeb801af91 28-Jun-2014 Matthew Xie <mattx@google.com> resolved conflicts for merge of e8c3d75b to master

Change-Id: I78ef69c4d54a36243620ae14296d3507e3339567
8e50f047de2999e89b6a19ec9bf513017fcde3f9 28-Jun-2014 Matthew Xie <mattx@google.com> resolved conflicts for merge of 6449e497 to master

Change-Id: I01ef7ea6c4ce49c9d775b355fb5b082b25ffbc39
e8c3d75b75493911ebf0f99c83676359657178f7 04-May-2014 Sharvil Nanavati <sharvil@google.com> Logging cleanup: BTIF and APPL.

Change-Id: I5b1214642bbb4b9aecc0fd2c899a6ec2c9793286
/system/bt/btif/src/btif_media_task.c
3e8a242fcbeebea2857fa964ca48624d8433333e 23-May-2014 Mike Lockwood <lockwood@google.com> More work on A2DP Sink:

Output audio data through A2DP audio HAL rather than playing directly
to native AudioTrack API.

Add separate HAL interface for A2DP sink

Change-Id: I6c6cb6088c350e104b4a7354f328b29c7178e295
/system/bt/btif/src/btif_media_task.c
ce24765fe7620c34e8d88ed4f826c8a6917582b2 20-Mar-2014 Hemant Gupta <hemantg@codeaurora.org> SBC Decoder for A2DP SINK

Change-Id: Ic8d1dd81d1788324ec140fe0d1379dfff33deb54
/system/bt/btif/src/btif_media_task.c
f7dd9f5779680da37dc89e5df2b26d436487818c 24-Oct-2013 Hemant Gupta <hemantg@codeaurora.org> Add A2DP Sink Support

Change-Id: I9affefdd2d00597545e49c593ef3bddb110d4c9c
/system/bt/btif/src/btif_media_task.c
1a3006f317b1b493dde1b80c4debbcf1bf5f6727 04-May-2014 Sharvil Nanavati <sharvil@google.com> Eliminate dead code (helped by compiler warnings).

I've removed all functions that the compiler decided were unused.

Change-Id: I0cbddf874ebd1586abe29b80e8d6390680679542
/system/bt/btif/src/btif_media_task.c
e7c4f99f1ca3da0ac46aa7425a37b383177c699f 05-Sep-2013 Hemant Gupta <hemantg@codeaurora.org> Bluetooth: On Suspend ignore media task timer event

On Recieving Suspend confirmation from remote device,
Media task timer reload and tx_timer is made false,
hence media task will not be stopped at that instant.
Media task timer expires causing buffer to be allocated.
Changes done to ensure buffer is allocated only if tx_timer
is true.

Change-Id: I971a82cccc64ba033475ad532b096862968de942
/system/bt/btif/src/btif_media_task.c
309243751678f395e6f7323e45433e5476dc17ef 23-May-2014 Mike Lockwood <lockwood@google.com> More work on A2DP Sink:

Output audio data through A2DP audio HAL rather than playing directly
to native AudioTrack API.

Add separate HAL interface for A2DP sink

Change-Id: I6c6cb6088c350e104b4a7354f328b29c7178e295
/system/bt/btif/src/btif_media_task.c
8e08ad12eae66877f9725ca2d66fc69fe6762340 20-Mar-2014 Hemant Gupta <hemantg@codeaurora.org> SBC Decoder for A2DP SINK

Change-Id: Ic8d1dd81d1788324ec140fe0d1379dfff33deb54
/system/bt/btif/src/btif_media_task.c
cc35559160745c60b42ae182002a59337d844d09 24-Oct-2013 Hemant Gupta <hemantg@codeaurora.org> Add A2DP Sink Support

Change-Id: I9affefdd2d00597545e49c593ef3bddb110d4c9c
/system/bt/btif/src/btif_media_task.c
6449e497dfe4d500810c3e7b4d7d056027c33a0e 06-Jun-2014 Sharvil Nanavati <sharvil@google.com> Eliminate more dead code in GKI.

Change-Id: I4c0000445535e5300b83a18f5f6ca45f1ef797da
/system/bt/btif/src/btif_media_task.c
740def526e757f5ea8f30d9d28d1e7a668dadc42 04-May-2014 Sharvil Nanavati <sharvil@google.com> Eliminate dead code (helped by compiler warnings).

I've removed all functions that the compiler decided were unused.

Change-Id: I0cbddf874ebd1586abe29b80e8d6390680679542
/system/bt/btif/src/btif_media_task.c
7e4c60ce7757d935901f53d1f21ecc696aa89979 05-Sep-2013 Hemant Gupta <hemantg@codeaurora.org> Bluetooth: On Suspend ignore media task timer event

On Recieving Suspend confirmation from remote device,
Media task timer reload and tx_timer is made false,
hence media task will not be stopped at that instant.
Media task timer expires causing buffer to be allocated.
Changes done to ensure buffer is allocated only if tx_timer
is true.

Change-Id: I971a82cccc64ba033475ad532b096862968de942
/system/bt/btif/src/btif_media_task.c
54db2c249efa91082c5a167a924a527ec73ff38d 13-Apr-2014 Sharvil Nanavati <sharvil@google.com> Remove executable bit on source files.

Change-Id: Id456478aea626f57fed3479346e8fb4dbd0fafa6
/system/bt/btif/src/btif_media_task.c
d2ccbbb73c7851d2fa28dc212d2fffc0ad4e5d50 13-Apr-2014 Sharvil Nanavati <sharvil@google.com> Remove executable bit on source files.

Change-Id: Id456478aea626f57fed3479346e8fb4dbd0fafa6
/system/bt/btif/src/btif_media_task.c
5cd8bff2dd0337cb52bf48f312e3d2d55a8882fb 01-Feb-2014 Mike J. Chen <mjchen@google.com> Major warnings cleanup

Mostly fixing unused parameter warnings.
A few other warnings also fixed like possible use of
unitialized variables (no real issue found, just compiler couldn't
follow the path), signed vs unsigned warning.

Also fixed some typos, indent issues, removal of dead code, etc.

Change-Id: I95eb887aefc4d559d7921f71a0af5f3bfb01ac01
Signed-off-by: Mike J. Chen <mjchen@google.com>
/system/bt/btif/src/btif_media_task.c
4aebca4662c280fdc32e0ad3705cae064bfa068d 19-Sep-2013 Zhihai Xu <zhihaixu@google.com> implement flow control to avoid dropping packets in btif_media_task.

implment flow conrol to save CPU usage and avoid dropping
packet in btif_media_task when overflow and cpu preemption happen.
when the packet count in the queue is above high watermark, we will
stopping adding packets, when the packet count in the queue is below
low watermark, we will start adding packets again.

bug:8252054
Change-Id: I3b7795dffbe5f2ae455e239a0234533f6cbb4403
/system/bt/btif/src/btif_media_task.c
01c686ce0051433d75605ff9ca4c3b7388ce3b6b 16-Sep-2013 Zhihai Xu <zhihaixu@google.com> should return correct length and use shorter poll time for ad2p data

the default poll timeout(100ms) is too long for a2dp data read,
because the a2dp timer pertiod to read data is 20ms. The poll timeout
should be far less than a2dp timer pertiod. also when poll timeout happen
for read, we should return the data length which we already read instead of 0.

bug:8252054
Change-Id: Ifa8587c6b7d127cbbbff76d9e20b630303b6379f
/system/bt/btif/src/btif_media_task.c
379743beded881127703334e1dda2cd327ec651d 29-Sep-2013 Zhihai Xu <zhihaixu@google.com> Failure to start playback on A2DP sink after connection

This is what happen:
after Headset is connected, we call start_audio_datapath which will send AVDTP_Start command to Headset,
Headset reject it with bad state. Bluedroid stack will ack failure to start_audio_datapath.
The next time we write audio data to bluetooth, we will call start_audio_datapath again to send AVDTP_Start command to Headset
Headset reject it with bad state again. Bluedroid stack will ack failure to start_audio_datapath.
When the third time we call start_audio_datapath, right at that time we receive AVDTP_Start command from Headset.
Handle AVDTP_Start command and Handle start_audio_datapath are in two different threads.
Handle AVDTP_Start command is in btu_task thread.
Handle start_audio_datapath() is in btif_task thread.
We have race condition in this case
Because when btif_task processed BTIF_AV_START_STREAM_REQ_EVT(triggered by start_audio_datapath),
it don't know we receive AVDTP_Start command which is processed in btu_task.
btif_task will send a message BTA_AV_API_START_EVT to btu_task, which will be handled by bta_av_do_start.
AVDTP_start command from headset is handled by bta_av_start_ok.
bta_av_start_ok will send BTA_AV_START_EVT with suspending true to btif_task and send AVDTP_Suspend command
to headset to suspend the AVDTP for reconfiguration purpose.

in bta_av_do_start, we will check whether the AVDTP is already started, we will know the AVDTP is already start at this time because
bta_av_do_start is also running in btu_task. We will send BTA_AV_START_EVT with success to btif_task.

In the btif_task, BTA_AV_START_EVT will be processed by btif_av_state_opened_handler:
For the first BTA_AV_START_EVT with suspending true sent by bta_av_start_ok, it will ignore it:
if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE))
return TRUE;
For the second BTA_AV_START_EVT with success sent by bta_av_do_start , it will ack success to start_audio_datapath, and change to
BTIF_AV_STATE_STARTED/BTAV_AUDIO_STATE_STARTED, after receive success ack from bluedroid stack, we will start send Audio data to bluetooth.

At last we received AVDTP_Suspend response accept from Headset, we will send BTA_AV_SUSPEND_EVT to btif_task, which will be
handled by btif_av_state_started_handler. It will call btif_a2dp_on_suspended and call audio_state_cb with new audio state
BTAV_AUDIO_STATE_STOPPED.
so The state between bluedroid stack and audio data path is out of sync.
The fix is to send failure message if we know we suspend AVDTP in bta_av_do_start,
also make sure we won't miss acknowledgement for pending start if we exit opened state,
to avoid audio data path dead lock.

bug:10953908
Change-Id: I1704839977324b7c4e234eb843cddf3719e10d2c
/system/bt/btif/src/btif_media_task.c
b8ceaa484a09be14263d5f10d022a272f9602378 05-Apr-2013 Mattias Agren <magren@broadcom.com> Set default a2dp sbc encoding quality to high

* Increased bitpool to high quality setting (53). * Added rate quality
reduction to medium quality for basic rate connections * Enhanced
a2dp frame calculation ratio to smooth out frame distrubution * Removed
iop scaling patch.

Bug 8252054

Change-Id: I20725d0decfe5f820e1c03407889b6272e830aca
/system/bt/btif/src/btif_media_task.c
5fd74f06caab4324d0ba69df86ad5170c072ec64 05-Apr-2013 Mattias Agren <magren@broadcom.com> Stability fixes for a2dp hal control path

Ensure av statemachine is preventing a2dp hal to restart the stream
when not ready. This prevents ending up in a scenario where a2dp hal
locks up. Code cleanup.
bug 7002859

Change-Id: I3f3eeaab4ca185733b8b0042ed2cfa701f76a203
/system/bt/btif/src/btif_media_task.c
45f5f9077c773b9d4533fef13045b5ff77e32e46 08-Feb-2013 Ganesh Ganapathi Batta <ganeshg@broadcom.com> Resolved partial uipc channel read issue

When partial data is read the previously read size wasn't
compensated for. Ensure we don't transmit empty a2dp frames in case
of underrun
Bug 8026551

Change-Id: I4195ed798008378b93343bf7cd266c6e2f11b094
/system/bt/btif/src/btif_media_task.c
5738f83aeb59361a0a2eda2460113f6dc9194271 13-Dec-2012 The Android Open Source Project <initial-contribution@android.com> Snapshot cdeccf6fdd8c2d494ea2867cb37a025bf8879baf

Change-Id: Ia2de32ccb97a9641462c72363b0a8c4288f4f36d
/system/bt/btif/src/btif_media_task.c