Ejemplo n.º 1
0
bool AudioPlaybackLocal::doPlaybackOrRecord(android::sp<Buffer>& buffer)
{
    if (buffer->amountToHandle() < (size_t)mSizes) {
        mSizes = buffer->amountToHandle();
    }
    if (pcm_write(mPcmHandle, buffer->getUnhanledData(), mSizes)) {
        LOGE("AudioPlaybackLocal error %s", pcm_get_error(mPcmHandle));
        return false;
    }
    buffer->increaseHandled(mSizes);
    LOGV("AudioPlaybackLocal::doPlaybackOrRecord %d", buffer->amountHandled());
    return true;
}
bool AudioRecordingLocal::doPlaybackOrRecord(android::sp<Buffer>& buffer)
{
    int toRead = mSizes;
    if (buffer->amountToHandle() < (size_t)mSizes) {
        toRead = buffer->amountToHandle();
    }
    LOGD("recording will read %d", toRead);

    while (toRead > 0) {
        int readSize = (toRead > mBufferSize) ? mBufferSize : toRead;
        if (pcm_read(mPcmHandle, buffer->getUnhanledData(), readSize)) {
            LOGE("AudioRecordingLocal error %s", pcm_get_error(mPcmHandle));
            return false;
        }
        buffer->increaseHandled(readSize);
        toRead -= readSize;
    }
    LOGV("AudioRecordingLocal::doPlaybackOrRecord %d", buffer->amountHandled());
    return true;
}