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