FFmpeg
Loading...
Searching...
No Matches
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"
24#include "mpegts.h"
25#include "internal.h"
26#include "mux.h"
28#include "libavutil/mem.h"
30#include "libavutil/opt.h"
31#include "libavcodec/opus/tab.h"
32
33#include "rtpenc.h"
34
35static const AVOption options[] = {
37 { "payload_type", "Specify RTP payload type", offsetof(RTPMuxContext, payload_type), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM },
38 { "ssrc", "Stream identifier", offsetof(RTPMuxContext, ssrc), AV_OPT_TYPE_UINT, { .i64 = 0 }, 0, UINT32_MAX, AV_OPT_FLAG_ENCODING_PARAM },
39 { "cname", "CNAME to include in RTCP SR packets", offsetof(RTPMuxContext, cname), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
40 { "seq", "Starting sequence number", offsetof(RTPMuxContext, seq), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 65535, AV_OPT_FLAG_ENCODING_PARAM },
41 { NULL },
42};
43
44static const AVClass rtp_muxer_class = {
45 .class_name = "RTP muxer",
46 .item_name = av_default_item_name,
47 .option = options,
48 .version = LIBAVUTIL_VERSION_INT,
49};
50
51#define RTCP_SR_SIZE 28
52
100
102{
104 int n, ret = AVERROR(EINVAL);
105 int payload_header_size = 0;
106 AVStream *st;
107
108 if (s1->nb_streams != 1) {
109 av_log(s1, AV_LOG_ERROR, "Only one stream supported in the RTP muxer\n");
110 return AVERROR(EINVAL);
111 }
112 st = s1->streams[0];
113 if (!is_supported(st->codecpar->codec_id)) {
114 av_log(s1, AV_LOG_ERROR, "Unsupported codec %s\n", avcodec_get_name(st->codecpar->codec_id));
115
116 return -1;
117 }
118
119 if (s->payload_type < 0) {
120 /* Re-validate non-dynamic payload types */
121 if (st->id < RTP_PT_PRIVATE)
122 st->id = ff_rtp_get_payload_type(s1, st->codecpar, -1);
123
124 s->payload_type = st->id;
125 } else {
126 /* private option takes priority */
127 st->id = s->payload_type;
128 }
129
130 s->base_timestamp = av_get_random_seed();
131 s->timestamp = s->base_timestamp;
132 s->cur_timestamp = 0;
133 if (!s->ssrc)
134 s->ssrc = av_get_random_seed();
135 s->first_packet = 1;
136 s->first_rtcp_ntp_time = ff_ntp_time();
138 /* Round the NTP time to whole milliseconds. */
139 s->first_rtcp_ntp_time = (s1->start_time_realtime / 1000) * 1000 +
141 // Pick a random sequence start number, but in the lower end of the
142 // available range, so that any wraparound doesn't happen immediately.
143 // (Immediate wraparound would be an issue for SRTP.)
144 if (s->seq < 0) {
145 if (s1->flags & AVFMT_FLAG_BITEXACT) {
146 s->seq = 0;
147 } else
148 s->seq = av_get_random_seed() & 0x0fff;
149 } else
150 s->seq &= 0xffff; // Use the given parameter, wrapped to the right interval
151
152 if (s1->packet_size) {
153 if (s1->pb->max_packet_size)
154 s1->packet_size = FFMIN(s1->packet_size,
155 s1->pb->max_packet_size);
156 } else
157 s1->packet_size = s1->pb->max_packet_size;
158 if (s1->packet_size <= 12) {
159 av_log(s1, AV_LOG_ERROR, "Max packet size %u too low\n", s1->packet_size);
160 return AVERROR(EIO);
161 }
162 s->buf = av_malloc(s1->packet_size);
163 if (!s->buf) {
164 return AVERROR(ENOMEM);
165 }
166 s->max_payload_size = s1->packet_size - 12;
167
170 } else {
171 avpriv_set_pts_info(st, 32, 1, 90000);
172 }
173 s->buf_ptr = s->buf;
174 switch(st->codecpar->codec_id) {
175 case AV_CODEC_ID_MP2:
176 case AV_CODEC_ID_MP3:
177 s->buf_ptr = s->buf + 4;
178 payload_header_size = 4;
179 avpriv_set_pts_info(st, 32, 1, 90000);
180 break;
183 payload_header_size = 4;
184 break;
186 if (s->max_payload_size < TS_PACKET_SIZE) {
188 "RTP payload size %u too small for MPEG-TS "
189 "(minimum %d bytes required)\n",
190 s->max_payload_size, TS_PACKET_SIZE);
191 ret = AVERROR(EINVAL);
192 goto fail;
193 }
194
195 n = s->max_payload_size / TS_PACKET_SIZE;
196 s->max_payload_size = n * TS_PACKET_SIZE;
197 break;
201 "Packetizing VC-2 is experimental and does not use all values "
202 "of the specification "
203 "(even though most receivers may handle it just fine). "
204 "Please set -strict experimental in order to enable it.\n");
206 goto fail;
207 }
208 payload_header_size = 20;
209 break;
210 case AV_CODEC_ID_H263:
211 if (s->flags & FF_RTP_FLAG_RFC2190) {
212 payload_header_size = 8;
213 break;
214 }
217 payload_header_size = 2;
218 break;
219 case AV_CODEC_ID_H261:
222 "Packetizing H.261 is experimental and produces incorrect "
223 "packetization for cases where GOBs don't fit into packets "
224 "(even though most receivers may handle it just fine). "
225 "Please set -f_strict experimental in order to enable it.\n");
227 goto fail;
228 }
229 payload_header_size = 4;
230 break;
231 case AV_CODEC_ID_H264:
232 /* check for H.264 MP4 syntax */
233 if (st->codecpar->extradata_size > 4 && st->codecpar->extradata[0] == 1) {
234 s->nal_length_size = (st->codecpar->extradata[4] & 0x03) + 1;
235 }
236 payload_header_size = 2;
237 break;
238 case AV_CODEC_ID_HEVC:
239 /* Only check for the standardized hvcC version of extradata, keeping
240 * things simple and similar to the avcC/H.264 case above, instead
241 * of trying to handle the pre-standardization versions (as in
242 * libavcodec/hevc.c). */
243 if (st->codecpar->extradata_size > 21 && st->codecpar->extradata[0] == 1) {
244 s->nal_length_size = (st->codecpar->extradata[21] & 0x03) + 1;
245 }
246 payload_header_size = 3;
247 break;
248 case AV_CODEC_ID_VP8:
249 payload_header_size = 4;
250 break;
253 if (st->codecpar->width > 32767 || st->codecpar->height > 32767) {
254 av_log(s1, AV_LOG_ERROR, "dimensions %dx%d too large for RFC 4175\n",
255 st->codecpar->width, st->codecpar->height);
256 return AVERROR(EINVAL);
257 }
260 if (st->codecpar->width <= 0 || st->codecpar->height <= 0) {
261 av_log(s1, AV_LOG_ERROR, "dimensions not set\n");
262 return AVERROR(EINVAL);
263 }
264 break;
265 case AV_CODEC_ID_VP9:
268 "Packetizing VP9 is experimental and its specification is "
269 "still in draft state. "
270 "Please set -strict experimental in order to enable it.\n");
272 goto fail;
273 }
274 payload_header_size = 1;
275 break;
276 case AV_CODEC_ID_AV1:
279 "Packetizing AV1 is experimental and its specification is "
280 "still in draft state. "
281 "Please set -strict experimental in order to enable it.\n");
283 goto fail;
284 }
285 payload_header_size = 3;
286 break;
289 s->max_frames_per_packet = 15;
290 break;
292 /* Due to a historical error, the clock rate for G722 in RTP is
293 * 8000, even if the sample rate is 16000. See RFC 3551. */
294 avpriv_set_pts_info(st, 32, 1, 8000);
295 break;
296 case AV_CODEC_ID_OPUS:
297 if (st->codecpar->ch_layout.nb_channels > 2) {
298 av_log(s1, AV_LOG_ERROR, "Multistream opus not supported in RTP\n");
299 goto fail;
300 }
301 /* The opus RTP RFC says that all opus streams should use 48000 Hz
302 * as clock rate, since all opus sample rates can be expressed in
303 * this clock rate, and sample rate changes on the fly are supported. */
305 break;
306 case AV_CODEC_ID_ILBC:
307 if (st->codecpar->block_align != 38 && st->codecpar->block_align != 50) {
308 av_log(s1, AV_LOG_ERROR, "Incorrect iLBC block size specified\n");
309 goto fail;
310 }
311 s->max_frames_per_packet = s->max_payload_size / st->codecpar->block_align;
312 if (!s->max_frames_per_packet) {
313 av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for iLBC\n");
314 goto fail;
315 }
316 break;
319 s->max_frames_per_packet = 50;
321 n = 31;
322 else
323 n = 61;
324 /* max_header_toc_size + the largest AMR payload must fit */
325 if (1 + s->max_frames_per_packet + n > s->max_payload_size) {
326 av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for AMR\n");
327 goto fail;
328 }
329 if (st->codecpar->ch_layout.nb_channels != 1) {
330 av_log(s1, AV_LOG_ERROR, "Only mono is supported\n");
331 goto fail;
332 }
333 break;
334 case AV_CODEC_ID_AAC:
335 s->max_frames_per_packet = 50;
336 if (!(s->flags & FF_RTP_FLAG_MP4A_LATM))
337 payload_header_size = 4;
338 break;
339 default:
340 break;
341 }
342
343 if (s->max_payload_size <= payload_header_size) {
344 av_log(s1, AV_LOG_ERROR, "Max packet size %u too low for a %d byte payload header\n",
345 s1->packet_size, payload_header_size);
346 goto fail;
347 }
348
349 return 0;
350
351fail:
352 av_freep(&s->buf);
353 return ret;
354}
355
356/* send an rtcp sender report packet */
357static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time, int bye)
358{
360 uint32_t rtp_ts;
361
362 av_log(s1, AV_LOG_TRACE, "RTCP: %02x %"PRIx64" %"PRIx32"\n", s->payload_type, ntp_time, s->timestamp);
363
364 s->last_rtcp_ntp_time = ntp_time;
365 rtp_ts = av_rescale_q(ntp_time - s->first_rtcp_ntp_time, (AVRational){1, 1000000},
366 s1->streams[0]->time_base) + s->base_timestamp;
367 avio_w8(s1->pb, RTP_VERSION << 6);
368 avio_w8(s1->pb, RTCP_SR);
369 avio_wb16(s1->pb, 6); /* length in words - 1 */
370 avio_wb32(s1->pb, s->ssrc);
371 avio_wb32(s1->pb, ntp_time / 1000000);
372 avio_wb32(s1->pb, ((ntp_time % 1000000) << 32) / 1000000);
373 avio_wb32(s1->pb, rtp_ts);
374 avio_wb32(s1->pb, s->packet_count);
375 avio_wb32(s1->pb, s->octet_count);
376
377 if (s->cname) {
378 int len = FFMIN(strlen(s->cname), 255);
379 avio_w8(s1->pb, (RTP_VERSION << 6) + 1);
380 avio_w8(s1->pb, RTCP_SDES);
381 avio_wb16(s1->pb, (7 + len + 3) / 4); /* length in words - 1 */
382
383 avio_wb32(s1->pb, s->ssrc);
384 avio_w8(s1->pb, 0x01); /* CNAME */
385 avio_w8(s1->pb, len);
386 avio_write(s1->pb, s->cname, len);
387 avio_w8(s1->pb, 0); /* END */
388 for (len = (7 + len) % 4; len % 4; len++)
389 avio_w8(s1->pb, 0);
390 }
391
392 if (bye) {
393 avio_w8(s1->pb, (RTP_VERSION << 6) | 1);
394 avio_w8(s1->pb, RTCP_BYE);
395 avio_wb16(s1->pb, 1); /* length in words - 1 */
396 avio_wb32(s1->pb, s->ssrc);
397 }
398
399 avio_flush(s1->pb);
400}
401
402/* send an rtp packet. sequence number is incremented, but the caller
403 must update the timestamp itself */
404void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
405{
407
408 av_log(s1, AV_LOG_TRACE, "rtp_send_data size=%d\n", len);
409
410 /* build the RTP header */
411 avio_w8(s1->pb, RTP_VERSION << 6);
412 avio_w8(s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7));
413 avio_wb16(s1->pb, s->seq);
414 avio_wb32(s1->pb, s->timestamp);
415 avio_wb32(s1->pb, s->ssrc);
416
417 avio_write(s1->pb, buf1, len);
418 avio_flush(s1->pb);
419
420 s->seq = (s->seq + 1) & 0xffff;
421 if (!s->seq)
422 s->seq_high++;
423 s->octet_count += len;
424 s->packet_count++;
425}
426
427/* send an integer number of samples and compute time stamp and fill
428 the rtp send buffer before sending. */
430 const uint8_t *buf1, int size, int bits_per_sample)
431{
433 int nb_channels = s1->streams[0]->codecpar->ch_layout.nb_channels;
434 int len, max_packet_size, n;
435
436 if (bits_per_sample <= 0 || nb_channels <= 0 ||
437 nb_channels > INT_MAX / bits_per_sample) {
438 av_log(s1, AV_LOG_ERROR, "Invalid sample size %d or channel count %d\n",
439 bits_per_sample, nb_channels);
440 return AVERROR(EINVAL);
441 }
442 int sample_size_bits = bits_per_sample * nb_channels;
443 /* Calculate the number of bytes to get samples aligned on a byte border */
444 int aligned_samples_size = sample_size_bits/av_gcd(sample_size_bits, 8);
445
446 max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size;
447 if (!max_packet_size) {
448 av_log(s1, AV_LOG_ERROR, "RTP max payload size too small for %d byte samples\n",
449 aligned_samples_size);
450 return AVERROR(EINVAL);
451 }
452 /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */
453 if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0)
454 return AVERROR(EINVAL);
455 n = 0;
456 while (size > 0) {
457 s->buf_ptr = s->buf;
458 len = FFMIN(max_packet_size, size);
459
460 /* copy data */
461 memcpy(s->buf_ptr, buf1, len);
462 s->buf_ptr += len;
463 buf1 += len;
464 size -= len;
465 s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits;
466 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
467 n += (s->buf_ptr - s->buf);
468 }
469 return 0;
470}
471
473 const uint8_t *buf1, int size)
474{
476 int len, count, max_packet_size;
477
478 max_packet_size = s->max_payload_size;
479
480 /* test if we must flush because not enough space */
481 len = (s->buf_ptr - s->buf);
482 if ((len + size) > max_packet_size) {
483 if (len > 4) {
484 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0);
485 s->buf_ptr = s->buf + 4;
486 }
487 }
488 if (s->buf_ptr == s->buf + 4) {
489 s->timestamp = s->cur_timestamp;
490 }
491
492 /* add the packet */
493 if (size > max_packet_size - 4) {
494 /* big packet: fragment */
495 count = 0;
496 while (size > 0) {
497 len = max_packet_size - 4;
498 if (len > size)
499 len = size;
500 /* build fragmented packet */
501 s->buf[0] = 0;
502 s->buf[1] = 0;
503 s->buf[2] = count >> 8;
504 s->buf[3] = count;
505 memcpy(s->buf + 4, buf1, len);
506 ff_rtp_send_data(s1, s->buf, len + 4, 0);
507 size -= len;
508 buf1 += len;
509 count += len;
510 }
511 } else {
512 if (s->buf_ptr == s->buf + 4) {
513 /* no fragmentation possible */
514 s->buf[0] = 0;
515 s->buf[1] = 0;
516 s->buf[2] = 0;
517 s->buf[3] = 0;
518 }
519 memcpy(s->buf_ptr, buf1, size);
520 s->buf_ptr += size;
521 }
522}
523
525 const uint8_t *buf1, int size)
526{
528 int len, max_packet_size;
529
530 max_packet_size = s->max_payload_size;
531
532 while (size > 0) {
533 len = max_packet_size;
534 if (len > size)
535 len = size;
536
537 s->timestamp = s->cur_timestamp;
538 ff_rtp_send_data(s1, buf1, len, (len == size));
539
540 buf1 += len;
541 size -= len;
542 }
543}
544
545/* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */
547 const uint8_t *buf1, int size)
548{
550 int len, out_len;
551
552 s->timestamp = s->cur_timestamp;
553 while (size >= TS_PACKET_SIZE) {
554 len = s->max_payload_size - (s->buf_ptr - s->buf);
555 if (len > size)
556 len = size;
557 memcpy(s->buf_ptr, buf1, len);
558 buf1 += len;
559 size -= len;
560 s->buf_ptr += len;
561
562 out_len = s->buf_ptr - s->buf;
563 if (out_len >= s->max_payload_size) {
564 ff_rtp_send_data(s1, s->buf, out_len, 0);
565 s->buf_ptr = s->buf;
566 }
567 }
568}
569
570static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
571{
573 AVStream *st = s1->streams[0];
574 int frame_duration = av_get_audio_frame_duration2(st->codecpar, 0);
576 int frames = size / frame_size;
577
578 while (frames > 0) {
579 if (s->num_frames > 0 &&
580 av_compare_ts(s->cur_timestamp - s->timestamp, st->time_base,
581 s1->max_delay, AV_TIME_BASE_Q) >= 0) {
582 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1);
583 s->num_frames = 0;
584 }
585
586 if (!s->num_frames) {
587 s->buf_ptr = s->buf;
588 s->timestamp = s->cur_timestamp;
589 }
590 memcpy(s->buf_ptr, buf, frame_size);
591 frames--;
592 s->num_frames++;
593 s->buf_ptr += frame_size;
594 buf += frame_size;
595 s->cur_timestamp += frame_duration;
596
597 if (s->num_frames == s->max_frames_per_packet) {
598 ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 1);
599 s->num_frames = 0;
600 }
601 }
602 return 0;
603}
604
606{
608 AVStream *st = s1->streams[0];
609 int rtcp_bytes;
610 int size= pkt->size;
611
612 av_log(s1, AV_LOG_TRACE, "%d: write len=%d\n", pkt->stream_index, size);
613
614 rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /
616 if ((s->first_packet || ((rtcp_bytes >= RTCP_SR_SIZE) &&
617 (ff_ntp_time() - s->last_rtcp_ntp_time > 5000000))) &&
618 !(s->flags & FF_RTP_FLAG_SKIP_RTCP)) {
619 rtcp_send_sr(s1, ff_ntp_time(), 0);
620 s->last_octet_count = s->octet_count;
621 s->first_packet = 0;
622 }
623 s->cur_timestamp = s->base_timestamp + pkt->pts;
624
625 switch(st->codecpar->codec_id) {
630 return rtp_send_samples(s1, pkt->data, size, 8);
635 return rtp_send_samples(s1, pkt->data, size, 16);
637 return rtp_send_samples(s1, pkt->data, size, 24);
639 /* The actual sample size is half a byte per sample, but since the
640 * stream clock rate is 8000 Hz while the sample rate is 16000 Hz,
641 * the correct parameter for send_samples_bits is 8 bits per stream
642 * clock. */
643 return rtp_send_samples(s1, pkt->data, size, 8);
646 return rtp_send_samples(s1, pkt->data, size, st->codecpar->bits_per_coded_sample);
647 case AV_CODEC_ID_MP2:
648 case AV_CODEC_ID_MP3:
649 rtp_send_mpegaudio(s1, pkt->data, size);
650 break;
653 ff_rtp_send_mpegvideo(s1, pkt->data, size);
654 break;
655 case AV_CODEC_ID_AAC: {
656 const uint8_t *aac_frame = pkt->data;
657
658 /* skip ADTS header, if present */
659 if (!st->codecpar->extradata_size) {
660 if (size < 7) {
661 av_log(s1, AV_LOG_ERROR, "AAC packet too small for ADTS header\n");
662 break;
663 }
664 aac_frame += 7;
665 size -= 7;
666 }
667 if (s->flags & FF_RTP_FLAG_MP4A_LATM)
668 ff_rtp_send_latm(s1, aac_frame, size);
669 else
670 ff_rtp_send_aac(s1, aac_frame, size);
671 break;
672 }
675 ff_rtp_send_amr(s1, pkt->data, size);
676 break;
677 case AV_CODEC_ID_AV1:
678 ff_rtp_send_av1(s1, pkt->data, size, (pkt->flags & AV_PKT_FLAG_KEY) ? 1 : 0);
679 break;
681 rtp_send_mpegts_raw(s1, pkt->data, size);
682 break;
685 break;
686 case AV_CODEC_ID_H264:
687 ff_rtp_send_h264_hevc(s1, pkt->data, size);
688 break;
689 case AV_CODEC_ID_H261:
690 ff_rtp_send_h261(s1, pkt->data, size);
691 break;
692 case AV_CODEC_ID_H263:
693 if (s->flags & FF_RTP_FLAG_RFC2190) {
694 size_t mb_info_size;
695 const uint8_t *mb_info =
697 &mb_info_size);
698 ff_rtp_send_h263_rfc2190(s1, pkt->data, size, mb_info, mb_info_size);
699 break;
700 }
703 ff_rtp_send_h263(s1, pkt->data, size);
704 break;
705 case AV_CODEC_ID_HEVC:
706 ff_rtp_send_h264_hevc(s1, pkt->data, size);
707 break;
710 ff_rtp_send_xiph(s1, pkt->data, size);
711 break;
712 case AV_CODEC_ID_VP8:
713 ff_rtp_send_vp8(s1, pkt->data, size);
714 break;
715 case AV_CODEC_ID_VP9:
716 ff_rtp_send_vp9(s1, pkt->data, size);
717 break;
718 case AV_CODEC_ID_ILBC:
719 rtp_send_ilbc(s1, pkt->data, size);
720 break;
722 ff_rtp_send_jpeg(s1, pkt->data, size);
723 break;
727
729 if (interlaced)
731 break;
732 }
733 case AV_CODEC_ID_OPUS:
734 if (size > s->max_payload_size) {
736 "Packet size %d too large for max RTP payload size %d\n",
737 size, s->max_payload_size);
738 return AVERROR(EINVAL);
739 }
741 default:
742 /* better than nothing : send the codec raw data */
743 rtp_send_raw(s1, pkt->data, size);
744 break;
745 }
746 return 0;
747}
748
750{
752
753 /* If the caller closes and recreates ->pb, this might actually
754 * be NULL here even if it was successfully allocated at the start. */
755 if (s1->pb && (s->flags & FF_RTP_FLAG_SEND_BYE))
756 rtcp_send_sr(s1, ff_ntp_time(), 1);
757
758 return 0;
759}
760
762{
764
765 av_freep(&s->buf);
766}
767
769 .p.name = "rtp",
770 .p.long_name = NULL_IF_CONFIG_SMALL("RTP output"),
771 .priv_data_size = sizeof(RTPMuxContext),
772 .p.audio_codec = AV_CODEC_ID_PCM_MULAW,
773 .p.video_codec = AV_CODEC_ID_MPEG4,
774 .write_header = rtp_write_header,
775 .write_packet = rtp_write_packet,
776 .write_trailer = rtp_write_trailer,
777 .deinit = rtp_deinit,
778 .p.priv_class = &rtp_muxer_class,
780};
const FFOutputFormat ff_rtp_muxer
Definition rtpenc.c:768
static int frames
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:865
Main libavformat public API header.
#define AVFMT_NODIMENSIONS
Format does not need width/height.
Definition avformat.h:504
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition avformat.h:1570
#define AVFMT_TS_NONSTRICT
Format does not require strictly increasing timestamps, but they must still be monotonic.
Definition avformat.h:509
void avio_w8(AVIOContext *s, int b)
Definition aviobuf.c:184
void avio_wb32(AVIOContext *s, unsigned int val)
Definition aviobuf.c:368
void avio_wb16(AVIOContext *s, unsigned int val)
Definition aviobuf.c:446
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition aviobuf.c:206
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition aviobuf.c:228
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition defs.h:62
@ AV_FIELD_PROGRESSIVE
Definition defs.h:229
static AVPacket * pkt
int ret
Definition ffplay.c:391
static const uint8_t frame_size[4]
Definition g723_1.h:222
#define fail
Definition test.h:479
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition opt.h:351
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
@ AV_OPT_TYPE_UINT
Underlying C type is unsigned int.
Definition opt.h:334
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition utils.c:421
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_DIRAC
Definition codec_id.h:166
@ AV_CODEC_ID_MPEG2TS
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
Definition codec_id.h:622
@ AV_CODEC_ID_PCM_S24BE
Definition codec_id.h:346
@ AV_CODEC_ID_VORBIS
Definition codec_id.h:464
@ AV_CODEC_ID_H261
Definition codec_id.h:53
@ AV_CODEC_ID_RAWVIDEO
Definition codec_id.h:63
@ AV_CODEC_ID_PCM_U8
Definition codec_id.h:338
@ AV_CODEC_ID_PCM_S16LE
Definition codec_id.h:333
@ AV_CODEC_ID_ADPCM_G722
Definition codec_id.h:402
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_G728
Definition codec_id.h:566
@ AV_CODEC_ID_PCM_S16BE
Definition codec_id.h:334
@ AV_CODEC_ID_BITPACKED
Definition codec_id.h:276
@ AV_CODEC_ID_ADPCM_G726LE
Definition codec_id.h:409
@ AV_CODEC_ID_PCM_S8
Definition codec_id.h:337
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
@ AV_CODEC_ID_VP8
Definition codec_id.h:190
@ AV_CODEC_ID_PCM_ALAW
Definition codec_id.h:340
@ AV_CODEC_ID_AMR_NB
Definition codec_id.h:440
@ AV_CODEC_ID_THEORA
Definition codec_id.h:80
@ AV_CODEC_ID_PCM_U16BE
Definition codec_id.h:336
@ AV_CODEC_ID_MP2
Definition codec_id.h:459
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
@ AV_CODEC_ID_ADPCM_G726
Definition codec_id.h:385
@ AV_CODEC_ID_AAC
Definition codec_id.h:461
@ AV_CODEC_ID_H263
Definition codec_id.h:54
@ AV_CODEC_ID_AMR_WB
Definition codec_id.h:441
@ AV_CODEC_ID_MPEG4
Definition codec_id.h:62
@ AV_CODEC_ID_MJPEG
Definition codec_id.h:57
@ AV_CODEC_ID_SPEEX
Definition codec_id.h:494
@ AV_CODEC_ID_ILBC
Definition codec_id.h:518
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition codec_id.h:460
@ AV_CODEC_ID_VP9
Definition codec_id.h:217
@ AV_CODEC_ID_MPEG1VIDEO
Definition codec_id.h:51
@ AV_CODEC_ID_H263P
Definition codec_id.h:69
@ AV_CODEC_ID_OPUS
Definition codec_id.h:519
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition codec_id.h:52
@ AV_CODEC_ID_PCM_U16LE
Definition codec_id.h:335
@ AV_CODEC_ID_PCM_MULAW
Definition codec_id.h:339
@ 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:90
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:657
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition packet.c:252
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
Definition error.h:74
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition log.h:236
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
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.
int64_t av_gcd(int64_t a, int64_t b)
Compute the greatest common divisor of two integer operands.
Definition mathematics.c:37
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
Definition utils.c:834
uint64_t ff_ntp_time(void)
Get the current time since NTP epoch in microseconds.
Definition utils.c:257
#define NTP_OFFSET_US
Definition internal.h:447
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
#define FFMIN(a, b)
Definition macros.h:49
Memory handling functions.
#define TS_PACKET_SIZE
Definition mpegts.h:29
uint8_t interlaced
Definition mxfenc.c:2390
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
int ff_rtp_get_payload_type(const AVFormatContext *fmt, const AVCodecParameters *par, int idx)
Return the payload type for a given stream used in the given format context.
Definition rtp.c:93
#define RTP_VERSION
Definition rtp.h:80
@ RTCP_SR
Definition rtp.h:99
@ RTCP_SDES
Definition rtp.h:101
@ RTCP_BYE
Definition rtp.h:102
#define RTP_PT_PRIVATE
Definition rtp.h:79
#define RTCP_TX_RATIO_NUM
Definition rtp.h:84
#define RTCP_TX_RATIO_DEN
Definition rtp.h:85
static int is_supported(enum AVCodecID id)
Definition rtpenc.c:53
static void rtp_send_mpegaudio(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition rtpenc.c:472
static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time, int bye)
Definition rtpenc.c:357
static int rtp_send_samples(AVFormatContext *s1, const uint8_t *buf1, int size, int bits_per_sample)
Definition rtpenc.c:429
static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
Definition rtpenc.c:605
static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
Definition rtpenc.c:570
static void rtp_deinit(AVFormatContext *s1)
Definition rtpenc.c:761
static int rtp_write_header(AVFormatContext *s1)
Definition rtpenc.c:101
static const AVClass rtp_muxer_class
Definition rtpenc.c:44
static void rtp_send_mpegts_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition rtpenc.c:546
static int rtp_write_trailer(AVFormatContext *s1)
Definition rtpenc.c:749
void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
Definition rtpenc.c:404
#define RTCP_SR_SIZE
Definition rtpenc.c:51
static void rtp_send_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition rtpenc.c:524
void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf1, int size, const uint8_t *mb_info, int mb_info_size)
void ff_rtp_send_h264_hevc(AVFormatContext *s1, const uint8_t *buf1, int size)
void ff_rtp_send_vp9(AVFormatContext *s1, const uint8_t *buff, int size)
Definition rtpenc_vp9.c:26
void ff_rtp_send_vp8(AVFormatContext *s1, const uint8_t *buff, int size)
Definition rtpenc_vp8.c:26
#define FF_RTP_FLAG_OPTS(ctx, fieldname)
Definition rtpenc.h:75
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
void ff_rtp_send_raw_rfc4175(AVFormatContext *s1, const uint8_t *buf, int size, int interlaced, int field)
void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buff, int size)
Definition rtpenc_jpeg.c:28
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
Definition rtpenc_aac.c:27
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition rtpenc_mpv.c:29
#define FF_RTP_FLAG_MP4A_LATM
Definition rtpenc.h:69
void ff_rtp_send_av1(AVFormatContext *s1, const uint8_t *buf1, int size, int is_keyframe)
Definition rtpenc_av1.c:42
#define FF_RTP_FLAG_SEND_BYE
Definition rtpenc.h:73
#define FF_RTP_FLAG_RFC2190
Definition rtpenc.h:70
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
void ff_rtp_send_h261(AVFormatContext *s1, const uint8_t *buf1, int size)
Definition rtpenc_h261.c:39
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
#define FF_RTP_FLAG_SKIP_RTCP
Definition rtpenc.h:71
void ff_rtp_send_vc2hq(AVFormatContext *s1, const uint8_t *buf, int size, int interlaced)
void ff_rtp_send_latm(AVFormatContext *s1, const uint8_t *buff, int size)
Definition rtpenc_latm.c:25
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
Definition log.h:76
int extradata_size
Size of the extradata content in bytes.
Definition codec_par.h:75
enum AVFieldOrder field_order
The order of the fields in interlaced video.
Definition codec_par.h:182
int height
The height of the video frame in pixels.
Definition codec_par.h:150
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition codec_par.h:113
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int width
The width of the video frame in pixels.
Definition codec_par.h:143
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
int block_align
The number of bytes per coded audio frame, required by some formats.
Definition codec_par.h:221
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition codec_par.h:71
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1401
unsigned int packet_size
Definition avformat.h:1546
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition avformat.h:1457
AVIOContext * pb
I/O context.
Definition avformat.h:1443
int flags
Flags modifying the (de)muxer behaviour.
Definition avformat.h:1553
int strict_std_compliance
Allow non-standard and experimental extension.
Definition avformat.h:1776
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:1662
void * priv_data
Format private data.
Definition avformat.h:1429
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1469
int max_packet_size
Definition avio.h:241
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:587
Rational number (pair of numerator and denominator).
Definition rational.h:58
Stream structure.
Definition avformat.h:768
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:791
int id
Format-specific stream ID.
Definition avformat.h:780
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:807
#define OPUS_TIMESTAMP_RATE
The clock of Opus: packet lengths, pre-skip and trimming count samples at 48 kHz whatever the sample ...
Definition tab.h:35
#define av_freep(p)
#define av_log(a,...)
int size
int len