Initial import tinycompress package which is required fo enabling audio dsp hardware... devel/audiohwdec accepted/tizen/generic/20140314.080452 accepted/tizen/ivi/20140314.171336 accepted/tizen/ivi/panda/20140318.013608 submit/tizen/20140314.055800
authorvivian,zhang <vivian.zhang@intel.com>
Wed, 18 Sep 2013 02:08:30 +0000 (10:08 +0800)
committerZhang,Vivian <vivian.zhang@intel.com>
Wed, 18 Sep 2013 06:28:00 +0000 (14:28 +0800)
Change-Id: I6ef4f8731ad6bacdf0163da9b22ae88cec1ead13

15 files changed:
Android.mk [new file with mode: 0644]
CMakeLists.txt [new file with mode: 0644]
README [new file with mode: 0644]
compress.c [new file with mode: 0644]
cplay.c [new file with mode: 0644]
include/sound/compress_offload.h [new file with mode: 0644]
include/sound/compress_params.h [new file with mode: 0644]
include/tinycompress/tinycompress.h [new file with mode: 0644]
include/tinycompress/tinymp3.h [new file with mode: 0644]
include/tinycompress/version.h [new file with mode: 0644]
makefile.linux [new file with mode: 0644]
packaging/tinycompress.changes [new file with mode: 0644]
packaging/tinycompress.spec [new file with mode: 0644]
tinycompress.pc.in [new file with mode: 0644]
utils.c [new file with mode: 0644]

