1From 1921efacfe1a230021849b83b2877c8f239b44ab Mon Sep 17 00:00:00 2001
2From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
3Date: Sun, 17 Jul 2022 19:09:04 +0200
4Subject: [PATCH] aplay/aplay.c: make UCM support optional
5
6Commit 90f59671784a7e47b40485095cd66892d4840ed7 ("topology:
7pre-processor: Move the call to expand variables") modified aplay by
8unconditionally invoking features of the use case manager (UCM) from
9alsa-lib. However, alsa-lib can be compiled without UCM support.
10
11In order to properly support this situation, this commit changes aplay
12to only conditionally compile the UCM related code.
13
14Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
15Upstream: https://mailman.alsa-project.org/pipermail/alsa-devel/2022-July/203847.html
16---
17 aplay/aplay.c | 10 ++++++++++
18 1 file changed, 10 insertions(+)
19
20diff --git a/aplay/aplay.c b/aplay/aplay.c
21index b3b3635..59f937d 100644
22--- a/aplay/aplay.c
23+++ b/aplay/aplay.c
24@@ -41,7 +41,9 @@
25 #include <time.h>
26 #include <locale.h>
27 #include <alsa/asoundlib.h>
28+#ifdef HAVE_ALSA_USE_CASE_H
29 #include <alsa/use-case.h>
30+#endif
31 #include <assert.h>
32 #include <termios.h>
33 #include <signal.h>
34@@ -453,6 +455,7 @@ static ssize_t xwrite(int fd, const void *buf, size_t count)
35 	return offset;
36 }
37
38+#ifdef HAVE_ALSA_USE_CASE_H
39 static int open_ucm(snd_use_case_mgr_t **uc_mgr, char **pcm_name, const char *name)
40 {
41 	char *s, *p;
42@@ -476,6 +479,7 @@ static int open_ucm(snd_use_case_mgr_t **uc_mgr, char **pcm_name, const char *na
43 	}
44 	return err;
45 }
46+#endif
47
48 static long parse_long(const char *str, int *err)
49 {
50@@ -553,7 +557,9 @@ int main(int argc, char *argv[])
51 	int do_device_list = 0, do_pcm_list = 0, force_sample_format = 0;
52 	snd_pcm_info_t *info;
53 	FILE *direction;
54+#ifdef HAVE_ALSA_USE_CASE_H
55 	snd_use_case_mgr_t *uc_mgr = NULL;
56+#endif
57
58 #ifdef ENABLE_NLS
59 	setlocale(LC_ALL, "");
60@@ -852,6 +858,7 @@ int main(int argc, char *argv[])
61 		goto __end;
62 	}
63
64+#ifdef HAVE_ALSA_USE_CASE_H
65 	if (strncmp(pcm_name, "ucm.", 4) == 0) {
66 		err = open_ucm(&uc_mgr, &pcm_name, pcm_name + 4);
67 		if (err < 0) {
68@@ -861,6 +868,7 @@ int main(int argc, char *argv[])
69 		if (verbose)
70 			fprintf(stderr, _("Found UCM PCM device: %s\n"), pcm_name);
71 	}
72+#endif
73
74 	err = snd_pcm_open(&handle, pcm_name, stream, open_mode);
75 	if (err < 0) {
76@@ -951,8 +959,10 @@ int main(int argc, char *argv[])
77 	if (verbose==2)
78 		putchar('\n');
79 	snd_pcm_close(handle);
80+#ifdef HAVE_ALSA_USE_CASE_H
81 	if (uc_mgr)
82 		snd_use_case_mgr_close(uc_mgr);
83+#endif
84 	handle = NULL;
85 	free(audiobuf);
86       __end:
87--
882.36.1
89
90