Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plasma 5.26 does not like PA_PROP_DEVICE_CLASS abstract #91

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 104 additions & 3 deletions src/module-xrdp-sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ PA_MODULE_USAGE(
"rate=<sample rate> "
"channels=<number of channels> "
"channel_map=<channel map> "
"description=<description for the sink> "
"xrdp_socket_path=<path to XRDP sockets> "
"xrdp_pulse_sink_socket=<name of sink socket>");

Expand All @@ -101,6 +102,8 @@ struct userdata {
pa_core *core;
pa_module *module;
pa_sink *sink;
pa_device_port *port;
pa_card *card;

pa_thread *thread;
pa_thread_mq thread_mq;
Expand All @@ -126,11 +129,81 @@ static const char* const valid_modargs[] = {
"channel_map",
"xrdp_socket_path",
"xrdp_pulse_sink_socket",
"description",
NULL
};

static int close_send(struct userdata *u);

static pa_device_port *xrdp_create_port(struct userdata *u) {
pa_device_port_new_data data;
pa_device_port *port;

pa_device_port_new_data_init(&data);

pa_device_port_new_data_set_name(&data, "xrdp-output");
pa_device_port_new_data_set_description(&data, "xrdp output");
pa_device_port_new_data_set_direction(&data, PA_DIRECTION_OUTPUT);
pa_device_port_new_data_set_available(&data, PA_AVAILABLE_YES);
#if defined(PA_CHECK_VERSION) && PA_CHECK_VERSION(14, 0, 0)
pa_device_port_new_data_set_type(&data, PA_DEVICE_PORT_TYPE_NETWORK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pa_device_port_new_data_set_type() was added for PA 14 (pull request here). This line fails to compile on Ubuntu 20.04 and CentOS 7. I'd suggest bracketing it with a version test like this:-

#if defined(PA_CHECK_VERSION) && PA_CHECK_VERSION(14, 0, 0)
    pa_device_port_new_data_set_type(&data, PA_DEVICE_PORT_TYPE_NETWORK);
#endif

#endif

port = pa_device_port_new(u->core, &data, 0);

pa_device_port_new_data_done(&data);

if (port == NULL)
{
return NULL;
}

pa_device_port_ref(port);

return port;
}

static pa_card_profile *xrdp_create_profile() {
pa_card_profile *profile;

profile = pa_card_profile_new("output:xrdp", "xrdp audio output", 0);
profile->priority = 10;
profile->n_sinks = 1;
profile->n_sources = 0;
profile->max_sink_channels = 2;
profile->max_source_channels = 0;

return profile;
}

static pa_card *xrdp_create_card(pa_module *m, pa_device_port *port, pa_card_profile *profile) {
pa_card_new_data data;
pa_card *card;

pa_card_new_data_init(&data);
data.driver = __FILE__;

pa_card_new_data_set_name(&data, "xrdp.sink");

pa_hashmap_put(data.ports, port->name, port);
pa_hashmap_put(data.profiles, profile->name, profile);

card = pa_card_new(m->core, &data);

pa_card_new_data_done(&data);

if (card == NULL)
{
return NULL;
}

pa_card_choose_initial_profile(card);

pa_card_put(card);

return card;
}

static int sink_process_msg(pa_msgobject *o, int code, void *data,
int64_t offset, pa_memchunk *chunk) {

Expand Down Expand Up @@ -513,6 +586,8 @@ static void set_sink_socket(pa_modargs *ma, struct userdata *u) {

int pa__init(pa_module*m) {
struct userdata *u = NULL;
pa_device_port *port;
pa_card_profile *profile;
pa_sample_spec ss;
pa_channel_map map;
pa_modargs *ma = NULL;
Expand Down Expand Up @@ -558,18 +633,39 @@ int pa__init(pa_module*m) {
pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME));
pa_sink_new_data_set_sample_spec(&data, &ss);
pa_sink_new_data_set_channel_map(&data, &map);
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "xrdp sink");
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "abstract");
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, pa_modargs_get_value(ma, "description", "remote audio output"));
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "sound");
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_FORM_FACTOR, "computer");
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PRODUCT_NAME, "xrdp");


if (pa_modargs_get_proplist(ma, "sink_properties", data.proplist,
PA_UPDATE_REPLACE) < 0) {
pa_log("Invalid properties");
pa_sink_new_data_done(&data);
goto fail;
}
port = xrdp_create_port(u);
if (port == NULL) {
pa_log("Failed to create port object");
goto fail;
}

profile = xrdp_create_profile();

pa_hashmap_put(port->profiles, profile->name, profile);

u->card = xrdp_create_card(m, port, profile);
if (u->card == NULL) {
pa_log("Failed to create card object");
goto fail;
}

data.card = u->card;
pa_hashmap_put(data.ports, port->name, port);

u->sink = pa_sink_new(m->core, &data,
PA_SINK_LATENCY | PA_SINK_DYNAMIC_LATENCY);
PA_SINK_LATENCY | PA_SINK_DYNAMIC_LATENCY | PA_SINK_NETWORK | PA_SINK_HARDWARE);
pa_sink_new_data_done(&data);

