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

Commit c644345b authored by Jean-Michel Trivi's avatar Jean-Michel Trivi Committed by Android (Google) Code Review
Browse files

Merge "AudioTrack non-blocking write"

parents 1ac16380 720ad9dd
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -556,8 +556,11 @@ public:
     *      WOULD_BLOCK         when obtainBuffer() returns same, or
     *      WOULD_BLOCK         when obtainBuffer() returns same, or
     *                          AudioTrack was stopped during the write
     *                          AudioTrack was stopped during the write
     *      or any other error code returned by IAudioTrack::start() or restoreTrack_l().
     *      or any other error code returned by IAudioTrack::start() or restoreTrack_l().
     * Default behavior is to only return until all data has been transferred. Set 'blocking' to
     * false for the method to return immediately without waiting to try multiple times to write
     * the full content of the buffer.
     */
     */
            ssize_t     write(const void* buffer, size_t size);
            ssize_t     write(const void* buffer, size_t size, bool blocking = true);


    /*
    /*
     * Dumps the state of an audio track.
     * Dumps the state of an audio track.
+3 −2
Original line number Original line Diff line number Diff line
@@ -1291,7 +1291,7 @@ void AudioTrack::releaseBuffer(Buffer* audioBuffer)


// -------------------------------------------------------------------------
// -------------------------------------------------------------------------


ssize_t AudioTrack::write(const void* buffer, size_t userSize)
ssize_t AudioTrack::write(const void* buffer, size_t userSize, bool blocking)
{
{
    if (mTransfer != TRANSFER_SYNC || mIsTimed) {
    if (mTransfer != TRANSFER_SYNC || mIsTimed) {
        return INVALID_OPERATION;
        return INVALID_OPERATION;
@@ -1310,7 +1310,8 @@ ssize_t AudioTrack::write(const void* buffer, size_t userSize)
    while (userSize >= mFrameSize) {
    while (userSize >= mFrameSize) {
        audioBuffer.frameCount = userSize / mFrameSize;
        audioBuffer.frameCount = userSize / mFrameSize;


        status_t err = obtainBuffer(&audioBuffer, &ClientProxy::kForever);
        status_t err = obtainBuffer(&audioBuffer,
                blocking ? &ClientProxy::kForever : &ClientProxy::kNonBlocking);
        if (err < 0) {
        if (err < 0) {
            if (written > 0) {
            if (written > 0) {
                break;
                break;