From: George Verhaegen Date: Fri, 1 Aug 2025 10:47:43 +0000 (+0100) Subject: compress_hw: cache ioctl version X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=f1183e52e28f11376a6e365922875326d5ead23f;p=tinycompress.git compress_hw: cache ioctl version Read the version when opened and cache it to reduce ioctl calls. --- diff --git a/src/lib/compress_hw.c b/src/lib/compress_hw.c index 2773639..a07fa8d 100644 --- a/src/lib/compress_hw.c +++ b/src/lib/compress_hw.c @@ -36,6 +36,7 @@ struct compress_hw_data { int fd; unsigned int flags; char error[COMPR_ERR_MAX]; + int ioctl_version; struct compr_config *config; int running; int max_poll_wait_ms; @@ -88,13 +89,7 @@ static int is_compress_hw_ready(void *data) static int get_compress_hw_version(struct compress_hw_data *compress) { - int version = 0; - - if (ioctl(compress->fd, SNDRV_COMPRESS_IOCTL_VERSION, &version)) { - oops(compress, errno, "cant read version"); - return -1; - } - return version; + return compress->ioctl_version; } static bool _is_codec_type_supported(int fd, struct snd_codec *codec) @@ -178,6 +173,11 @@ static void *compress_hw_open_by_name(const char *name, goto config_fail; } + if (ioctl(compress->fd, SNDRV_COMPRESS_IOCTL_VERSION, &compress->ioctl_version)) { + oops(&bad_compress, errno, "cannot read version"); + goto codec_fail; + } + if (ioctl(compress->fd, SNDRV_COMPRESS_GET_CAPS, &caps)) { oops(compress, errno, "cannot get device caps"); goto codec_fail;