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

Commit 6f380414 authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Automerger Merge Worker
Browse files

Merge changes I4a09a9f3,I7d087836,I1ae46d99,I0f0d476b into main am: 92e4b803

parents 81597369 92e4b803
Loading
Loading
Loading
Loading
+34 −6
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@
#include <set>

#include <gtest/gtest.h>
#include <log/log.h>
#include <media/AidlConversionCppNdk.h>
#include <media/IAudioFlinger.h>
#include <utils/Log.h>

#include "audio_test_utils.h"

@@ -277,23 +277,30 @@ TEST_F(AudioSystemTest, CreateAndReleaseAudioPatch) {
        GTEST_SKIP() << "No output devices returned by the audio system";
    }

    bool sourceFound = false, sinkFound = false;
    for (const auto& port : ports) {
        if (port.role == AUDIO_PORT_ROLE_SOURCE && port.type == AUDIO_PORT_TYPE_DEVICE) {
            sourcePort = port;
            sourceFound = true;
        }
        if (port.role == AUDIO_PORT_ROLE_SINK && port.type == AUDIO_PORT_TYPE_DEVICE &&
            port.ext.device.type == AUDIO_DEVICE_OUT_SPEAKER) {
            sinkPort = port;
            sinkFound = true;
        }
        if (sourceFound && sinkFound) break;
    }
    if (!sourceFound || !sinkFound) {
        GTEST_SKIP() << "No ports suitable for testing";
    }

    audioPatch.sources[0] = sourcePort.active_config;
    audioPatch.sinks[0] = sinkPort.active_config;

    status = AudioSystem::createAudioPatch(&audioPatch, &audioPatchHandle);
    EXPECT_EQ(OK, status) << "AudioSystem::createAudiopatch failed between source "
                          << sourcePort.ext.device.address << " and sink "
                          << sinkPort.ext.device.address;
    EXPECT_EQ(OK, status) << "AudioSystem::createAudioPatch failed between source "
                          << audio_device_to_string(sourcePort.ext.device.type) << " and sink "
                          << audio_device_to_string(sinkPort.ext.device.type);

    // verify that patch is established between source and the sink.
    ASSERT_NO_FATAL_FAILURE(anyPatchContainsInputDevice(sourcePort.id, patchFound));
@@ -302,8 +309,8 @@ TEST_F(AudioSystemTest, CreateAndReleaseAudioPatch) {
    EXPECT_NE(AUDIO_PORT_HANDLE_NONE, audioPatchHandle);
    status = AudioSystem::releaseAudioPatch(audioPatchHandle);
    EXPECT_EQ(OK, status) << "AudioSystem::releaseAudioPatch failed between source "
                          << sourcePort.ext.device.address << " and sink "
                          << sinkPort.ext.device.address;
                          << audio_device_to_string(sourcePort.ext.device.type) << " and sink "
                          << audio_device_to_string(sinkPort.ext.device.type);

    // verify that no patch is established between source and the sink after releaseAudioPatch.
    ASSERT_NO_FATAL_FAILURE(anyPatchContainsInputDevice(sourcePort.id, patchFound));
@@ -689,3 +696,24 @@ TEST_F(AudioSystemTest, SetDeviceConnectedState) {
        EXPECT_EQ(AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE, deviceState);
    }
}

class TestExecutionTracer : public ::testing::EmptyTestEventListener {
  public:
    void OnTestStart(const ::testing::TestInfo& test_info) override {
        TraceTestState("Started", test_info);
    }
    void OnTestEnd(const ::testing::TestInfo& test_info) override {
        TraceTestState("Completed", test_info);
    }

