]> git.alsa-project.org Git - tinycompress.git/commitdiff
tinycompress: add gapless meta data APIs
authorVinod Koul <vinod.koul@intel.com>
Fri, 22 Feb 2013 09:49:02 +0000 (15:19 +0530)
committerVinod Koul <vinod.koul@intel.com>
Sun, 24 Feb 2013 14:15:46 +0000 (19:45 +0530)
Based on newly introduced kernel API, we add gapless metatdata to the library.
Since kernel can recieve only key/value pairs for metadata we add a structure for
gapless_metdata and handle this in library

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
compress.c
include/sound/compress_offload.h
include/tinycompress/tinycompress.h
include/tinycompress/version.h

index ebd28dbc372eb8590e726b3816bd1e981916191e..86cca88bd746d295f810717ef5ef9d960973c4f0 100644 (file)
@@ -88,6 +88,8 @@ struct compress {
        struct compr_config *config;
        int running;
        int max_poll_wait_ms;
+       unsigned int gapless_metadata;
+       unsigned int next_track;
 };
 
 static int oops(struct compress *compress, int e, const char *fmt, ...)
@@ -124,6 +126,17 @@ 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)
 {
@@ -211,6 +224,8 @@ struct compress *compress_open(unsigned int card, unsigned int device,
                return &bad_compress;
        }
 
+       compress->next_track = 0;
+       compress->gapless_metadata = 0;
        compress->config = calloc(1, sizeof(*config));
        if (!compress->config)
                goto input_fail;
@@ -436,6 +451,62 @@ int compress_drain(struct compress *compress)
        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)
 {
index bbb09bca9ca58eedaa0d24ef13165df734be26c2..17377dfc60e0c9eb144f21eb541ecea07d2c0c38 100644 (file)
@@ -16,7 +16,7 @@
 #include <sound/asound.h>
 //#include <sound/compress_params.h>
 
-#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 0)
+#define SNDRV_COMPRESS_VERSION SNDRV_PROTOCOL_VERSION(0, 1, 1)
 
 struct snd_compressed_buffer {
  __u32 fragment_size;
@@ -64,11 +64,23 @@ struct snd_compr_codec_caps {
  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)
@@ -76,6 +88,8 @@ struct snd_compr_codec_caps {
 #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
index 7907c72584dde6dcb1e48be097de70a07dbca248..ba9f3b64ab719c37a21d78307f3fbeafc907bad4 100644 (file)
@@ -71,6 +71,11 @@ struct compr_config {
        struct snd_codec *codec;
 };
 
+struct compr_gapless_mdata {
+       __u32 encoder_delay;
+       __u32 encoder_padding;
+};
+
 #define COMPRESS_OUT        0x00000000
 #define COMPRESS_IN         0x10000000
 
@@ -183,6 +188,38 @@ int compress_resume(struct compress *compress);
  */
 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
index 89f0f4edc186b623c87e9590da762cb0ad7762b7..db191d66c2f8274da0901eb9fd098df411c206fa 100644 (file)
@@ -56,7 +56,7 @@
 
 #define TINYCOMPRESS_LIB_MAJOR         0 /* major number of library version */
 #define TINYCOMPRESS_LIB_MINOR         0 /* minor number of library version */
-#define TINYCOMPRESS_LIB_SUBMINOR      1 /* subminor number of library version */
+#define TINYCOMPRESS_LIB_SUBMINOR      2 /* subminor number of library version */
 
 /** library version */
 #define TINYCOMPRESS_LIB_VERSION \
@@ -65,6 +65,6 @@
                  TINYCOMPRESS_LIB_SUBMINOR)
 
 /** library version (string) */
-#define TINYCOMPRESS_LIB_VERSION_STR   "0.0.1"
+#define TINYCOMPRESS_LIB_VERSION_STR   "0.0.2"
 
 #endif