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

Commit 1f60cf8c authored by Ravi Kumar Alamanda's avatar Ravi Kumar Alamanda Committed by Eric Laurent
Browse files

hal: support seamless speaker channels swapping

Change-Id: Ia82254cfb5d2021759f6874e7d7272c75ab91497
parent d2063ecf
Loading
Loading
Loading
Loading
+1 −13
Original line number Diff line number Diff line
@@ -2244,19 +2244,7 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs)
            status = -EINVAL;
        }
        if (status == 0) {
            if (adev->speaker_lr_swap != reverse_speakers) {
                adev->speaker_lr_swap = reverse_speakers;
                // only update the selected device if there is active pcm playback
                struct audio_usecase *usecase;
                struct listnode *node;
                list_for_each(node, &adev->usecase_list) {
                    usecase = node_to_item(node, struct audio_usecase, list);
                    if (usecase->type == PCM_PLAYBACK) {
                        select_devices(adev, usecase->id);
                        break;
                    }
                }
            }
            platform_swap_lr_channels(adev, reverse_speakers);
        }
    }

+0 −1
Original line number Diff line number Diff line
@@ -211,7 +211,6 @@ struct audio_device {
    struct listnode usecase_list;
    struct audio_route *audio_route;
    int acdb_settings;
    bool speaker_lr_swap;
    struct voice voice;
    unsigned int cur_hdmi_channels;
    bool bt_wb_speech_enabled;
+32 −1
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ struct platform_data {
    bool fluence_in_voice_call;
    bool fluence_in_voice_rec;
    int  dualmic_config;
    bool speaker_lr_swap;

    void *acdb_handle;
    acdb_init_t acdb_init;
@@ -655,7 +656,7 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
        devices & AUDIO_DEVICE_OUT_WIRED_HEADSET) {
        snd_device = SND_DEVICE_OUT_HEADPHONES;
    } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
        if (adev->speaker_lr_swap)
        if (my_data->speaker_lr_swap)
            snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
        else
            snd_device = SND_DEVICE_OUT_SPEAKER;
@@ -1004,3 +1005,33 @@ void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_d
{
    return;
}

int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
{
    // only update the selected device if there is active pcm playback
    struct audio_usecase *usecase;
    struct listnode *node;
    struct platform_data *my_data = (struct platform_data *)adev->platform;
    int status = 0;

    if (my_data->speaker_lr_swap != swap_channels) {
        my_data->speaker_lr_swap = swap_channels;

        list_for_each(node, &adev->usecase_list) {
            usecase = node_to_item(node, struct audio_usecase, list);
            if (usecase->type == PCM_PLAYBACK &&
                usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
                const char *mixer_path;
                if (swap_channels) {
                    mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
                    audio_route_apply_and_update_path(adev->audio_route, mixer_path);
                } else {
                    mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
                    audio_route_apply_and_update_path(adev->audio_route, mixer_path);
                }
                break;
            }
        }
    }
    return status;
}
+32 −1
Original line number Diff line number Diff line
@@ -78,6 +78,8 @@ struct platform_data {
    bool fluence_in_voice_comm;
    bool fluence_in_voice_rec;
    int  dualmic_config;
    bool speaker_lr_swap;

    void *acdb_handle;
    acdb_init_t                acdb_init;
    acdb_deallocate_t          acdb_deallocate;
@@ -1265,7 +1267,7 @@ snd_device_t platform_get_output_snd_device(void *platform, audio_devices_t devi
    } else if (devices & AUDIO_DEVICE_OUT_SPEAKER_SAFE) {
        snd_device = SND_DEVICE_OUT_SPEAKER_SAFE;
    } else if (devices & AUDIO_DEVICE_OUT_SPEAKER) {
        if (adev->speaker_lr_swap)
        if (my_data->speaker_lr_swap)
            snd_device = SND_DEVICE_OUT_SPEAKER_REVERSE;
        else
            snd_device = SND_DEVICE_OUT_SPEAKER;
@@ -1734,3 +1736,32 @@ int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t p
done:
    return ret;
}

int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels)
{
    // only update if there is active pcm playback on speaker
    struct audio_usecase *usecase;
    struct listnode *node;
    struct platform_data *my_data = (struct platform_data *)adev->platform;

    if (my_data->speaker_lr_swap != swap_channels) {
        my_data->speaker_lr_swap = swap_channels;

        list_for_each(node, &adev->usecase_list) {
            usecase = node_to_item(node, struct audio_usecase, list);
            if (usecase->type == PCM_PLAYBACK &&
                usecase->stream.out->devices & AUDIO_DEVICE_OUT_SPEAKER) {
                const char *mixer_path;
                if (swap_channels) {
                    mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER_REVERSE);
                    audio_route_apply_and_update_path(adev->audio_route, mixer_path);
                } else {
                    mixer_path = platform_get_snd_device_name(SND_DEVICE_OUT_SPEAKER);
                    audio_route_apply_and_update_path(adev->audio_route, mixer_path);
                }
                break;
            }
        }
    }
    return 0;
}
+1 −1
Original line number Diff line number Diff line
@@ -64,5 +64,5 @@ int platform_info_init(void);
int platform_get_usecase_index(const char * usecase);
int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id);
void platform_set_echo_reference(struct audio_device *adev, bool enable, audio_devices_t out_device);

int platform_swap_lr_channels(struct audio_device *adev, bool swap_channels);
#endif // AUDIO_PLATFORM_API_H