Preliminary sound support (PCM only).

Based on code from GuoJunBo <guojunbo@ict.ac.cn>


git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@473 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Matt Chapman 2003-09-30 09:11:08 +00:00
parent 0e61021203
commit d3e6c1a157
8 changed files with 320 additions and 55 deletions

View File

@ -14,7 +14,7 @@ datadir = $(prefix)/share/rdesktop
KEYMAP_PATH = $(datadir)/keymaps/
RDPOBJ = tcp.o iso.o mcs.o secure.o licence.o rdp.o orders.o bitmap.o cache.o rdp5.o channels.o rdpsnd.o rdpdr.o serial.o printer.o
RDPOBJ = tcp.o iso.o mcs.o secure.o licence.o rdp.o orders.o bitmap.o cache.o rdp5.o channels.o rdpdr.o serial.o printer.o
X11OBJ = rdesktop.o xwin.o xkeymap.o ewmhints.o xclip.o cliprdr.o
VNCOBJ = vnc/rdp2vnc.o vnc/vnc.o vnc/xkeymap.o vnc/x11stubs.o
CRYPTOBJ = crypto/rc4_enc.o crypto/rc4_skey.o crypto/md5_dgst.o crypto/sha1dgst.o crypto/bn_exp.o crypto/bn_mul.o crypto/bn_div.o crypto/bn_sqr.o crypto/bn_add.o crypto/bn_shift.o crypto/bn_asm.o crypto/bn_ctx.o crypto/bn_lib.o
@ -23,11 +23,11 @@ include Makeconf # configure-generated
all: $(TARGETS)
rdesktop: $(X11OBJ) $(RDPOBJ) $(CRYPTOBJ)
$(CC) $(CFLAGS) -o rdesktop $(X11OBJ) $(RDPOBJ) $(CRYPTOBJ) $(LDFLAGS) -lX11
rdesktop: $(X11OBJ) $(SOUNDOBJ) $(RDPOBJ) $(CRYPTOBJ)
$(CC) $(CFLAGS) -o rdesktop $(X11OBJ) $(SOUNDOBJ) $(RDPOBJ) $(CRYPTOBJ) $(LDFLAGS) -lX11
rdp2vnc: $(VNCOBJ) $(RDPOBJ) $(CRYPTOBJ)
$(CCLD) $(CFLAGS) -o rdp2vnc $(VNCOBJ) $(RDPOBJ) $(CRYPTOBJ) $(LDFLAGS) $(LDVNC)
rdp2vnc: $(VNCOBJ) $(SOUNDOBJ) $(RDPOBJ) $(CRYPTOBJ)
$(CCLD) $(CFLAGS) -o rdp2vnc $(VNCOBJ) $(SOUNDOBJ) $(RDPOBJ) $(CRYPTOBJ) $(LDFLAGS) $(LDVNC)
vnc/rdp2vnc.o: rdesktop.c
$(CC) $(CFLAGS) $(VNCINC) -DRDP2VNC -o vnc/rdp2vnc.o -c rdesktop.c

13
configure vendored
View File

@ -235,6 +235,19 @@ if [ ! -c /dev/random -a ! -c /dev/urandom ]; then
fi
fi
# Check for OSS sound support
if [ -f /usr/include/sys/soundcard.h ]; then
echo Sound support enabled: Open Sound System
echo
echo "SOUNDOBJ = rdpsnd.o rdpsnd_oss.o" >>Makeconf
cflags="$cflags -DWITH_RDPSND"
else
echo "WARNING: sound support disabled (no /usr/include/sys/soundcard.h)"
echo "Only Open Sound System audio is supported at present"
echo
fi
# Platform-specific options

View File

@ -292,6 +292,9 @@ enum RDP_INPUT_DEVICE
#define CF_GDIOBJFIRST 768
#define CF_GDIOBJLAST 1023
/* Sound format constants */
#define WAVE_FORMAT_PCM 1
/* Virtual channel options */
#define CHANNEL_OPTION_INITIALIZED 0x80000000
#define CHANNEL_OPTION_ENCRYPT_RDP 0x40000000

87
proto.h
View File

