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