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

Commit 322b4d25 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio policy: fix unique audio port ID.

Remove mId member from AudioPort as it was shadowed
by mId in DeviceDescriptor.

Add getters for Id, and HW module name and version to device,
output and input descriptors.

Fix DeviceDescriptor name initialization.

Change-Id: I4a69f385e40330954d9dad5f2926c521f60b2ec1
parent 6dc4dc4a
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -34,12 +34,11 @@ class AudioInputDescriptor: public AudioPortConfig
public:
    AudioInputDescriptor(const sp<IOProfile>& profile);
    void setIoHandle(audio_io_handle_t ioHandle);

    audio_port_handle_t getId() const;
    audio_module_handle_t getModuleHandle() const;

    status_t    dump(int fd);

    audio_port_handle_t           mId;
    audio_io_handle_t             mIoHandle;       // input handle
    audio_devices_t               mDevice;         // current device this input is routed to
    AudioMix                      *mPolicyMix;     // non NULL when used by a dynamic policy
@@ -57,6 +56,9 @@ public:
            const struct audio_port_config *srcConfig = NULL) const;
    virtual sp<AudioPort> getAudioPort() const { return mProfile; }
    void toAudioPort(struct audio_port *port) const;

private:
    audio_port_handle_t           mId;
};

class AudioInputCollection :
+4 −2
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ public:

    audio_devices_t device() const;
    void changeRefCount(audio_stream_type_t stream, int delta);

    audio_port_handle_t getId() const;
    void setIoHandle(audio_io_handle_t ioHandle);
    bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); }
    audio_devices_t supportedDevices();
@@ -58,7 +58,6 @@ public:

    audio_module_handle_t getModuleHandle() const;

    audio_port_handle_t mId;
    audio_io_handle_t mIoHandle;              // output handle
    uint32_t mLatency;                  //
    audio_output_flags_t mFlags;   //
@@ -75,6 +74,9 @@ public:
    bool mStrategyMutedByDevice[NUM_STRATEGIES]; // strategies muted because of incompatible
                                        // device selection. See checkDeviceMuteStrategies()
    uint32_t mDirectOpenCount; // number of clients using this output (direct outputs only)

private:
    audio_port_handle_t mId;
};

class AudioOutputCollection :
+5 −12
Original line number Diff line number Diff line
@@ -32,13 +32,11 @@ class AudioPort : public virtual RefBase
{
public:
    AudioPort(const String8& name, audio_port_type_t type,
              audio_port_role_t role, const sp<HwModule>& module);
              audio_port_role_t role);
    virtual ~AudioPort() {}

    audio_port_handle_t getHandle() { return mId; }

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

    static audio_port_handle_t getNextUniqueId();

@@ -76,6 +74,8 @@ public:
    static int compareFormats(audio_format_t format1, audio_format_t format2);

    audio_module_handle_t getModuleHandle() const;
    uint32_t getModuleVersion() const;
    const char *getModuleName() const;

    void dump(int fd, int spaces) const;
    void log(const char* indent) const;
@@ -95,13 +95,6 @@ public:
    uint32_t mFlags; // attribute flags (e.g primary output,
                     // direct output...).


protected:
    //TODO - clarify the role of mId in this case, both an "attached" indicator
    // and a unique ID for identifying a port to the (upcoming) selection API,
    // and its relationship to the mId in AudioOutputDescriptor and AudioInputDescriptor.
    audio_port_handle_t mId;

private:
    static volatile int32_t mNextUniqueId;
};
+53 −1
Original line number Diff line number Diff line
@@ -39,11 +39,12 @@ struct StringToEnum {
};

#define STRING_TO_ENUM(string) { #string, string }
#define NAME_TO_ENUM(name, value) { name, value }
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif

