-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalsa.c
56 lines (45 loc) · 1.09 KB
/
alsa.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* bluealsa-autoconfig - alsa.c
* Copyright (c) 2023 @borine (https://github.com/borine/)
*
* This project is licensed under the terms of the MIT license.
*
*/
#include <alsa/asoundlib.h>
#include <stdio.h>
#include "alsa.h"
#include <pthread.h>
static struct {
const char *string;
unsigned int id;
} alsa_version = { 0 };
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void alsa_version_init(void) {
unsigned int major;
unsigned int minor;
unsigned int subminor;
unsigned int extra;
pthread_mutex_lock(&mutex);
if (alsa_version.string != NULL) {
pthread_mutex_unlock(&mutex);
return;
}
alsa_version.string = snd_asoundlib_version();
sscanf(alsa_version.string, "%u.%u.%u.%u",
&major,
&minor,
&subminor,
&extra);
alsa_version.id = major << 16 | minor << 8 | subminor;
pthread_mutex_unlock(&mutex);
}
unsigned int alsa_version_id(void) {
if (alsa_version.string == NULL)
alsa_version_init();
return alsa_version.id;
}
const char *alsa_version_string(void) {
if (alsa_version.string == NULL)
alsa_version_init();
return alsa_version.string;
}