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

Commit 79b67fcd authored by Divya Narayanan Poojary's avatar Divya Narayanan Poojary Committed by Gerrit - the friendly Code Review server
Browse files

hal: Restrict SSR recording to channel position representation

 Surround Sound Recording(SSR) supports only channel position
 representation while default channel mask for multi-channel
 recording is always index representation.
 Return updated channel mask in case index representation is sent
 for channel count 6. This ensures audio flinger reopens the session
 with updated position representation channel mask.
 And also handled the case if any client requests recording with
 multichannel when SSR is not enabled, will check the max_mic_count
 supported by the device and update the channel mask accordingly.

Change-Id: I767efd05f8b5aa5d9259d95f6f11d7670af74d81
parent a6ffa5e1
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -930,3 +930,51 @@ void audio_extn_perf_lock_release(void)
        ALOGE("%s: Perf lock release error \n", __func__);
}
#endif /* KPI_OPTIMIZE_ENABLED */

static int audio_extn_set_multichannel_usecase(struct audio_device *adev,
                                               struct stream_in *in,
                                               struct audio_config *config,
                                               bool *update_params)
{
    int ret = -EINVAL;
    int channel_count = audio_channel_count_from_in_mask(in->channel_mask);
    *update_params = false;

    int max_mic_count = platform_get_max_mic_count(adev->platform);
    /* validate input params*/
    if ((channel_count == 6) &&
        (in->format == AUDIO_FORMAT_PCM_16_BIT)) {

        switch (max_mic_count) {
            case 4:
                config->channel_mask = AUDIO_CHANNEL_INDEX_MASK_4;
                break;
            case 3:
                config->channel_mask = AUDIO_CHANNEL_INDEX_MASK_3;
                break;
            case 2:
                config->channel_mask = AUDIO_CHANNEL_IN_STEREO;
                break;
            default:
                config->channel_mask = AUDIO_CHANNEL_IN_STEREO;
                break;
       }
        ret = 0;
        *update_params = true;
    }
    return ret;
}

int audio_extn_check_and_set_multichannel_usecase(struct audio_device *adev,
                                                  struct stream_in *in,
                                                  struct audio_config *config,
                                                  bool *update_params)
{
    bool ssr_supported = false;
    ssr_supported = audio_extn_ssr_check_usecase(in);
    if (ssr_supported) {
        return audio_extn_ssr_set_usecase(in, config, update_params);
    } else {
        return audio_extn_set_multichannel_usecase(adev, in, config, update_params);
    }
}
+10 −1
Original line number Diff line number Diff line
@@ -148,6 +148,8 @@ bool audio_extn_usb_is_proxy_inuse();
#endif

#ifndef SSR_ENABLED
#define audio_extn_ssr_check_usecase(in)      (0)
#define audio_extn_ssr_set_usecase(in, config, update_params)      (0)
#define audio_extn_ssr_init(in, num_out_chan)         (0)
#define audio_extn_ssr_deinit()                       (0)
#define audio_extn_ssr_update_enabled()               (0)
@@ -157,6 +159,10 @@ bool audio_extn_usb_is_proxy_inuse();
#define audio_extn_ssr_get_parameters(adev, parms, reply) (0)
#define audio_extn_ssr_get_stream()                   (0)
#else
bool audio_extn_ssr_check_usecase(struct stream_in *in);
int audio_extn_ssr_set_usecase(struct stream_in *in,
                                         struct audio_config *config,
                                         bool *update_params);
int32_t audio_extn_ssr_init(struct stream_in *in,
                            int num_out_chan);
int32_t audio_extn_ssr_deinit();
@@ -171,7 +177,10 @@ void audio_extn_ssr_get_parameters(const struct audio_device *adev,
                                   struct str_parms *reply);
struct stream_in *audio_extn_ssr_get_stream();
#endif

int audio_extn_check_and_set_multichannel_usecase(struct audio_device *adev,
                                                  struct stream_in *in,
                                                  struct audio_config *config,
                                                  bool *update_params);
#ifndef HW_VARIANTS_ENABLED
#define hw_info_init(snd_card_name)                  (0)
#define hw_info_deinit(hw_info)                      (0)
+9 −20
Original line number Diff line number Diff line
@@ -3570,6 +3570,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
    int ret = 0, buffer_size, frame_size;
    int channel_count = audio_channel_count_from_in_mask(config->channel_mask);
    bool is_low_latency = false;
    bool updated_params = false;

    *stream_in = NULL;
    if (check_input_parameters(config->sample_rate, config->format, channel_count) != 0)
@@ -3651,27 +3652,15 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
        in->config = pcm_config_afe_proxy_record;
        in->config.channels = channel_count;
        in->config.rate = config->sample_rate;
    } else if (audio_extn_ssr_get_enabled() &&
                 ((channel_count == 2) ||(channel_count == 6)) &&
                 ((AUDIO_SOURCE_MIC == source) || (AUDIO_SOURCE_CAMCORDER == source))) {
                ALOGD("Found SSR use case starting SSR lib with channel_count :%d", channel_count);
                if(audio_extn_ssr_init(in, channel_count)) {
                    ALOGE("%s: audio_extn_ssr_init failed", __func__);
                    if(channel_count == 2 ) {
                    ALOGD("%s:falling back to default record usecase", __func__);
                    in->config.channels = channel_count;
                    frame_size = audio_stream_in_frame_size(&in->stream);
                    buffer_size = get_input_buffer_size(config->sample_rate,
                                            config->format,
                                            channel_count,
                                            is_low_latency);
                    in->config.period_size = buffer_size / frame_size;
				} else {
                    ALOGD("%s:unable to start SSR record session for 6 channel input", __func__);
    } else if (!audio_extn_check_and_set_multichannel_usecase(adev,
                    in, config, &updated_params)) {
            if (updated_params == true) {
                ALOGD("%s: updated params, return error for retry channel mask (%#x)",
                                           __func__, config->channel_mask);
                    ret = -EINVAL;
                    goto err_open;
            }
            } else
            ALOGD("%s: created surround sound session succesfully",__func__);
            in->usecase = USECASE_AUDIO_RECORD_3MIC_SSR;
    } else if (audio_extn_compr_cap_enabled() &&
            audio_extn_compr_cap_format_supported(config->format) &&
+4 −0
Original line number Diff line number Diff line
@@ -2678,3 +2678,7 @@ void platform_cache_edid(void * platform __unused)
void platform_invalidate_edid(void * platform __unused)
{
}

int platform_get_max_mic_count(void *platform) {
    return 0;
}
+5 −0
Original line number Diff line number Diff line
@@ -3690,3 +3690,8 @@ int platform_set_device_params(struct stream_out *out, int param, int value)
end:
    return ret;
}

int platform_get_max_mic_count(void *platform) {
    struct platform_data *my_data = (struct platform_data *)platform;
    return my_data->max_mic_count;
}
Loading