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

Commit 57ff9b5f authored by vivek mehta's avatar vivek mehta Committed by Eric Laurent
Browse files

hal: restrict 24 bit capture for unprocessed audio

- configure backend to 24 bit only when source is unprocessed
- for all other source force 16 bit only

- final result

  -----------------------------------------------------------------
  source        app request    audio policy requests    hal returns
  -----------------------------------------------------------------
  Unprocessed   16             8_24                     8_24
  Unprocessed   24/float/8_24  24/float/8_24            8_24

  any other     16             8_24                     -EINVAL
  (retry)                      16                       16

  any other     24/float/8_24  24/float/8_24            -EINVAL
  (retry)                      16                       16
  -----------------------------------------------------------------

Bug: 27348418.

Change-Id: I01139e741a414db1b9ff0079984cb5da007f9a0c
parent 4ed66e62
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) {