History log of /system/bt/stack/avdt/avdt_ccb.cc
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
1e71c20b14e69adae973fba405d53eb1bde556e2 18-May-2018 Pavlin Radoslavov <pavlin@google.com> Don't mix internal AVDTP state when connecting to two devices

There is a race condition when connecting to two devices, and
the connection to one of the devices is not powered on.

Because of the race condition, the wrong tBTA_AV_LCB entry inside
bta_av_sig_chg() might be allocated for the connection to
the device that is powered on. As a result of that, when
the connection attempt to the powered off device times out,
we will use the wrong bta_handle to close the existing AVDTP connection to
the device that is connected.

Also:
- Add a new function BTA_AvObtainPeerChannelIndex() to select the
appropriate AvdtpCcb entry if there an outgoing connection request
while an incoming connection is received.
- Added/updated log messages to help debugging similar issues in the future
- Removed unnecessary SetActivePeer() call inside the BtifAv state
machine for A2DP Source to avoid additional internal/transient glitches

Test: Manual
Bug: 79697137
Change-Id: Ie55e3dcf6c6a15637ce3631f2828548a2423d881
Merged-In: Ie55e3dcf6c6a15637ce3631f2828548a2423d881
(cherry picked from commit 1e2cab39a42542f12862df1cd47bf6d90853138b)
/system/bt/stack/avdt/avdt_ccb.cc
c7242818d4180dec4eae2e75f9fb91f7f6a160aa 25-Nov-2017 Pavlin Radoslavov <pavlin@google.com> Add support for Multi-A2DP state machines per device

* Reimplement most of the BTIF AV state machinery in C++
- Separate the BTIF AV Source from BTIF AV Sink state:
btif_av_source and btif_av_sink
- Remove the single btif_av_cb control block instance
- Add C++ based BtifStateMachine and remove the older C-based
btif_sm state machine
- Introduce C++ class BtifAvPeer to keep state per peer, and use
a single state machine instance per peer
- Update BTA_AvStart() and BTA_AvStop() to take tBTA_AV_HNDL handle
argument
- Register the BTA handles when enabling the Source/Sink service.
This needs to be done in advance during service startup, otherwise
a connection to a remote device will fail.
- Move local event_handler functions inside C++ ProcessEvent methods,
and pocess the BTIF, BTA AV and BTA AVRCP events per state machine
instance
- Cleanup callbacks and use do_in_jni_thread() to schedule the processing
- Add BTIF AV API that needs to be called by the AVRCP module for certain
AVRCP events: btif_av_avrcp_event_open(), btif_av_avrcp_event_close()
btif_av_avrcp_event_remote_play()
- Add a mechanism to set the active device
- Add BluetoothDevice argument to the codec-related internal Binder
APIs: getCodecStatus(), enableOptionalCodecs(),
disableOptionalCodecs(), setCodecConfigPreference()
- Rename btif_av_move_idle() to btif_av_acl_disconnected() and
refactor the processing to happen within each state machine on the
correct thread.
- Process cleanup_src and cleanup_sink on the JNI thread
- Add a mechanism to track the maximum number of connected devices.
- Add unit tests for the new BtifStateMachine class

* Redesign some of the AVDTP internals so it can handle multiple connected
devices
- Change some of the AVDTP struct entries to C++ classes.
This simplifies significantly the design fixes
- Reorganize the AvdtpScb entries: for each connection the
corresponding SEP entries are within the corresponding AvdtpCcb entry.
- Pass peer address as argument to the API functions inside bta_av_co.cc,
and update the peer address inside the corresponding peer entry in
bta_av_co.cc
- Add various log mesages
- Store precomputed BTA AV SCB index in the AvdtpCcb entry and use it as
appropriate.
- Fix the TCID computation and handling for the AvdtpAdaptationLayer
- Fix the computed value for AVDT_NUM_RT_TBL
- Remove video-related code inside AVDTP
- Refactor/cleanup hard-coded callbacks that depend on the BTA_AV_NUM_STRS
value.
- Update various #define values to support a larger number of connected
devices:
- Maximum number of streams:
BTA_AV_NUM_STRS: 2 -> 6
- BT_RC_NUM_APP: 1 -> 12 (AVRCP-related - 2 * MaxDevices)
- MAX_L2CAP_LINKS: 7 -> 13
- MAX_L2CAP_CHANNELS: 16 -> 32
- AVDT_NUM_LINKS: 2 -> 6
- AVDT_NUM_SEPS: (6 * AVDT_NUM_LINKS) -> 6
Now the value is used for the maximum number of SEPs per device
- AVDT_NUM_TC_TBL: 6 -> (AVDT_NUM_SEPS + AVDT_NUM_LINKS)
- AVCT_NUM_LINKS: 2 -> 6
- AVCT_NUM_CONN: 3 -> 14 (2 * MaxDevices + 2)

