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

Commit 49607806 authored by Haynes Mathew George's avatar Haynes Mathew George Committed by android-build-merger
Browse files

Merge "libeffects: validate channel mask in downmixer configure" into nyc-dev

am: 445531a5

* commit '445531a5':
  libeffects: validate channel mask in downmixer configure
parents 2f88a86e 445531a5
Loading
Loading
Loading
Loading
+40 −29
Original line number Original line Diff line number Diff line
@@ -141,6 +141,37 @@ void Downmix_testIndexComputation(uint32_t mask) {
}
}
#endif
#endif


static bool Downmix_validChannelMask(uint32_t mask)
{
    if (!mask) {
        return false;
    }
    // check against unsupported channels
    if (mask & kUnsupported) {
        ALOGE("Unsupported channels (top or front left/right of center)");
        return false;
    }
    // verify has FL/FR
    if ((mask & AUDIO_CHANNEL_OUT_STEREO) != AUDIO_CHANNEL_OUT_STEREO) {
        ALOGE("Front channels must be present");
        return false;
    }
    // verify uses SIDE as a pair (ok if not using SIDE at all)
    if ((mask & kSides) != 0) {
        if ((mask & kSides) != kSides) {
            ALOGE("Side channels must be used as a pair");
            return false;
        }
    }
    // verify uses BACK as a pair (ok if not using BACK at all)
    if ((mask & kBacks) != 0) {
        if ((mask & kBacks) != kBacks) {
            ALOGE("Back channels must be used as a pair");
            return false;
        }
    }
    return true;
}


/*----------------------------------------------------------------------------
/*----------------------------------------------------------------------------
 * Effect API implementation
 * Effect API implementation
@@ -624,9 +655,10 @@ int Downmix_Configure(downmix_module_t *pDwmModule, effect_config_t *pConfig, bo
        pDownmixer->apply_volume_correction = false;
        pDownmixer->apply_volume_correction = false;
        pDownmixer->input_channel_count = 8; // matches default input of AUDIO_CHANNEL_OUT_7POINT1
        pDownmixer->input_channel_count = 8; // matches default input of AUDIO_CHANNEL_OUT_7POINT1
    } else {
    } else {
        // when configuring the effect, do not allow a blank channel mask
        // when configuring the effect, do not allow a blank or unsupported channel mask
        if (pConfig->inputCfg.channels == 0) {
        if (!Downmix_validChannelMask(pConfig->inputCfg.channels)) {
            ALOGE("Downmix_Configure error: input channel mask can't be 0");
            ALOGE("Downmix_Configure error: input channel mask(0x%x) not supported",
                                                        pConfig->inputCfg.channels);
            return -EINVAL;
            return -EINVAL;
        }
        }
        pDownmixer->input_channel_count =
        pDownmixer->input_channel_count =
@@ -969,34 +1001,13 @@ void Downmix_foldFrom7Point1(int16_t *pSrc, int16_t*pDst, size_t numFrames, bool
 */
 */
bool Downmix_foldGeneric(
bool Downmix_foldGeneric(
        uint32_t mask, int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate) {
        uint32_t mask, int16_t *pSrc, int16_t*pDst, size_t numFrames, bool accumulate) {
    // check against unsupported channels

    if (mask & kUnsupported) {
    if (!Downmix_validChannelMask(mask)) {
        ALOGE("Unsupported channels (top or front left/right of center)");
        return false;
    }
    // verify has FL/FR
    if ((mask & AUDIO_CHANNEL_OUT_STEREO) != AUDIO_CHANNEL_OUT_STEREO) {
        ALOGE("Front channels must be present");
        return false;
    }
    // verify uses SIDE as a pair (ok if not using SIDE at all)
    bool hasSides = false;
    if ((mask & kSides) != 0) {
        if ((mask & kSides) != kSides) {
            ALOGE("Side channels must be used as a pair");
            return false;
        }
        hasSides = true;
    }
    // verify uses BACK as a pair (ok if not using BACK at all)
    bool hasBacks = false;
    if ((mask & kBacks) != 0) {
        if ((mask & kBacks) != kBacks) {
            ALOGE("Back channels must be used as a pair");
        return false;
        return false;
    }
    }
        hasBacks = true;

    }
    const bool hasSides = (mask & kSides) != 0;
    const bool hasBacks = (mask & kBacks) != 0;


    const int numChan = audio_channel_count_from_out_mask(mask);
    const int numChan = audio_channel_count_from_out_mask(mask);
    const bool hasFC = ((mask & AUDIO_CHANNEL_OUT_FRONT_CENTER) == AUDIO_CHANNEL_OUT_FRONT_CENTER);
    const bool hasFC = ((mask & AUDIO_CHANNEL_OUT_FRONT_CENTER) == AUDIO_CHANNEL_OUT_FRONT_CENTER);