PipeWire 0.3.77
Loading...
Searching...
No Matches
internal.c

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 <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_properties *props;
const char *dev = "hw:0";
pw_init(&argc, &argv);
data.loop = pw_main_loop_new(NULL);
if (argc > 1)
dev = argv[1];
pw_loop_add_signal(pw_main_loop_get_loop(data.loop), SIGINT, do_quit, &data);
pw_loop_add_signal(pw_main_loop_get_loop(data.loop), SIGTERM, do_quit, &data);
data.context = pw_context_new(pw_main_loop_get_loop(data.loop),
PW_KEY_CONFIG_NAME, "client-rt.conf",
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;
}
SPA_KEY_LIBRARY_NAME, "audiotestsrc/libspa-audiotestsrc",
SPA_KEY_FACTORY_NAME, "audiotestsrc",
PW_KEY_NODE_NAME, "test_source",
"Spa:Pod:Object:Param:Props:live", "false",
NULL);
data.source = pw_core_create_object(data.core,
"spa-node-factory",
&props->dict, 0);
SPA_KEY_LIBRARY_NAME, "alsa/libspa-alsa",
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",
&props->dict, 0);
while (true) {
if (pw_proxy_get_bound_id(data.source) != SPA_ID_INVALID &&
break;
}
data.link = pw_core_create_object(data.core,
"link-factory",
&props->dict, 0);
pw_main_loop_run(data.loop);
cleanup:
pw_context_destroy(data.context);
return data.res;
}
void pw_context_destroy(struct pw_context *context)
destroy a context object, all resources except the main_loop will be destroyed
Definition: context.c:384
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:172
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:442
static 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)
Definition: core.h:416
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:137
#define PW_KEY_LINK_INPUT_NODE
input node id of a link
Definition: src/pipewire/keys.h:303
#define PW_KEY_CONFIG_NAME
a config file name
Definition: src/pipewire/keys.h:82
#define PW_KEY_LINK_OUTPUT_NODE
output node id of a link
Definition: src/pipewire/keys.h:307
#define PW_KEY_NODE_NAME
node name
Definition: src/pipewire/keys.h:182
#define pw_loop_iterate(l,...)
Definition: src/pipewire/loop.h:53
#define pw_loop_add_signal(l,...)
Definition: src/pipewire/loop.h:63
int pw_main_loop_quit(struct pw_main_loop *loop)
Quit a main loop.
Definition: main-loop.c:105
void pw_main_loop_destroy(struct pw_main_loop *loop)
Destroy a loop.
Definition: main-loop.c:70
int pw_main_loop_run(struct pw_main_loop *loop)
Run a main loop.
Definition: main-loop.c:119
struct pw_main_loop * pw_main_loop_new(const struct spa_dict *props)
Create a new main loop.
Definition: main-loop.c:60
struct pw_loop * pw_main_loop_get_loop(struct pw_main_loop *loop)
Get the loop implementation.
Definition: main-loop.c:93
#define PW_TYPE_INTERFACE_Node
Definition: src/pipewire/node.h:35
#define PW_VERSION_NODE
Definition: src/pipewire/node.h:41
void pw_init(int *argc, char **argv[])
Initialize PipeWire.
Definition: pipewire.c:555
void pw_deinit(void)
Deinitialize PipeWire.
Definition: pipewire.c:668
void pw_properties_free(struct pw_properties *properties)
Free a properties object.
Definition: properties.c:350
struct pw_properties * pw_properties_new(const char *key,...) 1
Make a new properties object.
Definition: properties.c:84
int pw_properties_setf(struct pw_properties *properties, const char *key, const char *format,...) 1(3
void pw_properties_clear(struct pw_properties *properties)
Clear a properties object.
Definition: properties.c:263
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:149
#define SPA_KEY_FACTORY_NAME
the name of a factory
Definition: plugin.h:202
#define SPA_KEY_LIBRARY_NAME
the name of a library.
Definition: plugin.h:211
#define SPA_NAME_API_ALSA_PCM_SINK
an alsa Node interface for playback PCM
Definition: names.h:109
#define SPA_ID_INVALID
Definition: defs.h:228
pipewire/impl.h
spa/utils/names.h
pipewire/pipewire.h
A main loop object.
Definition: properties.h:33
struct spa_dict dict
dictionary of key/values
Definition: properties.h:34