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 //#define DEBUG
32 
33 static const AVOption options[] = {
35  { "payload_type", "Specify RTP payload type", offsetof(RTPMuxContext, payload_type), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM },
36  { "ssrc", "Stream identifier", offsetof(RTPMuxContext, ssrc), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
37  { "cname", "CNAME to include in RTCP SR packets", offsetof(RTPMuxContext, cname), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
38  { NULL },
39 };
40 
41 static const AVClass rtp_muxer_class = {
42  .class_name = "RTP muxer",
43  .item_name = av_default_item_name,
44  .option = options,
45  .version = LIBAVUTIL_VERSION_INT,
46 };
47 
48 #define RTCP_SR_SIZE 28
49 
50 static int is_supported(enum AVCodecID id)
51 {
52  switch(id) {
53  case AV_CODEC_ID_H263:
54  case AV_CODEC_ID_H263P:
55  case AV_CODEC_ID_H264:
58  case AV_CODEC_ID_MPEG4:
59  case AV_CODEC_ID_AAC:
60  case AV_CODEC_ID_MP2:
61  case AV_CODEC_ID_MP3:
64  case AV_CODEC_ID_PCM_S8:
69  case AV_CODEC_ID_PCM_U8:
71  case AV_CODEC_ID_AMR_NB:
72  case AV_CODEC_ID_AMR_WB:
73  case AV_CODEC_ID_VORBIS:
74  case AV_CODEC_ID_THEORA:
75  case AV_CODEC_ID_VP8:
78  case AV_CODEC_ID_ILBC:
79  case AV_CODEC_ID_MJPEG:
80  case AV_CODEC_ID_SPEEX:
81  case AV_CODEC_ID_OPUS:
82  return 1;
83  default:
84  return 0;
85  }
86 }
87 
89 {
90  RTPMuxContext *s = s1->priv_data;
91  int n;
92  AVStream *st;
93 
94  if (s1->nb_streams != 1) {
95  av_log(s1, AV_LOG_ERROR, "Only one stream supported in the RTP muxer\n");
96  return AVERROR(EINVAL);
97  }
98  st = s1->streams[0];
99  if (!is_supported(st->codec->codec_id)) {
100  av_log(s1, AV_LOG_ERROR, "Unsupported codec %x\n", st->codec->codec_id);
101 
102  return -1;
103  }
104 
105  if (s->payload_type < 0) {
106  /* Re-validate non-dynamic payload types */
107  if (st->id < RTP_PT_PRIVATE)
108  st->id = ff_rtp_get_payload_type(s1, st->codec, -1);
109 
110  s->payload_type = st->id;
111  } else {
112  /* private option takes priority */
113  st->id = s->payload_type;
114  }
115 
117  s->timestamp = s->base_timestamp;
118  s->cur_timestamp = 0;
119  if (!s->ssrc)
120  s->ssrc = av_get_random_seed();
121  s->first_packet = 1;
123  if (s1->start_time_realtime)
124  /* Round the NTP time to whole milliseconds. */
125  s->first_rtcp_ntp_time = (s1->start_time_realtime / 1000) * 1000 +
127 
128  if (s1->packet_size) {
129  if (s1->pb->max_packet_size)
130  s1->packet_size = FFMIN(s1->packet_size,
131  s1->pb->max_packet_size);
132  } else
133  s1->packet_size = s1->pb->max_packet_size;
134  if (s1->packet_size <= 12) {
135  av_log(s1, AV_LOG_ERROR, "Max packet size %d too low\n", s1->packet_size);
136  return AVERROR(EIO);
137  }
138  s->buf = av_malloc(s1->packet_size);
139  if (s->buf == NULL) {
140  return AVERROR(ENOMEM);
141  }
142  s->max_payload_size = s1->packet_size - 12;
143 
144  s->max_frames_per_packet = 0;
145  if (s1->max_delay > 0) {
146  if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
148  if (!frame_size)
149  frame_size = st->codec->frame_size;
150  if (frame_size == 0) {
151  av_log(s1, AV_LOG_ERROR, "Cannot respect max delay: frame size = 0\n");
152  } else {
156  (AVRational){ frame_size, st->codec->sample_rate },
157  AV_ROUND_DOWN);
158  }
159  }
160  if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
161  /* FIXME: We should round down here... */
162  s->max_frames_per_packet = av_rescale_q(s1->max_delay, (AVRational){1, 1000000}, st->codec->time_base);
163  }
164  }
165 
166  avpriv_set_pts_info(st, 32, 1, 90000);
167  switch(st->codec->codec_id) {
168  case AV_CODEC_ID_MP2:
169  case AV_CODEC_ID_MP3:
170  s->buf_ptr = s->buf + 4;
171  break;
174  break;
175  case AV_CODEC_ID_MPEG2TS:
176  n = s->max_payload_size / TS_PACKET_SIZE;
177  if (n < 1)
178  n = 1;
179  s->max_payload_size = n * TS_PACKET_SIZE;
180  s->buf_ptr = s->buf;
181  break;
182  case AV_CODEC_ID_H264:
183  /* check for H.264 MP4 syntax */
184  if (st->codec->extradata_size > 4 && st->codec->extradata[0] == 1) {
185  s->nal_length_size = (st->codec->extradata[4] & 0x03) + 1;
186  }
187  break;
188  case AV_CODEC_ID_VORBIS:
189  case AV_CODEC_ID_THEORA:
190  if (!s->max_frames_per_packet) s->max_frames_per_packet = 15;
191  s->max_frames_per_packet = av_clip(s->max_frames_per_packet, 1, 15);
192  s->max_payload_size -= 6; // ident+frag+tdt/vdt+pkt_num+pkt_length
193  s->num_frames = 0;
194  goto defaultcase;
196  /* Due to a historical error, the clock rate for G722 in RTP is
197  * 8000, even if the sample rate is 16000. See RFC 3551. */
198  avpriv_set_pts_info(st, 32, 1, 8000);
199  break;
200  case AV_CODEC_ID_OPUS:
201  if (st->codec->channels > 2) {
202  av_log(s1, AV_LOG_ERROR, "Multistream opus not supported in RTP\n");
203  goto fail;
204  }
205  /* The opus RTP RFC says that all opus streams should use 48000 Hz
206  * as clock rate, since all opus sample rates can be expressed in
207  * this clock rate, and sample rate changes on the fly are supported. */
208  avpriv_set_pts_info(st, 32, 1, 48000);
209  break;
210  case AV_CODEC_ID_ILBC:
211  if (st->codec->block_align != 38 && st->codec->block_align != 50) {
212  av_log(s1, AV_LOG_ERROR, "Incorrect iLBC block size specified\n");
213  goto fail;
214  }
215  if (!s->max_frames_per_packet)
216  s->max_frames_per_packet = 1;
217  s->max_frames_per_packet = FFMIN(s->max_frames_per_packet,
218  s->max_payload_size / st->codec->block_align);
219  goto defaultcase;
220  case AV_CODEC_ID_AMR_NB:
221  case AV_CODEC_ID_AMR_WB:
222  if (!s->max_frames_per_packet)
223  s->max_frames_per_packet = 12;
224  if (st->codec->codec_id == AV_CODEC_ID_AMR_NB)
225  n = 31;
226  else
227  n = 61;
228  /* max_header_toc_size + the largest AMR payload must fit */
229  if (1 + s->max_frames_per_packet + n > s->max_payload_size) {
230  av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n");
231  goto fail;
232  }
233  if (st->codec->channels != 1) {
234  av_log(s1, AV_LOG_ERROR, "Only mono is supported\n");
235  goto fail;
236  }
237  case AV_CODEC_ID_AAC:
238  s->num_frames = 0;
239  default:
240 defaultcase:
241  if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
242  avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate);
243  }
244  s->buf_ptr = s->buf;
245  break;
246  }
247 
248  return 0;
249 
250 fail:
251  av_freep(&s->buf);
252  return AVERROR(EINVAL);
253 }
254 
255 /* send an rtcp sender report packet */
256 static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
257 {
258  RTPMuxContext *s = s1->priv_data;
259  uint32_t rtp_ts;
260 
261  av_dlog(s1, "RTCP: %02x %"PRIx64" %x\n", s->payload_type, ntp_time, s->timestamp);
262 
263  s->last_rtcp_ntp_time = ntp_time;
264  rtp_ts = av_rescale_q(ntp_time - s->first_rtcp_ntp_time, (AVRational){1, 1000000},
265  s1->streams[0]->time_base) + s->base_timestamp;
266  avio_w8(s1->pb, (RTP_VERSION << 6));
267  avio_w8(s1->pb, RTCP_SR);
268  avio_wb16(s1->pb, 6); /* length in words - 1 */
269  avio_wb32(s1->pb, s->ssrc);
270  avio_wb32(s1->pb, ntp_time / 1000000);
271  avio_wb32(s1->pb, ((ntp_time % 1000000) << 32) / 1000000);
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  avio_flush(s1->pb);
292 }
293 
294 /* send an rtp packet. sequence number is incremented, but the caller
295  must update the timestamp itself */
296 void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
297 {
298  RTPMuxContext *s = s1->priv_data;
299 
300  av_dlog(s1, "rtp_send_data size=%d\n", len);
301 
302  /* build the RTP header */
303  avio_w8(s1->pb, (RTP_VERSION << 6));
304  avio_w8(s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7));
305  avio_wb16(s1->pb, s->seq);
306  avio_wb32(s1->pb, s->timestamp);
307  avio_wb32(s1->pb, s->ssrc);
308 
309  avio_write(s1->pb, buf1, len);
310  avio_flush(s1->pb);
311 
312  s->seq++;
313  s->octet_count += len;
314  s->packet_count++;
315 }
316 
317 /* send an integer number of samples and compute time stamp and fill
318  the rtp send buffer before sending. */
320  const uint8_t *buf1, int size, int sample_size_bits)
321 {
322  RTPMuxContext *s = s1->priv_data;
323  int len, max_packet_size, n;
324  /* Calculate the number of bytes to get samples aligned on a byte border */
325  int aligned_samples_size = sample_size_bits/av_gcd(sample_size_bits, 8);
326 
327  max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size;
328  /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */
329  if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0)
330  return AVERROR(EINVAL);
331  n = 0;
332  while (size > 0) {
333  s->buf_ptr = s->buf;
334  len = FFMIN(max_packet_size, size);
335 
336  /* copy data */
337  memcpy(s->buf_ptr, buf1, len);
338  s->buf_ptr += len;
339  buf1 += len;
340  size -= len;
341  s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits;
342  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
343  n += (s->buf_ptr - s->buf);
344  }
345  return 0;
346 }
347 
349  const uint8_t *buf1, int size)
350 {
351  RTPMuxContext *s = s1->priv_data;
352  int len, count, max_packet_size;
353 
354  max_packet_size = s->max_payload_size;
355 
356  /* test if we must flush because not enough space */
357  len = (s->buf_ptr - s->buf);
358  if ((len + size) > max_packet_size) {
359  if (len > 4) {
360  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
361  s->buf_ptr = s->buf + 4;
362  }
363  }
364  if (s->buf_ptr == s->buf + 4) {
365  s->timestamp = s->cur_timestamp;
366  }
367 
368  /* add the packet */
369  if (size > max_packet_size) {
370  /* big packet: fragment */
371  count = 0;
372  while (size > 0) {
373  len = max_packet_size - 4;
374  if (len > size)
375  len = size;
376  /* build fragmented packet */
377  s->buf[0] = 0;
378  s->buf[1] = 0;
379  s->buf[2] = count >> 8;
380  s->buf[3] = count;
381  memcpy(s->buf + 4, buf1, len);
382  ff_rtp_send_data(s1, s->buf, len + 4, 0);
383  size -= len;
384  buf1 += len;
385  count += len;
386  }
387  } else {
388  if (s->buf_ptr == s->buf + 4) {
389  /* no fragmentation possible */
390  s->buf[0] = 0;
391  s->buf[1] = 0;
392  s->buf[2] = 0;
393  s->buf[3] = 0;
394  }
395  memcpy(s->buf_ptr, buf1, size);
396  s->buf_ptr += size;
397  }
398 }
399 
401  const uint8_t *buf1, int size)
402 {
403  RTPMuxContext *s = s1->priv_data;
404  int len, max_packet_size;
405 
406  max_packet_size = s->max_payload_size;
407 
408  while (size > 0) {
409  len = max_packet_size;
410  if (len > size)
411  len = size;
412 
413  s->timestamp = s->cur_timestamp;
414  ff_rtp_send_data(s1, buf1, len, (len == size));
415 
416  buf1 += len;
417  size -= len;
418  }
419 }
420 
421 /* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */
423  const uint8_t *buf1, int size)
424 {
425  RTPMuxContext *s = s1->priv_data;
426  int len, out_len;
427 
428  while (size >= TS_PACKET_SIZE) {
429  len = s->max_payload_size - (s->buf_ptr - s->buf);
430  if (len > size)
431  len = size;
432  memcpy(s->buf_ptr, buf1, len);
433  buf1 += len;
434  size -= len;
435  s->buf_ptr += len;
436 
437  out_len = s->buf_ptr - s->buf;
438  if (out_len >= s->max_payload_size) {
439  ff_rtp_send_data(s1, s->buf, out_len, 0);
440  s->buf_ptr = s->buf;
441  }
442  }
443 }
444 
445 static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
446 {
447  RTPMuxContext *s = s1->priv_data;
448  AVStream *st = s1->streams[0];
449  int frame_duration = av_get_audio_frame_duration(st->codec, 0);
450  int frame_size = st->codec->block_align;
451  int frames = size / frame_size;
452 
453  while (frames > 0) {
454  int n = FFMIN(s->max_frames_per_packet - s->num_frames, frames);
455 
456  if (!s->num_frames) {
457  s->buf_ptr = s->buf;
458  s->timestamp = s->cur_timestamp;
459  }
460  memcpy(s->buf_ptr, buf, n * frame_size);
461  frames -= n;
462  s->num_frames += n;
463  s->buf_ptr += n * frame_size;
464  buf += n * frame_size;
465  s->cur_timestamp += n * frame_duration;
466 
467  if (s->num_frames == s->max_frames_per_packet) {
468  ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1);
469  s->num_frames = 0;
470  }
471  }
472  return 0;
473 }
474 
476 {
477  RTPMuxContext *s = s1->priv_data;
478  AVStream *st = s1->streams[0];
479  int rtcp_bytes;
480  int size= pkt->size;
481 
482  av_dlog(s1, "%d: write len=%d\n", pkt->stream_index, size);
483 
484  rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
486  if ((s->first_packet || ((rtcp_bytes >= RTCP_SR_SIZE) &&
487  (ff_ntp_time() - s->last_rtcp_ntp_time > 5000000))) &&
488  !(s->flags & FF_RTP_FLAG_SKIP_RTCP)) {
489  rtcp_send_sr(s1, ff_ntp_time());
491  s->first_packet = 0;
492  }
493  s->cur_timestamp = s->base_timestamp + pkt->pts;
494 
495  switch(st->codec->codec_id) {
498  case AV_CODEC_ID_PCM_U8:
499  case AV_CODEC_ID_PCM_S8:
500  return rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels);
505  return rtp_send_samples(s1, pkt->data, size, 16 * st->codec->channels);
507  /* The actual sample size is half a byte per sample, but since the
508  * stream clock rate is 8000 Hz while the sample rate is 16000 Hz,
509  * the correct parameter for send_samples_bits is 8 bits per stream
510  * clock. */
511  return rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels);
513  return rtp_send_samples(s1, pkt->data, size,
515  case AV_CODEC_ID_MP2:
516  case AV_CODEC_ID_MP3:
517  rtp_send_mpegaudio(s1, pkt->data, size);
518  break;
521  ff_rtp_send_mpegvideo(s1, pkt->data, size);
522  break;
523  case AV_CODEC_ID_AAC:
524  if (s->flags & FF_RTP_FLAG_MP4A_LATM)
525  ff_rtp_send_latm(s1, pkt->data, size);
526  else
527  ff_rtp_send_aac(s1, pkt->data, size);
528  break;
529  case AV_CODEC_ID_AMR_NB:
530  case AV_CODEC_ID_AMR_WB:
531  ff_rtp_send_amr(s1, pkt->data, size);
532  break;
533  case AV_CODEC_ID_MPEG2TS:
534  rtp_send_mpegts_raw(s1, pkt->data, size);
535  break;
536  case AV_CODEC_ID_H264:
537  ff_rtp_send_h264(s1, pkt->data, size);
538  break;
539  case AV_CODEC_ID_H263:
540  if (s->flags & FF_RTP_FLAG_RFC2190) {
541  int mb_info_size = 0;
542  const uint8_t *mb_info =
544  &mb_info_size);
545  ff_rtp_send_h263_rfc2190(s1, pkt->data, size, mb_info, mb_info_size);
546  break;
547  }
548  /* Fallthrough */
549  case AV_CODEC_ID_H263P:
550  ff_rtp_send_h263(s1, pkt->data, size);
551  break;
552  case AV_CODEC_ID_VORBIS:
553  case AV_CODEC_ID_THEORA:
554  ff_rtp_send_xiph(s1, pkt->data, size);
555  break;
556  case AV_CODEC_ID_VP8:
557  ff_rtp_send_vp8(s1, pkt->data, size);
558  break;
559  case AV_CODEC_ID_ILBC:
560  rtp_send_ilbc(s1, pkt->data, size);
561  break;
562  case AV_CODEC_ID_MJPEG:
563  ff_rtp_send_jpeg(s1, pkt->data, size);
564  break;
565  case AV_CODEC_ID_OPUS:
566  if (size > s->max_payload_size) {
567  av_log(s1, AV_LOG_ERROR,
568  "Packet size %d too large for max RTP payload size %d\n",
569  size, s->max_payload_size);
570  return AVERROR(EINVAL);
571  }
572  /* Intentional fallthrough */
573  default:
574  /* better than nothing : send the codec raw data */
575  rtp_send_raw(s1, pkt->data, size);
576  break;
577  }
578  return 0;
579 }
580 
582 {
583  RTPMuxContext *s = s1->priv_data;
584 
585  av_freep(&s->buf);
586 
587  return 0;
588 }
589 
591  .name = "rtp",
592  .long_name = NULL_IF_CONFIG_SMALL("RTP output"),
593  .priv_data_size = sizeof(RTPMuxContext),
594  .audio_codec = AV_CODEC_ID_PCM_MULAW,
595  .video_codec = AV_CODEC_ID_MPEG4,
599  .priv_class = &rtp_muxer_class,
600 };
unsigned int packet_size
Definition: avformat.h:902
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:61
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:981
int size
AVOption.
Definition: opt.h:233
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:3283
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:319
#define NTP_OFFSET_US
Definition: internal.h:88
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: assenc.c:58
static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition: rtpenc.c:475
#define RTP_VERSION
Definition: rtp.h:77
int64_t last_rtcp_ntp_time
Definition: rtpenc.h:42
int size
Definition: avcodec.h:916
#define RTCP_TX_RATIO_NUM
Definition: rtp.h:81
unsigned int last_octet_count
Definition: rtpenc.h:48
static const AVOption options[]
Definition: rtpenc.c:33
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
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", 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_DEN
Definition: rtp.h:82
An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of structures with info about macroblo...
Definition: avcodec.h:873
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2141
uint16_t seq
Definition: rtpenc.h:34
#define FF_RTP_FLAG_MP4A_LATM
Definition: rtpenc.h:69
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1465
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:151
Format I/O context.
Definition: avformat.h:828
#define RTP_PT_PRIVATE
Definition: rtp.h:76
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:38
uint8_t
AVOptions.
static const AVClass rtp_muxer_class
Definition: rtpenc.c:41
int id
Format-specific stream ID.
Definition: avformat.h:629
int max_frames_per_packet
Definition: rtpenc.h:54
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
Definition: avformat.h:876
unsigned int octet_count
Definition: rtpenc.h:47
#define TS_PACKET_SIZE
Definition: mpegts.h:29
static int rtp_write_header(AVFormatContext *s1)
Definition: rtpenc.c:88
uint8_t * data
Definition: avcodec.h:915
static int flags
Definition: log.c:42
Definition: rtp.h:98
uint8_t * buf
Definition: rtpenc.h:51
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2704
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:165
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:67
#define FF_RTP_FLAG_RFC2190
Definition: rtpenc.h:70
uint64_t ff_ntp_time(void)
Get the current time since NTP epoch in microseconds.
Definition: utils.c:3038
int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec, int idx)
Return the payload type for a given stream used in the given format context.
Definition: rtp.c:93
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:122
static const uint8_t frame_size[4]
Definition: g723_1_data.h:47
int max_packet_size
Definition: avio.h:98
uint32_t ssrc
Definition: rtpenc.h:32
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:95
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
Definition: rtpenc_aac.c:25
void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buff, int size)
Definition: rtpenc_jpeg.c:27
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:348
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:53
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
#define FF_RTP_FLAG_SKIP_RTCP
Definition: rtpenc.h:71
static void rtp_send_mpegts_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc.c:422
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:641
unsigned int nb_streams
A list of all streams in the file.
Definition: avformat.h:875
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
Definition: mathematics.c:114
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:30
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:180
void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
Definition: rtpenc.c:296
const char * name
Definition: avformat.h:376
static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
Definition: rtpenc.c:445
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:348
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:100
LIBAVUTIL_VERSION_INT
Definition: eval.c:52
Stream structure.
Definition: avformat.h:622
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2124
int64_t first_rtcp_ntp_time
Definition: rtpenc.h:43
uint32_t cur_timestamp
Definition: rtpenc.h:37
NULL
Definition: eval.c:52
AVOutputFormat ff_rtp_muxer
Definition: rtpenc.c:590
enum AVMediaType codec_type
Definition: avcodec.h:1347
enum AVCodecID codec_id
Definition: avcodec.h:1350
int sample_rate
samples per second
Definition: avcodec.h:2104
AVIOContext * pb
I/O context.
Definition: avformat.h:861
av_default_item_name
Definition: dnxhdenc.c:43
#define FF_RTP_FLAG_OPTS(ctx, fieldname)
Definition: rtpenc.h:74
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:144
static int is_supported(enum AVCodecID id)
Definition: rtpenc.c:50
int first_packet
Definition: rtpenc.h:49
Describe the class of an AVClass context structure.
Definition: log.h:33
rational number numerator/denominator
Definition: rational.h:43
int flags
Definition: rtpenc.h:62
static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
Definition: rtpenc.c:256
#define s1
Definition: regdef.h:38
int num_frames
Definition: rtpenc.h:39
uint32_t base_timestamp
Definition: rtpenc.h:36
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
Definition: utils.c:1831
Round toward -infinity.
Definition: mathematics.h:52
uint8_t * buf_ptr
Definition: rtpenc.h:52
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:342
struct RTPMuxContext RTPMuxContext
Definition: rtpenc.h:67
void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc_h264.c:84
Main libavformat public API header.
static void rtp_send_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition: rtpenc.c:400
#define RTCP_SR_SIZE
Definition: rtpenc.c:48
Definition: rtp.h:96
unsigned int packet_count
Definition: rtpenc.h:46
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
Definition: avcodec.h:430
uint32_t timestamp
Definition: rtpenc.h:35
int len
int channels
number of audio channels
Definition: avcodec.h:2105
void * priv_data
Format private data.
Definition: avformat.h:848
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:380
static int rtp_write_trailer(AVFormatContext *s1)
Definition: rtpenc.c:581
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:268
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
Definition: avpacket.c:190
uint32_t av_get_random_seed(void)
Get random data.
Definition: random_seed.c:85
int stream_index
Definition: avcodec.h:917
This structure stores compressed data.
Definition: avcodec.h:898
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:908