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

Commit f91f699b authored by Xin Li's avatar Xin Li Committed by Android (Google) Code Review
Browse files

Merge "Merge Android 12 QPR3 ab/8391262" into stage-aosp-master

parents 6cd39dfe ba655811
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ namespace android {

// for audio_track_cblk_t::mState, to match TrackBase.h
static inline constexpr int CBLK_STATE_IDLE = 0;
static inline constexpr int CBLK_STATE_ACTIVE = 6;
static inline constexpr int CBLK_STATE_PAUSING = 7;

/**
+3 −0
Original line number Diff line number Diff line
@@ -899,6 +899,9 @@ void CCodecConfig::initializeStandardParams() {
    add(ConfigMapper(KEY_AAC_MAX_OUTPUT_CHANNEL_COUNT, C2_PARAMKEY_MAX_CHANNEL_COUNT, "value")
        .limitTo(D::AUDIO & (D::CONFIG | D::PARAM | D::READ)));

    add(ConfigMapper(KEY_MAX_OUTPUT_CHANNEL_COUNT, C2_PARAMKEY_MAX_CHANNEL_COUNT, "value")
        .limitTo(D::AUDIO & (D::CONFIG | D::PARAM | D::READ)));

    add(ConfigMapper(KEY_AAC_SBR_MODE, C2_PARAMKEY_AAC_SBR_MODE, "value")
        .limitTo(D::AUDIO & D::ENCODER & (D::CONFIG | D::PARAM | D::READ))
        .withMapper([](C2Value v) -> C2Value {
+22 −15
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ public:

        c2_status_t err = mapInternal(mapSize, mapOffset, alignmentBytes, prot, flags, &(map.addr), addr);
        if (map.addr) {
            std::lock_guard<std::mutex> guard(mMutexMappings);
            mMappings.push_back(map);
        }
        return err;
@@ -217,6 +218,8 @@ public:
            ALOGD("tried to unmap unmapped buffer");
            return C2_NOT_FOUND;
        }
        { // Scope for the lock_guard of mMutexMappings.
            std::lock_guard<std::mutex> guard(mMutexMappings);
            for (auto it = mMappings.begin(); it != mMappings.end(); ++it) {
                if (addr != (uint8_t *)it->addr + it->alignmentBytes ||
                        size + it->alignmentBytes != it->size) {
@@ -231,9 +234,11 @@ public:
                    *fence = C2Fence(); // not using fences
                }
                (void)mMappings.erase(it);
            ALOGV("successfully unmapped: addr=%p size=%zu fd=%d", addr, size, mHandle.bufferFd());
                ALOGV("successfully unmapped: addr=%p size=%zu fd=%d", addr, size,
                          mHandle.bufferFd());
                return C2_OK;
            }
        }
        ALOGD("unmap failed to find specified map");
        return C2_BAD_VALUE;
    }
@@ -241,6 +246,7 @@ public:
    virtual ~Impl() {
        if (!mMappings.empty()) {
            ALOGD("Dangling mappings!");
            std::lock_guard<std::mutex> guard(mMutexMappings);
            for (const Mapping &map : mMappings) {
                (void)munmap(map.addr, map.size);
            }
@@ -320,6 +326,7 @@ protected:
        size_t size;
    };
    std::list<Mapping> mMappings;
    std::mutex mMutexMappings;
};

class C2AllocationIon::ImplV2 : public C2AllocationIon::Impl {
+2 −1
Original line number Diff line number Diff line
@@ -352,7 +352,8 @@ AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
{

    AudioStream *audioStream = convertAAudioStreamToAudioStream(stream);
    return audioStream->waitForStateChange(inputState, nextState, timeoutNanoseconds);
    android::sp<AudioStream> spAudioStream(audioStream);
    return spAudioStream->waitForStateChange(inputState, nextState, timeoutNanoseconds);
}

// ============================================================
+54 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

#include <gtest/gtest.h>
#include <unistd.h>
#include <thread>

// Callback function that does nothing.
aaudio_data_callback_result_t NoopDataCallbackProc(
@@ -51,6 +52,7 @@ aaudio_data_callback_result_t NoopDataCallbackProc(
}

constexpr int64_t NANOS_PER_MILLISECOND = 1000 * 1000;
constexpr int64_t MICROS_PER_MILLISECOND = 1000;

void checkReleaseThenClose(aaudio_performance_mode_t perfMode,
        aaudio_sharing_mode_t sharingMode,
@@ -762,6 +764,58 @@ TEST(test_various, aaudio_callback_once_lowlat) {
    checkCallbackOnce(AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
}

void waitForStateChangeToClosingorClosed(AAudioStream **stream, std::atomic<bool>* isReady)
{
    *isReady = true;
    aaudio_stream_state_t state = AAUDIO_STREAM_STATE_UNKNOWN;
    EXPECT_EQ(AAUDIO_OK, AAudioStream_waitForStateChange(*stream,
                                                         AAUDIO_STREAM_STATE_OPEN, &state,
                                                         10000 * NANOS_PER_MILLISECOND));
    if ((state != AAUDIO_STREAM_STATE_CLOSING) && (state != AAUDIO_STREAM_STATE_CLOSED)){
        FAIL() << "ERROR - State not closing or closed. Current state: " <<
                AAudio_convertStreamStateToText(state);
    }
}

void testWaitForStateChangeClose(aaudio_performance_mode_t perfMode) {
    AAudioStreamBuilder *aaudioBuilder = nullptr;
    AAudioStream *aaudioStream = nullptr;

    ASSERT_EQ(AAUDIO_OK, AAudio_createStreamBuilder(&aaudioBuilder));
    AAudioStreamBuilder_setPerformanceMode(aaudioBuilder, perfMode);
    ASSERT_EQ(AAUDIO_OK, AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream));

    // Verify Open State
    aaudio_stream_state_t state = AAUDIO_STREAM_STATE_UNKNOWN;
    EXPECT_EQ(AAUDIO_OK, AAudioStream_waitForStateChange(aaudioStream,
                                                         AAUDIO_STREAM_STATE_UNKNOWN, &state,
                                                         1000 * NANOS_PER_MILLISECOND));
    EXPECT_EQ(AAUDIO_STREAM_STATE_OPEN, state);

    std::atomic<bool> isWaitThreadReady{false};

    // Spawn a new thread to wait for the state change
    std::thread waitThread (waitForStateChangeToClosingorClosed, &aaudioStream,
                            &isWaitThreadReady);

    // Wait for worker thread to be ready
    while (!isWaitThreadReady) {
        usleep(MICROS_PER_MILLISECOND);
    }
    // Sleep an additional millisecond to make sure waitForAudioThread is called
    usleep(MICROS_PER_MILLISECOND);
    EXPECT_EQ(AAUDIO_OK, AAudioStream_close(aaudioStream));
    waitThread.join();
}

TEST(test_various, wait_for_state_change_close_none) {
    testWaitForStateChangeClose(AAUDIO_PERFORMANCE_MODE_NONE);
}

TEST(test_various, wait_for_state_change_close_lowlat) {
    testWaitForStateChangeClose(AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
}

// ************************************************************
struct WakeUpCallbackData {
    void wakeOther() {
Loading