Libav
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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; 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_H261:
53  case AV_CODEC_ID_H263:
54  case AV_CODEC_ID_H263P:
55  case AV_CODEC_ID_H264:
56  case AV_CODEC_ID_HEVC:
59  case AV_CODEC_ID_MPEG4:
60  case AV_CODEC_ID_AAC:
61  case AV_CODEC_ID_MP2:
62  case AV_CODEC_ID_MP3:
65  case AV_CODEC_ID_PCM_S8:
70  case AV_CODEC_ID_PCM_U8:
72  case AV_CODEC_ID_AMR_NB:
73  case AV_CODEC_ID_AMR_WB:
74  case AV_CODEC_ID_VORBIS:
75  case AV_CODEC_ID_THEORA:
76  case AV_CODEC_ID_VP8:
79  case AV_CODEC_ID_ILBC:
80  case AV_CODEC_ID_MJPEG:
81  case AV_CODEC_ID_SPEEX:
82  case AV_CODEC_ID_OPUS:
83  return 1;
84  default:
85  return 0;
86  }
87 }
88 
90 {
91  RTPMuxContext *s = s1->priv_data;
92  int n, ret = AVERROR(EINVAL);
93  AVStream *st;
94 
95  if (s1->nb_streams != 1) {
96  av_log(s1, AV_LOG_ERROR, "Only one stream supported in the RTP muxer\n");
97  return AVERROR(EINVAL);
98  }
99  st = s1->streams[0];
100  if (!is_supported(st->codecpar->codec_id)) {
101  av_log(s1, AV_LOG_ERROR, "Unsupported codec %x\n", st->codecpar->codec_id);
102 
103  return -1;
104  }
105 
106  if (s->payload_type < 0) {
107  /* Re-validate non-dynamic payload types */
108  if (st->id < RTP_PT_PRIVATE)
109  st->id = ff_rtp_get_payload_type(s1, st->codecpar, -1);
110 
111  s->payload_type = st->id;
112  } else {
113  /* private option takes priority */
114  st->id = s->payload_type;
115  }
116 
118  s->timestamp = s->base_timestamp;
119  s->cur_timestamp = 0;
120  if (!s->ssrc)
121  s->ssrc = av_get_random_seed();
122  s->first_packet = 1;
124  if (s1->start_time_realtime)
125  /* Round the NTP time to whole milliseconds. */
126  s->first_rtcp_ntp_time = (s1->start_time_realtime / 1000) * 1000 +
128  // Pick a random sequence start number, but in the lower end of the
129  // available range, so that any wraparound doesn't happen immediately.
130  // (Immediate wraparound would be an issue for SRTP.)
131  if (s->seq < 0)
132  s->seq = av_get_random_seed() & 0x0fff;
133  else
134  s->seq &= 0xffff; // Use the given parameter, wrapped to the right interval
135 
136  if (s1->packet_size) {
137  if (s1->pb->max_packet_size)
138  s1->packet_size = FFMIN(s1->packet_size,
139  s1->pb->max_packet_size);
140  } else
141  s1->packet_size = s1->pb->max_packet_size;
142  if (s1->packet_size <= 12) {
143  av_log(s1, AV_LOG_ERROR, "Max packet size %d too low\n", s1->packet_size);
144  return AVERROR(EIO);
145  }
146  s->buf = av_malloc(s1->packet_size);
147  if (!s->buf) {
148  return AVERROR(ENOMEM);
149  }
150  s->max_payload_size = s1->packet_size - 12;
151 
152  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
153  avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate);
154  } else {
155  avpriv_set_pts_info(st, 32, 1, 90000);
156  }
157  s->buf_ptr = s->buf;
158  switch(st->codecpar->codec_id) {
159  case AV_CODEC_ID_MP2:
160  case AV_CODEC_ID_MP3:
161  s->buf_ptr = s->buf + 4;
162  avpriv_set_pts_info(st, 32, 1, 90000);
163  break;
166  break;
167  case AV_CODEC_ID_MPEG2TS:
169  if (n < 1)
170  n = 1;
172  break;
173  case AV_CODEC_ID_H261:
175  av_log(s, AV_LOG_ERROR,
176  "Packetizing H.261 is experimental and produces incorrect "
177  "packetization for cases where GOBs don't fit into packets "
178  "(even though most receivers may handle it just fine). "
179  "Please set -f_strict experimental in order to enable it.\n");
180  ret = AVERROR_EXPERIMENTAL;
181  goto fail;
182  }
183  break;
184  case AV_CODEC_ID_H264:
185  /* check for H.264 MP4 syntax */
186  if (st->codecpar->extradata_size > 4 && st->codecpar->extradata[0] == 1) {
187  s->nal_length_size = (st->codecpar->extradata[4] & 0x03) + 1;
188  }
189  break;
190  case AV_CODEC_ID_HEVC:
191  /* Only check for the standardized hvcC version of extradata, keeping
192  * things simple and similar to the avcC/H.264 case above, instead
193  * of trying to handle the pre-standardization versions (as in
194  * libavcodec/hevc.c). */
195  if (st->codecpar->extradata_size > 21 && st->codecpar->extradata[0] == 1) {
196  s->nal_length_size = (st->codecpar->extradata[21] & 0x03) + 1;
197  }
198  break;
199  case AV_CODEC_ID_VORBIS:
200  case AV_CODEC_ID_THEORA:
201  s->max_frames_per_packet = 15;
202  break;
204  /* Due to a historical error, the clock rate for G722 in RTP is
205  * 8000, even if the sample rate is 16000. See RFC 3551. */
206  avpriv_set_pts_info(st, 32, 1, 8000);
207  break;
208  case AV_CODEC_ID_OPUS:
209  if (st->codecpar->channels > 2) {
210  av_log(s1, AV_LOG_ERROR, "Multistream opus not supported in RTP\n");
211  goto fail;
212  }
213  /* The opus RTP RFC says that all opus streams should use 48000 Hz
214  * as clock rate, since all opus sample rates can be expressed in
215  * this clock rate, and sample rate changes on the fly are supported. */
216  avpriv_set_pts_info(st, 32, 1, 48000);
217  break;
218  case AV_CODEC_ID_ILBC:
219  if (st->codecpar->block_align != 38 && st->codecpar->block_align != 50) {
220  av_log(s1, AV_LOG_ERROR, "Incorrect iLBC block size specified\n");
221  goto fail;
222  }
224  break;
225  case AV_CODEC_ID_AMR_NB:
226  case AV_CODEC_ID_AMR_WB:
227  s->max_frames_per_packet = 50;
229  n = 31;
230  else
231  n = 61;
232  /* max_header_toc_size + the largest AMR payload must fit */
233  if (1 + s->max_frames_per_packet + n > s->max_payload_size) {
234  av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n");
235  goto fail;
236  }
237  if (st->codecpar->channels != 1) {
238  av_log(s1, AV_LOG_ERROR, "Only mono is supported\n");
239  goto fail;
240  }
241  break;
242  case AV_CODEC_ID_AAC:
243  s->max_frames_per_packet = 50;
244  break;
245  default:
246  break;
247  }
248 
249  return 0;
250 
251 fail:
252  av_freep(&s->buf);
253  return ret;
254 }
255 
256 /* send an rtcp sender report packet */
257 static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time, int bye)
258 {
259  RTPMuxContext *s = s1->priv_data;
260  uint32_t rtp_ts;
261 
262  av_log(s1, AV_LOG_TRACE, "RTCP: %02x %"PRIx64" %x\n", s->payload_type, ntp_time, s->timestamp);
263 
264  s->last_rtcp_ntp_time = ntp_time;
265  rtp_ts = av_rescale_q(ntp_time - s->first_rtcp_ntp_time, (AVRational){1, 1000000},
266  s1->streams[0]->time_base) + s->base_timestamp;
267  avio_w8(s1->pb, RTP_VERSION << 6);
268  avio_w8(s1->pb, RTCP_SR);
269  avio_wb16(s1->pb, 6); /* length in words - 1 */
270  avio_wb32(s1->pb, s->ssrc);
271  avio_wb64(s1->pb, NTP_TO_RTP_FORMAT(ntp_time));
272  avio_wb32(s1->pb, rtp_ts);
273  avio_wb32(s1->pb, s->packet_count);
274  avio_wb32(s1->pb, s->octet_count);
275 
276  if (s->cname) {
277  int len = FFMIN(strlen(s->cname), 255);
278  avio_w8(s1->pb, (RTP_VERSION << 6) + 1);
279  avio_w8(s1->pb, RTCP_SDES);
280  avio_wb16(s1->pb, (7 + len + 3) / 4); /* length in words - 1 */
281 
282  avio_wb32(s1->pb, s->ssrc);
283  avio_w8(s1->pb, 0x01); /* CNAME */
284  avio_w8(s1->pb, len);
285  avio_write(s1->pb, s->cname, len);
286  avio_w8(s1->pb, 0); /* END */
287  for (len = (7 + len) % 4; len % 4; len++)
288  avio_w8(s1->pb, 0);
289  }
290 
291  if (bye) {
292  avio_w8(s1->pb, (RTP_VERSION << 6) | 1);
293  avio_w8(s1->pb, RTCP_BYE);
294  avio_wb16(s1->pb, 1); /* length in words - 1 */
295  avio_wb32(s1->pb, s->ssrc);
296  }
297 
298  avio_flush(s1->pb);
299 }
300 
301 /* send an rtp packet. sequence number is incremented, but the caller
302  must update the timestamp itself */
303 void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
304 {
305  RTPMuxContext *s = s1->priv_data;
306 
307  av_log(s1, AV_LOG_TRACE, "rtp_send_data size=%d\n", len);
308 
309  /* build the RTP header */
310  avio_w8(s1->pb, RTP_VERSION << 6);
311  avio_w8(s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7));
312  avio_wb16(s1->pb, s->seq);
313  avio_wb32(s1->pb, s->timestamp);
314  avio_wb32(s1->pb, s->ssrc);
315 
316  avio_write(s1->pb, buf1, len);
317  avio_flush(s1->pb);
318 
319  s->seq = (s->seq + 1) & 0xffff;
320  s->octet_count += len;
321  s->packet_count++;
322 }
323 
324 /* send an integer number of samples and compute time stamp and fill
325  the rtp send buffer before sending. */
327  const uint8_t *buf1, int size, int sample_size_bits)
328 {
329  RTPMuxContext *s = s1->priv_data;
330  int len, max_packet_size, n;
331  /* Calculate the number of bytes to get samples aligned on a byte border */
332  int aligned_samples_size = sample_size_bits/av_gcd(sample_size_bits, 8);
333 
334  max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size;
335  /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */
336  if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0)
337  return AVERROR(EINVAL);
338  n = 0;
339  while (size > 0) {
340  s->buf_ptr = s->buf;
341  len = FFMIN(max_packet_size, size);
342 
343  /* copy data */
344  memcpy(s->buf_ptr, buf1, len);
345  s->buf_ptr += len;
346  buf1 += len;
347  size -= len;
348  s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits;
349  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
350  n += (s->buf_ptr - s->buf);
351  }
352  return 0;
353 }
354 
356  const uint8_t *buf1, int size)
357 {
358  RTPMuxContext *s = s1->priv_data;
359  int len, count, max_packet_size;
360 
361  max_packet_size = s->max_payload_size;
362 
363  /* test if we must flush because not enough space */
364  len = (s->buf_ptr - s->buf);
365  if ((len + size) > max_packet_size) {
366  if (len > 4) {
367  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
368  s->buf_ptr = s->buf + 4;
369  }
370  }
371  if (s->buf_ptr == s->buf + 4) {
372  s->timestamp = s->cur_timestamp;
373  }
374 
375  /* add the packet */
376  if (size > max_packet_size) {
377  /* big packet: fragment */
378  count = 0;
379  while (size > 0) {
380  len = max_packet_size - 4;
381  if (len > size)
382  len = size;
383  /* build fragmented packet */
384  s->buf[0] = 0;
385  s->buf[1] = 0;
386  s->buf[2] = count >> 8;
387  s->buf[3] = count;
388  memcpy(s->buf + 4, buf1, len);
389  ff_rtp_send_data(s1, s->buf, len + 4, 0);
390  size -= len;
391  buf1 += len;
392  count += len;
393  }
394  } else {
395  if (s->buf_ptr == s->buf + 4) {
396  /* no fragmentation possible */
397  s->buf[0] = 0;
398  s->buf[1] = 0;
399  s->buf[2] = 0;
400  s->buf[3] = 0;
401  }
402  memcpy(s->buf_ptr, buf1, size);
403  s->buf_ptr += size;
404  }
405 }
406 
408  const uint8_t *buf1, int size)
409 {
410  RTPMuxContext *s = s1->priv_data;
411  int len, max_packet_size;
412 
413  max_packet_size = s->max_payload_size;
414 
415  while (size > 0) {
416  len = max_packet_size;
417  if (len > size)
418  len = size;
419 
420  s->timestamp = s->cur_timestamp;
421  ff_rtp_send_data(s1, buf1, len, (len == size));
422 
423  buf1 += len;
424  size -= len;
425  }
426 }
427 
428 /* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */
430  const uint8_t *buf1, int size)
431 {
432  RTPMuxContext *s = s1->priv_data;
433  int len, out_len;
434 
435  s->timestamp = s->cur_timestamp;
436  while (size >= TS_PACKET_SIZE) {
437  len = s->max_payload_size - (s->buf_ptr - s->buf);
438  if (len > size)
439  len = size;
440  memcpy(s->buf_ptr, buf1, len);
441  buf1 += len;
442  size -= len;
443  s->buf_ptr += len;
444 
445  out_len = s->buf_ptr - s->buf;
446  if (out_len >= s->max_payload_size) {
447  ff_rtp_send_data(s1, s->buf, out_len, 0);
448  s->buf_ptr = s->buf;
449  }
450  }
451 }
452 
453 static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
454 {
455  RTPMuxContext *s = s1->priv_data;
456  AVStream *st = s1->streams[0];
457  int frame_duration = av_get_audio_frame_duration2(st->codecpar, 0);
458  int frame_size = st->codecpar->block_align;
459  int frames = size / frame_size;
460 
461  while (frames > 0) {
462  if (s->num_frames > 0 &&
464  s1->max_delay, AV_TIME_BASE_Q) >= 0) {
465  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1);
466  s->num_frames = 0;
467  }
468 
469  if (!s->num_frames) {
470  s->buf_ptr = s->buf;
471  s->timestamp = s->cur_timestamp;
472  }
473  memcpy(s->buf_ptr, buf, frame_size);
474  frames--;
475  s->num_frames++;
476  s->buf_ptr += frame_size;
477  buf += frame_size;
478  s->cur_timestamp += frame_duration;
479 
480  if (s->num_frames == s->max_frames_per_packet) {
481  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1);
482  s->num_frames = 0;
483  }
484  }
485  return 0;
486 }
487 
489 {
490  RTPMuxContext *s = s1->priv_data;
491  AVStream *st = s1->streams[0];
492  int rtcp_bytes;
493  int size= pkt->size;
494 
495  av_log(s1, AV_LOG_TRACE, "%d: write len=%d\n", pkt->stream_index, size);
496 
497  rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
499  if ((s->first_packet || ((rtcp_bytes >= RTCP_SR_SIZE) &&
500  (ff_ntp_time() - s->last_rtcp_ntp_time > 5000000))) &&
501  !(s->flags & FF_RTP_FLAG_SKIP_RTCP)) {
502  rtcp_send_sr(s1, ff_ntp_time(), 0);
504  s->first_packet = 0;
505  }
506  s->cur_timestamp = s->base_timestamp + pkt->pts;
507 
508  switch(st->codecpar->codec_id) {
511  case AV_CODEC_ID_PCM_U8:
512  case AV_CODEC_ID_PCM_S8:
513  return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels);
518  return rtp_send_samples(s1, pkt->data, size, 16 * st->codecpar->channels);
520  /* The actual sample size is half a byte per sample, but since the
521  * stream clock rate is 8000 Hz while the sample rate is 16000 Hz,
522  * the correct parameter for send_samples_bits is 8 bits per stream
523  * clock. */
524  return rtp_send_samples(s1, pkt->data, size, 8 * st->codecpar->channels);
526  return rtp_send_samples(s1, pkt->data, size,
528  case AV_CODEC_ID_MP2:
529  case AV_CODEC_ID_MP3:
530  rtp_send_mpegaudio(s1, pkt->data, size);
531  break;
534  ff_rtp_send_mpegvideo(s1, pkt->data, size);
535  break;
536  case AV_CODEC_ID_AAC:
537  if (s->flags & FF_RTP_FLAG_MP4A_LATM)
538  ff_rtp_send_latm(s1, pkt->data, size);
539  else
540  ff_rtp_send_aac(s1, pkt->data, size);
541  break;
542  case AV_CODEC_ID_AMR_NB:
543  case AV_CODEC_ID_AMR_WB:
544  ff_rtp_send_amr(s1, pkt->data, size);
545  break;
546  case AV_CODEC_ID_MPEG2TS:
547  rtp_send_mpegts_raw(s1, pkt->data, size);
548  break;
549  case AV_CODEC_ID_H264:
550  ff_rtp_send_h264_hevc(s1, pkt->data, size);
551  break;
552  case AV_CODEC_ID_H261:
553  ff_rtp_send_h261(s1, pkt->data, size);
554  break;
555  case AV_CODEC_ID_H263:
556  if (s->flags & FF_RTP_FLAG_RFC2190) {
557  int mb_info_size = 0;
558  const uint8_t *mb_info =
560  &mb_info_size);
561  ff_rtp_send_h263_rfc2190(s1, pkt->data, size, mb_info, mb_info_size);
562  break;
563  }
564  /* Fallthrough */
565  case AV_CODEC_ID_H263P:
566  ff_rtp_send_h263(s1, pkt->data, size);
567  break;
568  case AV_CODEC_ID_HEVC:
569  ff_rtp_send_h264_hevc(s1, pkt->data, size);
570  break;
571  case AV_CODEC_ID_VORBIS:
572  case AV_CODEC_ID_THEORA:
573  ff_rtp_send_xiph(s1, pkt->data, size);
574  break;
575  case AV_CODEC_ID_VP8:
576  ff_rtp_send_vp8(s1, pkt->data, size);
577  break;
578  case AV_CODEC_ID_ILBC:
579  rtp_send_ilbc(s1, pkt->data, size);
580  break;
581  case AV_CODEC_ID_MJPEG:
582  ff_rtp_send_jpeg(s1, pkt->data, size);
583  break;
584  case AV_CODEC_ID_OPUS:
585  if (size > s->max_payload_size) {
586  av_log(s1, AV_LOG_ERROR,
587  "Packet size %d too large for max RTP payload size %d\n",
588  size, s->max_payload_size);
589  return AVERROR(EINVAL);
590  }
591  /* Intentional fallthrough */
592  default:
593  /* better than nothing : send the codec raw data */
594  rtp_send_raw(s1, pkt->data, size);
595  break;
596  }
597  return 0;
598 }
599 
601 {
602  RTPMuxContext *s = s1->priv_data;
603 
604  /* If the caller closes and recreates ->pb, this might actually
605  * be NULL here even if it was successfully allocated at the start. */
606  if (s1->pb && (s->flags & FF_RTP_FLAG_SEND_BYE))
607  rtcp_send_sr(s1, ff_ntp_time(), 1);
608  av_freep(&s->buf);
609 
610  return 0;
611 }
612 
614  .name = "rtp",
615  .long_name = NULL_IF_CONFIG_SMALL("RTP output"),
616  .priv_data_size = sizeof(RTPMuxContext),
617  .audio_codec = AV_CODEC_ID_PCM_MULAW,
618  .video_codec = AV_CODEC_ID_MPEG4,
622  .priv_class = &rtp_muxer_class,
624 };
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: avcodec.h:2610
unsigned int packet_size
Definition: avformat.h:1044
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:392
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
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:1156
int size
AVOption.
Definition: opt.h:234
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:2986
int payload_type
Definition: rtpenc.h:31
static const uint8_t frame_size[4]
Definition: g723_1.h:219
static int rtp_send_samples(AVFormatContext *s1, const uint8_t *buf1, int size, int sample_size_bits)
Definition: rtpenc.c:326
#define NTP_OFFSET_US
Definition: internal.h:166
static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: rtpenc.c:488
#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:3483
int size
Definition: avcodec.h:1347
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
#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
#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:1239
int strict_std_compliance
Allow non-standard and experimental extension.
Definition: avformat.h:1211
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition: avformat.h:430
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
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
Format I/O context.
Definition: avformat.h:940
#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:39
uint8_t
AVOptions.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:150
static const AVClass rtp_muxer_class
Definition: rtpenc.c:40
int id
Format-specific stream ID.
Definition: avformat.h:712
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:1008
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:89
uint8_t * data
Definition: avcodec.h:1346
static int flags
Definition: log.c:50
Definition: rtp.h:99
uint8_t * buf
Definition: rtpenc.h:49
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:221
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:64
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:264
#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:2812
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:99
int max_packet_size
Definition: avio.h:134
uint32_t ssrc
Definition: rtpenc.h:32
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:193
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
Definition: rtpenc_aac.c:27
void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buff, int size)
Definition: rtpenc_jpeg.c:27
#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:148
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:479
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3479
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)
Return the greatest common divisor of a and b.
Definition: mathematics.c:32
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:2515
#define FF_RTP_FLAG_SKIP_RTCP
Definition: rtpenc.h:70
#define fail()
Definition: checkasm.h:80
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:104
static void rtp_send_mpegts_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc.c:429
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3501
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:996
int block_align
Audio only.
Definition: avcodec.h:3571
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:32
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:236
#define FFMIN(a, b)
Definition: common.h:66
void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
Definition: rtpenc.c:303
void ff_rtp_send_h261(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc_h261.c:39
void ff_rtp_send_h264_hevc(AVFormatContext *s1, const uint8_t *buf1, int size)
const char * name
Definition: avformat.h:450
static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
Definition: rtpenc.c:453
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc_mpv.c:29
int frames
Definition: movenc.c:65
static void rtp_send_mpegaudio(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc.c:355
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:198
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it...
Definition: error.h:62
Stream structure.
Definition: avformat.h:705
int64_t first_rtcp_ntp_time
Definition: rtpenc.h:43
uint32_t cur_timestamp
Definition: rtpenc.h:37
NULL
Definition: eval.c:55
AVOutputFormat ff_rtp_muxer
Definition: rtpenc.c:613
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:247
Definition: rtp.h:100
AVIOContext * pb
I/O context.
Definition: avformat.h:982
av_default_item_name
Definition: dnxhdenc.c:55
#define FF_RTP_FLAG_OPTS(ctx, fieldname)
Definition: rtpenc.h:74
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
static int is_supported(enum AVCodecID id)
Definition: rtpenc.c:49
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Definition: avconv.c:278
int first_packet
Definition: rtpenc.h:47
Describe the class of an AVClass context structure.
Definition: log.h:34
rational number numerator/denominator
Definition: rational.h:43
int flags
Definition: rtpenc.h:61
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:404
#define NTP_TO_RTP_FORMAT(x)
Definition: rtp.h:113
int sample_rate
Audio only.
Definition: avcodec.h:3564
Main libavformat public API header.
static void rtp_send_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc.c:407
static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time, int bye)
Definition: rtpenc.c:257
#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:567
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:89
void * priv_data
Format private data.
Definition: avformat.h:968
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:373
static int rtp_write_trailer(AVFormatContext *s1)
Definition: rtpenc.c:600
int bits_per_coded_sample
Definition: avcodec.h:3514
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3497
int channels
Audio only.
Definition: avcodec.h:3560
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:324
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:284
uint32_t av_get_random_seed(void)
Get random data.
Definition: random_seed.c:95
AVCodecParameters * codecpar
Definition: avformat.h:831
int stream_index
Definition: avcodec.h:1348
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:742
const char * cname
Definition: rtpenc.h:33
This structure stores compressed data.
Definition: avcodec.h:1323
#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:1339