Make Multicast TTL for RTP configurable, patch from 'dfort'

Signed-off-by: Lennart Poettering <lennart@poettering.net>
This commit is contained in:
Lennart Poettering 2008-08-15 14:40:08 +02:00
parent f84536bc0a
commit 8d596a9bc5

View file

@ -68,9 +68,11 @@ PA_MODULE_USAGE(
"port=<port number> " "port=<port number> "
"mtu=<maximum transfer unit> " "mtu=<maximum transfer unit> "
"loop=<loopback to local host?> " "loop=<loopback to local host?> "
"ttl=<ttl value>"
); );
#define DEFAULT_PORT 46000 #define DEFAULT_PORT 46000
#define DEFAULT_TTL 1
#define SAP_PORT 9875 #define SAP_PORT 9875
#define DEFAULT_DESTINATION "224.0.0.56" #define DEFAULT_DESTINATION "224.0.0.56"
#define MEMBLOCKQ_MAXLENGTH (1024*170) #define MEMBLOCKQ_MAXLENGTH (1024*170)
@ -86,6 +88,7 @@ static const char* const valid_modargs[] = {
"port", "port",
"mtu" , "mtu" ,
"loop", "loop",
"ttl",
NULL NULL
}; };
@ -167,6 +170,7 @@ int pa__init(pa_module*m) {
pa_modargs *ma = NULL; pa_modargs *ma = NULL;
const char *dest; const char *dest;
uint32_t port = DEFAULT_PORT, mtu; uint32_t port = DEFAULT_PORT, mtu;
unsigned char ttl = DEFAULT_TTL;
int af, fd = -1, sap_fd = -1; int af, fd = -1, sap_fd = -1;
pa_source *s; pa_source *s;
pa_sample_spec ss; pa_sample_spec ss;
@ -235,6 +239,11 @@ int pa__init(pa_module*m) {
if (port & 1) if (port & 1)
pa_log_warn("Port number not even as suggested in RFC3550!"); pa_log_warn("Port number not even as suggested in RFC3550!");
if (pa_modargs_get_value_u32(ma, "ttl", &ttl) < 0 || ttl < 1 || ttl > 0xFF) {
pa_log("ttl= expects a numerical argument between 1 and 255.");
goto fail;
}
dest = pa_modargs_get_value(ma, "destination", DEFAULT_DESTINATION); dest = pa_modargs_get_value(ma, "destination", DEFAULT_DESTINATION);
if (inet_pton(AF_INET6, dest, &sa6.sin6_addr) > 0) { if (inet_pton(AF_INET6, dest, &sa6.sin6_addr) > 0) {
@ -279,6 +288,11 @@ int pa__init(pa_module*m) {
goto fail; goto fail;
} }
if (ttl != DEFAULT_TTL && setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) {
pa_log("IP_MULTICAST_TTL failed: %s", pa_cstrerror(errno));
goto fail;
}
/* If the socket queue is full, let's drop packets */ /* If the socket queue is full, let's drop packets */
pa_make_fd_nonblock(fd); pa_make_fd_nonblock(fd);
pa_make_udp_socket_low_delay(fd); pa_make_udp_socket_low_delay(fd);
@ -290,6 +304,7 @@ int pa__init(pa_module*m) {
pa_proplist_sets(data.proplist, "rtp.destination", dest); pa_proplist_sets(data.proplist, "rtp.destination", dest);
pa_proplist_setf(data.proplist, "rtp.mtu", "%lu", (unsigned long) mtu); pa_proplist_setf(data.proplist, "rtp.mtu", "%lu", (unsigned long) mtu);
pa_proplist_setf(data.proplist, "rtp.port", "%lu", (unsigned long) port); pa_proplist_setf(data.proplist, "rtp.port", "%lu", (unsigned long) port);
pa_proplist_setf(data.proplist, "rtp.ttl", "%lu", (unsigned long) ttl);
data.driver = __FILE__; data.driver = __FILE__;
data.module = m; data.module = m;
data.source = s; data.source = s;
@ -342,7 +357,7 @@ int pa__init(pa_module*m) {
pa_rtp_context_init_send(&u->rtp_context, fd, m->core->cookie, payload, pa_frame_size(&ss)); pa_rtp_context_init_send(&u->rtp_context, fd, m->core->cookie, payload, pa_frame_size(&ss));
pa_sap_context_init_send(&u->sap_context, sap_fd, p); pa_sap_context_init_send(&u->sap_context, sap_fd, p);
pa_log_info("RTP stream initialized with mtu %u on %s:%u, SSRC=0x%08x, payload=%u, initial sequence #%u", mtu, dest, port, u->rtp_context.ssrc, payload, u->rtp_context.sequence); pa_log_info("RTP stream initialized with mtu %u on %s:%u ttl=%u, SSRC=0x%08x, payload=%u, initial sequence #%u", mtu, dest, port, ttl, u->rtp_context.ssrc, payload, u->rtp_context.sequence);
pa_log_info("SDP-Data:\n%s\nEOF", p); pa_log_info("SDP-Data:\n%s\nEOF", p);
pa_sap_send(&u->sap_context, 0); pa_sap_send(&u->sap_context, 0);