~ubuntu-branches/ubuntu/vivid/oss4/vivid

« back to all changes in this revision

Viewing changes to tutorials/sndkit/libossmix_demo/ossmixlib_demo.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
#include <stdio.h>
 
14
#include <stdlib.h>
 
15
#include <unistd.h>
 
16
#include <string.h>
 
17
 
 
18
#include <sys/soundcard.h>
 
19
#include <sys/libossmix.h>
 
20
 
 
21
static void
 
22
event_callback(ossmix_callback_parm_t *parms)
 
23
{
 
24
        switch (parms->event)
 
25
        {
 
26
        case OSSMIX_EVENT_VALUE:
 
27
                printf("Value change, mixer=%d, ctl=%d, value=0x%08x\n", parms->p1, parms->p2, parms->p3);
 
28
                break;
 
29
 
 
30
        case OSSMIX_EVENT_NEWMIXER:
 
31
                printf("Number of mixers increased to %d\n", parms->p1);
 
32
                break;
 
33
 
 
34
        default:
 
35
                printf("Event callback %d, %d, %d, %d, %d\n", parms->event, parms->p1, parms->p2, parms->p3, parms->p4);
 
36
        }
 
37
}
 
38
 
 
39
static void
 
40
command_parser(char *line)
 
41
{
 
42
        char *p = line + strlen(line)-1;
 
43
 
 
44
        if (*p == '\n')
 
45
           *p=0;
 
46
 
 
47
        if (strcmp(line, "exit")==0 || strcmp(line, "q")==0)
 
48
           exit(0);
 
49
}
 
50
 
 
51
static void
 
52
interactive_mode(void)
 
53
{
 
54
  int libfd=-1, maxdev, ndevs;
 
55
  fd_set readfds;
 
56
  ossmix_select_poll_t pollfunc;
 
57
  struct timeval tmout;
 
58
 
 
59
  libfd=ossmix_get_fd(&pollfunc);
 
60
 
 
61
  ossmix_set_callback(event_callback);
 
62
 
 
63
  printf("libfd=%d, func=%p\n", libfd, pollfunc);
 
64
  printf("\n");
 
65
  printf("> ");fflush(stdout);
 
66
 
 
67
  if (libfd >= 0)
 
68
     {
 
69
        tmout.tv_sec = 0;
 
70
        tmout.tv_usec = 100000; /* 0.1 sec */
 
71
     }
 
72
  else
 
73
     {
 
74
        tmout.tv_sec = 0;
 
75
        tmout.tv_usec = 0;
 
76
     }
 
77
 
 
78
  while (1)
 
79
    {
 
80
      FD_ZERO (&readfds);
 
81
 
 
82
      maxdev = 0;
 
83
 
 
84
      FD_SET (0, &readfds); // Stdin
 
85
      if (libfd > 0)
 
86
         FD_SET (libfd, &readfds);
 
87
 
 
88
      if (libfd > maxdev)
 
89
        maxdev = libfd;
 
90
 
 
91
      if ((ndevs =
 
92
           select (maxdev + 1, &readfds, NULL, NULL, &tmout)) == -1)
 
93
        {
 
94
          perror ("select");
 
95
          exit (-1);
 
96
        }
 
97
 
 
98
      if (ndevs == 0)
 
99
        {
 
100
          ossmix_timertick();
 
101
          tmout.tv_sec = 0;
 
102
          tmout.tv_usec = 100000; /* 0.1 sec */
 
103
        }
 
104
 
 
105
      if (FD_ISSET (0, &readfds)) /* Stdio */
 
106
      {
 
107
              char line[128];
 
108
 
 
109
              if (fgets(line, sizeof(line)-1, stdin) != NULL)
 
110
              {
 
111
                command_parser(line);
 
112
                printf("> ");fflush(stdout);
 
113
              }
 
114
      }
 
115
 
 
116
      if (libfd > 0)
 
117
      if (FD_ISSET (libfd, &readfds))
 
118
         pollfunc();
 
119
    }
 
120
}
 
121
 
 
122
static void
 
123
print_enum_list(int mixnum, int ctl)
 
124
{
 
125
        oss_mixer_enuminfo desc;
 
126
        int i;
 
127
        
 
128
        if (ossmix_get_enuminfo(mixnum, ctl, &desc)<0)
 
129
        {
 
130
                fprintf(stderr, "ossmix_get_enuminfo() failed\n");
 
131
                return;
 
132
        }
 
133
 
 
134
        for (i=0;i<desc.nvalues;i++)
 
135
        {
 
136
                if (i>0)printf(" | ");
 
137
                printf("%s", desc.strings+desc.strindex[i]);
 
138
        }
 
139
 
 
140
        printf("\n");
 
141
}
 
142
 
 
143
static void
 
144
print_description(int mixnum, int ctl)
 
