50 |
unsigned int queue_hi, queue_lo, queue_pending; |
unsigned int queue_hi, queue_lo, queue_pending; |
51 |
struct audio_packet packet_queue[MAX_QUEUE]; |
struct audio_packet packet_queue[MAX_QUEUE]; |
52 |
|
|
53 |
|
static uint8 packet_opcode; |
54 |
|
static struct stream packet; |
55 |
|
|
56 |
void (*wave_out_play) (void); |
void (*wave_out_play) (void); |
57 |
|
|
58 |
static void rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index); |
static void rdpsnd_queue_write(STREAM s, uint16 tick, uint8 index); |
98 |
static void |
static void |
99 |
rdpsnd_process_negotiate(STREAM in) |
rdpsnd_process_negotiate(STREAM in) |
100 |
{ |
{ |
101 |
unsigned int in_format_count, i; |
uint16 in_format_count, i; |
102 |
|
uint8 pad; |
103 |
|
uint16 version; |
104 |
WAVEFORMATEX *format; |
WAVEFORMATEX *format; |
105 |
STREAM out; |
STREAM out; |
106 |
BOOL device_available = False; |
BOOL device_available = False; |
107 |
int readcnt; |
int readcnt; |
108 |
int discardcnt; |
int discardcnt; |
109 |
|
|
110 |
in_uint8s(in, 14); /* flags, volume, pitch, UDP port */ |
in_uint8s(in, 14); /* initial bytes not valid from server */ |
111 |
in_uint16_le(in, in_format_count); |
in_uint16_le(in, in_format_count); |
112 |
in_uint8s(in, 4); /* pad, status, pad */ |
in_uint8(in, pad); |
113 |
|
in_uint16_le(in, version); |
114 |
|
in_uint8s(in, 1); /* padding */ |
115 |
|
|
116 |
if (current_driver->wave_out_open()) |
if (current_driver->wave_out_open()) |
117 |
{ |
{ |
162 |
out_uint16(out, 0); /* UDP port */ |
out_uint16(out, 0); /* UDP port */ |
163 |
|
|
164 |
out_uint16_le(out, format_count); |
out_uint16_le(out, format_count); |
165 |
out_uint8(out, 0x95); /* pad? */ |
out_uint8(out, 0); /* padding */ |
166 |
out_uint16_le(out, 2); /* status */ |
out_uint16_le(out, 2); /* version */ |
167 |
out_uint8(out, 0x77); /* pad? */ |
out_uint8(out, 0); /* padding */ |
168 |
|
|
169 |
for (i = 0; i < format_count; i++) |
for (i = 0; i < format_count; i++) |
170 |
{ |
{ |
198 |
} |
} |
199 |
|
|
200 |
static void |
static void |
201 |
rdpsnd_process(STREAM s) |
rdpsnd_process_packet(uint8 opcode, STREAM s) |
202 |
{ |
{ |
203 |
uint8 type; |
uint16 vol_left, vol_right; |
|
uint16 datalen; |
|
|
uint32 volume; |
|
204 |
static uint16 tick, format; |
static uint16 tick, format; |
205 |
static uint8 packet_index; |
static uint8 packet_index; |
|
static BOOL awaiting_data_packet; |
|
|
static unsigned char missing_bytes[4] = { 0, 0, 0, 0 }; |
|
206 |
|
|
207 |
#ifdef RDPSND_DEBUG |
#ifdef RDPSND_DEBUG |
208 |
printf("RDPSND recv:\n"); |
printf("RDPSND recv:\n"); |
209 |
hexdump(s->p, s->end - s->p); |
hexdump(s->p, s->end - s->p); |
210 |
#endif |
#endif |
211 |
|
|
212 |
if (awaiting_data_packet) |
switch (opcode) |
213 |
{ |
{ |
214 |
if (format >= MAX_FORMATS) |
case RDPSND_WRITE: |
215 |
{ |
in_uint16_le(s, tick); |
216 |
error("RDPSND: Invalid format index\n"); |
in_uint16_le(s, format); |
217 |
return; |
in_uint8(s, packet_index); |
218 |
} |
in_uint8s(s, 3); |
219 |
|
|
220 |
if (!device_open || (format != current_format)) |
if (format >= MAX_FORMATS) |
|
{ |
|
|
if (!device_open && !current_driver->wave_out_open()) |
|
221 |
{ |
{ |
222 |
rdpsnd_send_completion(tick, packet_index); |
error("RDPSND: Invalid format index\n"); |
223 |
return; |
break; |
224 |
} |
} |
225 |
if (!current_driver->wave_out_set_format(&formats[format])) |
|
226 |
|
if (!device_open || (format != current_format)) |
227 |
{ |
{ |
228 |
rdpsnd_send_completion(tick, packet_index); |
if (!device_open && !current_driver->wave_out_open()) |
229 |
current_driver->wave_out_close(); |
{ |
230 |
device_open = False; |
rdpsnd_send_completion(tick, packet_index); |
231 |
return; |
break; |
232 |
|
} |
233 |
|
if (!current_driver->wave_out_set_format(&formats[format])) |
234 |
|
{ |
235 |
|
rdpsnd_send_completion(tick, packet_index); |
236 |
|
current_driver->wave_out_close(); |
237 |
|
device_open = False; |
238 |
|
break; |
239 |
|
} |
240 |
|
device_open = True; |
241 |
|
current_format = format; |
242 |
} |
} |
|
device_open = True; |
|
|
current_format = format; |
|
|
} |
|
|
|
|
|
/* Insert the 4 missing bytes retrieved from last RDPSND_WRITE */ |
|
|
memcpy(s->data, missing_bytes, 4); |
|
|
|
|
|
rdpsnd_queue_write(rdpsnd_dsp_process |
|
|
(s, current_driver, &formats[current_format]), tick, |
|
|
packet_index); |
|
|
awaiting_data_packet = False; |
|
|
return; |
|
|
} |
|
|
|
|
|
in_uint8(s, type); |
|
|
in_uint8s(s, 1); /* unknown? */ |
|
|
in_uint16_le(s, datalen); |
|
243 |
|
|
244 |
switch (type) |
rdpsnd_queue_write(rdpsnd_dsp_process |
245 |
{ |
(s->p, s->end - s->p, current_driver, |
246 |
case RDPSND_WRITE: |
&formats[current_format]), tick, packet_index); |
247 |
in_uint16_le(s, tick); |
return; |
|
in_uint16_le(s, format); |
|
|
in_uint8(s, packet_index); |
|
|
/* Here are our lost bytes, but why? */ |
|
|
memcpy(missing_bytes, s->end - 4, 4); |
|
|
awaiting_data_packet = True; |
|
248 |
break; |
break; |
249 |
case RDPSND_CLOSE: |
case RDPSND_CLOSE: |
250 |
current_driver->wave_out_close(); |
current_driver->wave_out_close(); |
257 |
rdpsnd_process_ping(s); |
rdpsnd_process_ping(s); |
258 |
break; |
break; |
259 |
case RDPSND_SET_VOLUME: |
case RDPSND_SET_VOLUME: |
260 |
in_uint32(s, volume); |
in_uint16_le(s, vol_left); |
261 |
|
in_uint16_le(s, vol_right); |
262 |
if (device_open) |
if (device_open) |
263 |
{ |
current_driver->wave_out_volume(vol_left, vol_right); |
|
current_driver->wave_out_volume((volume & 0xffff), |
|
|
(volume & 0xffff0000) >> 16); |
|
|
} |
|
264 |
break; |
break; |
265 |
default: |
default: |
266 |
unimpl("RDPSND packet type %d\n", type); |
unimpl("RDPSND packet type %x\n", opcode); |
267 |
break; |
break; |
268 |
} |
} |
269 |
} |
} |
270 |
|
|
271 |
|
static void |
272 |
|
rdpsnd_process(STREAM s) |
273 |
|
{ |
274 |
|
uint16 len; |
275 |
|
|
276 |
|
while (!s_check_end(s)) |
277 |
|
{ |
278 |
|
/* New packet */ |
279 |
|
if (packet.size == 0) |
280 |
|
{ |
281 |
|
if ((s->end - s->p) < 4) |
282 |
|
{ |
283 |
|
error("RDPSND: Split at packet header. Things will go south from here...\n"); |
284 |
|
return; |
285 |
|
} |
286 |
|
in_uint8(s, packet_opcode); |
287 |
|
in_uint8s(s, 1); /* Padding */ |
288 |
|
in_uint16_le(s, len); |
289 |
|
|
290 |
|
packet.p = packet.data; |
291 |
|
packet.end = packet.data + len; |
292 |
|
packet.size = len; |
293 |
|
} |
294 |
|
else |
295 |
|
{ |
296 |
|
len = MIN(s->end - s->p, packet.end - packet.p); |
297 |
|
|
298 |
|
/* Microsoft's server is so broken it's not even funny... */ |
299 |
|
if (packet_opcode == RDPSND_WRITE) |
300 |
|
{ |
301 |
|
if ((packet.p - packet.data) < 12) |
302 |
|
len = MIN(len, 12 - (packet.p - packet.data)); |
303 |
|
else if ((packet.p - packet.data) == 12) |
304 |
|
{ |
305 |
|
in_uint8s(s, 4); |
306 |
|
len -= 4; |
307 |
|
} |
308 |
|
} |
309 |
|
|
310 |
|
in_uint8a(s, packet.p, len); |
311 |
|
packet.p += len; |
312 |
|
} |
313 |
|
|
314 |
|
/* Packet fully assembled */ |
315 |
|
if (packet.p == packet.end) |
316 |
|
{ |
317 |
|
packet.p = packet.data; |
318 |
|
rdpsnd_process_packet(packet_opcode, &packet); |
319 |
|
packet.size = 0; |
320 |
|
} |
321 |
|
} |
322 |
|
} |
323 |
|
|
324 |
static BOOL |
static BOOL |
325 |
rdpsnd_auto_open(void) |
rdpsnd_auto_open(void) |
326 |
{ |
{ |
396 |
|
|
397 |
drivers = NULL; |
drivers = NULL; |
398 |
|
|
399 |
|
packet.data = xmalloc(65536); |
400 |
|
packet.p = packet.end = packet.data; |
401 |
|
packet.size = 0; |
402 |
|
|
403 |
rdpsnd_channel = |
rdpsnd_channel = |
404 |
channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP, |
channel_register("rdpsnd", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP, |
405 |
rdpsnd_process); |
rdpsnd_process); |