Project

General

Profile

Bug #9732 » 13-module-detect.patch

Gary Mills, 2020-09-14 09:32 PM

View differences:

pulseaudio-13.0/src/modules/module-detect.c Sat Aug 22 20:46:54 2020
19 19
  along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
20 20
***/
21 21

  
22
#if defined(__sun) || defined(__sun__)
23
#define HAVE_OSSV4
24
#endif
25

  
22 26
#ifdef HAVE_CONFIG_H
23 27
#include <config.h>
24 28
#endif
......
54 58
    NULL
55 59
};
56 60

  
61
#ifdef HAVE_OSSV4
62
static int get_device_number(const char *dev) {
63
    const char *p;
64
    char *rp = NULL;
65
    int r, n;
66

  
67
    pa_log_debug ("Finding number for device %s", dev);
68

  
69
    /* Ensure there is a trailing digit */
70
    if ((n = (strlen(dev) - 1)) < 0) {
71
        r = -1;
72
        goto finish;
73
    }
74
    p = dev + n;
75
    if (*p >= '0' && *p <= '9') {
76
        p = dev;
77
    }
78
    else {
79
        if (!(p = rp = pa_readlink(dev))) {
80
            r = -1;
81
            goto finish;
82
        }
83
    }
84

  
85
    if ((n = (strlen(p) - 1)) < 0) {
86
        r = -1;
87
        goto finish;
88
    }
89
    p += n;
90

  
91
    if (p == '/') {
92
        r = 0;
93
        goto finish;
94
    }
95

  
96
    if (*p >= '0' && *p <= '9') {
97
        r = *p - '0';
98
        goto finish;
99
    }
100

  
101
    r = -1;
102

  
103
finish:
104
    pa_xfree(rp);
105
    return r;
106
}
107
#endif
108

  
57 109
#ifdef HAVE_ALSA
58 110

  
59 111
static int detect_alsa(pa_core *c, int just_one) {
......
119 171

  
120 172
#ifdef HAVE_OSS_OUTPUT
121 173
static int detect_oss(pa_core *c, int just_one) {
174
    int n = 0;
175

  
176
#ifdef HAVE_OSSV4
177
#undef HAVE_SOLARIS
178

  
179
    struct stat s;
180
    const char *dev;
181
    int device;
182
    char args[64];
183
    pa_module *m = NULL;
184

  
185
    /* Get the audio device name for Solaris/illumos */
186
    dev = getenv("AUDIODEV");
187
    if (!dev)
188
        dev = "/dev/audio";
189

  
190
    if (stat(dev, &s) < 0) {
191
        if (errno != ENOENT)
192
            pa_log_error("failed to open device %s: %s", dev, pa_cstrerror(errno));
193
        return -1;
194
    }
195

  
196
    if (!S_ISCHR(s.st_mode)) {
197
        pa_log_debug ("Is not a character device %s", dev);
198
        return 0;
199
    }
200

  
201
    if ((device = get_device_number(dev)) < 0) {
202
        pa_log_debug ("Cannot find number for device %s", dev);
203
        return -1;
204
    }
205

  
206
    /* Use the corresponding dsp device name */
207
    pa_snprintf(args, sizeof(args), "device=/dev/dsp%d", device);
208

  
209
    if (pa_module_load(&m, c, "module-oss", args) < 0)
210
        return 0;
211

  
212
    n++;
213

  
214
#else /* HAVE_OSSV4 */
215

  
122 216
    FILE *f;
123
    int n = 0, b = 0;
217
    int b = 0;
124 218

  
125 219
    if (!(f = pa_fopen_cloexec("/dev/sndstat", "r")) &&
126 220
        !(f = pa_fopen_cloexec("/proc/sndstat", "r")) &&
......
174 268
    }
175 269

  
176 270
    fclose(f);
271

  
272
#endif /* HAVE_OSSV4 */
273

  
177 274
    return n;
178 275
}
179 276
#endif
(9-9/11)