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
|
/*
*
* This file is part of Open Sound System.
*
* Copyright (C) 4Front Technologies 1996-2008.
*
* This this source file is released under GPL v2 license (no other versions).
* See the COPYING file included in the main directory of this source
* distribution for the license terms and conditions.
*
*/
/*
* Settings cache for libossmix
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <soundcard.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <errno.h>
#include <netdb.h>
#define OSSMIX_REMOTE
#include "libossmix.h"
#include "libossmix_impl.h"
static local_mixer_t *mixers[MAX_TMP_MIXER] = { NULL };
void
mixc_add_node (int mixernum, int node, oss_mixext * ext)
{
local_mixer_t *lmixer;
oss_mixext *lnode;
if (mixers[mixernum] == NULL)
{
int i;
mixers[mixernum] = lmixer = malloc (sizeof (*lmixer));
if (lmixer == NULL)
{
fprintf (stderr, "mixc_add_node: Out of memory\n");
exit (EXIT_FAILURE);
}
memset (lmixer, 0, sizeof (*lmixer));
for (i = 0; i < MAX_TMP_NODES; i++)
lmixer->values[i] = -1; // Invalid
}
else
lmixer = mixers[mixernum];
if (ext->ctrl >= lmixer->nrext)
lmixer->nrext = ext->ctrl + 1;
if (node >= MAX_TMP_NODES)
{
fprintf (stderr, "mixc_add_node: Node number too large %d\n", node);
exit (EXIT_FAILURE);
}
lnode = lmixer->nodes[node];
if (lnode == NULL)
{
lmixer->nodes[node] = lnode = malloc (sizeof (*lnode));
if (lnode == NULL)
{
fprintf (stderr, "mixc_get_node: Out of memory\n");
exit (EXIT_FAILURE);
}
}
memcpy (lnode, ext, sizeof (*ext));
}
oss_mixext *
mixc_get_node (int mixernum, int node)
{
local_mixer_t *lmixer;
oss_mixext *lnode;
if (mixers[mixernum] == NULL)
{
return NULL;
}
lmixer = mixers[mixernum];
if (node >= MAX_TMP_NODES)
{
fprintf (stderr, "mixc_get_node: Node number too large %d\n", node);
exit (EXIT_FAILURE);
}
lnode = lmixer->nodes[node];
return lnode;
}
void
mixc_clear_changeflags(int mixernum)
{
local_mixer_t *lmixer;
if (mixers[mixernum] == NULL)
{
return;
}
lmixer = mixers[mixernum];
memset(lmixer->changemask, 0, sizeof(lmixer->changemask));
}
void
mixc_set_value (int mixernum, int node, int value)
{
local_mixer_t *lmixer;
if (mixers[mixernum] == NULL)
{
return;
}
lmixer = mixers[mixernum];
if (node >= MAX_TMP_NODES)
{
fprintf (stderr, "mixc_set_value: Node number too large %d\n", node);
exit (EXIT_FAILURE);
}
if (lmixer->values[node] != value)
lmixer->changemask[node / 8] |= (1 << (node % 8));
lmixer->values[node] = value;
}
int
mixc_get_value (int mixernum, int node)
{
local_mixer_t *lmixer;
if (mixers[mixernum] == NULL)
{
return -1;
}
lmixer = mixers[mixernum];
if (node >= MAX_TMP_NODES)
{
fprintf (stderr, "mixc_get_value: Node number too large %d\n", node);
exit (EXIT_FAILURE);
}
lmixer->changemask[node / 8] &= ~(1 << (node % 8));
return lmixer->values[node];
}
int
mixc_get_all_values (int mixernum, value_packet_t value_packet, int changecheck)
{
int i, n = 0;
oss_mixext *lnode;
local_mixer_t *lmixer;
if (mixers[mixernum] == NULL)
{
fprintf (stderr, "mixc_get_all_values: Mixer %d doesn't exist\n",
mixernum);
return 0;
}
lmixer = mixers[mixernum];
for (i = 0; i < lmixer->nrext; i++)
{
lnode = lmixer->nodes[i];
if (lnode == NULL)
{
fprintf (stderr, "mixc_get_all_values: Mixer %d, node %d == NULL\n",
mixernum, i);
continue;
}
if (changecheck) // Not changed since the last time
if (!(lmixer->changemask[i / 8] & (1 << (i % 8)) ))
continue;
if (lnode->type != MIXT_DEVROOT && lnode->type != MIXT_GROUP
&& lnode->type != MIXT_MARKER)
{
value_packet[n].node = i;
value_packet[n].value = lmixer->values[i];
lmixer->changemask[i / 8] &= ~(1 << (i % 8));
//printf("Send %d = %08x\n", i, lmixer->values[i]);
n++;
}
}
return n;
}
|