FFmpeg
rtpenc.c
Go to the documentation of this file.
1 /*
2  * RTP output 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 "avformat.h"
23 #include "mpegts.h"
24 #include "internal.h"
25 #include "libavutil/mathematics.h"
26 #include "libavutil/random_seed.h"
27 #include "libavutil/opt.h"
28 
29 #include "rtpenc.h"
30 
31 static const AVOption options[] = {
33  { "payload_type", "Specify RTP payload type", offsetof(RTPMuxContext, payload_type), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM },
34  { "ssrc", "Stream identifier", offsetof(RTPMuxContext, ssrc), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
35  { "cname", "CNAME to include in RTCP SR packets", offsetof(RTPMuxContext, cname), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
36  { "seq", "Starting sequence number", offsetof(RTPMuxContext, seq), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 65535, AV_OPT_FLAG_ENCODING_PARAM },
37  { NULL },
38 };
39 
40 static const AVClass rtp_muxer_class = {
41  .class_name = "RTP muxer",
42  .item_name = av_default_item_name,
43  .option = options,
44  .version = LIBAVUTIL_VERSION_INT,
45 };
46 
47 #define RTCP_SR_SIZE 28
48 
49 static int is_supported(enum AVCodecID id)
50 {
51  switch(id) {
52  case AV_CODEC_ID_DIRAC:
53  case AV_CODEC_ID_H261:
54  case AV_CODEC_ID_H263:
55  case AV_CODEC_ID_H263P:
56  case AV_CODEC_ID_H264:
57  case AV_CODEC_ID_HEVC:
60  case AV_CODEC_ID_MPEG4:
61  case AV_CODEC_ID_AAC:
62  case AV_CODEC_ID_MP2:
63  case AV_CODEC_ID_MP3:
66  case AV_CODEC_ID_PCM_S8:
72  case AV_CODEC_ID_PCM_U8:
74  case AV_CODEC_ID_AMR_NB:
75  case AV_CODEC_ID_AMR_WB:
76  case AV_CODEC_ID_VORBIS:
77  case AV_CODEC_ID_THEORA:
78  case AV_CODEC_ID_VP8:
79  case AV_CODEC_ID_VP9:
83  case AV_CODEC_ID_ILBC:
84  case AV_CODEC_ID_MJPEG:
85  case AV_CODEC_ID_SPEEX:
86  case AV_CODEC_ID_OPUS:
87  return 1;
88  default:
89  return 0;
90  }
91 }
92 
94 {
95  RTPMuxContext *s = s1->priv_data;
96  int n, ret = AVERROR(EINVAL);
97  AVStream *st;
98 
99  if (s1->nb_streams != 1) {
100  av_log(s1, AV_LOG_ERROR, "Only one stream supported in the RTP muxer\n");
101  return AVERROR(EINVAL);
102  }
103  st = s1->streams[0];
104  if (!is_supported(st->codecpar->codec_id)) {
105  av_log(s1, AV_LOG_ERROR, "Unsupported codec %s\n", avcodec_get_name(st->codecpar->codec_id));
106 
107  return -1;
108  }
109 
110  if (s->payload_type < 0) {
111  /* Re-validate non-dynamic payload types */
112  if (st->id < RTP_PT_PRIVATE)
113  st->id = ff_rtp_get_payload_type(s1, st->codecpar, -1);
114 
115  s->payload_type = st->id;
116  } else {
117  /* private option takes priority */
118  st->id = s->payload_type;
119  }
120 
121  s->base_timestamp = av_get_random_seed();
122  s->timestamp = s->base_timestamp;
123  s->cur_timestamp = 0;
124  if (!s->ssrc)
125  s->ssrc = av_get_random_seed();
126  s->first_packet = 1;
127  s->first_rtcp_ntp_time = ff_ntp_time();
128  if (s1->start_time_realtime != 0 && s1->start_time_realtime != AV_NOPTS_VALUE)
129  /* Round the NTP time to whole milliseconds. */
130  s->first_rtcp_ntp_time = (s1->start_time_realtime / 1000) * 1000 +
132  // Pick a random sequence start number, but in the lower end of the
133  // available range, so that any wraparound doesn't happen immediately.
134  // (Immediate wraparound would be an issue for SRTP.)
135  if (s->seq < 0) {
136  if (s1->flags & AVFMT_FLAG_BITEXACT) {
137  s->seq = 0;
138  } else
139  s->seq = av_get_random_seed() & 0x0fff;
140  } else
141  s->seq &= 0xffff; // Use the given parameter, wrapped to the right interval
142 
143  if (s1->packet_size) {
144  if (s1->pb->max_packet_size)
145  s1->packet_size = FFMIN(s1->packet_size,
146  s1->pb->max_packet_size);
147  } else
148  s1->packet_size = s1->pb->max_packet_size;
149  if (s1->packet_size <= 12) {
150  av_log(s1, AV_LOG_ERROR, "Max packet size %u too low\n", s1->packet_size);
151  return AVERROR(EIO);
152  }
153  s->buf = av_malloc(s1->packet_size);
154  if (!s->buf) {
155  return AVERROR(ENOMEM);
156  }
157  s->max_payload_size = s1->packet_size - 12;
158 
159  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
160  avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate);
161  } else {
162  avpriv_set_pts_info(st, 32, 1, 90000);
163  }
164  s->buf_ptr = s->buf;
165  switch(st->codecpar->codec_id) {
166  case AV_CODEC_ID_MP2:
167  case AV_CODEC_ID_MP3:
168  s->buf_ptr = s->buf + 4;
169  avpriv_set_pts_info(st, 32, 1, 90000);
170  break;
173  break;
174  case AV_CODEC_ID_MPEG2TS:
175  n = s->max_payload_size / TS_PACKET_SIZE;
176  if (n < 1)
177  n = 1;
178  s->max_payload_size = n * TS_PACKET_SIZE;
179  break;
180  case AV_CODEC_ID_DIRAC:
181  if (s1->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
183  "Packetizing VC-2 is experimental and does not use all values "
184  "of the specification "
185  "(even though most receivers may handle it just fine). "
186  "Please set -strict experimental in order to enable it.\n");
188  goto fail;
189  }
190  break;
191  case AV_CODEC_ID_H261:
192  if (s1->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
194  "Packetizing H.261 is experimental and produces incorrect "
195  "packetization for cases where GOBs don't fit into packets "
196  "(even though most receivers may handle it just fine). "
197  "Please set -f_strict experimental in order to enable it.\n");
199  goto fail;
200  }
201  break;
202  case AV_CODEC_ID_H264:
203  /* check for H.264 MP4 syntax */
204  if (st->codecpar->extradata_size > 4 && st->codecpar->extradata[0] == 1) {
205  s->nal_length_size = (st->codecpar->extradata[4] & 0x03) + 1;
206  }
207  break;
208  case AV_CODEC_ID_HEVC:
209  /* Only check for the standardized hvcC version of extradata, keeping
210  * things simple and similar to the avcC/H.264 case above, instead
211  * of trying to handle the pre-standardization versions (as in
212  * libavcodec/hevc.c). */
213  if (st->codecpar->extradata_size > 21 && st->codecpar->extradata[0] == 1) {
214  s->nal_length_size = (st->codecpar->extradata[21] & 0x03) + 1;
215  }
216  break;
217  case AV_CODEC_ID_VP9:
218  if (s1->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
220  "Packetizing VP9 is experimental and its specification is "
221  "still in draft state. "
222  "Please set -strict experimental in order to enable it.\n");
224  goto fail;
225  }
226  break;
227  case AV_CODEC_ID_VORBIS:
228  case AV_CODEC_ID_THEORA:
229  s->max_frames_per_packet = 15;
230  break;
232  /* Due to a historical error, the clock rate for G722 in RTP is
233  * 8000, even if the sample rate is 16000. See RFC 3551. */
234  avpriv_set_pts_info(st, 32, 1, 8000);
235  break;
236  case AV_CODEC_ID_OPUS:
237  if (st->codecpar->channels > 2) {
238  av_log(s1, AV_LOG_ERROR, "Multistream opus not supported in RTP\n");
239  goto fail;
240  }
241  /* The opus RTP RFC says that all opus streams should use 48000 Hz
242  * as clock rate, since all opus sample rates can be expressed in
243  * this clock rate, and sample rate changes on the fly are supported. */
244  avpriv_set_pts_info(st, 32, 1, 48000);
245  break;
246  case AV_CODEC_ID_ILBC:
247  if (st->codecpar->block_align != 38 && st->codecpar->block_align != 50) {
248  av_log(s1, AV_LOG_ERROR, "Incorrect iLBC block size specified\n");
249  goto fail;
250  }
251  s->max_frames_per_packet = s->max_payload_size / st->codecpar->block_align;
252  break;
253  case AV_CODEC_ID_AMR_NB:
254  case AV_CODEC_ID_AMR_WB:
255  s->max_frames_per_packet = 50;
257  n = 31;
258  else
259  n = 61;
260  /* max_header_toc_size + the largest AMR payload must fit */
261  if (1 + s->max_frames_per_packet + n > s->max_payload_size) {
262  av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n");
263  goto fail;
264  }
265  if (st->codecpar->channels != 1) {
266  av_log(s1, AV_LOG_ERROR, "Only mono is supported\n");
267  goto fail;
268  }
269  break;
270  case AV_CODEC_ID_AAC:
271  s->max_frames_per_packet = 50;
272  break;
273  default:
274  break;
275  }
276 
277  return 0;
278 
279 fail:
280  av_freep(&s->buf);
281  return ret;
282 }
283 
284 /* send an rtcp sender report packet */
285 static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time, int bye)
286 {
287  RTPMuxContext *s = s1->priv_data;
288  uint32_t rtp_ts;
289 
290  av_log(s1, AV_LOG_TRACE, "RTCP: %02x %"PRIx64" %"PRIx32"\n", s->payload_type, ntp_time, s->timestamp);
291 
292  s->last_rtcp_ntp_time = ntp_time;
293  rtp_ts = av_rescale_q(ntp_time - s->first_rtcp_ntp_time, (AVRational){1, 1000000},
294  s1->streams[0]->time_base) + s->base_timestamp;
295  avio_w8(s1->pb, RTP_VERSION << 6);
296  avio_w8(s1->pb, RTCP_SR);
297  avio_wb16(s1->pb, 6); /* length in words - 1 */
298  avio_wb32(s1->pb, s->ssrc);
299  avio_wb32(s1->pb, ntp_time / 1000000);
300  avio_wb32(s1->pb, ((ntp_time % 1000000) << 32) / 1000000);
301  avio_wb32(s1->pb, rtp_ts);
302  avio_wb32(s1->pb, s->packet_count);
303  avio_wb32(s1->pb, s->octet_count);
304 
305  if (s->cname) {
306  int len = FFMIN(strlen(s->cname), 255);
307  avio_w8(s1->pb, (RTP_VERSION << 6) + 1);
308  avio_w8(s1->pb, RTCP_SDES);
309  avio_wb16(s1->pb, (7 + len + 3) / 4); /* length in words - 1 */
310 
311  avio_wb32(s1->pb, s->ssrc);
312  avio_w8(s1->pb, 0x01); /* CNAME */
313  avio_w8(s1->pb, len);
314  avio_write(s1->pb, s->cname, len);
315  avio_w8(s1->pb, 0); /* END */
316  for (len = (7 + len) % 4; len % 4; len++)
317  avio_w8(s1->pb, 0);
318  }
319 
320  if (bye) {
321  avio_w8(s1->pb, (RTP_VERSION << 6) | 1);
322  avio_w8(s1->pb, RTCP_BYE);
323  avio_wb16(s1->pb, 1); /* length in words - 1 */
324  avio_wb32(s1->pb, s->ssrc);
325  }
326 
327  avio_flush(s1->pb);
328 }
329 
330 /* send an rtp packet. sequence number is incremented, but the caller
331  must update the timestamp itself */
332 void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
333 {
334  RTPMuxContext *s = s1->priv_data;
335 
336  av_log(s1, AV_LOG_TRACE, "rtp_send_data size=%d\n", len);
337 
338  /* build the RTP header */
339  avio_w8(s1->pb, RTP_VERSION << 6);
340  avio_w8(s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7));
341  avio_wb16(s1->pb, s->seq);
342  avio_wb32(s1->pb, s->timestamp);
343  avio_wb32(s1->pb, s->ssrc);
344 
345  avio_write(s1->pb, buf1, len);
346  avio_flush(s1->pb);
347 
348  s->seq = (s->seq + 1) & 0xffff;
349  s->octet_count += len;
350  s->packet_count++;
351 }
352 
353 /* send an integer number of samples and compute time stamp and fill
354  the rtp send buffer before sending. */
356  const uint8_t *buf1, int size, int sample_size_bits)
357 {
358  RTPMuxContext *s = s1->priv_data;
359  int len, max_packet_size, n;
360  /* Calculate the number of bytes to get samples aligned on a byte border */
361  int aligned_samples_size = sample_size_bits/av_gcd(sample_size_bits, 8);
362 
363  max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size;
364  /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */
365  if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0)
366  return AVERROR(EINVAL);
367  n = 0;
368  while (size > 0) {
369  s->buf_ptr = s->buf;
370  len = FFMIN(max_packet_size, size);
371 
372  /* copy data */
373  memcpy(s->buf_ptr, buf1, len);
374  s->buf_ptr += len;
375  buf1 += len;
376  size -= len;
377  s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits;
378  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
379  n += (s->buf_ptr - s->buf);
380  }
381  return 0;
382 }
383 
385  const uint8_t *buf1, int size)
386 {
387  RTPMuxContext *s = s1->priv_data;
388  int len, count, max_packet_size;
389 
390  max_packet_size = s->max_payload_size;
391 
392  /* test if we must flush because not enough space */
393  len = (s->buf_ptr - s->buf);
394  if ((len + size) > max_packet_size) {
395  if (len > 4) {
396  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
397  s->buf_ptr = s->buf + 4;
398  }
399  }
400  if (s->buf_ptr == s->buf + 4) {
401  s->timestamp = s->cur_timestamp;
402  }
403 
404  /* add the packet */
405  if (size > max_packet_size) {
406  /* big packet: fragment */
407  count = 0;
408  while (size > 0) {
409  len = max_packet_size - 4;
410  if (len > size)
411  len = size;
412  /* build fragmented packet */
413  s->buf[0] = 0;
414  s->buf[1] = 0;
415  s->buf[2] = count >> 8;
416  s->buf[3] = count;
417  memcpy(s->buf + 4, buf1, len);
418  ff_rtp_send_data(s1, s->buf, len + 4, 0);
419  size -= len;
420  buf1 += len;
421  count += len;
422  }
423  } else {
424  if (s->buf_ptr == s->buf + 4) {
425  /* no fragmentation possible */
426  s->buf[0] = 0;
427  s->buf[1] = 0;
428  s->buf[2] = 0;
429  s->buf[3] = 0;
430  }
431  memcpy(s->buf_ptr, buf1, size);
432  s->buf_ptr += size;
433  }
434 }
435 
437  const uint8_t *buf1, int size)
438 {
439  RTPMuxContext *s = s1->priv_data;
440  int len, max_packet_size;
441 
442  max_packet_size = s->max_payload_size;
443 
444  while (size > 0) {
445  len = max_packet_size;
446  if (len > size)
447  len = size;
448 
449  s->timestamp = s->cur_timestamp;
450  ff_rtp_send_data(s1, buf1, len, (len == size));
451 
452  buf1 += len;
453  size -= len;
454  }
455 }
456 
457 /* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */
459  const uint8_t *buf1, int size)
460 {
461  RTPMuxContext *s = s1->priv_data;
462  int len, out_len;
463 
464  s->timestamp = s->cur_timestamp;
465  while (size >= TS_PACKET_SIZE) {
466  len = s->max_payload_size - (s->buf_ptr - s->buf);
467  if (len > size)
468  len = size;
469  memcpy(s->buf_ptr, buf1, len);
470  buf1 += len;
471  size -= len;
472  s->buf_ptr += len;
473 
474  out_len = s->buf_ptr - s->buf;
475  if (out_len >= s->max_payload_size) {
476  ff_rtp_send_data(s1, s->buf, out_len, 0);
477  s->buf_ptr = s->buf;
478  }
479  }
480 }
481 
482 static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
483 {
484  RTPMuxContext *s = s1->priv_data;
485  AVStream *st = s1->streams[0];
486  int frame_duration = av_get_audio_frame_duration2(st->codecpar, 0);
487  int frame_size = st->codecpar->block_align;
488  int frames = size / frame_size;
489 
490  while (frames > 0) {
491  if (s->num_frames > 0 &&
492  av_compare_ts(s->cur_timestamp - s->timestamp, st->time_base,
493  s1->max_delay, AV_TIME_BASE_Q) >= 0) {
494  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1);
495  s->num_frames = 0;
496  }
497 
498  if (!s->num_frames) {
499  s->buf_ptr = s->buf;
500  s->timestamp = s->cur_timestamp;
501  }
502  memcpy(s->buf_ptr, buf, frame_size);
503  frames--;
504  s->num_frames++;
505  s->buf_ptr += frame_size;
506  buf += frame_size;
507  s->cur_timestamp += frame_duration;
508 
509  if (s->num_frames == s->max_frames_per_packet) {
510  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1);
511  s->num_frames = 0;
512  }
513  }
514  return 0;
515 }
516 
518 {
519  RTPMuxContext *s = s1->priv_data;
520  AVStream *st = s1->streams[0];
521  int rtcp_bytes;
522  int size= pkt->size;
523 
524  av_log(s1, AV_LOG_TRACE, "%d: write len=%d\n", pkt->stream_index, size);
525 
526  rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
528  if ((s->first_packet || ((rtcp_bytes >= RTCP_SR_SIZE) &&
529  (ff_ntp_time() - s->last_rtcp_ntp_time > 5000000))) &&
530  !(s->flags & FF_RTP_FLAG_SKIP_RTCP)) {
531  rtcp_send_sr(s1, ff_ntp_time(), 0);
532  s->last_octet_count = s->octet_count;
533  s->first_packet = 0;
534  }
535  s->cur_timestamp = s->base_timestamp + pkt->pts;
536 
537  switch(st->codecpar->codec_id) {
540  case AV_CODEC_ID_PCM_U8:
541  case AV_CODEC_ID_PCM_S8:
542  return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels);
547  return rtp_send_samples(s1, pkt->data, size, 16 * st->codecpar->channels);
549  return rtp_send_samples(s1, pkt->data, size, 24 * st->codecpar->channels);
551  /* The actual sample size is half a byte per sample, but since the
552  * stream clock rate is 8000 Hz while the sample rate is 16000 Hz,
553  * the correct parameter for send_samples_bits is 8 bits per stream
554  * clock. */
555  return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels);
558  return rtp_send_samples(s1, pkt->data, size,
560  case AV_CODEC_ID_MP2:
561  case AV_CODEC_ID_MP3:
563  break;
567  break;
568  case AV_CODEC_ID_AAC:
569  if (s->flags & FF_RTP_FLAG_MP4A_LATM)
571  else
573  break;
574  case AV_CODEC_ID_AMR_NB:
575  case AV_CODEC_ID_AMR_WB:
577  break;
578  case AV_CODEC_ID_MPEG2TS:
580  break;
581  case AV_CODEC_ID_DIRAC:
583  break;
584  case AV_CODEC_ID_H264:
586  break;
587  case AV_CODEC_ID_H261:
589  break;
590  case AV_CODEC_ID_H263:
591  if (s->flags & FF_RTP_FLAG_RFC2190) {
592  int mb_info_size = 0;
593  const uint8_t *mb_info =
595  &mb_info_size);
596  ff_rtp_send_h263_rfc2190(s1, pkt->data, size, mb_info, mb_info_size);
597  break;
598  }
599  /* Fallthrough */
600  case AV_CODEC_ID_H263P:
602  break;
603  case AV_CODEC_ID_HEVC:
605  break;
606  case AV_CODEC_ID_VORBIS:
607  case AV_CODEC_ID_THEORA:
609  break;
610  case AV_CODEC_ID_VP8:
612  break;
613  case AV_CODEC_ID_VP9:
615  break;
616  case AV_CODEC_ID_ILBC:
618  break;
619  case AV_CODEC_ID_MJPEG:
621  break;
622  case AV_CODEC_ID_OPUS:
623  if (size > s->max_payload_size) {
625  "Packet size %d too large for max RTP payload size %d\n",
626  size, s->max_payload_size);
627  return AVERROR(EINVAL);
628  }
629  /* Intentional fallthrough */
630  default:
631  /* better than nothing : send the codec raw data */
633  break;
634  }
635  return 0;
636 }
637 
639 {
640  RTPMuxContext *s = s1->priv_data;
641 
642  /* If the caller closes and recreates ->pb, this might actually
643  * be NULL here even if it was successfully allocated at the start. */
644  if (s1->pb && (s->flags & FF_RTP_FLAG_SEND_BYE))
645  rtcp_send_sr(s1, ff_ntp_time(), 1);
646  av_freep(&s->buf);
647 
648  return 0;
649 }
650 
652  .name = "rtp",
653  .long_name = NULL_IF_CONFIG_SMALL("RTP output"),
654  .priv_data_size = sizeof(RTPMuxContext),
655  .audio_codec = AV_CODEC_ID_PCM_MULAW,
656  .video_codec = AV_CODEC_ID_MPEG4,
660  .priv_class = &rtp_muxer_class,
662 };
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:301
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
ff_rtp_send_aac
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
Definition: rtpenc_aac.c:27
AVERROR_EXPERIMENTAL
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
Definition: error.h:72
rtp_write_header
static int rtp_write_header(AVFormatContext *s1)
Definition: rtpenc.c:93
ff_ntp_time
uint64_t ff_ntp_time(void)
Get the current time since NTP epoch in microseconds.
Definition: utils.c:4712
FF_RTP_FLAG_MP4A_LATM
#define FF_RTP_FLAG_MP4A_LATM
Definition: rtpenc.h:68
AVOutputFormat::name
const char * name
Definition: avformat.h:491
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
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
ff_rtp_send_jpeg
void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buff, int size)
Definition: rtpenc_jpeg.c:28
mpegts.h
av_compare_ts
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
Definition: mathematics.c:147
FF_COMPLIANCE_EXPERIMENTAL
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:1594
ff_rtp_send_h263_rfc2190
void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf1, int size, const uint8_t *mb_info, int mb_info_size)
Definition: rtpenc_h263_rfc2190.c:101
ff_rtp_send_h261
void ff_rtp_send_h261(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc_h261.c:39
RTP_VERSION
#define RTP_VERSION
Definition: rtp.h:78
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
AV_CODEC_ID_DIRAC
@ AV_CODEC_ID_DIRAC
Definition: codec_id.h:165
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:61
AVPacket::data
uint8_t * data
Definition: packet.h:355
AVOption
AVOption.
Definition: opt.h:246
AV_CODEC_ID_AMR_NB
@ AV_CODEC_ID_AMR_NB
Definition: codec_id.h:392
AV_CODEC_ID_ADPCM_G722
@ AV_CODEC_ID_ADPCM_G722
Definition: codec_id.h:368
ff_rtp_send_data
void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
Definition: rtpenc.c:332
mathematics.h
FF_RTP_FLAG_RFC2190
#define FF_RTP_FLAG_RFC2190
Definition: rtpenc.h:69
FF_RTP_FLAG_OPTS
#define FF_RTP_FLAG_OPTS(ctx, fieldname)
Definition: rtpenc.h:74
AV_CODEC_ID_AMR_WB
@ AV_CODEC_ID_AMR_WB
Definition: codec_id.h:393
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
AV_CODEC_ID_H261
@ AV_CODEC_ID_H261
Definition: codec_id.h:52
av_get_random_seed
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:120
av_gcd
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition: mathematics.c:37
ff_rtp_get_payload_type
int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecParameters *par, int idx)
Return the payload type for a given stream used in the given format context.
Definition: rtp.c:90
ff_rtp_send_mpegvideo
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc_mpv.c:29
AVCodecParameters::channels
int channels
Audio only.
Definition: codec_par.h:166
AV_CODEC_ID_SPEEX
@ AV_CODEC_ID_SPEEX
Definition: codec_id.h:445
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:302
fail
#define fail()
Definition: checkasm.h:123
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
ff_rtp_muxer
AVOutputFormat ff_rtp_muxer
Definition: rtpenc.c:651
rtp_write_trailer
static int rtp_write_trailer(AVFormatContext *s1)
Definition: rtpenc.c:638
ff_rtp_send_latm
void ff_rtp_send_latm(AVFormatContext *s1, const uint8_t *buff, int size)
Definition: rtpenc_latm.c:25
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:411
FF_RTP_FLAG_SKIP_RTCP
#define FF_RTP_FLAG_SKIP_RTCP
Definition: rtpenc.h:70
rtp_send_ilbc
static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
Definition: rtpenc.c:482
is_supported
static int is_supported(enum AVCodecID id)
Definition: rtpenc.c:49
options
static const AVOption options[]
Definition: rtpenc.c:31
AV_CODEC_ID_PCM_S8
@ AV_CODEC_ID_PCM_S8
Definition: codec_id.h:305
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:202
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AV_CODEC_ID_ADPCM_G726
@ AV_CODEC_ID_ADPCM_G726
Definition: codec_id.h:351
RTCP_TX_RATIO_NUM
#define RTCP_TX_RATIO_NUM
Definition: rtp.h:82
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:276
frame_size
int frame_size
Definition: mxfenc.c:2137
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:217
s1
#define s1
Definition: regdef.h:38
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:410
RTCP_TX_RATIO_DEN
#define RTCP_TX_RATIO_DEN
Definition: rtp.h:83
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
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:307
AV_CODEC_ID_PCM_U16BE
@ AV_CODEC_ID_PCM_U16BE
Definition: codec_id.h:304
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:76
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:353
avio_flush
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:233
AVFormatContext
Format I/O context.
Definition: avformat.h:1335
AV_CODEC_ID_PCM_ALAW
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:308
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1012
RTP_PT_PRIVATE
#define RTP_PT_PRIVATE
Definition: rtp.h:77
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:894
NULL
#define NULL
Definition: coverity.c:32
RTCP_SDES
@ RTCP_SDES
Definition: rtp.h:99
rtp_send_raw
static void rtp_send_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc.c:436
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:98
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AV_CODEC_ID_MPEG2TS
@ AV_CODEC_ID_MPEG2TS
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
Definition: codec_id.h:554
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:191
RTPMuxContext
Definition: rtpenc.h:27
rtp_muxer_class
static const AVClass rtp_muxer_class
Definition: rtpenc.c:40
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:170
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:50
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:46
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:412
rtp_send_samples
static int rtp_send_samples(AVFormatContext *s1, const uint8_t *buf1, int size, int sample_size_bits)
Definition: rtpenc.c:355
AVPacket::size
int size
Definition: packet.h:356
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4948
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:53
size
int size
Definition: twinvq_data.h:11134
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
NTP_OFFSET_US
#define NTP_OFFSET_US
Definition: internal.h:244
AV_CODEC_ID_OPUS
@ AV_CODEC_ID_OPUS
Definition: codec_id.h:470
AV_PKT_DATA_H263_MB_INFO
@ AV_PKT_DATA_H263_MB_INFO
An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of structures with info about macroblo...
Definition: packet.h:93
rtp_send_mpegts_raw
static void rtp_send_mpegts_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc.c:458
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:213
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:375
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
RTCP_SR_SIZE
#define RTCP_SR_SIZE
Definition: rtpenc.c:47
rtcp_send_sr
static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time, int bye)
Definition: rtpenc.c:285
write_packet
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:702
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:1206
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:56
AVOutputFormat
Definition: avformat.h:490
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:348
AV_CODEC_ID_THEORA
@ AV_CODEC_ID_THEORA
Definition: codec_id.h:79
ff_rtp_send_vp8
void ff_rtp_send_vp8(AVFormatContext *s1, const uint8_t *buff, int size)
Definition: rtpenc_vp8.c:26
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:177
FF_RTP_FLAG_SEND_BYE
#define FF_RTP_FLAG_SEND_BYE
Definition: rtpenc.h:72
RTCP_BYE
@ RTCP_BYE
Definition: rtp.h:100
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:223
uint8_t
uint8_t
Definition: audio_convert.c:194
ff_rtp_send_vp9
void ff_rtp_send_vp9(AVFormatContext *s1, const uint8_t *buff, int size)
Definition: rtpenc_vp9.c:26
len
int len
Definition: vorbis_enc_data.h:452
ff_rtp_send_vc2hq
void ff_rtp_send_vc2hq(AVFormatContext *s1, const uint8_t *buf, int size, int interlaced)
Definition: rtpenc_vc2hq.c:102
rtpenc.h
AVCodecParameters::field_order
enum AVFieldOrder field_order
Video only.
Definition: codec_par.h:141
AVFMT_TS_NONSTRICT
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:472
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:872
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1483
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:865
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
avformat.h
ff_rtp_send_h264_hevc
void ff_rtp_send_h264_hevc(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc_h264_hevc.c:180
ff_rtp_send_amr
void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
Packetize AMR frames into RTP packets according to RFC 3267, in octet-aligned mode.
Definition: rtpenc_amr.c:30
AV_CODEC_ID_H263P
@ AV_CODEC_ID_H263P
Definition: codec_id.h:68
random_seed.h
AV_CODEC_ID_ADPCM_G726LE
@ AV_CODEC_ID_ADPCM_G726LE
Definition: codec_id.h:376
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
ff_rtp_send_h263
void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
Packetize H.263 frames into RTP packets according to RFC 4629.
Definition: rtpenc_h263.c:43
RTCP_SR
@ RTCP_SR
Definition: rtp.h:97
av_get_audio_frame_duration2
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
Definition: utils.c:1809
AVPacket::stream_index
int stream_index
Definition: packet.h:357
rtp_write_packet
static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: rtpenc.c:517
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:102
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:306
AV_FIELD_PROGRESSIVE
@ AV_FIELD_PROGRESSIVE
Definition: codec_par.h:38
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:332
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_CODEC_ID_ILBC
@ AV_CODEC_ID_ILBC
Definition: codec_id.h:469
AV_CODEC_ID_PCM_U16LE
@ AV_CODEC_ID_PCM_U16LE
Definition: codec_id.h:303
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:453
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:189
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
TS_PACKET_SIZE
#define TS_PACKET_SIZE
Definition: mpegts.h:29
AV_CODEC_ID_VORBIS
@ AV_CODEC_ID_VORBIS
Definition: codec_id.h:415
ff_rtp_send_xiph
void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size)
Packetize Xiph frames into RTP according to RFC 5215 (Vorbis) and the Theora RFC draft.
Definition: rtpenc_xiph.c:33
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:346
rtp_send_mpegaudio
static void rtp_send_mpegaudio(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc.c:384
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:51
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:314
mb_info
Definition: cinepakenc.c:87