From: Mohammad Rafi Shaik Date: Tue, 1 Nov 2022 07:59:27 +0000 (+0530) Subject: src: lib: Add API to set codec parameters for next track X-Git-Tag: v1.2.11~1 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=b6e558633e8efc08578d9d4292477792b6c6bc07;p=tinycompress.git src: lib: Add API to set codec parameters for next track For gapless playback usecase where each track differs in encoding, new codec parameters that need to be propagated to kernel is done via compress_set_codec_params() Signed-off-by: Srinivas Kandagatla Signed-off-by: Mohammad Rafi Shaik Signed-off-by: Vinod Koul --- diff --git a/include/tinycompress/compress_ops.h b/include/tinycompress/compress_ops.h index 9b204a6..2ee8d15 100644 --- a/include/tinycompress/compress_ops.h +++ b/include/tinycompress/compress_ops.h @@ -42,6 +42,7 @@ struct compress_ops { int (*is_compress_running)(void *compress_data); int (*is_compress_ready)(void *compress_data); const char *(*get_error)(void *compress_data); + int (*set_codec_params)(void *compress_data, struct snd_codec *codec); }; #endif /* end of __COMPRESS_OPS_H__ */ diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h index c710a61..a8b4e58 100644 --- a/include/tinycompress/tinycompress.h +++ b/include/tinycompress/tinycompress.h @@ -307,6 +307,17 @@ int is_compress_ready(struct compress *compress); /* Returns a human readable reason for the last error */ const char *compress_get_error(struct compress *compress); +/* + * compress_set_param: set codec config intended for next track + * if DSP has support to switch CODEC config during gapless playback + * + * return 0 on success, negative on error + * + * @compress: compress stream for which metadata has to set + * @config: stream config for next track + */ +int compress_set_codec_params(struct compress *compress, struct snd_codec *codec); + #if defined(__cplusplus) } // extern "C" #endif diff --git a/src/lib/compress.c b/src/lib/compress.c index 68f1b55..5a8fd04 100644 --- a/src/lib/compress.c +++ b/src/lib/compress.c @@ -310,3 +310,7 @@ int compress_wait(struct compress *compress, int timeout_ms) return compress->ops->wait(compress->data, timeout_ms); } +int compress_set_codec_params(struct compress *compress, struct snd_codec *codec) +{ + return compress->ops->set_codec_params(compress->data, codec); +} diff --git a/src/lib/compress_hw.c b/src/lib/compress_hw.c index 9944f0e..5aabae0 100644 --- a/src/lib/compress_hw.c +++ b/src/lib/compress_hw.c @@ -573,6 +573,31 @@ static int compress_hw_wait(void *data, int timeout_ms) return oops(compress, EIO, "poll signalled unhandled event"); } +static int compress_hw_set_codec_params(void *data, struct snd_codec *codec) +{ + struct compress_hw_data *compress = (struct compress_hw_data *)data; + struct snd_compr_params params; + + if (!is_compress_hw_ready(compress)) + return oops(compress, ENODEV, "device not ready\n"); + + if (!codec) + return oops(compress, EINVAL, "passed bad config\n"); + + if (!compress->next_track) + return oops(compress, EPERM, + "set CODEC params while next track not signalled is not allowed"); + + params.buffer.fragment_size = compress->config->fragment_size; + params.buffer.fragments = compress->config->fragments; + memcpy(¶ms.codec, codec, sizeof(params.codec)); + + if (ioctl(compress->fd, SNDRV_COMPRESS_SET_PARAMS, ¶ms)) + return oops(compress, errno, "cannot set param for next track\n"); + + return 0; +} + struct compress_ops compress_hw_ops = { .open_by_name = compress_hw_open_by_name, .close = compress_hw_close, @@ -595,5 +620,6 @@ struct compress_ops compress_hw_ops = { .is_compress_running = is_compress_hw_running, .is_compress_ready = is_compress_hw_ready, .get_error = compress_hw_get_error, + .set_codec_params = compress_hw_set_codec_params, };