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

Commit 0805de16 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

APM: Provide mix port flags via 'listAudioPorts'

Flags are now provided for mix ports via the 'active_config.flags'
field of 'audio_port_v7'.

To enable this, the following changes were made:

1. Use 'AUDIO_PORT_CONFIG_ALL' config for the export in
   Audio{Input|Output}Descriptor::toAudioPortConfig.
2. Fix duplication of 'mFlags' field between AudioOutputDescriptor
   and its base class AudioPortConfig.
3. Add 'mFlags' field to AudioInputDescriptor which is a reference
   to the relevant part of AudioPortConfig.mFlags (same mechanism
   as in 2.)
4. Verify behavior in
   AudioPolicyManagerTestWithConfigurationFile#ListAudioPortsHasFlags

Also, 'test_audio_policy_configuration.xml' was updated to V7 syntax
to exercise more paths in APM.

Bug: 218507839
Test: atest audiopolicy_tests
Change-Id: I78fbd53dde15a90eca104aa17c68282563f8633a
parent c473ac09
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@ public:
    AudioPolicyClientInterface * const mClientInterface;
    int32_t mGlobalActiveCount = 0;  // non-client-specific activity ref count
    EffectDescriptorCollection mEnabledEffects;
    audio_input_flags_t& mFlags = AudioPortConfig::mFlags.input;
};

class AudioInputCollection :
+2 −1
Original line number Diff line number Diff line
@@ -316,6 +316,7 @@ protected:
    AudioPolicyClientInterface * const mClientInterface;
    uint32_t mGlobalActiveCount = 0;  // non-client-specific active count
    audio_patch_handle_t mPatchHandle = AUDIO_PATCH_HANDLE_NONE;
    audio_output_flags_t& mFlags = AudioPortConfig::mFlags.output;

    // The ActiveClients shows the clients that contribute to the @VolumeSource counts
    // and may include upstream clients from a duplicating thread.
@@ -424,7 +425,7 @@ public:
    const sp<IOProfile> mProfile;          // I/O profile this output derives from
    audio_io_handle_t mIoHandle;           // output handle
    uint32_t mLatency;                  //
    audio_output_flags_t mFlags;   //
    using AudioOutputDescriptor::mFlags;
    sp<SwAudioOutputDescriptor> mOutput1;    // used by duplicated outputs: first output
    sp<SwAudioOutputDescriptor> mOutput2;    // used by duplicated outputs: second output
    uint32_t mDirectOpenCount; // number of clients using this output (direct outputs only)
+9 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ AudioInputDescriptor::AudioInputDescriptor(const sp<IOProfile>& profile,
        if (profile->getGains().size() > 0) {
            profile->getGains()[0]->getDefaultConfig(&mGain);
        }
        mFlags = (audio_input_flags_t)profile->getFlags();
    }
}

