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>
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, ...)
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)
{
return &bad_compress;
}
+ compress->next_track = 0;
+ compress->gapless_metadata = 0;
compress->config = calloc(1, sizeof(*config));
if (!compress->config)
goto input_fail;
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)
{
#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;
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_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
struct snd_codec *codec;
};
+struct compr_gapless_mdata {
+ __u32 encoder_delay;
+ __u32 encoder_padding;
+};
+
#define COMPRESS_OUT 0x00000000
#define COMPRESS_IN 0x10000000
*/
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
#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 \
TINYCOMPRESS_LIB_SUBMINOR)
/** library version (string) */
-#define TINYCOMPRESS_LIB_VERSION_STR "0.0.1"
+#define TINYCOMPRESS_LIB_VERSION_STR "0.0.2"
#endif