summaryrefslogtreecommitdiffstats
path: root/sesman/chansrv
diff options
context:
space:
mode:
Diffstat (limited to 'sesman/chansrv')
-rw-r--r--sesman/chansrv/Makefile.am5
-rw-r--r--sesman/chansrv/pulse/module-xrdp-sink.c2
-rw-r--r--sesman/chansrv/pulse/module-xrdp-source.c2
-rw-r--r--sesman/chansrv/pulse/pulse-notes.ubuntu.txt29
-rw-r--r--sesman/chansrv/sound.c170
-rw-r--r--sesman/chansrv/sound.h1
6 files changed, 187 insertions, 22 deletions
diff --git a/sesman/chansrv/Makefile.am b/sesman/chansrv/Makefile.am
index 2d73f05c..9aa3ebe7 100644
--- a/sesman/chansrv/Makefile.am
+++ b/sesman/chansrv/Makefile.am
@@ -26,6 +26,11 @@ 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/pulse/module-xrdp-sink.c b/sesman/chansrv/pulse/module-xrdp-sink.c
index eb7211a0..d56a4883 100644
--- a/sesman/chansrv/pulse/module-xrdp-sink.c
+++ b/sesman/chansrv/pulse/module-xrdp-sink.c
@@ -72,7 +72,7 @@ PA_MODULE_USAGE(
"channels=<number of channels> "
"channel_map=<channel map>");
-#define DEFAULT_SINK_NAME "xrdp"
+#define DEFAULT_SINK_NAME "xrdp-sink"
#define BLOCK_USEC 30000
//#define BLOCK_USEC (PA_USEC_PER_SEC * 2)
#define CHANSRV_PORT_STR "/tmp/.xrdp/xrdp_chansrv_audio_out_socket_%d"
diff --git a/sesman/chansrv/pulse/module-xrdp-source.c b/sesman/chansrv/pulse/module-xrdp-source.c
index 2d85ad44..2d7ec4fa 100644
--- a/sesman/chansrv/pulse/module-xrdp-source.c
+++ b/sesman/chansrv/pulse/module-xrdp-source.c
@@ -60,7 +60,7 @@ PA_MODULE_USAGE(
"description=<description for the source> "
"latency_time=<latency time in ms>");
-#define DEFAULT_SOURCE_NAME "xrdp"
+#define DEFAULT_SOURCE_NAME "xrdp-source"
#define DEFAULT_LATENCY_TIME 10
#define MAX_LATENCY_USEC (PA_USEC_PER_SEC * 2)
#define CHANSRV_PORT_STR "/tmp/.xrdp/xrdp_chansrv_audio_in_socket_%d"
diff --git a/sesman/chansrv/pulse/pulse-notes.ubuntu.txt b/sesman/chansrv/pulse/pulse-notes.ubuntu.txt
index 51fc5060..053a0022 100644
--- a/sesman/chansrv/pulse/pulse-notes.ubuntu.txt
+++ b/sesman/chansrv/pulse/pulse-notes.ubuntu.txt
@@ -1,4 +1,8 @@
+--------------------------------------
+ Building pulseaudio modules for xrdp
+--------------------------------------
+
o append the following line to /etc/apt/sources.list
deb-src http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
@@ -45,31 +49,16 @@ o sudo cp module-xrdp-sink.so /usr/lib/pulse-<version>/modules
sudo cp module-xrdp-source.so /usr/lib/pulse-<version>/modules
note: on a 64bit machine use lib64 instead of lib
-o cd /etc/pulse
-
-o sudo mv default.pa default.pa.orig
+--------------------------------------
+ To test sound/microphone redirection
+--------------------------------------
-o sudo vi default.pa and add the following lines to it
+o install gnome sound recorder or your favorite sound recorder
-.nofail
-.fail
-load-module module-augment-properties
-#load-module module-alsa-sink device=hw:0
-#load-module module-alsa-source device=hw:0
-#load-module module-pipe-sink
-#load-module module-pipe-source
-#load-module module-null-sink
-load-module module-xrdp-sink
-load-module module-xrdp-source
-load-module module-native-protocol-unix
-#load-module module-udev-detect tsched=0
+o mplayer -ao pulse <audio file>
o sudo apt-get install pavucontrol
-o pulseaudio --kill
-
-o mplayer -ao pulse <audio file>
-
o in another window run pavucontrol and you should see xrdp-sink in use
o to enable pulseaudio log
diff --git a/sesman/chansrv/sound.c b/sesman/chansrv/sound.c
index 12e7a773..cc327744 100644
--- a/sesman/chansrv/sound.c
+++ b/sesman/chansrv/sound.c
@@ -16,6 +16,14 @@
* limitations under the License.
*/
+#include <stdio.h>
+#include <pulse/util.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/errno.h>
+#include <signal.h>
+#include <sys/un.h>
+
#include "sound.h"
#include "thread_calls.h"
#include "defines.h"
@@ -626,6 +634,12 @@ sound_init(void)
LOG(0, ("sound_init:"));
+
+#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();
@@ -691,6 +705,10 @@ sound_deinit(void)
fifo_deinit(&in_fifo);
+#ifdef XRDP_LOAD_PULSE_MODULES
+ system("pulseaudio --kill");
+#endif
+
return 0;
}
@@ -802,6 +820,158 @@ 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 **
diff --git a/sesman/chansrv/sound.h b/sesman/chansrv/sound.h
index 61b80b00..c26d0913 100644
--- a/sesman/chansrv/sound.h
+++ b/sesman/chansrv/sound.h
@@ -75,4 +75,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