25 #include "libavutil/mathematics.h"
26 #include "libavutil/random_seed.h"
27 #include "libavutil/opt.h"
47 #define RTCP_SR_SIZE 28
148 if (s->
buf == NULL) {
159 if (frame_size == 0) {
176 switch(st->codec->codec_id) {
179 s->buf_ptr =
s->buf + 4;
193 if (st->codec->extradata_size > 4 && st->codec->extradata[0] == 1) {
194 s->nal_length_size = (st->codec->extradata[4] & 0x03) + 1;
199 if (!
s->max_frames_per_packet)
s->max_frames_per_packet = 15;
200 s->max_frames_per_packet = av_clip(
s->max_frames_per_packet, 1, 15);
201 s->max_payload_size -= 6;
210 if (st->codec->channels > 2) {
220 if (st->codec->block_align != 38 && st->codec->block_align != 50) {
224 if (!
s->max_frames_per_packet)
225 s->max_frames_per_packet = 1;
226 s->max_frames_per_packet =
FFMIN(
s->max_frames_per_packet,
227 s->max_payload_size / st->codec->block_align);
231 if (!
s->max_frames_per_packet)
232 s->max_frames_per_packet = 12;
238 if (1 +
s->max_frames_per_packet +
n >
s->max_payload_size) {
242 if (st->codec->channels != 1) {
274 s1->streams[0]->time_base) +
s->base_timestamp;
295 for (len = (7 + len) % 4; len % 4; len++)
308 av_dlog(s1,
"rtp_send_data size=%d\n", len);
320 s->
seq = (s->
seq + 1) & 0xffff;
328 const uint8_t *buf1,
int size,
int sample_size_bits)
331 int len, max_packet_size,
n;
333 int aligned_samples_size = sample_size_bits/
av_gcd(sample_size_bits, 8);
335 max_packet_size = (s->
max_payload_size / aligned_samples_size) * aligned_samples_size;
337 if ((sample_size_bits % 8) == 0 && ((8 *
size) % sample_size_bits) != 0)
342 len =
FFMIN(max_packet_size, size);
366 if ((len + size) > max_packet_size) {
377 if (size > max_packet_size) {
381 len = max_packet_size - 4;
387 s->
buf[2] = count >> 8;
389 memcpy(s->
buf + 4, buf1, len);
403 memcpy(s->
buf_ptr, buf1, size);
412 int len, max_packet_size;
417 len = max_packet_size;
436 while (size >= TS_PACKET_SIZE) {
468 memcpy(s->
buf_ptr, buf, n * frame_size);
549 int mb_info_size = 0;
576 "Packet size %d too large for max RTP payload size %d\n",
607 .priv_class = &rtp_muxer_class,
int64_t start_time_realtime
Start time of the stream in real world time, in microseconds since the unix epoch (00:00 1st January ...
#define LIBAVUTIL_VERSION_INT
static int rtp_send_samples(AVFormatContext *s1, const uint8_t *buf1, int size, int sample_size_bits)
static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
int64_t last_rtcp_ntp_time
AVCodecContext * codec
Codec context associated with this stream.
#define RTCP_TX_RATIO_NUM
unsigned int last_octet_count
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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.
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
An AV_PKT_DATA_H263_MB_INFO side data packet contains a number of structures with info about macroblo...
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
#define FF_RTP_FLAG_MP4A_LATM
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const AVClass rtp_muxer_class
int id
Format-specific stream ID.
int max_frames_per_packet
void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
Packetize H.263 frames into RTP packets according to RFC 4629.
static int rtp_write_header(AVFormatContext *s1)
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
const OptionDef options[]
#define FF_RTP_FLAG_RFC2190
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.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
static const uint8_t frame_size[4]
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
void * priv_data
Format private data.
void ff_rtp_send_jpeg(AVFormatContext *s1, const uint8_t *buff, int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
preferred ID for decoding MPEG audio layer 1, 2 or 3
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
void ff_rtp_send_latm(AVFormatContext *s1, const uint8_t *buff, int size)
void ff_rtp_send_vp8(AVFormatContext *s1, const uint8_t *buff, int size)
int64_t av_const av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
#define FF_RTP_FLAG_SKIP_RTCP
static void rtp_send_mpegts_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
unsigned int nb_streams
A list of all streams in the file.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding) av_const
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
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.
void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m)
uint8_t * av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int *size)
Get side information from packet.
static int write_trailer(AVFormatContext *s1)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int rtp_send_ilbc(AVFormatContext *s1, const uint8_t *buf, int size)
void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
static void rtp_send_mpegaudio(AVFormatContext *s1, const uint8_t *buf1, int size)
preferred ID for MPEG-1/2 video decoding
int frame_size
Number of samples per channel in an audio frame.
int64_t first_rtcp_ntp_time
AVOutputFormat ff_rtp_muxer
enum AVMediaType codec_type
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int sample_rate
samples per second
#define FF_RTP_FLAG_OPTS(ctx, fieldname)
static int is_supported(enum AVCodecID id)
AVIOContext * pb
I/O context.
Describe the class of an AVClass context structure.
rational number numerator/denominator
static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time)
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
#define NTP_TO_RTP_FORMAT(x)
void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size)
static void rtp_send_raw(AVFormatContext *s1, const uint8_t *buf1, int size)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
unsigned int packet_count
FAKE codec to indicate a raw MPEG-2 TS stream (only used by libavformat)
int channels
number of audio channels
static void write_header(FFV1Context *f)
static int rtp_write_trailer(AVFormatContext *s1)
void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf1, int size, const uint8_t *mb_info, int mb_info_size)
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
This structure stores compressed data.
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...