@ -1,33 +1,30 @@
/* bitmap.c */
BOOL bitmap_decompress(unsigned char *output, int width, int height, unsigned char *input, int size,
int Bpp);
BOOL bitmap_decompress(unsigned char *output, int width, int height, unsigned char *input, int size, int Bpp);
/* cache.c */
HBITMAP cache_get_bitmap(uint8 cache_id, uint16 cache_idx);
void cache_put_bitmap(uint8 cache_id, uint16 cache_idx, HBITMAP bitmap);
FONTGLYPH *cache_get_font(uint8 font, uint16 character);
void cache_put_font(uint8 font, uint16 character, uint16 offset, uint16 baseline, uint16 width,
uint16 height, HGLYPH pixmap);
void cache_put_font(uint8 font, uint16 character, uint16 offset, uint16 baseline, uint16 width, uint16 height, HGLYPH pixmap);
DATABLOB *cache_get_text(uint8 cache_id);
void cache_put_text(uint8 cache_id, void *data, int length);
uint8 *cache_get_desktop(uint32 offset, int cx, int cy, int bytes_per_pixel);
void cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel,
uint8 * data);
void cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int bytes_per_pixel, uint8 *data);
HCURSOR cache_get_cursor(uint16 cache_idx);
void cache_put_cursor(uint16 cache_idx, HCURSOR cursor);
/* channels.c */
VCHANNEL *channel_register(char *name, uint32 flags, void (*callback) (STREAM));
STREAM channel_init(VCHANNEL * channel, uint32 length);
void channel_send(STREAM s, VCHANNEL * channel);
VCHANNEL *channel_register(char *name, uint32 flags, void (*callback)(STREAM));
STREAM channel_init(VCHANNEL *channel, uint32 length);
void channel_send(STREAM s, VCHANNEL *channel);
void channel_process(STREAM s, uint16 mcs_channel);
/* cliprdr.c */
void cliprdr_send_text_format_announce(void);
void cliprdr_send_blah_format_announce(void);
void cliprdr_send_native_format_announce(uint8 * data, uint32 length);
void cliprdr_send_native_format_announce(uint8 *data, uint32 length);
void cliprdr_send_data_request(uint32 format);
void cliprdr_send_data(uint8 * data, uint32 length);
void cliprdr_send_data(uint8 *data, uint32 length);
BOOL cliprdr_init(void);
/* ewmhints.c */
int get_current_workarea(uint32 * x, uint32 * y, uint32 * width, uint32 * height);
int get_current_workarea(uint32 *x, uint32 *y, uint32 *width, uint32 *height);
/* iso.c */
STREAM iso_init(int length);
void iso_send(STREAM s);
@ -40,7 +37,7 @@ void licence_process(STREAM s);
STREAM mcs_init(int length);
void mcs_send_to_channel(STREAM s, uint16 channel);
void mcs_send(STREAM s);
STREAM mcs_recv(uint16 * channel);
STREAM mcs_recv(uint16 *channel);
BOOL mcs_connect(char *server, STREAM mcs_data, char *username);
void mcs_disconnect(void);
/* orders.c */
@ -49,7 +46,7 @@ void reset_order_state(void);
/* printer.c */
/* rdesktop.c */
int main(int argc, char *argv[]);
void generate_random(uint8 * random);
void generate_random(uint8 *random);
void *xmalloc(int size);
void *xrealloc(void *oldmem, int size);
void xfree(void *mem);
@ -59,37 +56,45 @@ void unimpl(char *format, ...);
void hexdump(unsigned char *p, int len);
int load_licence(unsigned char **data);
void save_licence(unsigned char *data, int length);
/* rdp5.c */
void rdp5_process(STREAM s, BOOL encryption);
/* rdp.c */
void rdp_out_unistr(STREAM s, char *string, int len);
void rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1,
uint16 param2);
void rdp_send_input(uint32 time, uint16 message_type, uint16 device_flags, uint16 param1, uint16 param2);
void process_null_system_pointer_pdu(STREAM s);
void process_colour_pointer_pdu(STREAM s);
void process_cached_pointer_pdu(STREAM s);
void process_bitmap_updates(STREAM s);
void process_palette(STREAM s);
BOOL rdp_main_loop(void);
BOOL rdp_connect(char *server, uint32 flags, char *domain, char *password, char *command,
char *directory);
BOOL rdp_connect(char *server, uint32 flags, char *domain, char *password, char *command, char *directory);
void rdp_disconnect(void);
/* rdp5.c */
void rdp5_process(STREAM s, BOOL encryption);
/* rdpdr.c */
void rdpdr_send_connect(void);
void rdpdr_send_name(void);
void rdpdr_send_available(void);
void rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer,
uint32 length);
void rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 *buffer, uint32 length);
BOOL rdpdr_init(void);
/* rdpsnd.c */
STREAM rdpsnd_init_packet(uint16 type, uint16 size);
void rdpsnd_send(STREAM s);
void rdpsnd_send_completion(uint16 tick, uint8 packet_index);
void rdpsnd_process_negotiate(STREAM in);
void rdpsnd_process(STREAM s);
BOOL rdpsnd_init(void);
/* rdpsnd_oss.c */
BOOL wave_out_open(void);
void wave_out_close(void);
BOOL wave_out_format_supported(WAVEFORMATEX *pwfx);
BOOL wave_out_set_format(WAVEFORMATEX *pwfx);
void wave_out_write(STREAM s, uint16 tick, uint8 index);
void wave_out_play(void);
/* secure.c */
void sec_hash_48(uint8 * out, uint8 * in, uint8 * salt1, uint8 * salt2, uint8 salt);
void sec_hash_16(uint8 * out, uint8 * in, uint8 * salt1, uint8 * salt2);
void buf_out_uint32(uint8 * buffer, uint32 value);
void sec_sign(uint8 * signature, int siglen, uint8 * session_key, int keylen, uint8 * data,
int datalen);
void sec_decrypt(uint8 * data, int length);
void sec_hash_48(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2, uint8 salt);
void sec_hash_16(uint8 *out, uint8 *in, uint8 *salt1, uint8 *salt2);
void buf_out_uint32(uint8 *buffer, uint32 value);
void sec_sign(uint8 *signature, int siglen, uint8 *session_key, int keylen, uint8 *data, int datalen);
void sec_decrypt(uint8 *data, int length);
STREAM sec_init(uint32 flags, int maxlen);
void sec_send_to_channel(STREAM s, uint32 flags, uint16 channel);
void sec_send(STREAM s, uint32 flags);
@ -130,34 +135,28 @@ void ui_destroy_window(void);
void xwin_toggle_fullscreen(void);
int ui_select(int rdp_socket);
void ui_move_pointer(int x, int y);
HBITMAP ui_create_bitmap(int width, int height, uint8 * data);
void ui_paint_bitmap(int x, int y, int cx, int cy, int width, int height, uint8 * data);
HBITMAP ui_create_bitmap(int width, int height, uint8 *data);
void ui_paint_bitmap(int x, int y, int cx, int cy, int width, int height, uint8 *data);
void ui_destroy_bitmap(HBITMAP bmp);
HGLYPH ui_create_glyph(int width, int height, uint8 * data);
HGLYPH ui_create_glyph(int width, int height, uint8 *data);
void ui_destroy_glyph(HGLYPH glyph);
HCURSOR ui_create_cursor(unsigned int x, unsigned int y, int width, int height, uint8 * andmask,
uint8 * xormask);
HCURSOR ui_create_cursor(unsigned int x, unsigned int y, int width, int height, uint8 *andmask, uint8 *xormask);
void ui_set_cursor(HCURSOR cursor);
void ui_destroy_cursor(HCURSOR cursor);
HCOLOURMAP ui_create_colourmap(COLOURMAP * colours);
HCOLOURMAP ui_create_colourmap(COLOURMAP *colours);
void ui_destroy_colourmap(HCOLOURMAP map);
void ui_set_colourmap(HCOLOURMAP map);
void ui_set_clip(int x, int y, int cx, int cy);
void ui_reset_clip(void);
void ui_bell(void);
void ui_destblt(uint8 opcode, int x, int y, int cx, int cy);
void ui_patblt(uint8 opcode, int x, int y, int cx, int cy, BRUSH * brush, int bgcolour,
int fgcolour);
void ui_patblt(uint8 opcode, int x, int y, int cx, int cy, BRUSH *brush, int bgcolour, int fgcolour);
void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy, int srcx, int srcy);
void ui_memblt(uint8 opcode, int x, int y, int cx, int cy, HBITMAP src, int srcx, int srcy);
void ui_triblt(uint8 opcode, int x, int y, int cx, int cy, HBITMAP src, int srcx, int srcy,
BRUSH * brush, int bgcolour, int fgcolour);
void ui_line(uint8 opcode, int startx, int starty, int endx, int endy, PEN * pen);
void ui_triblt(uint8 opcode, int x, int y, int cx, int cy, HBITMAP src, int srcx, int srcy, BRUSH *brush, int bgcolour, int fgcolour);
void ui_line(uint8 opcode, int startx, int starty, int endx, int endy, PEN *pen);
void ui_rect(int x, int y, int cx, int cy, int colour);
void ui_draw_glyph(int mixmode, int x, int y, int cx, int cy, HGLYPH glyph, int srcx, int srcy,
int bgcolour, int fgcolour);
void ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y, int clipx, int clipy,
int clipcx, int clipcy, int boxx, int boxy, int boxcx, int boxcy, int bgcolour,
int fgcolour, uint8 * text, uint8 length);
void ui_draw_glyph(int mixmode, int x, int y, int cx, int cy, HGLYPH glyph, int srcx, int srcy, int bgcolour, int fgcolour);
void ui_draw_text(uint8 font, uint8 flags, int mixmode, int x, int y, int clipx, int clipy, int clipcx, int clipcy, int boxx, int boxy, int boxcx, int boxcy, int bgcolour, int fgcolour, uint8 *text, uint8 length);
void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy);
void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy);

