Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wireplumber
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pkg
wireplumber
Commits
21e9f0d9
Commit
21e9f0d9
authored
5 years ago
by
Julian Bouzas
Browse files
Options
Downloads
Patches
Plain Diff
alsa-udev: add listener to created audio softdsp endpoints when alsa nodes are created
parent
2fd0f631
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/module-pw-alsa-udev.c
+136
-0
136 additions, 0 deletions
modules/module-pw-alsa-udev.c
with
136 additions
and
0 deletions
modules/module-pw-alsa-udev.c
+
136
−
0
View file @
21e9f0d9
...
...
@@ -14,7 +14,143 @@
#include
<wp/wp.h>
#include
<pipewire/pipewire.h>
#define NAME "module-pw-alsa-udev"
struct
impl
{
WpCore
*
wp_core
;
struct
pw_remote
*
remote
;
struct
spa_hook
remote_listener
;
struct
pw_registry_proxy
*
registry_proxy
;
struct
spa_hook
registry_listener
;
};
static
void
handle_node
(
struct
impl
*
impl
,
uint32_t
id
,
uint32_t
parent_id
,
const
struct
spa_dict
*
props
)
{
const
gchar
*
media_class
=
NULL
,
*
node_name
=
NULL
;
struct
spa_proxy
*
proxy
=
NULL
;
GVariantBuilder
b
;
g_autoptr
(
GVariant
)
endpoint_props
=
NULL
;
/* Make sure the node has properties */
if
(
!
props
)
{
g_warning
(
NAME
" %p: node has no properties, skipping..."
,
impl
);
return
;
}
/* Make sure the media class is audio */
/* FIXME: need to handle only alsa nodes */
media_class
=
spa_dict_lookup
(
props
,
"media.class"
);
if
(
!
g_str_has_prefix
(
media_class
,
"Audio/"
))
return
;
/* Get the device name */
node_name
=
spa_dict_lookup
(
props
,
"node.name"
);
/* Get the proxy */
proxy
=
pw_registry_proxy_bind
(
impl
->
registry_proxy
,
id
,
PW_TYPE_INTERFACE_Node
,
PW_VERSION_NODE
,
0
);
/* Build the GVariant properties for the endpoint */
g_variant_builder_init
(
&
b
,
G_VARIANT_TYPE_VARDICT
);
g_variant_builder_add
(
&
b
,
"{sv}"
,
"name"
,
g_variant_new_take_string
(
g_strdup_printf
(
"Endpoint %u: %s"
,
id
,
node_name
)));
g_variant_builder_add
(
&
b
,
"{sv}"
,
"media-class"
,
g_variant_new_string
(
media_class
));
g_variant_builder_add
(
&
b
,
"{sv}"
,
"node-proxy"
,
g_variant_new_uint64
((
guint64
)
proxy
));
endpoint_props
=
g_variant_builder_end
(
&
b
);
/* Create the endpoint */
wp_factory_make
(
impl
->
wp_core
,
"pw-audio-softdsp-endpoint"
,
WP_TYPE_ENDPOINT
,
endpoint_props
);
}
static
void
registry_global
(
void
*
data
,
uint32_t
id
,
uint32_t
parent_id
,
uint32_t
permissions
,
uint32_t
type
,
uint32_t
version
,
const
struct
spa_dict
*
props
)
{
struct
impl
*
impl
=
data
;
/* Only handle nodes */
switch
(
type
)
{
case
PW_TYPE_INTERFACE_Node
:
handle_node
(
impl
,
id
,
parent_id
,
props
);
break
;
default:
break
;
}
}
static
const
struct
pw_registry_proxy_events
registry_events
=
{
PW_VERSION_REGISTRY_PROXY_EVENTS
,
.
global
=
registry_global
,
};
static
void
on_state_changed
(
void
*
_data
,
enum
pw_remote_state
old
,
enum
pw_remote_state
state
,
const
char
*
error
)
{
struct
impl
*
impl
=
_data
;
struct
pw_core_proxy
*
core_proxy
;
switch
(
state
)
{
case
PW_REMOTE_STATE_CONNECTED
:
core_proxy
=
pw_remote_get_core_proxy
(
impl
->
remote
);
impl
->
registry_proxy
=
pw_core_proxy_get_registry
(
core_proxy
,
PW_TYPE_INTERFACE_Registry
,
PW_VERSION_REGISTRY
,
0
);
pw_registry_proxy_add_listener
(
impl
->
registry_proxy
,
&
impl
->
registry_listener
,
&
registry_events
,
impl
);
break
;
case
PW_REMOTE_STATE_ERROR
:
/* TODO quit wireplumber */
break
;
case
PW_REMOTE_STATE_UNCONNECTED
:
/* TODO quit wireplumber */
break
;
default:
break
;
}
}
static
const
struct
pw_remote_events
remote_events
=
{
PW_VERSION_REMOTE_EVENTS
,
.
state_changed
=
on_state_changed
,
};
static
void
module_destroy
(
gpointer
data
)
{
struct
impl
*
impl
=
data
;
g_debug
(
"module-pipewire destroy"
);
g_slice_free
(
struct
impl
,
impl
);
}
void
wireplumber__module_init
(
WpModule
*
module
,
WpCore
*
core
,
GVariant
*
args
)
{
/* This needs to create the alsa sink and alsa source nodes, but since
* this is already implemented in the alsa-module of pipewire, for now
* we just listen for the alsa nodes created by pipewire. We eventually
* need to move all the node creation logic here */
/* Create the impl */
struct
impl
*
impl
=
g_new0
(
struct
impl
,
1
);
impl
->
wp_core
=
core
;
impl
->
remote
=
wp_core_get_global
(
core
,
WP_GLOBAL_PW_REMOTE
);
/* Set destroy callback for impl */
wp_module_set_destroy_callback
(
module
,
module_destroy
,
impl
);
/* Add a state changed listener */
pw_remote_add_listener
(
impl
->
remote
,
&
impl
->
remote_listener
,
&
remote_events
,
impl
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment