2
rdesktop: A Remote Desktop Protocol client.
3
Sound Channel Process Functions
4
Copyright (C) Matthew Chapman 2003
5
Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
#define RDPSND_CLOSE 1
25
#define RDPSND_WRITE 2
26
#define RDPSND_SET_VOLUME 3
27
#define RDPSND_UNKNOWN4 4
28
#define RDPSND_COMPLETION 5
29
#define RDPSND_UNKNOWN6 6
30
#define RDPSND_NEGOTIATE 7
32
#define MAX_FORMATS 10
34
static VCHANNEL *rdpsnd_channel;
36
static BOOL device_open;
37
static WAVEFORMATEX formats[MAX_FORMATS];
38
static unsigned int format_count;
39
static unsigned int current_format;
42
rdpsnd_init_packet(uint16 type, uint16 size)
46
s = channel_init(rdpsnd_channel, size + 4);
47
out_uint16_le(s, type);
48
out_uint16_le(s, size);
56
printf("RDPSND send:\n");
57
hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8);
60
channel_send(s, rdpsnd_channel);
64
rdpsnd_send_completion(uint16 tick, uint8 packet_index)
68
s = rdpsnd_init_packet(RDPSND_COMPLETION, 4);
69
out_uint16_le(s, tick + 50);
70
out_uint8(s, packet_index);
77
rdpsnd_process_negotiate(STREAM in)
79
unsigned int in_format_count, i;
82
BOOL device_available = False;
86
in_uint8s(in, 14); /* flags, volume, pitch, UDP port */
87
in_uint16_le(in, in_format_count);
88
in_uint8s(in, 4); /* pad, status, pad */
93
device_available = True;
97
if (s_check_rem(in, 18 * in_format_count))
99
for (i = 0; i < in_format_count; i++)
101
format = &formats[format_count];
102
in_uint16_le(in, format->wFormatTag);
103
in_uint16_le(in, format->nChannels);
104
in_uint32_le(in, format->nSamplesPerSec);
105
in_uint32_le(in, format->nAvgBytesPerSec);
106
in_uint16_le(in, format->nBlockAlign);
107
in_uint16_le(in, format->wBitsPerSample);
108
in_uint16_le(in, format->cbSize);
110
/* read in the buffer of unknown use */
111
readcnt = format->cbSize;
113
if (format->cbSize > MAX_CBSIZE)
115
fprintf(stderr, "cbSize too large for buffer: %d\n",
117
readcnt = MAX_CBSIZE;
118
discardcnt = format->cbSize - MAX_CBSIZE;
120
in_uint8a(in, format->cb, readcnt);
121
in_uint8s(in, discardcnt);
123
if (device_available && wave_out_format_supported(format))
126
if (format_count == MAX_FORMATS)
132
out = rdpsnd_init_packet(RDPSND_NEGOTIATE | 0x200, 20 + 18 * format_count);
133
out_uint32_le(out, 3); /* flags */
134
out_uint32(out, 0xffffffff); /* volume */
135
out_uint32(out, 0); /* pitch */
136
out_uint16(out, 0); /* UDP port */
138
out_uint16_le(out, format_count);
139
out_uint8(out, 0x95); /* pad? */
140
out_uint16_le(out, 2); /* status */
141
out_uint8(out, 0x77); /* pad? */
143
for (i = 0; i < format_count; i++)
145
format = &formats[i];
146
out_uint16_le(out, format->wFormatTag);
147
out_uint16_le(out, format->nChannels);
148
out_uint32_le(out, format->nSamplesPerSec);
149
out_uint32_le(out, format->nAvgBytesPerSec);
150
out_uint16_le(out, format->nBlockAlign);
151
out_uint16_le(out, format->wBitsPerSample);
152
out_uint16(out, 0); /* cbSize */
160
rdpsnd_process_unknown6(STREAM in)
162
uint16 unknown1, unknown2;
165
/* in_uint8s(in, 4); unknown */
166
in_uint16_le(in, unknown1);
167
in_uint16_le(in, unknown2);
169
out = rdpsnd_init_packet(RDPSND_UNKNOWN6 | 0x2300, 4);
170
out_uint16_le(out, unknown1);
171
out_uint16_le(out, unknown2);
177
rdpsnd_process(STREAM s)
182
static uint16 tick, format;
183
static uint8 packet_index;
184
static BOOL awaiting_data_packet;
187
printf("RDPSND recv:\n");
188
hexdump(s->p, s->end - s->p);
191
if (awaiting_data_packet)
193
if (format >= MAX_FORMATS)
195
error("RDPSND: Invalid format index\n");
199
if (!device_open || (format != current_format))
201
if (!device_open && !wave_out_open())
203
rdpsnd_send_completion(tick, packet_index);
206
if (!wave_out_set_format(&formats[format]))
208
rdpsnd_send_completion(tick, packet_index);
214
current_format = format;
217
wave_out_write(s, tick, packet_index);
218
awaiting_data_packet = False;
223
in_uint8s(s, 1); /* unknown? */
224
in_uint16_le(s, datalen);
229
in_uint16_le(s, tick);
230
in_uint16_le(s, format);
231
in_uint8(s, packet_index);
232
awaiting_data_packet = True;
238
case RDPSND_NEGOTIATE:
239
rdpsnd_process_negotiate(s);
241
case RDPSND_UNKNOWN6:
242
rdpsnd_process_unknown6(s);
244
case RDPSND_SET_VOLUME:
245
in_uint32(s, volume);
248
wave_out_volume((volume & 0xffff), (volume & 0xffff0000) >> 16);
252
unimpl("RDPSND packet type %d\n", type);
261
channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,
263
return (rdpsnd_channel != NULL);