public
Last active

OSS backend for e17 mixer module

  • Download Gist
sys_oss.c
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 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
#include "e_mod_system.h"
#include <sys/uio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
#if defined __FreeBSD__
# include <sys/soundcard.h>
#elif defined __NetBSD__ \
|| defined __OpenBSD__
# include <soundcard.h>
#endif
 
static const char *sound_device_labels[] = SOUND_DEVICE_LABELS;
 
static const char default_mixer[] = "/dev/mixer";
 
E_Mixer_System *
e_mixer_system_new(const char *name)
{
int devfd = 0;
 
if (name == NULL)
{
return NULL;
}
 
if ((devfd = open(name, O_RDWR)) < 0)
{
goto error_open;
}
 
/* Offset descriptor value so it won't be tought as NULL pointer */
return (void *)(devfd+1);
 
error_open:
fprintf(stderr, "MIXER: Cannot open %s: %s\n",
name,
strerror(errno));
return NULL;
}
 
void
e_mixer_system_del(E_Mixer_System *self)
{
close((int)(self)-1);
}
 
int
e_mixer_system_callback_set(E_Mixer_System *self,
int (*func)(void *data, E_Mixer_System *self),
void *data)
{
(void)self;
(void)func;
(void)data;
return 0;
}
 
Eina_List *
e_mixer_system_get_cards(void)
{
Eina_List *cards = NULL;
int devfd = 0;
int c = 0;
 
if ((devfd = open(default_mixer, O_RDWR)) >= 0)
{
close(devfd);
cards = eina_list_append(cards, eina_stringshare_add(default_mixer));
}
while (1)
{
char devpath[32];
snprintf(devpath, 31, "/dev/mixer%d", c);
if ((devfd = open(devpath, O_RDWR)) < 0)
{
break;
}
close(devfd);
cards = eina_list_append(cards, eina_stringshare_add(devpath));
c++;
}
 
return cards;
}
 
void
e_mixer_system_free_cards(Eina_List *cards)
{
eina_list_free(cards);
}
 
const char *
e_mixer_system_get_default_card(void)
{
int devfd = 0;
 
if ((devfd = open(default_mixer, O_RDWR)) < 0)
{
goto error_open;
}
close(devfd);
 
return eina_stringshare_add(default_mixer);
 
error_open:
fprintf(stderr, "MIXER: Cannot open %s: %s\n",
default_mixer,
strerror(errno));
return NULL;
}
 
const char *
e_mixer_system_get_card_name(const char *card)
{
/* Is it possible to get a card name with OSS? */
/* /dev/sndstat don't have a formated output (when it exists...) */
return card;
}
 
