diff options
author | dvdli <dvdli@google.com> | 2020-10-28 22:56:53 +0800 |
---|---|---|
committer | dvdli <dvdli@google.com> | 2020-10-28 22:56:53 +0800 |
commit | e43e85c1885d935e36c53fc04c4f1660c2b3fd3a (patch) | |
tree | 2ec47946b04a22b3855a5c575ef9c5373db74de8 | |
parent | 72216211c7a5f29510a2f50dbdc70b35af44fb3a (diff) |
AOSP CL "pcm: add API for MMAP NO IRQ mode"
https://android.googlesource.com/platform/external/tinyalsa/+/5b15b4cbd9e779a4ecd87e0f757fb0f8f6b9bcb8
commit 5b15b4cbd9e779a4ecd87e0f757fb0f8f6b9bcb8
author Eric Laurent <elaurent@google.com>
pcm: add API for MMAP NO IRQ mode
Bug: 33398120
Test: build
Change-Id: Iecb47f76337d98ceb01044ca488a04e1f350c6bc
-rw-r--r-- | include/tinyalsa/pcm.h | 2 | ||||
-rw-r--r-- | src/pcm.c | 28 |
2 files changed, 30 insertions, 0 deletions
diff --git a/include/tinyalsa/pcm.h b/include/tinyalsa/pcm.h index 99ca786..cdc31a5 100644 --- a/include/tinyalsa/pcm.h +++ b/include/tinyalsa/pcm.h @@ -343,6 +343,8 @@ int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames); int pcm_mmap_avail(struct pcm *pcm); +int pcm_mmap_get_hw_ptr(struct pcm* pcm, unsigned int *hw_ptr, struct timespec *tstamp); + int pcm_get_poll_fd(struct pcm *pcm); int pcm_link(struct pcm *pcm1, struct pcm *pcm2); @@ -1560,6 +1560,34 @@ int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count) return pcm_mmap_transfer(pcm, data, pcm_bytes_to_frames(pcm, count)); } +/* Returns current read/write position in the mmap buffer with associated time stamp. */ +int pcm_mmap_get_hw_ptr(struct pcm* pcm, unsigned int *hw_ptr, struct timespec *tstamp) +{ + int rc; + + if (pcm == NULL || hw_ptr == NULL || tstamp == NULL) + return oops(pcm, EINVAL, "pcm %p, hw_ptr %p, tstamp %p", pcm, hw_ptr, tstamp); + + if (!pcm_is_ready(pcm)) + return oops(pcm, errno, "pcm_is_ready failed"); + + rc = pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_HWSYNC); + if (rc < 0) + return oops(pcm, errno, "pcm_sync_ptr failed"); + + if ((pcm->mmap_status->state != PCM_STATE_RUNNING) && + (pcm->mmap_status->state != PCM_STATE_DRAINING)) + return oops(pcm, ENOSYS, "invalid stream state %d", pcm->mmap_status->state); + + *tstamp = pcm->mmap_status->tstamp; + if (tstamp->tv_sec == 0 && tstamp->tv_nsec == 0) + return oops(pcm, errno, "invalid time stamp"); + + *hw_ptr = pcm->mmap_status->hw_ptr; + + return 0; +} + static int pcm_rw_transfer(struct pcm *pcm, void *data, unsigned int frames) { int is_playback; |