[pulseaudio-discuss,3/3] rtp-recv: Allow same timestamp in consecutive packets

Submitted by Cédric Schieli on May 9, 2016, 9:33 a.m.

Details

Message ID 1462786434-18477-4-git-send-email-cschieli@gmail.com
State New
Headers show
Series "rtp-recv: interoperability fixes" ( rev: 1 ) in PulseAudio

Not browsing as part of any series.

Commit Message

Cédric Schieli May 9, 2016, 9:33 a.m.
The current code is built with the assumption that the timestamp field
in one RTP header will be greater than the one from the preceding packet,
which is true when recieving from another PA instance, but not in the
general case.

According to RFC 3550 section 5.1: Several consecutive RTP packets will
have equal timestamps if they are (logically) generated at once, e.g.,
belong to the same video frame.

Signed-off-by: Cédric Schieli <cschieli@gmail.com>
---
 src/modules/rtp/rtp.c | 10 ++++++++++
 src/modules/rtp/rtp.h |  2 ++
 2 files changed, 12 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/modules/rtp/rtp.c b/src/modules/rtp/rtp.c
index 170ce96..163f6f2 100644
--- a/src/modules/rtp/rtp.c
+++ b/src/modules/rtp/rtp.c
@@ -154,6 +154,8 @@  pa_rtp_context* pa_rtp_context_init_recv(pa_rtp_context *c, int fd, size_t frame
 
     c->fd = fd;
     c->frame_size = frame_size;
+    c->prev_timestamp = 0;
+    c->offset = 0;
 
     pa_memchunk_reset(&c->memchunk);
     return c;
@@ -308,6 +310,14 @@  int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_mempool *pool, struct
         pa_zero(*tstamp);
     }
 
+    if (c->timestamp == c->prev_timestamp) {
+        c->timestamp += c->offset;
+    } else {
+        c->prev_timestamp = c->timestamp;
+        c->offset = 0;
+    }
+    c->offset += (chunk->length / c->frame_size);
+
     return 0;
 
 fail:
diff --git a/src/modules/rtp/rtp.h b/src/modules/rtp/rtp.h
index bbd4278..7e5dbb0 100644
--- a/src/modules/rtp/rtp.h
+++ b/src/modules/rtp/rtp.h
@@ -30,6 +30,8 @@  typedef struct pa_rtp_context {
     int fd;
     uint16_t sequence;
     uint32_t timestamp;
+    uint32_t prev_timestamp;
+    uint32_t offset;
     uint32_t ssrc;
     uint8_t payload;
     size_t frame_size;