aboutsummaryrefslogtreecommitdiff
path: root/src/pcm.c
diff options
context:
space:
mode:
authordvdli <dvdli@google.com>2020-10-28 22:56:53 +0800
committerdvdli <dvdli@google.com>2020-10-28 22:56:53 +0800
commite43e85c1885d935e36c53fc04c4f1660c2b3fd3a (patch)
tree2ec47946b04a22b3855a5c575ef9c5373db74de8 /src/pcm.c
parent72216211c7a5f29510a2f50dbdc70b35af44fb3a (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
Diffstat (limited to 'src/pcm.c')
-rw-r--r--src/pcm.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pcm.c b/src/pcm.c
index eb16ed3..3b54ec7 100644
--- a/src/pcm.c
+++ b/src/pcm.c
@@ -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;