Also:
- Update the JNI codec-related calls to use const reference
instead of a pointer
- Update the implementation of bta_av_chk_2nd_start() so it is aligned
with bta_av_chk_start() and cleaned up both functions.
- Rename btif_dispatch_sm_event() to btif_av_dispatch_sm_event() and
btif_report_source_codec_state() to btif_av_report_source_codec_state()
for consistency with the rest of the BTIF AV API.
- Add new function btif_rc_is_connected_peer() and remove
btif_rc_get_connected_peer()
- Add new AVRCP header file btif/include/btif_rc.h
and move the AVRCP "extern" declarations from btif_av.cc there.
- Rename btif_av_execute_service() to btif_av_source_execute_service()
- Cleanup the btif_av.h API descriptions
- Print the BTIF AV state in the "dumpsys bluetooth_manager" output
- Print the BTA AV state in the "dumpsys bluetooth_manager" output
- Print the AVDTP state in the "dumpsys bluetooth_manager" output
- Refactor btif_a2dp_source_cb into a class with internal state.
- Refactor A2DP Source worker thread handling and replace it with
libchrome message handler
- Refactor BtaAvCo component (bta_av_co.cc)
- C++ classes and state
- Rename bta_av_co_audio_src_data_path to
bta_av_co_audio_source_data_path
- Remove most BTA_AV_CO_CP_SCMS_T checks
- Replace mutex_global_lock() usage with local mutex
- Keep codec-specific state per peer
- Keep state about the active peer - the first connected peer is the
default active peer
- Report source codec state only for valid peers; i.e., don't report
source codec state for empty RawAddress
- Keep the contect_protect_active flag per peer
- Print the BTA AV CO state in the dumpsys bluetooth_manager" output
- Misc cleanup in BTA AV
- Add ToString() method to struct btav_a2dp_codec_config_t
- Additional cleanup

Bug: 70350399
Test: Manual and unit tests
Change-Id: Icecd7fd44a222d939b63a7473a2239ae0679f08c
/system/bt/stack/avdt/avdt_ccb.cc
5b790feeeb211c42bf78ca3ae9c26aa30e516765 18-Sep-2017 Jakub Pawlowski <jpawlowski@google.com> Make copyright headers consistent with Google template; remove "(C)"

Test: Comment changes only; still compiles...
Change-Id: Id699a8170112f06e4a2c9f2e0f0834d1817ace4e
/system/bt/stack/avdt/avdt_ccb.cc
13d04d9813c740dd2e8c621cc64c589088268155 04-Oct-2017 Myles Watson <mylesgw@google.com> stack: Remove casts and spell local_keys correctly

Test: build
Change-Id: Ide6ec9528e1f8efca9850eab53aa2bdb88ba363d
/system/bt/stack/avdt/avdt_ccb.cc
8da87bea5e021e47f5ab3795513eee7a3c9df3d9 02-Aug-2017 Pavlin Radoslavov <pavlin@google.com> Don't reuse AVDTP internal state for different purposes

A number of issues were exposed by carkits that proactively try
to discover the codecs supported by the Phone and explicitly select
the A2DP codec.

* Don't reuse p_scb->p_cap for storing the most recent fetched capability
and for storing the result configuration while reconfiguring the stream.
Instead, use p_scb->cfg for storing the result configuration.
* Don't try to reconfigure the audio stream before all peer's capabilities
have been retrieved.
* Don't reset p_scb->sep_info_idx after fetching all capabilities inside
bta_av_save_caps(), otherwise the stream reconfiguration logic is
confused. Apparently, p_scb->sep_info_idx is overused for both:
(a) Pointing where to store the next capability while fetching the
capabilities.
(b) Storing the selected the SEP after the codec selection is completed.
Resetting p_scb->sep_info_idx to 0 creates logical confusion when the
actual selected SEP index is 0.
* Add extra debug log messages

Test: Connecting to and streaming with various carkits
Bug: 64128712
Change-Id: I5f57e9069d5402bcbb17613470ac0d29c8e45069
(cherry picked from commit c64dc1d28496b5e917d0f82317d40d3c60e6495d)
/system/bt/stack/avdt/avdt_ccb.cc
a484a888196ddf8bcbf1ad3226d6451bc735a94b 25-Jun-2017 Jakub Pawlowski <jpawlowski@google.com> Rename bt_bdaddr_t into RawAddress (3/3)

