From ca87d40448221bc579b70f69d119c9a9050da5be Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sun, 16 Jan 2022 19:48:43 +0200 Subject: [PATCH] examples: use PW_KEY_TARGET_OBJECT In examples, tell people how to use target.object. --- doc/tutorial4.c | 2 +- doc/tutorial4.dox | 4 ++-- doc/tutorial5.c | 16 ++++++++++------ doc/tutorial5.dox | 24 +++++++++++++++--------- src/examples/audio-src.c | 16 ++++++++++------ src/examples/export-sink.c | 2 +- src/examples/export-source.c | 2 +- src/examples/export-spa.c | 2 +- src/examples/video-dsp-play.c | 2 +- src/examples/video-play-fixate.c | 22 +++++++++++++--------- src/examples/video-play-pull.c | 22 +++++++++++++--------- src/examples/video-play-reneg.c | 20 ++++++++++++-------- src/examples/video-play.c | 19 +++++++++++-------- src/examples/video-src-alloc.c | 2 +- src/examples/video-src-fixate.c | 2 +- src/examples/video-src-reneg.c | 2 +- 16 files changed, 94 insertions(+), 65 deletions(-) diff --git a/doc/tutorial4.c b/doc/tutorial4.c index 94fb6d3e2..ff0cb2774 100644 --- a/doc/tutorial4.c +++ b/doc/tutorial4.c @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) pw_stream_connect(data.stream, PW_DIRECTION_OUTPUT, - argc > 1 ? (uint32_t)atoi(argv[1]) : PW_ID_ANY, + PW_ID_ANY, PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_RT_PROCESS, diff --git a/doc/tutorial4.dox b/doc/tutorial4.dox index 92840212d..b8d170744 100644 --- a/doc/tutorial4.dox +++ b/doc/tutorial4.dox @@ -118,8 +118,8 @@ Now we're ready to connect the stream and run the main loop: pw_main_loop_run(data.loop); \endcode -To connect we specify that we have a `PW_DIRECTION_OUTPUT` stream. `PW_ID_ANY` -means that we are ok with connecting to any consumer. Next we set some flags: +To connect we specify that we have a `PW_DIRECTION_OUTPUT` stream. The third argument +is always `PW_ID_ANY`. Next we set some flags: - `PW_STREAM_FLAG_AUTOCONNECT`: Automatically connect this stream. This instructs the session manager to link us to some consumer. diff --git a/doc/tutorial5.c b/doc/tutorial5.c index 754fc025d..e49da9116 100644 --- a/doc/tutorial5.c +++ b/doc/tutorial5.c @@ -83,19 +83,23 @@ int main(int argc, char *argv[]) const struct spa_pod *params[1]; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); + struct pw_properties *props; pw_init(&argc, &argv); data.loop = pw_main_loop_new(NULL); + props = pw_properties_new(PW_KEY_MEDIA_TYPE, "Video", + PW_KEY_MEDIA_CATEGORY, "Capture", + PW_KEY_MEDIA_ROLE, "Camera", + NULL); + if (argc > 1) + pw_properties_set(props, PW_KEY_TARGET_OBJECT, argv[1]); + data.stream = pw_stream_new_simple( pw_main_loop_get_loop(data.loop), "video-capture", - pw_properties_new( - PW_KEY_MEDIA_TYPE, "Video", - PW_KEY_MEDIA_CATEGORY, "Capture", - PW_KEY_MEDIA_ROLE, "Camera", - NULL), + props, &stream_events, &data); @@ -122,7 +126,7 @@ int main(int argc, char *argv[]) pw_stream_connect(data.stream, PW_DIRECTION_INPUT, - argc > 1 ? (uint32_t)atoi(argv[1]) : PW_ID_ANY, + PW_ID_ANY, PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS, params, 1); diff --git a/doc/tutorial5.dox b/doc/tutorial5.dox index b614fc531..e73c1cf44 100644 --- a/doc/tutorial5.dox +++ b/doc/tutorial5.dox @@ -23,18 +23,25 @@ We create a stream object with different properties to make it a Camera Video Capture stream. \code{.c} + props = pw_properties_new(PW_KEY_MEDIA_TYPE, "Video", + PW_KEY_MEDIA_CATEGORY, "Capture", + PW_KEY_MEDIA_ROLE, "Camera", + NULL); + if (argc > 1) + pw_properties_set(props, PW_KEY_TARGET_OBJECT, argv[1]); + data.stream = pw_stream_new_simple( pw_main_loop_get_loop(data.loop), "video-capture", - pw_properties_new( - PW_KEY_MEDIA_TYPE, "Video", - PW_KEY_MEDIA_CATEGORY, "Capture", - PW_KEY_MEDIA_ROLE, "Camera", - NULL), + props, &stream_events, &data); \endcode +We also optionally allow the user to pass the name of the target node where the session +manager is supposed to connect the node. The user may also give the value of the +unique target node serial (`PW_KEY_OBJECT_SERIAL`) as the value. + In addition to the `process` event, we are also going to listen to a new event, `param_changed`: @@ -122,7 +129,7 @@ Now we're ready to connect the stream and run the main loop: \code{.c} pw_stream_connect(data.stream, PW_DIRECTION_INPUT, - argc > 1 ? (uint32_t)atoi(argv[1]) : PW_ID_ANY, + PW_ID_ANY, PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS, params, 1); @@ -130,9 +137,8 @@ Now we're ready to connect the stream and run the main loop: pw_main_loop_run(data.loop); \endcode -To connect we specify that we have a `PW_DIRECTION_INPUT` stream. `PW_ID_ANY` -means that we are ok with connecting to any producer. We also allow the user -to pass an optional target id. +To connect we specify that we have a `PW_DIRECTION_INPUT` stream. The third +argument is always `PW_ID_ANY`. We're setting the `PW_STREAM_FLAG_AUTOCONNECT` flag to make an automatic connection to a suitable camera and `PW_STREAM_FLAG_MAP_BUFFERS` to let the diff --git a/src/examples/audio-src.c b/src/examples/audio-src.c index f65f6148a..121773219 100644 --- a/src/examples/audio-src.c +++ b/src/examples/audio-src.c @@ -120,6 +120,7 @@ int main(int argc, char *argv[]) struct data data = { 0, }; const struct spa_pod *params[1]; uint8_t buffer[1024]; + struct pw_properties *props; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); pw_init(&argc, &argv); @@ -142,14 +143,17 @@ int main(int argc, char *argv[]) * you need to listen to is the process event where you need to produce * the data. */ + props = pw_properties_new(PW_KEY_MEDIA_TYPE, "Audio", + PW_KEY_MEDIA_CATEGORY, "Playback", + PW_KEY_MEDIA_ROLE, "Music", + NULL); + if (argc > 1) + /* Set stream target if given on command line */ + pw_properties_set(props, PW_KEY_TARGET_OBJECT, argv[1]); data.stream = pw_stream_new_simple( pw_main_loop_get_loop(data.loop), "audio-src", - pw_properties_new( - PW_KEY_MEDIA_TYPE, "Audio", - PW_KEY_MEDIA_CATEGORY, "Playback", - PW_KEY_MEDIA_ROLE, "Music", - NULL), + props, &stream_events, &data); @@ -165,7 +169,7 @@ int main(int argc, char *argv[]) * called in a realtime thread. */ pw_stream_connect(data.stream, PW_DIRECTION_OUTPUT, - argc > 1 ? (uint32_t)atoi(argv[1]) : PW_ID_ANY, + PW_ID_ANY, PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_RT_PROCESS, diff --git a/src/examples/export-sink.c b/src/examples/export-sink.c index 05d6380df..9e0985475 100644 --- a/src/examples/export-sink.c +++ b/src/examples/export-sink.c @@ -472,7 +472,7 @@ static void make_node(struct data *data) props = pw_properties_new(PW_KEY_NODE_AUTOCONNECT, "true", NULL); if (data->path) - pw_properties_set(props, PW_KEY_NODE_TARGET, data->path); + pw_properties_set(props, PW_KEY_TARGET_OBJECT, data->path); pw_properties_set(props, PW_KEY_MEDIA_CLASS, "Stream/Input/Video"); pw_properties_set(props, PW_KEY_MEDIA_TYPE, "Video"); pw_properties_set(props, PW_KEY_MEDIA_CATEGORY, "Capture"); diff --git a/src/examples/export-source.c b/src/examples/export-source.c index 0310efb5b..f84d01d92 100644 --- a/src/examples/export-source.c +++ b/src/examples/export-source.c @@ -483,7 +483,7 @@ static void make_node(struct data *data) PW_KEY_MEDIA_ROLE, "Music", NULL); if (data->path) - pw_properties_set(props, PW_KEY_NODE_TARGET, data->path); + pw_properties_set(props, PW_KEY_TARGET_OBJECT, data->path); data->impl_node.iface = SPA_INTERFACE_INIT( SPA_TYPE_INTERFACE_Node, diff --git a/src/examples/export-spa.c b/src/examples/export-spa.c index 864555d1f..e2f27cf12 100644 --- a/src/examples/export-spa.c +++ b/src/examples/export-spa.c @@ -93,7 +93,7 @@ static int make_node(struct data *data) if (data->path) { pw_properties_set(props, PW_KEY_NODE_AUTOCONNECT, "true"); - pw_properties_set(props, PW_KEY_NODE_TARGET, data->path); + pw_properties_set(props, PW_KEY_TARGET_OBJECT, data->path); } data->proxy = pw_core_export(data->core, diff --git a/src/examples/video-dsp-play.c b/src/examples/video-dsp-play.c index 05828b591..71f9b0199 100644 --- a/src/examples/video-dsp-play.c +++ b/src/examples/video-dsp-play.c @@ -263,7 +263,7 @@ int main(int argc, char *argv[]) PW_KEY_MEDIA_CATEGORY, "Capture", PW_KEY_MEDIA_ROLE, "DSP", PW_KEY_NODE_AUTOCONNECT, data.target ? "true" : "false", - PW_KEY_NODE_TARGET, data.target, + PW_KEY_TARGET_OBJECT, data.target, PW_KEY_MEDIA_CLASS, "Stream/Input/Video", NULL), &filter_events, diff --git a/src/examples/video-play-fixate.c b/src/examples/video-play-fixate.c index 3131c1445..1badc3c39 100644 --- a/src/examples/video-play-fixate.c +++ b/src/examples/video-play-fixate.c @@ -419,6 +419,7 @@ int main(int argc, char *argv[]) const struct spa_pod *params[2]; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); + struct pw_properties *props; int res, n_params; pw_init(&argc, &argv); @@ -440,19 +441,22 @@ int main(int argc, char *argv[]) * you need to listen to is the process event where you need to consume * the data provided to you. */ + props = pw_properties_new(PW_KEY_MEDIA_TYPE, "Video", + PW_KEY_MEDIA_CATEGORY, "Capture", + PW_KEY_MEDIA_ROLE, "Camera", + NULL), + data.path = argc > 1 ? argv[1] : NULL; + if (data.path) + /* Set stream target if given on command line */ + pw_properties_set(props, PW_KEY_TARGET_OBJECT, data.path); + data.stream = pw_stream_new_simple( pw_main_loop_get_loop(data.loop), - "video-play-reneg", - pw_properties_new( - PW_KEY_MEDIA_TYPE, "Video", - PW_KEY_MEDIA_CATEGORY, "Capture", - PW_KEY_MEDIA_ROLE, "Camera", - NULL), + "video-play-fixate", + props, &stream_events, &data); - data.path = argc > 1 ? argv[1] : NULL; - if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "can't initialize SDL: %s\n", SDL_GetError()); return -1; @@ -477,7 +481,7 @@ int main(int argc, char *argv[]) */ if ((res = pw_stream_connect(data.stream, PW_DIRECTION_INPUT, - data.path ? (uint32_t)atoi(data.path) : PW_ID_ANY, + PW_ID_ANY, PW_STREAM_FLAG_AUTOCONNECT | /* try to automatically connect this stream */ PW_STREAM_FLAG_MAP_BUFFERS, /* mmap the buffer data for us */ params, n_params)) /* extra parameters, see above */ < 0) { diff --git a/src/examples/video-play-pull.c b/src/examples/video-play-pull.c index 37f7e7314..2b2c34660 100644 --- a/src/examples/video-play-pull.c +++ b/src/examples/video-play-pull.c @@ -493,6 +493,7 @@ int main(int argc, char *argv[]) const struct spa_pod *params[2]; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); + struct pw_properties *props; int res, n_params; pw_init(&argc, &argv); @@ -517,20 +518,23 @@ int main(int argc, char *argv[]) * you need to listen to is the process event where you need to consume * the data provided to you. */ + props = pw_properties_new(PW_KEY_MEDIA_TYPE, "Video", + PW_KEY_MEDIA_CATEGORY, "Capture", + PW_KEY_MEDIA_ROLE, "Camera", + PW_KEY_PRIORITY_DRIVER, "10000", + NULL), + data.path = argc > 1 ? argv[1] : NULL; + if (data.path) + /* Set stream target if given on command line */ + pw_properties_set(props, PW_KEY_TARGET_OBJECT, data.path); + data.stream = pw_stream_new_simple( pw_main_loop_get_loop(data.loop), "video-play", - pw_properties_new( - PW_KEY_MEDIA_TYPE, "Video", - PW_KEY_MEDIA_CATEGORY, "Capture", - PW_KEY_MEDIA_ROLE, "Camera", - PW_KEY_PRIORITY_DRIVER, "10000", - NULL), + props, &stream_events, &data); - data.path = argc > 1 ? argv[1] : NULL; - if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "can't initialize SDL: %s\n", SDL_GetError()); return -1; @@ -552,7 +556,7 @@ int main(int argc, char *argv[]) */ if ((res = pw_stream_connect(data.stream, PW_DIRECTION_INPUT, - data.path ? (uint32_t)atoi(data.path) : PW_ID_ANY, + PW_ID_ANY, PW_STREAM_FLAG_DRIVER | /* we're driver, we pull */ PW_STREAM_FLAG_AUTOCONNECT | /* try to automatically connect this stream */ PW_STREAM_FLAG_MAP_BUFFERS, /* mmap the buffer data for us */ diff --git a/src/examples/video-play-reneg.c b/src/examples/video-play-reneg.c index 3c86bd096..aa071850a 100644 --- a/src/examples/video-play-reneg.c +++ b/src/examples/video-play-reneg.c @@ -346,6 +346,7 @@ int main(int argc, char *argv[]) const struct spa_pod *params[2]; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); + struct pw_properties *props; int res, n_params; pw_init(&argc, &argv); @@ -367,19 +368,22 @@ int main(int argc, char *argv[]) * you need to listen to is the process event where you need to consume * the data provided to you. */ + props = pw_properties_new(PW_KEY_MEDIA_TYPE, "Video", + PW_KEY_MEDIA_CATEGORY, "Capture", + PW_KEY_MEDIA_ROLE, "Camera", + NULL), + data.path = argc > 1 ? argv[1] : NULL; + if (data.path) + /* Set stream target if given on command line */ + pw_properties_set(props, PW_KEY_TARGET_OBJECT, data.path); + data.stream = pw_stream_new_simple( pw_main_loop_get_loop(data.loop), "video-play-reneg", - pw_properties_new( - PW_KEY_MEDIA_TYPE, "Video", - PW_KEY_MEDIA_CATEGORY, "Capture", - PW_KEY_MEDIA_ROLE, "Camera", - NULL), + props, &stream_events, &data); - data.path = argc > 1 ? argv[1] : NULL; - if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "can't initialize SDL: %s\n", SDL_GetError()); return -1; @@ -401,7 +405,7 @@ int main(int argc, char *argv[]) */ if ((res = pw_stream_connect(data.stream, PW_DIRECTION_INPUT, - data.path ? (uint32_t)atoi(data.path) : PW_ID_ANY, + PW_ID_ANY, PW_STREAM_FLAG_AUTOCONNECT | /* try to automatically connect this stream */ PW_STREAM_FLAG_MAP_BUFFERS, /* mmap the buffer data for us */ params, n_params)) /* extra parameters, see above */ < 0) { diff --git a/src/examples/video-play.c b/src/examples/video-play.c index 20362b892..68589c902 100644 --- a/src/examples/video-play.c +++ b/src/examples/video-play.c @@ -439,6 +439,7 @@ int main(int argc, char *argv[]) const struct spa_pod *params[2]; uint8_t buffer[1024]; struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); + struct pw_properties *props; int res, n_params; pw_init(&argc, &argv); @@ -460,19 +461,21 @@ int main(int argc, char *argv[]) * you need to listen to is the process event where you need to consume * the data provided to you. */ + props = pw_properties_new(PW_KEY_MEDIA_TYPE, "Video", + PW_KEY_MEDIA_CATEGORY, "Capture", + PW_KEY_MEDIA_ROLE, "Camera", + NULL), + data.path = argc > 1 ? argv[1] : NULL; + if (data.path) + pw_properties_set(props, PW_KEY_TARGET_OBJECT, data.path); + data.stream = pw_stream_new_simple( pw_main_loop_get_loop(data.loop), "video-play", - pw_properties_new( - PW_KEY_MEDIA_TYPE, "Video", - PW_KEY_MEDIA_CATEGORY, "Capture", - PW_KEY_MEDIA_ROLE, "Camera", - NULL), + props, &stream_events, &data); - data.path = argc > 1 ? argv[1] : NULL; - if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "can't initialize SDL: %s\n", SDL_GetError()); return -1; @@ -494,7 +497,7 @@ int main(int argc, char *argv[]) */ if ((res = pw_stream_connect(data.stream, PW_DIRECTION_INPUT, - data.path ? (uint32_t)atoi(data.path) : PW_ID_ANY, + PW_ID_ANY, PW_STREAM_FLAG_AUTOCONNECT | /* try to automatically connect this stream */ PW_STREAM_FLAG_INACTIVE | /* we will activate ourselves */ PW_STREAM_FLAG_MAP_BUFFERS, /* mmap the buffer data for us */ diff --git a/src/examples/video-src-alloc.c b/src/examples/video-src-alloc.c index a35ecc8a7..ef364fd1d 100644 --- a/src/examples/video-src-alloc.c +++ b/src/examples/video-src-alloc.c @@ -442,7 +442,7 @@ int main(int argc, char *argv[]) * the server. */ pw_stream_connect(data.stream, PW_DIRECTION_OUTPUT, - PW_ID_ANY, /* link to any node */ + PW_ID_ANY, PW_STREAM_FLAG_DRIVER | PW_STREAM_FLAG_ALLOC_BUFFERS, params, 1); diff --git a/src/examples/video-src-fixate.c b/src/examples/video-src-fixate.c index bdfbb33a2..6d621d163 100644 --- a/src/examples/video-src-fixate.c +++ b/src/examples/video-src-fixate.c @@ -578,7 +578,7 @@ int main(int argc, char *argv[]) * the server. */ pw_stream_connect(data.stream, PW_DIRECTION_OUTPUT, - PW_ID_ANY, /* link to any node */ + PW_ID_ANY, PW_STREAM_FLAG_DRIVER | PW_STREAM_FLAG_ALLOC_BUFFERS, params, 2); diff --git a/src/examples/video-src-reneg.c b/src/examples/video-src-reneg.c index d0431210a..172e7dc91 100644 --- a/src/examples/video-src-reneg.c +++ b/src/examples/video-src-reneg.c @@ -487,7 +487,7 @@ int main(int argc, char *argv[]) * the server. */ pw_stream_connect(data.stream, PW_DIRECTION_OUTPUT, - PW_ID_ANY, /* link to any node */ + PW_ID_ANY, PW_STREAM_FLAG_DRIVER | PW_STREAM_FLAG_ALLOC_BUFFERS, params, 1);