aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <dvdli@google.com>2022-06-16 04:01:43 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-06-16 04:01:43 +0000
commit014d33173e685b4ed88a3e1fd31fdfed8bc68551 (patch)
tree17904b2db3a834df0f4341d9855da76e77d4f194
parent82eab38b0705f238e583226a49d22a1f391999bf (diff)
parent6f31e32d963011a0af240788dc50dbd40ecd60be (diff)
downloadtinyalsa_new-014d33173e685b4ed88a3e1fd31fdfed8bc68551.tar.gz
Merge remote-tracking branch 'remotes/aosp/upstream-master' into audio am: 9c5ad55c9c am: 9e37e62df7 am: 6f31e32d96
Original change: https://android-review.googlesource.com/c/platform/external/tinyalsa_new/+/2126378 Change-Id: Ie671db5e5e6ad8c9d579e292928f00082d395633 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--src/mixer.c1
-rw-r--r--src/mixer_hw.c1
-rw-r--r--src/pcm.c97
-rw-r--r--src/pcm_hw.c1
-rw-r--r--src/pcm_plugin.c1
-rw-r--r--utils/tinywavinfo.c4
6 files changed, 51 insertions, 54 deletions
diff --git a/src/mixer.c b/src/mixer.c
index afbc015..029fc84 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -55,6 +55,7 @@
#define __user
#endif
+#include <time.h>
#include <sound/asound.h>
#include <tinyalsa/mixer.h>
diff --git a/src/mixer_hw.c b/src/mixer_hw.c
index da5a390..50e9d07 100644
--- a/src/mixer_hw.c
+++ b/src/mixer_hw.c
@@ -42,6 +42,7 @@
#include <sys/ioctl.h>
#include <linux/ioctl.h>
+#include <time.h>
#include <sound/asound.h>
#include "mixer_io.h"
diff --git a/src/pcm.c b/src/pcm.c
index a97d325..d460593 100644
--- a/src/pcm.c
+++ b/src/pcm.c
@@ -305,7 +305,7 @@ struct pcm {
/** Size of the buffer */
unsigned int buffer_size;
/** The boundary for ring buffer pointers */
- unsigned int boundary;
+ unsigned long boundary;
/** Description of the last error that occured */
char error[PCM_ERROR_MAX];
/** Configuration that was passed to @ref pcm_open */
@@ -527,10 +527,6 @@ int pcm_set_config(struct pcm *pcm, const struct pcm_config *config)
sparams.xfer_align = config->period_size / 2; /* needed for old kernels */
sparams.silence_size = config->silence_size;
sparams.silence_threshold = config->silence_threshold;
- pcm->boundary = sparams.boundary = pcm->buffer_size;
-
- while (pcm->boundary * 2 <= INT_MAX - pcm->buffer_size)
- pcm->boundary *= 2;
if (pcm->ops->ioctl(pcm->data, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)) {
int errno_copy = errno;
@@ -538,6 +534,7 @@ int pcm_set_config(struct pcm *pcm, const struct pcm_config *config)
return -errno_copy;
}
+ pcm->boundary = sparams.boundary;
return 0;
}
@@ -603,20 +600,17 @@ unsigned int pcm_frames_to_bytes(const struct pcm *pcm, unsigned int frames)
static int pcm_sync_ptr(struct pcm *pcm, int flags)
{
if (pcm->sync_ptr == NULL) {
- /* status and control are mmaped */
-
+ /* status and control are mmapped */
if (flags & SNDRV_PCM_SYNC_PTR_HWSYNC) {
- if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HWSYNC) == -1) {
- oops(pcm, errno, "failed to sync hardware pointer");
- return -1;
+ if (pcm->ops->ioctl(pcm->data, SNDRV_PCM_IOCTL_HWSYNC) == -1) {
+ return oops(pcm, errno, "failed to sync hardware pointer");
}
}
} else {
pcm->sync_ptr->flags = flags;
if (pcm->ops->ioctl(pcm->data, SNDRV_PCM_IOCTL_SYNC_PTR,
pcm->sync_ptr) < 0) {
- oops(pcm, errno, "failed to sync mmap ptr");
- return -1;
+ return oops(pcm, errno, "failed to sync mmap ptr");
}
}
@@ -1235,45 +1229,49 @@ int pcm_stop(struct pcm *pcm)
return 0;
}
-static inline int pcm_mmap_playback_avail(struct pcm *pcm)
+static inline long pcm_mmap_playback_avail(struct pcm *pcm)
{
- int avail;
-
- avail = pcm->mmap_status->hw_ptr + pcm->buffer_size - pcm->mmap_control->appl_ptr;
+ long avail = pcm->mmap_status->hw_ptr + (unsigned long) pcm->buffer_size -
+ pcm->mmap_control->appl_ptr;
- if (avail < 0)
+ if (avail < 0) {
avail += pcm->boundary;
- else if (avail >= (int)pcm->boundary)
+ } else if ((unsigned long) avail >= pcm->boundary) {
avail -= pcm->boundary;
+ }
return avail;
}
-static inline int pcm_mmap_capture_avail(struct pcm *pcm)
+static inline long pcm_mmap_capture_avail(struct pcm *pcm)
{
- int avail = pcm->mmap_status->hw_ptr - pcm->mmap_control->appl_ptr;
- if (avail < 0)
+ long avail = pcm->mmap_status->hw_ptr - pcm->mmap_control->appl_ptr;
+ if (avail < 0) {
avail += pcm->boundary;
+ }
+
return avail;
}
int pcm_mmap_avail(struct pcm *pcm)
{
pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_HWSYNC);
- if (pcm->flags & PCM_IN)
- return pcm_mmap_capture_avail(pcm);
- else
- return pcm_mmap_playback_avail(pcm);
+ if (pcm->flags & PCM_IN) {
+ return (int) pcm_mmap_capture_avail(pcm);
+ } else {
+ return (int) pcm_mmap_playback_avail(pcm);
+ }
}
static void pcm_mmap_appl_forward(struct pcm *pcm, int frames)
{
- unsigned int appl_ptr = pcm->mmap_control->appl_ptr;
+ unsigned long appl_ptr = pcm->mmap_control->appl_ptr;
appl_ptr += frames;
/* check for boundary wrap */
- if (appl_ptr > pcm->boundary)
- appl_ptr -= pcm->boundary;
+ if (appl_ptr >= pcm->boundary) {
+ appl_ptr -= pcm->boundary;
+ }
pcm->mmap_control->appl_ptr = appl_ptr;
}
@@ -1293,7 +1291,7 @@ int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset,
avail = pcm->buffer_size;
continuous = pcm->buffer_size - *offset;
- /* we can only copy frames if the are availabale and continuos */
+ /* we can only copy frames if the are available and continuos */
copy_frames = *frames;
if (copy_frames > avail)
copy_frames = avail;
@@ -1411,7 +1409,7 @@ again:
*tstamp = pcm->mmap_status->tstamp;
/*
- * When status is mmaped, get avail again to ensure
+ * When status is mmapped, get avail again to ensure
* valid timestamp.
*/
if (!pcm->sync_ptr) {
@@ -1473,22 +1471,22 @@ int pcm_wait(struct pcm *pcm, int timeout)
}
/*
- * Transfer data to/from mmaped buffer. This imitates the
+ * Transfer data to/from mmapped buffer. This imitates the
* behavior of read/write system calls.
*
* However, this doesn't seems to offer any advantage over
* the read/write syscalls. Should it be removed?
*/
-int pcm_mmap_transfer(struct pcm *pcm, void *buffer, unsigned int frames)
+static int pcm_mmap_transfer(struct pcm *pcm, void *buffer, unsigned int frames)
{
int is_playback;
int state;
unsigned int avail;
- unsigned int user_offset;
+ unsigned int user_offset = 0;
int err;
- int tmp;
+ int transferred_frames;
is_playback = !(pcm->flags & PCM_IN);
@@ -1508,17 +1506,15 @@ int pcm_mmap_transfer(struct pcm *pcm, void *buffer, unsigned int frames)
* Another thread may start capture
*/
if (!is_playback && state == PCM_STATE_PREPARED &&
- frames >= pcm->config.start_threshold) {
- err = pcm->ops->ioctl(pcm->data, SNDRV_PCM_IOCTL_START);
- if (err == -1)
+ frames >= pcm->config.start_threshold) {
+ if (pcm_start(pcm) < 0) {
return -1;
- /* state = PCM_STATE_RUNNING */
+ }
}
- avail = pcm_mmap_avail(pcm);
- user_offset = 0;
-
while (frames) {
+ avail = pcm_mmap_avail(pcm);
+
if (!avail) {
if (pcm->flags & PCM_NONBLOCK) {
errno = EAGAIN;
@@ -1531,25 +1527,22 @@ int pcm_mmap_transfer(struct pcm *pcm, void *buffer, unsigned int frames)
errno = -err;
break;
}
-
- /* get hardware pointer */
- avail = pcm_avail_update(pcm);
}
- tmp = pcm_mmap_transfer_areas(pcm, buffer, user_offset, frames);
- if (tmp < 0)
+ transferred_frames = pcm_mmap_transfer_areas(pcm, buffer, user_offset, frames);
+ if (transferred_frames < 0) {
break;
+ }
- user_offset += tmp;
- frames -= tmp;
- avail -= tmp;
+ user_offset += transferred_frames;
+ frames -= transferred_frames;
/* start playback if written >= start_threshold */
if (is_playback && state == PCM_STATE_PREPARED &&
- pcm->buffer_size - avail >= pcm->config.start_threshold) {
- err = pcm->ops->ioctl(pcm->data, SNDRV_PCM_IOCTL_START);
- if (err == -1)
+ pcm->buffer_size - avail >= pcm->config.start_threshold) {
+ if (pcm_start(pcm) < 0) {
break;
+ }
}
}
diff --git a/src/pcm_hw.c b/src/pcm_hw.c
index 5eb53be..2383ae0 100644
--- a/src/pcm_hw.c
+++ b/src/pcm_hw.c
@@ -41,6 +41,7 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/ioctl.h>
+#include <time.h>
#include <sound/asound.h>
#include <tinyalsa/asoundlib.h>
diff --git a/src/pcm_plugin.c b/src/pcm_plugin.c
index 47bf4a5..b6b69aa 100644
--- a/src/pcm_plugin.c
+++ b/src/pcm_plugin.c
@@ -40,6 +40,7 @@
#include <sys/ioctl.h>
#include <linux/ioctl.h>
+#include <time.h>
#include <sound/asound.h>
#include <tinyalsa/asoundlib.h>
#include <tinyalsa/plugin.h>
diff --git a/utils/tinywavinfo.c b/utils/tinywavinfo.c
index a74ca7d..301f8dc 100644
--- a/utils/tinywavinfo.c
+++ b/utils/tinywavinfo.c
@@ -185,7 +185,7 @@ void analyse_sample(FILE *file, unsigned int channels, unsigned int bits,
if (num_read > 0) {
if (2 == bytes_per_sample) {
short *buffer_ptr = (short *)buffer;
- for (i = 0; i < num_read; i += channels) {
+ for (i = 0; i < num_read / bytes_per_sample; i += channels) {
for (ch = 0; ch < channels; ch++) {
int temp = *buffer_ptr++;
/* Signal Normalization */
@@ -196,7 +196,7 @@ void analyse_sample(FILE *file, unsigned int channels, unsigned int bits,
}
if (4 == bytes_per_sample) {
int *buffer_ptr = (int *)buffer;
- for (i = 0; i < num_read; i += channels) {
+ for (i = 0; i < num_read / bytes_per_sample; i += channels) {
for (ch = 0; ch < channels; ch++) {
int temp = *buffer_ptr++;
/* Signal Normalization */