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

Commit 11d30104 authored by François Gaffie's avatar François Gaffie Committed by Eric Laurent
Browse files

audiopolicy: apm: Prepare the future: use DeviceDescriptor/DeviceVector



This patch updates the policy manager and common to widely use (vector of)
device descriptor rather than the device type mask each time it is possible.
It will allow taking into account the address of the device.

Test: manual audio smoke tests
Change-Id: I822097f1240d379b2f89aaad1e6609059942e61c
Signed-off-by: default avatarFrançois Gaffie <francois.gaffie@renault.com>
parent 526aa572
Loading
Loading
Loading
Loading
+14 −8
Original line number Diff line number Diff line
@@ -23,11 +23,12 @@
#include "AudioIODescriptorInterface.h"
#include "AudioPort.h"
#include "ClientDescriptor.h"
#include "DeviceDescriptor.h"
#include "EffectDescriptor.h"
#include "IOProfile.h"

namespace android {

class IOProfile;
class AudioMix;
class AudioPolicyClientInterface;

@@ -42,10 +43,16 @@ public:
    audio_port_handle_t getId() const;
    audio_module_handle_t getModuleHandle() const;

    audio_devices_t getDeviceType() const { return (mDevice != nullptr) ?
                    mDevice->type() : AUDIO_DEVICE_NONE; }
    sp<DeviceDescriptor> getDevice() const { return mDevice; }
    void setDevice(const sp<DeviceDescriptor> &device) { mDevice = device; }
    DeviceVector supportedDevices() const  {
        return mProfile != nullptr ? mProfile->getSupportedDevices() :  DeviceVector(); }

    void dump(String8 *dst) const override;

    audio_io_handle_t   mIoHandle = AUDIO_IO_HANDLE_NONE; // input handle
    audio_devices_t     mDevice = AUDIO_DEVICE_NONE;  // current device this input is routed to
    AudioMix            *mPolicyMix = nullptr;        // non NULL when used by a dynamic policy
    const sp<IOProfile> mProfile;                     // I/O profile this output derives from

@@ -71,8 +78,7 @@ public:
    void setPatchHandle(audio_patch_handle_t handle) override;

    status_t open(const audio_config_t *config,
                  audio_devices_t device,
                  const String8& address,
                  const sp<DeviceDescriptor> &device,
                  audio_source_t source,
                  audio_input_flags_t flags,
                  audio_io_handle_t *input);
@@ -99,6 +105,8 @@ public:

    audio_patch_handle_t mPatchHandle = AUDIO_PATCH_HANDLE_NONE;
    audio_port_handle_t  mId = AUDIO_PORT_HANDLE_NONE;
    sp<DeviceDescriptor> mDevice = nullptr; /**< current device this input is routed to */

    // Because a preemptible capture session can preempt another one, we end up in an endless loop
    // situation were each session is allowed to restart after being preempted,
    // thus preempting the other one which restarts and so on.
@@ -120,8 +128,8 @@ public:
    sp<AudioInputDescriptor> getInputFromId(audio_port_handle_t id) const;

    // count active capture sessions using one of the specified devices.
    // ignore devices if AUDIO_DEVICE_IN_DEFAULT is passed
    uint32_t activeInputsCountOnDevices(audio_devices_t devices = AUDIO_DEVICE_IN_DEFAULT) const;
    // ignore devices if empty vector is passed
    uint32_t activeInputsCountOnDevices(const DeviceVector &devices) const;

    /**
     * return io handle of active input or 0 if no input is active
@@ -130,8 +138,6 @@ public:
     */
    Vector<sp <AudioInputDescriptor> > getActiveInputs();

    audio_devices_t getSupportedDevices(audio_io_handle_t handle) const;

    sp<AudioInputDescriptor> getInputForClient(audio_port_handle_t portId);

    void trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled);
+55 −29
Original line number Diff line number Diff line
@@ -26,13 +26,14 @@
#include "AudioIODescriptorInterface.h"
#include "AudioPort.h"
#include "ClientDescriptor.h"
#include "DeviceDescriptor.h"
#include <map>

namespace android {

class IOProfile;
class AudioMix;
class AudioPolicyClientInterface;
class DeviceDescriptor;

// descriptor for audio outputs. Used to maintain current configuration of each opened audio output
// and keep track of the usage of this output by each audio stream type.
@@ -48,14 +49,12 @@ public:
    void        log(const char* indent);

    audio_port_handle_t getId() const;
    virtual audio_devices_t device() const;
    virtual bool sharesHwModuleWith(const sp<AudioOutputDescriptor>& outputDesc);
    virtual audio_devices_t supportedDevices();
    virtual DeviceVector devices() const { return mDevices; }
    bool sharesHwModuleWith(const sp<AudioOutputDescriptor>& outputDesc);
    virtual DeviceVector supportedDevices() const  { return mDevices; }
    virtual bool isDuplicated() const { return false; }
    virtual uint32_t latency() { return 0; }
    virtual bool isFixedVolume(audio_devices_t device);
    virtual sp<AudioOutputDescriptor> subOutput1() { return 0; }
    virtual sp<AudioOutputDescriptor> subOutput2() { return 0; }
    virtual bool setVolume(float volume,
                           audio_stream_type_t stream,
                           audio_devices_t device,
@@ -119,7 +118,7 @@ public:
        return mActiveClients;
    }

