aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.mk2
-rw-r--r--NOTICE53
-rw-r--r--compress.c119
-rw-r--r--cplay.c54
-rw-r--r--include/tinycompress/tinycompress.h25
-rw-r--r--include/tinycompress/version.h4
-rw-r--r--utils.c96
7 files changed, 263 insertions, 90 deletions
diff --git a/Android.mk b/Android.mk
index b9c52e2..104dfef 100644
--- a/Android.mk
+++ b/Android.mk
@@ -2,7 +2,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= $(LOCAL_PATH)/include
-LOCAL_SRC_FILES:= compress.c
+LOCAL_SRC_FILES:= compress.c utils.c
LOCAL_MODULE := libtinycompress
LOCAL_SHARED_LIBRARIES:= libcutils libutils
LOCAL_MODULE_TAGS := optional
diff --git a/NOTICE b/NOTICE
index ba3e45d..5af5078 100644
--- a/NOTICE
+++ b/NOTICE
@@ -207,3 +207,56 @@ You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to
the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+
+===============================================================================
+
+BSD LICENSE
+
+tinycompress utility functions
+Copyright (c) 2011-2013, Intel Corporation
+All rights reserved.
+
+Author: Vinod Koul <vinod.koul@intel.com>
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+Neither the name of Intel Corporation nor the names of its contributors
+may be used to endorse or promote products derived from this software
+without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGE.
+
+LGPL LICENSE
+
+tinycompress utility functions
+Copyright (c) 2011-2013, Intel Corporation
+
+This program is free software; you can redistribute it and/or modify it
+under the terms and conditions of the GNU Lesser General Public License,
+version 2.1, as published by the Free Software Foundation.
+
+This program is distributed in the hope it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program; if not, write to
+the Free Software Foundation, Inc.,
+51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
diff --git a/compress.c b/compress.c
index d5115b6..734fbbf 100644
--- a/compress.c
+++ b/compress.c
@@ -72,9 +72,9 @@
#define __bitwise
#define __user
#include <sound/asound.h>
-#include <sound/compress_params.h>
-#include <sound/compress_offload.h>
-#include <tinycompress/tinycompress.h>
+#include "sound/compress_params.h"
+#include "sound/compress_offload.h"
+#include "tinycompress/tinycompress.h"
#define COMPR_ERR_MAX 128
@@ -88,6 +88,7 @@ struct compress {
struct compr_config *config;
int running;
int max_poll_wait_ms;
+ int nonblocking;
unsigned int gapless_metadata;
unsigned int next_track;
};
@@ -102,10 +103,11 @@ static int oops(struct compress *compress, int e, const char *fmt, ...)
va_end(ap);
sz = strlen(compress->error);
- if (errno)
- snprintf(compress->error + sz, COMPR_ERR_MAX - sz,
- ": %s", strerror(e));
- return e;
+ snprintf(compress->error + sz, COMPR_ERR_MAX - sz,
+ ": %s", strerror(e));
+ errno = e;
+
+ return -1;
}
const char *compress_get_error(struct compress *compress)
@@ -151,27 +153,27 @@ static bool _is_codec_supported(struct compress *compress, struct compr_config *
}
}
if (codec == false) {
- oops(compress, -ENXIO, "this codec is not supported");
+ oops(compress, ENXIO, "this codec is not supported");
return false;
}
if (config->fragment_size < caps->min_fragment_size) {
- oops(compress, -EINVAL, "requested fragment size %d is below min supported %d",
+ oops(compress, EINVAL, "requested fragment size %d is below min supported %d",
config->fragment_size, caps->min_fragment_size);
return false;
}
if (config->fragment_size > caps->max_fragment_size) {
- oops(compress, -EINVAL, "requested fragment size %d is above max supported %d",
+ oops(compress, EINVAL, "requested fragment size %d is above max supported %d",
config->fragment_size, caps->max_fragment_size);
return false;
}
if (config->fragments < caps->min_fragments) {
- oops(compress, -EINVAL, "requested fragments %d are below min supported %d",
+ oops(compress, EINVAL, "requested fragments %d are below min supported %d",
config->fragments, caps->min_fragments);
return false;
}
if (config->fragments > caps->max_fragments) {
- oops(compress, -EINVAL, "requested fragments %d are above max supported %d",
+ oops(compress, EINVAL, "requested fragments %d are above max supported %d",
config->fragments, caps->max_fragments);
return false;
}
@@ -218,8 +220,13 @@ struct compress *compress_open(unsigned int card, unsigned int device,
struct snd_compr_caps caps;
char fn[256];
+ if (!config) {
+ oops(&bad_compress, EINVAL, "passed bad config");
+ return &bad_compress;
+ }
+
compress = calloc(1, sizeof(struct compress));
- if (!compress || !config) {
+ if (!compress) {
oops(&bad_compress, errno, "cannot allocate compress object");
return &bad_compress;
}
@@ -229,7 +236,6 @@ struct compress *compress_open(unsigned int card, unsigned int device,
compress->config = calloc(1, sizeof(*config));
if (!compress->config)
goto input_fail;
- memcpy(compress->config, config, sizeof(*compress->config));
snprintf(fn, sizeof(fn), "/dev/snd/comprC%uD%u", card, device);
@@ -237,7 +243,7 @@ struct compress *compress_open(unsigned int card, unsigned int device,
compress->flags = flags;
if (!((flags & COMPRESS_OUT) || (flags & COMPRESS_IN))) {
- oops(&bad_compress, -EINVAL, "can't deduce device direction from given flags");
+ oops(&bad_compress, EINVAL, "can't deduce device direction from given flags");
goto config_fail;
}
@@ -271,6 +277,8 @@ struct compress *compress_open(unsigned int card, unsigned int device,
goto codec_fail;
}
#endif
+
+ memcpy(compress->config, config, sizeof(*compress->config));
fill_compress_params(config, &params);
if (ioctl(compress->fd, SNDRV_COMPRESS_SET_PARAMS, &params)) {
@@ -310,12 +318,12 @@ int compress_get_hpointer(struct compress *compress,
__u64 time;
if (!is_compress_ready(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &kavail))
return oops(compress, errno, "cannot get avail");
if (0 == kavail.tstamp.sampling_rate)
- return oops(compress, errno, "invalid paramter");
+ return oops(compress, ENODATA, "sample rate unknown");
*avail = (unsigned int)kavail.avail;
time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate;
tstamp->tv_sec = time;
@@ -330,7 +338,7 @@ int compress_get_tstamp(struct compress *compress,
struct snd_compr_tstamp ktstamp;
if (!is_compress_ready(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
if (ioctl(compress->fd, SNDRV_COMPRESS_TSTAMP, &ktstamp))
return oops(compress, errno, "cannot get tstamp");
@@ -350,9 +358,9 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
const unsigned int frag_size = compress->config->fragment_size;
if (!(compress->flags & COMPRESS_IN))
- return oops(compress, -EINVAL, "Invalid flag set");
+ return oops(compress, EINVAL, "Invalid flag set");
if (!is_compress_ready(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
fds.fd = compress->fd;
fds.events = POLLOUT;
@@ -361,12 +369,14 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail))
return oops(compress, errno, "cannot get avail");
- if ( (avail.avail < frag_size)
- || ((to_write != 0) && (avail.avail < size)) ) {
- /* not enough space for one fragment, or we have done
- * a short write and there isn't enough space for all
- * the remaining data
- */
+ /* We can write if we have at least one fragment available
+ * or there is enough space for all remaining data
+ */
+ if ((avail.avail < frag_size) && (avail.avail < size)) {
+
+ if (compress->nonblocking)
+ return total;
+
ret = poll(&fds, 1, compress->max_poll_wait_ms);
/* A pause will cause -EBADFD or zero.
* This is not an error, just stop writing */
@@ -378,7 +388,7 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
continue;
}
if (fds.revents & POLLERR) {
- return oops(compress, -EIO, "poll returned error!");
+ return oops(compress, EIO, "poll returned error!");
}
}
/* write avail bytes */
@@ -410,9 +420,9 @@ int compress_read(struct compress *compress, void *buf, unsigned int size)
const unsigned int frag_size = compress->config->fragment_size;
if (!(compress->flags & COMPRESS_OUT))
- return oops(compress, -EINVAL, "Invalid flag set");
+ return oops(compress, EINVAL, "Invalid flag set");
if (!is_compress_ready(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
fds.fd = compress->fd;
fds.events = POLLIN;
@@ -424,6 +434,9 @@ int compress_read(struct compress *compress, void *buf, unsigned int size)
/* Less than one fragment available and not at the
* end of the read, so poll
*/
+ if (compress->nonblocking)
+ return total;
+
ret = poll(&fds, 1, compress->max_poll_wait_ms);
/* A pause will cause -EBADFD or zero.
* This is not an error, just stop reading */
@@ -435,7 +448,7 @@ int compress_read(struct compress *compress, void *buf, unsigned int size)
continue;
}
if (fds.revents & POLLERR) {
- return oops(compress, -EIO, "poll returned error!");
+ return oops(compress, EIO, "poll returned error!");
}
}
/* read avail bytes */
@@ -461,7 +474,7 @@ int compress_read(struct compress *compress, void *buf, unsigned int size)
int compress_start(struct compress *compress)
{
if (!is_compress_ready(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
if (ioctl(compress->fd, SNDRV_COMPRESS_START))
return oops(compress, errno, "cannot start the stream");
compress->running = 1;
@@ -472,7 +485,7 @@ int compress_start(struct compress *compress)
int compress_stop(struct compress *compress)
{
if (!is_compress_running(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
if (ioctl(compress->fd, SNDRV_COMPRESS_STOP))
return oops(compress, errno, "cannot stop the stream");
return 0;
@@ -481,7 +494,7 @@ int compress_stop(struct compress *compress)
int compress_pause(struct compress *compress)
{
if (!is_compress_running(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
if (ioctl(compress->fd, SNDRV_COMPRESS_PAUSE))
return oops(compress, errno, "cannot pause the stream");
return 0;
@@ -497,7 +510,7 @@ int compress_resume(struct compress *compress)
int compress_drain(struct compress *compress)
{
if (!is_compress_running(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
if (ioctl(compress->fd, SNDRV_COMPRESS_DRAIN))
return oops(compress, errno, "cannot drain the stream");
return 0;
@@ -506,10 +519,10 @@ int compress_drain(struct compress *compress)
int compress_partial_drain(struct compress *compress)
{
if (!is_compress_running(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
if (!compress->next_track)
- return oops(compress, -EPERM, "next track not signalled");
+ return oops(compress, EPERM, "next track not signalled");
if (ioctl(compress->fd, SNDRV_COMPRESS_PARTIAL_DRAIN))
return oops(compress, errno, "cannot drain the stream\n");
compress->next_track = 0;
@@ -519,10 +532,10 @@ int compress_partial_drain(struct compress *compress)
int compress_next_track(struct compress *compress)
{
if (!is_compress_running(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
if (!compress->gapless_metadata)
- return oops(compress, -EPERM, "metadata not set");
+ return oops(compress, EPERM, "metadata not set");
if (ioctl(compress->fd, SNDRV_COMPRESS_NEXT_TRACK))
return oops(compress, errno, "cannot set next track\n");
compress->next_track = 1;
@@ -537,14 +550,14 @@ int compress_set_gapless_metadata(struct compress *compress,
int version;
if (!is_compress_ready(compress))
- return oops(compress, -ENODEV, "device not ready");
+ return oops(compress, ENODEV, "device not ready");
version = get_compress_version(compress);
if (version <= 0)
return -1;
if (version < SNDRV_PROTOCOL_VERSION(0, 1, 1))
- return oops(compress, -ENXIO, "gapless apis not supported in kernel");
+ return oops(compress, ENXIO, "gapless apis not supported in kernel");
metadata.key = SNDRV_COMPRESS_ENCODER_PADDING;
metadata.value[0] = mdata->encoder_padding;
@@ -589,3 +602,29 @@ void compress_set_max_poll_wait(struct compress *compress, int milliseconds)
compress->max_poll_wait_ms = milliseconds;
}
+void compress_nonblock(struct compress *compress, int nonblock)
+{
+ compress->nonblocking = !!nonblock;
+}
+
+int compress_wait(struct compress *compress, int timeout_ms)
+{
+ struct pollfd fds;
+ int ret;
+
+ fds.fd = compress->fd;
+ fds.events = POLLOUT | POLLIN;
+
+ ret = poll(&fds, 1, timeout_ms);
+ /* A pause will cause -EBADFD or zero. */
+ if ((ret < 0) && (ret != -EBADFD))
+ return oops(compress, errno, "poll error");
+ if (fds.revents & (POLLOUT | POLLIN)) {
+ return 0;
+ }
+ if (fds.revents & POLLERR) {
+ return oops(compress, -EIO, "poll returned error!");
+ }
+ return ret;
+}
+
diff --git a/cplay.c b/cplay.c
index 21e64a4..10c5424 100644
--- a/cplay.c
+++ b/cplay.c
@@ -66,9 +66,9 @@
#define __force
#define __bitwise
#define __user
-#include <sound/compress_params.h>
-#include <tinycompress/tinycompress.h>
-#include <tinycompress/tinymp3.h>
+#include "sound/compress_params.h"
+#include "tinycompress/tinycompress.h"
+#include "tinycompress/tinymp3.h"
static int verbose;
@@ -226,49 +226,11 @@ void play_samples(char *name, unsigned int card, unsigned int device,
codec.id = SND_AUDIOCODEC_MP3;
codec.ch_in = channels;
codec.ch_out = channels;
- switch (rate) {
- case 5512:
- codec.sample_rate = SNDRV_PCM_RATE_5512;
- break;
- case 8000:
- codec.sample_rate = SNDRV_PCM_RATE_8000;
- break;
- case 11025:
- codec.sample_rate = SNDRV_PCM_RATE_11025;
- break;
- case 16000:
- codec.sample_rate = SNDRV_PCM_RATE_16000;
- break;
- case 220500:
- codec.sample_rate = SNDRV_PCM_RATE_22050;
- break;
- case 32000:
- codec.sample_rate = SNDRV_PCM_RATE_32000;
- break;
- case 44100:
- codec.sample_rate = SNDRV_PCM_RATE_44100;
- break;
- case 48000:
- codec.sample_rate = SNDRV_PCM_RATE_48000;
- break;
- case 64000:
- codec.sample_rate = SNDRV_PCM_RATE_64000;
- break;
- case 88200:
- codec.sample_rate = SNDRV_PCM_RATE_88200;
- break;
- case 96000:
- codec.sample_rate = SNDRV_PCM_RATE_96000;
- break;
- case 176400:
- codec.sample_rate = SNDRV_PCM_RATE_176400;
- break;
- case 192000:
- codec.sample_rate = SNDRV_PCM_RATE_192000;
- break;
- default:
- fprintf(stderr, "unknown sample rate %d\n", rate);
- goto FILE_EXIT;
+ codec.sample_rate = compress_get_alsa_rate(rate);
+ if (!codec.sample_rate) {
+ fprintf(stderr, "invalid sample rate %d\n", rate);
+ fclose(file);
+ exit(EXIT_FAILURE);
}
codec.bit_rate = bits;
codec.rate_control = 0;
diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h
index 9867afc..40de69a 100644
--- a/include/tinycompress/tinycompress.h
+++ b/include/tinycompress/tinycompress.h
@@ -130,7 +130,15 @@ int compress_get_tstamp(struct compress *compress,
/*
* compress_write: write data to the compress stream
* return bytes written on success, negative on error
- * this is a blocking call
+ * By default this is a blocking call and will not return
+ * until all bytes have been written or there was a
+ * write error.
+ * If non-blocking mode has been enabled with compress_nonblock(),
+ * this function will write all bytes that can be written without
+ * blocking and will then return the number of bytes successfully
+ * written. If the return value is not an error and is < size
+ * the caller can use compress_wait() to block until the driver
+ * is ready for more data.
*
* @compress: compress stream to be written to
* @buf: pointer to data
@@ -141,6 +149,13 @@ int compress_write(struct compress *compress, const void *buf, unsigned int size
/*
* compress_read: read data from the compress stream
* return bytes read on success, negative on error
+ * By default this is a blocking call and will block until
+ * size bytes have been written or there was a read error.
+ * If non-blocking mode was enabled using compress_nonblock()
+ * the behaviour will change to read only as many bytes as
+ * are currently available (if no bytes are available it
+ * will return immediately). The caller can then use
+ * compress_wait() to block until more bytes are available.
*
* @compress: compress stream from where data is to be read
* @buf: pointer to data buffer
@@ -242,6 +257,12 @@ bool is_codec_supported(unsigned int card, unsigned int device,
*/
void compress_set_max_poll_wait(struct compress *compress, int milliseconds);
+/* Enable or disable non-blocking mode for write and read */
+void compress_nonblock(struct compress *compress, int nonblock);
+
+/* Wait for ring buffer to ready for next read or write */
+int compress_wait(struct compress *compress, int timeout_ms);
+
int is_compress_running(struct compress *compress);
int is_compress_ready(struct compress *compress);
@@ -267,4 +288,6 @@ const char *compress_get_error(struct compress *compress);
#define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */
#define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */
+/* utility functions */
+unsigned int compress_get_alsa_rate(unsigned int rate);
#endif
diff --git a/include/tinycompress/version.h b/include/tinycompress/version.h
index 795fe77..000f6a2 100644
--- a/include/tinycompress/version.h
+++ b/include/tinycompress/version.h
@@ -55,7 +55,7 @@
#define TINYCOMPRESS_LIB_MAJOR 0 /* major number of library version */
-#define TINYCOMPRESS_LIB_MINOR 1 /* minor number of library version */
+#define TINYCOMPRESS_LIB_MINOR 2 /* minor number of library version */
#define TINYCOMPRESS_LIB_SUBMINOR 0 /* subminor number of library version */
/** library version */
@@ -65,6 +65,6 @@
TINYCOMPRESS_LIB_SUBMINOR)
/** library version (string) */
-#define TINYCOMPRESS_LIB_VERSION_STR "0.1.0"
+#define TINYCOMPRESS_LIB_VERSION_STR "0.2.0"
#endif
diff --git a/utils.c b/utils.c
new file mode 100644
index 0000000..fa37f23
--- /dev/null
+++ b/utils.c
@@ -0,0 +1,96 @@
+/*
+ * BSD LICENSE
+ *
+ * tinycompress utility functions
+ * Copyright (c) 2011-2013, Intel Corporation
+ * All rights reserved.
+ *
+ * Author: Vinod Koul <vinod.koul@intel.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * LGPL LICENSE
+ *
+ * tinycompress utility functions
+ * Copyright (c) 2011-2013, Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to
+ * the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <linux/types.h>
+#include <sys/time.h>
+#define __force
+#define __bitwise
+#define __user
+#include "tinycompress/tinycompress.h"
+
+
+unsigned int compress_get_alsa_rate(unsigned int rate)
+{
+ switch (rate) {
+ case 5512:
+ return SNDRV_PCM_RATE_5512;
+ case 8000:
+ return SNDRV_PCM_RATE_8000;
+ case 11025:
+ return SNDRV_PCM_RATE_11025;
+ case 16000:
+ return SNDRV_PCM_RATE_16000;
+ case 220500:
+ return SNDRV_PCM_RATE_22050;
+ case 32000:
+ return SNDRV_PCM_RATE_32000;
+ case 44100:
+ return SNDRV_PCM_RATE_44100;
+ case 48000:
+ return SNDRV_PCM_RATE_48000;
+ case 64000:
+ return SNDRV_PCM_RATE_64000;
+ case 88200:
+ return SNDRV_PCM_RATE_88200;
+ case 96000:
+ return SNDRV_PCM_RATE_96000;
+ case 176400:
+ return SNDRV_PCM_RATE_176400;
+ case 192000:
+ return SNDRV_PCM_RATE_192000;
+ default:
+ return 0;
+ }
+}