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
f4c43472
Commit
f4c43472
authored
5 years ago
by
George Kiagiadakis
Browse files
Options
Downloads
Patches
Plain Diff
cli: extend with operations to list endpoints and change the default
parent
aa4fb5b1
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
tools/wireplumber-cli.c
+163
-5
163 additions, 5 deletions
tools/wireplumber-cli.c
with
163 additions
and
5 deletions
tools/wireplumber-cli.c
+
163
−
5
View file @
f4c43472
...
...
@@ -18,10 +18,126 @@ struct WpCliData
{
WpCore
*
core
;
GMainLoop
*
loop
;
union
{
struct
{
guint32
id
;
}
set_default
;
}
params
;
};
static
void
on_objects_changed
(
WpObjectManager
*
om
,
struct
WpCliData
*
d
)
print_dev_endpoint
(
WpEndpoint
*
ep
,
WpSession
*
session
,
WpDefaultEndpointType
type
)
{
guint32
id
=
wp_proxy_get_global_id
(
WP_PROXY
(
ep
));
gboolean
is_default
=
(
session
&&
type
!=
0
&&
wp_session_get_default_endpoint
(
session
,
type
)
==
id
);
g_print
(
" %c %4u. %s
\n
"
,
is_default
?
'*'
:
' '
,
id
,
wp_endpoint_get_name
(
ep
));
}
static
void
print_client_endpoint
(
WpEndpoint
*
ep
)
{
guint32
id
=
wp_proxy_get_global_id
(
WP_PROXY
(
ep
));
g_print
(
" %4u. %s (%s)
\n
"
,
id
,
wp_endpoint_get_name
(
ep
),
wp_endpoint_get_media_class
(
ep
));
}
static
void
list_endpoints
(
WpObjectManager
*
om
,
struct
WpCliData
*
d
)
{
g_autoptr
(
GPtrArray
)
arr
=
NULL
;
g_autoptr
(
WpSession
)
session
=
NULL
;
guint
i
;
arr
=
wp_object_manager_get_objects
(
om
,
WP_TYPE_PROXY_SESSION
);
if
(
arr
->
len
>
0
)
session
=
WP_SESSION
(
g_object_ref
(
g_ptr_array_index
(
arr
,
0
)));
g_clear_pointer
(
&
arr
,
g_ptr_array_unref
);
arr
=
wp_object_manager_get_objects
(
om
,
WP_TYPE_PROXY_ENDPOINT
);
g_print
(
"Audio capture devices:
\n
"
);
for
(
i
=
0
;
i
<
arr
->
len
;
i
++
)
{
WpEndpoint
*
ep
=
g_ptr_array_index
(
arr
,
i
);
if
(
g_strcmp0
(
wp_endpoint_get_media_class
(
ep
),
"Audio/Source"
)
==
0
)
print_dev_endpoint
(
ep
,
session
,
WP_DEFAULT_ENDPOINT_TYPE_AUDIO_SOURCE
);
}
g_print
(
"
\n
Audio playback devices:
\n
"
);
for
(
i
=
0
;
i
<
arr
->
len
;
i
++
)
{
WpEndpoint
*
ep
=
g_ptr_array_index
(
arr
,
i
);
if
(
g_strcmp0
(
wp_endpoint_get_media_class
(
ep
),
"Audio/Sink"
)
==
0
)
print_dev_endpoint
(
ep
,
session
,
WP_DEFAULT_ENDPOINT_TYPE_AUDIO_SINK
);
}
g_print
(
"
\n
Client streams:
\n
"
);
for
(
i
=
0
;
i
<
arr
->
len
;
i
++
)
{
WpEndpoint
*
ep
=
g_ptr_array_index
(
arr
,
i
);
if
(
g_str_has_suffix
(
wp_endpoint_get_media_class
(
ep
),
"/Audio"
))
print_client_endpoint
(
ep
);
}
g_main_loop_quit
(
d
->
loop
);
}
static
void
set_default_done
(
WpCore
*
core
,
GAsyncResult
*
res
,
struct
WpCliData
*
d
)
{
g_print
(
"Success
\n
"
);
g_main_loop_quit
(
d
->
loop
);
}
static
void
set_default
(
WpObjectManager
*
om
,
struct
WpCliData
*
d
)
{
g_autoptr
(
GPtrArray
)
arr
=
NULL
;
g_autoptr
(
WpSession
)
session
=
NULL
;
guint
i
;
arr
=
wp_object_manager_get_objects
(
om
,
WP_TYPE_PROXY_SESSION
);
if
(
arr
->
len
>
0
)
session
=
WP_SESSION
(
g_object_ref
(
g_ptr_array_index
(
arr
,
0
)));
g_clear_pointer
(
&
arr
,
g_ptr_array_unref
);
if
(
!
session
)
{
g_print
(
"No Session object - changing the default endpoint is not supported
\n
"
);
g_main_loop_quit
(
d
->
loop
);
return
;
}
arr
=
wp_object_manager_get_objects
(
om
,
WP_TYPE_PROXY_ENDPOINT
);
for
(
i
=
0
;
i
<
arr
->
len
;
i
++
)
{
WpEndpoint
*
ep
=
g_ptr_array_index
(
arr
,
i
);
guint32
id
=
wp_proxy_get_global_id
(
WP_PROXY
(
ep
));
if
(
id
==
d
->
params
.
set_default
.
id
)
{
WpDefaultEndpointType
type
;
if
(
g_strcmp0
(
wp_endpoint_get_media_class
(
ep
),
"Audio/Sink"
)
==
0
)
type
=
WP_DEFAULT_ENDPOINT_TYPE_AUDIO_SINK
;
else
if
(
g_strcmp0
(
wp_endpoint_get_media_class
(
ep
),
"Audio/Source"
)
==
0
)
type
=
WP_DEFAULT_ENDPOINT_TYPE_AUDIO_SOURCE
;
else
{
g_print
(
"%u: not a device endpoint
\n
"
,
id
);
g_main_loop_quit
(
d
->
loop
);
return
;
}
wp_session_set_default_endpoint
(
session
,
type
,
id
);
wp_core_sync
(
d
->
core
,
NULL
,
(
GAsyncReadyCallback
)
set_default_done
,
d
);
return
;
}
}
g_print
(
"%u: not an endpoint
\n
"
,
d
->
params
.
set_default
.
id
);
g_main_loop_quit
(
d
->
loop
);
}
static
void
device_node_props
(
WpObjectManager
*
om
,
struct
WpCliData
*
d
)
{
g_autoptr
(
GPtrArray
)
arr
=
NULL
;
guint
i
;
...
...
@@ -88,6 +204,13 @@ remote_state_changed (WpCore *core, WpRemoteState state,
}
}
static
const
gchar
*
const
usage_string
=
"Operations:
\n
"
" ls-endpoints
\t\t
Lists all endpoints
\n
"
" set-default [id]
\t
Sets [id] to be the default device endpoint of its kind (capture/playback)
\n
"
" device-node-props
\t
Shows device node properties
\n
"
""
;
gint
main
(
gint
argc
,
gchar
**
argv
)
{
...
...
@@ -100,6 +223,7 @@ main (gint argc, gchar **argv)
context
=
g_option_context_new
(
"- PipeWire Session/Policy Manager Helper CLI"
);
g_option_context_add_main_entries
(
context
,
entries
,
NULL
);
g_option_context_set_description
(
context
,
usage_string
);
if
(
!
g_option_context_parse
(
context
,
&
argc
,
&
argv
,
&
error
))
{
return
1
;
}
...
...
@@ -109,10 +233,44 @@ main (gint argc, gchar **argv)
(
GCallback
)
remote_state_changed
,
&
data
);
om
=
wp_object_manager_new
();
wp_object_manager_add_proxy_interest
(
om
,
PW_TYPE_INTERFACE_Node
,
NULL
,
WP_PROXY_FEATURE_INFO
);
g_signal_connect
(
om
,
"objects-changed"
,
(
GCallback
)
on_objects_changed
,
&
data
);
if
(
argc
==
2
&&
!
g_strcmp0
(
argv
[
1
],
"ls-endpoints"
))
{
wp_object_manager_add_proxy_interest
(
om
,
PW_TYPE_INTERFACE_Endpoint
,
NULL
,
WP_PROXY_FEATURE_INFO
|
WP_PROXY_ENDPOINT_FEATURE_CONTROLS
);
wp_object_manager_add_proxy_interest
(
om
,
PW_TYPE_INTERFACE_Session
,
NULL
,
WP_PROXY_FEATURE_INFO
|
WP_PROXY_SESSION_FEATURE_DEFAULT_ENDPOINT
);
g_signal_connect
(
om
,
"objects-changed"
,
(
GCallback
)
list_endpoints
,
&
data
);
}
else
if
(
argc
==
3
&&
!
g_strcmp0
(
argv
[
1
],
"set-default"
))
{
long
id
=
strtol
(
argv
[
2
],
NULL
,
10
);
if
(
id
==
0
)
{
g_print
(
"%s: not a valid id
\n
"
,
argv
[
2
]);
return
1
;
}
wp_object_manager_add_proxy_interest
(
om
,
PW_TYPE_INTERFACE_Endpoint
,
NULL
,
WP_PROXY_FEATURE_INFO
|
WP_PROXY_ENDPOINT_FEATURE_CONTROLS
);
wp_object_manager_add_proxy_interest
(
om
,
PW_TYPE_INTERFACE_Session
,
NULL
,
WP_PROXY_FEATURE_INFO
|
WP_PROXY_SESSION_FEATURE_DEFAULT_ENDPOINT
);
data
.
params
.
set_default
.
id
=
id
;
g_signal_connect
(
om
,
"objects-changed"
,
(
GCallback
)
set_default
,
&
data
);
}
else
if
(
argc
==
2
&&
!
g_strcmp0
(
argv
[
1
],
"device-node-props"
))
{
wp_object_manager_add_proxy_interest
(
om
,
PW_TYPE_INTERFACE_Node
,
NULL
,
WP_PROXY_FEATURE_INFO
);
g_signal_connect
(
om
,
"objects-changed"
,
(
GCallback
)
device_node_props
,
&
data
);
}
else
{
g_autofree
gchar
*
help
=
g_option_context_get_help
(
context
,
TRUE
,
NULL
);
g_print
(
help
);
return
1
;
}
wp_core_install_object_manager
(
core
,
om
);
wp_core_connect
(
core
);
...
...
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