diff --git a/libavformat/rdt.c b/libavformat/rdt.c
index 35540de4a6298f8296552afde0d319526a152f27..77c1c8c9205590d9ef056ad1b29e4a614d290cb5 100644
--- a/libavformat/rdt.c
+++ b/libavformat/rdt.c
@@ -293,7 +293,7 @@ ff_rdt_parse_header(const uint8_t *buf, int len,
 static int
 rdt_parse_packet (AVFormatContext *ctx, PayloadContext *rdt, AVStream *st,
                   AVPacket *pkt, uint32_t *timestamp,
-                  const uint8_t *buf, int len, int flags)
+                  const uint8_t *buf, int len, uint16_t rtp_seq, int flags)
 {
     int seq = 1, res;
     AVIOContext pb;
@@ -348,7 +348,7 @@ ff_rdt_parse_packet(RDTDemuxContext *s, AVPacket *pkt,
         timestamp= 0; ///< Should not be used if buf is NULL, but should be set to the timestamp of the packet returned....
         rv= s->parse_packet(s->ic, s->dynamic_protocol_context,
                             s->streams[s->prev_stream_id],
-                            pkt, &timestamp, NULL, 0, flags);
+                            pkt, &timestamp, NULL, 0, 0, flags);
         return rv;
     }
 
@@ -375,7 +375,7 @@ ff_rdt_parse_packet(RDTDemuxContext *s, AVPacket *pkt,
 
     rv = s->parse_packet(s->ic, s->dynamic_protocol_context,
                          s->streams[s->prev_stream_id],
-                         pkt, &timestamp, buf, len, flags);
+                         pkt, &timestamp, buf, len, 0, flags);
 
     return rv;
 }
diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c
index b83a79bdbbf25497ba83037292d1e7bdf7ac8718..10439305ddd5c149bc20fd5455c64d4bb149f617 100644
--- a/libavformat/rtpdec.c
+++ b/libavformat/rtpdec.c
@@ -539,7 +539,7 @@ static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt,
         return 0;
     } else if (s->parse_packet) {
         rv = s->parse_packet(s->ic, s->dynamic_protocol_context,
-                             s->st, pkt, &timestamp, buf, len, flags);
+                             s->st, pkt, &timestamp, buf, len, seq, flags);
     } else {
         /* At this point, the RTP header has been stripped;
          * This is ASSUMING that there is only 1 CSRC, which isn't wise. */
@@ -682,7 +682,8 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
              * the packet is left with pts == AV_NOPTS_VALUE */
             timestamp = RTP_NOTS_VALUE;
             rv        = s->parse_packet(s->ic, s->dynamic_protocol_context,
-                                        s->st, pkt, &timestamp, NULL, 0, flags);
+                                        s->st, pkt, &timestamp, NULL, 0, 0,
+                                        flags);
             finalize_packet(s, pkt, timestamp);
             return rv;
         } else {
diff --git a/libavformat/rtpdec.h b/libavformat/rtpdec.h
index 668a1f7c989d2c42102bb9094cefe343d5b6ef90..98e266a687837ce1bc552e2308cb7b5bf91b7f7d 100644
--- a/libavformat/rtpdec.h
+++ b/libavformat/rtpdec.h
@@ -101,6 +101,7 @@ typedef struct RTPStatistics {
  *                  updated by the function if returning older, buffered data
  * @param buf pointer to raw RTP packet data
  * @param len length of buf
+ * @param seq RTP sequence number of the packet
  * @param flags flags from the RTP packet header (RTP_FLAG_*)
  */
 typedef int (*DynamicPayloadPacketHandlerProc)(AVFormatContext *ctx,
@@ -108,7 +109,7 @@ typedef int (*DynamicPayloadPacketHandlerProc)(AVFormatContext *ctx,
                                                AVStream *st, AVPacket *pkt,
                                                uint32_t *timestamp,
                                                const uint8_t * buf,
-                                               int len, int flags);
+                                               int len, uint16_t seq, int flags);
 
 struct RTPDynamicProtocolHandler {
     const char enc_name[50];
diff --git a/libavformat/rtpdec_amr.c b/libavformat/rtpdec_amr.c
index 1e602874657f899ab52fbfba84b8b4acde1f7f22..fd18ff22d4280e4e0582cea5df8e1f5f63da8f9b 100644
--- a/libavformat/rtpdec_amr.c
+++ b/libavformat/rtpdec_amr.c
@@ -51,13 +51,10 @@ static void amr_free_context(PayloadContext *data)
     av_free(data);
 }
 
-static int amr_handle_packet(AVFormatContext *ctx,
-                             PayloadContext *data,
-                             AVStream *st,
-                             AVPacket * pkt,
-                             uint32_t * timestamp,
-                             const uint8_t * buf,
-                             int len, int flags)
+static int amr_handle_packet(AVFormatContext *ctx, PayloadContext *data,
+                             AVStream *st, AVPacket *pkt, uint32_t *timestamp,
+                             const uint8_t *buf, int len, uint16_t seq,
+                             int flags)
 {
     const uint8_t *frame_sizes = NULL;
     int frames;
diff --git a/libavformat/rtpdec_asf.c b/libavformat/rtpdec_asf.c
index 7c13b967f5dbc41962a7f89273a6c896668a750d..e42565069651dbbfa215c3bc762ce528313dae3d 100644
--- a/libavformat/rtpdec_asf.c
+++ b/libavformat/rtpdec_asf.c
@@ -168,7 +168,8 @@ struct PayloadContext {
 static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf,
                                AVStream *st, AVPacket *pkt,
                                uint32_t *timestamp,
-                               const uint8_t *buf, int len, int flags)
+                               const uint8_t *buf, int len, uint16_t seq,
+                               int flags)
 {
     AVIOContext *pb = &asf->pb;
     int res, mflags, len_off;
diff --git a/libavformat/rtpdec_formats.h b/libavformat/rtpdec_formats.h
index c538b93cca0219b8abb664d99acc0a46cf363655..e449ddfac3e6b6ff0ca8436f7949e238e5d5756e 100644
--- a/libavformat/rtpdec_formats.h
+++ b/libavformat/rtpdec_formats.h
@@ -33,7 +33,7 @@ int ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p);
 
 int ff_h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                           AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                          const uint8_t *buf, int len, int flags);
+                          const uint8_t *buf, int len, uint16_t seq, int flags);
 
 extern RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler;
 extern RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler;
