[PATCH 3/3] rtp-recv: Allow same timestamp in consecutive packets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 at gmail.com>
---
 src/modules/rtp/rtp.c | 10 ++++++++++
 src/modules/rtp/rtp.h |  2 ++
 2 files changed, 12 insertions(+)

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;
-- 
2.7.3



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux