LADI
/
spa
1
Fork 0

examples: use PW_KEY_TARGET_OBJECT

In examples, tell people how to use target.object.
This commit is contained in:
Pauli Virtanen 2022-01-16 19:48:43 +02:00
parent de65fd442f
commit ca87d40448
16 changed files with 94 additions and 65 deletions

View File

@ -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,

View File

@ -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.

View File

@ -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);

View File

@ -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

View File

@ -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,

View File

@ -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");

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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) {

View File

@ -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 */

View File

@ -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) {

View File

@ -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 */

View File

@ -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);

View File

@ -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);

View File

@ -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);