diff options
Diffstat (limited to 'sesman')
-rw-r--r-- | sesman/chansrv/Makefile.am | 10 | ||||
-rw-r--r-- | sesman/chansrv/sound.c | 307 | ||||
-rw-r--r-- | sesman/chansrv/sound.h | 9 |
3 files changed, 3 insertions, 323 deletions
diff --git a/sesman/chansrv/Makefile.am b/sesman/chansrv/Makefile.am index 9aa3ebe7..81218db1 100644 --- a/sesman/chansrv/Makefile.am +++ b/sesman/chansrv/Makefile.am @@ -16,21 +16,11 @@ EXTRA_INCLUDES = EXTRA_LIBS = EXTRA_FLAGS = -if XRDP_SIMPLESOUND -EXTRA_DEFINES += -DXRDP_SIMPLESOUND -EXTRA_LIBS += -lpthread -lpulse -lpulse-simple -endif - if XRDP_FUSE EXTRA_DEFINES += -DXRDP_FUSE EXTRA_LIBS += -lfuse endif -if XRDP_LOAD_PULSE_MODULES -EXTRA_DEFINES += -DXRDP_LOAD_PULSE_MODULES -EXTRA_LIBS += -lpulse -endif - AM_CFLAGS = \ -DXRDP_CFG_PATH=\"${sysconfdir}/xrdp\" \ -DXRDP_SBIN_PATH=\"${sbindir}\" \ diff --git a/sesman/chansrv/sound.c b/sesman/chansrv/sound.c index efb7ff85..d95d1afa 100644 --- a/sesman/chansrv/sound.c +++ b/sesman/chansrv/sound.c @@ -1,7 +1,7 @@ /** * xrdp: A Remote Desktop Protocol server. * - * Copyright (C) Jay Sorg 2009-2013 + * Copyright (C) Jay Sorg 2009-2014 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,10 +23,6 @@ #include <signal.h> #include <sys/un.h> -#ifdef XRDP_LOAD_PULSE_MODULES -#include <pulse/util.h> -#endif - #include "sound.h" #include "thread_calls.h" #include "defines.h" @@ -56,11 +52,6 @@ int g_buf_index = 0; int g_sent_time[256]; int g_sent_flag[256]; -#if defined(XRDP_SIMPLESOUND) -static void *DEFAULT_CC -read_raw_audio_data(void *arg); -#endif - #define CHANSRV_PORT_OUT_STR "/tmp/.xrdp/xrdp_chansrv_audio_out_socket_%d" #define CHANSRV_PORT_IN_STR "/tmp/.xrdp/xrdp_chansrv_audio_in_socket_%d" @@ -655,11 +646,6 @@ sound_init(void) g_memset(g_sent_flag, 0, sizeof(g_sent_flag)); -#ifdef XRDP_LOAD_PULSE_MODULES - if (load_pulse_modules()) - LOG(0, ("Audio and microphone redirection will not work!")); -#endif - /* init sound output */ sound_send_server_output_formats(); @@ -685,13 +671,6 @@ sound_init(void) /* save data from sound_server_source */ fifo_init(&in_fifo, 100); -#if defined(XRDP_SIMPLESOUND) - - /* start thread to read raw audio data from pulseaudio device */ - tc_thread_create(read_raw_audio_data, 0); - -#endif - return 0; } @@ -726,10 +705,6 @@ sound_deinit(void) fifo_deinit(&in_fifo); -#ifdef XRDP_LOAD_PULSE_MODULES - system("pulseaudio --kill"); -#endif - return 0; } @@ -841,158 +816,6 @@ sound_check_wait_objs(void) return 0; } -/** - * Load xrdp pulseaudio sink and source modules - * - * @return 0 on success, -1 on failure - *****************************************************************************/ - -#ifdef XRDP_LOAD_PULSE_MODULES - -static int APP_CC -load_pulse_modules() -{ - struct sockaddr_un sa; - - pid_t pid; - char* cli; - int fd; - int i; - int rv; - char buf[1024]; - - /* is pulse audio daemon running? */ - if (pa_pid_file_check_running(&pid, "pulseaudio") < 0) - { - LOG(0, ("load_pulse_modules: No PulseAudio daemon running, " - "or not running as session daemon")); - } - - /* get name of unix domain socket used by pulseaudio for CLI */ - if ((cli = (char *) pa_runtime_path("cli")) == NULL) - { - LOG(0, ("load_pulse_modules: Error getting PulesAudio runtime path")); - return -1; - } - - /* open a socket */ - if ((fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) - { - pa_xfree(cli); - LOG(0, ("load_pulse_modules: Socket open error")); - return -1; - } - - /* set it up */ - memset(&sa, 0, sizeof(struct sockaddr_un)); - sa.sun_family = AF_UNIX; - pa_strlcpy(sa.sun_path, cli, sizeof(sa.sun_path)); - pa_xfree(cli); - - for (i = 0; i < 20; i++) - { - if (pa_pid_file_kill(SIGUSR2, NULL, "pulseaudio") < 0) - LOG(0, ("load_pulse_modules: Failed to kill PulseAudio daemon")); - - if ((rv = connect(fd, (struct sockaddr*) &sa, sizeof(sa))) < 0 && - (errno != ECONNREFUSED && errno != ENOENT)) - { - LOG(0, ("load_pulse_modules: connect() failed with error: %s", - strerror(errno))); - return -1; - } - - if (rv >= 0) - break; - - pa_msleep(300); - } - - if (i >= 20) - { - LOG(0, ("load_pulse_modules: Daemon not responding")); - return -1; - } - - LOG(0, ("load_pulse_modules: connected to pulseaudio daemon")); - - /* read back PulseAudio sign on message */ - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - - /* send cmd to load source module */ - memset(buf, 0, 1024); - sprintf(buf, "load-module module-xrdp-source\n"); - send(fd, buf, strlen(buf), 0); - - /* read back response */ - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - if (strcasestr(buf, "Module load failed") != 0) - { - LOG(0, ("load_pulse_modules: Error loading module-xrdp-source")); - } - else - { - LOG(0, ("load_pulse_modules: Loaded module-xrdp-source")); - - /* success, set it as the default source */ - memset(buf, 0, 1024); - sprintf(buf, "set-default-source xrdp-source\n"); - send(fd, buf, strlen(buf), 0); - - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - - if (strcasestr(buf, "does not exist") != 0) - { - LOG(0, ("load_pulse_modules: Error setting default source")); - } - else - { - LOG(0, ("load_pulse_modules: set default source")); - } - } - - /* send cmd to load sink module */ - memset(buf, 0, 1024); - sprintf(buf, "load-module module-xrdp-sink\n"); - send(fd, buf, strlen(buf), 0); - - /* read back response */ - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - if (strcasestr(buf, "Module load failed") != 0) - { - LOG(0, ("load_pulse_modules: Error loading module-xrdp-sink")); - } - else - { - LOG(0, ("load_pulse_modules: Loaded module-xrdp-sink")); - - /* success, set it as the default sink */ - memset(buf, 0, 1024); - sprintf(buf, "set-default-sink xrdp-sink\n"); - send(fd, buf, strlen(buf), 0); - - memset(buf, 0, 1024); - recv(fd, buf, 1024, 0); - - if (strcasestr(buf, "does not exist") != 0) - { - LOG(0, ("load_pulse_modules: Error setting default sink")); - } - else - { - LOG(0, ("load_pulse_modules: set default sink")); - } - } - - close(fd); - return 0; -} -#endif - /****************************************************************************** ** ** ** Microphone releated code ** @@ -1326,131 +1149,3 @@ sound_sndsrvr_source_data_in(struct trans *trans) return 0; } - -/*****************************************************************************/ - -#if defined(XRDP_SIMPLESOUND) - -#define AUDIO_BUF_SIZE 2048 - -static int DEFAULT_CC -sttrans_data_in(struct trans *self) -{ - LOG(0, ("sttrans_data_in:\n")); - return 0; -} - -/** - * read raw audio data from pulseaudio device and write it - * to a unix domain socket on which trans server is listening - */ - -static void *DEFAULT_CC -read_raw_audio_data(void *arg) -{ - pa_sample_spec samp_spec; - pa_simple *simple = NULL; - uint32_t bytes_read; - char *cptr; - int i; - int error; - struct trans *strans; - char path[256]; - struct stream *outs; - - strans = trans_create(TRANS_MODE_UNIX, 8192, 8192); - - if (strans == 0) - { - LOG(0, ("read_raw_audio_data: trans_create failed\n")); - return 0; - } - - strans->trans_data_in = sttrans_data_in; - g_snprintf(path, 255, CHANSRV_PORT_OUT_STR, g_display_num); - - if (trans_connect(strans, "", path, 100) != 0) - { - LOG(0, ("read_raw_audio_data: trans_connect failed\n")); - trans_delete(strans); - return 0; - } - - /* setup audio format */ - samp_spec.format = PA_SAMPLE_S16LE; - samp_spec.rate = 44100; - samp_spec.channels = 2; - - /* if we are root, then for first 8 seconds connection to pulseaudo server - fails; if we are non-root, then connection succeeds on first attempt; - for now we have changed code to be non-root, but this may change in the - future - so pretend we are root and try connecting to pulseaudio server - for upto one minute */ - for (i = 0; i < 60; i++) - { - simple = pa_simple_new(NULL, "xrdp", PA_STREAM_RECORD, NULL, - "record", &samp_spec, NULL, NULL, &error); - - if (simple) - { - /* connected to pulseaudio server */ - LOG(0, ("read_raw_audio_data: connected to pulseaudio server\n")); - break; - } - - LOG(0, ("read_raw_audio_data: ERROR creating PulseAudio async interface\n")); - LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error))); - g_sleep(1000); - } - - if (i == 60) - { - /* failed to connect to audio server */ - trans_delete(strans); - return NULL; - } - - /* insert header just once */ - outs = trans_get_out_s(strans, 8192); - out_uint32_le(outs, 0); - out_uint32_le(outs, AUDIO_BUF_SIZE + 8); - cptr = outs->p; - out_uint8s(outs, AUDIO_BUF_SIZE); - s_mark_end(outs); - - while (1) - { - /* read a block of raw audio data... */ - g_memset(cptr, 0, 4); - bytes_read = pa_simple_read(simple, cptr, AUDIO_BUF_SIZE, &error); - - if (bytes_read < 0) - { - LOG(0, ("read_raw_audio_data: ERROR reading from pulseaudio stream\n")); - LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error))); - break; - } - - /* bug workaround: - even when there is no audio data, pulseaudio is returning without - errors but the data itself is zero; we use this zero data to - determine that there is no audio data present */ - if (*cptr == 0 && *(cptr + 1) == 0 && *(cptr + 2) == 0 && *(cptr + 3) == 0) - { - g_sleep(10); - continue; - } - - if (trans_force_write_s(strans, outs) != 0) - { - LOG(0, ("read_raw_audio_data: ERROR writing audio data to server\n")); - break; - } - } - - pa_simple_free(simple); - trans_delete(strans); - return NULL; -} - -#endif diff --git a/sesman/chansrv/sound.h b/sesman/chansrv/sound.h index c26d0913..b443f0e3 100644 --- a/sesman/chansrv/sound.h +++ b/sesman/chansrv/sound.h @@ -1,7 +1,7 @@ /** * xrdp: A Remote Desktop Protocol server. * - * Copyright (C) Jay Sorg 2009-2013 + * Copyright (C) Jay Sorg 2009-2014 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,6 @@ #ifndef _SOUND_H_ #define _SOUND_H_ -#if defined(XRDP_SIMPLESOUND) -#include <pulse/simple.h> -#include <pulse/error.h> -#endif - #include "arch.h" #include "parse.h" #include "os_calls.h" @@ -75,5 +70,5 @@ static int APP_CC sound_input_start_recording(); static int APP_CC sound_input_stop_recording(); static int APP_CC sound_process_input_data(struct stream *s, int bytes); static int DEFAULT_CC sound_sndsrvr_source_data_in(struct trans *trans); -static int APP_CC load_pulse_modules(); + #endif |