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

Commit 1cbfc5d1 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge changes Ic9ecd592,I5e809296,I822097f1

* changes:
  audiopolicy: apm: Fix segfault when using bus device without Policy Mix
  audiopolicy: fix rsubmix / device with dynamic address regressions
  audiopolicy: apm: Prepare the future: use DeviceDescriptor/DeviceVector
parents bf06f7af b141c526
Loading
Loading
Loading
Loading
+15 −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

@@ -61,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);
@@ -71,8 +79,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 +106,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 +129,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 +139,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);
+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;
+19 −0
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);

@@ -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;
Loading