if (!u->sink) {
Expand Down Expand Up @@ -666,6 +762,11 @@ void pa__done(pa_module*m) {
pa_rtpoll_free(u->rtpoll);
}

if (u->card)
{
pa_card_free(u->card);
}

if (u->fd >= 0)
{
close(u->fd);
Expand Down
110 changes: 104 additions & 6 deletions src/module-xrdp-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ struct userdata {
pa_core *core;
pa_module *module;
pa_source *source;
pa_device_port *port;
pa_card *card;

pa_thread *thread;
pa_thread_mq thread_mq;
Expand Down Expand Up @@ -111,6 +113,75 @@ static const char* const valid_modargs[] = {
NULL
};

static pa_device_port *xrdp_create_port(struct userdata *u) {
pa_device_port_new_data data;
pa_device_port *port;

pa_device_port_new_data_init(&data);

pa_device_port_new_data_set_name(&data, "xrdp-input");
pa_device_port_new_data_set_description(&data, "xrdp input");
pa_device_port_new_data_set_direction(&data, PA_DIRECTION_INPUT);
pa_device_port_new_data_set_available(&data, PA_AVAILABLE_YES);
#if defined(PA_CHECK_VERSION) && PA_CHECK_VERSION(14, 0, 0)
pa_device_port_new_data_set_type(&data, PA_DEVICE_PORT_TYPE_NETWORK);
#endif

port = pa_device_port_new(u->core, &data, 0);

pa_device_port_new_data_done(&data);

if (port == NULL)
{
return NULL;
}

pa_device_port_ref(port);

return port;
}

static pa_card_profile *xrdp_create_profile() {
pa_card_profile *profile;

profile = pa_card_profile_new("input:xrdp", "xrdp audio input", 0);
profile->priority = 10;
profile->n_sinks = 0;
profile->n_sources = 1;
profile->max_sink_channels = 0;
profile->max_source_channels = 2;

return profile;
}

static pa_card *xrdp_create_card(pa_module *m, pa_device_port *port, pa_card_profile *profile) {
pa_card_new_data data;
pa_card *card;

pa_card_new_data_init(&data);
data.driver = __FILE__;

pa_card_new_data_set_name(&data, "xrdp.source");

pa_hashmap_put(data.ports, port->name, port);
pa_hashmap_put(data.profiles, profile->name, profile);

card = pa_card_new(m->core, &data);

pa_card_new_data_done(&data);

if (card == NULL)
{
return NULL;
}

pa_card_choose_initial_profile(card);

pa_card_put(card);

return card;
}

static int get_display_num_from_display(const char *display_text) ;

static int source_process_msg(pa_msgobject *o, int code, void *data,
Expand Down Expand Up @@ -400,6 +471,8 @@ static void set_source_socket(pa_modargs *ma, struct userdata *u) {

int pa__init(pa_module *m) {
struct userdata *u = NULL;
pa_device_port *port;
pa_card_profile *profile;
pa_sample_spec ss;
pa_channel_map map;
pa_modargs *ma = NULL;
Expand Down Expand Up @@ -454,10 +527,32 @@ int pa__init(pa_module *m) {
pa_source_new_data_set_name(&data, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME));
pa_source_new_data_set_sample_spec(&data, &ss);
pa_source_new_data_set_channel_map(&data, &map);
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, pa_modargs_get_value(ma, "description", "xrdp source"));
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "abstract");
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_DESCRIPTION, pa_modargs_get_value(ma, "description", "remote audio input"));
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_CLASS, "sound");
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_FORM_FACTOR, "microphone");
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_PRODUCT_NAME, "xrdp");

port = xrdp_create_port(u);
if (port == NULL) {
pa_log("Failed to create port object");
goto fail;
}

profile = xrdp_create_profile();

u->source = pa_source_new(m->core, &data, PA_SOURCE_LATENCY | PA_SOURCE_DYNAMIC_LATENCY);
pa_hashmap_put(port->profiles, profile->name, profile);

u->card = xrdp_create_card(m, port, profile);
if (u->card == NULL) {
pa_log("Failed to create card object");
goto fail;
}

data.card = u->card;
pa_hashmap_put(data.ports, port->name, port);

u->source = pa_source_new(m->core, &data, PA_SOURCE_LATENCY |
PA_SOURCE_DYNAMIC_LATENCY | PA_SOURCE_NETWORK | PA_SOURCE_HARDWARE);
pa_source_new_data_done(&data);

if (!u->source) {
Expand Down Expand Up @@ -528,16 +623,14 @@ void pa__done(pa_module*m) {
if (u->source)
pa_source_unlink(u->source);


if (u->thread) {
pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
pa_thread_free(u->thread);
}

pa_thread_mq_done(&u->thread_mq);

if (u->source)
pa_source_unref(u->source);

if (u->rtpoll)
pa_rtpoll_free(u->rtpoll);

Expand All @@ -547,6 +640,11 @@ void pa__done(pa_module*m) {
u->fd = -1;
}

if (u->card)
{
pa_card_free(u->card);
}

pa_xfree(u->source_socket);
pa_xfree(u);
}
Expand Down