diff --git a/Android.mk b/Android.mk
new file mode 100644 (file)
index 0000000..104dfef
--- /dev/null
@@ -0,0 +1,22 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_C_INCLUDES:= $(LOCAL_PATH)/include
+LOCAL_SRC_FILES:= compress.c utils.c
+LOCAL_MODULE := libtinycompress
+LOCAL_SHARED_LIBRARIES:= libcutils libutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_PRELINK_MODULE := false
+
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+
+LOCAL_C_INCLUDES:= $(LOCAL_PATH)/include
+LOCAL_SRC_FILES:= cplay.c
+LOCAL_MODULE := cplay
+LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinycompress
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..82a26d1
--- /dev/null
@@ -0,0 +1,51 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(tinycompress C)
+
+#INCLUDE(FindPkgConfig)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+
+# Set required packages
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED alsa)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_SOURCE_DIR}/include ${EXTRA_CFLAGS} -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align")
+
+MESSAGE(${CMAKE_C_FLAGS})
+MESSAGE(${CMAKE_EXE_LINKER_FLAGS})
+
+SET(CPLAY_SRCS
+               cplay.c
+)
+
+SET(TINYCOMPRESS_SRCS
+               compress.c
+               utils.c
+)
+
+# library build
+ADD_LIBRARY(tinycompress SHARED ${TINYCOMPRESS_SRCS})
+TARGET_LINK_LIBRARIES(tinycompress ${pkgs_LDFLAGS})
+SET_TARGET_PROPERTIES(tinycompress PROPERTIES VERSION 0.1.0 SOVERSION 0 OUTPUT_NAME tinycompress)
+
+# executable build
+ADD_EXECUTABLE(cplay ${CPLAY_SRCS})
+TARGET_LINK_LIBRARIES(cplay ${pkg_LDFLAGS} tinycompress)
+
+# pkgconfig file
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+CONFIGURE_FILE(tinycompress.pc.in tinycompress.pc @ONLY)
+
+
+# install
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include/tinycompress-0.2.0)
+INSTALL(TARGETS tinycompress LIBRARY DESTINATION lib)
+INSTALL(TARGETS cplay RUNTIME DESTINATION bin)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinycompress.pc DESTINATION lib/pkgconfig)
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..73c19a6
--- /dev/null
+++ b/README
@@ -0,0 +1,30 @@
+               README for tinycompress
+               =======================
+              vinod.koul@linux.intel.com
+              ==========================
+
+1. WHAT
+       tinycompress is a userspace library for anyone who wants to use the ALSA
+compressed APIs introduced in Linux 3.3
+This library provides the APIs to open a ALSA compressed device and read/write
+compressed data like MP3 etc to it.
+
+       This also includes a utility command line player (cplay) which demonstrates 
+the usage of this API. Currently this contains support for playing the mp3 format
+
+2. WHERE
+       The library can found in alsa-project.org
+Git: git clone git://git.alsa-project.org/tinycompress.git
+Http: http://git.alsa-project.org/?p=tinycompress.git
+
+3. PATCHES
+       Please send any enhancements/fixes to alsa developer mailing list at:
+alsa-devel@alsa-project.org. 
+
+4. LICENSE
+       tinycompress is provided under LGPL and BSD dual license
+
+5. CREDITS
+- Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> for library design
+- Navjot Singh <navjot.singh@intel.com> for writing the mp3 parser code 
+
diff --git a/compress.c b/compress.c
new file mode 100644 (file)
index 0000000..734fbbf
--- /dev/null
@@ -0,0 +1,630 @@
+/*
+ * BSD LICENSE
+ *
+ * tinycompress library for compress audio offload in alsa
+ * Copyright (c) 2011-2012, Intel Corporation
+ * All rights reserved.
+ *
+ * Author: Vinod Koul <vinod.koul@linux.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 library for compress audio offload in alsa
+ * Copyright (c) 2011-2012, 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 <fcntl.h>
+#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <poll.h>
+#include <stdbool.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <limits.h>
+
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#define __force
+#define __bitwise
+#define __user
+#include <sound/asound.h>
+#include "sound/compress_params.h"
+#include "sound/compress_offload.h"
+#include "tinycompress/tinycompress.h"
+
+#define COMPR_ERR_MAX 128
+
+/* Default maximum time we will wait in a poll() - 20 seconds */
+#define DEFAULT_MAX_POLL_WAIT_MS    20000
+
+struct compress {
+       int fd;
+       unsigned int flags;
+       char error[COMPR_ERR_MAX];
+       struct compr_config *config;
+       int running;
+       int max_poll_wait_ms;
+       int nonblocking;
+       unsigned int gapless_metadata;
+       unsigned int next_track;
+};
+
+static int oops(struct compress *compress, int e, const char *fmt, ...)
+{
+       va_list ap;
+       int sz;
+
+       va_start(ap, fmt);
+       vsnprintf(compress->error, COMPR_ERR_MAX, fmt, ap);
+       va_end(ap);
+       sz = strlen(compress->error);
+
+       snprintf(compress->error + sz, COMPR_ERR_MAX - sz,
+               ": %s", strerror(e));
+       errno = e;
+
+       return -1;
+}
+
+const char *compress_get_error(struct compress *compress)
+{
+       return compress->error;
+}
+static struct compress bad_compress = {
+       .fd = -1,
+};
+
+int is_compress_running(struct compress *compress)
+{
+       return ((compress->fd > 0) && compress->running) ? 1 : 0;
+}
+
+int is_compress_ready(struct compress *compress)
+{
+       return (compress->fd > 0) ? 1 : 0;
+}
+
+static int get_compress_version(struct compress *compress)
+{
+       int version = 0;
+
+       if (ioctl(compress->fd, SNDRV_COMPRESS_IOCTL_VERSION, &version)) {
+               oops(compress, errno, "cant read version");
+               return -1;
+       }
+       return version;
+}
+
+static bool _is_codec_supported(struct compress *compress, struct compr_config *config,
+                               const struct snd_compr_caps *caps)
+{
+       bool codec = false;
+       unsigned int i;
+
+       for (i = 0; i < caps->num_codecs; i++) {
+               if (caps->codecs[i] == config->codec->id) {
+                       /* found the codec */
+                       codec = true;
+                       break;
+               }
+       }
+       if (codec == false) {
+               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",
+                       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",
+                       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",
+                       config->fragments, caps->min_fragments);
+               return false;
+       }
+       if (config->fragments > caps->max_fragments) {
+               oops(compress, EINVAL, "requested fragments %d are above max supported %d",
+                       config->fragments, caps->max_fragments);
+               return false;
+       }
+
+       /* TODO: match the codec properties */
+       return true;
+}
+
+static bool _is_codec_type_supported(int fd, struct snd_codec *codec)
+{
+       struct snd_compr_caps caps;
+       bool found = false;
+       unsigned int i;
+
+       if (ioctl(fd, SNDRV_COMPRESS_GET_CAPS, &caps)) {
+               oops(&bad_compress, errno, "cannot get device caps");
+               return false;
+       }
+
+       for (i = 0; i < caps.num_codecs; i++) {
+               if (caps.codecs[i] == codec->id) {
+                       /* found the codec */
+                       found = true;
+                       break;
+               }
+       }
+       /* TODO: match the codec properties */
+       return found;
+}
+
+static inline void
+fill_compress_params(struct compr_config *config, struct snd_compr_params *params)
+{
+       params->buffer.fragment_size = config->fragment_size;
+       params->buffer.fragments = config->fragments;
+       memcpy(&params->codec, config->codec, sizeof(params->codec));
+}
+
+struct compress *compress_open(unsigned int card, unsigned int device,
+               unsigned int flags, struct compr_config *config)
+{
+       struct compress *compress;
+       struct snd_compr_params params;
+       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) {
+               oops(&bad_compress, errno, "cannot allocate compress object");
+               return &bad_compress;
+       }
+
+       compress->next_track = 0;
+       compress->gapless_metadata = 0;
+       compress->config = calloc(1, sizeof(*config));
+       if (!compress->config)
+               goto input_fail;
+
+       snprintf(fn, sizeof(fn), "/dev/snd/comprC%uD%u", card, device);
+
+       compress->max_poll_wait_ms = DEFAULT_MAX_POLL_WAIT_MS;
+
+       compress->flags = flags;
+       if (!((flags & COMPRESS_OUT) || (flags & COMPRESS_IN))) {
+               oops(&bad_compress, EINVAL, "can't deduce device direction from given flags");
+               goto config_fail;
+       }
+
+       if (flags & COMPRESS_OUT) {
+               compress->fd = open(fn, O_RDONLY);
+       } else {
+               compress->fd = open(fn, O_WRONLY);
+       }
+       if (compress->fd < 0) {
+               oops(&bad_compress, errno, "cannot open device '%s'", fn);
+               goto config_fail;
+       }
+
+       if (ioctl(compress->fd, SNDRV_COMPRESS_GET_CAPS, &caps)) {
+               oops(compress, errno, "cannot get device caps");
+               goto codec_fail;
+       }
+
+       /* If caller passed "don't care" fill in default values */
+       if ((config->fragment_size == 0) || (config->fragments == 0)) {
+               config->fragment_size = caps.min_fragment_size;
+               config->fragments = caps.max_fragments;
+       }
+
+#if 0
+       /* FIXME need to turn this On when DSP supports
+        * and treat in no support case
+        */
+       if (_is_codec_supported(compress, config, &caps) == false) {
+               oops(compress, errno, "codec not supported\n");
+               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)) {
+               oops(&bad_compress, errno, "cannot set device");
+               goto codec_fail;
+       }
+
+       return compress;
+
+codec_fail:
+       close(compress->fd);
+       compress->fd = -1;
+config_fail:
+       free(compress->config);
+input_fail:
+       free(compress);
+       return &bad_compress;
+}
+
+void compress_close(struct compress *compress)
+{
+       if (compress == &bad_compress)
+               return;
+
+       if (compress->fd >= 0)
+               close(compress->fd);
+       compress->running = 0;
+       compress->fd = -1;
+       free(compress->config);
+       free(compress);
+}
+
+int compress_get_hpointer(struct compress *compress,
+               unsigned int *avail, struct timespec *tstamp)
+{
+       struct snd_compr_avail kavail;
+       __u64 time;
+
+       if (!is_compress_ready(compress))
+               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, ENODATA, "sample rate unknown");
+       *avail = (unsigned int)kavail.avail;
+       time = kavail.tstamp.pcm_io_frames / kavail.tstamp.sampling_rate;
+       tstamp->tv_sec = time;
+       time = kavail.tstamp.pcm_io_frames % kavail.tstamp.sampling_rate;
+       tstamp->tv_nsec = time * 1000000000 / kavail.tstamp.sampling_rate;
+       return 0;
+}
+
+int compress_get_tstamp(struct compress *compress,
+                       unsigned long *samples, unsigned int *sampling_rate)
+{
+       struct snd_compr_tstamp ktstamp;
+
+       if (!is_compress_ready(compress))
+               return oops(compress, ENODEV, "device not ready");
+
+       if (ioctl(compress->fd, SNDRV_COMPRESS_TSTAMP, &ktstamp))
+               return oops(compress, errno, "cannot get tstamp");
+
+       *samples = ktstamp.pcm_io_frames;
+       *sampling_rate = ktstamp.sampling_rate;
+       return 0;
+}
+
+int compress_write(struct compress *compress, const void *buf, unsigned int size)
+{
+       struct snd_compr_avail avail;
+       struct pollfd fds;
+       int to_write = 0;       /* zero indicates we haven't written yet */
+       int written, total = 0, ret;
+       const char* cbuf = buf;
+       const unsigned int frag_size = compress->config->fragment_size;
+
+       if (!(compress->flags & COMPRESS_IN))
+               return oops(compress, EINVAL, "Invalid flag set");
+       if (!is_compress_ready(compress))
+               return oops(compress, ENODEV, "device not ready");
+       fds.fd = compress->fd;
+       fds.events = POLLOUT;
+
+       /*TODO: treat auto start here first */
+       while (size) {
+               if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail))
+                       return oops(compress, errno, "cannot get avail");
+
+               /* 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 */
+                       if ((ret == 0) || (ret == -EBADFD))
+                               break;
+                       if (ret < 0)
+                               return oops(compress, errno, "poll error");
+                       if (fds.revents & POLLOUT) {
+                               continue;
+                       }
+                       if (fds.revents & POLLERR) {
+                               return oops(compress, EIO, "poll returned error!");
+                       }
+               }
+               /* write avail bytes */
+               if (size > avail.avail)
+                       to_write =  avail.avail;
+               else
+                       to_write = size;
+               written = write(compress->fd, cbuf, to_write);
+               /* If play was paused the write returns -EBADFD */
+               if (written == -EBADFD)
+                       break;
+               if (written < 0)
+                       return oops(compress, errno, "write failed!");
+
+               size -= written;
+               cbuf += written;
+               total += written;
+       }
+       return total;
+}
+
+int compress_read(struct compress *compress, void *buf, unsigned int size)
+{
+       struct snd_compr_avail avail;
+       struct pollfd fds;
+       int to_read = 0;
+       int num_read, total = 0, ret;
+       char* cbuf = buf;
+       const unsigned int frag_size = compress->config->fragment_size;
+
+       if (!(compress->flags & COMPRESS_OUT))
+               return oops(compress, EINVAL, "Invalid flag set");
+       if (!is_compress_ready(compress))
+               return oops(compress, ENODEV, "device not ready");
+       fds.fd = compress->fd;
+       fds.events = POLLIN;
+
+       while (size) {
+               if (ioctl(compress->fd, SNDRV_COMPRESS_AVAIL, &avail))
+                       return oops(compress, errno, "cannot get avail");
+
+               if ( (avail.avail < frag_size) && (avail.avail < 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 */
+                       if ((ret == 0) || (ret == -EBADFD))
+                               break;
+                       if (ret < 0)
+                               return oops(compress, errno, "poll error");
+                       if (fds.revents & POLLIN) {
+                               continue;
+                       }
+                       if (fds.revents & POLLERR) {
+                               return oops(compress, EIO, "poll returned error!");
+                       }
+               }
+               /* read avail bytes */
+               if (size > avail.avail)
+                       to_read = avail.avail;
+               else
+                       to_read = size;
+               num_read = read(compress->fd, cbuf, to_read);
+               /* If play was paused the read returns -EBADFD */
+               if (num_read == -EBADFD)
+                       break;
+               if (num_read < 0)
+                       return oops(compress, errno, "read failed!");
+
+               size -= num_read;
+               cbuf += num_read;
+               total += num_read;
+       }
+
+       return total;
+}
+
+int compress_start(struct compress *compress)
+{
+       if (!is_compress_ready(compress))
+               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;
+       return 0;
+
+}
+
+int compress_stop(struct compress *compress)
+{
+       if (!is_compress_running(compress))
+               return oops(compress, ENODEV, "device not ready");
+       if (ioctl(compress->fd, SNDRV_COMPRESS_STOP))
+               return oops(compress, errno, "cannot stop the stream");
+       return 0;
+}
+
+int compress_pause(struct compress *compress)
+{
+       if (!is_compress_running(compress))
+               return oops(compress, ENODEV, "device not ready");
+       if (ioctl(compress->fd, SNDRV_COMPRESS_PAUSE))
+               return oops(compress, errno, "cannot pause the stream");
+       return 0;
+}
+
+int compress_resume(struct compress *compress)
+{
+       if (ioctl(compress->fd, SNDRV_COMPRESS_RESUME))
+               return oops(compress, errno, "cannot resume the stream");
+       return 0;
+}
+
+int compress_drain(struct compress *compress)
+{
+       if (!is_compress_running(compress))
+               return oops(compress, ENODEV, "device not ready");
+       if (ioctl(compress->fd, SNDRV_COMPRESS_DRAIN))
+               return oops(compress, errno, "cannot drain the stream");
+       return 0;
+}
+
+int compress_partial_drain(struct compress *compress)
+{
+       if (!is_compress_running(compress))
+               return oops(compress, ENODEV, "device not ready");
+
+       if (!compress->next_track)
+               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;
+       return 0;
+}
+
+int compress_next_track(struct compress *compress)
+{
+       if (!is_compress_running(compress))
+               return oops(compress, ENODEV, "device not ready");
+
+       if (!compress->gapless_metadata)
+               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;
+       compress->gapless_metadata = 0;
+       return 0;
+}
+
+int compress_set_gapless_metadata(struct compress *compress,
+       struct compr_gapless_mdata *mdata)
+{
+       struct snd_compr_metadata metadata;
+       int version;
+
+       if (!is_compress_ready(compress))
+               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");
+
+       metadata.key = SNDRV_COMPRESS_ENCODER_PADDING;
+       metadata.value[0] = mdata->encoder_padding;
+       if (ioctl(compress->fd, SNDRV_COMPRESS_SET_METADATA, &metadata))
+               return oops(compress, errno, "can't set metadata for stream\n");
+
+       metadata.key = SNDRV_COMPRESS_ENCODER_DELAY;
+       metadata.value[0] = mdata->encoder_delay;
+       if (ioctl(compress->fd, SNDRV_COMPRESS_SET_METADATA, &metadata))
+               return oops(compress, errno, "can't set metadata for stream\n");
+       compress->gapless_metadata = 1;
+       return 0;
+}
+
+bool is_codec_supported(unsigned int card, unsigned int device,
+               unsigned int flags, struct snd_codec *codec)
+{
+       unsigned int dev_flag;
+       bool ret;
+       int fd;
+       char fn[256];
+
+       snprintf(fn, sizeof(fn), "/dev/snd/comprC%uD%u", card, device);
+
+       if (flags & COMPRESS_OUT)
+               dev_flag = O_RDONLY;
+       else
+               dev_flag = O_WRONLY;
+
+       fd = open(fn, dev_flag);
+       if (fd < 0)
+               return oops(&bad_compress, errno, "cannot open device '%s'", fn);
+
+       ret = _is_codec_type_supported(fd, codec);
+
+       close(fd);
+       return ret;
+}
+
+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
new file mode 100644 (file)
index 0000000..10c5424
--- /dev/null
+++ b/cplay.c
@@ -0,0 +1,330 @@
+/*
+ * BSD LICENSE
+ *
+ * tinyplay command line player for compress audio offload in alsa
+ * Copyright (c) 2011-2012, Intel Corporation
+ * All rights reserved.
+ *
+ * Author: Vinod Koul <vinod.koul@linux.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
+ *
+ * tinyplay command line player for compress audio offload in alsa
+ * Copyright (c) 2011-2012, 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 <stdint.h>
+#include <linux/types.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <getopt.h>
+#include <sys/time.h>
+#define __force
+#define __bitwise
+#define __user
+#include "sound/compress_params.h"
+#include "tinycompress/tinycompress.h"
+#include "tinycompress/tinymp3.h"
+
+static int verbose;
+
+static void usage(void)
+{
+       fprintf(stderr, "usage: cplay [OPTIONS] filename\n"
+               "-c\tcard number\n"
+               "-d\tdevice node\n"
+               "-b\tbuffer size\n"
+               "-f\tfragments\n\n"
+               "-v\tverbose mode\n"
+               "-h\tPrints this help list\n\n"
+               "Example:\n"
+               "\tcplay -c 1 -d 2 test.mp3\n"
+               "\tcplay -f 5 test.mp3\n");
+
+       exit(EXIT_FAILURE);
+}
+
+void play_samples(char *name, unsigned int card, unsigned int device,
+               unsigned long buffer_size, unsigned int frag);
+
+struct mp3_header {
+       uint16_t sync;
+       uint8_t format1;
+       uint8_t format2;
+};
+
+int parse_mp3_header(struct mp3_header *header, unsigned int *num_channels,
+               unsigned int *sample_rate, unsigned int *bit_rate)
+{
+       int ver_idx, mp3_version, layer, bit_rate_idx, sample_rate_idx, channel_idx;
+
+       /* check sync bits */
+       if ((header->sync & MP3_SYNC) != MP3_SYNC) {
+               fprintf(stderr, "Error: Can't find sync word\n");
+               return -1;
+       }
+       ver_idx = (header->sync >> 11) & 0x03;
+       mp3_version = ver_idx == 0 ? MPEG25 : ((ver_idx & 0x1) ? MPEG1 : MPEG2);
+       layer = 4 - ((header->sync >> 9) & 0x03);
+       bit_rate_idx = ((header->format1 >> 4) & 0x0f);
+       sample_rate_idx = ((header->format1 >> 2) & 0x03);
+       channel_idx = ((header->format2 >> 6) & 0x03);
+
+       if (sample_rate_idx == 3 || layer == 4 || bit_rate_idx == 15) {
+               fprintf(stderr, "Error: Can't find valid header\n");
+               return -1;
+       }
+       *num_channels = (channel_idx == MONO ? 1 : 2);
+       *sample_rate = mp3_sample_rates[mp3_version][sample_rate_idx];
+       *bit_rate = (mp3_bit_rates[mp3_version][layer - 1][bit_rate_idx]) * 1000;
+       if (verbose)
+               printf("%s: exit\n", __func__);
+       return 0;
+}
+
+int check_codec_format_supported(unsigned int card, unsigned int device, struct snd_codec *codec)
+{
+       if (is_codec_supported(card, device, COMPRESS_IN, codec) == false) {
+               fprintf(stderr, "Error: This codec or format is not supported by DSP\n");
+               return -1;
+       }
+       return 0;
+}
+
+static int print_time(struct compress *compress)
+{
+       unsigned int avail;
+       struct timespec tstamp;
+
+       if (compress_get_hpointer(compress, &avail, &tstamp) != 0) {
+               fprintf(stderr, "Error querying timestamp\n");
+               fprintf(stderr, "ERR: %s\n", compress_get_error(compress));
+               return -1;
+       } else
+               fprintf(stderr, "DSP played %jd.%jd\n", (intmax_t)tstamp.tv_sec, (intmax_t)tstamp.tv_nsec*1000);
+       return 0;
+}
+
+int main(int argc, char **argv)
+{
+       char *file;
+       unsigned long buffer_size = 0;
+       int c;
+       unsigned int card = 0, device = 0, frag = 0;
+
+
+       if (argc < 2)
+               usage();
+
+       verbose = 0;
+       while ((c = getopt(argc, argv, "hvb:f:c:d:")) != -1) {
+               switch (c) {
+               case 'h':
+                       usage();
+                       break;
+               case 'b':
+                       buffer_size = strtol(optarg, NULL, 0);
+                       break;
+               case 'f':
+                       frag = strtol(optarg, NULL, 10);
+                       break;
+               case 'c':
+                       card = strtol(optarg, NULL, 10);
+                       break;
+               case 'd':
+                       device = strtol(optarg, NULL, 10);
+                       break;
+               case 'v':
+                       verbose = 1;
+                       break;
+               default:
+                       exit(EXIT_FAILURE);
+               }
+       }
+       if (optind >= argc)
+               usage();
+
+       file = argv[optind];
+
+       play_samples(file, card, device, buffer_size, frag);
+
+       fprintf(stderr, "Finish Playing.... Close Normally\n");
+       exit(EXIT_SUCCESS);
+}
+
+void play_samples(char *name, unsigned int card, unsigned int device,
+               unsigned long buffer_size, unsigned int frag)
+{
+       struct compr_config config;
+       struct snd_codec codec;
+       struct compress *compress;
+       struct mp3_header header;
+       FILE *file;
+       char *buffer;
+       int size, num_read, wrote;
+       unsigned int channels, rate, bits;
+
+       if (verbose)
+               printf("%s: entry\n", __func__);
+       file = fopen(name, "rb");
+       if (!file) {
+               fprintf(stderr, "Unable to open file '%s'\n", name);
+               exit(EXIT_FAILURE);
+       }
+
+       fread(&header, sizeof(header), 1, file);
+
+       if (parse_mp3_header(&header, &channels, &rate, &bits) == -1) {
+               fclose(file);
+               exit(EXIT_FAILURE);
+       }
+
+       codec.id = SND_AUDIOCODEC_MP3;
+       codec.ch_in = channels;
+       codec.ch_out = channels;
+       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;
+       codec.profile = 0;
+       codec.level = 0;
+       codec.ch_mode = 0;
+       codec.format = 0;
+       if ((buffer_size != 0) && (frag != 0)) {
+               config.fragment_size = buffer_size/frag;
+               config.fragments = frag;
+       } else {
+               /* use driver defaults */
+               config.fragment_size = 0;
+               config.fragments = 0;
+       }
+       config.codec = &codec;
+
+       compress = compress_open(card, device, COMPRESS_IN, &config);
+       if (!compress || !is_compress_ready(compress)) {
+               fprintf(stderr, "Unable to open Compress device %d:%d\n",
+                               card, device);
+               fprintf(stderr, "ERR: %s\n", compress_get_error(compress));
+               goto FILE_EXIT;
+       };
+       if (verbose)
+               printf("%s: Opened compress device\n", __func__);
+       size = config.fragment_size;
+       buffer = malloc(size * config.fragments);
+       if (!buffer) {
+               fprintf(stderr, "Unable to allocate %d bytes\n", size);
+               goto COMP_EXIT;
+       }
+
+       /* we will write frag fragment_size and then start */
+       num_read = fread(buffer, 1, size * config.fragments, file);
+       if (num_read > 0) {
+               if (verbose)
+                       printf("%s: Doing first buffer write of %d\n", __func__, num_read);
+               wrote = compress_write(compress, buffer, num_read);
+               if (wrote < 0) {
+                       fprintf(stderr, "Error %d playing sample\n", wrote);
+                       fprintf(stderr, "ERR: %s\n", compress_get_error(compress));
+                       goto BUF_EXIT;
+               }
+               if (wrote != num_read) {
+                       /* TODO: Buufer pointer needs to be set here */
+                       fprintf(stderr, "We wrote %d, DSP accepted %d\n", num_read, wrote);
+               }
+       }
+       printf("Playing file %s On Card %u device %u, with buffer of %lu bytes\n",
+                       name, card, device, buffer_size);
+       printf("Format %u Channels %u, %u Hz, Bit Rate %d\n",
+                       SND_AUDIOCODEC_MP3, channels, rate, bits);
+
+       compress_start(compress);
+       if (verbose)
+               printf("%s: You should hear audio NOW!!!\n", __func__);
+
+       do {
+               num_read = fread(buffer, 1, size, file);
+               if (num_read > 0) {
+                       wrote = compress_write(compress, buffer, num_read);
+                       if (wrote < 0) {
+                               fprintf(stderr, "Error playing sample\n");
+                               fprintf(stderr, "ERR: %s\n", compress_get_error(compress));
+                               goto BUF_EXIT;
+                       }
+                       if (wrote != num_read) {
+                               /* TODO: Buffer pointer needs to be set here */
+                               fprintf(stderr, "We wrote %d, DSP accepted %d\n", num_read, wrote);
+                       }
+                       if (verbose) {
+                               print_time(compress);
+                               printf("%s: wrote %d\n", __func__, wrote);
+                       }
+               }
+       } while (num_read > 0);
+
+       if (verbose)
+               printf("%s: exit success\n", __func__);
+       /* issue drain if it supports */
+       compress_drain(compress);
+       free(buffer);
+       fclose(file);
+       compress_close(compress);
+       return;
+BUF_EXIT:
+       free(buffer);
+COMP_EXIT:
+       compress_close(compress);
+FILE_EXIT:
+       fclose(file);
+       if (verbose)
+               printf("%s: exit failure\n", __func__);
+       exit(EXIT_FAILURE);
+}
+
diff --git a/include/sound/compress_offload.h b/include/sound/compress_offload.h
new file mode 100644 (file)
index 0000000..17377df
--- /dev/null
@@ -0,0 +1,95 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __COMPRESS_OFFLOAD_H
+#define __COMPRESS_OFFLOAD_H
+
+#include <linux/types.h>
+#include <sound/asound.h>
+//#include <sound/compress_params.h>
+
+#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 1)
+
+struct snd_compressed_buffer {
+ __u32 fragment_size;
+ __u32 fragments;
+};
+
+struct snd_compr_params {
+ struct snd_compressed_buffer buffer;
+ struct snd_codec codec;
+ __u8 no_wake_mode;
+};
+
+struct snd_compr_tstamp {
+ __u32 byte_offset;
+ __u32 copied_total;
+ snd_pcm_uframes_t pcm_frames;
+ snd_pcm_uframes_t pcm_io_frames;
+ __u32 sampling_rate;
+};
+
+struct snd_compr_avail {
+ __u64 avail;
+ struct snd_compr_tstamp tstamp;
+};
+
+enum snd_compr_direction {
+ SND_COMPRESS_PLAYBACK = 0,
+ SND_COMPRESS_CAPTURE
+};
+
+struct snd_compr_caps {
+ __u32 num_codecs;
+ __u32 direction;
+ __u32 min_fragment_size;
+ __u32 max_fragment_size;
+ __u32 min_fragments;
+ __u32 max_fragments;
+ __u32 codecs[MAX_NUM_CODECS];
+ __u32 reserved[11];
+};
+
+struct snd_compr_codec_caps {
+ __u32 codec;
+ __u32 num_descriptors;
+ struct snd_codec_desc descriptor[MAX_NUM_CODEC_DESCRIPTORS];
+};
+
+enum {
+       SNDRV_COMPRESS_ENCODER_PADDING = 1,
+       SNDRV_COMPRESS_ENCODER_DELAY = 2,
+};
+
+struct snd_compr_metadata {
+        __u32 key;
+        __u32 value[8];
+};
+
+#define SNDRV_COMPRESS_IOCTL_VERSION _IOR('C', 0x00, int)
+#define SNDRV_COMPRESS_GET_CAPS _IOWR('C', 0x10, struct snd_compr_caps)
+#define SNDRV_COMPRESS_GET_CODEC_CAPS _IOWR('C', 0x11,  struct snd_compr_codec_caps)
+#define SNDRV_COMPRESS_SET_PARAMS _IOW('C', 0x12, struct snd_compr_params)
+#define SNDRV_COMPRESS_GET_PARAMS _IOR('C', 0x13, struct snd_codec)
+#define SNDRV_COMPRESS_SET_METADATA _IOW('C', 0x14,  struct snd_compr_metadata)
+#define SNDRV_COMPRESS_GET_METADATA _IOWR('C', 0x15,  struct snd_compr_metadata)
+#define SNDRV_COMPRESS_TSTAMP _IOR('C', 0x20, struct snd_compr_tstamp)
+#define SNDRV_COMPRESS_AVAIL _IOR('C', 0x21, struct snd_compr_avail)
+#define SNDRV_COMPRESS_PAUSE _IO('C', 0x30)
+#define SNDRV_COMPRESS_RESUME _IO('C', 0x31)
+#define SNDRV_COMPRESS_START _IO('C', 0x32)
+#define SNDRV_COMPRESS_STOP _IO('C', 0x33)
+#define SNDRV_COMPRESS_DRAIN _IO('C', 0x34)
+#define SNDRV_COMPRESS_NEXT_TRACK _IO('C', 0x35)
+#define SNDRV_COMPRESS_PARTIAL_DRAIN _IO('C', 0x36)
+#define SND_COMPR_TRIGGER_DRAIN 7  
+#define SND_COMPR_TRIGGER_PARTIAL_DRAIN 8
+#endif
diff --git a/include/sound/compress_params.h b/include/sound/compress_params.h
new file mode 100644 (file)
index 0000000..bc977c5
--- /dev/null
@@ -0,0 +1,230 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef __SND_COMPRESS_PARAMS_H
+#define __SND_COMPRESS_PARAMS_H
+
+#define MAX_NUM_CODECS 32
+#define MAX_NUM_CODEC_DESCRIPTORS 32
+#define MAX_NUM_BITRATES 32
+
+#define SND_AUDIOCODEC_PCM ((__u32) 0x00000001)
+#define SND_AUDIOCODEC_MP3 ((__u32) 0x00000002)
+#define SND_AUDIOCODEC_AMR ((__u32) 0x00000003)
+#define SND_AUDIOCODEC_AMRWB ((__u32) 0x00000004)
+#define SND_AUDIOCODEC_AMRWBPLUS ((__u32) 0x00000005)
+#define SND_AUDIOCODEC_AAC ((__u32) 0x00000006)
+#define SND_AUDIOCODEC_WMA ((__u32) 0x00000007)
+#define SND_AUDIOCODEC_REAL ((__u32) 0x00000008)
+#define SND_AUDIOCODEC_VORBIS ((__u32) 0x00000009)
+#define SND_AUDIOCODEC_FLAC ((__u32) 0x0000000A)
+#define SND_AUDIOCODEC_IEC61937 ((__u32) 0x0000000B)
+#define SND_AUDIOCODEC_G723_1 ((__u32) 0x0000000C)
+#define SND_AUDIOCODEC_G729 ((__u32) 0x0000000D)
+
+#define SND_AUDIOPROFILE_PCM ((__u32) 0x00000001)
+
+#define SND_AUDIOCHANMODE_MP3_MONO ((__u32) 0x00000001)
+#define SND_AUDIOCHANMODE_MP3_STEREO ((__u32) 0x00000002)
+#define SND_AUDIOCHANMODE_MP3_JOINTSTEREO ((__u32) 0x00000004)
+#define SND_AUDIOCHANMODE_MP3_DUAL ((__u32) 0x00000008)
+
+#define SND_AUDIOPROFILE_AMR ((__u32) 0x00000001)
+
+#define SND_AUDIOMODE_AMR_DTX_OFF ((__u32) 0x00000001)
+#define SND_AUDIOMODE_AMR_VAD1 ((__u32) 0x00000002)
+#define SND_AUDIOMODE_AMR_VAD2 ((__u32) 0x00000004)
+
+#define SND_AUDIOSTREAMFORMAT_UNDEFINED ((__u32) 0x00000000)
+#define SND_AUDIOSTREAMFORMAT_CONFORMANCE ((__u32) 0x00000001)
+#define SND_AUDIOSTREAMFORMAT_IF1 ((__u32) 0x00000002)
+#define SND_AUDIOSTREAMFORMAT_IF2 ((__u32) 0x00000004)
+#define SND_AUDIOSTREAMFORMAT_FSF ((__u32) 0x00000008)
+#define SND_AUDIOSTREAMFORMAT_RTPPAYLOAD ((__u32) 0x00000010)
+#define SND_AUDIOSTREAMFORMAT_ITU ((__u32) 0x00000020)
+
+#define SND_AUDIOPROFILE_AMRWB ((__u32) 0x00000001)
+
+#define SND_AUDIOMODE_AMRWB_DTX_OFF ((__u32) 0x00000001)
+#define SND_AUDIOMODE_AMRWB_VAD1 ((__u32) 0x00000002)
+#define SND_AUDIOMODE_AMRWB_VAD2 ((__u32) 0x00000004)
+
+#define SND_AUDIOPROFILE_AMRWBPLUS ((__u32) 0x00000001)
+
+#define SND_AUDIOPROFILE_AAC ((__u32) 0x00000001)
+
+#define SND_AUDIOMODE_AAC_MAIN ((__u32) 0x00000001)
+#define SND_AUDIOMODE_AAC_LC ((__u32) 0x00000002)
+#define SND_AUDIOMODE_AAC_SSR ((__u32) 0x00000004)
+#define SND_AUDIOMODE_AAC_LTP ((__u32) 0x00000008)
+#define SND_AUDIOMODE_AAC_HE ((__u32) 0x00000010)
+#define SND_AUDIOMODE_AAC_SCALABLE ((__u32) 0x00000020)
+#define SND_AUDIOMODE_AAC_ERLC ((__u32) 0x00000040)
+#define SND_AUDIOMODE_AAC_LD ((__u32) 0x00000080)
+#define SND_AUDIOMODE_AAC_HE_PS ((__u32) 0x00000100)
+#define SND_AUDIOMODE_AAC_HE_MPS ((__u32) 0x00000200)
+
+#define SND_AUDIOSTREAMFORMAT_MP2ADTS ((__u32) 0x00000001)
+#define SND_AUDIOSTREAMFORMAT_MP4ADTS ((__u32) 0x00000002)
+#define SND_AUDIOSTREAMFORMAT_MP4LOAS ((__u32) 0x00000004)
+#define SND_AUDIOSTREAMFORMAT_MP4LATM ((__u32) 0x00000008)
+#define SND_AUDIOSTREAMFORMAT_ADIF ((__u32) 0x00000010)
+#define SND_AUDIOSTREAMFORMAT_MP4FF ((__u32) 0x00000020)
+#define SND_AUDIOSTREAMFORMAT_RAW ((__u32) 0x00000040)
+
+#define SND_AUDIOPROFILE_WMA7 ((__u32) 0x00000001)
+#define SND_AUDIOPROFILE_WMA8 ((__u32) 0x00000002)
+#define SND_AUDIOPROFILE_WMA9 ((__u32) 0x00000004)
+#define SND_AUDIOPROFILE_WMA10 ((__u32) 0x00000008)
+
+#define SND_AUDIOMODE_WMA_LEVEL1 ((__u32) 0x00000001)
+#define SND_AUDIOMODE_WMA_LEVEL2 ((__u32) 0x00000002)
+#define SND_AUDIOMODE_WMA_LEVEL3 ((__u32) 0x00000004)
+#define SND_AUDIOMODE_WMA_LEVEL4 ((__u32) 0x00000008)
+#define SND_AUDIOMODE_WMAPRO_LEVELM0 ((__u32) 0x00000010)
+#define SND_AUDIOMODE_WMAPRO_LEVELM1 ((__u32) 0x00000020)
+#define SND_AUDIOMODE_WMAPRO_LEVELM2 ((__u32) 0x00000040)
+#define SND_AUDIOMODE_WMAPRO_LEVELM3 ((__u32) 0x00000080)
+
+#define SND_AUDIOSTREAMFORMAT_WMA_ASF ((__u32) 0x00000001)
+
+#define SND_AUDIOSTREAMFORMAT_WMA_NOASF_HDR ((__u32) 0x00000002)
+
+#define SND_AUDIOPROFILE_REALAUDIO ((__u32) 0x00000001)
+
+#define SND_AUDIOMODE_REALAUDIO_G2 ((__u32) 0x00000001)
+#define SND_AUDIOMODE_REALAUDIO_8 ((__u32) 0x00000002)
+#define SND_AUDIOMODE_REALAUDIO_10 ((__u32) 0x00000004)
+#define SND_AUDIOMODE_REALAUDIO_SURROUND ((__u32) 0x00000008)
+
+#define SND_AUDIOPROFILE_VORBIS ((__u32) 0x00000001)
+
+#define SND_AUDIOMODE_VORBIS ((__u32) 0x00000001)
+
+#define SND_AUDIOPROFILE_FLAC ((__u32) 0x00000001)
+
+#define SND_AUDIOMODE_FLAC_LEVEL0 ((__u32) 0x00000001)
+#define SND_AUDIOMODE_FLAC_LEVEL1 ((__u32) 0x00000002)
+#define SND_AUDIOMODE_FLAC_LEVEL2 ((__u32) 0x00000004)
+#define SND_AUDIOMODE_FLAC_LEVEL3 ((__u32) 0x00000008)
+#define SND_AUDIOMODE_FLAC_LEVEL4 ((__u32) 0x00000010)
+#define SND_AUDIOMODE_FLAC_LEVEL5 ((__u32) 0x00000020)
+#define SND_AUDIOMODE_FLAC_LEVEL6 ((__u32) 0x00000040)
+#define SND_AUDIOMODE_FLAC_LEVEL7 ((__u32) 0x00000080)
+#define SND_AUDIOMODE_FLAC_LEVEL8 ((__u32) 0x00000100)
+
+#define SND_AUDIOSTREAMFORMAT_FLAC ((__u32) 0x00000001)
+#define SND_AUDIOSTREAMFORMAT_FLAC_OGG ((__u32) 0x00000002)
+
+#define SND_AUDIOPROFILE_IEC61937 ((__u32) 0x00000001)
+
+#define SND_AUDIOPROFILE_IEC61937_SPDIF ((__u32) 0x00000002)
+
+#define SND_AUDIOMODE_IEC_REF_STREAM_HEADER ((__u32) 0x00000000)
+#define SND_AUDIOMODE_IEC_LPCM ((__u32) 0x00000001)
+#define SND_AUDIOMODE_IEC_AC3 ((__u32) 0x00000002)
+#define SND_AUDIOMODE_IEC_MPEG1 ((__u32) 0x00000004)
+#define SND_AUDIOMODE_IEC_MP3 ((__u32) 0x00000008)
+#define SND_AUDIOMODE_IEC_MPEG2 ((__u32) 0x00000010)
+#define SND_AUDIOMODE_IEC_AACLC ((__u32) 0x00000020)
+#define SND_AUDIOMODE_IEC_DTS ((__u32) 0x00000040)
+#define SND_AUDIOMODE_IEC_ATRAC ((__u32) 0x00000080)
+#define SND_AUDIOMODE_IEC_SACD ((__u32) 0x00000100)
+#define SND_AUDIOMODE_IEC_EAC3 ((__u32) 0x00000200)
+#define SND_AUDIOMODE_IEC_DTS_HD ((__u32) 0x00000400)
+#define SND_AUDIOMODE_IEC_MLP ((__u32) 0x00000800)
+#define SND_AUDIOMODE_IEC_DST ((__u32) 0x00001000)
+#define SND_AUDIOMODE_IEC_WMAPRO ((__u32) 0x00002000)
+#define SND_AUDIOMODE_IEC_REF_CXT ((__u32) 0x00004000)
+#define SND_AUDIOMODE_IEC_HE_AAC ((__u32) 0x00008000)
+#define SND_AUDIOMODE_IEC_HE_AAC2 ((__u32) 0x00010000)
+#define SND_AUDIOMODE_IEC_MPEG_SURROUND ((__u32) 0x00020000)
+
+#define SND_AUDIOPROFILE_G723_1 ((__u32) 0x00000001)
+
+#define SND_AUDIOMODE_G723_1_ANNEX_A ((__u32) 0x00000001)
+#define SND_AUDIOMODE_G723_1_ANNEX_B ((__u32) 0x00000002)
+#define SND_AUDIOMODE_G723_1_ANNEX_C ((__u32) 0x00000004)
+
+#define SND_AUDIOPROFILE_G729 ((__u32) 0x00000001)
+
+#define SND_AUDIOMODE_G729_ANNEX_A ((__u32) 0x00000001)
+#define SND_AUDIOMODE_G729_ANNEX_B ((__u32) 0x00000002)
+
+#define SND_RATECONTROLMODE_CONSTANTBITRATE ((__u32) 0x00000001)
+#define SND_RATECONTROLMODE_VARIABLEBITRATE ((__u32) 0x00000002)
+
+struct snd_enc_wma {
+ __u32 super_block_align;
+};
+
+struct snd_enc_vorbis {
+ __s32 quality;
+ __u32 managed;
+ __u32 max_bit_rate;
+ __u32 min_bit_rate;
+ __u32 downmix;
+};
+
+struct snd_enc_real {
+ __u32 quant_bits;
+ __u32 start_region;
+ __u32 num_regions;
+};
+
+struct snd_enc_flac {
+ __u32 num;
+ __u32 gain;
+};
+
+struct snd_enc_generic {
+ __u32 bw;
+ __s32 reserved[15];
+};
+
+union snd_codec_options {
+ struct snd_enc_wma wma;
+ struct snd_enc_vorbis vorbis;
+ struct snd_enc_real real;
+ struct snd_enc_flac flac;
+ struct snd_enc_generic generic;
+};
+
+struct snd_codec_desc {
+ __u32 max_ch;
+ __u32 sample_rates;
+ __u32 bit_rate[MAX_NUM_BITRATES];
+ __u32 num_bitrates;
+ __u32 rate_control;
+ __u32 profiles;
+ __u32 modes;
+ __u32 formats;
+ __u32 min_buffer;
+ __u32 reserved[15];
+};
+
+struct snd_codec {
+ __u32 id;
+ __u32 ch_in;
+ __u32 ch_out;
+ __u32 sample_rate;
+ __u32 bit_rate;
+ __u32 rate_control;
+ __u32 profile;
+ __u32 level;
+ __u32 ch_mode;
+ __u32 format;
+ __u32 align;
+ union snd_codec_options options;
+ __u32 reserved[3];
+};
+
+#endif
diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h
new file mode 100644 (file)
index 0000000..40de69a
--- /dev/null
@@ -0,0 +1,293 @@
+/*
+ * BSD LICENSE
+ *
+ * Copyright (c) 2011-2012, Intel Corporation
+ * All rights reserved.
+ *
+ * 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 library for compress audio offload in alsa
+ * Copyright (c) 2011-2012, 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.
+ */
+
+
+#ifndef __TINYCOMPRESS_H
+#define __TINYCOMPRESS_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+/*
+ * struct compr_config: config structure, needs to be filled by app
+ * If fragment_size or fragments are zero, this means "don't care"
+ * and tinycompress will choose values that the driver supports
+ *
+ * @fragment_size: size of fragment requested, in bytes
+ * @fragments: number of fragments
+ * @codec: codec type and parameters requested
+ */
+struct compr_config {
+       __u32 fragment_size;
+       __u32 fragments;
+       struct snd_codec *codec;
+};
+
+struct compr_gapless_mdata {
+       __u32 encoder_delay;
+       __u32 encoder_padding;
+};
+
+#define COMPRESS_OUT        0x20000000
+#define COMPRESS_IN         0x10000000
+
+struct compress;
+struct snd_compr_tstamp;
+
+/*
+ * compress_open: open a new compress stream
+ * returns the valid struct compress on success, NULL on failure
+ * If config does not specify a requested fragment size, on return
+ * it will be updated with the size and number of fragments that
+ * were configured
+ *
+ * @card: sound card number
+ * @device: device number
+ * @flags: device flags can be COMPRESS_OUT or COMPRESS_IN
+ * @config: stream config requested. Returns actual fragment config
+ */
+struct compress *compress_open(unsigned int card, unsigned int device,
+               unsigned int flags, struct compr_config *config);
+
+/*
+ * compress_close: close the compress stream
+ *
+ * @compress: compress stream to be closed
+ */
+void compress_close(struct compress *compress);
+
+/*
+ * compress_get_hpointer: get the hw timestamp
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream on which query is made
+ * @avail: buffer availble for write/read, in bytes
+ * @tstamp: hw time
+ */
+int compress_get_hpointer(struct compress *compress,
+               unsigned int *avail, struct timespec *tstamp);
+
+
+/*
+ * compress_get_tstamp: get the raw hw timestamp
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream on which query is made
+ * @samples: number of decoded samples played
+ * @sampling_rate: sampling rate of decoded samples
+ */
+int compress_get_tstamp(struct compress *compress,
+               unsigned long *samples, unsigned int *sampling_rate);
+
+/*
+ * compress_write: write data to the compress stream
+ * return bytes written on success, negative on error
+ * 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
+ * @size: number of bytes to be written
+ */
+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
+ * @size: size of given buffer
+ */
+int compress_read(struct compress *compress, void *buf, unsigned int size);
+
+/*
+ * compress_start: start the compress stream
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream to be started
+ */
+int compress_start(struct compress *compress);
+
+/*
+ * compress_stop: stop the compress stream
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream to be stopped
+ */
+int compress_stop(struct compress *compress);
+
+/*
+ * compress_pause: pause the compress stream
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream to be paused
+ */
+int compress_pause(struct compress *compress);
+
+/*
+ * compress_resume: resume the compress stream
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream to be resumed
+ */
+int compress_resume(struct compress *compress);
+
+/*
+ * compress_drain: drain the compress stream
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream to be drain
+ */
+int compress_drain(struct compress *compress);
+
+/*
+ * compress_next_track: set the next track for stream
+ *
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream to be transistioned to next track
+ */
+int compress_next_track(struct compress *compress);
+
+/*
+ * compress_partial_drain: drain will return after the last frame is decoded
+ * by DSP and will play the , All the data written into compressed
+ * ring buffer is decoded
+ *
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream to be drain
+ */
+int compress_partial_drain(struct compress *compress);
+
+/*
+ * compress_set_gapless_metadata: set gapless metadata of a compress strem
+ *
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream for which metadata has to set
+ * @mdata: metadata encoder delay and  padding
+ */
+
+int compress_set_gapless_metadata(struct compress *compress,
+                       struct compr_gapless_mdata *mdata);
+
+/*
+ * is_codec_supported:check if the given codec is supported
+ * returns true when supported, false if not
+ *
+ * @card: sound card number
+ * @device: device number
+ * @flags: stream flags
+ * @codec: codec type and parameters to be checked
+ */
+bool is_codec_supported(unsigned int card, unsigned int device,
+              unsigned int flags, struct snd_codec *codec);
+
+/*
+ * compress_set_max_poll_wait: set the maximum time tinycompress
+ * will wait for driver to signal a poll(). Interval is in
+ * milliseconds.
+ * Pass interval of -1 to disable timeout and make poll() wait
+ * until driver signals.
+ * If this function is not used the timeout defaults to 20 seconds.
+ */
+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);
+
+/* Returns a human readable reason for the last error */
+const char *compress_get_error(struct compress *compress);
+/*
+ * since the SNDRV_PCM_RATE_* is not availble anywhere in userspace
+ * and we have used these to define the sampling rate, we need to define
+ * then here
+ */
+#define SNDRV_PCM_RATE_5512            (1<<0)          /* 5512Hz */
+#define SNDRV_PCM_RATE_8000            (1<<1)          /* 8000Hz */
+#define SNDRV_PCM_RATE_11025           (1<<2)          /* 11025Hz */
+#define SNDRV_PCM_RATE_16000           (1<<3)          /* 16000Hz */
+#define SNDRV_PCM_RATE_22050           (1<<4)          /* 22050Hz */
+#define SNDRV_PCM_RATE_32000           (1<<5)          /* 32000Hz */
+#define SNDRV_PCM_RATE_44100           (1<<6)          /* 44100Hz */
+#define SNDRV_PCM_RATE_48000           (1<<7)          /* 48000Hz */
+#define SNDRV_PCM_RATE_64000           (1<<8)          /* 64000Hz */
+#define SNDRV_PCM_RATE_88200           (1<<9)          /* 88200Hz */
+#define SNDRV_PCM_RATE_96000           (1<<10)         /* 96000Hz */
+#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/tinymp3.h b/include/tinycompress/tinymp3.h
new file mode 100644 (file)
index 0000000..b7b45e3
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * BSD LICENSE
+ *
+ * mp3 header and prasing
+ * Copyright (c) 2011-2012, Intel Corporation
+ * All rights reserved.
+ *
+ * Author: Vinod Koul <vinod.koul@linux.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
+ *
+ * mp3 header and parsing
+ * Copyright (c) 2011-2012, 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.
+ */
+
+
+#ifndef __TINYMP3_H
+#define __TINYMP3_H
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+#define MP3_SYNC 0xe0ff
+
+const int mp3_sample_rates[3][3] = {
+       {44100, 48000, 32000},        /* MPEG-1 */
+       {22050, 24000, 16000},        /* MPEG-2 */
+       {11025, 12000,  8000},        /* MPEG-2.5 */
+};
+
+const int mp3_bit_rates[3][3][15] = {
+       {
+               /* MPEG-1 */
+               {  0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448}, /* Layer 1 */
+               {  0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384}, /* Layer 2 */
+               {  0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320}, /* Layer 3 */
+       },
+       {
+               /* MPEG-2 */
+               {  0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256}, /* Layer 1 */
+               {  0,  8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}, /* Layer 2 */
+               {  0,  8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}, /* Layer 3 */
+       },
+       {
+               /* MPEG-2.5 */
+               {  0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256}, /* Layer 1 */
+               {  0,  8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}, /* Layer 2 */
+               {  0,  8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}, /* Layer 3 */
+       },
+};
+
+enum mpeg_version {
+       MPEG1  = 0,
+       MPEG2  = 1,
+       MPEG25 = 2
+};
+
+enum mp3_stereo_mode {
+       STEREO = 0x00,
+       JOINT = 0x01,
+       DUAL = 0x02,
+       MONO = 0x03
+};
+
+#endif
diff --git a/include/tinycompress/version.h b/include/tinycompress/version.h
new file mode 100644 (file)
index 0000000..000f6a2
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * BSD LICENSE
+ *
+ * Copyright (c) 2011-2012, Intel Corporation
+ * All rights reserved.
+ *
+ * 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 library for compress audio offload in alsa
+ * Copyright (c) 2011-2012, 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.
+ */
+
+
+#ifndef __VERSION_H
+#define __VERSION_H
+
+
+#define TINYCOMPRESS_LIB_MAJOR         0 /* major 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 */
+#define TINYCOMPRESS_LIB_VERSION \
+               ((TINYCOMPRESS_LIB_MAJOR<<16)|\
+                (TINYCOMPRESS_LIB_MINOR<<8)|\
+                 TINYCOMPRESS_LIB_SUBMINOR)
+
+/** library version (string) */
+#define TINYCOMPRESS_LIB_VERSION_STR   "0.2.0"
+
+#endif
diff --git a/makefile.linux b/makefile.linux
new file mode 100644 (file)
index 0000000..677878d
--- /dev/null
@@ -0,0 +1,35 @@
+LIB = libtinycompress
+BIN = cplay
+VER = 0.1
+LIBSRC = compress.c
+SRC = cplay.c utils.c
+LIBOBJ = ${LIBSRC:.c=.o}
+OBJ = ${SRC:.c=.o}
+
+CC = gcc
+CROSS_COMPILE =
+
+CFLAGS += -std=c99 -Wall -Wextra -Wunused -DVERSION=\"${VER}\" -I./include
+LDFLAGS += -L. -ltinycompress
+LIBLDFLAGS = -lasound
+
+all: libtinycompress cplay
+
+$(LIB): ${LIBOBJ}
+       @echo "  LD     "$@
+       @${CROSS_COMPILE}${CC} ${CFLAGS} -shared -Wl,-soname,$@.so -o $@.so ${LIBOBJ} ${LIBLDFLAGS}
+
+$(BIN): ${OBJ} ${LIB}
+       @echo "  LD     "$@
+       @${CROSS_COMPILE}${CC} ${CFLAGS} -o $@ ${OBJ} ${LDFLAGS}
+
+
+%.o: %.c
+       @echo "  CC     "$<
+       @${CROSS_COMPILE}${CC} ${CFLAGS} -c -fPIC -o $@ $<
+
+clean:
+       @rm -rf ${BIN} ${OBJ} ${LIB}.so ${LIBOBJ}
+
+
+.PHONY: all clean
diff --git a/packaging/tinycompress.changes b/packaging/tinycompress.changes
new file mode 100644 (file)
index 0000000..954e3d8
--- /dev/null
@@ -0,0 +1,2 @@
+* Wed Sep 18 2013 Vivian Zhang <vivian.zhang@intel.com> - 0.1
+- Initial import the package for enabling audio dsp hw decoding feature
diff --git a/packaging/tinycompress.spec b/packaging/tinycompress.spec
new file mode 100644 (file)
index 0000000..8aea42d
--- /dev/null
@@ -0,0 +1,52 @@
+Name:       tinycompress
+Summary:    userspace library for alsa compressed API
+Version:    0.2.0
+Release:    1
+Group:      System/Libraries
+License:    LGPL & BSD
+Source0:    tinycompress-%{version}.tar.gz
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+BuildRequires:  cmake
+BuildRequires: pkgconfig(alsa)
+
+%description
+userspace library for alsa compressed API
+
+%package devel
+Summary:    tinycompress headers and libraries for development.
+Group:      Development/Libraries
+Requires:   %{name} = %{version}-%{release}
+
+%description devel
+tinycompress headers and libraries for development.
+
+%prep
+%setup -q -n %{name}-%{version}
+
+
+%build
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DVERSION=%{version}
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%defattr(-,root,root,-)
+%{_bindir}/cplay
+%{_libdir}/libtinycompress.so.*
+
+%files devel
+%{_libdir}/libtinycompress.so
+%{_libdir}/pkgconfig/*.pc
+%{_includedir}/tinycompress-0.2.0/tinycompress/tinycompress.h
+%{_includedir}/tinycompress-0.2.0/tinycompress/tinymp3.h
+%{_includedir}/tinycompress-0.2.0/tinycompress/version.h
+%{_includedir}/tinycompress-0.2.0/sound/compress_offload.h
+%{_includedir}/tinycompress-0.2.0/sound/compress_params.h
diff --git a/tinycompress.pc.in b/tinycompress.pc.in
new file mode 100644 (file)
index 0000000..27b5679
--- /dev/null
@@ -0,0 +1,12 @@
+prefix=@PREFIX@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: tinycompress 
+Description: userspace library for alsa compressed API
+Version: 0.2.0
+Requires: alsa
+Libs: -L${libdir} -ltinycompress
+Cflags: -I${includedir}/tinycompress-0.2.0
+
diff --git a/utils.c b/utils.c
new file mode 100644 (file)
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;
+       }
+}