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

Commit 2110e04c authored by François Gaffie's avatar François Gaffie Committed by Jean-Michel Trivi
Browse files

Split ManagerDefault into manager and engine



This patch defines an interface for a new component: policy engine.
The APIs found under this interface are the one we may want to customize
and to configure easily.
This patch also split the current manager code into manager and engine to
provide a default version of the policy engine.

Change-Id: I97cf59760b53d248fe9efe466ae5e73bd7e5cc06
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@intel.com>
parent dfd7409c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ LOCAL_C_INCLUDES := \
    frameworks/av/services/audioflinger \
    frameworks/av/services/audiopolicy \
    frameworks/av/services/audiopolicy/common/managerdefinitions/include \
    frameworks/av/services/audiopolicy/common/include \
    frameworks/av/services/audiopolicy/engine/interface \
    frameworks/av/services/camera/libcameraservice \
    frameworks/av/services/mediaresourcemanager \
    $(call include-path-for, audio-utils) \
+6 −1
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@ LOCAL_C_INCLUDES := \
    $(TOPDIR)frameworks/av/services/audioflinger \
    $(call include-path-for, audio-effects) \
    $(call include-path-for, audio-utils) \
    $(TOPDIR)frameworks/av/services/audiopolicy/common/include
    $(TOPDIR)frameworks/av/services/audiopolicy/common/include \
    $(TOPDIR)frameworks/av/services/audiopolicy/engine/interface \

LOCAL_SHARED_LIBRARIES := \
    libcutils \
@@ -63,8 +64,11 @@ LOCAL_SHARED_LIBRARIES := \
    liblog \
    libsoundtrigger

LOCAL_SHARED_LIBRARIES += libaudiopolicyenginedefault

LOCAL_C_INCLUDES += \
    $(TOPDIR)frameworks/av/services/audiopolicy/common/include \
    $(TOPDIR)frameworks/av/services/audiopolicy/engine/interface \

LOCAL_STATIC_LIBRARIES := \
    libmedia_helper \
@@ -89,6 +93,7 @@ LOCAL_STATIC_LIBRARIES := \

LOCAL_C_INCLUDES += \
    $(TOPDIR)frameworks/av/services/audiopolicy/common/include \
    $(TOPDIR)frameworks/av/services/audiopolicy/engine/interface \

LOCAL_MODULE:= libaudiopolicymanager

+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@

namespace android {

// Time in milliseconds after media stopped playing during which we consider that the
// sonification should be as unobtrusive as during the time media was playing.
#define SONIFICATION_RESPECTFUL_AFTER_MUSIC_DELAY 5000

enum routing_strategy {
    STRATEGY_MEDIA,
    STRATEGY_PHONE,
+0 −34
Original line number Diff line number Diff line
@@ -16,46 +16,12 @@

#pragma once

#include <Volume.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
#include <system/audio.h>

namespace android {

class StreamDescriptor;

class ApmGains
{
public :
    static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
                    int indexInUi);

