44 .class_name =
"RTP muxer",
50#define RTCP_SR_SIZE 28
117 if (
s->payload_type < 0) {
122 s->payload_type = st->
id;
125 st->
id =
s->payload_type;
129 s->timestamp =
s->base_timestamp;
130 s->cur_timestamp = 0;
175 s->buf_ptr =
s->buf + 4;
184 "RTP payload size %u too small for MPEG-TS "
185 "(minimum %d bytes required)\n",
197 "Packetizing VC-2 is experimental and does not use all values "
198 "of the specification "
199 "(even though most receivers may handle it just fine). "
200 "Please set -strict experimental in order to enable it.\n");
208 "Packetizing H.261 is experimental and produces incorrect "
209 "packetization for cases where GOBs don't fit into packets "
210 "(even though most receivers may handle it just fine). "
211 "Please set -f_strict experimental in order to enable it.\n");
248 "Packetizing VP9 is experimental and its specification is "
249 "still in draft state. "
250 "Please set -strict experimental in order to enable it.\n");
258 "Packetizing AV1 is experimental and its specification is "
259 "still in draft state. "
260 "Please set -strict experimental in order to enable it.\n");
267 s->max_frames_per_packet = 15;
293 s->max_frames_per_packet = 50;
299 if (1 +
s->max_frames_per_packet + n >
s->max_payload_size) {
309 s->max_frames_per_packet = 50;
328 av_log(s1,
AV_LOG_TRACE,
"RTCP: %02x %"PRIx64
" %"PRIx32
"\n",
s->payload_type, ntp_time,
s->timestamp);
330 s->last_rtcp_ntp_time = ntp_time;
338 avio_wb32(s1->
pb, ((ntp_time % 1000000) << 32) / 1000000);
378 avio_w8(s1->
pb, (
s->payload_type & 0x7f) | ((m & 0x01) << 7));
386 s->seq = (
s->seq + 1) & 0xffff;
389 s->octet_count +=
len;
396 const uint8_t *buf1,
int size,
int sample_size_bits)
399 int len, max_packet_size, n;
401 int aligned_samples_size = sample_size_bits/
av_gcd(sample_size_bits, 8);
403 max_packet_size = (
s->max_payload_size / aligned_samples_size) * aligned_samples_size;
405 if ((sample_size_bits % 8) == 0 && ((8 *
size) % sample_size_bits) != 0)
413 memcpy(
s->buf_ptr, buf1,
len);
417 s->timestamp =
s->cur_timestamp + n * 8 / sample_size_bits;
419 n += (
s->buf_ptr -
s->buf);
425 const uint8_t *buf1,
int size)
428 int len, count, max_packet_size;
430 max_packet_size =
s->max_payload_size;
433 len = (
s->buf_ptr -
s->buf);
434 if ((
len +
size) > max_packet_size) {
437 s->buf_ptr =
s->buf + 4;
440 if (
s->buf_ptr ==
s->buf + 4) {
441 s->timestamp =
s->cur_timestamp;
445 if (
size > max_packet_size) {
449 len = max_packet_size - 4;
455 s->buf[2] = count >> 8;
457 memcpy(
s->buf + 4, buf1,
len);
464 if (
s->buf_ptr ==
s->buf + 4) {
471 memcpy(
s->buf_ptr, buf1,
size);
477 const uint8_t *buf1,
int size)
480 int len, max_packet_size;
482 max_packet_size =
s->max_payload_size;
485 len = max_packet_size;
489 s->timestamp =
s->cur_timestamp;
499 const uint8_t *buf1,
int size)
504 s->timestamp =
s->cur_timestamp;
506 len =
s->max_payload_size - (
s->buf_ptr -
s->buf);
509 memcpy(
s->buf_ptr, buf1,
len);
514 out_len =
s->buf_ptr -
s->buf;
515 if (out_len >=
s->max_payload_size) {
531 if (
s->num_frames > 0 &&
538 if (!
s->num_frames) {
540 s->timestamp =
s->cur_timestamp;
547 s->cur_timestamp += frame_duration;
549 if (
s->num_frames ==
s->max_frames_per_packet) {
572 s->last_octet_count =
s->octet_count;
575 s->cur_timestamp =
s->base_timestamp +
pkt->pts;
609 const uint8_t *aac_frame =
pkt->data;
687 if (
size >
s->max_payload_size) {
689 "Packet size %d too large for max RTP payload size %d\n",
690 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_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_send_samples(AVFormatContext *s1, const uint8_t *buf1, int size, int sample_size_bits)
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.