145
{
 
146
        oss_mixer_enuminfo desc;
 
147
        
 
148
        if (ossmix_get_description(mixnum, ctl, &desc)<0)
 
149
        {
 
150
                fprintf(stderr, "ossmix_get_description() failed\n");
 
151
                return;
 
152
        }
 
153
 
 
154
        printf("%s\n", desc.strings);
 
155
}
 
156
 
 
157
int
 
158
main(int argc, char *argv[])
 
159
{
 
160
        int err, i;
 
161
        char *host=NULL;
 
162
        int port=7777;
 
163
        int nmixers=0;
 
164
        extern int mixlib_trace;
 
165
        int interactive=0;
 
166
 
 
167
        //mixlib_trace=1;
 
168
 
 
169
        while ((i = getopt(argc, argv, "ip:h:")) != EOF)
 
170
        switch (i)
 
171
        {
 
172
        case 'i':
 
173
                interactive=1;
 
174
                break;
 
175
        case 'p':
 
176
                port = atoi(optarg);
 
177
                break;
 
178
 
 
179
        case 'h':
 
180
                host=optarg;
 
181
                break;
 
182
        }
 
183
 
 
184
        if ((err=ossmix_init())<0)
 
185
        {
 
186
                fprintf(stderr, "ossmix_init() failed, err=%d\n");
 
187
                exit(EXIT_FAILURE);
 
188
        }
 
189
 
 
190
        if ((err=ossmix_connect(host, port))<0)
 
191
        {
 
192
                fprintf(stderr, "ossmix_connect() failed, err=%d\n", err);
 
193
                exit(EXIT_FAILURE);
 
194
        }
 
195
 
 
196
        if ((nmixers=ossmix_get_nmixers())<0)
 
197
        {
 
198
                fprintf(stderr, "ossmix_get_nmixers() failed, err=%d\n", nmixers);
 
199
                exit(EXIT_FAILURE);
 
200
        }
 
201
 
 
202
        printf("Number of mixers=%d\n", nmixers);
 
203
 
 
204
        for (i=0;i<nmixers;i++)
 
205
        {
 
206
                oss_mixerinfo mi;
 
207
                int n, ctl;
 
208
 
 
209
                if (ossmix_get_mixerinfo(i, &mi)<0)
 
210
                {
 
211
                        fprintf(stderr, "ossmix_get_mixerinfo(%d) failed\n", i);
 
212
                        exit(EXIT_FAILURE);
 
213
                }
 
214
 
 
215
                printf("Mixer %2d: %s\n", i, mi.name);
 
216
 
 
217
                if (ossmix_open_mixer(i)<0)
 
218
                {
 
219
                        fprintf(stderr, "ossmix_open_mixer(%d) failed\n", i);
 
220
                        exit(EXIT_FAILURE);
 
221
                }
 
222
 
 
223
                if ((n=ossmix_get_nrext(i))<0)
 
224
                {
 
225
                        fprintf(stderr, "ossmix_get_nrext(%d) failed, err=\n", i, n);
 
226
                        exit(EXIT_FAILURE);
 
227
                }
 
228
 
 
229
                printf("Mixer has %d nodes\n", n);
 
230
 
 
231
                for (ctl=0;ctl<n;ctl++)
 
232
                {
 
233
                        oss_mixext node;
 
234
                        int value=0;
 
235
 
 
236
                        if (ossmix_get_nodeinfo(i, ctl, &node)<0)
 
237
                        {
 
238
                                fprintf(stderr, "ossmix_get_nodeinfo(%d, %d) failed\n",
 
239
                                                i, ctl);
 
240
                                exit(EXIT_FAILURE);
 
241
 
 
242
                        }
 
243
 
 
244
                        if (node.type != MIXT_DEVROOT && node.type != MIXT_GROUP && node.type != MIXT_MARKER)
 
245
                        if ((value=ossmix_get_value(i, ctl, node.timestamp))<0)
 
246
                        {
 
247
                                fprintf(stderr, "ossmix_get_value(%d, %d, %d) failed, err=%d\n",
 
248
                                                i, ctl, node.timestamp, value);
 
249
                        }
 
250
 
 
251
                        printf("%3d: %s = 0x%08x\n", ctl, node.extname, value);
 
252
 
 
253
                        if (node.type == MIXT_ENUM)
 
254
                           print_enum_list(i, ctl);
 
255
 
 
256
                        if (node.flags & MIXF_DESCR)
 
257
                           print_description(i, ctl);
 
258
                           
 
259
                }
 
260
 
 
261
                if (!interactive)
 
262
                   ossmix_close_mixer(i);
 
263
        }
 
264
 
 
265
        if (interactive)
 
266
           interactive_mode();
 
267
 
 
268
printf("Disconnecting\n");
 
269
        ossmix_disconnect();
 
270
 
 
271
        exit(EXIT_SUCCESS);
 
272
}