FFmpeg
rtpdec.c
Go to the documentation of this file.
1 /*
2  * RTP input format
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/mathematics.h"
23 #include "libavutil/avstring.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/time.h"
26 
27 #include "libavcodec/bytestream.h"
28 
29 #include "avformat.h"
30 #include "network.h"
31 #include "srtp.h"
32 #include "url.h"
33 #include "rtpdec.h"
34 #include "rtpdec_formats.h"
35 #include "internal.h"
36 
37 #define MIN_FEEDBACK_INTERVAL 200000 /* 200 ms in us */
38 
40  .enc_name = "L24",
41  .codec_type = AVMEDIA_TYPE_AUDIO,
42  .codec_id = AV_CODEC_ID_PCM_S24BE,
43 };
44 
46  .enc_name = "GSM",
47  .codec_type = AVMEDIA_TYPE_AUDIO,
48  .codec_id = AV_CODEC_ID_GSM,
49 };
50 
52  .enc_name = "X-MP3-draft-00",
53  .codec_type = AVMEDIA_TYPE_AUDIO,
54  .codec_id = AV_CODEC_ID_MP3ADU,
55 };
56 
58  .enc_name = "speex",
59  .codec_type = AVMEDIA_TYPE_AUDIO,
60  .codec_id = AV_CODEC_ID_SPEEX,
61 };
62 
64  .enc_name = "opus",
65  .codec_type = AVMEDIA_TYPE_AUDIO,
66  .codec_id = AV_CODEC_ID_OPUS,
67 };
68 
69 static const RTPDynamicProtocolHandler t140_dynamic_handler = { /* RFC 4103 */
70  .enc_name = "t140",
71  .codec_type = AVMEDIA_TYPE_SUBTITLE,
72  .codec_id = AV_CODEC_ID_TEXT,
73 };
74 
79 
81  /* rtp */
130  /* rdt */
135  NULL,
136 };
137 
139 {
140  uintptr_t i = (uintptr_t)*opaque;
141  const RTPDynamicProtocolHandler *r = rtp_dynamic_protocol_handler_list[i];
142 
143  if (r)
144  *opaque = (void*)(i + 1);
145 
146  return r;
147 }
148 
150  enum AVMediaType codec_type)
151 {
152  void *i = 0;
154  while (handler = ff_rtp_handler_iterate(&i)) {
155  if (handler->enc_name &&
156  !av_strcasecmp(name, handler->enc_name) &&
157  codec_type == handler->codec_type)
158  return handler;
159  }
160  return NULL;
161 }
162 
164  enum AVMediaType codec_type)
165 {
166  void *i = 0;
168  while (handler = ff_rtp_handler_iterate(&i)) {
169  if (handler->static_payload_id && handler->static_payload_id == id &&
170  codec_type == handler->codec_type)
171  return handler;
172  }
173  return NULL;
174 }
175 
176 static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf,
177  int len)
178 {
179  int payload_len;
180  while (len >= 4) {
181  payload_len = FFMIN(len, (AV_RB16(buf + 2) + 1) * 4);
182 
183  switch (buf[1]) {
184  case RTCP_SR:
185  if (payload_len < 20) {
186  av_log(s->ic, AV_LOG_ERROR, "Invalid RTCP SR packet length\n");
187  return AVERROR_INVALIDDATA;
188  }
189 
191  s->last_rtcp_ntp_time = AV_RB64(buf + 8);
192  s->last_rtcp_timestamp = AV_RB32(buf + 16);
195  if (!s->base_timestamp)
198  }
199 
200  break;
201  case RTCP_BYE:
202  return -RTCP_BYE;
203  }
204 
205  buf += payload_len;
206  len -= payload_len;
207  }
208  return -1;
209 }
210 
211 #define RTP_SEQ_MOD (1 << 16)
212 
213 static void rtp_init_statistics(RTPStatistics *s, uint16_t base_sequence)
214 {
215  memset(s, 0, sizeof(RTPStatistics));
216  s->max_seq = base_sequence;
217  s->probation = 1;
218 }
219 
220 /*
221  * Called whenever there is a large jump in sequence numbers,
222  * or when they get out of probation...
223  */
224 static void rtp_init_sequence(RTPStatistics *s, uint16_t seq)
225 {
226  s->max_seq = seq;
227  s->cycles = 0;
228  s->base_seq = seq - 1;
229  s->bad_seq = RTP_SEQ_MOD + 1;
230  s->received = 0;
231  s->expected_prior = 0;
232  s->received_prior = 0;
233  s->jitter = 0;
234  s->transit = 0;
235 }
236 
237 /* Returns 1 if we should handle this packet. */
238 static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq)
239 {
240  uint16_t udelta = seq - s->max_seq;
241  const int MAX_DROPOUT = 3000;
242  const int MAX_MISORDER = 100;
243  const int MIN_SEQUENTIAL = 2;
244 
245  /* source not valid until MIN_SEQUENTIAL packets with sequence
246  * seq. numbers have been received */
247  if (s->probation) {
248  if (seq == s->max_seq + 1) {
249  s->probation--;
250  s->max_seq = seq;
251  if (s->probation == 0) {
252  rtp_init_sequence(s, seq);
253  s->received++;
254  return 1;
255  }
256  } else {
257  s->probation = MIN_SEQUENTIAL - 1;
258  s->max_seq = seq;
259  }
260  } else if (udelta < MAX_DROPOUT) {
261  // in order, with permissible gap
262  if (seq < s->max_seq) {
263  // sequence number wrapped; count another 64k cycles
264  s->cycles += RTP_SEQ_MOD;
265  }
266  s->max_seq = seq;
267  } else if (udelta <= RTP_SEQ_MOD - MAX_MISORDER) {
268  // sequence made a large jump...
269  if (seq == s->bad_seq) {
270  /* two sequential packets -- assume that the other side
271  * restarted without telling us; just resync. */
272  rtp_init_sequence(s, seq);
273  } else {
274  s->bad_seq = (seq + 1) & (RTP_SEQ_MOD - 1);
275  return 0;
276  }
277  } else {
278  // duplicate or reordered packet...
279  }
280  s->received++;
281  return 1;
282 }
283 
284 static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp,
285  uint32_t arrival_timestamp)
286 {
287  // Most of this is pretty straight from RFC 3550 appendix A.8
288  uint32_t transit = arrival_timestamp - sent_timestamp;
289  uint32_t prev_transit = s->transit;
290  int32_t d = transit - prev_transit;
291  // Doing the FFABS() call directly on the "transit - prev_transit"
292  // expression doesn't work, since it's an unsigned expression. Doing the
293  // transit calculation in unsigned is desired though, since it most
294  // probably will need to wrap around.
295  d = FFABS(d);
296  s->transit = transit;
297  if (!prev_transit)
298  return;
299  s->jitter += d - (int32_t) ((s->jitter + 8) >> 4);
300 }
301 
303  AVIOContext *avio, int count)
304 {
305  AVIOContext *pb;
306  uint8_t *buf;
307  int len;
308  int rtcp_bytes;
310  uint32_t lost;
311  uint32_t extended_max;
312  uint32_t expected_interval;
313  uint32_t received_interval;
314  int32_t lost_interval;
315  uint32_t expected;
316  uint32_t fraction;
317 
318  if ((!fd && !avio) || (count < 1))
319  return -1;
320 
321  /* TODO: I think this is way too often; RFC 1889 has algorithm for this */
322  /* XXX: MPEG pts hardcoded. RTCP send every 0.5 seconds */
323  s->octet_count += count;
324  rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
326  rtcp_bytes /= 50; // mmu_man: that's enough for me... VLC sends much less btw !?
327  if (rtcp_bytes < 28)
328  return -1;
330 
331  if (!fd)
332  pb = avio;
333  else if (avio_open_dyn_buf(&pb) < 0)
334  return -1;
335 
336  // Receiver Report
337  avio_w8(pb, (RTP_VERSION << 6) + 1); /* 1 report block */
338  avio_w8(pb, RTCP_RR);
339  avio_wb16(pb, 7); /* length in words - 1 */
340  // our own SSRC: we use the server's SSRC + 1 to avoid conflicts
341  avio_wb32(pb, s->ssrc + 1);
342  avio_wb32(pb, s->ssrc); // server SSRC
343  // some placeholders we should really fill...
344  // RFC 1889/p64
345  extended_max = stats->cycles + stats->max_seq;
346  expected = extended_max - stats->base_seq;
347  lost = expected - stats->received;
348  lost = FFMIN(lost, 0xffffff); // clamp it since it's only 24 bits...
349  expected_interval = expected - stats->expected_prior;
350  stats->expected_prior = expected;
351  received_interval = stats->received - stats->received_prior;
352  stats->received_prior = stats->received;
353  lost_interval = expected_interval - received_interval;
354  if (expected_interval == 0 || lost_interval <= 0)
355  fraction = 0;
356  else
357  fraction = (lost_interval << 8) / expected_interval;
358 
359  fraction = (fraction << 24) | lost;
360 
361  avio_wb32(pb, fraction); /* 8 bits of fraction, 24 bits of total packets lost */
362  avio_wb32(pb, extended_max); /* max sequence received */
363  avio_wb32(pb, stats->jitter >> 4); /* jitter */
364 
366  avio_wb32(pb, 0); /* last SR timestamp */
367  avio_wb32(pb, 0); /* delay since last SR */
368  } else {
369  uint32_t middle_32_bits = s->last_rtcp_ntp_time >> 16; // this is valid, right? do we need to handle 64 bit values special?
370  uint32_t delay_since_last = av_rescale(av_gettime_relative() - s->last_rtcp_reception_time,
371  65536, AV_TIME_BASE);
372 
373  avio_wb32(pb, middle_32_bits); /* last SR timestamp */
374  avio_wb32(pb, delay_since_last); /* delay since last SR */
375  }
376 
377  // CNAME
378  avio_w8(pb, (RTP_VERSION << 6) + 1); /* 1 report block */
379  avio_w8(pb, RTCP_SDES);
380  len = strlen(s->hostname);
381  avio_wb16(pb, (7 + len + 3) / 4); /* length in words - 1 */
382  avio_wb32(pb, s->ssrc + 1);
383  avio_w8(pb, 0x01);
384  avio_w8(pb, len);
385  avio_write(pb, s->hostname, len);
386  avio_w8(pb, 0); /* END */
387  // padding
388  for (len = (7 + len) % 4; len % 4; len++)
389  avio_w8(pb, 0);
390 
391  avio_flush(pb);
392  if (!fd)
393  return 0;
394  len = avio_close_dyn_buf(pb, &buf);
395  if ((len > 0) && buf) {
396  int av_unused result;
397  av_log(s->ic, AV_LOG_TRACE, "sending %d bytes of RR\n", len);
398  result = ffurl_write(fd, buf, len);
399  av_log(s->ic, AV_LOG_TRACE, "result from ffurl_write: %d\n", result);
400  av_free(buf);
401  }
402  return 0;
403 }
404 
406 {
407  uint8_t buf[RTP_MIN_PACKET_LENGTH], *ptr = buf;
408 
409  /* Send a small RTP packet */
410 
411  bytestream_put_byte(&ptr, (RTP_VERSION << 6));
412  bytestream_put_byte(&ptr, 0); /* Payload type */
413  bytestream_put_be16(&ptr, 0); /* Seq */
414  bytestream_put_be32(&ptr, 0); /* Timestamp */
415  bytestream_put_be32(&ptr, 0); /* SSRC */
416 
417  ffurl_write(rtp_handle, buf, ptr - buf);
418 
419  /* Send a minimal RTCP RR */
420  ptr = buf;
421  bytestream_put_byte(&ptr, (RTP_VERSION << 6));
422  bytestream_put_byte(&ptr, RTCP_RR); /* receiver report */
423  bytestream_put_be16(&ptr, 1); /* length in words - 1 */
424  bytestream_put_be32(&ptr, 0); /* our own SSRC */
425 
426  ffurl_write(rtp_handle, buf, ptr - buf);
427 }
428 
429 static int find_missing_packets(RTPDemuxContext *s, uint16_t *first_missing,
430  uint16_t *missing_mask)
431 {
432  int i;
433  uint16_t next_seq = s->seq + 1;
434  RTPPacket *pkt = s->queue;
435 
436  if (!pkt || pkt->seq == next_seq)
437  return 0;
438 
439  *missing_mask = 0;
440  for (i = 1; i <= 16; i++) {
441  uint16_t missing_seq = next_seq + i;
442  while (pkt) {
443  int16_t diff = pkt->seq - missing_seq;
444  if (diff >= 0)
445  break;
446  pkt = pkt->next;
447  }
448  if (!pkt)
449  break;
450  if (pkt->seq == missing_seq)
451  continue;
452  *missing_mask |= 1 << (i - 1);
453  }
454 
455  *first_missing = next_seq;
456  return 1;
457 }
458 
460  AVIOContext *avio)
461 {
462  int len, need_keyframe, missing_packets;
463  AVIOContext *pb;
464  uint8_t *buf;
465  int64_t now;
466  uint16_t first_missing = 0, missing_mask = 0;
467 
468  if (!fd && !avio)
469  return -1;
470 
471  need_keyframe = s->handler && s->handler->need_keyframe &&
473  missing_packets = find_missing_packets(s, &first_missing, &missing_mask);
474 
475  if (!need_keyframe && !missing_packets)
476  return 0;
477 
478  /* Send new feedback if enough time has elapsed since the last
479  * feedback packet. */
480 
481  now = av_gettime_relative();
482  if (s->last_feedback_time &&
484  return 0;
485  s->last_feedback_time = now;
486 
487  if (!fd)
488  pb = avio;
489  else if (avio_open_dyn_buf(&pb) < 0)
490  return -1;
491 
492  if (need_keyframe) {
493  avio_w8(pb, (RTP_VERSION << 6) | 1); /* PLI */
494  avio_w8(pb, RTCP_PSFB);
495  avio_wb16(pb, 2); /* length in words - 1 */
496  // our own SSRC: we use the server's SSRC + 1 to avoid conflicts
497  avio_wb32(pb, s->ssrc + 1);
498  avio_wb32(pb, s->ssrc); // server SSRC
499  }
500 
501  if (missing_packets) {
502  avio_w8(pb, (RTP_VERSION << 6) | 1); /* NACK */
503  avio_w8(pb, RTCP_RTPFB);
504  avio_wb16(pb, 3); /* length in words - 1 */
505  avio_wb32(pb, s->ssrc + 1);
506  avio_wb32(pb, s->ssrc); // server SSRC
507 
508  avio_wb16(pb, first_missing);
509  avio_wb16(pb, missing_mask);
510  }
511 
512  avio_flush(pb);
513  if (!fd)
514  return 0;
515  len = avio_close_dyn_buf(pb, &buf);
516  if (len > 0 && buf) {
517  ffurl_write(fd, buf, len);
518  av_free(buf);
519  }
520  return 0;
521 }
522 
524 {
525  uint8_t *bs;
526  int ret;
527 
528  /* This function writes an extradata with a channel mapping family of 0.
529  * This mapping family only supports mono and stereo layouts. And RFC7587
530  * specifies that the number of channels in the SDP must be 2.
531  */
532  if (codecpar->channels > 2) {
533  return AVERROR_INVALIDDATA;
534  }
535 
536  ret = ff_alloc_extradata(codecpar, 19);
537  if (ret < 0)
538  return ret;
539 
540  bs = (uint8_t *)codecpar->extradata;
541 
542  /* Opus magic */
543  bytestream_put_buffer(&bs, "OpusHead", 8);
544  /* Version */
545  bytestream_put_byte (&bs, 0x1);
546  /* Channel count */
547  bytestream_put_byte (&bs, codecpar->channels);
548  /* Pre skip */
549  bytestream_put_le16 (&bs, 0);
550  /* Input sample rate */
551  bytestream_put_le32 (&bs, 48000);
552  /* Output gain */
553  bytestream_put_le16 (&bs, 0x0);
554  /* Mapping family */
555  bytestream_put_byte (&bs, 0x0);
556 
557  return 0;
558 }
559 
560 /**
561  * open a new RTP parse context for stream 'st'. 'st' can be NULL for
562  * MPEG-2 TS streams.
563  */
565  int payload_type, int queue_size)
566 {
568  int ret;
569 
570  s = av_mallocz(sizeof(RTPDemuxContext));
571  if (!s)
572  return NULL;
573  s->payload_type = payload_type;
576  s->ic = s1;
577  s->st = st;
578  s->queue_size = queue_size;
579 
580  av_log(s->ic, AV_LOG_VERBOSE, "setting jitter buffer size to %d\n",
581  s->queue_size);
582 
584  if (st) {
585  switch (st->codecpar->codec_id) {
587  /* According to RFC 3551, the stream clock rate is 8000
588  * even if the sample rate is 16000. */
589  if (st->codecpar->sample_rate == 8000)
590  st->codecpar->sample_rate = 16000;
591  break;
592  case AV_CODEC_ID_OPUS:
593  ret = opus_write_extradata(st->codecpar);
594  if (ret < 0) {
595  av_log(s1, AV_LOG_ERROR,
596  "Error creating opus extradata: %s\n",
597  av_err2str(ret));
598  av_free(s);
599  return NULL;
600  }
601  break;
602  default:
603  break;
604  }
605  }
606  // needed to send back RTCP RR in RTSP sessions
607  gethostname(s->hostname, sizeof(s->hostname));
608  return s;
609 }
610 
613 {
615  s->handler = handler;
616 }
617 
619  const char *params)
620 {
621  if (!ff_srtp_set_crypto(&s->srtp, suite, params))
622  s->srtp_enabled = 1;
623 }
624 
625 static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) {
626  int64_t rtcp_time, delta_timestamp, delta_time;
627 
631  if (!prft)
632  return AVERROR(ENOMEM);
633 
635  delta_timestamp = (int64_t)timestamp - (int64_t)s->last_rtcp_timestamp;
636  delta_time = av_rescale_q(delta_timestamp, s->st->time_base, AV_TIME_BASE_Q);
637 
638  prft->wallclock = rtcp_time + delta_time;
639  prft->flags = 24;
640  return 0;
641 }
642 
643 /**
644  * This was the second switch in rtp_parse packet.
645  * Normalizes time, if required, sets stream_index, etc.
646  */
647 static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
648 {
649  if (pkt->pts != AV_NOPTS_VALUE || pkt->dts != AV_NOPTS_VALUE)
650  return; /* Timestamp already set by depacketizer */
651  if (timestamp == RTP_NOTS_VALUE)
652  return;
653 
655  if (rtp_set_prft(s, pkt, timestamp) < 0) {
656  av_log(s->ic, AV_LOG_WARNING, "rtpdec: failed to set prft");
657  }
658  }
659 
660  if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && s->ic->nb_streams > 1) {
661  int64_t addend;
662  int delta_timestamp;
663 
664  /* compute pts from timestamp with received ntp_time */
665  delta_timestamp = timestamp - s->last_rtcp_timestamp;
666  /* convert to the PTS timebase */
668  s->st->time_base.den,
669  (uint64_t) s->st->time_base.num << 32);
670  pkt->pts = s->range_start_offset + s->rtcp_ts_offset + addend +
671  delta_timestamp;
672  return;
673  }
674 
675  if (!s->base_timestamp)
676  s->base_timestamp = timestamp;
677  /* assume that the difference is INT32_MIN < x < INT32_MAX,
678  * but allow the first timestamp to exceed INT32_MAX */
679  if (!s->timestamp)
680  s->unwrapped_timestamp += timestamp;
681  else
682  s->unwrapped_timestamp += (int32_t)(timestamp - s->timestamp);
683  s->timestamp = timestamp;
685  s->base_timestamp;
686 }
687 
689  const uint8_t *buf, int len)
690 {
691  unsigned int ssrc;
692  int payload_type, seq, flags = 0;
693  int ext, csrc;
694  AVStream *st;
695  uint32_t timestamp;
696  int rv = 0;
697 
698  csrc = buf[0] & 0x0f;
699  ext = buf[0] & 0x10;
700  payload_type = buf[1] & 0x7f;
701  if (buf[1] & 0x80)
702  flags |= RTP_FLAG_MARKER;
703  seq = AV_RB16(buf + 2);
704  timestamp = AV_RB32(buf + 4);
705  ssrc = AV_RB32(buf + 8);
706  /* store the ssrc in the RTPDemuxContext */
707  s->ssrc = ssrc;
708 
709  /* NOTE: we can handle only one payload type */
710  if (s->payload_type != payload_type)
711  return -1;
712 
713  st = s->st;
714  // only do something with this if all the rtp checks pass...
715  if (!rtp_valid_packet_in_sequence(&s->statistics, seq)) {
716  av_log(s->ic, AV_LOG_ERROR,
717  "RTP: PT=%02x: bad cseq %04x expected=%04x\n",
718  payload_type, seq, ((s->seq + 1) & 0xffff));
719  return -1;
720  }
721 
722  if (buf[0] & 0x20) {
723  int padding = buf[len - 1];
724  if (len >= 12 + padding)
725  len -= padding;
726  }
727 
728  s->seq = seq;
729  len -= 12;
730  buf += 12;
731 
732  len -= 4 * csrc;
733  buf += 4 * csrc;
734  if (len < 0)
735  return AVERROR_INVALIDDATA;
736 
737  /* RFC 3550 Section 5.3.1 RTP Header Extension handling */
738  if (ext) {
739  if (len < 4)
740  return -1;
741  /* calculate the header extension length (stored as number
742  * of 32-bit words) */
743  ext = (AV_RB16(buf + 2) + 1) << 2;
744 
745  if (len < ext)
746  return -1;
747  // skip past RTP header extension
748  len -= ext;
749  buf += ext;
750  }
751 
752  if (s->handler && s->handler->parse_packet) {
754  s->st, pkt, &timestamp, buf, len, seq,
755  flags);
756  } else if (st) {
757  if ((rv = av_new_packet(pkt, len)) < 0)
758  return rv;
759  memcpy(pkt->data, buf, len);
760  pkt->stream_index = st->index;
761  } else {
762  return AVERROR(EINVAL);
763  }
764 
765  // now perform timestamp things....
766  finalize_packet(s, pkt, timestamp);
767 
768  return rv;
769 }
770 
772 {
773  while (s->queue) {
774  RTPPacket *next = s->queue->next;
775  av_freep(&s->queue->buf);
776  av_freep(&s->queue);
777  s->queue = next;
778  }
779  s->seq = 0;
780  s->queue_len = 0;
781  s->prev_ret = 0;
782 }
783 
784 static int enqueue_packet(RTPDemuxContext *s, uint8_t *buf, int len)
785 {
786  uint16_t seq = AV_RB16(buf + 2);
787  RTPPacket **cur = &s->queue, *packet;
788 
789  /* Find the correct place in the queue to insert the packet */
790  while (*cur) {
791  int16_t diff = seq - (*cur)->seq;
792  if (diff < 0)
793  break;
794  cur = &(*cur)->next;
795  }
796 
797  packet = av_mallocz(sizeof(*packet));
798  if (!packet)
799  return AVERROR(ENOMEM);
800  packet->recvtime = av_gettime_relative();
801  packet->seq = seq;
802  packet->len = len;
803  packet->buf = buf;
804  packet->next = *cur;
805  *cur = packet;
806  s->queue_len++;
807 
808  return 0;
809 }
810 
812 {
813  return s->queue && s->queue->seq == (uint16_t) (s->seq + 1);
814 }
815 
817 {
818  return s->queue ? s->queue->recvtime : 0;
819 }
820 
822 {
823  int rv;
824  RTPPacket *next;
825 
826  if (s->queue_len <= 0)
827  return -1;
828 
829  if (!has_next_packet(s))
831  "RTP: missed %d packets\n", s->queue->seq - s->seq - 1);
832 
833  /* Parse the first packet in the queue, and dequeue it */
834  rv = rtp_parse_packet_internal(s, pkt, s->queue->buf, s->queue->len);
835  next = s->queue->next;
836  av_freep(&s->queue->buf);
837  av_freep(&s->queue);
838  s->queue = next;
839  s->queue_len--;
840  return rv;
841 }
842 
844  uint8_t **bufptr, int len)
845 {
846  uint8_t *buf = bufptr ? *bufptr : NULL;
847  int flags = 0;
848  uint32_t timestamp;
849  int rv = 0;
850 
851  if (!buf) {
852  /* If parsing of the previous packet actually returned 0 or an error,
853  * there's nothing more to be parsed from that packet, but we may have
854  * indicated that we can return the next enqueued packet. */
855  if (s->prev_ret <= 0)
856  return rtp_parse_queued_packet(s, pkt);
857  /* return the next packets, if any */
858  if (s->handler && s->handler->parse_packet) {
859  /* timestamp should be overwritten by parse_packet, if not,
860  * the packet is left with pts == AV_NOPTS_VALUE */
861  timestamp = RTP_NOTS_VALUE;
863  s->st, pkt, &timestamp, NULL, 0, 0,
864  flags);
865  finalize_packet(s, pkt, timestamp);
866  return rv;
867  }
868  }
869 
870  if (len < 12)
871  return -1;
872 
873  if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
874  return -1;
875  if (RTP_PT_IS_RTCP(buf[1])) {
876  return rtcp_parse_packet(s, buf, len);
877  }
878 
879  if (s->st) {
880  int64_t received = av_gettime_relative();
881  uint32_t arrival_ts = av_rescale_q(received, AV_TIME_BASE_Q,
882  s->st->time_base);
883  timestamp = AV_RB32(buf + 4);
884  // Calculate the jitter immediately, before queueing the packet
885  // into the reordering queue.
886  rtcp_update_jitter(&s->statistics, timestamp, arrival_ts);
887  }
888 
889  if ((s->seq == 0 && !s->queue) || s->queue_size <= 1) {
890  /* First packet, or no reordering */
891  return rtp_parse_packet_internal(s, pkt, buf, len);
892  } else {
893  uint16_t seq = AV_RB16(buf + 2);
894  int16_t diff = seq - s->seq;
895  if (diff < 0) {
896  /* Packet older than the previously emitted one, drop */
898  "RTP: dropping old packet received too late\n");
899  return -1;
900  } else if (diff <= 1) {
901  /* Correct packet */
902  rv = rtp_parse_packet_internal(s, pkt, buf, len);
903  return rv;
904  } else {
905  /* Still missing some packet, enqueue this one. */
906  rv = enqueue_packet(s, buf, len);
907  if (rv < 0)
908  return rv;
909  *bufptr = NULL;
910  /* Return the first enqueued packet if the queue is full,
911  * even if we're missing something */
912  if (s->queue_len >= s->queue_size) {
913  av_log(s->ic, AV_LOG_WARNING, "jitter buffer full\n");
914  return rtp_parse_queued_packet(s, pkt);
915  }
916  return -1;
917  }
918  }
919 }
920 
921 /**
922  * Parse an RTP or RTCP packet directly sent as a buffer.
923  * @param s RTP parse context.
924  * @param pkt returned packet
925  * @param bufptr pointer to the input buffer or NULL to read the next packets
926  * @param len buffer len
927  * @return 0 if a packet is returned, 1 if a packet is returned and more can follow
928  * (use buf as NULL to read the next). -1 if no packet (error or no more packet).
929  */
931  uint8_t **bufptr, int len)
932 {
933  int rv;
934  if (s->srtp_enabled && bufptr && ff_srtp_decrypt(&s->srtp, *bufptr, &len) < 0)
935  return -1;
936  rv = rtp_parse_one_packet(s, pkt, bufptr, len);
937  s->prev_ret = rv;
938  while (rv < 0 && has_next_packet(s))
939  rv = rtp_parse_queued_packet(s, pkt);
940  return rv ? rv : has_next_packet(s);
941 }
942 
944 {
946  ff_srtp_free(&s->srtp);
947  av_free(s);
948 }
949 
951  AVStream *stream, PayloadContext *data, const char *p,
952  int (*parse_fmtp)(AVFormatContext *s,
953  AVStream *stream,
954  PayloadContext *data,
955  const char *attr, const char *value))
956 {
957  char attr[256];
958  char *value;
959  int res;
960  int value_size = strlen(p) + 1;
961 
962  if (!(value = av_malloc(value_size))) {
963  av_log(s, AV_LOG_ERROR, "Failed to allocate data for FMTP.\n");
964  return AVERROR(ENOMEM);
965  }
966 
967  // remove protocol identifier
968  while (*p && *p == ' ')
969  p++; // strip spaces
970  while (*p && *p != ' ')
971  p++; // eat protocol identifier
972  while (*p && *p == ' ')
973  p++; // strip trailing spaces
974 
975  while (ff_rtsp_next_attr_and_value(&p,
976  attr, sizeof(attr),
977  value, value_size)) {
978  res = parse_fmtp(s, stream, data, attr, value);
979  if (res < 0 && res != AVERROR_PATCHWELCOME) {
980  av_free(value);
981  return res;
982  }
983  }
984  av_free(value);
985  return 0;
986 }
987 
988 int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx)
989 {
990  int ret;
991  av_packet_unref(pkt);
992 
993  pkt->size = avio_close_dyn_buf(*dyn_buf, &pkt->data);
994  pkt->stream_index = stream_idx;
995  *dyn_buf = NULL;
996  if ((ret = av_packet_from_data(pkt, pkt->data, pkt->size)) < 0) {
997  av_freep(&pkt->data);
998  return ret;
999  }
1000  return pkt->size;
1001 }
int queue_size
The size of queue, or 0 if reordering is disabled.
Definition: rtpdec.h:171
const RTPDynamicProtocolHandler ff_rdt_live_audio_handler
#define NULL
Definition: coverity.c:32
void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite, const char *params)
Definition: rtpdec.c:618
Bytestream IO Context.
Definition: avio.h:161
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
Definition: packet.h:268
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AVFormatContext * ic
Definition: rtpdec.h:148
uint16_t seq
Definition: rtpdec.h:152
const RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler
Definition: rtpdec_amr.c:185
void ff_rtp_send_punch_packets(URLContext *rtp_handle)
Send a dummy packet on both port pairs to set up the connection state in potential NAT routers...
Definition: rtpdec.c:405
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1424
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
const RTPDynamicProtocolHandler ff_qt_rtp_aud_handler
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp, uint32_t arrival_timestamp)
Definition: rtpdec.c:284
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: avio.c:415
int payload_type
Definition: rtpdec.h:150
int64_t range_start_offset
Definition: rtpdec.h:156
const RTPDynamicProtocolHandler ff_ms_rtp_asf_pfv_handler
#define NTP_OFFSET_US
Definition: internal.h:416
int prev_ret
Fields for packet reordering.
Definition: rtpdec.h:168
RTP/JPEG specific private data.
Definition: rdt.c:83
int64_t last_feedback_time
Definition: rtpdec.h:185
unsigned int last_octet_count
Definition: rtpdec.h:184
static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt, const uint8_t *buf, int len)
Definition: rtpdec.c:688
const RTPDynamicProtocolHandler ff_g726le_32_dynamic_handler
RTPPacket * queue
A sorted queue of buffered packets not yet returned.
Definition: rtpdec.h:169
#define RTP_VERSION
Definition: rtp.h:78
static int parse_fmtp(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *attr, const char *value)
Definition: rtpdec_latm.c:130
static int opus_write_extradata(AVCodecParameters *codecpar)
Definition: rtpdec.c:523
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
int num
Numerator.
Definition: rational.h:59
int index
stream index in AVFormatContext
Definition: avformat.h:885
int size
Definition: packet.h:370
#define RTCP_TX_RATIO_NUM
Definition: rtp.h:82
const RTPDynamicProtocolHandler * handler
Definition: rtpdec.h:188
enum AVMediaType codec_type
Definition: rtp.c:37
static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len)
Definition: rtpdec.c:176
const RTPDynamicProtocolHandler ff_rfc4175_rtp_handler
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
uint64_t last_rtcp_ntp_time
Definition: rtpdec.h:175
uint32_t cycles
shifted count of sequence number cycles
Definition: rtpdec.h:81
AVPacket * pkt
Definition: movenc.c:59
#define RTCP_TX_RATIO_DEN
Definition: rtp.h:83
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:91
const RTPDynamicProtocolHandler ff_rdt_video_handler
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1379
static int find_missing_packets(RTPDemuxContext *s, uint16_t *first_missing, uint16_t *missing_mask)
Definition: rtpdec.c:429
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
enum AVMediaType codec_type
Definition: rtpdec.h:117
RTPDemuxContext * ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, int payload_type, int queue_size)
open a new RTP parse context for stream &#39;st&#39;.
Definition: rtpdec.c:564
static const RTPDynamicProtocolHandler *const rtp_dynamic_protocol_handler_list[]
Definition: rtpdec.c:80
PayloadContext * dynamic_protocol_context
Definition: rtpdec.h:189
Format I/O context.
Definition: avformat.h:1247
uint64_t first_rtcp_ntp_time
Definition: rtpdec.h:177
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, buffer_size_t size)
Definition: avpacket.c:343
uint32_t base_seq
base sequence number
Definition: rtpdec.h:82
void ff_srtp_free(struct SRTPContext *s)
Definition: srtp.c:31
uint8_t
#define av_malloc(s)
int(* need_keyframe)(PayloadContext *context)
Definition: rtpdec.h:136
const RTPDynamicProtocolHandler ff_g726le_40_dynamic_handler
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:220
#define RTP_MIN_PACKET_LENGTH
Definition: rtpdec.h:35
void ff_rtp_reset_packet_queue(RTPDemuxContext *s)
Definition: rtpdec.c:771
const RTPDynamicProtocolHandler ff_vp9_dynamic_handler
Definition: rtpdec_vp9.c:333
const RTPDynamicProtocolHandler ff_quicktime_rtp_aud_handler
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:108
int len
Definition: rtpdec.h:142
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
Initialize a reference-counted packet from av_malloc()ed data.
Definition: avpacket.c:166
static void handler(vbi_event *ev, void *user_data)
int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:91
int64_t wallclock
A UTC timestamp, in microseconds, since Unix epoch (e.g, av_gettime()).
Definition: avcodec.h:507
uint8_t * data
Definition: packet.h:369
const RTPDynamicProtocolHandler ff_mp4a_latm_dynamic_handler
Definition: rtpdec_latm.c:164
Definition: rtp.h:99
static int rtp_parse_queued_packet(RTPDemuxContext *s, AVPacket *pkt)
Definition: rtpdec.c:821
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
const RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler
Definition: rtpdec_h263.c:100
const RTPDynamicProtocolHandler ff_jpeg_dynamic_handler
Definition: rtpdec_jpeg.c:382
const RTPDynamicProtocolHandler ff_qdm2_dynamic_handler
Definition: rtpdec_qdm2.c:303
char hostname[256]
Definition: rtpdec.h:159
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:225
const RTPDynamicProtocolHandler ff_hevc_dynamic_handler
Definition: rtpdec_hevc.c:343
uint32_t expected_prior
packets expected in last interval
Definition: rtpdec.h:86
const RTPDynamicProtocolHandler ff_mp4v_es_dynamic_handler
Definition: rtpdec_mpeg4.c:349
#define av_log(a,...)
const RTPDynamicProtocolHandler ff_rdt_audio_handler
const RTPDynamicProtocolHandler * ff_rtp_handler_iterate(void **opaque)
Iterate over all registered rtp dynamic protocol handlers.
Definition: rtpdec.c:138
static const RTPDynamicProtocolHandler l24_dynamic_handler
Definition: rtpdec.c:39
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
int srtp_enabled
Definition: rtpdec.h:161
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:99
const RTPDynamicProtocolHandler ff_vorbis_dynamic_handler
Definition: rtpdec_xiph.c:379
const RTPDynamicProtocolHandler ff_ms_rtp_asf_pfa_handler
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
Parse the NTP time in micro seconds (since NTP epoch).
Definition: utils.c:4781
uint16_t seq
Definition: rtpdec.h:140
#define RTP_FLAG_MARKER
RTP marker bit was set for this packet.
Definition: rtpdec.h:93
const RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler
Definition: rtpdec_amr.c:195
Definition: rtp.h:103
const RTPDynamicProtocolHandler ff_ilbc_dynamic_handler
Definition: rtpdec_ilbc.c:69
int probation
sequence packets till source is valid
Definition: rtpdec.h:84
const RTPDynamicProtocolHandler ff_mpeg_audio_dynamic_handler
Definition: rtpdec_mpeg12.c:52
static void rtp_init_sequence(RTPStatistics *s, uint16_t seq)
Definition: rtpdec.c:224
const char * r
Definition: vf_curves.c:116
static const RTPDynamicProtocolHandler opus_dynamic_handler
Definition: rtpdec.c:63
GLenum GLint * params
Definition: opengl_enc.c:113
#define RTP_SEQ_MOD
Definition: rtpdec.c:211
void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, const RTPDynamicProtocolHandler *handler)
Definition: rtpdec.c:611
GLsizei count
Definition: opengl_enc.c:108
DynamicPayloadPacketHandlerProc parse_packet
Parse handler for this dynamic packet.
Definition: rtpdec.h:135
int64_t rtcp_ts_offset
Definition: rtpdec.h:179
uint32_t timestamp
Definition: rtpdec.h:153
uint32_t transit
relative transit time for previous packet
Definition: rtpdec.h:88
uint32_t jitter
estimated jitter.
Definition: rtpdec.h:89
int queue_len
The number of packets in queue.
Definition: rtpdec.h:170
const RTPDynamicProtocolHandler ff_g726le_16_dynamic_handler
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1303
int ff_alloc_extradata(AVCodecParameters *par, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0...
Definition: utils.c:3368
int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr)
Definition: srtp.c:126
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:129
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
#define FFMIN(a, b)
Definition: common.h:105
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:215
Definition: rtp.h:98
const RTPDynamicProtocolHandler ff_qcelp_dynamic_handler
Definition: rtpdec_qcelp.c:212
const RTPDynamicProtocolHandler ff_g726_16_dynamic_handler
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
static void stats(AVPacket *const *in, int n_in, unsigned *_max, unsigned *_sum)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define s(width, name)
Definition: cbs_vp9.c:257
int ff_rtp_send_rtcp_feedback(RTPDemuxContext *s, URLContext *fd, AVIOContext *avio)
Definition: rtpdec.c:459
Stream structure.
Definition: avformat.h:884
uint32_t received
packets received
Definition: rtpdec.h:85
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
const RTPDynamicProtocolHandler ff_rdt_live_video_handler
int64_t last_rtcp_reception_time
Definition: rtpdec.h:176
const RTPDynamicProtocolHandler ff_mpegts_dynamic_handler
Definition: rtpdec_mpegts.c:92
const RTPDynamicProtocolHandler ff_g726le_24_dynamic_handler
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
Definition: rtp.h:100
static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt, uint8_t **bufptr, int len)
Definition: rtpdec.c:843
int64_t unwrapped_timestamp
Definition: rtpdec.h:155
uint32_t last_rtcp_timestamp
Definition: rtpdec.h:178
static int has_next_packet(RTPDemuxContext *s)
Definition: rtpdec.c:811
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:203
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:634
const RTPDynamicProtocolHandler ff_qt_rtp_vid_handler
const RTPDynamicProtocolHandler ff_mpeg_video_dynamic_handler
Definition: rtpdec_mpeg12.c:60
unsigned int octet_count
Definition: rtpdec.h:183
Definition: url.h:38
RTPStatistics statistics
Statistics for this stream (used by RTCP receiver reports)
Definition: rtpdec.h:165
uint32_t received_prior
packets received in last interval
Definition: rtpdec.h:87
const RTPDynamicProtocolHandler ff_g726_24_dynamic_handler
uint32_t bad_seq
last bad sequence number + 1
Definition: rtpdec.h:83
const RTPDynamicProtocolHandler ff_theora_dynamic_handler
Definition: rtpdec_xiph.c:369
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:245
AVMediaType
Definition: avutil.h:199
int64_t ff_rtp_queued_packet_time(RTPDemuxContext *s)
Definition: rtpdec.c:816
int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, AVIOContext *avio, int count)
some rtp servers assume client is dead if they don&#39;t hear from them...
Definition: rtpdec.c:302
#define s1
Definition: regdef.h:38
int ff_parse_fmtp(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *p, int(*parse_fmtp)(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *attr, const char *value))
Definition: rtpdec.c:950
static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
This was the second switch in rtp_parse packet.
Definition: rtpdec.c:647
uint16_t max_seq
highest sequence number seen
Definition: rtpdec.h:80
const char * enc_name
Definition: rtpdec.h:116
uint8_t * buf
Definition: rtpdec.h:141
#define RTP_PT_IS_RTCP(x)
Definition: rtp.h:110
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:461
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
#define flags(name, subs,...)
Definition: cbs_av1.c:561
static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
Definition: rtpdec.c:625
static const RTPDynamicProtocolHandler gsm_dynamic_handler
Definition: rtpdec.c:45
int sample_rate
Audio only.
Definition: codec_par.h:170
const RTPDynamicProtocolHandler ff_svq3_dynamic_handler
Definition: rtpdec_svq3.c:109
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
Definition: bytestream.h:91
Main libavformat public API header.
const RTPDynamicProtocolHandler ff_h263_rfc2190_dynamic_handler
struct RTPPacket * next
Definition: rtpdec.h:144
uint32_t ssrc
Definition: rtpdec.h:151
static const RTPDynamicProtocolHandler realmedia_mp3_dynamic_handler
Definition: rtpdec.c:51
const RTPDynamicProtocolHandler ff_vc2hq_dynamic_handler
Definition: rtpdec_vc2hq.c:219
int64_t recvtime
Definition: rtpdec.h:143
const RTPDynamicProtocolHandler ff_g726_32_dynamic_handler
raw UTF-8 text
Definition: codec_id.h:525
const RTPDynamicProtocolHandler ff_h261_dynamic_handler
Definition: rtpdec_h261.c:165
const RTPDynamicProtocolHandler ff_quicktime_rtp_vid_handler
const RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler
Definition: rtpdec_mpeg4.c:358
int den
Denominator.
Definition: rational.h:60
Definition: rtp.h:97
int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx)
Close the dynamic buffer and make a packet from it.
Definition: rtpdec.c:988
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:372
uint32_t base_timestamp
Definition: rtpdec.h:154
This structure supplies correlation between a packet timestamp and a wall clock production time...
Definition: avcodec.h:503
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define av_free(p)
as in Berlin toast format
Definition: codec_id.h:442
int len
const RTPDynamicProtocolHandler ff_h264_dynamic_handler
Definition: rtpdec_h264.c:411
const RTPDynamicProtocolHandler ff_g726_40_dynamic_handler
static const RTPDynamicProtocolHandler t140_dynamic_handler
Definition: rtpdec.c:69
int ff_srtp_set_crypto(struct SRTPContext *s, const char *suite, const char *params)
Definition: srtp.c:65
const RTPDynamicProtocolHandler ff_dv_dynamic_handler
Definition: rtpdec_dv.c:134
void ff_rtp_parse_close(RTPDemuxContext *s)
Definition: rtpdec.c:943
const RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler
Definition: rtpdec_h263.c:92
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
int channels
Audio only.
Definition: codec_par.h:166
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: packet.h:368
and forward the result(frame or status change) to the corresponding input.If nothing is possible
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:383
#define RTP_NOTS_VALUE
Definition: rtpdec.h:40
FFmpeg currently uses a custom build this text attempts to document some of its obscure features and options Makefile the full command issued by make and its output will be shown on the screen DBG Preprocess x86 external assembler files to a dbg asm file in the object which then gets compiled Helps in developing those assembler files DESTDIR Destination directory for the install useful to prepare packages or install FFmpeg in cross environments GEN Set to ‘1’ to generate the missing or mismatched references Makefile builds all the libraries and the executables fate Run the fate test suite
Definition: build_system.txt:1
static int enqueue_packet(RTPDemuxContext *s, uint8_t *buf, int len)
Definition: rtpdec.c:784
#define av_freep(p)
unbuffered private I/O API
static void rtp_init_statistics(RTPStatistics *s, uint16_t base_sequence)
Definition: rtpdec.c:213
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1049
int stream_index
Definition: packet.h:371
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:913
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int32_t rv
Definition: input.c:405
int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, uint8_t **bufptr, int len)
Parse an RTP or RTCP packet directly sent as a buffer.
Definition: rtpdec.c:930
AVStream * st
Definition: rtpdec.h:149
const RTPDynamicProtocolHandler * ff_rtp_handler_find_by_id(int id, enum AVMediaType codec_type)
Find a registered rtp dynamic protocol handler with a matching codec ID.
Definition: rtpdec.c:163
This structure stores compressed data.
Definition: packet.h:346
const RTPDynamicProtocolHandler ff_ac3_dynamic_handler
Definition: rtpdec_ac3.c:125
static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq)
Definition: rtpdec.c:238
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
int i
Definition: input.c:407
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
const RTPDynamicProtocolHandler ff_vp8_dynamic_handler
Definition: rtpdec_vp8.c:279
const RTPDynamicProtocolHandler * ff_rtp_handler_find_by_name(const char *name, enum AVMediaType codec_type)
Find a registered rtp dynamic protocol handler with the specified name.
Definition: rtpdec.c:149
#define MIN_FEEDBACK_INTERVAL
Definition: rtpdec.c:37
#define av_unused
Definition: attributes.h:131
static const RTPDynamicProtocolHandler speex_dynamic_handler
Definition: rtpdec.c:57
struct SRTPContext srtp
Definition: rtpdec.h:162
const char * name
Definition: opengl_enc.c:102
const RTPDynamicProtocolHandler ff_mpeg_audio_robust_dynamic_handler