PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
#include <errno.h>
-#include <string.h>
#include <unistd.h>
+#include <pulse/rtclock.h>
#include <pulse/timeval.h>
#include <pulse/util.h>
#include <pulse/xmalloc.h>
#include <pulsecore/core-error.h>
#include <pulsecore/module.h>
-#include <pulsecore/llist.h>
#include <pulsecore/source.h>
#include <pulsecore/source-output.h>
#include <pulsecore/memblockq.h>
#include <pulsecore/sample-util.h>
#include <pulsecore/macro.h>
#include <pulsecore/socket-util.h>
+#include <pulsecore/arpa-inet.h>
#include "module-rtp-send-symdef.h"
#define DEFAULT_DESTINATION "224.0.0.56"
#define MEMBLOCKQ_MAXLENGTH (1024*170)
#define DEFAULT_MTU 1280
-#define SAP_INTERVAL 5
+#define SAP_INTERVAL (5*PA_USEC_PER_SEC)
static const char* const valid_modargs[] = {
"source",
static void sap_event_cb(pa_mainloop_api *m, pa_time_event *t, const struct timeval *tv, void *userdata) {
struct userdata *u = userdata;
- struct timeval next;
pa_assert(m);
pa_assert(t);
- pa_assert(tv);
pa_assert(u);
pa_sap_send(&u->sap_context, 0);
- pa_gettimeofday(&next);
- pa_timeval_add(&next, SAP_INTERVAL * PA_USEC_PER_SEC);
- m->time_restart(t, &next);
+ pa_core_rttime_restart(u->module->core, t, pa_rtclock_now() + SAP_INTERVAL);
}
int pa__init(pa_module*m) {
pa_sample_spec ss;
pa_channel_map cm;
struct sockaddr_in sa4, sap_sa4;
+#ifdef HAVE_IPV6
struct sockaddr_in6 sa6, sap_sa6;
+#endif
struct sockaddr_storage sa_dst;
pa_source_output *o = NULL;
uint8_t payload;
char *p;
int r, j;
socklen_t k;
- struct timeval tv;
char hn[128], *n;
pa_bool_t loop = FALSE;
pa_source_output_new_data data;
goto fail;
}
- if (!(s = pa_namereg_get(m->core, pa_modargs_get_value(ma, "source", NULL), PA_NAMEREG_SOURCE, 1))) {
+ if (!(s = pa_namereg_get(m->core, pa_modargs_get_value(ma, "source", NULL), PA_NAMEREG_SOURCE))) {
pa_log("Source does not exist.");
goto fail;
}
dest = pa_modargs_get_value(ma, "destination", DEFAULT_DESTINATION);
- if (inet_pton(AF_INET6, dest, &sa6.sin6_addr) > 0) {
- sa6.sin6_family = af = AF_INET6;
- sa6.sin6_port = htons((uint16_t) port);
- sap_sa6 = sa6;
- sap_sa6.sin6_port = htons(SAP_PORT);
- } else if (inet_pton(AF_INET, dest, &sa4.sin_addr) > 0) {
+ if (inet_pton(AF_INET, dest, &sa4.sin_addr) > 0) {
sa4.sin_family = af = AF_INET;
sa4.sin_port = htons((uint16_t) port);
sap_sa4 = sa4;
sap_sa4.sin_port = htons(SAP_PORT);
+#ifdef HAVE_IPV6
+ } else if (inet_pton(AF_INET6, dest, &sa6.sin6_addr) > 0) {
+ sa6.sin6_family = af = AF_INET6;
+ sa6.sin6_port = htons((uint16_t) port);
+ sap_sa6 = sa6;
+ sap_sa6.sin6_port = htons(SAP_PORT);
+#endif
} else {
pa_log("Invalid destination '%s'", dest);
goto fail;
}
- if ((fd = socket(af, SOCK_DGRAM, 0)) < 0) {
+ if ((fd = pa_socket_cloexec(af, SOCK_DGRAM, 0)) < 0) {
pa_log("socket() failed: %s", pa_cstrerror(errno));
goto fail;
}
- if (connect(fd, af == AF_INET ? (struct sockaddr*) &sa4 : (struct sockaddr*) &sa6, (socklen_t) (af == AF_INET ? sizeof(sa4) : sizeof(sa6))) < 0) {
+ if (af == AF_INET && connect(fd, (struct sockaddr*) &sa4, sizeof(sa4)) < 0) {
+ pa_log("connect() failed: %s", pa_cstrerror(errno));
+ goto fail;
+#ifdef HAVE_IPV6
+ } else if (af == AF_INET6 && connect(fd, (struct sockaddr*) &sa6, sizeof(sa6)) < 0) {
pa_log("connect() failed: %s", pa_cstrerror(errno));
goto fail;
+#endif
}
- if ((sap_fd = socket(af, SOCK_DGRAM, 0)) < 0) {
+ if ((sap_fd = pa_socket_cloexec(af, SOCK_DGRAM, 0)) < 0) {
pa_log("socket() failed: %s", pa_cstrerror(errno));
goto fail;
}
- if (connect(sap_fd, af == AF_INET ? (struct sockaddr*) &sap_sa4 : (struct sockaddr*) &sap_sa6, (socklen_t) (af == AF_INET ? sizeof(sap_sa4) : sizeof(sap_sa6))) < 0) {
+ if (af == AF_INET && connect(sap_fd, (struct sockaddr*) &sap_sa4, sizeof(sap_sa4)) < 0) {
+ pa_log("connect() failed: %s", pa_cstrerror(errno));
+ goto fail;
+#ifdef HAVE_IPV6
+ } else if (af == AF_INET6 && connect(sap_fd, (struct sockaddr*) &sap_sa6, sizeof(sap_sa6)) < 0) {
pa_log("connect() failed: %s", pa_cstrerror(errno));
goto fail;
+#endif
}
j = !!loop;
pa_log("IP_MULTICAST_TTL failed: %s", pa_cstrerror(errno));
goto fail;
}
+
+ if (setsockopt(sap_fd, IPPROTO_IP, IP_MULTICAST_TTL, &_ttl, sizeof(_ttl)) < 0) {
+ pa_log("IP_MULTICAST_TTL (sap) failed: %s", pa_cstrerror(errno));
+ goto fail;
+ }
}
/* If the socket queue is full, let's drop packets */
pa_make_fd_nonblock(fd);
pa_make_udp_socket_low_delay(fd);
- pa_make_fd_cloexec(fd);
- pa_make_fd_cloexec(sap_fd);
pa_source_output_new_data_init(&data);
pa_proplist_sets(data.proplist, PA_PROP_MEDIA_NAME, "RTP Monitor Stream");
pa_proplist_setf(data.proplist, "rtp.ttl", "%lu", (unsigned long) ttl);
data.driver = __FILE__;
data.module = m;
- data.source = s;
+ pa_source_output_new_data_set_source(&data, s, FALSE);
pa_source_output_new_data_set_sample_spec(&data, &ss);
pa_source_output_new_data_set_channel_map(&data, &cm);
+ data.flags = PA_SOURCE_OUTPUT_DONT_INHIBIT_AUTO_SUSPEND;
- o = pa_source_output_new(m->core, &data, PA_SOURCE_OUTPUT_DONT_INHIBIT_AUTO_SUSPEND);
+ pa_source_output_new(&o, m->core, &data);
pa_source_output_new_data_done(&data);
if (!o) {
o->push = source_output_push;
o->kill = source_output_kill;
- u = pa_xnew(struct userdata, 1);
- m->userdata = u;
- o->userdata = u;
+ pa_log_info("Configured source latency of %llu ms.",
+ (unsigned long long) pa_source_output_set_requested_latency(o, pa_bytes_to_usec(mtu, &o->sample_spec)) / PA_USEC_PER_MSEC);
+ m->userdata = o->userdata = u = pa_xnew(struct userdata, 1);
u->module = m;
u->source_output = o;
n = pa_sprintf_malloc("PulseAudio RTP Stream on %s", pa_get_fqdn(hn, sizeof(hn)));
- p = pa_sdp_build(af,
- af == AF_INET ? (void*) &((struct sockaddr_in*) &sa_dst)->sin_addr : (void*) &((struct sockaddr_in6*) &sa_dst)->sin6_addr,
- af == AF_INET ? (void*) &sa4.sin_addr : (void*) &sa6.sin6_addr,
+ if (af == AF_INET) {
+ p = pa_sdp_build(af,
+ (void*) &((struct sockaddr_in*) &sa_dst)->sin_addr,
+ (void*) &sa4.sin_addr,
+ n, (uint16_t) port, payload, &ss);
+#ifdef HAVE_IPV6
+ } else {
+ p = pa_sdp_build(af,
+ (void*) &((struct sockaddr_in6*) &sa_dst)->sin6_addr,
+ (void*) &sa6.sin6_addr,
n, (uint16_t) port, payload, &ss);
+#endif
+ }
pa_xfree(n);
pa_sap_send(&u->sap_context, 0);
- pa_gettimeofday(&tv);
- pa_timeval_add(&tv, SAP_INTERVAL * PA_USEC_PER_SEC);
- u->sap_event = m->core->mainloop->time_new(m->core->mainloop, &tv, sap_event_cb, u);
+ u->sap_event = pa_core_rttime_new(m->core, pa_rtclock_now() + SAP_INTERVAL, sap_event_cb, u);
pa_source_output_put(u->source_output);