summaryrefslogtreecommitdiff
path: root/src/libasound.c
blob: b43ae9514eeb254f173883ffe92ff909675b425f (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <alsa/asoundlib.h>
#include <alsa/pcm.h>
#include <alsa/pcm_plugin.h>
#include <alsa/pcm_extplug.h>
#include <alsa/pcm_ioplug.h>
#include <alsa/control_external.h>
#include <alsa/mixer_abst.h>
#include <alsa/use-case.h>
#include <alsa/topology.h>

#include "util/util.h"
#include "stubs.h"
#include "symversioning-hell.h"

struct _snd_config { char noop; } s_snd_config;
struct _snd_config *snd_config = &s_snd_config;

const char*
snd_asoundlib_version(void)
{
   return "1.1.7";
}

const char*
snd_strerror(int errnum)
{
   // Do not bother implementing this, just WARN/ERR directly in this lib
   // Letting applications show useful error messages never works out
   return "^";
}

snd_lib_error_handler_t snd_lib_error;

int snd_lib_error_set_handler(snd_lib_error_handler_t handler)
{
   snd_lib_error = handler;
   return 0;
}

int
snd_card_load(int card)
{
   return 0;
}

int
snd_card_next(int *card)
{
   if (card) {
      *card = (*card == -1 ? 0 : -1);
      return 0;
   }

   return -1;
}

int
snd_card_get_index(const char *name)
{
   if (!strcmp(name, "default"))
      return 0;

   return -1;
}

int
snd_card_get_name(int card, char **name)
{
   if (name) *name = "default";
   return 0;
}

int snd_card_get_longname(int card, char **name)
{
   if (name) *name = "default";
   return 0;
}

struct device_name_hint { char *name, *ioid; };

int
snd_device_name_hint(int card, const char *iface, void ***hints)
{
   static struct device_name_hint defaults[] = { { .name = "default", .ioid = "Output" }, { .name = "capture", .ioid = "Input" } };
   static struct device_name_hint *array[] = { &defaults[0], &defaults[1], NULL };
   *hints = (void**)array;
   return 0;
}

char*
snd_device_name_get_hint(const void *hint, const char *id)
{
   const struct device_name_hint *shint = hint;

   if (!strcmp(id, "NAME"))
      return c_strdup(shint->name);
   else if (!strcmp(id, "IOID"))
      return c_strdup(shint->ioid);

   return NULL;
}

int
snd_device_name_free_hint(void **hints)
{
   return 0;
}

struct _snd_ctl {
   char noop;
};

int
snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode)
{
   if (!(*ctl = calloc(1sizeof(**ctl)))) {
      WARNX1("calloc");
      return -1;
   }

   return 0;
}

int
snd_ctl_close(snd_ctl_t *ctl)
{
   free(ctl);
   return 0;
}

struct _snd_ctl_card_info {
   const char *name;
};

size_t
snd_ctl_card_info_sizeof(void)
{
   return sizeof(snd_ctl_card_info_t);
}

int
snd_ctl_card_info_malloc(snd_ctl_card_info_t **ptr)
{
   if (!(*ptr = calloc(1sizeof(**ptr))))
      return -1;

   return 0;
}

void
snd_ctl_card_info_free(snd_ctl_card_info_t *obj)
{
   free(obj);
}

int
snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info)
{
   info->name = "sndio";
   return 0;
}

const char*
snd_ctl_card_info_get_name(const snd_ctl_card_info_t *obj)
{
   return obj->name;
}

const char*
snd_ctl_card_info_get_mixername(const snd_ctl_card_info_t *obj)
{
   return obj->name;
}