~ubuntu-branches/ubuntu/wily/oss4/wily

« back to all changes in this revision

Viewing changes to lib/libossmix/libossmix_local.c

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis, Samuel Thibault, Romain Beauxis, Sebastien NOEL
  • Date: 2011-06-14 10:06:56 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110614100656-cx4oc7u426zn812z
Tags: 4.2-build2004-1
[ Samuel Thibault ]
* debian/control: Add liboss4-salsa2, liboss4-salsa-dev and
  liboss4-salsa-asound2 packages, equivalent to (and will replace) those from
  the oss-libsalsa package (Closes: #589127).
* debian/patches/liboss4-salsa.patch: New patch to rename libsalsa into
  liboss4-salsa to avoid conflicts in the archive for no good reason.
* debian/rules: Make in libOSSlib and libsalsa.
* debian/liboss4-salsa-dev.install, debian/liboss4-salsa2.install,
  debian/liboss4-salsa-asound2.links, debian/liboss4-salsa-dev.links:
  Install liboss4-salsa libraries like was done in the oss-libsalsa package.
* include-alsa: Add a copy of ALSA 1.0.5 headers: Cf ALSA_1.0.* symbols in
  libsalsa, this is the roughly supported version.
* debian/copyright: Update for new include-alsa files.
* alsa.pc: New file for compatibility with libasound-dev.
* debian/control:
  - Add Vcs-Browser and Vcs-Svn fields.
  - Use linux-any instead of the list of Linux archs (Closes: #604679).
  - Make dkms dependency linux-any only.
* debian/patches/hurd_iot.patch: New patch to fix soundcard.h usage in
  libsalsa on hurd-i386.
* debian/patches/libsalsa_fixes.patch: New patch to fix some printf usages
  and ioctl declaration in libsalsa.
* debian/patches/no_EBADE.patch: New patch to cope with hurd-i386 not having
  EBADE.
* debian/patches/CFLAGS.patch: New patch to make oss4 take debian/rules
  CFLAGS into account.
* debian/patches/snd_asoundlib_version.patch: New patch to add
  snd_asoundlib_version().
* debian/patches/generic_srccconf.patch: New patch to fix source
  configuration on unknown archs.

[ Romain Beauxis ]
* Fixed README.Debian to only mention dkms' modules.
* Switch to dpkg-source 3.0 (quilt) format
* Added DM-Upload-Allowed: yes

[ Sebastien NOEL ]
* New upstream release (Closes: #595298, #619272).
* Fix typo in initscript (Closes: #627149).
* debian/control: adjust linux-headers dependencies (Closes: #628879).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * This file is part of Open Sound System.
 
4
 *
 
5
 * Copyright (C) 4Front Technologies 1996-2008.
 
6
 *
 
7
 * This this source file is released under GPL v2 license (no other versions).
 
8
 * See the COPYING file included in the main directory of this source
 
9
 * distribution for the license terms and conditions.
 
10
 *
 
11
 */
 
12
/*
 
13
 * Local driver for libossmix
 
14
 */
 
15
#include <stdio.h>
 
16
#include <stdlib.h>
 
17
#include <unistd.h>
 
18
#include <fcntl.h>
 
19
#include <sys/ioctl.h>
 
20
#include <errno.h>
 
21
 
 
22
#include <soundcard.h>
 
23
 
 
24
#define OSSMIX_REMOTE
 
25
 
 
26
#include "libossmix.h"
 
27
#include "libossmix_impl.h"
 
28
 
 
29
static int global_fd = -1;
 
30
static int num_mixers=0;
 
31
 
 
32
static int mixer_fd[MAX_TMP_MIXER];
 
33
 
 
34
static int
 
35
local_connect (const char *hostname, int port)
 
36
{
 
37
  char *devmixer;
 
38
  int i;
 
39
 
 
40
  if (mixlib_trace > 0)
 
41
    fprintf (stderr, "Entered local_connect()\n");
 
42
 
 
43
  for (i = 0; i < MAX_TMP_MIXER; i++)
 
44
    mixer_fd[i] = -1;
 
45
 
 
46
  if ((devmixer = getenv ("OSS_MIXERDEV")) == NULL)
 
47
    devmixer = "/dev/mixer";
 
48
 
 
49
/*
 
50
 *      Open the mixer device
 
51
 */
 
52
  if ((global_fd = open (devmixer, O_RDWR, 0)) == -1)
 
53
    {
 
54
      perror (devmixer);
 
55
      return -1;
 
56
    }
 
57
 
 
58
  return 0;
 
59
}
 
60
 
 
61
static void
 
62
local_disconnect (void)
 
63
{
 
64
  if (mixlib_trace > 0)
 
65
    fprintf (stderr, "Entered local_disconnect()\n");
 
66
 
 
67
  if (global_fd >= 0)
 
68
    close (global_fd);
 
69
 
 
70
  global_fd = -1;
 
71
}
 
72
 
 
73
static void
 
74
local_enable_events (void)
 
75
{
 
76
}
 
77
 
 
78
static int
 
79
local_get_fd (ossmix_select_poll_t * cb)
 
80
{
 
81
  *cb = NULL;
 
82
  return -1;                    /* No poll handling required */
 
83
}
 
84
 
 
85
static int
 
86
local_get_nmixers (void)
 
87
{
 
88
  oss_sysinfo si;
 
89
 
 
90
  if (ioctl (global_fd, SNDCTL_SYSINFO, &si) == -1)
 
91
    {
 
92
      perror ("SNDCTL_SYSINFO");
 
93
      return -1;
 
94
    }
 
95
 
 
96
  return num_mixers = si.nummixers;
 
97
}
 
98
 
 
99
static int
 
100
local_get_mixerinfo (int mixernum, oss_mixerinfo * mi)
 
101
{
 
102
  mi->dev = mixernum;
 
103
 
 
104
  if (ioctl (global_fd, SNDCTL_MIXERINFO, mi) == -1)
 
105
    {
 
106
      perror ("SNDCTL_MIXERINFO");
 
107
      return -1;
 
108
    }
 
109
 
 
110
  return 0;
 
111
}
 
112
 
 
113
static int
 
114
local_open_mixer (int mixernum)
 
115
{
 
116
  oss_mixerinfo mi;
 
117
 
 
118
  if (mixer_fd[mixernum] > -1)
 
119
    return 0;
 
120
 
 
121
  if (ossmix_get_mixerinfo (mixernum, &mi) < 0)
 
122
    return -1;
 
123
 
 
124
//fprintf(stderr, "local_open_mixer(%d: %s)\n", mixernum, mi.devnode);
 
125
 
 
126
  if ((mixer_fd[mixernum] = open (mi.devnode, O_RDWR, 0)) == -1)
 
127
    {
 
128
      perror (mi.devnode);
 
129
      return -1;
 
130
    }
 
131
 
 
132
  return 0;
 
133
}
 
134
 
 
135
static void
 
136
local_close_mixer (int mixernum)
 
137
{
 
138
//fprintf(stderr, "local_close_mixer(%d)\n", mixernum);
 
139
 
 
140
  if (mixer_fd[mixernum] == -1)
 
141
    return;
 
142
 
 
143
  close (mixer_fd[mixernum]);
 
144
  mixer_fd[mixernum] = -1;
 
145
}
 
146
 
 
147
static int
 
148
local_get_nrext (int mixernum)
 
149
{
 
150
  int n = -1;
 
151
 
 
152
  if (ioctl (mixer_fd[mixernum], SNDCTL_MIX_NREXT, &n) == -1)
 
153
    {
 
154
      perror ("SNDCTL_MIX_NREXT");
 
155
      return -1;
 
156
    }
 
157
 
 
158
  return n;
 
159
}
 
160
 
 
161
static int
 
162
local_get_nodeinfo (int mixernum, int node, oss_mixext * ext)
 
163
{
 
164
  ext->dev = mixernum;
 
165
  ext->ctrl = node;
 
166
 
 
167
  if (ioctl (mixer_fd[mixernum], SNDCTL_MIX_EXTINFO, ext) == -1)
 
168
    {
 
169
      perror ("SNDCTL_MIX_EXTINFO");
 
170
      return -1;
 
171
    }
 
172
 
 
173
  mixc_add_node (mixernum, node, ext);
 
174
  return 0;
 
175
}
 
176
 
 
177
static int
 
178
local_get_enuminfo (int mixernum, int node, oss_mixer_enuminfo * ei)
 
179
{
 
180
  ei->dev = mixernum;
 
181
  ei->ctrl = node;
 
182
 
 
183
  if (ioctl (mixer_fd[mixernum], SNDCTL_MIX_ENUMINFO, ei) == -1)
 
184
    {
 
185
      perror ("SNDCTL_MIX_ENUMINFO");
 
186
      return -1;
 
187
    }
 
188
 
 
189
  return 0;
 
190
}
 
191
 
 
192
static int
 
193
local_get_description (int mixernum, int node, oss_mixer_enuminfo * desc)
 
194
{
 
195
  desc->dev = mixernum;
 
196
  desc->ctrl = node;
 
197
 
 
198
  if (ioctl (mixer_fd[mixernum], SNDCTL_MIX_DESCRIPTION, desc) == -1)
 
199
    {
 
200
      perror ("SNDCTL_MIX_DESCRIPTION");
 
201
      return -1;
 
202
    }
 
203
 
 
204
  return 0;
 
205
}
 
206
 
 
207
static int
 
208
local_get_value (int mixernum, int ctl, int timestamp)
 
209
{
 
210
  oss_mixer_value val;
 
211
 
 
212
  val.dev = mixernum;
 
213
  val.ctrl = ctl;
 
214
  val.timestamp = timestamp;
 
215
 
 
216
  if (ioctl (mixer_fd[mixernum], SNDCTL_MIX_READ, &val) == -1)
 
217
    {
 
218
      perror ("SNDCTL_MIX_READ");
 
219
      return -1;
 
220
    }
 
221
 
 
222
  mixc_set_value (mixernum, ctl, val.value);
 
223
  return val.value;
 
224
}
 
225
 
 
226
static int
 
227
private_get_value (int mixernum, int ctl, int timestamp)
 
228
{
 
229
  oss_mixer_value val;
 
230
 
 
231
  val.dev = mixernum;
 
232
  val.ctrl = ctl;
 
233
  val.timestamp = timestamp;
 
234
 
 
235
  if (ioctl (mixer_fd[mixernum], SNDCTL_MIX_READ, &val) == -1)
 
236
    {
 
237
      perror ("SNDCTL_MIX_READ");
 
238
      return -1;
 
239
    }
 
240
 
 
241
  return val.value;
 
242
}
 
243
 
 
244
static void
 
245
local_set_value (int mixernum, int ctl, int timestamp, int value)
 
246
{
 
247
  oss_mixer_value val;
 
248
 
 
249
  val.dev = mixernum;
 
250
  val.ctrl = ctl;
 
251
  val.timestamp = timestamp;
 
252
  val.value = value;
 
253
 
 
254
  if (ioctl (mixer_fd[mixernum], SNDCTL_MIX_WRITE, &val) == -1)
 
255
    {
 
256
      perror ("SNDCTL_MIX_WRITE");
 
257
    }
 
258
  mixc_set_value (mixernum, ctl, val.value);
 
259
}
 
260
 
 
261
static void
 
262
update_values (int mixernum)
 
263
{
 
264
  oss_mixext *ext;
 
265
  int i;
 
266
  int nrext;
 
267
  int value, prev_value;
 
268
 
 
269
  nrext = ossmix_get_nrext (mixernum);
 
270
 
 
271
  for (i = 0; i < nrext; i++)
 
272
    {
 
273
      if ((ext = mixc_get_node (mixernum, i)) == NULL)
 
274
      {
 
275
        continue;
 
276
      }
 
277
 
 
278
      if (ext->type == MIXT_DEVROOT || ext->type == MIXT_GROUP
 
279
          || ext->type == MIXT_MARKER)
 
280
        continue;
 
281
 
 
282
      prev_value = mixc_get_value (mixernum, i);
 
283
 
 
284
      if ((value = private_get_value (mixernum, i, ext->timestamp)) < 0)
 
285
        continue;
 
286
      // TODO check for EIDRM
 
287
 
 
288
      if (value != prev_value)
 
289
      {
 
290
         mixc_set_value (mixernum, i, value);
 
291
         _client_event (OSSMIX_EVENT_VALUE, mixernum, i, value, 0, 0);
 
292
      }
 
293
 
 
294
    }
 
295
}
 
296
 
 
297
static void
 
298
local_timertick(void)
 
299
{
 
300
        int mixernum, n;
 
301
 
 
302
        for (mixernum=0;mixernum<num_mixers;mixernum++)
 
303
        if (mixer_fd[mixernum] >= 0) /* Open */
 
304
        {
 
305
                update_values (mixernum);
 
306
        }
 
307
 
 
308
        n=ossmix_get_nmixers();
 
309
        if (n>num_mixers)
 
310
        {
 
311
                num_mixers=n;
 
312
                _client_event (OSSMIX_EVENT_NEWMIXER, n, 0, 0, 0, 0);
 
313
        }
 
314
}
 
315
 
 
316
ossmix_driver_t ossmix_local_driver = {
 
317
  local_connect,
 
318
  local_get_fd,
 
319
  local_disconnect,
 
320
  local_enable_events,
 
321
  local_get_nmixers,
 
322
  local_get_mixerinfo,
 
323
  local_open_mixer,
 
324
  local_close_mixer,
 
325
  local_get_nrext,
 
326
  local_get_nodeinfo,
 
327
  local_get_enuminfo,
 
328
  local_get_description,
 
329
  local_get_value,
 
330
  local_set_value,
 
331
  local_timertick
 
332
};