PipeWire 1.4.5 |

Loading...
Searching...
No Matches
internal.c

In process pipewire graph

In process pipewire graph

/* PipeWire */
/* SPDX-FileCopyrightText: Copyright © 2023 Wim Taymans */
/* SPDX-License-Identifier: MIT */
/*
[title]
In process pipewire graph
[title]
*/
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <math.h>
#include <spa/utils/names.h>
#include <pipewire/pipewire.h>
#include <pipewire/impl.h>
struct data {
struct pw_main_loop *loop;
struct pw_context *context;
struct pw_core *core;
struct pw_proxy *source;
struct pw_proxy *sink;
struct pw_proxy *link;
int res;
};
static void do_quit(void *userdata, int signal_number)
{
struct data *data = userdata;
pw_main_loop_quit(data->loop);
}
int main(int argc, char *argv[])
{
struct data data = { 0, };
struct pw_loop *loop;
struct pw_properties *props;
const char *dev = "hw:0";
pw_init(&argc, &argv);
data.loop = pw_main_loop_new(NULL);
loop = pw_main_loop_get_loop(data.loop);
if (argc > 1)
dev = argv[1];
pw_loop_add_signal(loop, SIGINT, do_quit, &data);
pw_loop_add_signal(loop, SIGTERM, do_quit, &data);
data.context = pw_context_new(loop, NULL, 0);
pw_context_load_module(data.context, "libpipewire-module-spa-node-factory", NULL, NULL);
pw_context_load_module(data.context, "libpipewire-module-link-factory", NULL, NULL);
data.core = pw_context_connect_self(data.context, NULL, 0);
if (data.core == NULL) {
fprintf(stderr, "can't connect: %m\n");
data.res = -errno;
goto cleanup;
}
props = pw_properties_new(
SPA_KEY_LIBRARY_NAME, "audiotestsrc/libspa-audiotestsrc",
SPA_KEY_FACTORY_NAME, "audiotestsrc",
PW_KEY_NODE_NAME, "test_source",
"node.param.Props", "{ live = false }",
NULL);
data.source = pw_core_create_object(data.core,
"spa-node-factory",
PW_TYPE_INTERFACE_Node,
PW_VERSION_NODE,
&props->dict, 0);
pw_properties_free(props);
props = pw_properties_new(
SPA_KEY_LIBRARY_NAME, "alsa/libspa-alsa",
SPA_KEY_FACTORY_NAME, SPA_NAME_API_ALSA_PCM_SINK,
PW_KEY_NODE_NAME, "alsa_sink",
"api.alsa.path", dev,
"priority.driver", "1000",
NULL);
data.sink = pw_core_create_object(data.core,
"spa-node-factory",
PW_TYPE_INTERFACE_Node,
PW_VERSION_NODE,
&props->dict, 0);
pw_loop_enter(loop);
while (true) {
if (pw_proxy_get_bound_id(data.source) != SPA_ID_INVALID &&
pw_proxy_get_bound_id(data.sink) != SPA_ID_INVALID)
break;
pw_loop_iterate(loop, -1);
}
pw_loop_leave(loop);
pw_properties_clear(props);
pw_properties_setf(props,
PW_KEY_LINK_OUTPUT_NODE, "%d", pw_proxy_get_bound_id(data.source));
pw_properties_setf(props,
PW_KEY_LINK_INPUT_NODE, "%d", pw_proxy_get_bound_id(data.sink));
data.link = pw_core_create_object(data.core,
"link-factory",
PW_TYPE_INTERFACE_Link,
PW_VERSION_LINK,
&props->dict, 0);
pw_properties_free(props);
pw_main_loop_run(data.loop);
cleanup:
pw_context_destroy(data.context);
pw_main_loop_destroy(data.loop);
pw_deinit();
return data.res;
}
pw_context_destroy
void pw_context_destroy(struct pw_context *context)
destroy a context object, all resources except the main_loop will be destroyed
Definition context.c:522
pw_context_new
struct pw_context * pw_context_new(struct pw_loop *main_loop, struct pw_properties *props, size_t user_data_size)
Make a new context object for a given main_loop.
Definition context.c:310
pw_context_connect_self
struct pw_core * pw_context_connect_self(struct pw_context *context, struct pw_properties *properties, size_t user_data_size)
Connect to a given PipeWire instance.
Definition core.c:462
pw_core_create_object
PW_API_CORE_IMPL void * pw_core_create_object(struct pw_core *core, const char *factory_name, const char *type, uint32_t version, const struct spa_dict *props, size_t user_data_size)
Create a new object on the PipeWire server from a factory.
Definition core.h:466
res
uint32_t int int res
Definition core.h:433
pw_context_load_module
struct pw_impl_module * pw_context_load_module(struct pw_context *context, const char *name, const char *args, struct pw_properties *properties)
Load a module.
Definition impl-module.c:139
PW_KEY_LINK_INPUT_NODE
#define PW_KEY_LINK_INPUT_NODE
input node id of a link
Definition keys.h:367
PW_KEY_LINK_OUTPUT_NODE
#define PW_KEY_LINK_OUTPUT_NODE
output node id of a link
Definition keys.h:371
PW_KEY_NODE_NAME
#define PW_KEY_NODE_NAME
node name
Definition keys.h:208
PW_TYPE_INTERFACE_Link
#define PW_TYPE_INTERFACE_Link
Definition link.h:37
PW_VERSION_LINK
#define PW_VERSION_LINK
Definition link.h:43
pw_loop_enter
PW_API_LOOP_IMPL void pw_loop_enter(struct pw_loop *object)
Definition loop.h:83
pw_loop_add_signal
PW_API_LOOP_IMPL struct spa_source * pw_loop_add_signal(struct pw_loop *object, int signal_number, spa_source_signal_func_t func, void *data)
Definition loop.h:141
pw_loop_leave
PW_API_LOOP_IMPL void pw_loop_leave(struct pw_loop *object)
Definition loop.h:87
pw_loop_iterate
PW_API_LOOP_IMPL int pw_loop_iterate(struct pw_loop *object, int timeout)
Definition loop.h:91
pw_main_loop_quit
int pw_main_loop_quit(struct pw_main_loop *loop)
Quit a main loop.
Definition main-loop.c:108
pw_main_loop_destroy
void pw_main_loop_destroy(struct pw_main_loop *loop)
Destroy a loop.
Definition main-loop.c:73
pw_main_loop_run
int pw_main_loop_run(struct pw_main_loop *loop)
Run a main loop.
Definition main-loop.c:122
pw_main_loop_new
struct pw_main_loop * pw_main_loop_new(const struct spa_dict *props)
Create a new main loop.
Definition main-loop.c:63
pw_main_loop_get_loop
struct pw_loop * pw_main_loop_get_loop(struct pw_main_loop *loop)
Get the loop implementation.
Definition main-loop.c:96
PW_TYPE_INTERFACE_Node
#define PW_TYPE_INTERFACE_Node
Definition node.h:35
PW_VERSION_NODE
#define PW_VERSION_NODE
Definition node.h:41
pw_init
void pw_init(int *argc, char **argv[])
Initialize PipeWire.
Definition pipewire.c:488
pw_deinit
void pw_deinit(void)
Deinitialize PipeWire.
Definition pipewire.c:603
pw_properties_free
void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition properties.c:558
pw_properties_new
struct pw_properties * pw_properties_new(const char *key,...)
Make a new properties object.
Definition properties.c:97
pw_properties_setf
int pw_properties_setf(struct pw_properties *properties, const char *key, const char *format,...)
Set a property value by format.
Definition properties.c:616
pw_properties_clear
void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition properties.c:456
pw_proxy_get_bound_id
uint32_t pw_proxy_get_bound_id(struct pw_proxy *proxy)
Get the global id bound to this proxy of SPA_ID_INVALID when not bound to a global.
Definition proxy.c:150
SPA_KEY_FACTORY_NAME
#define SPA_KEY_FACTORY_NAME
the name of a factory
Definition plugin.h:242
SPA_KEY_LIBRARY_NAME
#define SPA_KEY_LIBRARY_NAME
the name of a library.
Definition plugin.h:251
SPA_NAME_API_ALSA_PCM_SINK
#define SPA_NAME_API_ALSA_PCM_SINK
an alsa Node interface for playback PCM
Definition names.h:112
SPA_ID_INVALID
#define SPA_ID_INVALID
Definition defs.h:250
impl.h
pipewire/impl.h
names.h
spa/utils/names.h
pipewire.h
pipewire/pipewire.h
pw_context
pw_core
pw_loop
Definition loop.h:33
pw_loop::loop
struct spa_loop * loop
wrapped loop
Definition loop.h:35
pw_main_loop
A main loop object.
pw_properties
Definition properties.h:39
pw_properties::dict
struct spa_dict dict
dictionary of key/values
Definition properties.h:40
pw_proxy