diff --git a/libavformat/rtpdec_h263.c b/libavformat/rtpdec_h263.c
index 78773b9f663bf8d6d0095b29255536f941408be6..bdb5195396c3be505b4823101c5fee0b4edbd2f5 100644
--- a/libavformat/rtpdec_h263.c
+++ b/libavformat/rtpdec_h263.c
@@ -25,7 +25,7 @@
 
 int ff_h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                           AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                          const uint8_t *buf, int len, int flags)
+                          const uint8_t *buf, int len, uint16_t seq, int flags)
 {
     uint8_t *ptr;
     uint16_t header;
diff --git a/libavformat/rtpdec_h263_rfc2190.c b/libavformat/rtpdec_h263_rfc2190.c
index 4957b337c7b96c8c928c443495a7252fdf5cbea8..4792a9fdc5f50ef33b565881471c4d9ceaafb02f 100644
--- a/libavformat/rtpdec_h263_rfc2190.c
+++ b/libavformat/rtpdec_h263_rfc2190.c
@@ -57,7 +57,8 @@ static void h263_free_context(PayloadContext *data)
 
 static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                              const uint8_t *buf, int len, int flags)
+                              const uint8_t *buf, int len, uint16_t seq,
+                              int flags)
 {
     /* Corresponding to header fields in the RFC */
     int f, p, i, sbit, ebit, src, r;
@@ -65,7 +66,7 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
 
     if (data->newformat)
         return ff_h263_handle_packet(ctx, data, st, pkt, timestamp, buf, len,
-                                     flags);
+                                     seq, flags);
 
     if (data->buf && data->timestamp != *timestamp) {
         /* Dropping old buffered, unfinished data */
@@ -122,7 +123,7 @@ static int h263_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                    "signalled with a static payload type.\n");
             data->newformat = 1;
             return ff_h263_handle_packet(ctx, data, st, pkt, timestamp, buf,
-                                         len, flags);
+                                         len, seq, flags);
         }
     }
 
