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

Commit 4b3f468e authored by Aiguo's avatar Aiguo Committed by Mikhail Naganov
Browse files

audio: add readMmap and writeMmap for mmap stream.



Add readMmap and writeMmap for mmap stream to let the driver
know that the client has started data transfer.

Bug: 398760899
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I6f8fb81b2866a703aebaf89a59d6bba96655b190
Signed-off-by: default avatarAiguo <aiguo.feng@amlogic.corp-partner.google.com>
parent 292bec0a
Loading
Loading
Loading
Loading
+44 −6
Original line number Diff line number Diff line
@@ -252,9 +252,10 @@ StreamInWorkerLogic::Status StreamInWorkerLogic::cycle() {
                    mState == StreamDescriptor::State::ACTIVE ||
                    mState == StreamDescriptor::State::PAUSED ||
                    mState == StreamDescriptor::State::DRAINING) {
                    if (hasMmapFlag(mContext->getFlags())) {
                        populateReply(&reply, mIsConnected);
                    } else if (!read(fmqByteCount, &reply)) {
                    if (bool success = hasMmapFlag(mContext->getFlags())
                                               ? readMmap(&reply)
                                               : read(fmqByteCount, &reply);
                        !success) {
                        mState = StreamDescriptor::State::ERROR;
                    }
                    if (mState == StreamDescriptor::State::IDLE ||
@@ -383,6 +384,24 @@ bool StreamInWorkerLogic::read(size_t clientSize, StreamDescriptor::Reply* reply
    return !fatal;
}

bool StreamInWorkerLogic::readMmap(StreamDescriptor::Reply* reply) {
    void* buffer = nullptr;
    size_t frameCount = 0;
    size_t actualFrameCount = 0;
    int32_t latency = mContext->getNominalLatencyMs();
    // use default-initialized parameter values for mmap stream.
    if (::android::status_t status =
                mDriver->transfer(buffer, frameCount, &actualFrameCount, &latency);
        status == ::android::OK) {
        populateReply(reply, mIsConnected);
        reply->latencyMs = latency;
        return true;
    } else {
        LOG(ERROR) << __func__ << ": transfer failed: " << status;
        return false;
    }
}

const std::string StreamOutWorkerLogic::kThreadName = "writer";

void StreamOutWorkerLogic::onBufferStateChange(size_t bufferFramesLeft) {
@@ -523,9 +542,10 @@ StreamOutWorkerLogic::Status StreamOutWorkerLogic::cycle() {
                if (mState != StreamDescriptor::State::ERROR &&
                    mState != StreamDescriptor::State::TRANSFERRING &&
                    mState != StreamDescriptor::State::TRANSFER_PAUSED) {
                    if (hasMmapFlag(mContext->getFlags())) {
                        populateReply(&reply, mIsConnected);
                    } else if (!write(fmqByteCount, &reply)) {
                    if (bool success = hasMmapFlag(mContext->getFlags())
                                               ? writeMmap(&reply)
                                               : write(fmqByteCount, &reply);
                        !success) {
                        mState = StreamDescriptor::State::ERROR;
                    }
                    std::shared_ptr<IStreamCallback> asyncCallback = mContext->getAsyncCallback();
@@ -700,6 +720,24 @@ bool StreamOutWorkerLogic::write(size_t clientSize, StreamDescriptor::Reply* rep
    return !fatal;
}

bool StreamOutWorkerLogic::writeMmap(StreamDescriptor::Reply* reply) {
    void* buffer = nullptr;
    size_t frameCount = 0;
    size_t actualFrameCount = 0;
    int32_t latency = mContext->getNominalLatencyMs();
    // use default-initialized parameter values for mmap stream.
    if (::android::status_t status =
                mDriver->transfer(buffer, frameCount, &actualFrameCount, &latency);
        status == ::android::OK) {
        populateReply(reply, mIsConnected);
        reply->latencyMs = latency;
        return true;
    } else {
        LOG(ERROR) << __func__ << ": transfer failed: " << status;
        return false;
    }
}

StreamCommonImpl::~StreamCommonImpl() {
    // It is responsibility of the class that implements 'DriverInterface' to call 'cleanupWorker'
    // in the destructor. Note that 'cleanupWorker' can not be properly called from this destructor
+2 −0
Original line number Diff line number Diff line
@@ -307,6 +307,7 @@ class StreamInWorkerLogic : public StreamWorkerCommonLogic {

  private:
    bool read(size_t clientSize, StreamDescriptor::Reply* reply);
    bool readMmap(StreamDescriptor::Reply* reply);
};
using StreamInWorker = StreamWorkerImpl<StreamInWorkerLogic>;

@@ -325,6 +326,7 @@ class StreamOutWorkerLogic : public StreamWorkerCommonLogic {

  private:
    bool write(size_t clientSize, StreamDescriptor::Reply* reply);
    bool writeMmap(StreamDescriptor::Reply* reply);

    std::shared_ptr<IStreamOutEventCallback> mEventCallback;