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
49 files changed
tree: b631dacd6e8b1a054085b73c1ebfd43fc3ffadf6
  1. audio_a2dp_hw/
  2. bta/
  3. btcore/
  4. btif/
  5. build/
  6. conf/
  7. device/
  8. doc/
  9. embdrv/
  10. hci/
  11. include/
  12. main/
  13. osi/
  14. service/
  15. stack/
  16. test/
  17. tools/
  18. udrv/
  19. utils/
  20. vendor_libs/
  21. vnd/
  22. .clang-format
  23. .gitignore
  24. .gn
  25. Android.mk
  26. BUILD.gn
  27. CleanSpec.mk
  28. EventLogTags.logtags
  29. MODULE_LICENSE_APACHE2
  30. NOTICE
  31. OWNERS
  32. PREUPLOAD.cfg
  33. README.md
README.md

Fluoride Bluetooth stack

Building and running on AOSP

Just build AOSP - Fluoride is there by default.

Building and running on Linux

Instructions for Ubuntu, tested on 14.04 with Clang 3.5.0 and 16.10 with Clang 3.8.0

Download source

mkdir ~/fluoride
cd ~/fluoride
git clone https://android.googlesource.com/platform/system/bt

Install dependencies (require sudo access):

cd ~/fluoride/bt
build/install_deps.sh

Then fetch third party dependencies:

cd ~/fluoride/bt
mkdir third_party
cd third_party
git clone https://github.com/google/googletest.git
git clone https://android.googlesource.com/platform/external/libchrome
git clone https://android.googlesource.com/platform/external/modp_b64
git clone https://android.googlesource.com/platform/external/tinyxml2
git clone https://android.googlesource.com/platform/hardware/libhardware

And third party dependencies of third party dependencies:

cd fluoride/bt/third_party/libchrome/base/third_party
mkdir valgrind
cd valgrind
curl https://chromium.googlesource.com/chromium/src/base/+/master/third_party/valgrind/valgrind.h?format=TEXT | base64 -d > valgrind.h
curl https://chromium.googlesource.com/chromium/src/base/+/master/third_party/valgrind/memcheck.h?format=TEXT | base64 -d > memcheck.h

NOTE: If system/bt is checked out under AOSP, then create symbolic links instead of downloading sources

cd system/bt
mkdir third_party
cd third_party
ln -s ../../../external/libchrome libchrome
ln -s ../../../external/modp_b64 modp_b64
ln -s ../../../external/tinyxml2 tinyxml2
ln -s ../../../hardware/libhardware libhardware
ln -s ../../../external/googletest googletest

Generate your build files

cd ~/fluoride/bt
gn gen out/Default

Build

cd ~/fluoride/bt
ninja -C out/Default all

This will build all targets (the shared library, executables, tests, etc) and put them in out/Default. To build an individual target, replace "all" with the target of your choice, e.g. ninja -C out/Default net_test_osi.

Run

cd ~/fluoride/bt/out/Default
LD_LIBRARY_PATH=./ ./bluetoothtbd -create-ipc-socket=fluoride

Eclipse IDE Support

  1. Follows the Chromium project Eclipse Setup Instructions until "Optional: Building inside Eclipse" section (don't do that section, we will set it up differently)

  2. Generate Eclipse settings:

cd system/bt
gn gen --ide=eclipse out/Default
  1. In Eclipse, do File->Import->C/C++->C/C++ Project Settings, choose the XML location under system/bt/out/Default

  2. Right click on the project. Go to Preferences->C/C++ Build->Builder Settings. Uncheck "Use default build command", but instead using "ninja -C out/Default"

  3. Goto Behaviour tab, change clean command to "-t clean"