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

Commit 3a4311c6 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: use new audio device representation

Represent audio devices with more attributes than just the
type (audio_device_t).
This is in preparation for new routing APIs allowing
device selection based on more criteria than just the type
(address, channel mask...)
A new class DeviceDescriptor is created and used by functions
needing more information than just the device type.
Bit fields for available and supported input or output devices are
replaced by vectors of device descriptors.
Each available device is allocated a unique ID for future use.
Removed obsolete mA2dpDeviceAddress, mScoDeviceAddress and mUsbCardAndDevice
fields replaced by address stored in DeviceDescriptor.

Policy decisions like getDeviceForStrategy() are still based
only on the device type.

Change-Id: I5de3b3ffb12ff8dcfb746782ab1e6b15bf040d0c
parent 172a7a96
Loading
Loading
Loading
Loading
+495 −269

File changed.

Preview size limit exceeded, changes collapsed.

+54 −12
Original line number Original line Diff line number Diff line
@@ -175,6 +175,47 @@ protected:


        class IOProfile;
        class IOProfile;


        class DeviceDescriptor: public RefBase
        {
        public:
            DeviceDescriptor(audio_devices_t type, String8 address,
                             audio_channel_mask_t channelMask) :
                                 mType(type), mAddress(address),
                                 mChannelMask(channelMask), mId(0) {}

            DeviceDescriptor(audio_devices_t type) :
                                 mType(type), mAddress(""),
                                 mChannelMask(AUDIO_CHANNEL_NONE), mId(0) {}

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

            bool equals(const sp<DeviceDescriptor>& other) const;

            audio_devices_t mType;
            String8 mAddress;
            audio_channel_mask_t mChannelMask;
            uint32_t mId;
        };

        class DeviceVector : public SortedVector< sp<DeviceDescriptor> >
        {
        public:
            DeviceVector() : SortedVector(), mTypes(AUDIO_DEVICE_NONE) {}

            ssize_t         add(const sp<DeviceDescriptor>& item);
            ssize_t         remove(const sp<DeviceDescriptor>& item);
            ssize_t         indexOf(const sp<DeviceDescriptor>& item) const;

            audio_devices_t types() const { return mTypes; }

            void loadDevicesFromType(audio_devices_t types);

        private:
            void refreshTypes();
            audio_devices_t mTypes;
        };

        class HwModule {
        class HwModule {
        public:
        public:
                    HwModule(const char *name);
                    HwModule(const char *name);
@@ -213,8 +254,8 @@ protected:
            Vector <uint32_t> mSamplingRates; // supported sampling rates
            Vector <uint32_t> mSamplingRates; // supported sampling rates
            Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks
            Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks
            Vector <audio_format_t> mFormats; // supported audio formats
            Vector <audio_format_t> mFormats; // supported audio formats
            audio_devices_t mSupportedDevices; // supported devices (devices this output can be
            DeviceVector  mSupportedDevices; // supported devices
                                               // routed to)
                                             // (devices this output can be routed to)
            audio_output_flags_t mFlags; // attribute flags (e.g primary output,
            audio_output_flags_t mFlags; // attribute flags (e.g primary output,
                                                // direct output...). For outputs only.
                                                // direct output...). For outputs only.
            HwModule *mModule;                     // audio HW module exposing this I/O stream
            HwModule *mModule;                     // audio HW module exposing this I/O stream
@@ -411,7 +452,7 @@ protected:
        status_t checkOutputsForDevice(audio_devices_t device,
        status_t checkOutputsForDevice(audio_devices_t device,
                                       audio_policy_dev_state_t state,
                                       audio_policy_dev_state_t state,
                                       SortedVector<audio_io_handle_t>& outputs,
                                       SortedVector<audio_io_handle_t>& outputs,
                                       const String8 paramStr);
                                       const String8 address);


        // close an output and its companion duplicating output.
        // close an output and its companion duplicating output.
        void closeOutput(audio_io_handle_t output);
        void closeOutput(audio_io_handle_t output);
@@ -496,6 +537,9 @@ protected:
        static uint32_t stringToEnum(const struct StringToEnum *table,
        static uint32_t stringToEnum(const struct StringToEnum *table,
                                     size_t size,
                                     size_t size,
                                     const char *name);
                                     const char *name);
        static const char *enumToString(const struct StringToEnum *table,
                                      size_t size,
                                      uint32_t value);
        static bool stringToBool(const char *value);
        static bool stringToBool(const char *value);
        static audio_output_flags_t parseFlagNames(char *name);
        static audio_output_flags_t parseFlagNames(char *name);
        static audio_devices_t parseDeviceNames(char *name);
        static audio_devices_t parseDeviceNames(char *name);
@@ -520,18 +564,14 @@ protected:
        // reset to mOutputs when updateDevicesAndOutputs() is called.
        // reset to mOutputs when updateDevicesAndOutputs() is called.
        DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mPreviousOutputs;
        DefaultKeyedVector<audio_io_handle_t, AudioOutputDescriptor *> mPreviousOutputs;
        DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs;     // list of input descriptors
        DefaultKeyedVector<audio_io_handle_t, AudioInputDescriptor *> mInputs;     // list of input descriptors
        audio_devices_t mAvailableOutputDevices; // bit field of all available output devices
        DeviceVector  mAvailableOutputDevices; // bit field of all available output devices
        audio_devices_t mAvailableInputDevices; // bit field of all available input devices
        DeviceVector  mAvailableInputDevices; // bit field of all available input devices
                                                // without AUDIO_DEVICE_BIT_IN to allow direct bit
                                                // without AUDIO_DEVICE_BIT_IN to allow direct bit
                                                // field comparisons
                                                // field comparisons
        int mPhoneState;                                                    // current phone state
        int mPhoneState;                                                    // current phone state
        audio_policy_forced_cfg_t mForceUse[AUDIO_POLICY_FORCE_USE_CNT];   // current forced use configuration
        audio_policy_forced_cfg_t mForceUse[AUDIO_POLICY_FORCE_USE_CNT];   // current forced use configuration


        StreamDescriptor mStreams[AUDIO_STREAM_CNT];           // stream descriptors for volume control
        StreamDescriptor mStreams[AUDIO_STREAM_CNT];           // stream descriptors for volume control
        String8 mA2dpDeviceAddress;                                         // A2DP device MAC address
        String8 mScoDeviceAddress;                                          // SCO device MAC address
        String8 mUsbCardAndDevice; // USB audio ALSA card and device numbers:
                                   // card=<card_number>;device=<><device_number>
        bool    mLimitRingtoneVolume;                                       // limit ringtone volume to music volume if headset connected
        bool    mLimitRingtoneVolume;                                       // limit ringtone volume to music volume if headset connected
        audio_devices_t mDeviceForStrategy[NUM_STRATEGIES];
        audio_devices_t mDeviceForStrategy[NUM_STRATEGIES];
        float   mLastVoiceVolume;                                           // last voice volume value sent to audio HAL
        float   mLastVoiceVolume;                                           // last voice volume value sent to audio HAL
@@ -547,13 +587,12 @@ protected:
        bool mHasA2dp; // true on platforms with support for bluetooth A2DP
        bool mHasA2dp; // true on platforms with support for bluetooth A2DP
        bool mHasUsb; // true on platforms with support for USB audio
        bool mHasUsb; // true on platforms with support for USB audio
        bool mHasRemoteSubmix; // true on platforms with support for remote presentation of a submix
        bool mHasRemoteSubmix; // true on platforms with support for remote presentation of a submix
        audio_devices_t mAttachedOutputDevices; // output devices always available on the platform
        sp<DeviceDescriptor> mDefaultOutputDevice; // output device selected by default at boot time
        audio_devices_t mDefaultOutputDevice; // output device selected by default at boot time
                                              // (must be in mAttachedOutputDevices)
        bool mSpeakerDrcEnabled;// true on devices that use DRC on the DEVICE_CATEGORY_SPEAKER path
        bool mSpeakerDrcEnabled;// true on devices that use DRC on the DEVICE_CATEGORY_SPEAKER path
                                // to boost soft sounds, used to adjust volume curves accordingly
                                // to boost soft sounds, used to adjust volume curves accordingly


        Vector <HwModule *> mHwModules;
        Vector <HwModule *> mHwModules;
        volatile int32_t mNextUniqueId;


#ifdef AUDIO_POLICY_TEST
#ifdef AUDIO_POLICY_TEST
        Mutex   mLock;
        Mutex   mLock;
@@ -577,6 +616,9 @@ private:
        //    routing of notifications
        //    routing of notifications
        void handleNotificationRoutingForStream(audio_stream_type_t stream);
        void handleNotificationRoutingForStream(audio_stream_type_t stream);
        static bool isVirtualInputDevice(audio_devices_t device);
        static bool isVirtualInputDevice(audio_devices_t device);
        uint32_t nextUniqueId();
        // converts device address to string sent to audio HAL via setParameters
        static String8 addressToParameter(audio_devices_t device, const String8 address);
};
};


};
};