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

Commit 2ea44dd8 authored by Lorena Torres-Huerta's avatar Lorena Torres-Huerta Committed by Gerrit Code Review
Browse files

Merge changes from topic "engineConfigHalInterface"

* changes:
  Default implementation for IConfig engine configuration.
  Add engine configuration to the AIDL Audio HAL interface.
parents 00be453d bc585bd9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35,4 +35,5 @@ package android.hardware.audio.core;
@VintfStability
interface IConfig {
  android.hardware.audio.core.SurroundSoundConfig getSurroundSoundConfig();
  android.media.audio.common.AudioHalEngineConfig getEngineConfig();
}
+16 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.hardware.audio.core;

import android.hardware.audio.core.SurroundSoundConfig;
import android.media.audio.common.AudioHalEngineConfig;

/**
 * This interface provides system-wide configuration parameters for audio I/O
@@ -34,4 +35,19 @@ interface IConfig {
     * @return The surround sound configuration
     */
    SurroundSoundConfig getSurroundSoundConfig();
    /**
     * Returns the configuration items used to determine the audio policy engine
     * flavor and initial configuration.
     *
     * Engine flavor is determined by presence of capSpecificConfig, which must
     * only be present if the device uses the Configurable Audio Policy (CAP)
     * engine. Clients normally use the default audio policy engine. The client
     * will use the CAP engine only when capSpecificConfig has a non-null value.
     *
     * This method is expected to only be called during the initialization of
     * the audio policy engine, and must always return the same result.
     *
     * @return The engine configuration
     */
    AudioHalEngineConfig getEngineConfig();
}
+17 −0
Original line number Diff line number Diff line
@@ -18,11 +18,14 @@ cc_defaults {
        "libfmq",
        "libstagefright_foundation",
        "libutils",
        "libxml2",
        "android.hardware.common-V2-ndk",
        "android.hardware.common.fmq-V1-ndk",
    ],
    header_libs: [
        "libaudio_system_headers",
        "libaudioaidl_headers",
        "libxsdc-utils",
    ],
}

@@ -35,12 +38,26 @@ cc_library_static {
    ],
    export_include_dirs: ["include"],
    srcs: [
        "AudioPolicyConfigXmlConverter.cpp",
        "Config.cpp",
        "Configuration.cpp",
        "EngineConfigXmlConverter.cpp",
        "Module.cpp",
        "Stream.cpp",
        "Telephony.cpp",
    ],
    generated_sources: [
        "audio_policy_configuration_aidl_default",
        "audio_policy_engine_configuration_aidl_default",
    ],
    generated_headers: [
        "audio_policy_configuration_aidl_default",
        "audio_policy_engine_configuration_aidl_default",
    ],
    export_generated_headers: [
        "audio_policy_configuration_aidl_default",
        "audio_policy_engine_configuration_aidl_default",
    ],
    visibility: [
        ":__subpackages__",
    ],
+130 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */

#include <fcntl.h>
#include <inttypes.h>
#include <unistd.h>

#include <functional>
#include <unordered_map>

#include <aidl/android/media/audio/common/AudioHalEngineConfig.h>
#include <system/audio-base-utils.h>

#include "core-impl/AudioPolicyConfigXmlConverter.h"

using aidl::android::media::audio::common::AudioHalEngineConfig;
using aidl::android::media::audio::common::AudioHalVolumeCurve;
using aidl::android::media::audio::common::AudioHalVolumeGroup;
using aidl::android::media::audio::common::AudioStreamType;

namespace xsd = android::audio::policy::configuration;