    // default volume curve
    static const VolumeCurvePoint sDefaultVolumeCurve[Volume::VOLCNT];
    // default volume curve for media strategy
    static const VolumeCurvePoint sDefaultMediaVolumeCurve[Volume::VOLCNT];
    // volume curve for non-media audio on ext media outputs (HDMI, Line, etc)
    static const VolumeCurvePoint sExtMediaSystemVolumeCurve[Volume::VOLCNT];
    // volume curve for media strategy on speakers
    static const VolumeCurvePoint sSpeakerMediaVolumeCurve[Volume::VOLCNT];
    static const VolumeCurvePoint sSpeakerMediaVolumeCurveDrc[Volume::VOLCNT];
    // volume curve for sonification strategy on speakers
    static const VolumeCurvePoint sSpeakerSonificationVolumeCurve[Volume::VOLCNT];
    static const VolumeCurvePoint sSpeakerSonificationVolumeCurveDrc[Volume::VOLCNT];
    static const VolumeCurvePoint sDefaultSystemVolumeCurve[Volume::VOLCNT];
    static const VolumeCurvePoint sDefaultSystemVolumeCurveDrc[Volume::VOLCNT];
    static const VolumeCurvePoint sHeadsetSystemVolumeCurve[Volume::VOLCNT];
    static const VolumeCurvePoint sDefaultVoiceVolumeCurve[Volume::VOLCNT];
    static const VolumeCurvePoint sSpeakerVoiceVolumeCurve[Volume::VOLCNT];
    static const VolumeCurvePoint sLinearVolumeCurve[Volume::VOLCNT];
    static const VolumeCurvePoint sSilentVolumeCurve[Volume::VOLCNT];
    static const VolumeCurvePoint sFullScaleVolumeCurve[Volume::VOLCNT];
    // default volume curves per stream and device category. See initializeVolumeCurves()
    static const VolumeCurvePoint *sVolumeProfiles[AUDIO_STREAM_CNT][Volume::DEVICE_CATEGORY_CNT];
};


class AudioGain: public RefBase
{
public:
+0 −214
Original line number Diff line number Diff line
@@ -33,220 +33,6 @@

namespace android {

const VolumeCurvePoint
ApmGains::sDefaultVolumeCurve[Volume::VOLCNT] = {
    {1, -49.5f}, {33, -33.5f}, {66, -17.0f}, {100, 0.0f}
};


const VolumeCurvePoint
ApmGains::sDefaultMediaVolumeCurve[Volume::VOLCNT] = {
    {1, -58.0f}, {20, -40.0f}, {60, -17.0f}, {100, 0.0f}
};

const VolumeCurvePoint
ApmGains::sExtMediaSystemVolumeCurve[Volume::VOLCNT] = {
    {1, -58.0f}, {20, -40.0f}, {60, -21.0f}, {100, -10.0f}
};

const VolumeCurvePoint
ApmGains::sSpeakerMediaVolumeCurve[Volume::VOLCNT] = {
    {1, -56.0f}, {20, -34.0f}, {60, -11.0f}, {100, 0.0f}
};

const VolumeCurvePoint
ApmGains::sSpeakerMediaVolumeCurveDrc[Volume::VOLCNT] = {
    {1, -55.0f}, {20, -43.0f}, {86, -12.0f}, {100, 0.0f}
};

const VolumeCurvePoint
ApmGains::sSpeakerSonificationVolumeCurve[Volume::VOLCNT] = {
    {1, -29.7f}, {33, -20.1f}, {66, -10.2f}, {100, 0.0f}
};

const VolumeCurvePoint
ApmGains::sSpeakerSonificationVolumeCurveDrc[Volume::VOLCNT] = {
    {1, -35.7f}, {33, -26.1f}, {66, -13.2f}, {100, 0.0f}
};

// AUDIO_STREAM_SYSTEM, AUDIO_STREAM_ENFORCED_AUDIBLE and AUDIO_STREAM_DTMF volume tracks
// AUDIO_STREAM_RING on phones and AUDIO_STREAM_MUSIC on tablets.
// AUDIO_STREAM_DTMF tracks AUDIO_STREAM_VOICE_CALL while in call (See AudioService.java).
// The range is constrained between -24dB and -6dB over speaker and -30dB and -18dB over headset.

const VolumeCurvePoint
ApmGains::sDefaultSystemVolumeCurve[Volume::VOLCNT] = {
    {1, -24.0f}, {33, -18.0f}, {66, -12.0f}, {100, -6.0f}
};

const VolumeCurvePoint
ApmGains::sDefaultSystemVolumeCurveDrc[Volume::VOLCNT] = {
    {1, -34.0f}, {33, -24.0f}, {66, -15.0f}, {100, -6.0f}
};

const VolumeCurvePoint
ApmGains::sHeadsetSystemVolumeCurve[Volume::VOLCNT] = {
    {1, -30.0f}, {33, -26.0f}, {66, -22.0f}, {100, -18.0f}
};

const VolumeCurvePoint
ApmGains::sDefaultVoiceVolumeCurve[Volume::VOLCNT] = {
    {0, -42.0f}, {33, -28.0f}, {66, -14.0f}, {100, 0.0f}
};

const VolumeCurvePoint
ApmGains::sSpeakerVoiceVolumeCurve[Volume::VOLCNT] = {
    {0, -24.0f}, {33, -16.0f}, {66, -8.0f}, {100, 0.0f}
};

const VolumeCurvePoint
ApmGains::sLinearVolumeCurve[Volume::VOLCNT] = {
    {0, -96.0f}, {33, -68.0f}, {66, -34.0f}, {100, 0.0f}
};

const VolumeCurvePoint
ApmGains::sSilentVolumeCurve[Volume::VOLCNT] = {
    {0, -96.0f}, {1, -96.0f}, {2, -96.0f}, {100, -96.0f}
};

const VolumeCurvePoint
ApmGains::sFullScaleVolumeCurve[Volume::VOLCNT] = {
    {0, 0.0f}, {1, 0.0f}, {2, 0.0f}, {100, 0.0f}
};

const VolumeCurvePoint *ApmGains::sVolumeProfiles[AUDIO_STREAM_CNT]
                                                  [Volume::DEVICE_CATEGORY_CNT] = {
    { // AUDIO_STREAM_VOICE_CALL
        ApmGains::sDefaultVoiceVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sSpeakerVoiceVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sSpeakerVoiceVolumeCurve, // DEVICE_CATEGORY_EARPIECE
        ApmGains::sDefaultMediaVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_SYSTEM
        ApmGains::sHeadsetSystemVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sDefaultSystemVolumeCurve,  // DEVICE_CATEGORY_EARPIECE
        ApmGains::sExtMediaSystemVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_RING
        ApmGains::sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sSpeakerSonificationVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sDefaultVolumeCurve,  // DEVICE_CATEGORY_EARPIECE
        ApmGains::sExtMediaSystemVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_MUSIC
        ApmGains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sSpeakerMediaVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_EARPIECE
        ApmGains::sDefaultMediaVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_ALARM
        ApmGains::sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sSpeakerSonificationVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sDefaultVolumeCurve,  // DEVICE_CATEGORY_EARPIECE
        ApmGains::sExtMediaSystemVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_NOTIFICATION
        ApmGains::sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sSpeakerSonificationVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sDefaultVolumeCurve,  // DEVICE_CATEGORY_EARPIECE
        ApmGains::sExtMediaSystemVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_BLUETOOTH_SCO
        ApmGains::sDefaultVoiceVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sSpeakerVoiceVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sDefaultVoiceVolumeCurve, // DEVICE_CATEGORY_EARPIECE
        ApmGains::sDefaultMediaVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_ENFORCED_AUDIBLE
        ApmGains::sHeadsetSystemVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_EARPIECE
        ApmGains::sExtMediaSystemVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    {  // AUDIO_STREAM_DTMF
        ApmGains::sHeadsetSystemVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sDefaultSystemVolumeCurve, // DEVICE_CATEGORY_EARPIECE
        ApmGains::sExtMediaSystemVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_TTS
      // "Transmitted Through Speaker": always silent except on DEVICE_CATEGORY_SPEAKER
        ApmGains::sSilentVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sLinearVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sSilentVolumeCurve, // DEVICE_CATEGORY_EARPIECE
        ApmGains::sSilentVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_ACCESSIBILITY
        ApmGains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sSpeakerMediaVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sDefaultMediaVolumeCurve, // DEVICE_CATEGORY_EARPIECE
        ApmGains::sDefaultMediaVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_REROUTING
        ApmGains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_EARPIECE
        ApmGains::sFullScaleVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
    { // AUDIO_STREAM_PATCH
        ApmGains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_HEADSET
        ApmGains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_SPEAKER
        ApmGains::sFullScaleVolumeCurve, // DEVICE_CATEGORY_EARPIECE
        ApmGains::sFullScaleVolumeCurve  // DEVICE_CATEGORY_EXT_MEDIA
    },
};

//static
float ApmGains::volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
        int indexInUi)
{
    Volume::device_category deviceCategory = Volume::getDeviceCategory(device);
    const VolumeCurvePoint *curve = streamDesc.getVolumeCurvePoint(deviceCategory);

    // the volume index in the UI is relative to the min and max volume indices for this stream type
    int nbSteps = 1 + curve[Volume::VOLMAX].mIndex -
            curve[Volume::VOLMIN].mIndex;
    int volIdx = (nbSteps * (indexInUi - streamDesc.getVolumeIndexMin())) /
            (streamDesc.getVolumeIndexMax() - streamDesc.getVolumeIndexMin());

    // find what part of the curve this index volume belongs to, or if it's out of bounds
    int segment = 0;
    if (volIdx < curve[Volume::VOLMIN].mIndex) {         // out of bounds
        return 0.0f;
    } else if (volIdx < curve[Volume::VOLKNEE1].mIndex) {
        segment = 0;
    } else if (volIdx < curve[Volume::VOLKNEE2].mIndex) {
        segment = 1;
    } else if (volIdx <= curve[Volume::VOLMAX].mIndex) {
        segment = 2;
    } else {                                                               // out of bounds
        return 1.0f;
    }

    // linear interpolation in the attenuation table in dB
    float decibels = curve[segment].mDBAttenuation +
            ((float)(volIdx - curve[segment].mIndex)) *
                ( (curve[segment+1].mDBAttenuation -
                        curve[segment].mDBAttenuation) /
                    ((float)(curve[segment+1].mIndex -
                            curve[segment].mIndex)) );

    float amplification = exp( decibels * 0.115129f); // exp( dB * ln(10) / 20 )

    ALOGVV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f] ampl=%.5f",
            curve[segment].mIndex, volIdx,
            curve[segment+1].mIndex,
            curve[segment].mDBAttenuation,
            decibels,
            curve[segment+1].mDBAttenuation,
            amplification);

    return amplification;
}



AudioGain::AudioGain(int index, bool useInChannelMask)
{
    mIndex = index;
Loading