    audio_devices_t mDevice = AUDIO_DEVICE_NONE; // current device this output is routed to
    DeviceVector mDevices; /**< current devices this output is routed to */
    nsecs_t mStopTime[AUDIO_STREAM_CNT];
    int mMuteCount[AUDIO_STREAM_CNT];            // mute request counter
    bool mStrategyMutedByDevice[NUM_STRATEGIES]; // strategies muted because of incompatible
@@ -151,14 +150,15 @@ public:
    virtual ~SwAudioOutputDescriptor() {}

            void dump(String8 *dst) const override;
    virtual audio_devices_t device() const;
    virtual bool sharesHwModuleWith(const sp<AudioOutputDescriptor>& outputDesc);
    virtual audio_devices_t supportedDevices();
    virtual DeviceVector devices() const;
    void setDevices(const DeviceVector &devices) { mDevices = devices; }
    bool sharesHwModuleWith(const sp<SwAudioOutputDescriptor>& outputDesc);
    virtual DeviceVector supportedDevices() const;
    virtual uint32_t latency();
    virtual bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); }
    virtual bool isFixedVolume(audio_devices_t device);
    virtual sp<AudioOutputDescriptor> subOutput1() { return mOutput1; }
    virtual sp<AudioOutputDescriptor> subOutput2() { return mOutput2; }
    sp<SwAudioOutputDescriptor> subOutput1() { return mOutput1; }
    sp<SwAudioOutputDescriptor> subOutput2() { return mOutput2; }
            void changeStreamActiveCount(
                    const sp<TrackClientDescriptor>& client, int delta) override;
    virtual bool setVolume(float volume,
@@ -172,11 +172,11 @@ public:
    virtual void toAudioPort(struct audio_port *port) const;

        status_t open(const audio_config_t *config,
                          audio_devices_t device,
                          const String8& address,
                      const DeviceVector &devices,
                      audio_stream_type_t stream,
                      audio_output_flags_t flags,
                      audio_io_handle_t *output);

        // Called when a stream is about to be started
        // Note: called before setClientActive(true);
        status_t start();
@@ -188,6 +188,33 @@ public:
                                 const sp<SwAudioOutputDescriptor>& output2,
                                 audio_io_handle_t *ioHandle);

    /**
     * @brief supportsDevice
     * @param device to be checked against
     * @return true if the device is supported by type (for non bus / remote submix devices),
     *         true if the device is supported (both type and address) for bus / remote submix
     *         false otherwise
     */
    bool supportsDevice(const sp<DeviceDescriptor> &device) const;

    /**
     * @brief supportsAllDevices
     * @param devices to be checked against
     * @return true if the device is weakly supported by type (e.g. for non bus / rsubmix devices),
     *         true if the device is supported (both type and address) for bus / remote submix
     *         false otherwise
     */
    bool supportsAllDevices(const DeviceVector &devices) const;

    /**
     * @brief filterSupportedDevices takes a vector of devices and filters them according to the
     * device supported by this output (the profile from which this output derives from)
     * @param devices reference device vector to be filtered
     * @return vector of devices filtered from the supported devices of this output (weakly or not
     * depending on the device type)
     */
    DeviceVector filterSupportedDevices(const DeviceVector &devices) const;

    const sp<IOProfile> mProfile;          // I/O profile this output derives from
    audio_io_handle_t mIoHandle;           // output handle
    uint32_t mLatency;                  //
@@ -208,7 +235,6 @@ public:

            void dump(String8 *dst) const override;

    virtual audio_devices_t supportedDevices();
    virtual bool setVolume(float volume,
                           audio_stream_type_t stream,
                           audio_devices_t device,
+4 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#pragma once

#include "DeviceDescriptor.h"
#include <utils/RefBase.h>
#include <media/AudioPolicy.h>
#include <utils/KeyedVector.h>
@@ -74,8 +75,8 @@ public:
    status_t getOutputForAttr(audio_attributes_t attributes, uid_t uid,
            sp<SwAudioOutputDescriptor> &desc);

    audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource,
                                                  audio_devices_t availableDeviceTypes,
    sp<DeviceDescriptor> getDeviceAndMixForInputSource(audio_source_t inputSource,
                                                       const DeviceVector &availableDeviceTypes,
                                                       AudioMix **policyMix);

    status_t getInputMixForAttr(audio_attributes_t attr, AudioMix **policyMix);
+19 −0
Original line number Diff line number Diff line
@@ -125,6 +125,8 @@ 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
@@ -164,6 +166,23 @@ public:
        return !operator==(right);
    }

    /**
     * @brief getFirstValidAddress
     * @return the first valid address of a list of device, "" if no device with valid address
     * found.
     * This helper function helps maintaining compatibility with legacy where we used to have a
     * devices mask and an address.
     */
    String8 getFirstValidAddress() const
    {
        for (const auto &device : *this) {
            if (device->address() != "") {
                return device->address();
            }
        }
        return String8("");
    }

    std::string toString() const;

    void dump(String8 *dst, const String8 &tag, int spaces = 0, bool verbose = true) const;
+6 −1
Original line number Diff line number Diff line
@@ -113,7 +113,12 @@ class HwModuleCollection : public Vector<sp<HwModule> >
public:
    sp<HwModule> getModuleFromName(const char *name) const;

    sp<HwModule> getModuleForDevice(audio_devices_t device) const;
    sp<HwModule> getModuleForDeviceTypes(audio_devices_t device) const;

    sp<HwModule> getModuleForDevice(const sp<DeviceDescriptor> &device) const;

    DeviceVector getAvailableDevicesFromModuleName(const char *name,
                                                   const DeviceVector &availableDevices) const;

    sp<DeviceDescriptor> getDeviceDescriptor(const audio_devices_t device,
                                             const char *device_address,
Loading