View File

@ -425,7 +425,9 @@ main(int argc, char *argv[])
if (!ui_init())
return 1;
/* rdpsnd_init(); */
#ifdef WITH_RDPSND
rdpsnd_init();
#endif
/* rdpdr_init(); */
if (!rdp_connect(server, flags, domain, password, shell, directory))

223
rdpsnd.c
View File

@ -1,12 +1,229 @@
/*
rdesktop: A Remote Desktop Protocol client.
Sound Channel Process Functions
Copyright (C) Matthew Chapman 2003
Copyright (C) GuoJunBo guojunbo@ict.ac.cn 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "rdesktop.h"
#define RDPSND_CLOSE 1
#define RDPSND_WRITE 2
#define RDPSND_SET_VOLUME 3
#define RDPSND_UNKNOWN4 4
#define RDPSND_COMPLETION 5
#define RDPSND_UNKNOWN6 6
#define RDPSND_NEGOTIATE 7
#define MAX_FORMATS 10
static VCHANNEL *rdpsnd_channel;
static void
static BOOL device_open;
static WAVEFORMATEX formats[MAX_FORMATS];
static unsigned int format_count;
static unsigned int current_format;
STREAM
rdpsnd_init_packet(uint16 type, uint16 size)
{
STREAM s;
s = channel_init(rdpsnd_channel, size+4);
out_uint16_le(s, type);
out_uint16_le(s, size);
return s;
}
void
rdpsnd_send(STREAM s)
{
#ifdef RDPSND_DEBUG
printf("RDPSND send:\n");
hexdump(s->channel_hdr+8, s->end-s->channel_hdr-8);
#endif
channel_send(s, rdpsnd_channel);
}
void rdpsnd_send_completion(uint16 tick, uint8 packet_index)
{
STREAM s;
s = rdpsnd_init_packet(RDPSND_COMPLETION, 4);
out_uint16_le(s, tick+50);
out_uint8(s, packet_index);
out_uint8(s, 0);
s_mark_end(s);
rdpsnd_send(s);
}
void
rdpsnd_process_negotiate(STREAM in)
{
unsigned int in_format_count, i;
WAVEFORMATEX *format;
STREAM out;
in_uint8s(in, 14); /* flags, volume, pitch, UDP port */
in_uint16_le(in, in_format_count);
in_uint8s(in, 4); /* pad, status, pad */
format_count = 0;
if (s_check_rem(in, 18*in_format_count))
{
for (i = 0; i < in_format_count; i++)
{
format = &formats[format_count];
in_uint16_le(in, format->wFormatTag);
in_uint16_le(in, format->nChannels);
in_uint32_le(in, format->nSamplesPerSec);
in_uint32_le(in, format->nAvgBytesPerSec);
in_uint16_le(in, format->nBlockAlign);
in_uint16_le(in, format->wBitsPerSample);
in_uint16_le(in, format->cbSize);
if (wave_out_format_supported(format))
{
format_count++;
if (format_count == MAX_FORMATS)
break;
}
}
}
out = rdpsnd_init_packet(RDPSND_NEGOTIATE | 0x200, 20 + 18*format_count);
out_uint32_le(out, 3); /* flags */
out_uint32(out, 0xffffffff); /* volume */
out_uint32(out, 0); /* pitch */
out_uint16(out, 0); /* UDP port */
out_uint16_le(out, format_count);
out_uint8(out, 0x95); /* pad? */
out_uint16_le(out, 2); /* status */
out_uint8(out, 0x77); /* pad? */
for (i = 0; i < format_count; i++)
{
format = &formats[i];
out_uint16_le(out, format->wFormatTag);
out_uint16_le(out, format->nChannels);
out_uint32_le(out, format->nSamplesPerSec);
out_uint32_le(out, format->nAvgBytesPerSec);
out_uint16_le(out, format->nBlockAlign);
out_uint16_le(out, format->wBitsPerSample);
out_uint16(out, 0); /* cbSize */
}
s_mark_end(out);
rdpsnd_send(out);
}
void
rdpsnd_process_unknown6(STREAM in)
{
uint16 unknown1, unknown2;
STREAM out;
/* in_uint8s(in, 4); unknown */
in_uint16_le(in, unknown1);
in_uint16_le(in, unknown2);
out = rdpsnd_init_packet(RDPSND_UNKNOWN6 | 0x2300, 4);
out_uint16_le(out, unknown1);
out_uint16_le(out, unknown2);
s_mark_end(out);
rdpsnd_send(out);
}
void
rdpsnd_process(STREAM s)
{
printf("rdpsnd_process\n");
hexdump(s->p, s->end - s->p);
uint8 type;
uint16 datalen;
static uint16 tick, format;
static uint8 packet_index;
static BOOL awaiting_data_packet;
#ifdef RDPSND_DEBUG
printf("RDPSND recv:\n");
hexdump(s->p, s->end-s->p);
#endif
if (awaiting_data_packet)
{
if (format >= MAX_FORMATS)
{
error("RDPSND: Invalid format index\n");
return;
}
if (!device_open || (format != current_format))
{
if (!device_open && !wave_out_open())
{
rdpsnd_send_completion(tick, packet_index);
return;
}
if (!wave_out_set_format(&formats[format]))
{
rdpsnd_send_completion(tick, packet_index);
wave_out_close();
device_open = False;
return;
}
device_open = True;
current_format = format;
}
wave_out_write(s, tick, packet_index);
awaiting_data_packet = False;
return;
}
in_uint8(s, type);
in_uint8s(s, 1); /* unknown? */
in_uint16_le(s, datalen);
switch (type)
{
case RDPSND_WRITE:
in_uint16_le(s, tick);
in_uint16_le(s, format);
in_uint8(s, packet_index);
awaiting_data_packet = True;
break;
case RDPSND_CLOSE:
wave_out_close();
device_open = False;
break;
case RDPSND_NEGOTIATE:
rdpsnd_process_negotiate(s);
break;
case RDPSND_UNKNOWN6:
rdpsnd_process_unknown6(s);
break;
case RDPSND_SET_VOLUME:
/* uint32 volume */
break;
default:
unimpl("RDPSND packet type %d\n", type);
break;
}
}
BOOL

