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

Commit 997e18c4 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

release-request-bf3460d4-15ec-4b2b-816a-b106ef372c4b-for-git_oc-dr1-release-41...

release-request-bf3460d4-15ec-4b2b-816a-b106ef372c4b-for-git_oc-dr1-release-4164433 snap-temp-L62100000080728136

Change-Id: I60c9df93655ccc156f1a365af8db64ec64c970f8
parents f81f5e07 15fb0ee6
Loading
Loading
Loading
Loading
+31 −20
Original line number Original line Diff line number Diff line
@@ -26,42 +26,31 @@
#define MMAP_POLICY              AAUDIO_POLICY_AUTO
#define MMAP_POLICY              AAUDIO_POLICY_AUTO
//#define MMAP_POLICY              AAUDIO_POLICY_ALWAYS
//#define MMAP_POLICY              AAUDIO_POLICY_ALWAYS


#define MAX_STREAMS   100
#define MAX_STREAMS   200

int main(int argc, char **argv)
{
    (void)argc; // unused
    (void)argv; // unused


aaudio_result_t testMaxStreams(aaudio_direction_t direction) {
    aaudio_result_t result = AAUDIO_OK;
    aaudio_result_t result = AAUDIO_OK;
    AAudioStreamBuilder *aaudioBuilder = nullptr;
    AAudioStreamBuilder *aaudioBuilder = nullptr;
    AAudioStream *aaudioStream[MAX_STREAMS];
    AAudioStream *aaudioStreams[MAX_STREAMS];
    int32_t numStreams = 0;
    int32_t numStreams = 0;


    // Make printf print immediately so that debug info is not stuck
    // in a buffer if we hang or crash.
    setvbuf(stdout, NULL, _IONBF, (size_t) 0);

    printf("Try to open a maximum of %d streams.\n", MAX_STREAMS);

    AAudio_setMMapPolicy(MMAP_POLICY);
    printf("requested MMapPolicy = %d\n", AAudio_getMMapPolicy());

    result = AAudio_createStreamBuilder(&aaudioBuilder);
    result = AAudio_createStreamBuilder(&aaudioBuilder);
    if (result != AAUDIO_OK) {
    if (result != AAUDIO_OK) {
        return 1;
        return 1;
    }
    }


    AAudioStreamBuilder_setDirection(aaudioBuilder, direction);

    for (int i = 0; i < MAX_STREAMS; i++) {
    for (int i = 0; i < MAX_STREAMS; i++) {
        // Create an AAudioStream using the Builder.
        // Create an AAudioStream using the Builder.
        result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream[i]);
        result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStreams[i]);
        if (result != AAUDIO_OK) {
        if (result != AAUDIO_OK) {
            printf("ERROR could not open AAudio stream, %d %s\n",
            printf("ERROR could not open AAudio stream, %d %s\n",
                   result, AAudio_convertResultToText(result));
                   result, AAudio_convertResultToText(result));
            break;
            break;
        } else {
        } else {
            printf("AAudio stream[%2d] opened successfully. MMAP = %s\n",
            printf("AAudio stream[%2d] opened successfully. MMAP = %s\n",
                   i, AAudioStream_isMMapUsed(aaudioStream[i]) ? "YES" : "NO");
                   i, AAudioStream_isMMapUsed(aaudioStreams[i]) ? "YES" : "NO");
            numStreams++;
            numStreams++;
        }
        }
    }
    }
