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

Commit c8a2c9c5 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "hal: restrict 24 bit capture for unprocessed audio" into nyc-dev

parents 8d89f409 57ff9b5f
Loading
Loading
Loading
Loading
+29 −8
Original line number Original line Diff line number Diff line
@@ -2706,18 +2706,39 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
    in->channel_mask = config->channel_mask;
    in->channel_mask = config->channel_mask;
    in->capture_handle = handle;
    in->capture_handle = handle;
    in->flags = flags;
    in->flags = flags;
    in->format = config->format;
    // in->frames_read = 0;


    if (in->format == AUDIO_FORMAT_DEFAULT)
    // restrict 24 bit capture for unprocessed source only
    // for other sources if 24 bit requested reject 24 and set 16 bit capture only
    if (config->format == AUDIO_FORMAT_DEFAULT) {
        config->format = AUDIO_FORMAT_PCM_16_BIT;
        config->format = AUDIO_FORMAT_PCM_16_BIT;

    } else if (config->format == AUDIO_FORMAT_PCM_FLOAT ||
    if (config->format == AUDIO_FORMAT_PCM_FLOAT ||
               config->format == AUDIO_FORMAT_PCM_24_BIT_PACKED ||
        config->format == AUDIO_FORMAT_PCM_24_BIT_PACKED) {
               config->format == AUDIO_FORMAT_PCM_8_24_BIT) {
        bool ret_error = false;
        /* 24 bit is restricted to UNPROCESSED source only,also format supported
           from HAL is 8_24
           *> In case of UNPROCESSED source, for 24 bit, if format requested is other than
              8_24 return error indicating supported format is 8_24
           *> In case of any other source requesting 24 bit or float return error
              indicating format supported is 16 bit only.

           on error flinger will retry with supported format passed
         */
        if (source != AUDIO_SOURCE_UNPROCESSED) {
            config->format = AUDIO_FORMAT_PCM_16_BIT;
            ret_error = true;
        } else if (config->format != AUDIO_FORMAT_PCM_8_24_BIT) {
            config->format = AUDIO_FORMAT_PCM_8_24_BIT;
            config->format = AUDIO_FORMAT_PCM_8_24_BIT;
            ret_error = true;
        }

        if (ret_error) {
            ret = -EINVAL;
            ret = -EINVAL;
            goto err_open;
            goto err_open;
        }
        }
    }

    in->format = config->format;


    /* Update config params with the requested sample rate and channels */
    /* Update config params with the requested sample rate and channels */
    if (in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) {
    if (in->device == AUDIO_DEVICE_IN_TELEPHONY_RX) {