~ubuntu-branches/debian/stretch/rdesktop/stretch

« back to all changes in this revision

Viewing changes to rdpsnd_oss.c

  • Committer: Bazaar Package Importer
  • Author(s): Tomas Fasth
  • Date: 2005-05-24 13:31:34 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050524133134-6hn24gprfmo91sfv
Tags: 1.4.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
 
1
/*
2
2
   rdesktop: A Remote Desktop Protocol client.
3
3
   Sound Channel Process Functions - Open Sound System
4
4
   Copyright (C) Matthew Chapman 2003
33
33
BOOL g_dsp_busy = False;
34
34
static int g_snd_rate;
35
35
static short g_samplewidth;
 
36
static BOOL g_driver_broken = False;
36
37
 
37
38
static struct audio_packet
38
39
{
45
46
BOOL
46
47
wave_out_open(void)
47
48
{
48
 
        char *dsp_dev = "/dev/dsp";
 
49
        char *dsp_dev = getenv("AUDIODEV");
 
50
 
 
51
        if (dsp_dev == NULL)
 
52
        {
 
53
                dsp_dev = strdup("/dev/dsp");
 
54
        }
49
55
 
50
56
        if ((g_dsp_fd = open(dsp_dev, O_WRONLY | O_NONBLOCK)) == -1)
51
57
        {
80
86
BOOL
81
87
wave_out_set_format(WAVEFORMATEX * pwfx)
82
88
{
83
 
        int channels, format;
 
89
        int stereo, format, fragments;
84
90
 
85
91
        ioctl(g_dsp_fd, SNDCTL_DSP_RESET, NULL);
86
92
        ioctl(g_dsp_fd, SNDCTL_DSP_SYNC, NULL);
99
105
                return False;
100
106
        }
101
107
 
102
 
        channels = pwfx->nChannels;
103
 
        if (ioctl(g_dsp_fd, SNDCTL_DSP_CHANNELS, &channels) == -1)
 
108
        if (pwfx->nChannels == 2)
 
109
        {
 
110
                stereo = 1;
 
111
                g_samplewidth *= 2;
 
112
        }
 
113
        else
 
114
        {
 
115
                stereo = 0;
 
116
        }
 
117
 
 
118
        if (ioctl(g_dsp_fd, SNDCTL_DSP_STEREO, &stereo) == -1)
104
119
        {
105
120
                perror("SNDCTL_DSP_CHANNELS");
106
121
                close(g_dsp_fd);
107
122
                return False;
108
123
        }
109
124
 
110
 
        if (channels == 2)
111
 
        {
112
 
                g_samplewidth *= 2;
113
 
        }
114
 
 
115
125
        g_snd_rate = pwfx->nSamplesPerSec;
116
126
        if (ioctl(g_dsp_fd, SNDCTL_DSP_SPEED, &g_snd_rate) == -1)
117
127
        {
120
130
                return False;
121
131
        }
122
132
 
 
133
        /* try to get 7 fragments of 2^12 bytes size */
 
134
        fragments = (7 << 16) + 12;
 
135
        ioctl(g_dsp_fd, SNDCTL_DSP_SETFRAGMENT, &fragments);
 
136
 
 
137
        if (!g_driver_broken)
 
138
        {
 
139
                audio_buf_info info;
 
140
 
 
141
                memset(&info, 0, sizeof(info));
 
142
                if (ioctl(g_dsp_fd, SNDCTL_DSP_GETOSPACE, &info) == -1)
 
143
                {
 
144
                        perror("SNDCTL_DSP_GETOSPACE");
 
145
                        close(g_dsp_fd);
 
146
                        return False;
 
147
                }
 
148
 
 
149
                if (info.fragments == 0 || info.fragstotal == 0 || info.fragsize == 0)
 
150
                {
 
151
                        fprintf(stderr,
 
152
                                "Broken OSS-driver detected: fragments: %d, fragstotal: %d, fragsize: %d\n",
 
153
                                info.fragments, info.fragstotal, info.fragsize);
 
154
                        g_driver_broken = True;
 
155
                }
 
156
        }
 
157
 
123
158
        return True;
124
159
}
125
160
 
178
213
        packet->s.p += 4;
179
214
 
180
215
        /* we steal the data buffer from s, give it a new one */
181
 
        s->data = malloc(s->size);
 
216
        s->data = (uint8 *) malloc(s->size);
182
217
 
183
218
        if (!g_dsp_busy)
184
219
                wave_out_play();
194
229
        static long startedat_s;
195
230
        static BOOL started = False;
196
231
        struct timeval tv;
 
232
        audio_buf_info info;
197
233
 
198
234
        while (1)
199
235
        {
214
250
                        started = True;
215
251
                }
216
252
 
217
 
                len = write(g_dsp_fd, out->p, out->end - out->p);
 
253
                len = out->end - out->p;
 
254
 
 
255
                if (!g_driver_broken)
 
256
                {
 
257
                        memset(&info, 0, sizeof(info));
 
258
                        if (ioctl(g_dsp_fd, SNDCTL_DSP_GETOSPACE, &info) == -1)
 
259
                        {
 
260
                                perror("SNDCTL_DSP_GETOSPACE");
 
261
                                return;
 
262
                        }
 
263
 
 
264
                        if (info.fragments == 0)
 
265
                        {
 
266
                                g_dsp_busy = 1;
 
267
                                return;
 
268
                        }
 
269
 
 
270
                        if (info.fragments * info.fragsize < len
 
271
                            && info.fragments * info.fragsize > 0)
 
272
                        {
 
273
                                len = info.fragments * info.fragsize;
 
274
                        }
 
275
                }
 
276
 
 
277
 
 
278
                len = write(g_dsp_fd, out->p, len);
218
279
                if (len == -1)
219
280
                {
220
281
                        if (errno != EWOULDBLOCK)
233
294
                        duration = (out->size * (1000000 / (g_samplewidth * g_snd_rate)));
234
295
                        elapsed = (tv.tv_sec - startedat_s) * 1000000 + (tv.tv_usec - startedat_us);
235
296
 
236
 
                        if (elapsed >= (duration * 7) / 10)
 
297
                        if (elapsed >= (duration * 85) / 100)
237
298
                        {
238
299
                                rdpsnd_send_completion(packet->tick, packet->index);
239
300
                                free(out->data);