summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2019-12-04 13:17:53 +0100
committerWim Taymans <wtaymans@redhat.com>2019-12-04 13:17:53 +0100
commit9efe32b45cb461fd058791a1c94e587b9ef15e1d (patch)
tree8c2d801e8c0d6a6d7dab9701fbc0e8e375946211 /src/examples
parent97915b352915c1ddcac793654d37f1eef51ccc5a (diff)
more API refactoringAPI
Try to remove the pw_remote from view and work directly with the pw_core proxies.
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/audio-dsp-filter.c9
-rw-r--r--src/examples/export-sink.c79
-rw-r--r--src/examples/export-source.c46
-rw-r--r--src/examples/export-spa-device.c58
-rw-r--r--src/examples/export-spa.c52
-rw-r--r--src/examples/media-session/media-session.c1
-rw-r--r--src/examples/video-src.c111
7 files changed, 139 insertions, 217 deletions
diff --git a/src/examples/audio-dsp-filter.c b/src/examples/audio-dsp-filter.c
index 3b9d0f70..dbb23899 100644
--- a/src/examples/audio-dsp-filter.c
+++ b/src/examples/audio-dsp-filter.c
@@ -22,15 +22,6 @@
* DEALINGS IN THE SOFTWARE.
*/
-#include <stdio.h>
-#include <errno.h>
-#include <time.h>
-#include <math.h>
-#include <sys/mman.h>
-
-#include <spa/param/audio/format-utils.h>
-#include <spa/param/props.h>
-
#include <pipewire/pipewire.h>
#include <pipewire/filter.h>
diff --git a/src/examples/export-sink.c b/src/examples/export-sink.c
index 5e686698..4524b254 100644
--- a/src/examples/export-sink.c
+++ b/src/examples/export-sink.c
@@ -68,10 +68,8 @@ struct data {
struct pw_main_loop *loop;
- struct pw_impl_core *core;
-
- struct pw_remote *remote;
- struct spa_hook remote_listener;
+ struct pw_core *core;
+ struct spa_hook core_listener;
struct spa_node impl_node;
struct spa_hook_list hooks;
@@ -473,47 +471,42 @@ static void make_node(struct data *data)
SPA_TYPE_INTERFACE_Node,
SPA_VERSION_NODE,
&impl_node, data);
- pw_remote_export(data->remote, SPA_TYPE_INTERFACE_Node, props, &data->impl_node, 0);
+ pw_core_export_object(data->core,
+ SPA_TYPE_INTERFACE_Node,
+ &props->dict,
+ &data->impl_node.iface, 0);
}
-static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remote_state state, const char *error)
+static void set_permissions(struct data *data)
{
- struct data *data = _data;
-
- switch (state) {
- case PW_REMOTE_STATE_ERROR:
- printf("remote error: %s\n", error);
- pw_main_loop_quit(data->loop);
- break;
-
- case PW_REMOTE_STATE_CONNECTED:
- {
- struct pw_permission permissions[2];
-
- /* an example, set specific permissions on one object, this is the
- * core object. */
- permissions[0].id = 0;
- permissions[0].permissions = PW_PERM_R | PW_PERM_X;
- /* remove WX from all other objects */
- permissions[1].id = SPA_ID_INVALID;
- permissions[1].permissions = PW_PERM_R;
+ struct pw_permission permissions[2];
+
+ /* an example, set specific permissions on one object, this is the
+ * core object. */
+ permissions[0].id = 0;
+ permissions[0].permissions = PW_PERM_R | PW_PERM_X;
+ /* remove WX from all other objects */
+ permissions[1].id = SPA_ID_INVALID;
+ permissions[1].permissions = PW_PERM_R;
+
+ pw_client_update_permissions(
+ pw_core_get_client(data->core),
+ 2, permissions);
+}
- pw_client_update_permissions(
- pw_remote_get_client(data->remote),
- 2, permissions);
+static void on_error(void *object, uint32_t id, int seq, int res, const char *message)
+{
+ struct data *data = object;
- make_node(data);
- break;
- }
- default:
- printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
- break;
+ printf("error: %s\n", message);
+ if (id == 0) {
+ pw_main_loop_quit(data->loop);
}
}
-static const struct pw_remote_events remote_events = {
- PW_VERSION_REMOTE_EVENTS,
- .state_changed = on_state_changed,
+static const struct pw_core_events core_events = {
+ PW_VERSION_CORE_EVENTS,
+ .error = on_error,
};
int main(int argc, char *argv[])
@@ -523,8 +516,7 @@ int main(int argc, char *argv[])
pw_init(&argc, &argv);
data.loop = pw_main_loop_new(NULL);
- data.core = pw_impl_core_new(pw_main_loop_get_loop(data.loop), NULL, 0);
- data.remote = pw_remote_new(data.core, NULL, 0);
+ data.core = pw_core_connect(pw_main_loop_get_loop(data.loop), NULL, 0);
data.path = argc > 1 ? argv[1] : NULL;
spa_hook_list_init(&data.hooks);
@@ -554,14 +546,15 @@ int main(int argc, char *argv[])
return -1;
}
- pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);
+ pw_core_add_listener(data.core, &data.core_listener, &core_events, &data);
- if (pw_remote_connect(data.remote) < 0)
- return -1;
+ set_permissions(&data);
+
+ make_node(&data);
pw_main_loop_run(data.loop);
- pw_impl_core_destroy(data.core);
+ pw_core_disconnect(data.core);
pw_main_loop_destroy(data.loop);
return 0;
diff --git a/src/examples/export-source.c b/src/examples/export-source.c
index 1716da49..ff0e8c21 100644
--- a/src/examples/export-source.c
+++ b/src/examples/export-source.c
@@ -53,10 +53,8 @@ struct data {
struct pw_main_loop *loop;
- struct pw_impl_core *core;
-
- struct pw_remote *remote;
- struct spa_hook remote_listener;
+ struct pw_core *core;
+ struct spa_hook core_listener;
uint64_t info_all;
struct spa_port_info info;
@@ -481,33 +479,26 @@ static void make_node(struct data *data)
SPA_TYPE_INTERFACE_Node,
SPA_VERSION_NODE,
&impl_node, data);
- pw_remote_export(data->remote, SPA_TYPE_INTERFACE_Node, props, &data->impl_node, 0);
+
+ pw_core_export_object(data->core,
+ SPA_TYPE_INTERFACE_Node,
+ &props->dict,
+ &data->impl_node.iface, 0);
}
-static void on_state_changed(void *_data, enum pw_remote_state old,
- enum pw_remote_state state, const char *error)
+static void on_error(void *object, uint32_t id, int seq, int res, const char *message)
{
- struct data *data = _data;
+ struct data *data = object;
- switch (state) {
- case PW_REMOTE_STATE_ERROR:
- printf("remote error: %s\n", error);
+ printf("error: %s\n", message);
+ if (id == 0) {
pw_main_loop_quit(data->loop);
- break;
-
- case PW_REMOTE_STATE_CONNECTED:
- make_node(data);
- break;
-
- default:
- printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
- break;
}
}
-static const struct pw_remote_events remote_events = {
- PW_VERSION_REMOTE_EVENTS,
- .state_changed = on_state_changed,
+static const struct pw_core_events core_events = {
+ PW_VERSION_CORE_EVENTS,
+ .error = on_error,
};
int main(int argc, char *argv[])
@@ -517,8 +508,7 @@ int main(int argc, char *argv[])
pw_init(&argc, &argv);
data.loop = pw_main_loop_new(NULL);
- data.core = pw_impl_core_new(pw_main_loop_get_loop(data.loop), NULL, 0);
- data.remote = pw_remote_new(data.core, NULL, 0);
+ data.core = pw_core_connect(pw_main_loop_get_loop(data.loop), NULL, 0);
data.path = argc > 1 ? argv[1] : NULL;
data.info_all = SPA_PORT_CHANGE_MASK_FLAGS |
@@ -540,13 +530,13 @@ int main(int argc, char *argv[])
spa_list_init(&data.empty);
spa_hook_list_init(&data.hooks);
- pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);
+ pw_core_add_listener(data.core, &data.core_listener, &core_events, &data);
- pw_remote_connect(data.remote);
+ make_node(&data);
pw_main_loop_run(data.loop);
- pw_impl_core_destroy(data.core);
+ pw_core_disconnect(data.core);
pw_main_loop_destroy(data.loop);
return 0;
diff --git a/src/examples/export-spa-device.c b/src/examples/export-spa-device.c
index e5e4589b..fe053281 100644
--- a/src/examples/export-spa-device.c
+++ b/src/examples/export-spa-device.c
@@ -34,10 +34,8 @@
struct data {
struct pw_main_loop *loop;
- struct pw_impl_core *core;
-
- struct pw_remote *remote;
- struct spa_hook remote_listener;
+ struct pw_core *core;
+ struct spa_hook core_listener;
struct pw_impl_device *device;
const char *library;
@@ -47,6 +45,7 @@ struct data {
static int make_device(struct data *data)
{
+#if 0
struct pw_impl_factory *factory;
struct pw_properties *props;
@@ -66,36 +65,22 @@ static int make_device(struct data *data)
pw_remote_export(data->remote, SPA_TYPE_INTERFACE_Device, NULL,
pw_impl_device_get_implementation(data->device), 0);
+#endif
return 0;
}
-static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remote_state state, const char *error)
+static void on_error(void *object, uint32_t id, int seq, int res, const char *message)
{
- struct data *data = _data;
-
- switch (state) {
- case PW_REMOTE_STATE_ERROR:
- printf("remote error: %s\n", error);
+ struct data *data = object;
+ printf("core error: id:%u seq:%d res:%d %s\n", id, seq, res, message);
+ if (id == 0) {
pw_main_loop_quit(data->loop);
- break;
-
- case PW_REMOTE_STATE_CONNECTED:
- printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
- if (make_device(data) < 0) {
- pw_log_error("can't make device");
- pw_main_loop_quit(data->loop);
- }
- break;
-
- default:
- printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
- break;
}
}
-static const struct pw_remote_events remote_events = {
- PW_VERSION_REMOTE_EVENTS,
- .state_changed = on_state_changed,
+static const struct pw_core_events core_events = {
+ PW_VERSION_CORE_EVENTS,
+ .error = on_error,
};
static void do_quit(void *data, int signal_number)
@@ -122,21 +107,24 @@ int main(int argc, char *argv[])
l = pw_main_loop_get_loop(data.loop);
pw_loop_add_signal(l, SIGINT, do_quit, &data);
pw_loop_add_signal(l, SIGTERM, do_quit, &data);
- data.core = pw_impl_core_new(l, NULL, 0);
- data.remote = pw_remote_new(data.core, NULL, 0);
- data.library = argv[1];
- data.factory = argv[2];
- pw_impl_module_load(data.core, "libpipewire-module-spa-device-factory", NULL, NULL);
- pw_impl_module_load(data.core, "libpipewire-module-client-device", NULL, NULL);
+ pw_context_load_module(NULL, "libpipewire-module-spa-device-factory", NULL, NULL);
+ pw_context_load_module(NULL, "libpipewire-module-client-device", NULL, NULL);
- pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);
+ data.core = pw_core_connect(l, NULL, 0);
+ pw_core_add_listener(data.core, &data.core_listener, &core_events, &data);
- pw_remote_connect(data.remote);
+ data.library = argv[1];
+ data.factory = argv[2];
+
+ if (make_device(&data) < 0) {
+ fprintf(stderr, "can't make device");
+ return -1;
+ }
pw_main_loop_run(data.loop);
- pw_impl_core_destroy(data.core);
+ pw_core_disconnect(data.core);
pw_main_loop_destroy(data.loop);
return 0;
diff --git a/src/examples/export-spa.c b/src/examples/export-spa.c
index 01fe2abf..1a5e45c8 100644
--- a/src/examples/export-spa.c
+++ b/src/examples/export-spa.c
@@ -34,10 +34,8 @@
struct data {
struct pw_main_loop *loop;
- struct pw_impl_core *core;
-
- struct pw_remote *remote;
- struct spa_hook remote_listener;
+ struct pw_core *core;
+ struct spa_hook core_listener;
struct pw_impl_node *node;
const char *library;
@@ -66,6 +64,7 @@ static const struct pw_node_events node_events = {
static int make_node(struct data *data)
{
+#if 0
struct pw_impl_factory *factory;
struct pw_properties *props;
@@ -98,36 +97,23 @@ static int make_node(struct data *data)
pw_node_add_listener((struct pw_node*)data->proxy,
&data->node_listener, &node_events, data);
+#endif
return 0;
}
-static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remote_state state, const char *error)
+static void on_error(void *object, uint32_t id, int seq, int res, const char *message)
{
- struct data *data = _data;
+ struct data *data = object;
- switch (state) {
- case PW_REMOTE_STATE_ERROR:
- printf("remote error: %s\n", error);
+ printf("error: %s\n", message);
+ if (id == 0) {
pw_main_loop_quit(data->loop);
- break;
-
- case PW_REMOTE_STATE_CONNECTED:
- printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
- if (make_node(data) < 0) {
- pw_log_error("can't make node");
- pw_main_loop_quit(data->loop);
- }
- break;
-
- default:
- printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
- break;
}
}
-static const struct pw_remote_events remote_events = {
- PW_VERSION_REMOTE_EVENTS,
- .state_changed = on_state_changed,
+static const struct pw_core_events core_events = {
+ PW_VERSION_CORE_EVENTS,
+ .error = on_error,
};
static void do_quit(void *data, int signal_number)
@@ -154,22 +140,26 @@ int main(int argc, char *argv[])
l = pw_main_loop_get_loop(data.loop);
pw_loop_add_signal(l, SIGINT, do_quit, &data);
pw_loop_add_signal(l, SIGTERM, do_quit, &data);
- data.core = pw_impl_core_new(l, NULL, 0);
- data.remote = pw_remote_new(data.core, NULL, 0);
+
+ data.core = pw_core_connect(l, NULL, 0);
+
data.library = argv[1];
data.factory = argv[2];
if (argc > 3)
data.path = argv[3];
- pw_impl_module_load(data.core, "libpipewire-module-spa-node-factory", NULL, NULL);
+ pw_core_load_module(data.core, "libpipewire-module-spa-node-factory", NULL, NULL, 0);
- pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);
+ pw_core_add_listener(data.core, &data.core_listener, &core_events, &data);
- pw_remote_connect(data.remote);
+ if (make_node(&data) < 0) {
+ pw_log_error("can't make node");
+ return -1;
+ }
pw_main_loop_run(data.loop);
- pw_impl_core_destroy(data.core);
+ pw_core_disconnect(data.core);
pw_main_loop_destroy(data.loop);
return 0;
diff --git a/src/examples/media-session/media-session.c b/src/examples/media-session/media-session.c
index d3f29f3b..b39017b4 100644
--- a/src/examples/media-session/media-session.c
+++ b/src/examples/media-session/media-session.c
@@ -1657,6 +1657,7 @@ int main(int argc, char *argv[])
impl.loop = pw_main_loop_new(NULL);
impl.this.loop = pw_main_loop_get_loop(impl.loop);
+
impl.this.core_impl = pw_impl_core_new(impl.this.loop, NULL, 0);
pw_impl_core_add_spa_lib(impl.this.core_impl, "api.bluez5.*", "bluez5/libspa-bluez5");
diff --git a/src/examples/video-src.c b/src/examples/video-src.c
index 8a76301e..3e2524f7 100644
--- a/src/examples/video-src.c
+++ b/src/examples/video-src.c
@@ -46,10 +46,7 @@ struct data {
struct pw_main_loop *loop;
struct spa_source *timer;
- struct pw_impl_core *core;
- struct pw_remote *remote;
- struct spa_hook remote_listener;
-
+ struct pw_core *core;
struct pw_stream *stream;
struct spa_hook stream_listener;
@@ -186,9 +183,17 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum
printf("stream state: \"%s\"\n", pw_stream_state_as_string(state));
switch (state) {
+ case PW_STREAM_STATE_UNCONNECTED:
+ case PW_STREAM_STATE_ERROR:
+ pw_main_loop_quit(data->loop);
+ break;
+
case PW_STREAM_STATE_PAUSED:
printf("node id: %d\n", pw_stream_get_node_id(data->stream));
+ pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
+ data->timer, NULL, NULL, false);
break;
+
case PW_STREAM_STATE_STREAMING:
{
struct timespec timeout, interval;
@@ -203,8 +208,6 @@ static void on_stream_state_changed(void *_data, enum pw_stream_state old, enum
break;
}
default:
- pw_loop_update_timer(pw_main_loop_get_loop(data->loop),
- data->timer, NULL, NULL, false);
break;
}
}
@@ -266,85 +269,51 @@ static const struct pw_stream_events stream_events = {
.param_changed = on_stream_param_changed,
};
-static void on_state_changed(void *_data, enum pw_remote_state old, enum pw_remote_state state, const char *error)
-{
- struct data *data = _data;
- struct pw_remote *remote = data->remote;
-
- switch (state) {
- case PW_REMOTE_STATE_ERROR:
- printf("remote error: %s\n", error);
- pw_main_loop_quit(data->loop);
- break;
-
- case PW_REMOTE_STATE_CONNECTED:
- {
- const struct spa_pod *params[1];
- uint8_t buffer[1024];
- struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
-
- printf("remote state: \"%s\"\n",
- pw_remote_state_as_string(state));
-
- data->stream = pw_stream_new(remote, "video-src",
- pw_properties_new(
- PW_KEY_MEDIA_CLASS, "Video/Source",
- NULL));
-
- params[0] = spa_pod_builder_add_object(&b,
- SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
- SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
- SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
- SPA_FORMAT_VIDEO_format, SPA_POD_Id(SPA_VIDEO_FORMAT_RGB),
- SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(
- &SPA_RECTANGLE(320, 240),
- &SPA_RECTANGLE(1, 1),
- &SPA_RECTANGLE(4096, 4096)),
- SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&SPA_FRACTION(25, 1)));
-
- pw_stream_add_listener(data->stream,
- &data->stream_listener,
- &stream_events,
- data);
-
- pw_stream_connect(data->stream,
- PW_DIRECTION_OUTPUT,
- SPA_ID_INVALID,
- PW_STREAM_FLAG_DRIVER |
- PW_STREAM_FLAG_MAP_BUFFERS,
- params, 1);
- break;
- }
- default:
- printf("remote state: \"%s\"\n", pw_remote_state_as_string(state));
- break;
- }
-}
-
-static const struct pw_remote_events remote_events = {
- PW_VERSION_REMOTE_EVENTS,
- .state_changed = on_state_changed,
-};
-
int main(int argc, char *argv[])
{
struct data data = { 0, };
+ const struct spa_pod *params[1];
+ uint8_t buffer[1024];
+ struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
pw_init(&argc, &argv);
data.loop = pw_main_loop_new(NULL);
- data.core = pw_impl_core_new(pw_main_loop_get_loop(data.loop), NULL, 0);
- data.remote = pw_remote_new(data.core, NULL, 0);
+ data.core = pw_core_connect(pw_main_loop_get_loop(data.loop), NULL, 0);
data.timer = pw_loop_add_timer(pw_main_loop_get_loop(data.loop), on_timeout, &data);
- pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);
+ data.stream = pw_stream_new(data.core, "video-src",
+ pw_properties_new(
+ PW_KEY_MEDIA_CLASS, "Video/Source",
+ NULL));
+
+ pw_stream_add_listener(data.stream,
+ &data.stream_listener,
+ &stream_events,
+ &data);
- pw_remote_connect(data.remote);
+ params[0] = spa_pod_builder_add_object(&b,
+ SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
+ SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
+ SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
+ SPA_FORMAT_VIDEO_format, SPA_POD_Id(SPA_VIDEO_FORMAT_RGB),
+ SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(
+ &SPA_RECTANGLE(320, 240),
+ &SPA_RECTANGLE(1, 1),
+ &SPA_RECTANGLE(4096, 4096)),
+ SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction(&SPA_FRACTION(25, 1)));
+
+ pw_stream_connect(data.stream,
+ PW_DIRECTION_OUTPUT,
+ SPA_ID_INVALID,
+ PW_STREAM_FLAG_DRIVER |
+ PW_STREAM_FLAG_MAP_BUFFERS,
+ params, 1);
pw_main_loop_run(data.loop);
- pw_impl_core_destroy(data.core);
+ pw_core_disconnect(data.core);
pw_main_loop_destroy(data.loop);
return 0;