@@ -70,7 +59,7 @@ int main(int argc, char **argv)


    // Close all the streams.
    // Close all the streams.
    for (int i = 0; i < numStreams; i++) {
    for (int i = 0; i < numStreams; i++) {
        result = AAudioStream_close(aaudioStream[i]);
        result = AAudioStream_close(aaudioStreams[i]);
        if (result != AAUDIO_OK) {
        if (result != AAUDIO_OK) {
            printf("ERROR could not close AAudio stream, %d %s\n",
            printf("ERROR could not close AAudio stream, %d %s\n",
                   result, AAudio_convertResultToText(result));
                   result, AAudio_convertResultToText(result));
@@ -83,6 +72,28 @@ int main(int argc, char **argv)
    AAudioStreamBuilder_delete(aaudioBuilder);
    AAudioStreamBuilder_delete(aaudioBuilder);


finish:
finish:
    return (result != AAUDIO_OK) ? EXIT_FAILURE : EXIT_SUCCESS;
    return result;
}

int main(int argc, char **argv) {
    (void)argc; // unused
    (void)argv; // unused

    // Make printf print immediately so that debug info is not stuck
    // in a buffer if we hang or crash.
    setvbuf(stdout, NULL, _IONBF, (size_t) 0);

    printf("Try to open a maximum of %d streams.\n", MAX_STREAMS);

    AAudio_setMMapPolicy(MMAP_POLICY);
    printf("requested MMapPolicy = %d\n", AAudio_getMMapPolicy());

    printf("Test AAUDIO_DIRECTION_OUTPUT ---------\n");
    aaudio_result_t result = testMaxStreams(AAUDIO_DIRECTION_OUTPUT);
    if (result == AAUDIO_OK) {
        printf("Test AAUDIO_DIRECTION_INPUT ---------\n");
        result = testMaxStreams(AAUDIO_DIRECTION_INPUT);
    }
    }


    return (result != AAUDIO_OK) ? EXIT_FAILURE : EXIT_SUCCESS;
}
+38 −35
Original line number Original line Diff line number Diff line
@@ -90,13 +90,15 @@ Return<void> Omx::allocateNode(
    using ::android::IOMXNode;
    using ::android::IOMXNode;
    using ::android::IOMXObserver;
    using ::android::IOMXObserver;


    sp<OMXNodeInstance> instance;
    {
        Mutex::Autolock autoLock(mLock);
        Mutex::Autolock autoLock(mLock);
        if (mLiveNodes.size() == kMaxNodeInstances) {
        if (mLiveNodes.size() == kMaxNodeInstances) {
            _hidl_cb(toStatus(NO_MEMORY), nullptr);
            _hidl_cb(toStatus(NO_MEMORY), nullptr);
            return Void();
            return Void();
        }
        }


    sp<OMXNodeInstance> instance = new OMXNodeInstance(
        instance = new OMXNodeInstance(
                this, new LWOmxObserver(observer), name.c_str());
                this, new LWOmxObserver(observer), name.c_str());


        OMX_COMPONENTTYPE *handle;
        OMX_COMPONENTTYPE *handle;
@@ -128,8 +130,9 @@ Return<void> Omx::allocateNode(
        }
        }


        mLiveNodes.add(observer.get(), instance);
        mLiveNodes.add(observer.get(), instance);
    observer->linkToDeath(this, 0);
        mNode2Observer.add(instance.get(), observer.get());
        mNode2Observer.add(instance.get(), observer.get());
    }
    observer->linkToDeath(this, 0);


    _hidl_cb(toStatus(OK), new TWOmxNode(instance));
    _hidl_cb(toStatus(OK), new TWOmxNode(instance));
    return Void();
    return Void();
+5 −3
Original line number Original line Diff line number Diff line
@@ -137,6 +137,7 @@ aaudio_handle_t AAudioService::openStream(const aaudio::AAudioStreamRequest &req
        aaudio_handle_t handle = mHandleTracker.put(AAUDIO_HANDLE_TYPE_STREAM, serviceStream.get());
        aaudio_handle_t handle = mHandleTracker.put(AAUDIO_HANDLE_TYPE_STREAM, serviceStream.get());
        if (handle < 0) {
        if (handle < 0) {
            ALOGE("AAudioService::openStream(): handle table full");
            ALOGE("AAudioService::openStream(): handle table full");
            serviceStream->close();
            serviceStream.clear();
            serviceStream.clear();
        } else {
        } else {
            ALOGD("AAudioService::openStream(): handle = 0x%08X", handle);
            ALOGD("AAudioService::openStream(): handle = 0x%08X", handle);
@@ -150,17 +151,18 @@ aaudio_handle_t AAudioService::openStream(const aaudio::AAudioStreamRequest &req
}
}


aaudio_result_t AAudioService::closeStream(aaudio_handle_t streamHandle) {
aaudio_result_t AAudioService::closeStream(aaudio_handle_t streamHandle) {
    // Check permission first.
    // Check permission and ownership first.
    AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
    sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
    if (serviceStream == nullptr) {
    if (serviceStream == nullptr) {
        ALOGE("AAudioService::startStream(), illegal stream handle = 0x%0x", streamHandle);
        ALOGE("AAudioService::startStream(), illegal stream handle = 0x%0x", streamHandle);
        return AAUDIO_ERROR_INVALID_HANDLE;
        return AAUDIO_ERROR_INVALID_HANDLE;
    }
    }


    ALOGD("AAudioService.closeStream(0x%08X)", streamHandle);
    // Remove handle from tracker so that we cannot look up the raw address any more.
    serviceStream = (AAudioServiceStreamBase *)
    serviceStream = (AAudioServiceStreamBase *)
            mHandleTracker.remove(AAUDIO_HANDLE_TYPE_STREAM,
            mHandleTracker.remove(AAUDIO_HANDLE_TYPE_STREAM,
                                  streamHandle);
                                  streamHandle);
    ALOGD("AAudioService.closeStream(0x%08X)", streamHandle);
    if (serviceStream != nullptr) {
    if (serviceStream != nullptr) {
        serviceStream->close();
        serviceStream->close();
        pid_t pid = serviceStream->getOwnerProcessId();
        pid_t pid = serviceStream->getOwnerProcessId();
+25 −10
Original line number Original line Diff line number Diff line
@@ -41,8 +41,12 @@ AAudioServiceStreamBase::AAudioServiceStreamBase()
}
}


AAudioServiceStreamBase::~AAudioServiceStreamBase() {
AAudioServiceStreamBase::~AAudioServiceStreamBase() {
    close();
    ALOGD("AAudioServiceStreamBase::~AAudioServiceStreamBase() destroying %p", this);
    ALOGD("AAudioServiceStreamBase::~AAudioServiceStreamBase() destroyed %p", this);
    // If the stream is deleted when OPEN or in use then audio resources will leak.
    // This would indicate an internal error. So we want to find this ASAP.
    LOG_ALWAYS_FATAL_IF(!(mState == AAUDIO_STREAM_STATE_CLOSED
                        || mState == AAUDIO_STREAM_STATE_UNINITIALIZED),
                        "service stream still open, state = %d", mState);
}
}


std::string AAudioServiceStreamBase::dump() const {
std::string AAudioServiceStreamBase::dump() const {
@@ -71,11 +75,13 @@ aaudio_result_t AAudioServiceStreamBase::open(const aaudio::AAudioStreamRequest
}
}


aaudio_result_t AAudioServiceStreamBase::close() {
aaudio_result_t AAudioServiceStreamBase::close() {
    stop();
    if (mState != AAUDIO_STREAM_STATE_CLOSED) {
        stopTimestampThread();
        std::lock_guard<std::mutex> lock(mLockUpMessageQueue);
        std::lock_guard<std::mutex> lock(mLockUpMessageQueue);
        delete mUpMessageQueue;
        delete mUpMessageQueue;
        mUpMessageQueue = nullptr;
        mUpMessageQueue = nullptr;

        mState = AAUDIO_STREAM_STATE_CLOSED;
    }
    return AAUDIO_OK;
    return AAUDIO_OK;
}
}


@@ -106,9 +112,8 @@ aaudio_result_t AAudioServiceStreamBase::stop() {
    aaudio_result_t result = AAUDIO_OK;
    aaudio_result_t result = AAUDIO_OK;
    if (isRunning()) {
    if (isRunning()) {
        // TODO wait for data to be played out
        // TODO wait for data to be played out
        sendCurrentTimestamp();
        sendCurrentTimestamp(); // warning - this calls a virtual function
        mThreadEnabled.store(false);
        result = stopTimestampThread();
        result = mAAudioThread.stop();
        if (result != AAUDIO_OK) {
        if (result != AAUDIO_OK) {
            disconnect();
            disconnect();
            return result;
            return result;
@@ -119,6 +124,15 @@ aaudio_result_t AAudioServiceStreamBase::stop() {
    return result;
    return result;
}
}


aaudio_result_t AAudioServiceStreamBase::stopTimestampThread() {
    aaudio_result_t result = AAUDIO_OK;
    // clear flag that tells thread to loop
    if (mThreadEnabled.exchange(false)) {
        result = mAAudioThread.stop();
    }
    return result;
}

aaudio_result_t AAudioServiceStreamBase::flush() {
aaudio_result_t AAudioServiceStreamBase::flush() {
    sendServiceEvent(AAUDIO_SERVICE_EVENT_FLUSHED);
    sendServiceEvent(AAUDIO_SERVICE_EVENT_FLUSHED);
    mState = AAUDIO_STREAM_STATE_FLUSHED;
    mState = AAUDIO_STREAM_STATE_FLUSHED;
@@ -141,6 +155,7 @@ void AAudioServiceStreamBase::run() {
            nextTime = timestampScheduler.nextAbsoluteTime();
            nextTime = timestampScheduler.nextAbsoluteTime();
        } else  {
        } else  {
            // Sleep until it is time to send the next timestamp.
            // Sleep until it is time to send the next timestamp.
            // TODO Wait for a signal with a timeout so that we can stop more quickly.
            AudioClock::sleepUntilNanoTime(nextTime);
            AudioClock::sleepUntilNanoTime(nextTime);
        }
        }
    }
    }
+11 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,8 @@ public:
     */
     */
    virtual aaudio_result_t stop();
    virtual aaudio_result_t stop();


    aaudio_result_t stopTimestampThread();

    /**
    /**
     *  Discard any data held by the underlying HAL or Service.
     *  Discard any data held by the underlying HAL or Service.
     */
     */
@@ -142,7 +144,16 @@ public:
        mHandle = handle;
        mHandle = handle;
    }
    }


    aaudio_stream_state_t getState() const {
        return mState;
    }

protected:
protected:

    void setState(aaudio_stream_state_t state) {
        mState = state;
    }

    aaudio_result_t writeUpMessageQueue(AAudioServiceMessage *command);
    aaudio_result_t writeUpMessageQueue(AAudioServiceMessage *command);


    aaudio_result_t sendCurrentTimestamp();
    aaudio_result_t sendCurrentTimestamp();
Loading