m-rtp-sap: add sap.announcer option to disable the send socket

In circumstances where the network interface is not ready yet,
creating a send socket will fail. This may be ok if we only
intend to use rtp-sap as a listener, therefore add an option for it.
This commit is contained in:
George Kiagiadakis 2024-08-19 13:06:03 +03:00
parent 1ef6db7d54
commit 242d75c6fc

View file

@ -45,6 +45,10 @@
* sess.sap.announce = true and it will create a receiver for all announced
* streams.
*
* If `sap.announcer` is set to `false`, the announce-stream action will not
* work. Use this to avoid opening a send socket if you are not going to use
* this functionality.
*
* ## Module Name
*
* `libpipewire-module-rtp-sap`
@ -64,6 +68,7 @@
* - `sap.max-sessions = <int>`: maximum number of concurrent send/receive sessions to track
* - `sap.preamble-extra = [strings]`: extra attributes to add to the atomic SDP preamble
* - `sap.end-extra = [strings]`: extra attributes to add to the end of the SDP message
* - `sap.announcer = <bool>`: enable announcing local streams, default true
*
* ## General options
*
@ -265,6 +270,7 @@ struct impl {
struct sockaddr_storage src_addr;
socklen_t src_len;
bool announcer;
uint16_t sap_port;
struct sockaddr_storage sap_addr;
@ -1085,7 +1091,7 @@ static int rule_matched(void *data, const char *location, const char *action,
session_load_source(i->session, i->props);
}
else if (i->node && spa_streq(action, "announce-stream")) {
else if (i->node && i->impl->announcer && spa_streq(action, "announce-stream")) {
struct pw_properties *props;
if ((props = pw_properties_new_dict(i->node->info->props)) == NULL)
@ -1486,12 +1492,14 @@ static int start_sap(struct impl *impl)
struct timespec value, interval;
char addr[128] = "invalid";
if ((fd = make_send_socket(&impl->src_addr, impl->src_len,
&impl->sap_addr, impl->sap_len,
impl->mcast_loop, impl->ttl)) < 0)
return fd;
if (impl->announcer) {
if ((fd = make_send_socket(&impl->src_addr, impl->src_len,
&impl->sap_addr, impl->sap_len,
impl->mcast_loop, impl->ttl)) < 0)
return fd;
impl->sap_fd = fd;
impl->sap_fd = fd;
}
pw_log_info("starting SAP timer");
impl->timer = pw_loop_add_timer(impl->loop, on_timer_event, impl);
@ -1733,6 +1741,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
impl->module = module;
impl->loop = pw_context_get_main_loop(context);
impl->announcer = pw_properties_get_bool(props, "sap.announcer", true);
str = pw_properties_get(props, "local.ifname");
impl->ifname = str ? strdup(str) : NULL;
@ -1754,7 +1764,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
"sap.cleanup.sec", DEFAULT_CLEANUP_SEC);
if ((str = pw_properties_get(props, "source.ip")) == NULL) {
if (impl->ifname) {
if (impl->ifname && impl->announcer) {
int fd = socket(impl->sap_addr.ss_family, SOCK_DGRAM, 0);
if (fd >= 0) {
struct ifreq req;