Test: compilation test
Change-Id: I4571721a0c6165a66450ee157a53d8d15bfc45d0
/system/bt/stack/avdt/avdt_ccb.cc
903c16685e62e7721d44460b9171e020f38609f5 14-Jun-2017 Jakub Pawlowski <jpawlowski@google.com> Use bt_bdaddr_t instead of BD_ADDR in AVDT related code

Test: compilation test
Change-Id: Ibdfd79972d2270303cf1d2e0da26b23d8d5d62d5
/system/bt/stack/avdt/avdt_ccb.cc
5ce0116fbf5b530d5b93f11312096eade1021c1e 05-Dec-2016 Pavlin Radoslavov <pavlin@google.com> Add a mechanism for configuring the A2DP Source codecs

* Codec config internal abstraction:
- Add new classes A2dpCodecConfig and A2dpCodecs that (will)
encapsulate all codec-related APIs
- Add unit tests for the above two classes
- Add method A2dpCodecConfig.buildCodecConfig(), and use it when
creating the codec configuration instead of A2DP_InitSource2SinkCodec().
The new method can build the codec config by taking into account
optional user codec-related configuration preferences.
- Use the A2DP codec config API from the hardware/libhardware bt_av.h API
- Replace enum tA2DP_CODEC_SEP_INDEX with btav_a2dp_codec_index_t
from the bt_av.h API
- Move codec-specific functions from stack/include/a2dp_api.h
and stack/a2dp/a2dp_api.cc to stack/include/a2dp_codec_api.h
and stack/a2dp/a2dp_codec_config.cc
- Create a new base class A2dpCodecConfig() to hold some of the
codec-related state, and implement the corresponding A2dpCodecConfigSbc
and A2dpCodecConfigSbcSink derived classes.
- Move A2DP spec-related constants from stack/include/a2dp_api.h
to stack/include/a2dp_constants.h
- Move A2DP-related error codes from stack/include/a2dp_api.h
to stack/include/a2dp_error_codes.h
- Move A2DP SBC spec-related constants from stack/include/a2dp_sbc.h to
stack/include/a2dp_sbc_constants.h

* Implement the backend mechanism for handling user (re)configuration of
A2DP Source codecs as requested via the JNI API calls.
Also, any codec changes are reported back via JNI API callbacks.
The current audio parameter selection (sample rate, bits per
sample, channel mode - mono/stereo) is as follows:
- If the user selected parameters are acceptable (based on
local codec capability and the remote Sink capability),
those parameters are used.
- Else if the Audio HAL's requested parameters are acceptable,
those are used.
- Else if the default settings are acceptable, those are used.
- Else use the best match among the local and the remote device's
capabilities.

* Update the mechanism for handling OTA configuration requests from the
remote Sink device.
- The OTA prefered codec configuration is ignored if the current
codec configuration contains explicit user configuration, or if the
codec configuration for the same codec contains explicit user
configuration.

* Refactor the Audio HAL <-> Bluetooth audio parameter negotiation
mechanism:
The new mechanism gives some flexibility to the Media Framework to
choose the appropriate audio format (sample rate, bits per sample,
and channel mode - mono/stereo), and at the same time allows
the Bluetooth stack to double-check / overwrite the choice.
- out_get_parameters() on the Audio HAL side asks the Bluetooth stack
for all currently supported formats (for the current codec),
and returns them to the Media Framework: sample rate, bits per sample,
and channel mode (mono/stereo).
- The first time adev_open_output_stream() is called on the Audio HAL,
it asks the Bluetooth stack about the audio format currently selected
by the Bluetooth stack (based on codec negotiation with the Sink device,
and User Configuration).
- The second time adev_open_output_stream() is called on the Audio HAL,
its "config" will eventually contain the audio format selected
internally by the Media Framework. That audio format is sent to the
Bluetooth stack.
If that format is acceptable to the Bluetooth stack, the Bluetooth
stack will reconfigure itself internally, and will respond back with
those values. Otherwise, it will respond back with the values that
should be used instead.

* Misc other fixes and refactoring:
- Fix the BTA handling of A2DP codec reconfiguration
- Fix a bug in the implementation of A2DP_BitsSet(), and add the
approriate unit test. Also, fix the code that was using this function
incorrectly.
- The SBC encoder is compiled as a separate library
- Replace leftover usage of "false" with "FALSE" for macros, and
vice-versa for variable values.

Test: A2DP streaming to headsets, TestPlans/71390
Bug: 30958229
Change-Id: I440b6126e2250e33b0075f9789dd93154c007c2b
/system/bt/stack/avdt/avdt_ccb.cc
911d1ae03efec2d54c3b1b605589d790d1745488 29-Nov-2016 Myles Watson <mylesgw@google.com> Apply clang-format to the rest of the tree

