GUACAMOLE-179: Merge move of PulseAudio support into library.
This commit is contained in:
commit
b8f4f19c36
@ -28,6 +28,7 @@ DIST_SUBDIRS = \
|
||||
src/terminal \
|
||||
src/guacd \
|
||||
src/guacenc \
|
||||
src/pulse \
|
||||
src/protocols/rdp \
|
||||
src/protocols/ssh \
|
||||
src/protocols/telnet \
|
||||
@ -48,6 +49,10 @@ if ENABLE_TERMINAL
|
||||
SUBDIRS += src/terminal
|
||||
endif
|
||||
|
||||
if ENABLE_PULSE
|
||||
SUBDIRS += src/pulse
|
||||
endif
|
||||
|
||||
if ENABLE_RDP
|
||||
SUBDIRS += src/protocols/rdp
|
||||
endif
|
||||
|
@ -119,6 +119,10 @@ AC_SUBST([LIBGUAC_INCLUDE], '-I$(top_srcdir)/src/libguac')
|
||||
AC_SUBST([COMMON_LTLIB], '$(top_builddir)/src/common/libguac_common.la')
|
||||
AC_SUBST([COMMON_INCLUDE], '-I$(top_srcdir)/src/common')
|
||||
|
||||
# Common PulseAudio utility library
|
||||
AC_SUBST([PULSE_LTLIB], '$(top_builddir)/src/pulse/libguac_pulse.la')
|
||||
AC_SUBST([PULSE_INCLUDE], '-I$(top_srcdir)/src/pulse')
|
||||
|
||||
# Common utility library for guacd implementations
|
||||
AC_SUBST([LIBGUACD_LTLIB], '$(top_builddir)/src/libguacd/libguacd.la')
|
||||
AC_SUBST([LIBGUACD_INCLUDE], '-I$(top_srcdir)/src/libguacd')
|
||||
@ -1108,6 +1112,7 @@ AC_CONFIG_FILES([Makefile
|
||||
src/libguacd/Makefile
|
||||
src/guacd/Makefile
|
||||
src/guacenc/Makefile
|
||||
src/pulse/Makefile
|
||||
src/protocols/rdp/Makefile
|
||||
src/protocols/ssh/Makefile
|
||||
src/protocols/telnet/Makefile
|
||||
|
@ -30,16 +30,38 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* Sets the encoder associated with the given guac_audio_stream, automatically
|
||||
* invoking its begin_handler. The guac_audio_stream MUST NOT already be
|
||||
* associated with an encoder.
|
||||
*
|
||||
* @param audio
|
||||
* The guac_audio_stream whose encoder is being set.
|
||||
*
|
||||
* @param encoder
|
||||
* The encoder to associate with the given guac_audio_stream.
|
||||
*/
|
||||
static void guac_audio_stream_set_encoder(guac_audio_stream* audio,
|
||||
guac_audio_encoder* encoder) {
|
||||
|
||||
/* Call handler, if defined */
|
||||
if (encoder != NULL && encoder->begin_handler)
|
||||
encoder->begin_handler(audio);
|
||||
|
||||
/* Assign encoder, which may be NULL */
|
||||
audio->encoder = encoder;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a new audio encoder to the given guac_audio_stream based on the
|
||||
* audio mimetypes declared as supported by the given user. If no audio encoder
|
||||
* can be found, no new audio encoder is assigned, and the existing encoder is
|
||||
* left untouched (if any).
|
||||
*
|
||||
* @param owner
|
||||
* @param user
|
||||
* The user whose supported audio mimetypes should determine the audio
|
||||
* encoder selected. It is expected that this user will be the owner of
|
||||
* the connection.
|
||||
* encoder selected.
|
||||
*
|
||||
* @param data
|
||||
* The guac_audio_stream to which the new encoder should be assigned.
|
||||
@ -50,31 +72,32 @@
|
||||
* The assigned audio encoder. If no new audio encoder can be assigned,
|
||||
* this will be the currently-assigned audio encoder (which may be NULL).
|
||||
*/
|
||||
static void* guac_audio_assign_encoder(guac_user* owner, void* data) {
|
||||
static void* guac_audio_assign_encoder(guac_user* user, void* data) {
|
||||
|
||||
int i;
|
||||
|
||||
guac_audio_stream* audio = (guac_audio_stream*) data;
|
||||
int bps = audio->bps;
|
||||
|
||||
/* If there is no owner, do not attempt to assign a new encoder */
|
||||
if (owner == NULL)
|
||||
/* If no user is provided, or an encoder has already been assigned,
|
||||
* do not attempt to assign a new encoder */
|
||||
if (user == NULL || audio->encoder != NULL)
|
||||
return audio->encoder;
|
||||
|
||||
/* For each supported mimetype, check for an associated encoder */
|
||||
for (i=0; owner->info.audio_mimetypes[i] != NULL; i++) {
|
||||
for (i=0; user->info.audio_mimetypes[i] != NULL; i++) {
|
||||
|
||||
const char* mimetype = owner->info.audio_mimetypes[i];
|
||||
const char* mimetype = user->info.audio_mimetypes[i];
|
||||
|
||||
/* If 16-bit raw audio is supported, done. */
|
||||
if (bps == 16 && strcmp(mimetype, raw16_encoder->mimetype) == 0) {
|
||||
audio->encoder = raw16_encoder;
|
||||
guac_audio_stream_set_encoder(audio, raw16_encoder);
|
||||
break;
|
||||
}
|
||||
|
||||
/* If 8-bit raw audio is supported, done. */
|
||||
if (bps == 8 && strcmp(mimetype, raw8_encoder->mimetype) == 0) {
|
||||
audio->encoder = raw8_encoder;
|
||||
guac_audio_stream_set_encoder(audio, raw8_encoder);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -100,16 +123,17 @@ guac_audio_stream* guac_audio_stream_alloc(guac_client* client,
|
||||
audio->channels = channels;
|
||||
audio->bps = bps;
|
||||
|
||||
/* Assign encoder for owner, abort if no encoder can be found */
|
||||
if (!guac_client_for_owner(client, guac_audio_assign_encoder, audio)) {
|
||||
guac_client_free_stream(client, audio->stream);
|
||||
free(audio);
|
||||
return NULL;
|
||||
}
|
||||
/* Assign encoder if explicitly provided */
|
||||
if (encoder != NULL)
|
||||
guac_audio_stream_set_encoder(audio, encoder);
|
||||
|
||||
/* Call handler, if defined */
|
||||
if (audio->encoder->begin_handler)
|
||||
audio->encoder->begin_handler(audio);
|
||||
/* Otherwise, attempt to automatically assign encoder for owner */
|
||||
if (audio->encoder == NULL)
|
||||
guac_client_for_owner(client, guac_audio_assign_encoder, audio);
|
||||
|
||||
/* Failing that, attempt to assign encoder for ANY connected user */
|
||||
if (audio->encoder == NULL)
|
||||
guac_client_foreach_user(client, guac_audio_assign_encoder, audio);
|
||||
|
||||
return audio;
|
||||
|
||||
@ -118,8 +142,12 @@ guac_audio_stream* guac_audio_stream_alloc(guac_client* client,
|
||||
void guac_audio_stream_reset(guac_audio_stream* audio,
|
||||
guac_audio_encoder* encoder, int rate, int channels, int bps) {
|
||||
|
||||
/* Pull assigned encoder if no other encoder is requested */
|
||||
if (encoder == NULL)
|
||||
encoder = audio->encoder;
|
||||
|
||||
/* Do nothing if nothing is changing */
|
||||
if ((encoder == NULL || encoder == audio->encoder)
|
||||
if (encoder == audio->encoder
|
||||
&& rate == audio->rate
|
||||
&& channels == audio->channels
|
||||
&& bps == audio->bps) {
|
||||
@ -127,31 +155,28 @@ void guac_audio_stream_reset(guac_audio_stream* audio,
|
||||
}
|
||||
|
||||
/* Free old encoder data */
|
||||
if (audio->encoder->end_handler)
|
||||
if (audio->encoder != NULL && audio->encoder->end_handler)
|
||||
audio->encoder->end_handler(audio);
|
||||
|
||||
/* Assign new encoder, if changed */
|
||||
if (encoder != NULL)
|
||||
audio->encoder = encoder;
|
||||
|
||||
/* Set PCM properties */
|
||||
audio->rate = rate;
|
||||
audio->channels = channels;
|
||||
audio->bps = bps;
|
||||
|
||||
/* Init encoder with new data */
|
||||
if (audio->encoder->begin_handler)
|
||||
audio->encoder->begin_handler(audio);
|
||||
/* Re-init encoder */
|
||||
guac_audio_stream_set_encoder(audio, encoder);
|
||||
|
||||
}
|
||||
|
||||
void guac_audio_stream_add_user(guac_audio_stream* audio, guac_user* user) {
|
||||
|
||||
guac_audio_encoder* encoder = audio->encoder;
|
||||
/* Attempt to assign encoder if no encoder has yet been assigned */
|
||||
if (audio->encoder == NULL)
|
||||
guac_audio_assign_encoder(user, audio);
|
||||
|
||||
/* Notify encoder that a new user is present */
|
||||
if (encoder->join_handler)
|
||||
encoder->join_handler(audio, user);
|
||||
if (audio->encoder != NULL && audio->encoder->join_handler)
|
||||
audio->encoder->join_handler(audio, user);
|
||||
|
||||
}
|
||||
|
||||
@ -161,7 +186,7 @@ void guac_audio_stream_free(guac_audio_stream* audio) {
|
||||
guac_audio_stream_flush(audio);
|
||||
|
||||
/* Clean up encoder */
|
||||
if (audio->encoder->end_handler)
|
||||
if (audio->encoder != NULL && audio->encoder->end_handler)
|
||||
audio->encoder->end_handler(audio);
|
||||
|
||||
/* Free associated data */
|
||||
@ -173,7 +198,7 @@ void guac_audio_stream_write_pcm(guac_audio_stream* audio,
|
||||
const unsigned char* data, int length) {
|
||||
|
||||
/* Write data */
|
||||
if (audio->encoder->write_handler)
|
||||
if (audio->encoder != NULL && audio->encoder->write_handler)
|
||||
audio->encoder->write_handler(audio, data, length);
|
||||
|
||||
}
|
||||
@ -181,7 +206,7 @@ void guac_audio_stream_write_pcm(guac_audio_stream* audio,
|
||||
void guac_audio_stream_flush(guac_audio_stream* audio) {
|
||||
|
||||
/* Flush any buffered data */
|
||||
if (audio->encoder->flush_handler)
|
||||
if (audio->encoder != NULL && audio->encoder->flush_handler)
|
||||
audio->encoder->flush_handler(audio);
|
||||
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ struct guac_audio_stream {
|
||||
* Allocates a new audio stream at the client level which encodes audio data
|
||||
* using the given encoder. If NULL is specified for the encoder, an
|
||||
* appropriate encoder will be selected based on the encoders built into
|
||||
* libguac and the level of support declared by the owner associated with the
|
||||
* libguac and the level of support declared by users associated with the
|
||||
* given guac_client. The PCM format specified here (via rate, channels, and
|
||||
* bps) must be the format used for all PCM data provided to the audio stream.
|
||||
* The format may only be changed using guac_audio_stream_reset().
|
||||
@ -125,10 +125,10 @@ struct guac_audio_stream {
|
||||
* for the new user.
|
||||
*
|
||||
* @param client
|
||||
* The guac_client for which this audio stream is being allocated. Only the
|
||||
* connection owner is used to determine the level of audio support, and it
|
||||
* is currently assumed that all other joining users on the connection will
|
||||
* have the same level of audio support.
|
||||
* The guac_client for which this audio stream is being allocated. The
|
||||
* connection owner is given priority when determining the level of audio
|
||||
* support. It is currently assumed that all other joining users on the
|
||||
* connection will have the same level of audio support.
|
||||
*
|
||||
* @param encoder
|
||||
* The guac_audio_encoder to use when encoding audio, or NULL if libguac
|
||||
|
@ -46,22 +46,16 @@ noinst_HEADERS = \
|
||||
user.h \
|
||||
vnc.h
|
||||
|
||||
# Optional PulseAudio support
|
||||
if ENABLE_PULSE
|
||||
libguac_client_vnc_la_SOURCES += pulse.c
|
||||
noinst_HEADERS += pulse.h
|
||||
endif
|
||||
|
||||
libguac_client_vnc_la_CFLAGS = \
|
||||
-Werror -Wall -pedantic -Iinclude \
|
||||
@COMMON_INCLUDE@ \
|
||||
@COMMON_SSH_INCLUDE@ \
|
||||
@LIBGUAC_INCLUDE@
|
||||
@LIBGUAC_INCLUDE@ \
|
||||
@PULSE_INCLUDE@
|
||||
|
||||
libguac_client_vnc_la_LDFLAGS = \
|
||||
-version-info 0:0:0 \
|
||||
@CAIRO_LIBS@ \
|
||||
@PULSE_LIBS@ \
|
||||
@VNC_LIBS@
|
||||
|
||||
libguac_client_vnc_la_LIBADD = \
|
||||
@ -75,3 +69,8 @@ noinst_HEADERS += sftp.h
|
||||
libguac_client_vnc_la_LIBADD += @COMMON_SSH_LTLIB@
|
||||
endif
|
||||
|
||||
# Optional PulseAudio support
|
||||
if ENABLE_PULSE
|
||||
libguac_client_vnc_la_LIBADD += @PULSE_LTLIB@
|
||||
endif
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_PULSE
|
||||
#include "pulse.h"
|
||||
#include "pulse/pulse.h"
|
||||
#endif
|
||||
|
||||
#include <guacamole/client.h>
|
||||
@ -110,20 +110,16 @@ int guac_vnc_client_free_handler(guac_client* client) {
|
||||
if (vnc_client->display != NULL)
|
||||
guac_common_display_free(vnc_client->display);
|
||||
|
||||
/* Free settings-dependend data */
|
||||
if (settings != NULL) {
|
||||
|
||||
#ifdef ENABLE_PULSE
|
||||
/* If audio enabled, stop streaming */
|
||||
if (settings->audio_enabled)
|
||||
guac_pa_stop_stream(client);
|
||||
/* If audio enabled, stop streaming */
|
||||
if (vnc_client->audio)
|
||||
guac_pa_stream_free(vnc_client->audio);
|
||||
#endif
|
||||
|
||||
/* Free parsed settings */
|
||||
/* Free parsed settings */
|
||||
if (settings != NULL)
|
||||
guac_vnc_settings_free(settings);
|
||||
|
||||
}
|
||||
|
||||
/* Free generic data struct */
|
||||
free(client->data);
|
||||
|
||||
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GUAC_VNC_PULSE_H
|
||||
#define __GUAC_VNC_PULSE_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <guacamole/client.h>
|
||||
|
||||
/**
|
||||
* The number of bytes to request for the audio fragments received from
|
||||
* PulseAudio.
|
||||
*/
|
||||
#define GUAC_VNC_AUDIO_FRAGMENT_SIZE 8192
|
||||
|
||||
/**
|
||||
* The minimum number of PCM bytes to wait for before flushing an audio
|
||||
* packet. The current value is 48K, which works out to be around 280ms.
|
||||
*/
|
||||
#define GUAC_VNC_PCM_WRITE_RATE 49152
|
||||
|
||||
/**
|
||||
* Rate of audio to stream, in Hz.
|
||||
*/
|
||||
#define GUAC_VNC_AUDIO_RATE 44100
|
||||
|
||||
/**
|
||||
* The number of channels to stream.
|
||||
*/
|
||||
#define GUAC_VNC_AUDIO_CHANNELS 2
|
||||
|
||||
/**
|
||||
* The number of bits per sample.
|
||||
*/
|
||||
#define GUAC_VNC_AUDIO_BPS 16
|
||||
|
||||
/**
|
||||
* Starts streaming audio from PulseAudio to the given Guacamole client.
|
||||
*
|
||||
* @param client The client to stream data to.
|
||||
*/
|
||||
void guac_pa_start_stream(guac_client* client);
|
||||
|
||||
/**
|
||||
* Stops streaming audio from PulseAudio to the given Guacamole client.
|
||||
*
|
||||
* @param client The client to stream data to.
|
||||
*/
|
||||
void guac_pa_stop_stream(guac_client* client);
|
||||
|
||||
#endif
|
||||
|
@ -28,6 +28,10 @@
|
||||
#include "sftp.h"
|
||||
#include "vnc.h"
|
||||
|
||||
#ifdef ENABLE_PULSE
|
||||
#include "pulse/pulse.h"
|
||||
#endif
|
||||
|
||||
#include <guacamole/audio.h>
|
||||
#include <guacamole/client.h>
|
||||
#include <guacamole/socket.h>
|
||||
@ -75,7 +79,7 @@ int guac_vnc_user_join_handler(guac_user* user, int argc, char** argv) {
|
||||
#ifdef ENABLE_PULSE
|
||||
/* Synchronize an audio stream */
|
||||
if (vnc_client->audio)
|
||||
guac_audio_stream_add_user(vnc_client->audio, user);
|
||||
guac_pa_stream_add_user(vnc_client->audio, user);
|
||||
#endif
|
||||
|
||||
/* Synchronize with current display */
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "vnc.h"
|
||||
|
||||
#ifdef ENABLE_PULSE
|
||||
#include "pulse.h"
|
||||
#include "pulse/pulse.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COMMON_SSH
|
||||
@ -207,32 +207,10 @@ void* guac_vnc_client_thread(void* data) {
|
||||
}
|
||||
|
||||
#ifdef ENABLE_PULSE
|
||||
/* If an encoding is available, load an audio stream */
|
||||
if (settings->audio_enabled) {
|
||||
|
||||
vnc_client->audio = guac_audio_stream_alloc(client, NULL,
|
||||
GUAC_VNC_AUDIO_RATE,
|
||||
GUAC_VNC_AUDIO_CHANNELS,
|
||||
GUAC_VNC_AUDIO_BPS);
|
||||
|
||||
/* If successful, init audio system */
|
||||
if (vnc_client->audio != NULL) {
|
||||
|
||||
guac_client_log(client, GUAC_LOG_INFO,
|
||||
"Audio will be encoded as %s",
|
||||
vnc_client->audio->encoder->mimetype);
|
||||
|
||||
/* Start audio stream */
|
||||
guac_pa_start_stream(client);
|
||||
|
||||
}
|
||||
|
||||
/* Otherwise, audio loading failed */
|
||||
else
|
||||
guac_client_log(client, GUAC_LOG_INFO,
|
||||
"No available audio encoding. Sound disabled.");
|
||||
|
||||
} /* end if audio enabled */
|
||||
/* If audio is enabled, start streaming via PulseAudio */
|
||||
if (settings->audio_enabled)
|
||||
vnc_client->audio = guac_pa_stream_alloc(client,
|
||||
settings->pa_servername);
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COMMON_SSH
|
||||
|
@ -33,8 +33,7 @@
|
||||
#include <rfb/rfbclient.h>
|
||||
|
||||
#ifdef ENABLE_PULSE
|
||||
#include <guacamole/audio.h>
|
||||
#include <pulse/pulseaudio.h>
|
||||
#include "pulse/pulse.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COMMON_SSH
|
||||
@ -89,14 +88,9 @@ typedef struct guac_vnc_client {
|
||||
|
||||
#ifdef ENABLE_PULSE
|
||||
/**
|
||||
* Audio output, if any.
|
||||
* PulseAudio output, if any.
|
||||
*/
|
||||
guac_audio_stream* audio;
|
||||
|
||||
/**
|
||||
* PulseAudio event loop.
|
||||
*/
|
||||
pa_threaded_mainloop* pa_mainloop;
|
||||
guac_pa_stream* audio;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_COMMON_SSH
|
||||
|
40
src/pulse/Makefile.am
Normal file
40
src/pulse/Makefile.am
Normal file
@ -0,0 +1,40 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
noinst_LTLIBRARIES = libguac_pulse.la
|
||||
|
||||
noinst_HEADERS = \
|
||||
pulse/pulse.h
|
||||
|
||||
libguac_pulse_la_SOURCES = \
|
||||
pulse.c
|
||||
|
||||
libguac_pulse_la_CFLAGS = \
|
||||
-Werror -Wall -pedantic \
|
||||
@LIBGUAC_INCLUDE@
|
||||
|
||||
libguac_pulse_la_LIBADD = \
|
||||
@LIBGUAC_LTLIB@
|
||||
|
||||
libguac_pulse_la_LDFLAGS = \
|
||||
@PULSE_LIBS@
|
||||
|
@ -19,12 +19,11 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "pulse.h"
|
||||
#include "vnc.h"
|
||||
#include "pulse/pulse.h"
|
||||
|
||||
#include <guacamole/audio.h>
|
||||
#include <guacamole/client.h>
|
||||
#include <guacamole/socket.h>
|
||||
#include <guacamole/user.h>
|
||||
#include <pulse/pulseaudio.h>
|
||||
|
||||
/**
|
||||
@ -62,9 +61,8 @@ static int guac_pa_is_silence(const void* buffer, size_t length) {
|
||||
static void __stream_read_callback(pa_stream* stream, size_t length,
|
||||
void* data) {
|
||||
|
||||
guac_client* client = (guac_client*) data;
|
||||
guac_vnc_client* vnc_client = (guac_vnc_client*) client->data;
|
||||
guac_audio_stream* audio = vnc_client->audio;
|
||||
guac_pa_stream* guac_stream = (guac_pa_stream*) data;
|
||||
guac_audio_stream* audio = guac_stream->audio;
|
||||
|
||||
const void* buffer;
|
||||
|
||||
@ -86,7 +84,8 @@ static void __stream_read_callback(pa_stream* stream, size_t length,
|
||||
|
||||
static void __stream_state_callback(pa_stream* stream, void* data) {
|
||||
|
||||
guac_client* client = (guac_client*) data;
|
||||
guac_pa_stream* guac_stream = (guac_pa_stream*) data;
|
||||
guac_client* client = guac_stream->client;
|
||||
|
||||
switch (pa_stream_get_state(stream)) {
|
||||
|
||||
@ -137,11 +136,11 @@ static void __context_get_sink_info_callback(pa_context* context,
|
||||
|
||||
/* Set format */
|
||||
spec.format = PA_SAMPLE_S16LE;
|
||||
spec.rate = GUAC_VNC_AUDIO_RATE;
|
||||
spec.channels = GUAC_VNC_AUDIO_CHANNELS;
|
||||
spec.rate = GUAC_PULSE_AUDIO_RATE;
|
||||
spec.channels = GUAC_PULSE_AUDIO_CHANNELS;
|
||||
|
||||
attr.maxlength = -1;
|
||||
attr.fragsize = GUAC_VNC_AUDIO_FRAGMENT_SIZE;
|
||||
attr.fragsize = GUAC_PULSE_AUDIO_FRAGMENT_SIZE;
|
||||
|
||||
/* Create stream */
|
||||
stream = pa_stream_new(context, "Guacamole Audio", &spec, NULL);
|
||||
@ -226,41 +225,54 @@ static void __context_state_callback(pa_context* context, void* data) {
|
||||
|
||||
}
|
||||
|
||||
void guac_pa_start_stream(guac_client* client) {
|
||||
guac_pa_stream* guac_pa_stream_alloc(guac_client* client,
|
||||
const char* server_name) {
|
||||
|
||||
guac_vnc_client* vnc_client = (guac_vnc_client*) client->data;
|
||||
guac_vnc_settings* settings = vnc_client->settings;
|
||||
guac_audio_stream* audio = guac_audio_stream_alloc(client, NULL,
|
||||
GUAC_PULSE_AUDIO_RATE, GUAC_PULSE_AUDIO_CHANNELS,
|
||||
GUAC_PULSE_AUDIO_BPS);
|
||||
|
||||
pa_context* context;
|
||||
|
||||
guac_client_log(client, GUAC_LOG_INFO, "Starting audio stream");
|
||||
/* Abort if audio stream cannot be created */
|
||||
if (audio == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Init main loop */
|
||||
vnc_client->pa_mainloop = pa_threaded_mainloop_new();
|
||||
guac_pa_stream* stream = malloc(sizeof(guac_pa_stream));
|
||||
stream->client = client;
|
||||
stream->audio = audio;
|
||||
stream->pa_mainloop = pa_threaded_mainloop_new();
|
||||
|
||||
/* Create context */
|
||||
context = pa_context_new(
|
||||
pa_threaded_mainloop_get_api(vnc_client->pa_mainloop),
|
||||
pa_context* context = pa_context_new(
|
||||
pa_threaded_mainloop_get_api(stream->pa_mainloop),
|
||||
"Guacamole Audio");
|
||||
|
||||
/* Set up context */
|
||||
pa_context_set_state_callback(context, __context_state_callback, client);
|
||||
pa_context_connect(context, settings->pa_servername,
|
||||
PA_CONTEXT_NOAUTOSPAWN, NULL);
|
||||
pa_context_set_state_callback(context, __context_state_callback, stream);
|
||||
pa_context_connect(context, server_name, PA_CONTEXT_NOAUTOSPAWN, NULL);
|
||||
|
||||
/* Start loop */
|
||||
pa_threaded_mainloop_start(vnc_client->pa_mainloop);
|
||||
pa_threaded_mainloop_start(stream->pa_mainloop);
|
||||
|
||||
return stream;
|
||||
|
||||
}
|
||||
|
||||
void guac_pa_stop_stream(guac_client* client) {
|
||||
void guac_pa_stream_add_user(guac_pa_stream* stream, guac_user* user) {
|
||||
guac_audio_stream_add_user(stream->audio, user);
|
||||
}
|
||||
|
||||
guac_vnc_client* vnc_client = (guac_vnc_client*) client->data;
|
||||
void guac_pa_stream_free(guac_pa_stream* stream) {
|
||||
|
||||
/* Stop loop */
|
||||
pa_threaded_mainloop_stop(vnc_client->pa_mainloop);
|
||||
pa_threaded_mainloop_stop(stream->pa_mainloop);
|
||||
|
||||
guac_client_log(client, GUAC_LOG_INFO, "Audio stream finished");
|
||||
/* Free underlying audio stream */
|
||||
guac_audio_stream_free(stream->audio);
|
||||
|
||||
/* Stream now ended */
|
||||
guac_client_log(stream->client, GUAC_LOG_INFO, "Audio stream finished");
|
||||
free(stream);
|
||||
|
||||
}
|
||||
|
124
src/pulse/pulse/pulse.h
Normal file
124
src/pulse/pulse/pulse.h
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GUAC_PULSE_H
|
||||
#define GUAC_PULSE_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <guacamole/audio.h>
|
||||
#include <guacamole/client.h>
|
||||
#include <guacamole/user.h>
|
||||
#include <pulse/pulseaudio.h>
|
||||
|
||||
/**
|
||||
* The number of bytes to request for the audio fragments received from
|
||||
* PulseAudio.
|
||||
*/
|
||||
#define GUAC_PULSE_AUDIO_FRAGMENT_SIZE 8192
|
||||
|
||||
/**
|
||||
* The minimum number of PCM bytes to wait for before flushing an audio
|
||||
* packet. The current value is 48K, which works out to be around 280ms.
|
||||
*/
|
||||
#define GUAC_PULSE_PCM_WRITE_RATE 49152
|
||||
|
||||
/**
|
||||
* Rate of audio to stream, in Hz.
|
||||
*/
|
||||
#define GUAC_PULSE_AUDIO_RATE 44100
|
||||
|
||||
/**
|
||||
* The number of channels to stream.
|
||||
*/
|
||||
#define GUAC_PULSE_AUDIO_CHANNELS 2
|
||||
|
||||
/**
|
||||
* The number of bits per sample.
|
||||
*/
|
||||
#define GUAC_PULSE_AUDIO_BPS 16
|
||||
|
||||
/**
|
||||
* An audio stream which connects to a PulseAudio server and streams the
|
||||
* received audio through a guac_client.
|
||||
*/
|
||||
typedef struct guac_pa_stream {
|
||||
|
||||
/**
|
||||
* The client associated with the audio stream.
|
||||
*/
|
||||
guac_client* client;
|
||||
|
||||
/**
|
||||
* Audio output stream.
|
||||
*/
|
||||
guac_audio_stream* audio;
|
||||
|
||||
/**
|
||||
* PulseAudio event loop.
|
||||
*/
|
||||
pa_threaded_mainloop* pa_mainloop;
|
||||
|
||||
} guac_pa_stream;
|
||||
|
||||
/**
|
||||
* Allocates a new PulseAudio audio stream for the given Guacamole client and
|
||||
* begins streaming.
|
||||
*
|
||||
* @param client
|
||||
* The client to stream audio to.
|
||||
*
|
||||
* @param server_name
|
||||
* The hostname of the PulseAudio server to connect to, or NULL to connect
|
||||
* to the default (local) server.
|
||||
*
|
||||
* @return
|
||||
* A newly-allocated PulseAudio stream, or NULL if audio cannot be
|
||||
* streamed.
|
||||
*/
|
||||
guac_pa_stream* guac_pa_stream_alloc(guac_client* client,
|
||||
const char* server_name);
|
||||
|
||||
/**
|
||||
* Notifies the given PulseAudio stream that a user has joined the connection.
|
||||
* The audio stream itself may need to be restarted. and the audio stream will
|
||||
* need to be created for the new user to ensure they can properly handle
|
||||
* future data received along the stream.
|
||||
*
|
||||
* @param stream
|
||||
* The guac_pa_stream associated with the Guacamole connection being
|
||||
* joined.
|
||||
*
|
||||
* @param user
|
||||
* The user that has joined the Guacamole connection.
|
||||
*/
|
||||
void guac_pa_stream_add_user(guac_pa_stream* stream, guac_user* user);
|
||||
|
||||
/**
|
||||
* Stops streaming audio from the given PulseAudio stream, freeing all
|
||||
* associated resources.
|
||||
*
|
||||
* @param stream
|
||||
* The PulseAudio stream to free.
|
||||
*/
|
||||
void guac_pa_stream_free(guac_pa_stream* stream);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user