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

Commit 0d1ffa17 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "audio HAL: add support for audio patch API." into tm-qpr-dev

parents 4e4e0f93 987e86c8
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 {