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

Commit 5f67a948 authored by Derek Chen's avatar Derek Chen
Browse files

hal: add device compare util for type and address

Add device comparasion utility for type and
address validation within device list.
Update bus device and address check with this
for audio port gain configuration on automotive
platform.

Change-Id: Ic2d4522ecb61179198766e2bb8e2d644b3a3d950
parent 9a59b4ca
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -605,12 +605,10 @@ int auto_hal_set_audio_port_config(struct audio_hw_device *dev,
                                                    streams_output_ctxt_t,
                                                    list);
                /* limit audio gain support for bus device only */
                if (is_single_device_type_equal(
                        &out_ctxt->output->device_list, AUDIO_DEVICE_OUT_BUS) &&
                    is_single_device_type_equal(&out_ctxt->output->device_list,
                                                config->ext.device.type) &&
                    strcmp(out_ctxt->output->address,
                        config->ext.device.address) == 0) {
                if (config->ext.device.type == AUDIO_DEVICE_OUT_BUS &&
                    compare_device_type_and_address(&out_ctxt->output->device_list,
                                                    config->ext.device.type,
                                                    config->ext.device.address)) {
                    /* millibel = 1/100 dB = 1/1000 bel
                     * q13 = (10^(mdb/100/20))*(2^13)
                     */
+24 −0
Original line number Diff line number Diff line
@@ -375,6 +375,30 @@ bool compare_device_type(struct listnode *devices, audio_devices_t device_type)
    return false;
}

/*
 * Check if a device with given type and address is present in devices list
 */
bool compare_device_type_and_address(struct listnode *devices,
                                     audio_devices_t type, const char* address)
{
    struct listnode *node = devices;
    struct audio_device_info *item = NULL;

    if (devices == NULL)
        return false;

    list_for_each (node, devices) {
        item = node_to_item(node, struct audio_device_info, list);
        if (item != NULL && (item->type == type) &&
            (strcmp((const char *)&item->address[0], address) == 0)) {
            ALOGV("%s: device type %x and address %s match", __func__,
                item->type, (const char *)&item->address[0]);
            return true;
        }
    }
    return false;
}

/*
 * Returns true if intersection of d1 and d2 is not NULL
 */
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ bool is_a2dp_in_device_type(struct listnode *devices);
bool is_a2dp_out_device_type(struct listnode *devices);
int clear_devices(struct listnode *devices);
bool compare_device_type(struct listnode *devices, audio_devices_t device_type);
bool compare_device_type_and_address(struct listnode *devices,
                                     audio_devices_t type, const char* address);
bool compare_devices_for_any_match(struct listnode *d1, struct listnode *d2);
audio_devices_t get_device_types(struct listnode *devices);
bool is_single_device_type_equal(struct listnode *devices,
+1 −4
Original line number Diff line number Diff line
@@ -7603,10 +7603,7 @@ int adev_open_output_stream(struct audio_hw_device *dev,
            ret = -EINVAL;
            goto error_open;
        }
        /* save car audio stream and address for bus device */
        strlcpy(out->address, address, AUDIO_DEVICE_MAX_ADDRESS_LEN);
        ALOGV("%s: address %s, car_audio_stream %x",
            __func__, out->address, out->car_audio_stream);
        ALOGV("%s: car_audio_stream %x", __func__, out->car_audio_stream);
    }

    /* Check for VOIP usecase */
+1 −2
Original line number Diff line number Diff line
@@ -445,7 +445,6 @@ struct stream_out {
    error_log_t *error_log;
    bool pspd_coeff_sent;

    char address[AUDIO_DEVICE_MAX_ADDRESS_LEN];
    int car_audio_stream;

    union {
@@ -767,7 +766,7 @@ int adev_open_output_stream(struct audio_hw_device *dev,
                            audio_output_flags_t flags,
                            struct audio_config *config,
                            struct audio_stream_out **stream_out,
                            const char *address __unused);
                            const char *address);
void adev_close_output_stream(struct audio_hw_device *dev __unused,
                              struct audio_stream_out *stream);