find * | grep "\.[ch]" | xargs clang-format --style=file -i

Test: mma -j32
Change-Id: I6fcc9862bb7bc07c2a367ca58fef2b3cd27a6f05
/system/bt/stack/avdt/avdt_ccb.cc
9ca07091a1f07ea201cee0504dab6a1d7073d429 29-Nov-2016 Myles Watson <mylesgw@google.com> Reformat long comments before clang-format

Test: mma -j32
Change-Id: I86a2a4af9dcd22d675ca1f764bb2c9623d63edcc
/system/bt/stack/avdt/avdt_ccb.cc
ee96a3c60fca590d38025925c072d264e06493c4 23-Nov-2016 Myles Watson <mylesgw@google.com> Fix asterisks in block quotes

Remove double asterisks from block quotes.

git grep -lP '^[*][*]' | xargs sed 's/^[*][*]/ \*/' -i

Fix asterisk line lengths

git grep -l '^[ /][*]\{79,\}[*/]' | \
xargs sed -i s,"^\([ /]\)[*]\([*]\{78\}\)[*]*\([*/]\)","\1\2\3",

Test: mma -j32
Change-Id: Ie3fd375ac2f804cb0f53bf1314a005e85973b3d7
/system/bt/stack/avdt/avdt_ccb.cc
f33b6f434f086b20fabe5913016bc423ac975057 23-Nov-2016 Marie Janssen <jamuraa@google.com> readability fix: No assigns in if conditionals

Coccinelle-assisted:
@@
variable i;
expression E;
statement S1, S2;
@@

+ i = E;
if (
(
- (i = E)
+ i
!= ...
|
- (i = E)
+ i
== ...
|
- (i = E)
+ i
< ...
|
- (i = E)
+ i
> ...
|
- (i = E)
+ i
<= ...
|
- (i = E)
+ i
>= ...
|
- (i = E)
+ i
)
) S1 else S2

for file in $(find . -name "*.cc"); do
spatch --sp no-if-assigns.cocci --in-place $file
done

clang-format --style=file -i bta/**/*.cc

Test: mma -j37 and basic sanity testing on angler, sailfish

Change-Id: I41a2964afac347c24e13869b6c172e321e646091
/system/bt/stack/avdt/avdt_ccb.cc
d7ffd64accbd50a27289a388856e56244ccbb5da 27-Oct-2016 Myles Watson <mylesgw@google.com> Remove deprecated UNUSED macro (5/5)

Include osi.h for UNUSED_ATTR.

Test: mma -j32

Change-Id: I43260669dc1f54639e46cc9620093d727ee86276
/system/bt/stack/avdt/avdt_ccb.cc
d35a648d39710bbc5ac59f8add85166455af5af7 27-Oct-2016 Myles Watson <mylesgw@google.com> Remove deprecated UNUSED macro (1/5)

Generated automatically with coccinelle

/* This rule matches functions with arguments
* that have an UNUSED(arg) in the body.
*/
@r1@
identifier arg;
identifier fn;
type t;
parameter list[n] P;
@@

fn(P, const t arg) { ...
UNUSED(arg);
...
}

/* This rule removes the UNUSED line, and adds
* UNUSED_ATTR to the parameter list.
*/
@depends on r1@
identifier r1.arg;
identifier r1.fn;
type r1.t;
parameter list[r1.n] r1.P;
typedef UNUSED_ATTR;
@@

fn(P,
- const t arg
+ UNUSED_ATTR GETRIDOFTHISCOMMA, const t arg
) { ...
-UNUSED(arg);
...
}

Test: mma -j32

Change-Id: Idcaadd688d669d484e557becd050e69454508f3c
/system/bt/stack/avdt/avdt_ccb.cc
b2a292b5d8df2f359c38b0787bc01181225a9bc9 15-Oct-2016 Pavlin Radoslavov <pavlin@google.com> Renamed most C files to C++: *.c to *.cc

Also:
- Fixed C++ related compilation errors.
- Added missing 'extern "C"' guards in some of the header files.
- Added missing LOCAL_CPP_EXTENSION to Android.mk files.
- Added-back btif/src/btif_mce.cc and bta/mce/bta_mce_* to
btif/Android.mk and bta/Android.mk respectively.
- Fixed the alphabetical ordering of the *.cc files in some
of the Android.mk files.
- Added missing Copyright header to "osi/include/list.h"
- Updated "osi/src/wakelock.cc" to use C++ std::string
instead of dynamic allocation of C-style strings.

Test: code compilation, unit tests, and A2DP streaming
Change-Id: Ia2f7215ed9df32775c701b68fc86b09875b942c7
/system/bt/stack/avdt/avdt_ccb.cc