summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <git@arunraghavan.net>2016-02-29 14:28:58 +0530
committerTanu Kaskinen <tanuk@iki.fi>2016-04-02 21:41:10 +0300
commitc931d41b789b22d4c1f15bb0d14b41011a448c65 (patch)
treef3bceed207179129d37a9f803c54a6bfb36c10d5
parent2d12aadc7c9349101d37990a8185036f054d64e6 (diff)
rtp: Do all receive side rate calculations in sink-input domain
The code was mixing sink and sink input domain rate updates, and that only works if the rate of the RTP stream is the same as the rate of the sink. This changes all the calcuations to be on the sink-input rate, since that's the rate we are trying to guess (and resample for).
-rw-r--r--src/modules/rtp/module-rtp-recv.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index dc42f7cf8..5977500cf 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -106,6 +106,7 @@ struct session {
pa_usec_t intended_latency;
pa_usec_t sink_latency;
+ unsigned int base_rate;
pa_usec_t last_rate_update;
pa_usec_t last_latency;
double estimated_rate;
@@ -284,7 +285,6 @@ static int rtpoll_work_cb(pa_rtpoll_item *i) {
if (s->last_rate_update + RATE_UPDATE_INTERVAL < pa_timeval_load(&now)) {
pa_usec_t wi, ri, render_delay, sink_delay = 0, latency;
- uint32_t base_rate = s->sink_input->sink->sample_spec.rate;
uint32_t current_rate = s->sink_input->sample_spec.rate;
uint32_t new_rate;
double estimated_rate, alpha = 0.02;
@@ -351,12 +351,12 @@ static int rtpoll_work_cb(pa_rtpoll_item *i) {
new_rate = (uint32_t) ((double) (RATE_UPDATE_INTERVAL + latency/4 - s->intended_latency/4) / (double) RATE_UPDATE_INTERVAL * s->avg_estimated_rate);
s->last_latency = latency;
- if (new_rate < (uint32_t) (base_rate*0.8) || new_rate > (uint32_t) (base_rate*1.25)) {
- pa_log_warn("Sample rates too different, not adjusting (%u vs. %u).", base_rate, new_rate);
- new_rate = base_rate;
+ if (new_rate < (uint32_t) (s->base_rate*0.8) || new_rate > (uint32_t) (s->base_rate*1.25)) {
+ pa_log_warn("Sample rates too different, not adjusting (%u vs. %u).", s->base_rate, new_rate);
+ new_rate = s->base_rate;
} else {
- if (base_rate < new_rate + 20 && new_rate < base_rate + 20)
- new_rate = base_rate;
+ if (s->base_rate < new_rate + 20 && new_rate < s->base_rate + 20)
+ new_rate = s->base_rate;
/* Do the adjustment in small steps; 2‰ can be considered inaudible */
if (new_rate < (uint32_t) (current_rate*0.998) || new_rate > (uint32_t) (current_rate*1.002)) {
pa_log_info("New rate of %u Hz not within 2‰ of %u Hz, forcing smaller adjustment", new_rate, current_rate);
@@ -521,8 +521,6 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in
s->intended_latency = u->latency;
s->last_rate_update = pa_timeval_load(&now);
s->last_latency = u->latency;
- s->estimated_rate = (double) sink->sample_spec.rate;
- s->avg_estimated_rate = (double) sink->sample_spec.rate;
pa_atomic_store(&s->timestamp, (int) now.tv_sec);
if ((fd = mcast_socket((const struct sockaddr*) &sdp_info->sa, sdp_info->salen)) < 0)
@@ -554,6 +552,10 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in
goto fail;
}
+ s->base_rate = (double) s->sink_input->sample_spec.rate;
+ s->estimated_rate = (double) s->sink_input->sample_spec.rate;
+ s->avg_estimated_rate = (double) s->sink_input->sample_spec.rate;
+
s->sink_input->userdata = s;
s->sink_input->parent.process_msg = sink_input_process_msg;