+ if ((s->seq == 0 && !s->queue) || s->queue_size <= 1) {
+ /* First packet, or no reordering */
+ return rtp_parse_packet_internal(s, pkt, buf, len);
+ } else {
+ uint16_t seq = AV_RB16(buf + 2);
+ int16_t diff = seq - s->seq;
+ if (diff < 0) {
+ /* Packet older than the previously emitted one, drop */
+ av_log(s->st ? s->st->codec : NULL, AV_LOG_WARNING,
+ "RTP: dropping old packet received too late\n");
+ return -1;
+ } else if (diff <= 1) {
+ /* Correct packet */
+ rv = rtp_parse_packet_internal(s, pkt, buf, len);
+ return rv;
+ } else {
+ /* Still missing some packet, enqueue this one. */
+ enqueue_packet(s, buf, len);
+ *bufptr = NULL;
+ /* Return the first enqueued packet if the queue is full,
+ * even if we're missing something */
+ if (s->queue_len >= s->queue_size)
+ return rtp_parse_queued_packet(s, pkt);
+ return -1;
+ }
+ }
+}
+
+/**
+ * Parse an RTP or RTCP packet directly sent as a buffer.
+ * @param s RTP parse context.
+ * @param pkt returned packet
+ * @param bufptr pointer to the input buffer or NULL to read the next packets
+ * @param len buffer len
+ * @return 0 if a packet is returned, 1 if a packet is returned and more can follow
+ * (use buf as NULL to read the next). -1 if no packet (error or no more packet).
+ */
+int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
+ uint8_t **bufptr, int len)
+{
+ int rv = rtp_parse_one_packet(s, pkt, bufptr, len);
+ s->prev_ret = rv;
+ while (rv == AVERROR(EAGAIN) && has_next_packet(s))
+ rv = rtp_parse_queued_packet(s, pkt);
+ return rv ? rv : has_next_packet(s);