static snd_pcm_sframes_t snd_pcm_ioplug_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size) { if (pcm->mmap_rw) return snd_pcm_mmap_readi(pcm, buffer, size); else { snd_pcm_channel_area_t areas[pcm->channels]; snd_pcm_areas_from_buf(pcm, areas, buffer); return snd_pcm_read_areas(pcm, areas, 0, size, ioplug_priv_transfer_areas); } }
int FCDProThread::work(int n_items) { int l; SampleVector::iterator it; void *out; it = m_convertBuffer.begin(); out = (void *)&it[0]; l = snd_pcm_mmap_readi(fcd_handle, out, (snd_pcm_uframes_t)n_items); if (l > 0) m_sampleFifo->write(it, it + l); if (l == -EPIPE) { qDebug("FCD: Overrun detected"); return 0; } return l; }
ssize_t AudioStreamInALSA::read(void *buffer, ssize_t bytes) { android::AutoMutex lock(mLock); if (!mPowerLock) { acquire_wake_lock (PARTIAL_WAKE_LOCK, "AudioInLock"); mPowerLock = true; } acoustic_device_t *aDev = acoustics(); // If there is an acoustics module read method, then it overrides this // implementation (unlike AudioStreamOutALSA write). if (aDev && aDev->read) return aDev->read(aDev, buffer, bytes); snd_pcm_sframes_t n, frames = snd_pcm_bytes_to_frames(mHandle->handle, bytes); status_t err; do { if (mHandle->mmap) n = snd_pcm_mmap_readi(mHandle->handle, buffer, frames); else n = snd_pcm_readi(mHandle->handle, buffer, frames); if (n < frames) { if (mHandle->handle) { if (n < 0) { n = snd_pcm_recover(mHandle->handle, n, 0); if (aDev && aDev->recover) aDev->recover(aDev, n); } else n = snd_pcm_prepare(mHandle->handle); } return static_cast<ssize_t>(n); } } while (n == -EAGAIN); return static_cast<ssize_t>(snd_pcm_frames_to_bytes(mHandle->handle, n)); }