  private:
    static void TraceTestState(const std::string& state, const ::testing::TestInfo& test_info) {
        ALOGI("%s %s::%s", state.c_str(), test_info.test_suite_name(), test_info.name());
    }
};

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    ::testing::UnitTest::GetInstance()->listeners().Append(new TestExecutionTracer());
    return RUN_ALL_TESTS();
}
+14 −6
Original line number Diff line number Diff line
@@ -713,7 +713,11 @@ status_t DeviceHalAidl::createAudioPatch(unsigned int num_sources,
        aidlPatch.sourcePortConfigIds.clear();
        aidlPatch.sinkPortConfigIds.clear();
    }
    ALOGD("%s: sources: %s, sinks: %s",
    // The IDs will be found by 'fillPortConfigs', however the original 'aidlSources' and
    // 'aidlSinks' will not be updated because 'setAudioPatch' only needs IDs. Here we log
    // the source arguments, where only the audio configuration and device specifications
    // are relevant.
    ALOGD("%s: [disregard IDs] sources: %s, sinks: %s",
            __func__, ::android::internal::ToString(aidlSources).c_str(),
            ::android::internal::ToString(aidlSinks).c_str());
    auto fillPortConfigs = [&](
@@ -1078,9 +1082,10 @@ status_t DeviceHalAidl::setConnectedState(const struct audio_port_v7 *port, bool
        if (portsIt == mPorts.end()) {
            // Since 'setConnectedState' is called for all modules, it is normal when the device
            // port not found in every one of them.
            ALOGD("%s: device port for device %s is not found in the module %s",
                    __func__, matchDevice.toString().c_str(), mInstance.c_str());
            return BAD_VALUE;
        } else {
            ALOGD("%s: device port for device %s found in the module %s",
                    __func__, matchDevice.toString().c_str(), mInstance.c_str());
        }
        // Use the ID of the "template" port, use all the information from the provided port.
        aidlPort.id = portsIt->first;
@@ -1096,9 +1101,12 @@ status_t DeviceHalAidl::setConnectedState(const struct audio_port_v7 *port, bool
        AudioDevice matchDevice = aidlPort.ext.get<AudioPortExt::device>().device;
        auto portsIt = findPort(matchDevice);
        if (portsIt == mPorts.end()) {
            ALOGW("%s: device port for device %s is not found in the module %s",
                    __func__, matchDevice.toString().c_str(), mInstance.c_str());
            // Since 'setConnectedState' is called for all modules, it is normal when the device
            // port not found in every one of them.
            return BAD_VALUE;
        } else {
            ALOGD("%s: device port for device %s found in the module %s",
                    __func__, matchDevice.toString().c_str(), mInstance.c_str());
        }
        // Any streams opened on the external device must be closed by this time,
        // thus we can clean up patches and port configs that were created for them.
@@ -1527,7 +1535,7 @@ status_t DeviceHalAidl::findOrCreatePortConfig(
        }
        RETURN_STATUS_IF_ERROR(createOrUpdatePortConfig(requestedPortConfig, &portConfigIt,
                created));
    } else if (!flags.has_value()) {
    } else if (portConfigIt == mPortConfigs.end() && !flags.has_value()) {
        ALOGW("%s: mix port config for %s, handle %d not found in the module %s, "
                "and was not created as flags are not specified",
                __func__, config.toString().c_str(), ioHandle, mInstance.c_str());
+2 −1
Original line number Diff line number Diff line
@@ -1827,7 +1827,7 @@ void AudioFlinger::ThreadBase::toAudioPortConfig(struct audio_port_config *confi
    config->type = AUDIO_PORT_TYPE_MIX;
    config->ext.mix.handle = mId;
    config->sample_rate = mSampleRate;
    config->format = mFormat;
    config->format = mHALFormat;
    config->channel_mask = mChannelMask;
    config->config_mask = AUDIO_PORT_CONFIG_SAMPLE_RATE|AUDIO_PORT_CONFIG_CHANNEL_MASK|
                            AUDIO_PORT_CONFIG_FORMAT;
@@ -9483,6 +9483,7 @@ AudioFlinger::AudioStreamIn* AudioFlinger::RecordThread::clearInput()
    Mutex::Autolock _l(mLock);
    AudioStreamIn *input = mInput;
    mInput = NULL;
    mInputSource.clear();
    return input;
}