diff --git a/libavformat/rtpdec_h264.c b/libavformat/rtpdec_h264.c
index 7408b431017a38b258bba781863ad5fa064daaca..2df0930f6163a595143050eabe45d2ed799cd30d 100644
--- a/libavformat/rtpdec_h264.c
+++ b/libavformat/rtpdec_h264.c
@@ -165,7 +165,8 @@ static int sdp_parse_fmtp_config_h264(AVStream *stream,
 // return 0 on packet, no more left, 1 on packet, 1 on partial packet
 static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data,
                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                              const uint8_t *buf, int len, int flags)
+                              const uint8_t *buf, int len, uint16_t seq,
+                              int flags)
 {
     uint8_t nal;
     uint8_t type;
diff --git a/libavformat/rtpdec_jpeg.c b/libavformat/rtpdec_jpeg.c
index 25bb88d0d1b7c838174ff23b19f8f58e6d479553..ed9c86ceb960359a66223474c60dba1ec7d94a6a 100644
--- a/libavformat/rtpdec_jpeg.c
+++ b/libavformat/rtpdec_jpeg.c
@@ -219,7 +219,8 @@ static void create_default_qtables(uint8_t *qtables, uint8_t q)
 
 static int jpeg_parse_packet(AVFormatContext *ctx, PayloadContext *jpeg,
                              AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                             const uint8_t *buf, int len, int flags)
+                             const uint8_t *buf, int len, uint16_t seq,
+                             int flags)
 {
     uint8_t type, q, width, height;
     const uint8_t *qtables = NULL;
diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c
index 3fa04682b8c098b62fdb75676f8cf32d62fa3c16..7d4ae1e44847766d0180279838684491e6c3dec8 100644
--- a/libavformat/rtpdec_latm.c
+++ b/libavformat/rtpdec_latm.c
@@ -51,7 +51,8 @@ static void latm_free_context(PayloadContext *data)
 
 static int latm_parse_packet(AVFormatContext *ctx, PayloadContext *data,
                              AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                             const uint8_t *buf, int len, int flags)
+                             const uint8_t *buf, int len, uint16_t seq,
+                             int flags)
 {
     int ret, cur_len;
 
diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c
index dda48d8972629435585de21c79ece73a6eebc707..13d051ae85e6aea5c56efdd10162db300695b732 100644
--- a/libavformat/rtpdec_mpeg4.c
+++ b/libavformat/rtpdec_mpeg4.c
@@ -159,7 +159,8 @@ static int rtp_parse_mp4_au(PayloadContext *data, const uint8_t *buf)
 /* Follows RFC 3640 */
 static int aac_parse_packet(AVFormatContext *ctx, PayloadContext *data,
                             AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                            const uint8_t *buf, int len, int flags)
+                            const uint8_t *buf, int len, uint16_t seq,
+                            int flags)
 {
     if (rtp_parse_mp4_au(data, buf))
         return -1;
diff --git a/libavformat/rtpdec_qcelp.c b/libavformat/rtpdec_qcelp.c
index 56f3e17819caff5f668eb8d8c0ea0e8bc5851af0..45a89ae4f773da1b89959f395a1179262c623e6f 100644
--- a/libavformat/rtpdec_qcelp.c
+++ b/libavformat/rtpdec_qcelp.c
@@ -210,7 +210,8 @@ static int return_stored_frame(AVFormatContext *ctx, PayloadContext *data,
 
 static int qcelp_parse_packet(AVFormatContext *ctx, PayloadContext *data,
                               AVStream *st, AVPacket *pkt, uint32_t *timestamp,
-                              const uint8_t *buf, int len, int flags)
+                              const uint8_t *buf, int len, uint16_t seq,
+                              int flags)
 {
     if (buf)
         return store_packet(ctx, data, st, pkt, timestamp, buf, len);
diff --git a/libavformat/rtpdec_qdm2.c b/libavformat/rtpdec_qdm2.c
index a2ce510d26bc97822340e965aded3d2c5d8fe9af..0d7b5bb87a601d5003cd23906d5a19a0f036cbb0 100644
--- a/libavformat/rtpdec_qdm2.c
+++ b/libavformat/rtpdec_qdm2.c
@@ -237,7 +237,8 @@ static int qdm2_restore_block(PayloadContext *qdm, AVStream *st, AVPacket *pkt)
 static int qdm2_parse_packet(AVFormatContext *s, PayloadContext *qdm,
                              AVStream *st, AVPacket *pkt,
                              uint32_t *timestamp,
-                             const uint8_t *buf, int len, int flags)
+                             const uint8_t *buf, int len, uint16_t seq,
+                             int flags)
 {
     int res = AVERROR_INVALIDDATA, n;
     const uint8_t *end = buf + len, *p = buf;
diff --git a/libavformat/rtpdec_qt.c b/libavformat/rtpdec_qt.c
index 30931326727312a5d757b456fed2ec6a45393804..6350507fc211e137f9a7d03a479baa980237dc1c 100644
--- a/libavformat/rtpdec_qt.c
+++ b/libavformat/rtpdec_qt.c
@@ -42,7 +42,7 @@ struct PayloadContext {
 static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
                                AVStream *st, AVPacket *pkt,
                                uint32_t *timestamp, const uint8_t *buf,
-                               int len, int flags)
+                               int len, uint16_t seq, int flags)
 {
     AVIOContext pb;
     GetBitContext gb;
diff --git a/libavformat/rtpdec_svq3.c b/libavformat/rtpdec_svq3.c
index 087a1e3346cd31dc04daeb0f10aec9a091cef417..aa880e595487a2e90ea1d685dcd9441144b6bb0f 100644
--- a/libavformat/rtpdec_svq3.c
+++ b/libavformat/rtpdec_svq3.c
@@ -41,7 +41,8 @@ struct PayloadContext {
 static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv,
                               AVStream *st, AVPacket *pkt,
                               uint32_t *timestamp,
-                              const uint8_t *buf, int len, int flags)
+                              const uint8_t *buf, int len, uint16_t seq,
+                              int flags)
 {
     int config_packet, start_packet, end_packet;
 
diff --git a/libavformat/rtpdec_vp8.c b/libavformat/rtpdec_vp8.c
index 99ca60a6f7c496c592af074ffde4d2dc5b72b630..1259eff5090c70f3016273f7ceffa65be8b85331 100644
--- a/libavformat/rtpdec_vp8.c
+++ b/libavformat/rtpdec_vp8.c
@@ -36,13 +36,10 @@ struct PayloadContext {
     uint32_t     timestamp;
 };
 
-static int vp8_handle_packet(AVFormatContext *ctx,
-                             PayloadContext *vp8,
-                             AVStream *st,
-                             AVPacket *pkt,
-                             uint32_t *timestamp,
-                             const uint8_t *buf,
-                             int len, int flags)
+static int vp8_handle_packet(AVFormatContext *ctx, PayloadContext *vp8,
+                             AVStream *st, AVPacket *pkt, uint32_t *timestamp,
+                             const uint8_t *buf, int len, uint16_t seq,
+                             int flags)
 {
     int start_partition, end_packet;
     int extended_bits, part_id;
diff --git a/libavformat/rtpdec_xiph.c b/libavformat/rtpdec_xiph.c
index 40415d8f2f17a5962da74f86e1b220012cb8803f..db39462f4a38c90116c0f9fbed1aeba0f7995a04 100644
--- a/libavformat/rtpdec_xiph.c
+++ b/libavformat/rtpdec_xiph.c
@@ -70,12 +70,10 @@ static void xiph_free_context(PayloadContext * data)
     av_free(data);
 }
 
-static int xiph_handle_packet(AVFormatContext * ctx,
-                              PayloadContext * data,
-                              AVStream * st,
-                              AVPacket * pkt,
-                              uint32_t * timestamp,
-                              const uint8_t * buf, int len, int flags)
+static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
+                              AVStream *st, AVPacket *pkt, uint32_t *timestamp,
+                              const uint8_t *buf, int len, uint16_t seq,
+                              int flags)
 {
 
     int ident, fragmented, tdt, num_pkts, pkt_len;