1. 26 Apr, 2020 15 commits
  2. 17 Apr, 2020 1 commit
  3. 15 Apr, 2020 6 commits
    • pali's avatar
      bluetooth: Add more variants of SBC codec · 8c1a6eec
      pali authored
      Specify configuration for Low, Middle, High and eXtreme Quality of SBC
      codec. SBC codec in eXtreme Quality has higher quality than aptX.
      
      Automatic Quality mode matches configuration of SBC codec which was used
      before this change. Which means that it accept configuration between Low
      and High quality.
      
      Current SBC code was extended to allow definitions of arbitrary
      configuration variants of SBC codec parameters.
      
      SBC XQ testing is in following article:
      http://soundexpert.org/articles/-/blogs/audio-quality-of-sbc-xq-bluetooth-audio-codec
      8c1a6eec
    • pali's avatar
      bluetooth: Add A2DP FastStream codec support · 3f3d3a0f
      pali authored
      This patch provides support for FastStream codec in bluetooth A2DP profile.
      FastStream codec is bi-directional, which means that it supports both music
      playback and microphone voice at the same time.
      
      FastStream codec is just SBC codec with fixed parameters. For playback are
      used following parameters: 48.0kHz or 44.1kHz, Blocks 16, Sub-bands 8,
      Joint Stereo, Loudness, Bitpool = 29 (data rate = 212kbps, packet size =
      (71+1)*3 <= DM5 = 220, with 3 SBC frames). SBC frame size is 71 bytes, but
      FastStream is zero-padded to the even size (72). For microphone are used
      following SBC parameters: 16kHz, Mono, Blocks 16, Sub-bands 8, Loudness,
      Bitpool = 32 (data rate = 72kbps, packet size = 72*3 <= DM5 = 220, with
      3 SBC frames).
      
      So FastStream codec is equivalent to SBC in Low Quality settings. But the
      main benefit of FastStream codec is support for microphone voice channel
      for audio calls. Compared to bluetooth HSP profile (with CVSD codec), it
      provides better audio quality for both playback and recording.
      3f3d3a0f
    • pali's avatar
      bluetooth: Add A2DP aptX and aptX HD codecs support · 09e87210
      pali authored
      This patch provides support for aptX and aptX HD codecs in bluetooth A2DP
      profile. It uses open source LGPLv2.1+ licensed libopenaptx library which
      can be found at https://github.com/pali/libopenaptx.
      
      aptX for s24 stereo samples provides fixed 6:1 compression ratio and
      bitrate 352.8 kbit/s, aptX HD provides fixed 4:1 compression ratio and
      bitrate 529.2 kbit/s.
      
      According to soundexpert research, aptX codec used in bluetooth A2DP is no
      better than SBC High Quality settings. And you cannot hear difference
      between aptX and SBC High Quality, aptX is just a copper-less overpriced
      audio cable.
      
      aptX HD is high-bitrate version of aptX. It has clearly noticeable increase
      in sound quality (not dramatic though taking into account the increase in
      bitrate).
      
      http://soundexpert.org/news/-/blogs/audio-quality-of-bluetooth-aptx
      09e87210
    • pali's avatar
      bluetooth: policy: Treat bi-directional A2DP profiles as suitable for VOIP · 0123c32a
      pali authored
      Previously module-bluetooth-policy was switching from A2DP to HSP profile
      when VOIP application started recording of source. Now it switch to profile
      with the highest priority which has both sink and source. In most cases it
      is HSP profile, but it can be also bi-directional A2DP profile (e.g.
      FastStream codec) as it has better audio quality.
      0123c32a
    • pali's avatar
      bluetooth: Set initial A2DP profile which bluez already activated · 878401d9
      pali authored
      Bluez and remote device decide which A2DP codec would use. Use this
      selected A2DP codec as initial profile in pulseaudio.
      
      In most cases it is either last used codec or codec with higher priority by
      defined by remote device.
      
      To detect which A2DP profile was activated by bluez, look at bluez
      transport state.
      878401d9
    • pali's avatar
      bluetooth: Implement A2DP codec switching and backchannel support · efef94a8
      pali authored
      Some A2DP codecs (like FastStream or aptX Low Latency) are bi-directional
      and can be used for both music playback and audio calls. This patch
      implements usage of backchannel if A2DP codec provided by pulseaudio API
      supports it.
      
      A2DP codec switching needs new version of bluez as older version does not
      provide needed org.freedesktop.DBus.ObjectManager and RegisterApplication
      DBus APIs.
      
      Pulseaudio use for each A2DP codec separate pulseaudio profile, therefore
      codec switching is implemented via changing pulseaudio profile and
      currently used A2DP codec is visible in pulseaudio profile.
      
      Getting list of supported codecs by remote device is supported only by new
      version of bluez daemon.
      
      If old bluez version is detected then only one SBC codec is supported.
      efef94a8
  4. 14 Apr, 2020 4 commits
    • pali's avatar
      bluetooth: policy: Reflect a2dp profile names · 6f25f0ee
      pali authored
      In next patches, codec name is appended end the end of a2dp profile names.
      6f25f0ee
    • pali's avatar
      bluetooth: Change codec API for choosing remote endpoint · d055e4b5
      pali authored
      Current codec API for choosing remote endpoint was not suitable for
      implementing fallback to another endpoint when first chosen one was not
      possible to establish.
      
      To overcome this problem change codec API to rather provide generic method
      for comparing two endpoints by their capabilities. Return value is standard
      value what comparator function returns (-1, 0, 1). It can be used e.g. for
      searching the best remote endpoint (like did previous API method) or
      creating a full list of all endpoints in preferred order (e.g. by sorting
      function).
      
      Currently this method is not used (neither old choose remote endpoint).
      It is used by code for switching A2DP codec which is in next patches.
      d055e4b5
    • pali's avatar
      bluetooth: Do not export pa_a2dp_codecs array · 26675195
      pali authored
      It is not used directly outside of a2dp-codec-util.c file.
      26675195
    • pali's avatar
      bluetooth: Add missing newlines into inline XML document · 69703c58
      pali authored
      When calling introspection function, newlines in XML document makes it
      better readable. There are already leading spaces for indentation but
      newlines were probably forgotten.
      69703c58
  5. 19 Mar, 2020 1 commit
  6. 02 Jan, 2020 2 commits
  7. 25 Sep, 2019 1 commit
  8. 27 Aug, 2019 1 commit
  9. 05 Aug, 2019 2 commits
  10. 24 Jul, 2019 3 commits
    • pali's avatar
      bluetooth: Fix usage of RTP structures in SBC codec · 9e70d052
      pali authored and Tanu Kaskinen's avatar Tanu Kaskinen committed
      Rename struct rtp_payload to rtp_sbc_payload as it is specific for SBC
      codec payload.
      
      Add proper checks for endianity in rtp.h header and use uint8_t type
      where appropriated.
      
      Field frame_count is only 4 bit number, so add checks to prevent overflow.
      
      And because is_fragmented field is not parsed by decoder there is no
      support for decoding fragmented SBC frames. So throw an error in this case.
      9e70d052
    • pali's avatar
      bluetooth: Change A2DP codec API of reset() method to indicate failure · 064277b4
      pali authored and Tanu Kaskinen's avatar Tanu Kaskinen committed
      SBC codec reset() method may fail, so propagate this failure to caller.
      064277b4
    • pali's avatar
      bluetooth: Fix usage of MTU, buffer sizes and return values of encode/decode methods · 018b38ec
      pali authored and Tanu Kaskinen's avatar Tanu Kaskinen committed
      Add explanation why minimal bitpool value is used in SBC codec as initial
      bitpool value for A2DP source.
      
      Set buffer size for reading/writing from/to A2DP socket to exact link MTU
      value. This would ensure that A2DP codec does not produce larger packet as
      maximal possible size which can be sent.
      
      Because A2DP socket is of SOCK_SEQPACKET type, it is guaranteed that
      we do not read two packets via one read/recvmsg call.
      
      Properly check for all return values of encode/encode methods of A2DP codec
      functions. They may fail at different levels. Also encode or decode API
      method may return zero length buffer (e.g. because of algorithmic delay of
      codec), so do not fail in this case.
      018b38ec
  11. 02 Jul, 2019 2 commits
    • Frédéric Danis's avatar
      bluetooth: Fix crash when disabling Bluetooth adapter · f89d64b9
      Frédéric Danis authored and Tanu Kaskinen's avatar Tanu Kaskinen committed
      This crash occurs when PA is connected to a phone through the oFono
      backend.
      When disabling the Bluetooth adapter, pa_bluetooth_device is removed before
      hf_audio_card. Both keep refs on pa_bluetooth_transport. Those removal will
      call pa_bluetooth_transport_free() from device_free() (bluez5-util.c) and
      hf_audio_card_free() (backend-ofono.c).
      In the end, the call to pa_bluetooth_transport_free() calls
      pa_hasmap_remove() through pa_bluetooth_transport_unlink(), but since
      memory has already been freed, the second try results in a segfault.
      
      Triggering hf_audio_card removal during pa_bluetooth_device removal allows
      hf_audio_card to be freed at the right time.
      f89d64b9
    • Frédéric Danis's avatar
      bluetooth: Fix crash in setup_stream() · 661b13d5
      Frédéric Danis authored and Tanu Kaskinen's avatar Tanu Kaskinen committed
      setup_stream() crashes when calling set_nonblock() with an invalid
      stream_fd.
      
      On a new call, the ofono backend gets notified of a new connection.
      The ofono backend sets the transport state to playing, and that triggers
      a profile change, which sets up the stream for the first time.
      Then module-bluetooth-policy sets up the loopbacks. The loopbacks get
      fully initialized before the crash.
      
      After module-bluetooth-policy has done its things, the execution
      continues in the transport state change hook. The next hook user is
      module-bluez5-device, whose handle_transport_state_change() function
      gets called. It will then set up the stream again even though it's
      already set up. I'm not sure if that's a some kind of a bug.
      setup_stream() can handle the case where it's unnecessarily called,
      though, so this second setup is not a big problem.
      
      The crash happens, because the connection died due to POLLHUP in the IO
      thread before the second setup_stream() call.
      661b13d5
  12. 16 Jun, 2019 1 commit
    • Tanu Kaskinen's avatar
      a2dp-codec-sbc: get rid of compiler warnings · 4e08c14c
      Tanu Kaskinen authored
      The warnings:
      
      modules/bluetooth/a2dp-codec-sbc.c: In function ‘default_bitpool’:
      modules/bluetooth/a2dp-codec-sbc.c:161:13: warning: this statement may fall through [-Wimplicit-fallthrough=]
                   switch (mode) {
                   ^~~~~~
      modules/bluetooth/a2dp-codec-sbc.c:169:9: note: here
               case SBC_SAMPLING_FREQ_44100:
               ^~~~
      modules/bluetooth/a2dp-codec-sbc.c:170:13: warning: this statement may fall through [-Wimplicit-fallthrough=]
                   switch (mode) {
                   ^~~~~~
      modules/bluetooth/a2dp-codec-sbc.c:180:9: note: here
               case SBC_SAMPLING_FREQ_48000:
               ^~~~
      
      These were valid warnings in that an invalid channel mode would result
      in unintended fallthroughs, but the end result would anyway been a crash
      in the pa_assert_not_reached() at the end of the function, so
      functionally there's no change.
      4e08c14c
  13. 08 Jun, 2019 1 commit