Eina_List *
e_mixer_system_get_channels(E_Mixer_System *self)
{
Eina_List *channels = NULL;
int devmask = 0x0;
short c = 0;
 
if (ioctl((int)self-1, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
{
goto error_ioctl;
}
 
for (c = 0; c < SOUND_MIXER_NRDEVICES; c++)
{
if ((1 << c) & devmask)
{
/* Offset channel value so it won't be tought as NULL pointer */
channels = eina_list_append(channels, (void *)(c+1));
}
}
 
return channels;
 
error_ioctl:
fprintf(stderr, "MIXER: Cannot check available mixer channels: %s\n",
strerror(errno));
return NULL;
}
 
void
e_mixer_system_free_channels(Eina_List *channels)
{
eina_list_free(channels);
}
 
Eina_List *
e_mixer_system_get_channels_names(E_Mixer_System *self)
{
Eina_List *channels_names = NULL;
int devmask = 0x0;
short c = 0;
 
if (ioctl((int)self-1, SOUND_MIXER_READ_DEVMASK, &devmask) == -1)
{
goto error_ioctl;
}
 
for (c = 0; c < SOUND_MIXER_NRDEVICES; c++)
{
if ((1 << c) & devmask)
{
channels_names =
eina_list_append(channels_names,
eina_stringshare_add(sound_device_labels[c]));
}
}
 
return channels_names;
 
error_ioctl:
fprintf(stderr, "MIXER: Cannot check available mixer channel names: %s\n",
strerror(errno));
return NULL;
}
 
void
e_mixer_system_free_channels_names(Eina_List *channels_names)
{
eina_list_free(channels_names);
}
 
const char *
e_mixer_system_get_default_channel_name(E_Mixer_System *self)
{
return eina_stringshare_add(sound_device_labels[SOUND_MIXER_VOLUME]);
}
 
E_Mixer_Channel *
e_mixer_system_get_channel_by_name(E_Mixer_System *self, const char *name)
{
int c = 0;
 
if (self == NULL || name == NULL)
{
return NULL;
}
 
for (c = 0; c < SOUND_MIXER_NRDEVICES; c++)
{
if (strcmp(sound_device_labels[c], name) == 0)
{
/* Offset channel value so it won't be tought as NULL pointer */
return (void *)(c+1);
}
}
 
return NULL;
}
 
void
e_mixer_system_channel_del(E_Mixer_Channel *channel)
{
(void)channel;
}
 
const char *
e_mixer_system_get_channel_name(E_Mixer_System *self, E_Mixer_Channel *channel)
{
const char *name = NULL;
 
(void)self;
 
name = eina_stringshare_add(sound_device_labels[(size_t)channel-1]);
 
return name;
}
 
int
e_mixer_system_get_volume(E_Mixer_System *self,
E_Mixer_Channel *channel,
int *left,
int *right)
{
int vol = 0;
 
if ((!left) || (!right))
{
return 0;
}
 
if (ioctl((int)self-1, MIXER_READ((int)channel-1), &vol) == -1)
{
goto error_ioctl;
}
*left = vol & 0xff;
*right = (vol & 0xff00) >> 8;
 
return 1;
 
error_ioctl:
fprintf(stderr, "MIXER: Cannot get mixer volume: %s\n",
strerror(errno));
return 0;
}
 
int
e_mixer_system_set_volume(E_Mixer_System *self,
E_Mixer_Channel *channel,
int left,
int right)
{
int vol = 0;
 
vol |= left & 0xff;
vol |= (right & 0xff) << 8;
if (ioctl((int)self-1, MIXER_WRITE((int)channel-1), &vol) == -1)
{
goto error_ioctl;
}
 
return 0;
 
error_ioctl:
fprintf(stderr, "MIXER: Cannot set mixer volume: %s\n",
strerror(errno));
return 1;
}
 
int
e_mixer_system_can_mute(E_Mixer_System *self, E_Mixer_Channel *channel)
{
/* Mute is not really managed in OSS. Other mixers create a mute sys by
* saving/restoring volumes before setting them to zero. */
(void)self;
(void)channel;
return 0;
}
 
int
e_mixer_system_get_mute(E_Mixer_System *self, E_Mixer_Channel *channel, int *mute)
{
(void)self;
(void)channel;
if (!mute)
{
return 0;
}
 
return 1;
}
 
int
e_mixer_system_set_mute(E_Mixer_System *self, E_Mixer_Channel *channel, int mute)
{
(void)self;
(void)channel;
(void)mute;
return 0;
}
 
int
e_mixer_system_get_state(E_Mixer_System *self,
E_Mixer_Channel *channel,
E_Mixer_Channel_State *state)
{
if (!state)
{
return 0;
}
 
if (e_mixer_system_get_mute(self, channel, &state->mute) == 0)
{
return 0;
}
if (e_mixer_system_get_volume(self, channel, &state->left, &state->right) == 0)
{
return 0;
}
 
return 1;
}
 
int
e_mixer_system_set_state(E_Mixer_System *self,
E_Mixer_Channel *channel,
const E_Mixer_Channel_State *state)
{
if (!state)
{
return 0;
}
 
if (e_mixer_system_set_mute(self, channel, state->mute) == 0)
{
return 0;
}
if (e_mixer_system_set_volume(self, channel, state->left, state->right) == 0)
{
return 0;
}
 
return 0;
}
 
int
e_mixer_system_has_capture(E_Mixer_System *self, E_Mixer_Channel *channel)
{
(void)self;
(void)channel;
return 0;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.