const StringToEnum sDeviceNameToEnumTable[] = {
const StringToEnum sDeviceTypeToEnumTable[] = {
    STRING_TO_ENUM(AUDIO_DEVICE_OUT_EARPIECE),
    STRING_TO_ENUM(AUDIO_DEVICE_OUT_SPEAKER),
    STRING_TO_ENUM(AUDIO_DEVICE_OUT_SPEAKER_SAFE),
@@ -94,6 +95,57 @@ const StringToEnum sDeviceNameToEnumTable[] = {
    STRING_TO_ENUM(AUDIO_DEVICE_IN_LOOPBACK),
};

const StringToEnum sDeviceNameToEnumTable[] = {
    NAME_TO_ENUM("Earpiece", AUDIO_DEVICE_OUT_EARPIECE),
    NAME_TO_ENUM("Speaker", AUDIO_DEVICE_OUT_SPEAKER),
    NAME_TO_ENUM("Speaker Protected", AUDIO_DEVICE_OUT_SPEAKER_SAFE),
    NAME_TO_ENUM("Wired Headset", AUDIO_DEVICE_OUT_WIRED_HEADSET),
    NAME_TO_ENUM("Wired Headphones", AUDIO_DEVICE_OUT_WIRED_HEADPHONE),
    NAME_TO_ENUM("BT SCO", AUDIO_DEVICE_OUT_BLUETOOTH_SCO),
    NAME_TO_ENUM("BT SCO Headset", AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET),
    NAME_TO_ENUM("BT SCO Car Kit", AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
    NAME_TO_ENUM("", AUDIO_DEVICE_OUT_ALL_SCO),
    NAME_TO_ENUM("BT A2DP Out", AUDIO_DEVICE_OUT_BLUETOOTH_A2DP),
    NAME_TO_ENUM("BT A2DP Headphones", AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES),
    NAME_TO_ENUM("BT A2DP Speaker", AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
    NAME_TO_ENUM("", AUDIO_DEVICE_OUT_ALL_A2DP),
    NAME_TO_ENUM("HDMI Out", AUDIO_DEVICE_OUT_AUX_DIGITAL),
    NAME_TO_ENUM("HDMI Out", AUDIO_DEVICE_OUT_HDMI),
    NAME_TO_ENUM("Analog Dock Out", AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET),
    NAME_TO_ENUM("Digital Dock Out", AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET),
    NAME_TO_ENUM("USB Host Out", AUDIO_DEVICE_OUT_USB_ACCESSORY),
    NAME_TO_ENUM("USB Device Out", AUDIO_DEVICE_OUT_USB_DEVICE),
    NAME_TO_ENUM("", AUDIO_DEVICE_OUT_ALL_USB),
    NAME_TO_ENUM("Reroute Submix Out", AUDIO_DEVICE_OUT_REMOTE_SUBMIX),
    NAME_TO_ENUM("Telephony Tx", AUDIO_DEVICE_OUT_TELEPHONY_TX),
    NAME_TO_ENUM("Line Out", AUDIO_DEVICE_OUT_LINE),
    NAME_TO_ENUM("HDMI ARC Out", AUDIO_DEVICE_OUT_HDMI_ARC),
    NAME_TO_ENUM("S/PDIF Out", AUDIO_DEVICE_OUT_SPDIF),
    NAME_TO_ENUM("FM transceiver Out", AUDIO_DEVICE_OUT_FM),
    NAME_TO_ENUM("Aux Line Out", AUDIO_DEVICE_OUT_AUX_LINE),
    NAME_TO_ENUM("Ambient Mic", AUDIO_DEVICE_IN_AMBIENT),
    NAME_TO_ENUM("Built-In Mic", AUDIO_DEVICE_IN_BUILTIN_MIC),
    NAME_TO_ENUM("BT SCO Headset Mic", AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
    NAME_TO_ENUM("", AUDIO_DEVICE_IN_ALL_SCO),
    NAME_TO_ENUM("Wired Headset Mic", AUDIO_DEVICE_IN_WIRED_HEADSET),
    NAME_TO_ENUM("HDMI In", AUDIO_DEVICE_IN_AUX_DIGITAL),
    NAME_TO_ENUM("HDMI In", AUDIO_DEVICE_IN_HDMI),
    NAME_TO_ENUM("Telephony Rx", AUDIO_DEVICE_IN_TELEPHONY_RX),
    NAME_TO_ENUM("Telephony Rx", AUDIO_DEVICE_IN_VOICE_CALL),
    NAME_TO_ENUM("Built-In Back Mic", AUDIO_DEVICE_IN_BACK_MIC),
    NAME_TO_ENUM("Reroute Submix In", AUDIO_DEVICE_IN_REMOTE_SUBMIX),
    NAME_TO_ENUM("Analog Dock In", AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET),
    NAME_TO_ENUM("Digital Dock In", AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
    NAME_TO_ENUM("USB Host In", AUDIO_DEVICE_IN_USB_ACCESSORY),
    NAME_TO_ENUM("USB Device In", AUDIO_DEVICE_IN_USB_DEVICE),
    NAME_TO_ENUM("FM Tuner In", AUDIO_DEVICE_IN_FM_TUNER),
    NAME_TO_ENUM("TV Tuner In", AUDIO_DEVICE_IN_TV_TUNER),
    NAME_TO_ENUM("Line In", AUDIO_DEVICE_IN_LINE),
    NAME_TO_ENUM("S/PDIF In", AUDIO_DEVICE_IN_SPDIF),
    NAME_TO_ENUM("BT A2DP In", AUDIO_DEVICE_IN_BLUETOOTH_A2DP),
    NAME_TO_ENUM("Loopback In", AUDIO_DEVICE_IN_LOOPBACK),
};

const StringToEnum sOutputFlagNameToEnumTable[] = {
    STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_DIRECT),
    STRING_TO_ENUM(AUDIO_OUTPUT_FLAG_PRIMARY),
+4 −2
Original line number Diff line number Diff line
@@ -41,20 +41,22 @@ public:
            const struct audio_port_config *srcConfig = NULL) const;

    // AudioPort
    virtual void attach(const sp<HwModule>& module);
    virtual void loadGains(cnode *root);
    virtual void toAudioPort(struct audio_port *port) const;

    audio_port_handle_t getId() const;
    audio_devices_t type() const { return mDeviceType; }
    status_t dump(int fd, int spaces, int index) const;
    void log() const;

    String8 mAddress;
    audio_port_handle_t mId;

    static String8  emptyNameStr;

private:
    audio_devices_t     mDeviceType;
    audio_port_handle_t mId;

friend class DeviceVector;
};
Loading