~aleteoryx/muditaos

10e46cbbbc2351c99da9b60dd253dce5b46bcd15 — Hubert Chrzaniuk 5 years ago 31df1ce
[EGD-5061] Fix lack of audio during call

Audio might have not work if audio streams
were reused. This was fixed by introducing proper
cleaning procedures.
M changelog.md => changelog.md +1 -0
@@ 17,6 17,7 @@

* Fix auto unlock screen on idle
* Fix missing texts for ApplicationDesktop windows
* Fix no audio during call

### Changed


M module-audio/Audio/Operation/PlaybackOperation.cpp => module-audio/Audio/Operation/PlaybackOperation.cpp +3 -0
@@ 58,6 58,7 @@ namespace audio
        operationToken = token;

        assert(dataStreamOut);

        dec->startDecodingWorker(*dataStreamOut, endOfFileCallback);

        if (!tags) {


@@ 196,6 197,8 @@ namespace audio
    PlaybackOperation::~PlaybackOperation()
    {
        Stop();
        dataStreamOut->reset();
        dataStreamIn->reset();
    }

} // namespace audio

M module-audio/Audio/Operation/RouterOperation.cpp => module-audio/Audio/Operation/RouterOperation.cpp +2 -0
@@ 88,6 88,8 @@ namespace audio
        state = State::Idle;
        audioDevice->Stop();
        audioDeviceCellular->Stop();
        dataStreamOut->reset();
        dataStreamIn->reset();

        return RetCode::Success;
    }

M module-audio/Audio/Stream.cpp => module-audio/Audio/Stream.cpp +13 -0
@@ 245,6 245,19 @@ bool Stream::blocksAvailable() const noexcept
    return !isEmpty();
}

void Stream::reset()
{
    _dataStart                = {_buffer.get(), _blockSize * _blockCount, _buffer.get(), _blockSize};
    _dataEnd                  = _dataStart;
    _peekPosition             = _dataStart;
    _writeReservationPosition = _dataStart;
    std::fill(_emptyBuffer.get(), _emptyBuffer.get() + _blockSize, 0);

    _blocksUsed   = 0;
    _peekCount    = 0;
    _reserveCount = 0;
}

Stream::UniqueStreamBuffer StandardStreamAllocator::allocate(std::size_t size)
{
    return std::make_unique<uint8_t[]>(size);

M module-audio/Audio/Stream.hpp => module-audio/Audio/Stream.hpp +2 -0
@@ 101,6 101,8 @@ namespace audio
        /// get empty data span
        Span getNullSpan() const noexcept;

        void reset();

        [[nodiscard]] std::size_t getBlockSize() const noexcept;
        [[nodiscard]] std::size_t getBlockCount() const noexcept;
        [[nodiscard]] std::size_t getUsedBlockCount() const noexcept;

M module-bsp/board/rt1051/bsp/audio/RT1051Audiocodec.cpp => module-bsp/board/rt1051/bsp/audio/RT1051Audiocodec.cpp +6 -0
@@ 297,6 297,9 @@ namespace bsp
            SAI_TransferTerminateSendEDMA(BOARD_AUDIOCODEC_SAIx, &txHandle);
        }
        memset(&txHandle, 0, sizeof(txHandle));
        if (sink.isConnected()) {
            sink.getStream()->unpeek();
        }
    }

    void RT1051Audiocodec::InStop()


@@ 306,6 309,9 @@ namespace bsp
            SAI_TransferAbortReceiveEDMA(BOARD_AUDIOCODEC_SAIx, &rxHandle);
        }
        memset(&rxHandle, 0, sizeof(rxHandle));
        if (source.isConnected()) {
            source.getStream()->release();
        }
    }

    void rxAudioCodecCallback(I2S_Type *base, sai_edma_handle_t *handle, status_t status, void *userData)

M module-bsp/board/rt1051/bsp/audio/RT1051CellularAudio.cpp => module-bsp/board/rt1051/bsp/audio/RT1051CellularAudio.cpp +6 -0
@@ 259,6 259,9 @@ namespace bsp
            SAI_TransferTerminateSendEDMA(BOARD_CELLULAR_AUDIO_SAIx, &txHandle);
        }
        memset(&txHandle, 0, sizeof(txHandle));
        if (sink.isConnected()) {
            sink.getStream()->unpeek();
        }
    }

    void RT1051CellularAudio::InStop()


@@ 268,6 271,9 @@ namespace bsp
            SAI_TransferAbortReceiveEDMA(BOARD_CELLULAR_AUDIO_SAIx, &rxHandle);
        }
        memset(&rxHandle, 0, sizeof(rxHandle));
        if (source.isConnected()) {
            source.getStream()->release();
        }
    }

    void rxCellularCallback(I2S_Type *base, sai_edma_handle_t *handle, status_t status, void *userData)