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

Commit 987e86c8 authored by Eric Laurent's avatar Eric Laurent Committed by Jakub Tyszkowski
Browse files

audio HAL: add support for audio patch API.

Add support for audio patch routing APIs and update
audio HAL version to 3.0.

Audio patch APIs are needed for LE audio because LE Audio
device types have more than one bit set.

Bug: 150670922
Test: regression tests with BT A2DP SW encoder path
Change-Id: I2c7c3db05063c6cc248681b9964af6c4633ffe99
(cherry picked from commit 2f7ce9f5a539aa99b4e91743007941f21cfee22f)
parent 9f6645c3
Loading
Loading
Loading
Loading
+57 −1
Original line number Diff line number Diff line
@@ -99,6 +99,59 @@ static int adev_get_mic_mute(const struct audio_hw_device* dev, bool* state) {
  return -ENOSYS;
}

static int adev_create_audio_patch(struct audio_hw_device* device,
                                   unsigned int num_sources,
                                   const struct audio_port_config* sources,
                                   unsigned int num_sinks,
                                   const struct audio_port_config* sinks,
                                   audio_patch_handle_t* handle) {
  if (device == nullptr || sources == nullptr || sinks == nullptr ||
      handle == nullptr || num_sources != 1 || num_sinks == 0 ||
      num_sinks > AUDIO_PATCH_PORTS_MAX) {
    return -EINVAL;
  }
  if (sources[0].type == AUDIO_PORT_TYPE_DEVICE) {
    if (num_sinks != 1 || sinks[0].type != AUDIO_PORT_TYPE_MIX) {
      return -EINVAL;
    }
  } else if (sources[0].type == AUDIO_PORT_TYPE_MIX) {
    for (unsigned int i = 0; i < num_sinks; i++) {
      if (sinks[i].type != AUDIO_PORT_TYPE_DEVICE) {
        return -EINVAL;
      }
    }
  } else {
    return -EINVAL;
  }

  auto* bluetooth_device = reinterpret_cast<BluetoothAudioDevice*>(device);
  std::lock_guard<std::mutex> guard(bluetooth_device->mutex_);
  if (*handle == AUDIO_PATCH_HANDLE_NONE) {
    *handle = ++bluetooth_device->next_unique_id;
  }

  LOG(INFO) << __func__ << ": device=" << std::hex << sinks[0].ext.device.type
            << " handle: " << *handle;
  return 0;
}

static int adev_release_audio_patch(struct audio_hw_device* device,
                                    audio_patch_handle_t patch_handle) {
  if (device == nullptr) {
    return -EINVAL;
  }
  LOG(INFO) << __func__ << ": patch_handle=" << patch_handle;
  return 0;
}

static int adev_get_audio_port(struct audio_hw_device* device,
                               struct audio_port* port) {
  if (device == nullptr || port == nullptr) {
    return -EINVAL;
  }
  return -ENOSYS;
}

static int adev_dump(const audio_hw_device_t* device, int fd) { return 0; }

static int adev_close(hw_device_t* device) {
@@ -117,7 +170,7 @@ static int adev_open(const hw_module_t* module, const char* name,
  if (!adev) return -ENOMEM;

  adev->common.tag = HARDWARE_DEVICE_TAG;
  adev->common.version = AUDIO_DEVICE_API_VERSION_2_0;
  adev->common.version = AUDIO_DEVICE_API_VERSION_3_0;
  adev->common.module = (struct hw_module_t*)module;
  adev->common.close = adev_close;

@@ -138,6 +191,9 @@ static int adev_open(const hw_module_t* module, const char* name,
  adev->dump = adev_dump;
  adev->set_master_mute = adev_set_master_mute;
  adev->get_master_mute = adev_get_master_mute;
  adev->create_audio_patch = adev_create_audio_patch;
  adev->release_audio_patch = adev_release_audio_patch;
  adev->get_audio_port = adev_get_audio_port;

  *device = &adev->common;
  return 0;
+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ struct BluetoothAudioDevice {
  std::mutex mutex_;
  std::list<BluetoothStreamOut*> opened_stream_outs_ =
      std::list<BluetoothStreamOut*>(0);
  uint32_t next_unique_id = 1;
};

struct BluetoothStreamIn {