namespace aidl::android::hardware::audio::core::internal {

static const int kDefaultVolumeIndexMin = 0;
static const int kDefaultVolumeIndexMax = 100;
static const int KVolumeIndexDeferredToAudioService = -1;
/**
 * Valid curve points take the form "<index>,<attenuationMb>", where the index
 * must be in the range [0,100]. kInvalidCurvePointIndex is used to indicate
 * that a point was formatted incorrectly (e.g. if a vendor accidentally typed a
 * '.' instead of a ',' in their XML) -- using such a curve point will result in
 * failed VTS tests.
 */
static const int8_t kInvalidCurvePointIndex = -1;

AudioHalVolumeCurve::CurvePoint AudioPolicyConfigXmlConverter::convertCurvePointToAidl(
        const std::string& xsdcCurvePoint) {
    AudioHalVolumeCurve::CurvePoint aidlCurvePoint{};
    if (sscanf(xsdcCurvePoint.c_str(), "%" SCNd8 ",%d", &aidlCurvePoint.index,
               &aidlCurvePoint.attenuationMb) != 2) {
        aidlCurvePoint.index = kInvalidCurvePointIndex;
    }
    return aidlCurvePoint;
}

AudioHalVolumeCurve AudioPolicyConfigXmlConverter::convertVolumeCurveToAidl(
        const xsd::Volume& xsdcVolumeCurve) {
    AudioHalVolumeCurve aidlVolumeCurve;
    aidlVolumeCurve.deviceCategory =
            static_cast<AudioHalVolumeCurve::DeviceCategory>(xsdcVolumeCurve.getDeviceCategory());
    if (xsdcVolumeCurve.hasRef()) {
        if (mVolumesReferenceMap.empty()) {
            mVolumesReferenceMap = generateReferenceMap<xsd::Volumes, xsd::Reference>(
                    getXsdcConfig()->getVolumes());
        }
        aidlVolumeCurve.curvePoints =
                convertCollectionToAidl<std::string, AudioHalVolumeCurve::CurvePoint>(
                        mVolumesReferenceMap.at(xsdcVolumeCurve.getRef()).getPoint(),
                        std::bind(&AudioPolicyConfigXmlConverter::convertCurvePointToAidl, this,
                                  std::placeholders::_1));
    } else {
        aidlVolumeCurve.curvePoints =
                convertCollectionToAidl<std::string, AudioHalVolumeCurve::CurvePoint>(
                        xsdcVolumeCurve.getPoint(),
                        std::bind(&AudioPolicyConfigXmlConverter::convertCurvePointToAidl, this,
                                  std::placeholders::_1));
    }
    return aidlVolumeCurve;
}

void AudioPolicyConfigXmlConverter::mapStreamToVolumeCurve(const xsd::Volume& xsdcVolumeCurve) {
    mStreamToVolumeCurvesMap[xsdcVolumeCurve.getStream()].push_back(
            convertVolumeCurveToAidl(xsdcVolumeCurve));
}

const AudioHalEngineConfig& AudioPolicyConfigXmlConverter::getAidlEngineConfig() {
    if (mAidlEngineConfig.volumeGroups.empty() && getXsdcConfig() &&
        getXsdcConfig()->hasVolumes()) {
        parseVolumes();
    }
    return mAidlEngineConfig;
}

void AudioPolicyConfigXmlConverter::mapStreamsToVolumeCurves() {
    if (getXsdcConfig()->hasVolumes()) {
        for (const xsd::Volumes& xsdcWrapperType : getXsdcConfig()->getVolumes()) {
            for (const xsd::Volume& xsdcVolume : xsdcWrapperType.getVolume()) {
                mapStreamToVolumeCurve(xsdcVolume);
            }
        }
    }
}

void AudioPolicyConfigXmlConverter::addVolumeGroupstoEngineConfig() {
    for (const auto& [xsdcStream, volumeCurves] : mStreamToVolumeCurvesMap) {
        AudioHalVolumeGroup volumeGroup;
        volumeGroup.name = xsd::toString(xsdcStream);
        if (static_cast<int>(xsdcStream) >= AUDIO_STREAM_PUBLIC_CNT) {
            volumeGroup.minIndex = kDefaultVolumeIndexMin;
            volumeGroup.maxIndex = kDefaultVolumeIndexMax;
        } else {
            volumeGroup.minIndex = KVolumeIndexDeferredToAudioService;
            volumeGroup.maxIndex = KVolumeIndexDeferredToAudioService;
        }
        volumeGroup.volumeCurves = volumeCurves;
        mAidlEngineConfig.volumeGroups.push_back(std::move(volumeGroup));
    }
}

void AudioPolicyConfigXmlConverter::parseVolumes() {
    if (mStreamToVolumeCurvesMap.empty() && getXsdcConfig()->hasVolumes()) {
        mapStreamsToVolumeCurves();
        addVolumeGroupstoEngineConfig();
    }
}
}  // namespace aidl::android::hardware::audio::core::internal
+28 −1
Original line number Diff line number Diff line
@@ -13,10 +13,17 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define LOG_TAG "AHAL_Module"

#define LOG_TAG "AHAL_Config"
#include <android-base/logging.h>

#include <system/audio_config.h>

#include "core-impl/AudioPolicyConfigXmlConverter.h"
#include "core-impl/Config.h"
#include "core-impl/EngineConfigXmlConverter.h"

using aidl::android::media::audio::common::AudioHalEngineConfig;

namespace aidl::android::hardware::audio::core {
ndk::ScopedAStatus Config::getSurroundSoundConfig(SurroundSoundConfig* _aidl_return) {
@@ -26,4 +33,24 @@ ndk::ScopedAStatus Config::getSurroundSoundConfig(SurroundSoundConfig* _aidl_ret
    LOG(DEBUG) << __func__ << ": returning " << _aidl_return->toString();
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus Config::getEngineConfig(AudioHalEngineConfig* _aidl_return) {
    static const AudioHalEngineConfig returnEngCfg = [this]() {
        AudioHalEngineConfig engConfig;
        if (mEngConfigConverter.getStatus() == ::android::OK) {
            engConfig = mEngConfigConverter.getAidlEngineConfig();
        } else {
            LOG(INFO) << __func__ << mEngConfigConverter.getError();
            if (mAudioPolicyConverter.getStatus() == ::android::OK) {
                engConfig = mAudioPolicyConverter.getAidlEngineConfig();
            } else {
                LOG(WARNING) << __func__ << mAudioPolicyConverter.getError();
            }
        }
        return engConfig;
    }();
    *_aidl_return = returnEngCfg;
    LOG(DEBUG) << __func__ << ": returning " << _aidl_return->toString();
    return ndk::ScopedAStatus::ok();
}
}  // namespace aidl::android::hardware::audio::core
Loading