module-rtp-sap/sink: try to bind sockets to an explicit interface

This commit is contained in:
Arun Raghavan 2023-10-24 07:17:21 +00:00 committed by Wim Taymans
parent 963ea1f57c
commit 5617fa0501
2 changed files with 16 additions and 3 deletions

View file

@ -757,6 +757,11 @@ static int session_load_source(struct session *session, struct pw_properties *pr
if ((str = pw_properties_get(props, "rtp.session")) != NULL) if ((str = pw_properties_get(props, "rtp.session")) != NULL)
fprintf(f, "\"sess.name\" = \"%s\", ", str); fprintf(f, "\"sess.name\" = \"%s\", ", str);
/* Use an interface if explicitly specified, else use the SAP interface if that was specified */
if ((str = pw_properties_get(props, "local.ifname")) != NULL || (str = impl->ifname) != NULL) {
fprintf(f, "\"local.ifname\" = \"%s\", ", str);
}
if ((media = pw_properties_get(props, "sess.media")) == NULL) if ((media = pw_properties_get(props, "sess.media")) == NULL)
media = "audio"; media = "audio";
@ -1540,7 +1545,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
pw_impl_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_info)); pw_impl_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_info));
pw_log_info("Successfully loaded module-rtp-sink"); pw_log_info("Successfully loaded module-rtp-sap");
return 0; return 0;
out: out:

View file

@ -253,7 +253,7 @@ static bool is_multicast(struct sockaddr *sa, socklen_t salen)
static int make_socket(struct sockaddr_storage *src, socklen_t src_len, static int make_socket(struct sockaddr_storage *src, socklen_t src_len,
struct sockaddr_storage *dst, socklen_t dst_len, struct sockaddr_storage *dst, socklen_t dst_len,
bool loop, int ttl, int dscp) bool loop, int ttl, int dscp, char *ifname)
{ {
int af, fd, val, res; int af, fd, val, res;
@ -267,6 +267,13 @@ static int make_socket(struct sockaddr_storage *src, socklen_t src_len,
pw_log_error("bind() failed: %m"); pw_log_error("bind() failed: %m");
goto error; goto error;
} }
#ifdef SO_BINDTODEVICE
if (ifname && setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname)) < 0) {
res = -errno;
pw_log_error("setsockopt(SO_BINDTODEVICE) failed: %m");
goto error;
}
#endif
if (connect(fd, (struct sockaddr*)dst, dst_len) < 0) { if (connect(fd, (struct sockaddr*)dst, dst_len) < 0) {
res = -errno; res = -errno;
pw_log_error("connect() failed: %m"); pw_log_error("connect() failed: %m");
@ -517,7 +524,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
if ((res = make_socket(&impl->src_addr, impl->src_len, if ((res = make_socket(&impl->src_addr, impl->src_len,
&impl->dst_addr, impl->dst_len, &impl->dst_addr, impl->dst_len,
impl->mcast_loop, impl->ttl, impl->dscp)) < 0) { impl->mcast_loop, impl->ttl, impl->dscp,
impl->ifname)) < 0) {
pw_log_error("can't make socket: %s", spa_strerror(res)); pw_log_error("can't make socket: %s", spa_strerror(res));
goto out; goto out;
} }