int audioPlayerWriteFrame()

in source/T31/T31AudioPlayer.c [241:292]


int audioPlayerWriteFrame(AudioPlayerHandle handle, void* pData, const size_t size)
{
    T31_HANDLE_NULL_CHECK(handle);
    T31_HANDLE_GET(handle);

    T31_HANDLE_STATUS_CHECK(t31Handle, AUD_PLY_STATUS_STREAM_ON);

    if (!pData) {
        return -EINVAL;
    }

    IMPAudioFrame frame = {0};

    if (t31Handle->format != AUD_FMT_PCM) {
        // Need to decode
        IMPAudioStream streamIn;
        streamIn.stream = (uint8_t*) pData;
        streamIn.len = size;

        if (IMP_ADEC_SendStream(T31_SPK_DEC_CHN_ID, &streamIn, BLOCK)) {
            LOG("IMP_ADEC_SendStream failed");
            return -EAGAIN;
        }

        IMPAudioStream streamOut;
        if (IMP_ADEC_PollingStream(T31_SPK_DEC_CHN_ID, 1000)) {
            LOG("IMP_ADEC_PollingStream failed");
            return -EAGAIN;
        }

        if (IMP_ADEC_GetStream(T31_SPK_DEC_CHN_ID, &streamOut, BLOCK)) {
            LOG("IMP_ADEC_GetStream failed");
            return -EAGAIN;
        }

        frame.virAddr = (uint32_t*) streamOut.stream;
        frame.len = streamOut.len;
        playFrame(handle, &frame);

        if (IMP_ADEC_ReleaseStream(T31_SPK_DEC_CHN_ID, &streamOut)) {
            LOG("IMP_ADEC_ReleaseStream failed");
            return -EAGAIN;
        }
    } else {
        // No need to decode
        frame.virAddr = (uint32_t*) pData;
        frame.len = size;
        playFrame(handle, &frame);
    }

    return 0;
}