11
types.h
View File

@ -119,6 +119,17 @@ typedef struct _VCHANNEL
}
VCHANNEL;
/* RDPSND */
typedef struct {
uint16 wFormatTag;
uint16 nChannels;
uint32 nSamplesPerSec;
uint32 nAvgBytesPerSec;
uint16 nBlockAlign;
uint16 wBitsPerSample;
uint16 cbSize;
} WAVEFORMATEX;
/* RDPDR */
typedef uint32 NTSTATUS;
typedef uint32 HANDLE;

24
xwin.c
View File

@ -66,6 +66,11 @@ static BOOL g_moving_wnd;
static int g_move_x_offset = 0;
static int g_move_y_offset = 0;
#ifdef WITH_RDPSND
extern int g_dsp_fd;
extern BOOL g_dsp_busy;
#endif
/* MWM decorations */
#define MWM_HINTS_DECORATIONS (1L << 1)
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5
@ -1078,7 +1083,7 @@ int
ui_select(int rdp_socket)
{
int n = (rdp_socket > g_x_socket) ? rdp_socket + 1 : g_x_socket + 1;
fd_set rfds;
fd_set rfds, wfds;
FD_ZERO(&rfds);
@ -1090,10 +1095,20 @@ ui_select(int rdp_socket)
return 0;
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_SET(rdp_socket, &rfds);
FD_SET(g_x_socket, &rfds);
switch (select(n, &rfds, NULL, NULL, NULL))
#ifdef WITH_RDPSND
/* FIXME: there should be an API for registering fds */
if (g_dsp_busy)
{
FD_SET(g_dsp_fd, &wfds);
n = (g_dsp_fd + 1 > n) ? g_dsp_fd + 1 : n;
}
#endif
switch (select(n, &rfds, &wfds, NULL, NULL))
{
case -1:
error("select: %s\n", strerror(errno));
@ -1104,6 +1119,11 @@ ui_select(int rdp_socket)
if (FD_ISSET(rdp_socket, &rfds))
return 1;
#ifdef WITH_RDPSND
if (FD_ISSET(g_dsp_fd, &wfds))
wave_out_play();
#endif
}
}