summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.mk47
-rw-r--r--Android_bp (renamed from Android.bp)24
-rw-r--r--CleanSpec.mk4
-rw-r--r--compress.c98
-rw-r--r--compress_plugin.c11
-rw-r--r--include/tinycompress/tinycompress.h27
6 files changed, 169 insertions, 42 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..55bd87e
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,47 @@
+ifneq ($(AUDIO_USE_STUB_HAL), true)
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_CFLAGS := -Wno-macro-redefined -Wno-unused-function
+ifeq ($(strip $(AUDIO_FEATURE_ENABLED_EXTENDED_COMPRESS_FORMAT)), true)
+LOCAL_CFLAGS += -DENABLE_EXTENDED_COMPRESS_FORMAT
+endif
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
+LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/techpack/audio/include
+LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+LOCAL_SRC_FILES := compress.c utils.c compress_hw.c compress_plugin.c snd_utils.c
+LOCAL_MODULE := libtinycompress
+LOCAL_SHARED_LIBRARIES := libcutils libutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_VENDOR_MODULE := true
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_CFLAGS := -Wno-macro-redefined -Wno-unused-function
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
+LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/techpack/audio/include
+LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+LOCAL_SRC_FILES := cplay.c
+LOCAL_MODULE := cplay
+LOCAL_VENDOR_MODULE := true
+LOCAL_SHARED_LIBRARIES := libcutils libutils libtinycompress
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+LOCAL_CFLAGS := -Wno-macro-redefined -Wno-unused-function
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
+LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/techpack/audio/include
+LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
+LOCAL_SRC_FILES := compress.c utils.c
+LOCAL_CFLAGS += -DUSE_VENDOR_EXTN
+LOCAL_CFLAGS += -DENABLE_EXTENDED_COMPRESS_FORMAT
+LOCAL_MODULE := libtinycompress_vendor
+LOCAL_SHARED_LIBRARIES := libcutils libutils
+LOCAL_MODULE_TAGS := optional
+LOCAL_VENDOR_MODULE := true
+include $(BUILD_SHARED_LIBRARY)
+endif
diff --git a/Android.bp b/Android_bp
index a4f8d6d..9255d37 100644
--- a/Android.bp
+++ b/Android_bp
@@ -46,6 +46,30 @@ cc_library_shared {
],
}
+cc_library_shared {
+ name: "libtinycompress_vendor",
+ vendor: true,
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wno-macro-redefined",
+ "-Wno-unused-function",
+ ],
+ export_include_dirs: ["include"],
+ srcs: [
+ "compress.c",
+ "utils.c",
+ ],
+ shared_libs: [
+ "libcutils",
+ "libutils",
+ ],
+ header_libs: [
+ "device_kernel_headers",
+ ],
+}
+
cc_binary {
name: "cplay",
vendor: true,
diff --git a/CleanSpec.mk b/CleanSpec.mk
index f7dec23..9eab8b3 100644
--- a/CleanSpec.mk
+++ b/CleanSpec.mk
@@ -44,7 +44,9 @@
#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
-$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/bin/cplay)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/bin/cplay)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/lib64/libtinycompress.so)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/vendor/lib/libtinycompress.so)
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
diff --git a/compress.c b/compress.c
index ac2c73f..3019cb3 100644
--- a/compress.c
+++ b/compress.c
@@ -397,51 +397,49 @@ int compress_read(struct compress *compress, void *buf, unsigned int size)
return oops(compress, ENODEV, "device not ready");
fds.events = POLLIN;
- while (size) {
- if (compress->ops->ioctl(compress->data, SNDRV_COMPRESS_AVAIL, &avail))
- return oops(compress, errno, "cannot get avail");
+ if (compress->ops->ioctl(compress->data, 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;
+ 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 = compress->ops->poll(compress->data, &fds, 1,
- compress->max_poll_wait_ms);
- if (fds.revents & POLLERR) {
- return oops(compress, EIO, "poll returned error!");
- }
- /* A pause will cause -EBADFD or zero.
- * This is not an error, just stop reading */
- if ((ret == 0) || (ret < 0 && errno == EBADFD))
- break;
- if (ret < 0)
- return oops(compress, errno, "poll error");
- if (fds.revents & POLLIN) {
- continue;
- }
+ ret = compress->ops->poll(compress->data, &fds, 1,
+ compress->max_poll_wait_ms);
+ 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 = compress->ops->read(compress->data, cbuf, to_read);
- if (num_read < 0) {
- /* If play was paused the read returns -EBADFD */
- if (errno == EBADFD)
- break;
- return oops(compress, errno, "read failed!");
+ /* A pause will cause -EBADFD or zero.
+ * This is not an error, just stop reading */
+ if ((ret == 0) || (ret < 0 && errno == EBADFD))
+ return 0;
+ if (ret < 0)
+ return oops(compress, errno, "poll error");
+ if (fds.revents & POLLIN) {
+ return 0;
}
-
- size -= num_read;
- cbuf += num_read;
- total += num_read;
+ }
+ /* read avail bytes */
+ if (size > avail.avail)
+ to_read = avail.avail;
+ else
+ to_read = size;
+ num_read = compress->ops->read(compress->data, cbuf, to_read);
+ if (num_read < 0) {
+ /* If play was paused the read returns -EBADFD */
+ if (errno == EBADFD)
+ return 0;
+ return oops(compress, errno, "read failed!");
}
- return total;
+ size -= num_read;
+ cbuf += num_read;
+ total += num_read;
+
+ return num_read;
}
int compress_start(struct compress *compress)
@@ -552,8 +550,13 @@ int compress_set_next_track_param(struct compress *compress,
if (!is_compress_running(compress))
return oops(compress, ENODEV, "device not ready");
+ if (codec_options == NULL)
+ return oops(compress, ENODEV, "codec_option NULL");
+
+#ifdef SNDRV_COMPRESS_SET_NEXT_TRACK_PARAM
if (ioctl(compress->fd, SNDRV_COMPRESS_SET_NEXT_TRACK_PARAM, codec_options))
return oops(compress, errno, "cannot set next track params\n");
+#endif
return 0;
}
#endif
@@ -619,6 +622,23 @@ int compress_wait(struct compress *compress, int timeout_ms)
return oops(compress, EIO, "poll signalled unhandled event");
}
+int compress_set_codec_params(struct compress *compress,
+ struct snd_codec *codec) {
+ struct snd_compr_params params;
+
+ if (!is_compress_running(compress))
+ return oops(compress, ENODEV, "device not ready");
+
+ params.buffer.fragment_size = compress->config->fragment_size;
+ params.buffer.fragments = compress->config->fragments;
+ memcpy(&params.codec, codec, sizeof(params.codec));
+
+ if (compress->ops->ioctl(compress->data, SNDRV_COMPRESS_SET_PARAMS, &params))
+ return oops(compress, errno, "cannot set device");
+
+ return 0;
+}
+
#ifdef ENABLE_EXTENDED_COMPRESS_FORMAT
int compress_get_metadata(struct compress *compress,
struct snd_compr_metadata *mdata) {
diff --git a/compress_plugin.c b/compress_plugin.c
index 7a5538d..22f8f11 100644
--- a/compress_plugin.c
+++ b/compress_plugin.c
@@ -43,6 +43,7 @@
#include <linux/ioctl.h>
#include <sound/asound.h>
#include "tinycompress/compress_plugin.h"
+#include "tinycompress/tinycompress.h"
#include "sound/compress_offload.h"
#include "compress_ops.h"
#include "snd_utils.h"
@@ -84,7 +85,10 @@ static int compress_plug_set_params(struct compress_plug_data *plug_data,
struct compress_plugin *plugin = plug_data->plugin;
int rc;
- if (plugin->state != COMPRESS_PLUG_STATE_OPEN)
+ if (plugin->state == COMPRESS_PLUG_STATE_RUNNING)
+ return plugin->ops->set_params(plugin, params);
+ else if (plugin->state != COMPRESS_PLUG_STATE_OPEN &&
+ plugin->state != COMPRESS_PLUG_STATE_SETUP)
return -EBADFD;
if (params->buffer.fragment_size == 0 ||
@@ -93,8 +97,11 @@ static int compress_plug_set_params(struct compress_plug_data *plug_data,
return -EINVAL;
rc = plugin->ops->set_params(plugin, params);
- if (!rc)
+ if (!rc) {
plugin->state = COMPRESS_PLUG_STATE_SETUP;
+ if (plug_data->flags & COMPRESS_OUT)
+ plugin->state = COMPRESS_PLUG_STATE_PREPARED;
+ }
return rc;
}
diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h
index 0ab7134..83c8f9e 100644
--- a/include/tinycompress/tinycompress.h
+++ b/include/tinycompress/tinycompress.h
@@ -53,6 +53,8 @@
#ifndef __TINYCOMPRESS_H
#define __TINYCOMPRESS_H
+#include <stdbool.h>
+
#if defined(__cplusplus)
extern "C" {
#endif
@@ -81,6 +83,8 @@ struct compr_gapless_mdata {
struct compress;
struct snd_compr_tstamp;
+union snd_codec_options;
+struct snd_compr_metadata;
#ifdef ENABLE_EXTENDED_COMPRESS_FORMAT
union snd_codec_options;
@@ -254,6 +258,18 @@ int compress_set_next_track_param(struct compress *compress,
#endif
/*
+ * compress_set_next_track_param: set params of next compress stream in gapless
+ *
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream for which codec options has to be set
+ * @codec_options: codec options of compress stream based on codec type
+ */
+
+int compress_set_next_track_param(struct compress *compress,
+ union snd_codec_options *codec_options);
+
+/*
* is_codec_supported:check if the given codec is supported
* returns true when supported, false if not
*
@@ -309,6 +325,17 @@ const char *compress_get_error(struct compress *compress);
/* utility functions */
unsigned int compress_get_alsa_rate(unsigned int rate);
+ /*
+ * compress_set_codec_params: set codec config intended for next track
+ * if DSP has support to switch CODEC config during gapless playback
+ * This API is expected to be called after compress_next_track is called
+ * return 0 on success, negative on error
+ *
+ * @compress: compress stream for which metadata has to set
+ * @codec: codec configuration for next track
+ */
+int compress_set_codec_params(struct compress *compress, struct snd_codec *codec);
+
#ifdef ENABLE_EXTENDED_COMPRESS_FORMAT
/* set metadata */
int compress_set_metadata(struct compress *compress,