modules: align tunnel.mode

Source for a source, sink for a sink. We use capture and playback for
streams that link to a source/sink respectively.
This commit is contained in:
Wim Taymans 2022-06-03 10:51:46 +02:00
parent fe1652e843
commit 87172fde06
4 changed files with 19 additions and 19 deletions

View file

@ -81,7 +81,7 @@ static int module_tunnel_sink_load(struct client *client, struct module *module)
fprintf(f, "{"); fprintf(f, "{");
pw_properties_serialize_dict(f, &module->props->dict, 0); pw_properties_serialize_dict(f, &module->props->dict, 0);
fprintf(f, " pulse.server.address = \"%s\" ", server); fprintf(f, " pulse.server.address = \"%s\" ", server);
fprintf(f, " tunnel.mode = playback "); fprintf(f, " tunnel.mode = sink ");
if (data->latency_msec > 0) if (data->latency_msec > 0)
fprintf(f, " pulse.latency = %u ", data->latency_msec); fprintf(f, " pulse.latency = %u ", data->latency_msec);
fprintf(f, " stream.props = {"); fprintf(f, " stream.props = {");

View file

@ -81,7 +81,7 @@ static int module_tunnel_source_load(struct client *client, struct module *modul
fprintf(f, "{"); fprintf(f, "{");
pw_properties_serialize_dict(f, &module->props->dict, 0); pw_properties_serialize_dict(f, &module->props->dict, 0);
fprintf(f, " pulse.server.address = \"%s\" ", server); fprintf(f, " pulse.server.address = \"%s\" ", server);
fprintf(f, " tunnel.mode = capture "); fprintf(f, " tunnel.mode = source ");
if (data->latency_msec > 0) if (data->latency_msec > 0)
fprintf(f, " pulse.latency = %u ", data->latency_msec); fprintf(f, " pulse.latency = %u ", data->latency_msec);
fprintf(f, " stream.props = {"); fprintf(f, " stream.props = {");

View file

@ -68,8 +68,8 @@
* *
* ## Module Options * ## Module Options
* *
* - `tunnel.mode`: the desired tunnel to create, must be `capture` or `playback`. * - `tunnel.mode`: the desired tunnel to create, must be `source` or `sink`.
* (Default `playback`) * (Default `sink`)
* - `pulse.server.address`: the address of the PulseAudio server to tunnel to. * - `pulse.server.address`: the address of the PulseAudio server to tunnel to.
* - `pulse.latency`: the latency to end-to-end latency in milliseconds to * - `pulse.latency`: the latency to end-to-end latency in milliseconds to
* maintain (Default 200ms). * maintain (Default 200ms).
@ -97,7 +97,7 @@
* context.modules = [ * context.modules = [
* { name = libpipewire-module-pulse-tunnel * { name = libpipewire-module-pulse-tunnel
* args = { * args = {
* tunnel.mode = playback * tunnel.mode = sink
* # Set the remote address to tunnel to * # Set the remote address to tunnel to
* pulse.server.address = "tcp:192.168.1.126" * pulse.server.address = "tcp:192.168.1.126"
* #audio.rate=<sample rate> * #audio.rate=<sample rate>
@ -128,7 +128,7 @@ PW_LOG_TOPIC_STATIC(mod_topic, "mod." NAME);
"[ audio.position=<channel map> ] " \ "[ audio.position=<channel map> ] " \
"pulse.server.address=<address> " \ "pulse.server.address=<address> " \
"pulse.latency=<latency in msec> " \ "pulse.latency=<latency in msec> " \
"[ tunnel.mode=capture|playback " \ "[ tunnel.mode=source|sink " \
"[ stream.props=<properties> ] " "[ stream.props=<properties> ] "
@ -147,8 +147,8 @@ static const struct spa_dict_item module_props[] = {
struct impl { struct impl {
struct pw_context *context; struct pw_context *context;
#define MODE_PLAYBACK 0 #define MODE_SINK 0
#define MODE_CAPTURE 1 #define MODE_SOURCE 1
uint32_t mode; uint32_t mode;
struct pw_properties *props; struct pw_properties *props;
@ -193,7 +193,7 @@ static void cork_stream(struct impl *impl, bool cork)
pa_threaded_mainloop_lock(impl->pa_mainloop); pa_threaded_mainloop_lock(impl->pa_mainloop);
pw_log_debug("corking: %d", cork); pw_log_debug("corking: %d", cork);
if (cork && impl->mode == MODE_PLAYBACK) { if (cork && impl->mode == MODE_SINK) {
/* When the sink becomes suspended (which is the only case where we /* When the sink becomes suspended (which is the only case where we
* cork the stream), we don't want to keep any old data around, because * cork the stream), we don't want to keep any old data around, because
* the old data is most likely unrelated to the audio that will be * the old data is most likely unrelated to the audio that will be
@ -376,7 +376,7 @@ static int create_stream(struct impl *impl)
if (impl->stream == NULL) if (impl->stream == NULL)
return -errno; return -errno;
if (impl->mode == MODE_CAPTURE) { if (impl->mode == MODE_SOURCE) {
pw_stream_add_listener(impl->stream, pw_stream_add_listener(impl->stream,
&impl->stream_listener, &impl->stream_listener,
&capture_stream_events, impl); &capture_stream_events, impl);
@ -392,14 +392,14 @@ static int create_stream(struct impl *impl)
SPA_PARAM_EnumFormat, &impl->info); SPA_PARAM_EnumFormat, &impl->info);
spa_zero(latency); spa_zero(latency);
latency.direction = impl->mode == MODE_CAPTURE ? PW_DIRECTION_OUTPUT : PW_DIRECTION_INPUT; latency.direction = impl->mode == MODE_SOURCE ? PW_DIRECTION_OUTPUT : PW_DIRECTION_INPUT;
latency.min_ns = latency.max_ns = impl->latency_msec * SPA_NSEC_PER_MSEC; latency.min_ns = latency.max_ns = impl->latency_msec * SPA_NSEC_PER_MSEC;
params[n_params++] = spa_latency_build(&b, params[n_params++] = spa_latency_build(&b,
SPA_PARAM_Latency, &latency); SPA_PARAM_Latency, &latency);
if ((res = pw_stream_connect(impl->stream, if ((res = pw_stream_connect(impl->stream,
impl->mode == MODE_CAPTURE ? PW_DIRECTION_OUTPUT : PW_DIRECTION_INPUT, impl->mode == MODE_SOURCE ? PW_DIRECTION_OUTPUT : PW_DIRECTION_INPUT,
PW_ID_ANY, PW_ID_ANY,
PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_AUTOCONNECT |
PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_MAP_BUFFERS |
@ -665,7 +665,7 @@ static int create_pulse_stream(struct impl *impl)
/* half in our buffer, half in the network + remote */ /* half in our buffer, half in the network + remote */
impl->target_buffer = latency_bytes / 2; impl->target_buffer = latency_bytes / 2;
if (impl->mode == MODE_CAPTURE) { if (impl->mode == MODE_SOURCE) {
bufferattr.fragsize = latency_bytes / 2; bufferattr.fragsize = latency_bytes / 2;
res = pa_stream_connect_record(impl->pa_stream, res = pa_stream_connect_record(impl->pa_stream,
@ -931,10 +931,10 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
spa_dll_init(&impl->dll); spa_dll_init(&impl->dll);
if ((str = pw_properties_get(props, "tunnel.mode")) != NULL) { if ((str = pw_properties_get(props, "tunnel.mode")) != NULL) {
if (spa_streq(str, "capture")) { if (spa_streq(str, "source")) {
impl->mode = MODE_CAPTURE; impl->mode = MODE_SOURCE;
} else if (spa_streq(str, "playback")) { } else if (spa_streq(str, "sink")) {
impl->mode = MODE_PLAYBACK; impl->mode = MODE_SINK;
} else { } else {
pw_log_error("invalid tunnel.mode '%s'", str); pw_log_error("invalid tunnel.mode '%s'", str);
res = -EINVAL; res = -EINVAL;
@ -952,7 +952,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
if (pw_properties_get(props, PW_KEY_MEDIA_CLASS) == NULL) if (pw_properties_get(props, PW_KEY_MEDIA_CLASS) == NULL)
pw_properties_set(props, PW_KEY_MEDIA_CLASS, pw_properties_set(props, PW_KEY_MEDIA_CLASS,
impl->mode == MODE_PLAYBACK ? impl->mode == MODE_SINK ?
"Audio/Sink" : "Audio/Source"); "Audio/Sink" : "Audio/Source");
if ((str = pw_properties_get(props, "stream.props")) != NULL) if ((str = pw_properties_get(props, "stream.props")) != NULL)

View file

@ -311,7 +311,7 @@ static void resolver_cb(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiPr
pw_properties_setf(props, PW_KEY_NODE_NAME, pw_properties_setf(props, PW_KEY_NODE_NAME,
"tunnel.%s", host_name); "tunnel.%s", host_name);
str = strstr(type, "sink") ? "playback" : "capture"; str = strstr(type, "sink") ? "sink" : "source";
pw_properties_set(props, "tunnel.mode", str); pw_properties_set(props, "tunnel.mode", str);
if (a->proto == AVAHI_PROTO_INET6 && if (a->proto == AVAHI_PROTO_INET6 &&