45 .class_name =
"RTP muxer",
51#define RTCP_SR_SIZE 28
105 int payload_header_size = 0;
119 if (
s->payload_type < 0) {
124 s->payload_type = st->
id;
127 st->
id =
s->payload_type;
131 s->timestamp =
s->base_timestamp;
132 s->cur_timestamp = 0;
177 s->buf_ptr =
s->buf + 4;
178 payload_header_size = 4;
183 payload_header_size = 4;
188 "RTP payload size %u too small for MPEG-TS "
189 "(minimum %d bytes required)\n",
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");
208 payload_header_size = 20;
212 payload_header_size = 8;
217 payload_header_size = 2;
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");
229 payload_header_size = 4;
236 payload_header_size = 2;
246 payload_header_size = 3;
249 payload_header_size = 4;
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");
274 payload_header_size = 1;
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");
285 payload_header_size = 3;
289 s->max_frames_per_packet = 15;
312 if (!
s->max_frames_per_packet) {
319 s->max_frames_per_packet = 50;
325 if (1 +
s->max_frames_per_packet + n >
s->max_payload_size) {
335 s->max_frames_per_packet = 50;
337 payload_header_size = 4;
343 if (
s->max_payload_size <= payload_header_size) {
362 av_log(s1,
AV_LOG_TRACE,
"RTCP: %02x %"PRIx64
" %"PRIx32
"\n",
s->payload_type, ntp_time,
s->timestamp);
364 s->last_rtcp_ntp_time = ntp_time;
372 avio_wb32(s1->
pb, ((ntp_time % 1000000) << 32) / 1000000);
412 avio_w8(s1->
pb, (
s->payload_type & 0x7f) | ((m & 0x01) << 7));
420 s->seq = (
s->seq + 1) & 0xffff;
423 s->octet_count +=
len;
430 const uint8_t *buf1,
int size,
int bits_per_sample)
434 int len, max_packet_size, n;
436 if (bits_per_sample <= 0 || nb_channels <= 0 ||
437 nb_channels > INT_MAX / bits_per_sample) {
439 bits_per_sample, nb_channels);
442 int sample_size_bits = bits_per_sample * nb_channels;
444 int aligned_samples_size = sample_size_bits/
av_gcd(sample_size_bits, 8);
446 max_packet_size = (
s->max_payload_size / aligned_samples_size) * aligned_samples_size;
447 if (!max_packet_size) {
449 aligned_samples_size);
453 if ((sample_size_bits % 8) == 0 && ((8 *
size) % sample_size_bits) != 0)
461 memcpy(
s->buf_ptr, buf1,
len);
465 s->timestamp =
s->cur_timestamp + n * 8 / sample_size_bits;
467 n += (
s->buf_ptr -
s->buf);
473 const uint8_t *buf1,
int size)
476 int len, count, max_packet_size;
478 max_packet_size =
s->max_payload_size;
481 len = (
s->buf_ptr -
s->buf);
482 if ((
len +
size) > max_packet_size) {
485 s->buf_ptr =
s->buf + 4;
488 if (
s->buf_ptr ==
s->buf + 4) {
489 s->timestamp =
s->cur_timestamp;
493 if (
size > max_packet_size - 4) {
497 len = max_packet_size - 4;
503 s->buf[2] = count >> 8;
505 memcpy(
s->buf + 4, buf1,
len);
512 if (
s->buf_ptr ==
s->buf + 4) {
519 memcpy(
s->buf_ptr, buf1,
size);
525 const uint8_t *buf1,
int size)
528 int len, max_packet_size;
530 max_packet_size =
s->max_payload_size;
533 len = max_packet_size;
537 s->timestamp =
s->cur_timestamp;
547 const uint8_t *buf1,
int size)
552 s->timestamp =
s->cur_timestamp;
554 len =
s->max_payload_size - (
s->buf_ptr -
s->buf);
557 memcpy(
s->buf_ptr, buf1,
len);
562 out_len =
s->buf_ptr -
s->buf;
563 if (out_len >=
s->max_payload_size) {
579 if (
s->num_frames > 0 &&
586 if (!
s->num_frames) {
588 s->timestamp =
s->cur_timestamp;
595 s->cur_timestamp += frame_duration;
597 if (
s->num_frames ==
s->max_frames_per_packet) {
620 s->last_octet_count =
s->octet_count;
623 s->cur_timestamp =
s->base_timestamp +
pkt->pts;
656 const uint8_t *aac_frame =
pkt->data;
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);
void avio_w8(AVIOContext *s, int b)
void avio_wb32(AVIOContext *s, unsigned int val)
void avio_wb16(AVIOContext *s, unsigned int val)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
#define flags(name, subs,...)
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
static const uint8_t frame_size[4]
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ 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...
@ AV_OPT_TYPE_UINT
Underlying C type is unsigned int.
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AV_CODEC_ID_MPEG2TS
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
@ AV_CODEC_ID_ADPCM_G726LE
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
@ 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...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
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.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
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.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
Macro definitions for various function/variable attributes.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Memory handling functions.
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.
#define RTCP_TX_RATIO_NUM
#define RTCP_TX_RATIO_DEN
static int is_supported(enum AVCodecID id)
static void rtp_send_mpegaudio(AVFormatContext *s1, const uint8_t *buf1, int size)
static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time, int bye)
static int rtp_send_samples(AVFormatContext *s1, const uint8_t *buf1, int size, int bits_per_sample)
static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
static void rtp_deinit(AVFormatContext *s1)
static int rtp_write_header(AVFormatContext *s1)
static const AVClass rtp_muxer_class
static void rtp_send_mpegts_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
static int rtp_write_trailer(AVFormatContext *s1)
void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
static void rtp_send_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
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)
void ff_rtp_send_vp8(AVFormatContext *s1, const uint8_t *buff, int size)
#define FF_RTP_FLAG_OPTS(ctx, fieldname)
void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
Packetize H.263 frames into RTP packets according to RFC 4629.
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)
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
#define FF_RTP_FLAG_MP4A_LATM
void ff_rtp_send_av1(AVFormatContext *s1, const uint8_t *buf1, int size, int is_keyframe)
#define FF_RTP_FLAG_SEND_BYE
#define FF_RTP_FLAG_RFC2190
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.
void ff_rtp_send_h261(AVFormatContext *s1, const uint8_t *buf1, int size)
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.
#define FF_RTP_FLAG_SKIP_RTCP
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)
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
int extradata_size
Size of the extradata content in bytes.
enum AVFieldOrder field_order
The order of the fields in interlaced video.
int height
The height of the video frame in pixels.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
AVChannelLayout ch_layout
The channel layout and number of channels.
int width
The width of the video frame in pixels.
enum AVMediaType codec_type
General type of the encoded data.
int block_align
The number of bytes per coded audio frame, required by some formats.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVIOContext * pb
I/O context.
int flags
Flags modifying the (de)muxer behaviour.
int strict_std_compliance
Allow non-standard and experimental extension.
int64_t start_time_realtime
Start time of the stream in real world time, in microseconds since the Unix epoch (00:00 1st January ...
void * priv_data
Format private data.
AVStream ** streams
A list of all streams in the file.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int id
Format-specific stream ID.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define OPUS_TIMESTAMP_RATE
The clock of Opus: packet lengths, pre-skip and trimming count samples at 48 kHz whatever the sample ...