@@ -77,8 +78,7 @@ void AudioInputDescriptor::toAudioPortConfig(struct audio_port_config *dstConfig
{
    ALOG_ASSERT(mProfile != 0,
                "toAudioPortConfig() called on input with null profile %d", mIoHandle);
    dstConfig->config_mask = AUDIO_PORT_CONFIG_SAMPLE_RATE|AUDIO_PORT_CONFIG_CHANNEL_MASK|
                            AUDIO_PORT_CONFIG_FORMAT|AUDIO_PORT_CONFIG_GAIN;
    dstConfig->config_mask = AUDIO_PORT_CONFIG_ALL;
    if (srcConfig != NULL) {
        dstConfig->config_mask |= srcConfig->config_mask;
    }
@@ -512,8 +512,13 @@ void AudioInputDescriptor::checkSuspendEffects()

void AudioInputDescriptor::dump(String8 *dst, int spaces, const char* extraInfo) const
{
    dst->appendFormat("Port ID: %d%s%s\n",
            getId(), extraInfo != nullptr ? "; " : "", extraInfo != nullptr ? extraInfo : "");
    std::string flagsLiteral = toString(mFlags);
    if (!flagsLiteral.empty()) {
        flagsLiteral = " (" + flagsLiteral + ")";
    }
    dst->appendFormat("Port ID: %d; 0x%04x%s%s%s\n",
            getId(), mFlags, flagsLiteral.c_str(),
            extraInfo != nullptr ? "; " : "", extraInfo != nullptr ? extraInfo : "");
    dst->appendFormat("%*s%s; %d; Channel mask: 0x%x\n", spaces, "",
            audio_format_to_string(mFormat), mSamplingRate, mChannelMask);
    dst->appendFormat("%*sDevices: %s\n", spaces, "",
+1 −3
Original line number Diff line number Diff line
@@ -202,8 +202,7 @@ status_t AudioOutputDescriptor::applyAudioPortConfig(const struct audio_port_con
void AudioOutputDescriptor::toAudioPortConfig(struct audio_port_config *dstConfig,
                                              const struct audio_port_config *srcConfig) const
{
    dstConfig->config_mask = AUDIO_PORT_CONFIG_SAMPLE_RATE|AUDIO_PORT_CONFIG_CHANNEL_MASK|
                            AUDIO_PORT_CONFIG_FORMAT|AUDIO_PORT_CONFIG_GAIN;
    dstConfig->config_mask = AUDIO_PORT_CONFIG_ALL;
    if (srcConfig != NULL) {
        dstConfig->config_mask |= srcConfig->config_mask;
    }
@@ -298,7 +297,6 @@ SwAudioOutputDescriptor::SwAudioOutputDescriptor(const sp<IOProfile>& profile,
                                                 AudioPolicyClientInterface *clientInterface)
    : AudioOutputDescriptor(profile, clientInterface),
    mProfile(profile), mIoHandle(AUDIO_IO_HANDLE_NONE), mLatency(0),
    mFlags((audio_output_flags_t)0),
    mOutput1(0), mOutput2(0), mDirectOpenCount(0),
    mDirectClientSession(AUDIO_SESSION_NONE)
{
+54 −9
Original line number Diff line number Diff line
@@ -137,6 +137,8 @@ class AudioPolicyManagerTest : public testing::Test {
            audio_port_handle_t *portId = nullptr);
    PatchCountCheck snapshotPatchCount() { return PatchCountCheck(mClient.get()); }

    void getAudioPorts(audio_port_type_t type, audio_port_role_t role,
            std::vector<audio_port_v7>* ports);
    // Tries to find a device port. If 'foundPort' isn't nullptr,
    // will generate a failure if the port hasn't been found.
    bool findDevicePort(audio_port_role_t role, audio_devices_t deviceType,
@@ -255,21 +257,26 @@ void AudioPolicyManagerTest::getInputForAttr(
    ASSERT_NE(AUDIO_PORT_HANDLE_NONE, *portId);
}

bool AudioPolicyManagerTest::findDevicePort(audio_port_role_t role,
        audio_devices_t deviceType, const std::string &address, audio_port_v7 *foundPort) {
void AudioPolicyManagerTest::getAudioPorts(audio_port_type_t type, audio_port_role_t role,
        std::vector<audio_port_v7>* ports) {
    uint32_t numPorts = 0;
    uint32_t generation1;
    status_t ret;

    ret = mManager->listAudioPorts(role, AUDIO_PORT_TYPE_DEVICE, &numPorts, nullptr, &generation1);
    EXPECT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error";
    if (HasFailure()) return false;
    ret = mManager->listAudioPorts(role, type, &numPorts, nullptr, &generation1);
    ASSERT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error";

    uint32_t generation2;
    struct audio_port_v7 ports[numPorts];
    ret = mManager->listAudioPorts(role, AUDIO_PORT_TYPE_DEVICE, &numPorts, ports, &generation2);
    EXPECT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error";
    EXPECT_EQ(generation1, generation2) << "Generations changed during ports retrieval";
    ports->resize(numPorts);
    ret = mManager->listAudioPorts(role, type, &numPorts, ports->data(), &generation2);
    ASSERT_EQ(NO_ERROR, ret) << "mManager->listAudioPorts returned error";
    ASSERT_EQ(generation1, generation2) << "Generations changed during ports retrieval";
}

bool AudioPolicyManagerTest::findDevicePort(audio_port_role_t role,
        audio_devices_t deviceType, const std::string &address, audio_port_v7 *foundPort) {
    std::vector<audio_port_v7> ports;
    getAudioPorts(AUDIO_PORT_TYPE_DEVICE, role, &ports);
    if (HasFailure()) return false;

    for (const auto &port : ports) {
@@ -671,6 +678,44 @@ TEST_F(AudioPolicyManagerTestWithConfigurationFile, Dump) {
    dumpToLog();
}

TEST_F(AudioPolicyManagerTestWithConfigurationFile, ListAudioPortsHasFlags) {
    // Create an input for VOIP TX because it's not opened automatically like outputs are.
    audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE;
    audio_port_handle_t mixPortId = AUDIO_PORT_HANDLE_NONE;
    audio_source_t source = AUDIO_SOURCE_VOICE_COMMUNICATION;
    audio_attributes_t attr = {
        AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, AUDIO_FLAG_NONE, ""};
    ASSERT_NO_FATAL_FAILURE(getInputForAttr(attr, 1, &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT,
                    AUDIO_CHANNEL_IN_MONO, 8000, AUDIO_INPUT_FLAG_VOIP_TX, &mixPortId));

    std::vector<audio_port_v7> ports;
    ASSERT_NO_FATAL_FAILURE(
            getAudioPorts(AUDIO_PORT_TYPE_MIX, AUDIO_PORT_ROLE_NONE, &ports));
    EXPECT_NE(0, ports.size());
    bool hasFlags = false, foundPrimary = false, foundVoipRx = false, foundVoipTx = false;
    for (const auto& port : ports) {
        if ((port.active_config.config_mask & AUDIO_PORT_CONFIG_FLAGS) != 0) {
            hasFlags = true;
            if (port.role == AUDIO_PORT_ROLE_SOURCE) {
                if ((port.active_config.flags.output & AUDIO_OUTPUT_FLAG_PRIMARY) != 0) {
                    foundPrimary = true;
                }
                if ((port.active_config.flags.output & AUDIO_OUTPUT_FLAG_VOIP_RX) != 0) {
                    foundVoipRx = true;
                }
            } else if (port.role == AUDIO_PORT_ROLE_SINK) {
                if ((port.active_config.flags.input & AUDIO_INPUT_FLAG_VOIP_TX) != 0) {
                    foundVoipTx = true;
                }
            }
        }
    }
    EXPECT_TRUE(hasFlags);
    EXPECT_TRUE(foundPrimary);
    EXPECT_TRUE(foundVoipRx);
    EXPECT_TRUE(foundVoipTx);
}

using PolicyMixTuple = std::tuple<audio_usage_t, audio_source_t, uint32_t>;

class AudioPolicyManagerTestDynamicPolicy : public AudioPolicyManagerTestWithConfigurationFile {
Loading