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

Commit af86dcee authored by Glenn Kasten's avatar Glenn Kasten Committed by Android (Google) Code Review
Browse files

Merge "NBAIO: re-implement NBAIO Pipe and MonoPipe using fifo"

parents 5fd7ccae ed99c2b5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public:

    // This is an over-estimate, and could dupe the caller into making a blocking write()
    // FIXME Use an audio HAL API to query the buffer emptying status when it's available.
    virtual ssize_t availableToWrite() const { return mStreamBufferSizeBytes / mFrameSize; }
    virtual ssize_t availableToWrite() { return mStreamBufferSizeBytes / mFrameSize; }

    virtual ssize_t write(const void *buffer, size_t count);

+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ public:
    //virtual size_t framesWritten() const;
    //virtual size_t framesUnderrun() const;
    //virtual size_t underruns() const;
    //virtual ssize_t availableToWrite() const;
    //virtual ssize_t availableToWrite();
    virtual ssize_t write(const void *buffer, size_t count);
    //virtual ssize_t writeVia(writeVia_t via, size_t total, void *user, size_t block);

+9 −11
Original line number Diff line number Diff line
@@ -18,8 +18,9 @@
#define ANDROID_AUDIO_MONO_PIPE_H

#include <time.h>
#include "NBAIO.h"
#include <audio_utils/fifo.h>
#include <media/SingleStateQueue.h>
#include "NBAIO.h"

namespace android {

@@ -55,7 +56,10 @@ public:
    //virtual int64_t framesUnderrun() const;
    //virtual int64_t underruns() const;

    virtual ssize_t availableToWrite() const;
    // returns n where 0 <= n <= mMaxFrames, or a negative status_t
    // including the private status codes in NBAIO.h
    virtual ssize_t availableToWrite();

    virtual ssize_t write(const void *buffer, size_t count);
    //virtual ssize_t writeVia(writeVia_t via, size_t total, void *user, size_t block);

@@ -80,16 +84,10 @@ public:
            status_t getTimestamp(ExtendedTimestamp &timestamp);

private:
    const size_t    mReqFrames;     // as requested in constructor, unrounded
    const size_t    mMaxFrames;     // always a power of 2
    const size_t    mMaxFrames;     // as requested in constructor, rounded up to a power of 2
    void * const    mBuffer;
    // mFront and mRear will never be separated by more than mMaxFrames.
    // 32-bit overflow is possible if the pipe is active for a long time, but if that happens it's
    // safe because we "&" with (mMaxFrames-1) at end of computations to calculate a buffer index.
    volatile int32_t mFront;        // written by reader with android_atomic_release_store,
                                    // read by writer with android_atomic_acquire_load
    volatile int32_t mRear;         // written by writer with android_atomic_release_store,
                                    // read by reader with android_atomic_acquire_load
    audio_utils_fifo        mFifo;
    audio_utils_fifo_writer mFifoWriter;
    bool            mWriteTsValid;  // whether mWriteTs is valid
    struct timespec mWriteTs;       // time that the previous write() completed
    size_t          mSetpoint;      // target value for pipe fill depth
+2 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class MonoPipeReader : public NBAIO_Source {
public:

    // Construct a MonoPipeReader and associate it with a MonoPipe;
    // any data already in the pipe is visible to this PipeReader.
    // any data already in the pipe is visible to this MonoPipeReader.
    // There can be only a single MonoPipeReader per MonoPipe.
    // FIXME make this constructor a factory method of MonoPipe.
    MonoPipeReader(MonoPipe* pipe);
@@ -59,6 +59,7 @@ public:

private:
    MonoPipe * const mPipe;
    audio_utils_fifo_reader mFifoReader;
};

}   // namespace android
+6 −1
Original line number Diff line number Diff line
@@ -164,7 +164,12 @@ public:
    //  UNDERRUN    write() has not been called frequently enough, or with enough frames to keep up.
    //              An underrun event is counted, and the caller should re-try this operation.
    //  WOULD_BLOCK Determining how many frames can be written without blocking would itself block.
    virtual ssize_t availableToWrite() const { return SSIZE_MAX; }
    virtual ssize_t availableToWrite() {
        if (!mNegotiated) {
            return NEGOTIATE;
        }
        return SSIZE_MAX;
    }

    // Transfer data to sink from single input buffer.  Implies a copy.
    // Inputs:
Loading