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

Commit 1afeecb8 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: parse device descriptors in config file

Implement parsing of audio_policy.conf for device and gain
controller definitions.
Copy audio_policy_conf.h from hardware_legacy.
New syntax for devices and gain controllers description will not
be parsed by legacy audio policy manager.

Bug: 14815883.

Change-Id: I7f1035d514dcf55fb3e45ed1f633a2f63ee398f5
parent b52c152d
Loading
Loading
Loading
Loading
+431 −166

File changed.

Preview size limit exceeded, changes collapsed.

+54 −28
Original line number Diff line number Diff line
@@ -190,26 +190,25 @@ protected:
            DEVICE_CATEGORY_CNT
        };

        class IOProfile;
        class HwModule;

        class HwModule {
        class AudioGain: public RefBase
        {
        public:
                    HwModule(const char *name);
                    ~HwModule();
            AudioGain();
            virtual ~AudioGain() {}

            void dump(int fd);
            void dump(int fd, int spaces, int index) const;

            const char *const mName; // base name of the audio HW module (primary, a2dp ...)
            audio_module_handle_t mHandle;
            Vector < sp<IOProfile> > mOutputProfiles; // output profiles exposed by this module
            Vector < sp<IOProfile> > mInputProfiles;  // input profiles exposed by this module
            struct audio_gain mGain;
        };

        class AudioPort: public RefBase
        {
        public:
            AudioPort(audio_port_type_t type, audio_port_role_t role, HwModule *module) :
                mType(type), mRole(role), mModule(module) {}
            AudioPort(const String8& name, audio_port_type_t type,
                      audio_port_role_t role, HwModule *module) :
                mName(name), mType(type), mRole(role), mModule(module) {}
            virtual ~AudioPort() {}

            virtual void toAudioPort(struct audio_port *port) const;
@@ -219,6 +218,13 @@ protected:
            void loadOutChannels(char *name);
            void loadInChannels(char *name);

            audio_gain_mode_t loadGainMode(char *name);
            void loadGain(cnode *root);
            void loadGains(cnode *root);

            void dump(int fd, int spaces) const;

            String8           mName;
            audio_port_type_t mType;
            audio_port_role_t mRole;
            // by convention, "0' in the first entry in mSamplingRates, mChannelMasks or mFormats
@@ -227,6 +233,7 @@ protected:
            Vector <uint32_t> mSamplingRates; // supported sampling rates
            Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks
            Vector <audio_format_t> mFormats; // supported audio formats
            Vector < sp<AudioGain> > mGains; // gain controllers
            HwModule *mModule;                 // audio HW module exposing this I/O stream
        };

@@ -246,17 +253,17 @@ protected:
        class DeviceDescriptor: public AudioPort
        {
        public:
            DeviceDescriptor(audio_devices_t type, String8 address,
            DeviceDescriptor(const String8& name, audio_devices_t type, String8 address,
                             audio_channel_mask_t channelMask) :
                                 AudioPort(AUDIO_PORT_TYPE_DEVICE,
                                 AudioPort(name, AUDIO_PORT_TYPE_DEVICE,
                                           audio_is_output_device(type) ? AUDIO_PORT_ROLE_SINK :
                                                                          AUDIO_PORT_ROLE_SOURCE,
                                         NULL),
                                 mDeviceType(type), mAddress(address),
                                 mChannelMask(channelMask), mId(0) {}

            DeviceDescriptor(audio_devices_t type) :
                                AudioPort(AUDIO_PORT_TYPE_DEVICE,
            DeviceDescriptor(String8 name, audio_devices_t type) :
                                AudioPort(name, AUDIO_PORT_TYPE_DEVICE,
                                          audio_is_output_device(type) ? AUDIO_PORT_ROLE_SINK :
                                                                         AUDIO_PORT_ROLE_SOURCE,
                                        NULL),
@@ -267,10 +274,10 @@ protected:
            bool equals(const sp<DeviceDescriptor>& other) const;
            void toAudioPortConfig(struct audio_port_config *dstConfig,
                                   const struct audio_port_config *srcConfig = NULL) const;

            virtual void toAudioPort(struct audio_port *port) const;

            status_t dump(int fd, int spaces) const;
            static void dumpHeader(int fd, int spaces);
            status_t dump(int fd, int spaces, int index) const;

            audio_devices_t mDeviceType;
            String8 mAddress;
@@ -290,9 +297,12 @@ protected:
            audio_devices_t types() const { return mDeviceTypes; }

            void loadDevicesFromType(audio_devices_t types);
            void loadDevicesFromName(char *name, const DeviceVector& declaredDevices);

            sp<DeviceDescriptor> getDevice(audio_devices_t type, String8 address) const;
            DeviceVector getDevicesFromType(audio_devices_t types) const;
            sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const;
            sp<DeviceDescriptor> getDeviceFromName(const String8& name) const;

        private:
            void refreshTypes();
@@ -307,7 +317,7 @@ protected:
        class IOProfile : public AudioPort
        {
        public:
            IOProfile(audio_port_role_t role, HwModule *module);
            IOProfile(const String8& name, audio_port_role_t role, HwModule *module);
            virtual ~IOProfile();

            bool isCompatibleProfile(audio_devices_t device,
@@ -325,6 +335,25 @@ protected:
                                                // direct output...). For outputs only.
        };

        class HwModule {
        public:
                    HwModule(const char *name);
                    ~HwModule();

            status_t loadOutput(cnode *root);
            status_t loadInput(cnode *root);
            status_t loadDevice(cnode *root);

            void dump(int fd);

            const char *const mName; // base name of the audio HW module (primary, a2dp ...)
            audio_module_handle_t mHandle;
            Vector < sp<IOProfile> > mOutputProfiles; // output profiles exposed by this module
            Vector < sp<IOProfile> > mInputProfiles;  // input profiles exposed by this module
            DeviceVector             mDeclaredDevices; // devices declared in audio_policy.conf

        };

        // default volume curve
        static const VolumeCurvePoint sDefaultVolumeCurve[AudioPolicyManager::VOLCNT];
        // default volume curve for media strategy
@@ -633,6 +662,7 @@ protected:
        AudioOutputDescriptor *getOutputFromId(audio_port_handle_t id) const;
        AudioInputDescriptor *getInputFromId(audio_port_handle_t id) const;
        HwModule *getModuleForDevice(audio_devices_t device) const;
        HwModule *getModuleFromName(const char *name) const;
        //
        // Audio policy configuration file parsing (audio_policy.conf)
        //
@@ -645,11 +675,9 @@ protected:
        static bool stringToBool(const char *value);
        static audio_output_flags_t parseFlagNames(char *name);
        static audio_devices_t parseDeviceNames(char *name);
        status_t loadOutput(cnode *root,  HwModule *module);
        status_t loadInput(cnode *root,  HwModule *module);
        void loadHwModule(cnode *root);
        void loadHwModules(cnode *root);
        void loadGlobalConfig(cnode *root);
        void loadGlobalConfig(cnode *root, HwModule *module);
        status_t loadAudioPolicyConfig(const char *path);
        void defaultAudioPolicyConfig(void);

@@ -663,10 +691,8 @@ protected:
        // reset to mOutputs when updateDevicesAndOutputs() is called.
        DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mPreviousOutputs;
        DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs;     // list of input descriptors
        DeviceVector  mAvailableOutputDevices; // bit field of all available output devices
        DeviceVector  mAvailableInputDevices; // bit field of all available input devices
                                                // without AUDIO_DEVICE_BIT_IN to allow direct bit
                                                // field comparisons
        DeviceVector  mAvailableOutputDevices; // all available output devices
        DeviceVector  mAvailableInputDevices;  // all available input devices
        int mPhoneState;                                                    // current phone state
        audio_policy_forced_cfg_t mForceUse[AUDIO_POLICY_FORCE_USE_CNT];   // current forced use configuration

+76 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.
 */


#ifndef ANDROID_AUDIO_POLICY_CONF_H
#define ANDROID_AUDIO_POLICY_CONF_H


/////////////////////////////////////////////////
//      Definitions for audio policy configuration file (audio_policy.conf)
/////////////////////////////////////////////////

#define AUDIO_HARDWARE_MODULE_ID_MAX_LEN 32

#define AUDIO_POLICY_CONFIG_FILE "/system/etc/audio_policy.conf"
#define AUDIO_POLICY_VENDOR_CONFIG_FILE "/vendor/etc/audio_policy.conf"

// global configuration
#define GLOBAL_CONFIG_TAG "global_configuration"

#define ATTACHED_OUTPUT_DEVICES_TAG "attached_output_devices"
#define DEFAULT_OUTPUT_DEVICE_TAG "default_output_device"
#define ATTACHED_INPUT_DEVICES_TAG "attached_input_devices"
#define SPEAKER_DRC_ENABLED_TAG "speaker_drc_enabled"

// hw modules descriptions
#define AUDIO_HW_MODULE_TAG "audio_hw_modules"

#define OUTPUTS_TAG "outputs"
#define INPUTS_TAG "inputs"

#define SAMPLING_RATES_TAG "sampling_rates"
#define FORMATS_TAG "formats"
#define CHANNELS_TAG "channel_masks"
#define DEVICES_TAG "devices"
#define FLAGS_TAG "flags"

#define DYNAMIC_VALUE_TAG "dynamic" // special value for "channel_masks", "sampling_rates" and
                                    // "formats" in outputs descriptors indicating that supported
                                    // values should be queried after opening the output.

#define DEVICES_TAG "devices"
#define DEVICE_TYPE "type"
#define DEVICE_ADDRESS "address"

#define MIXERS_TAG "mixers"
#define MIXER_TYPE "type"
#define MIXER_TYPE_MUX "mux"
#define MIXER_TYPE_MIX "mix"

#define GAINS_TAG "gains"
#define GAIN_MODE "mode"
#define GAIN_CHANNELS "channel_mask"
#define GAIN_MIN_VALUE "min_value_mB"
#define GAIN_MAX_VALUE "max_value_mB"
#define GAIN_DEFAULT_VALUE "default_value_mB"
#define GAIN_STEP_VALUE "step_value_mB"
#define GAIN_MIN_RAMP_MS "min_ramp_ms"
#define GAIN_MAX_RAMP_MS "max_ramp_ms"



#endif  // ANDROID_AUDIO_POLICY_CONF_H