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

Commit ba8e52b1 authored by Andy Hung's avatar Andy Hung
Browse files

AudioFlinger: remove float and multichannel shim for AIDL

Test: Validate AudioEffects with AIDL mode on and off.
Test: atest android.media.audio.cts.AudioEffectTest \
  android.media.audio.cts.AudioPreProcessingTest \
  android.media.audio.cts.BassBoostTest \
  android.media.audio.cts.EnvReverbTest \
  android.media.audio.cts.EqualizerTest \
  android.media.audio.cts.LoudnessEnhancerTest \
  android.media.audio.cts.PresetReverbTest \
  android.media.audio.cts.VirtualizerTest \
  android.media.audio.cts.VisualizerTest
Bug: 282066693
Change-Id: I08ab707f56d4e7c445306dc1532e887bbbb276c7
parent 9f896f2f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ class AudioHalVersionInfo : public android::media::AudioHalVersion {
        minor = halMinor;
    }

    bool isHidl() const { return type == Type::HIDL; }

    Type getType() const { return type; }

    int getMajorVersion() const { return major; }
+2 −1
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@
#include <audiomanager/IAudioManager.h>

#include "AudioFlinger.h"
#include "EffectConfiguration.h"
#include "NBAIO_Tee.h"
#include "PropertyUtils.h"

@@ -372,7 +373,7 @@ AudioFlinger::AudioFlinger()
    BatteryNotifier::getInstance().noteResetAudio();

    mDevicesFactoryHal = DevicesFactoryHalInterface::create();
    mEffectsFactoryHal = EffectsFactoryHalInterface::create();
    mEffectsFactoryHal = audioflinger::EffectConfiguration::getEffectsFactoryHal();

    mMediaLogNotifier->run("MediaLogNotifier");
    std::vector<pid_t> halPids;
+8 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <audio_utils/primitives.h>

#include "AudioFlinger.h"
#include "EffectConfiguration.h"
#include <media/audiohal/EffectsFactoryHalInterface.h>

// ----------------------------------------------------------------------------
@@ -111,14 +112,16 @@ sp<AudioFlinger::EffectHandle> AudioFlinger::DeviceEffectManager::createEffect_l

status_t AudioFlinger::DeviceEffectManager::checkEffectCompatibility(
        const effect_descriptor_t *desc) {
    sp<EffectsFactoryHalInterface> effectsFactory = mAudioFlinger.getEffectsFactory();
    const sp<EffectsFactoryHalInterface> effectsFactory =
            audioflinger::EffectConfiguration::getEffectsFactoryHal();
    if (effectsFactory == nullptr) {
        return BAD_VALUE;
    }

    static AudioHalVersionInfo sMinDeviceEffectHalVersion =
    static const AudioHalVersionInfo sMinDeviceEffectHalVersion =
            AudioHalVersionInfo(AudioHalVersionInfo::Type::HIDL, 6, 0);
    AudioHalVersionInfo halVersion = effectsFactory->getHalVersion();
    static const AudioHalVersionInfo halVersion =
            audioflinger::EffectConfiguration::getAudioHalVersionInfo();

    // We can trust AIDL generated AudioHalVersionInfo comparison operator (based on std::tie) as
    // long as the type, major and minor sequence doesn't change in the definition.
@@ -137,7 +140,8 @@ status_t AudioFlinger::DeviceEffectManager::createEffectHal(
        const effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t deviceId,
        sp<EffectHalInterface> *effect) {
    status_t status = NO_INIT;
    sp<EffectsFactoryHalInterface> effectsFactory = mAudioFlinger.getEffectsFactory();
    const sp<EffectsFactoryHalInterface> effectsFactory =
            audioflinger::EffectConfiguration::getEffectsFactoryHal();
    if (effectsFactory != 0) {
        status = effectsFactory->createEffect(
                pEffectUuid, sessionId, AUDIO_IO_HANDLE_NONE, deviceId, effect);
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <media/audiohal/EffectsFactoryHalInterface.h>

namespace android::audioflinger {

/**
 * Effect Configuration abstraction and helper class.
 */
class EffectConfiguration {
public:
    static bool isHidl() {
        static const bool isHidl = getAudioHalVersionInfo().isHidl();
        return isHidl;
    }

    static const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() {
        static const auto effectsFactoryHal = EffectsFactoryHalInterface::create();
        return effectsFactoryHal;
    }

    static const detail::AudioHalVersionInfo& getAudioHalVersionInfo() {
        static const auto audioHalVersionInfo = getEffectsFactoryHal() ?
                getEffectsFactoryHal()->getHalVersion() : detail::AudioHalVersionInfo{
                        detail::AudioHalVersionInfo::Type::HIDL, 0 /* major */, 0 /* minor */ };
        return audioHalVersionInfo;
    }
};

} // namespace android::audioflinger
+7 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
#include <mediautils/TimeCheck.h>

#include "AudioFlinger.h"
#include "EffectConfiguration.h"

// ----------------------------------------------------------------------------

@@ -65,6 +66,7 @@
namespace android {

using aidl_utils::statusTFromBinderStatus;
using audioflinger::EffectConfiguration;
using binder::Status;

namespace {
@@ -982,6 +984,7 @@ status_t AudioFlinger::EffectModule::configure()

#ifdef MULTICHANNEL_EFFECT_CHAIN
    if (status != NO_ERROR &&
            EffectConfiguration::isHidl() && // only HIDL effects support channel conversion
            mIsOutput &&
            (mConfig.inputCfg.channels != AUDIO_CHANNEL_OUT_STEREO
                    || mConfig.outputCfg.channels != AUDIO_CHANNEL_OUT_STEREO)) {
@@ -1012,7 +1015,8 @@ status_t AudioFlinger::EffectModule::configure()
        mSupportsFloat = true;
    }

    if (status != NO_ERROR) {
    // only HIDL effects support integer conversion.
    if (status != NO_ERROR && EffectConfiguration::isHidl()) {
        ALOGV("EFFECT_CMD_SET_CONFIG failed with float format, retry with int16_t.");
        mConfig.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
        mConfig.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
@@ -3032,7 +3036,8 @@ status_t AudioFlinger::EffectChain::EffectCallback::createEffectHal(
        const effect_uuid_t *pEffectUuid, int32_t sessionId, int32_t deviceId,
        sp<EffectHalInterface> *effect) {
    status_t status = NO_INIT;
    sp<EffectsFactoryHalInterface> effectsFactory = mAudioFlinger.getEffectsFactory();
    const sp<EffectsFactoryHalInterface> effectsFactory =
            EffectConfiguration::getEffectsFactoryHal();
    if (effectsFactory != 0) {
        status = effectsFactory->createEffect(pEffectUuid, sessionId, io(), deviceId, effect);
    }