diff options
author | Eric Laurent | 2013-09-16 16:31:17 -0500 |
---|---|---|
committer | Eric Laurent | 2013-09-17 13:54:47 -0500 |
commit | c98da79067d89d934c4eb7de6a03e412eb421a5c (patch) | |
tree | 252af255884d55166115e09c74280aeeeeeb5553 | |
parent | 6b0a206624ebe78cc10dba7015438371d1506de5 (diff) | |
download | platform-external-tinyalsa-c98da79067d89d934c4eb7de6a03e412eb421a5c.tar.gz platform-external-tinyalsa-c98da79067d89d934c4eb7de6a03e412eb421a5c.tar.xz platform-external-tinyalsa-c98da79067d89d934c4eb7de6a03e412eb421a5c.zip |
add support for mmap read
Change-Id: Ief5e043025332480307017295317a3d20d6d4d65
-rw-r--r-- | include/tinyalsa/asoundlib.h | 1 | ||||
-rw-r--r-- | pcm.c | 36 |
2 files changed, 30 insertions, 7 deletions
diff --git a/include/tinyalsa/asoundlib.h b/include/tinyalsa/asoundlib.h index 41a8f06..ec526e6 100644 --- a/include/tinyalsa/asoundlib.h +++ b/include/tinyalsa/asoundlib.h | |||
@@ -194,6 +194,7 @@ int pcm_read(struct pcm *pcm, void *data, unsigned int count); | |||
194 | * mmap() support. | 194 | * mmap() support. |
195 | */ | 195 | */ |
196 | int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count); | 196 | int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count); |
197 | int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count); | ||
197 | int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset, | 198 | int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset, |
198 | unsigned int *frames); | 199 | unsigned int *frames); |
199 | int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames); | 200 | int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames); |
@@ -308,7 +308,7 @@ static void pcm_hw_munmap_status(struct pcm *pcm) { | |||
308 | } | 308 | } |
309 | 309 | ||
310 | static int pcm_areas_copy(struct pcm *pcm, unsigned int pcm_offset, | 310 | static int pcm_areas_copy(struct pcm *pcm, unsigned int pcm_offset, |
311 | const char *src, unsigned int src_offset, | 311 | char *buf, unsigned int src_offset, |
312 | unsigned int frames) | 312 | unsigned int frames) |
313 | { | 313 | { |
314 | int size_bytes = pcm_frames_to_bytes(pcm, frames); | 314 | int size_bytes = pcm_frames_to_bytes(pcm, frames); |
@@ -316,12 +316,18 @@ static int pcm_areas_copy(struct pcm *pcm, unsigned int pcm_offset, | |||
316 | int src_offset_bytes = pcm_frames_to_bytes(pcm, src_offset); | 316 | int src_offset_bytes = pcm_frames_to_bytes(pcm, src_offset); |
317 | 317 | ||
318 | /* interleaved only atm */ | 318 | /* interleaved only atm */ |
319 | memcpy((char*)pcm->mmap_buffer + pcm_offset_bytes, | 319 | if (pcm->flags & PCM_IN) |
320 | src + src_offset_bytes, size_bytes); | 320 | memcpy(buf + src_offset_bytes, |
321 | (char*)pcm->mmap_buffer + pcm_offset_bytes, | ||
322 | size_bytes); | ||
323 | else | ||
324 | memcpy((char*)pcm->mmap_buffer + pcm_offset_bytes, | ||
325 | buf + src_offset_bytes, | ||
326 | size_bytes); | ||
321 | return 0; | 327 | return 0; |
322 | } | 328 | } |
323 | 329 | ||
324 | static int pcm_mmap_write_areas(struct pcm *pcm, const char *src, | 330 | static int pcm_mmap_transfer_areas(struct pcm *pcm, char *buf, |
325 | unsigned int offset, unsigned int size) | 331 | unsigned int offset, unsigned int size) |
326 | { | 332 | { |
327 | void *pcm_areas; | 333 | void *pcm_areas; |
@@ -331,7 +337,7 @@ static int pcm_mmap_write_areas(struct pcm *pcm, const char *src, | |||
331 | while (size > 0) { | 337 | while (size > 0) { |
332 | frames = size; | 338 | frames = size; |
333 | pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames); | 339 | pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames); |
334 | pcm_areas_copy(pcm, pcm_offset, src, offset, frames); | 340 | pcm_areas_copy(pcm, pcm_offset, buf, offset, frames); |
335 | commit = pcm_mmap_commit(pcm, pcm_offset, frames); | 341 | commit = pcm_mmap_commit(pcm, pcm_offset, frames); |
336 | if (commit < 0) { | 342 | if (commit < 0) { |
337 | oops(pcm, commit, "failed to commit %d frames\n", frames); | 343 | oops(pcm, commit, "failed to commit %d frames\n", frames); |
@@ -931,7 +937,7 @@ int pcm_wait(struct pcm *pcm, int timeout) | |||
931 | return 1; | 937 | return 1; |
932 | } | 938 | } |
933 | 939 | ||
934 | int pcm_mmap_write(struct pcm *pcm, const void *buffer, unsigned int bytes) | 940 | int pcm_mmap_transfer(struct pcm *pcm, const void *buffer, unsigned int bytes) |
935 | { | 941 | { |
936 | int err = 0, frames, avail; | 942 | int err = 0, frames, avail; |
937 | unsigned int offset = 0, count; | 943 | unsigned int offset = 0, count; |
@@ -1002,7 +1008,7 @@ int pcm_mmap_write(struct pcm *pcm, const void *buffer, unsigned int bytes) | |||
1002 | break; | 1008 | break; |
1003 | 1009 | ||
1004 | /* copy frames from buffer */ | 1010 | /* copy frames from buffer */ |
1005 | frames = pcm_mmap_write_areas(pcm, buffer, offset, frames); | 1011 | frames = pcm_mmap_transfer_areas(pcm, (void *)buffer, offset, frames); |
1006 | if (frames < 0) { | 1012 | if (frames < 0) { |
1007 | fprintf(stderr, "write error: hw 0x%x app 0x%x avail 0x%x\n", | 1013 | fprintf(stderr, "write error: hw 0x%x app 0x%x avail 0x%x\n", |
1008 | (unsigned int)pcm->mmap_status->hw_ptr, | 1014 | (unsigned int)pcm->mmap_status->hw_ptr, |
@@ -1017,3 +1023,19 @@ int pcm_mmap_write(struct pcm *pcm, const void *buffer, unsigned int bytes) | |||
1017 | 1023 | ||
1018 | return 0; | 1024 | return 0; |
1019 | } | 1025 | } |
1026 | |||
1027 | int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count) | ||
1028 | { | ||
1029 | if ((~pcm->flags) & (PCM_OUT | PCM_MMAP)) | ||
1030 | return -ENOSYS; | ||
1031 | |||
1032 | return pcm_mmap_transfer(pcm, (void *)data, count); | ||
1033 | } | ||
1034 | |||
1035 | int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count) | ||
1036 | { | ||
1037 | if ((~pcm->flags) & (PCM_IN | PCM_MMAP)) | ||
1038 | return -ENOSYS; | ||
1039 | |||
1040 | return pcm_mmap_transfer(pcm, data, count); | ||
1041 | } | ||