diff options
author | Alfred E. Heggestad <aeh@db.org> | 2014-05-17 22:31:27 +0200 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2014-05-17 22:31:27 +0200 |
commit | f364bd21b79f214966ef0d0eb62a998cdc5a575f (patch) | |
tree | c4b63f494f4f2fda5d64fd42882750f6451d95d1 /src/audio.c | |
parent | b2d645892600b8103293587662fb81baae3d8220 (diff) |
audio: fix timestamp calculation for sending
according to RFC 3551 the RTP timestamp is independent of
number of channels and encoding. fix the timestamp calculation
for outgoing RTP packets, by dividing the total number of samples
on number of channels.
the bug was not affecting calls with mono audio, but was very
likely to affect calls with stereo audio (e.g. OPUS)
Diffstat (limited to 'src/audio.c')
-rw-r--r-- | src/audio.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/audio.c b/src/audio.c index 46d7f03..d8bb689 100644 --- a/src/audio.c +++ b/src/audio.c @@ -302,6 +302,7 @@ static int add_audio_codec(struct audio *a, struct sdp_media *m, static void encode_rtp_send(struct audio *a, struct autx *tx, int16_t *sampv, size_t sampc) { + unsigned frame_size; /* number of samples per channel */ size_t len; int err; @@ -328,7 +329,12 @@ static void encode_rtp_send(struct audio *a, struct autx *tx, goto out; } - tx->ts += (uint32_t)(tx->is_g722 ? sampc/2 : sampc); + /* The RTP clock rate used for generating the RTP timestamp is + * independent of the number of channels and the encoding + */ + frame_size = (tx->is_g722 ? sampc/2 : sampc) / tx->ac->ch; + + tx->ts += frame_size; out: tx->marker = false; @@ -700,7 +706,7 @@ int audio_alloc(struct audio **ap, const struct config *cfg, auresamp_init(&tx->resamp); str_ncpy(tx->device, a->cfg.src_dev, sizeof(tx->device)); tx->ptime = ptime; - tx->ts = 160; + tx->ts = rand_u16(); tx->marker = true; auresamp_init(&rx->resamp); |