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

Commit 6b3e7e19 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "policy-hal: add custom audio policy"

parents 240ac657 ca67a02c
Loading
Loading
Loading
Loading
+20 −33
Original line number Original line Diff line number Diff line
ifeq ($(strip $(BOARD_USES_EXTN_AUDIO_POLICY_MANAGER)),true)
ifneq ($(USE_LEGACY_AUDIO_POLICY), 1)

ifeq ($(USE_CUSTOM_AUDIO_POLICY), 1)
LOCAL_PATH := $(call my-dir)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(CLEAR_VARS)


LOCAL_SRC_FILES := AudioPolicyManager.cpp
LOCAL_SRC_FILES := AudioPolicyManager.cpp


LOCAL_C_INCLUDES := $(TOPDIR)frameworks/av/services \
                    $(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/engine/interface \
                    $(TOPDIR)frameworks/av/services/audiopolicy \
                    $(TOPDIR)frameworks/av/services/audiopolicy/common/managerdefinitions/include \
                    $(call include-path-for, avextension)


LOCAL_SHARED_LIBRARIES := \
LOCAL_SHARED_LIBRARIES := \
    libcutils \
    libcutils \
    libutils \
    libutils \
    liblog
    liblog \
    libsoundtrigger \
    libaudiopolicymanagerdefault \
    libserviceutility


LOCAL_STATIC_LIBRARIES := \
LOCAL_STATIC_LIBRARIES := \
    libmedia_helper
    libmedia_helper \

LOCAL_WHOLE_STATIC_LIBRARIES := \
    libaudiopolicy_legacy


LOCAL_MODULE := audio_policy.$(TARGET_BOARD_PLATFORM)
LOCAL_MODULE := libaudiopolicymanager
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_MODULE_TAGS := optional

ifeq ($(strip $(AUDIO_FEATURE_ENABLED_FM)),true)
LOCAL_CFLAGS += -DAUDIO_EXTN_FM_ENABLED
endif
ifeq ($(strip $(AUDIO_FEATURE_ENABLED_PROXY_DEVICE)),true)
LOCAL_CFLAGS += -DAUDIO_EXTN_AFE_PROXY_ENABLED
endif
ifeq ($(strip $(AUDIO_FEATURE_ENABLED_INCALL_MUSIC)),true)
LOCAL_CFLAGS += -DAUDIO_EXTN_INCALL_MUSIC_ENABLED
endif
ifeq ($(strip $(AUDIO_FEATURE_ENABLED_HDMI_SPK)),true)
LOCAL_CFLAGS += -DAUDIO_EXTN_HDMI_SPK_ENABLED
endif


ifeq ($(strip $(TARGET_BOARD_PLATFORM)),msm8916)
LOCAL_CFLAGS += -DVOICE_CONCURRENCY
LOCAL_CFLAGS += -DWFD_CONCURRENCY
endif

ifeq ($(strip $(AUDIO_FEATURE_ENABLED_MULTIPLE_TUNNEL)), true)
LOCAL_CFLAGS += -DMULTIPLE_OFFLOAD_ENABLED
endif


include $(BUILD_SHARED_LIBRARY)
include $(BUILD_SHARED_LIBRARY)


endif
endif
endif
+821 −917

File changed.

Preview size limit exceeded, changes collapsed.

+94 −59
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
 * Not a contribution.
 * Not a contribution.
 *
 *
 * Copyright (C) 2009 The Android Open Source Project
 * Copyright (C) 2009 The Android Open Source Project
@@ -18,82 +18,117 @@
 */
 */




#include <stdint.h>
#include <audiopolicy/managerdefault/AudioPolicyManager.h>
#include <sys/types.h>
#include <audio_policy_conf.h>
#include <utils/Timers.h>
#include <Volume.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <hardware_legacy/AudioPolicyManagerBase.h>




namespace android_audio_legacy {
namespace android {
#ifndef FLAC_OFFLOAD_ENABLED
#define AUDIO_FORMAT_FLAC 0x1D000000UL
#endif


#ifndef WMA_OFFLOAD_ENABLED
#define AUDIO_FORMAT_WMA 0x13000000UL
#define AUDIO_FORMAT_WMA_PRO 0x14000000UL
#endif

#ifndef ALAC_OFFLOAD_ENABLED
#define AUDIO_FORMAT_ALAC 0x1F000000UL
#endif

#ifndef APE_OFFLOAD_ENABLED
#define AUDIO_FORMAT_APE 0x20000000UL
#endif

#ifndef AFE_PROXY_ENABLED
#define AUDIO_DEVICE_OUT_PROXY 0x40000
#endif
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


class AudioPolicyManager: public AudioPolicyManagerBase
class AudioPolicyManagerCustom: public AudioPolicyManager
{
{


public:
public:
                AudioPolicyManager(AudioPolicyClientInterface *clientInterface)
                AudioPolicyManagerCustom(AudioPolicyClientInterface *clientInterface)
                : AudioPolicyManagerBase(clientInterface) {}
                : AudioPolicyManager(clientInterface) {
                    mHdmiAudioDisabled = false;
                    mHdmiAudioEvent = false;}

        virtual ~AudioPolicyManagerCustom() {}

        status_t setDeviceConnectionStateInt(audio_devices_t device,
                                          audio_policy_dev_state_t state,
                                          const char *device_address,
                                          const char *device_name);
        virtual void setPhoneState(audio_mode_t state);


        virtual ~AudioPolicyManager() {}


        virtual status_t setDeviceConnectionState(audio_devices_t device,
                                                          AudioSystem::device_connection_state state,
                                                          const char *device_address);
        virtual void setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config);
        virtual audio_io_handle_t getInput(int inputSource,
                                            uint32_t samplingRate,
                                            uint32_t format,
                                            uint32_t channels,
                                            AudioSystem::audio_in_acoustics acoustics);
        virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
        virtual bool isOffloadSupported(const audio_offload_info_t& offloadInfo);
        virtual void setPhoneState(int state);

        // true if given state represents a device in a telephony or VoIP call
protected:
protected:
        // return the strategy corresponding to a given stream type
        static routing_strategy getStrategy(AudioSystem::stream_type stream);

        // return appropriate device for streams handled by the specified strategy according to current
        // phone state, connected devices...
        // if fromCache is true, the device is returned from mDeviceForStrategy[],
        // otherwise it is determine by current state
        // (device connected,phone state, force use, a2dp output...)
        // This allows to:
        //  1 speed up process when the state is stable (when starting or stopping an output)
        //  2 access to either current device selection (fromCache == true) or
        // "future" device selection (fromCache == false) when called from a context
        //  where conditions are changing (setDeviceConnectionState(), setPhoneState()...) AND
        //  before updateDevicesAndOutputs() is called.
        virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy,
                                                     bool fromCache = true);
        // select input device corresponding to requested audio source
        virtual audio_devices_t getDeviceForInputSource(int inputSource);

        // compute the actual volume for a given stream according to the requested index and a particular
        // device
        virtual float computeVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device);

        // check that volume change is permitted, compute and send new volume to audio hardware
        status_t checkAndSetVolume(int stream, int index, audio_io_handle_t output, audio_devices_t device, int delayMs = 0, bool force = false);

        // returns the category the device belongs to with regard to volume curve management
        static device_category getDeviceCategory(audio_devices_t device);

        // returns true if give output is direct output
        bool isDirectOutput(audio_io_handle_t output);


        static const char* HDMI_SPKR_STR;
         status_t checkAndSetVolume(audio_stream_type_t stream,
                                                   int index,
                                                   const sp<SwAudioOutputDescriptor>& outputDesc,
                                                   audio_devices_t device,
                                                   int delayMs = 0, bool force = false);

        // selects the most appropriate device on output for current state
        // must be called every time a condition that affects the device choice for a given output is
        // changed: connected device, phone state, force use, output start, output stop..
        // see getDeviceForStrategy() for the use of fromCache parameter
        audio_devices_t getNewOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
                                           bool fromCache);
        // returns true if given output is direct output
        bool isDirectOutput(audio_io_handle_t output);


        //parameter indicates of HDMI speakers disabled from the Qualcomm settings
        // if argument "device" is different from AUDIO_DEVICE_NONE,  startSource() will force
        // the re-evaluation of the output device.
        status_t startSource(sp<SwAudioOutputDescriptor> outputDesc,
                             audio_stream_type_t stream,
                             audio_devices_t device,
                             uint32_t *delayMs);
         status_t stopSource(sp<SwAudioOutputDescriptor> outputDesc,
                            audio_stream_type_t stream,
                            bool forceDeviceUpdate);
        // event is one of STARTING_OUTPUT, STARTING_BEACON, STOPPING_OUTPUT, STOPPING_BEACON   313
        // returns 0 if no mute/unmute event happened, the largest latency of the device where   314
        //   the mute/unmute happened 315
        uint32_t handleEventForBeacon(int){return 0;}
        uint32_t setBeaconMute(bool){return 0;}

        // handle special cases for sonification strategy while in call: mute streams or replace by
        // a special tone in the device used for communication
        void handleIncallSonification(audio_stream_type_t stream, bool starting, bool stateChange, audio_io_handle_t output);
        //parameter indicates of HDMI speakers disabled
        bool mHdmiAudioDisabled;
        bool mHdmiAudioDisabled;

        //parameter indicates if HDMI plug in/out detected
        //parameter indicates if HDMI plug in/out detected
        bool mHdmiAudioEvent;
        bool mHdmiAudioEvent;

private:
private:
        static float volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
                int indexInUi);
        // updates device caching and output for streams that can influence the
        //    routing of notifications
        void handleNotificationRoutingForStream(audio_stream_type_t stream);
        static bool isVirtualInputDevice(audio_devices_t device);
        static bool deviceDistinguishesOnAddress(audio_devices_t device);
        uint32_t nextUniqueId();
        // internal method to return the output handle for the given device and format
        audio_io_handle_t getOutputForDevice(
                audio_devices_t device,
                audio_session_t session,
                audio_stream_type_t stream,
                uint32_t samplingRate,
                audio_format_t format,
                audio_channel_mask_t channelMask,
                audio_output_flags_t flags,
                const audio_offload_info_t *offloadInfo);
        // Used for voip + voice concurrency usecase
        // Used for voip + voice concurrency usecase
        int mPrevPhoneState;
        int mPrevPhoneState;
        int mvoice_call_state;


};
};

};
};