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

Commit 716e1435 authored by Francois Gaffie's avatar Francois Gaffie Committed by Eric Laurent
Browse files

audiopolicy: fix rsubmix / device with dynamic address regressions



Orphan devices (aka devices not declared in configuration file) used to be
managed by apm::mAvailable<Output|Input>Devices and affinity with profile
was done by type only.
As the device affinity with profile is now enforced by checking with descriptor
rather than with type, profile's supported devices list shall be dynamically
updated.

Test: manual audio smoke tests
Change-Id: I5e8092968bbdb03ac7dc1aa1a3f15a0bc1b09251
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 11d30104
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ public:
    bool isSourceActive(audio_source_t source) const;
    audio_source_t source() const;
    bool isSoundTrigger() const;
    audio_attributes_t getHighestPriorityAttributes() const;
    void setClientActive(const sp<RecordClientDescriptor>& client, bool active);
    int32_t activeCount() { return mGlobalActiveCount; }
    void trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled);
+2 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public:
    uint32_t getFlags() const { return mFlags; }

    virtual void attach(const sp<HwModule>& module);
    virtual void detach();
    bool isAttached() { return mModule != 0; }

    // Audio port IDs are in a different namespace than AudioFlinger unique IDs
@@ -161,7 +162,7 @@ public:
                                   const struct audio_port_config *srcConfig = NULL) const = 0;
    virtual sp<AudioPort> getAudioPort() const = 0;
    virtual bool hasSameHwModuleAs(const sp<AudioPortConfig>& other) const {
        return (other != 0) &&
        return (other != 0) && (other->getAudioPort() != 0) && (getAudioPort() != 0) &&
                (other->getAudioPort()->getModuleHandle() == getAudioPort()->getModuleHandle());
    }
    unsigned int mSamplingRate = 0u;
+2 −2
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public:

    // AudioPort
    virtual void attach(const sp<HwModule>& module);
    virtual void detach();

    virtual void toAudioPort(struct audio_port *port) const;
    virtual void importAudioPort(const sp<AudioPort>& port, bool force = false);

@@ -125,8 +127,6 @@ public:
     */
    DeviceVector filter(const DeviceVector &devices) const;

    DeviceVector filter(audio_devices_t deviceTypes) const;

    /**
     * @brief merge two vectors. As SortedVector Implementation is buggy (it does not check the size
     * of the destination vector, only of the source, it provides a safe implementation
+60 −3
Original line number Diff line number Diff line
@@ -46,6 +46,22 @@ public:

    const DeviceVector &getDeclaredDevices() const { return mDeclaredDevices; }
    void setDeclaredDevices(const DeviceVector &devices);
    DeviceVector getAllDevices() const
    {
        DeviceVector devices = mDeclaredDevices;
        devices.merge(mDynamicDevices);
        return devices;
    }
    void addDynamicDevice(const sp<DeviceDescriptor> &device)
    {
        mDynamicDevices.add(device);
    }

    bool removeDynamicDevice(const sp<DeviceDescriptor> &device)
    {
        return mDynamicDevices.remove(device) >= 0;
    }
    DeviceVector getDynamicDevices() const { return mDynamicDevices; }

    const InputProfileCollection &getInputProfiles() const { return mInputProfiles; }
    const OutputProfileCollection &getOutputProfiles() const { return mOutputProfiles; }
@@ -104,6 +120,7 @@ private:
    InputProfileCollection mInputProfiles;  // input profiles exposed by this module
    uint32_t mHalVersion; // audio HAL API version
    DeviceVector mDeclaredDevices; // devices declared in audio_policy configuration file.
    DeviceVector mDynamicDevices; /**< devices that can be added/removed at runtime (e.g. rsbumix)*/
    AudioRouteVector mRoutes;
    AudioPortVector mPorts;
};
@@ -120,11 +137,51 @@ public:
    DeviceVector getAvailableDevicesFromModuleName(const char *name,
                                                   const DeviceVector &availableDevices) const;

    sp<DeviceDescriptor> getDeviceDescriptor(const audio_devices_t device,
                                             const char *device_address,
                                             const char *device_name,
    /**
     * @brief getDeviceDescriptor returns a device descriptor associated to the device type and
     * device address (if matchAddress is true).
     * It may loop twice on all modules to check if allowToCreate is true
     *      -first loop will check if the device is found on a module since declared in the list
     * of device port in configuration file
     *      -(allowToCreate is true)second loop will check if the device is weakly supported by one
     * or more profiles on a given module and will add as a supported device for this module.
     *       The device will also be added to the dynamic list of device of this module
     * @param type of the device requested
     * @param address of the device requested
     * @param name of the device that requested
     * @param matchAddress true if a strong match is required
     * @param allowToCreate true if allowed to create dynamic device (e.g. hdmi, usb...)
     * @return device descriptor associated to the type (and address if matchAddress is true)
     */
    sp<DeviceDescriptor> getDeviceDescriptor(const audio_devices_t type,
                                             const char *address,
                                             const char *name,
                                             bool allowToCreate = false,
                                             bool matchAddress = true) const;

    /**
     * @brief createDevice creates a new device from the type and address given. It checks that
     * according to the device type, a module is supporting this device (weak check).
     * This concerns only dynamic device, aka device with a specific address and not
     * already supported by module/underlying profiles.
     * @param type of the device to be created
     * @param address of the device to be created
     * @param name of the device to be created
     * @return device descriptor if a module is supporting this type, nullptr otherwise.
     */
    sp<DeviceDescriptor> createDevice(const audio_devices_t type,
                                      const char *address,
                                      const char *name) const;

    /**
     * @brief cleanUpForDevice: loop on all profiles of all modules to remove device from
     * the list of supported device. If this device is a dynamic device (aka a device not in the
     * xml file with a runtime address), it is also removed from the module collection of dynamic
     * devices.
     * @param device that has been disconnected
     */
    void cleanUpForDevice(const sp<DeviceDescriptor> &device);

    void dump(String8 *dst) const;
};

+4 −20
Original line number Diff line number Diff line
@@ -99,11 +99,6 @@ public:
        return mSupportedDevices.types() & (device & ~AUDIO_DEVICE_BIT_IN);
    }

    bool supportDeviceAddress(const String8 &address) const
    {
        return mSupportedDevices[0]->address() == address;
    }

    /**
     * @brief supportsDevice
     * @param device to be checked against
@@ -121,26 +116,15 @@ public:
        return mSupportedDevices.contains(device);
    }

    // chose first device present in mSupportedDevices also part of deviceType
    audio_devices_t getSupportedDeviceForType(audio_devices_t deviceType) const
    {
        for (size_t k = 0; k  < mSupportedDevices.size(); k++) {
            audio_devices_t profileType = mSupportedDevices[k]->type();
            if (profileType & deviceType) {
                return profileType;
            }
        }
        return AUDIO_DEVICE_NONE;
    }

    audio_devices_t getSupportedDevicesType() const { return mSupportedDevices.types(); }

    void clearSupportedDevices() { mSupportedDevices.clear(); }
    void addSupportedDevice(const sp<DeviceDescriptor> &device)
    {
        mSupportedDevices.add(device);
    }

    void removeSupportedDevice(const sp<DeviceDescriptor> &device)
    {
        mSupportedDevices.remove(device);
    }
    void setSupportedDevices(const DeviceVector &devices)
    {
        mSupportedDevices = devices;
Loading