38#define MIN_FEEDBACK_INTERVAL 200000
53 .enc_name =
"X-MP3-draft-00",
145 uintptr_t
i = (uintptr_t)*opaque;
149 *opaque = (
void*)(
i + 1);
174 if (
handler->static_payload_id &&
handler->static_payload_id ==
id &&
190 if (payload_len < 28) {
196 s->last_sr.ntp_timestamp =
AV_RB64(buf + 8);
197 s->last_sr.rtp_timestamp =
AV_RB32(buf + 16);
198 s->last_sr.sender_nb_packets =
AV_RB32(buf + 20);
199 s->last_sr.sender_nb_bytes =
AV_RB32(buf + 24);
205 s->first_rtcp_ntp_time =
s->last_sr.ntp_timestamp;
206 if (!
s->base_timestamp)
207 s->base_timestamp =
s->last_sr.rtp_timestamp;
208 s->rtcp_ts_offset = (
int32_t)(
s->last_sr.rtp_timestamp -
s->base_timestamp);
222#define RTP_SEQ_MOD (1 << 16)
227 s->max_seq = base_sequence;
239 s->base_seq = seq - 1;
242 s->expected_prior = 0;
243 s->received_prior = 0;
251 uint16_t udelta = seq -
s->max_seq;
252 const int MAX_DROPOUT = 3000;
253 const int MAX_MISORDER = 100;
254 const int MIN_SEQUENTIAL = 2;
259 if (seq ==
s->max_seq + 1) {
262 if (
s->probation == 0) {
268 s->probation = MIN_SEQUENTIAL - 1;
271 }
else if (udelta < MAX_DROPOUT) {
273 if (seq < s->max_seq) {
280 if (seq ==
s->bad_seq) {
296 uint32_t arrival_timestamp)
299 uint32_t transit = arrival_timestamp - sent_timestamp;
300 uint32_t prev_transit =
s->transit;
301 int32_t d = transit - prev_transit;
307 s->transit = transit;
310 s->jitter += d - (
int32_t) ((
s->jitter + 8) >> 4);
322 uint32_t extended_max;
323 uint32_t expected_interval;
324 uint32_t received_interval;
329 if ((!fd && !avio) || (count < 1))
334 s->octet_count += count;
340 s->last_octet_count =
s->octet_count;
356 extended_max =
stats->cycles +
stats->max_seq;
357 expected = extended_max -
stats->base_seq;
359 expected_interval = expected -
stats->expected_prior;
360 stats->expected_prior = expected;
361 received_interval =
stats->received -
stats->received_prior;
363 lost_interval = expected_interval - received_interval;
364 if (expected_interval == 0 || lost_interval <= 0)
367 fraction = (lost_interval << 8) / expected_interval;
369 fraction = (fraction << 24) | lost;
379 uint32_t middle_32_bits =
s->last_sr.ntp_timestamp >> 16;
390 len = strlen(
s->hostname);
405 if ((
len > 0) && buf) {
422 bytestream_put_byte(&ptr, 0);
423 bytestream_put_be16(&ptr, 0);
424 bytestream_put_be32(&ptr, 0);
425 bytestream_put_be32(&ptr, 0);
432 bytestream_put_byte(&ptr,
RTCP_RR);
433 bytestream_put_be16(&ptr, 1);
434 bytestream_put_be32(&ptr, 0);
440 uint16_t *missing_mask)
443 uint16_t next_seq =
s->seq + 1;
446 if (!
pkt ||
pkt->seq == next_seq)
450 for (
i = 1;
i <= 16;
i++) {
451 uint16_t missing_seq = next_seq +
i;
453 int16_t
diff =
pkt->seq - missing_seq;
460 if (
pkt->seq == missing_seq)
462 *missing_mask |= 1 << (
i - 1);
465 *first_missing = next_seq;
472 int len, need_keyframe, missing_packets;
476 uint16_t first_missing = 0, missing_mask = 0;
481 need_keyframe =
s->handler &&
s->handler->need_keyframe &&
482 s->handler->need_keyframe(
s->dynamic_protocol_context);
485 if (!need_keyframe && !missing_packets)
492 if (
s->last_feedback_time &&
495 s->last_feedback_time = now;
511 if (missing_packets) {
526 if (
len > 0 && buf) {
538 int payload_type,
int queue_size)
545 s->payload_type = payload_type;
550 s->queue_size = queue_size;
576 gethostname(
s->hostname,
sizeof(
s->hostname));
583 s->dynamic_protocol_context =
ctx;
606 delta_timestamp = (
int32_t)(timestamp -
s->last_sr.rtp_timestamp);
609 prft->
wallclock = rtcp_time + delta_time;
655 delta_timestamp = (
int32_t)(timestamp -
s->last_sr.rtp_timestamp);
657 addend =
av_rescale(
s->last_sr.ntp_timestamp -
s->first_rtcp_ntp_time,
658 s->st->time_base.den,
659 (uint64_t)
s->st->time_base.num << 32);
660 pkt->pts =
s->range_start_offset +
s->rtcp_ts_offset + addend +
665 if (!
s->base_timestamp)
666 s->base_timestamp = timestamp;
670 s->unwrapped_timestamp += timestamp;
672 s->unwrapped_timestamp += (
int32_t)(timestamp -
s->timestamp);
673 s->timestamp = timestamp;
674 pkt->pts =
s->unwrapped_timestamp +
s->range_start_offset -
679 const uint8_t *buf,
int len)
682 int payload_type, seq,
flags = 0;
688 csrc = buf[0] & 0x0f;
690 payload_type = buf[1] & 0x7f;
700 if (
s->payload_type != payload_type)
707 "RTP: PT=%02x: bad cseq %04x expected=%04x\n",
708 payload_type, seq, ((
s->seq + 1) & 0xffff));
713 int padding = buf[
len - 1];
714 if (
len >= 12 + padding)
733 ext = (
AV_RB16(buf + 2) + 1) << 2;
742 if (
s->handler &&
s->handler->parse_packet) {
743 rv =
s->handler->parse_packet(
s->ic,
s->dynamic_protocol_context,
744 s->st,
pkt, ×tamp, buf,
len, seq,
749 memcpy(
pkt->data, buf,
len);
776 uint16_t seq =
AV_RB16(buf + 2);
781 int16_t
diff = seq - (*cur)->seq;
803 return s->queue &&
s->queue->seq == (uint16_t) (
s->seq + 1);
808 return s->queue ?
s->queue->recvtime : 0;
816 if (
s->queue_len <= 0)
820 int pkt_missed =
s->queue->seq -
s->seq - 1;
823 pkt_missed += UINT16_MAX;
825 "RTP: missed %d packets\n", pkt_missed);
830 next =
s->queue->next;
839 uint8_t **bufptr,
int len)
841 uint8_t *buf = bufptr ? *bufptr :
NULL;
850 if (
s->prev_ret <= 0)
853 if (
s->handler &&
s->handler->parse_packet) {
857 rv =
s->handler->parse_packet(
s->ic,
s->dynamic_protocol_context,
884 if ((
s->seq == 0 && !
s->queue) ||
s->queue_size <= 1) {
888 uint16_t seq =
AV_RB16(buf + 2);
889 int16_t
diff = seq -
s->seq;
893 "RTP: dropping old packet received too late\n");
895 }
else if (
diff <= 1) {
907 if (
s->queue_len >=
s->queue_size) {
926 uint8_t **bufptr,
int len)
950 const char *attr,
const char *
value))
955 int value_size = strlen(p) + 1;
963 while (*p && *p ==
' ')
965 while (*p && *p !=
' ')
967 while (*p && *p ==
' ')
972 value, value_size)) {
989 pkt->stream_index = stream_idx;
SwsAArch64OpImplParams params
static AVFormatContext * ctx
void avio_w8(AVIOContext *s, int b)
void avio_wb32(AVIOContext *s, unsigned int val)
void avio_wb16(AVIOContext *s, unsigned int val)
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static CheckasmStats stats
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
@ AV_CODEC_ID_GSM
as in Berlin toast format
@ AV_CODEC_ID_TEXT
raw UTF-8 text
@ AV_PKT_DATA_PRFT
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
@ AV_PKT_DATA_RTCP_SR
Contains the last received RTCP SR (Sender Report) information in the form of the AVRTCPSenderReport ...
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
Initialize a reference-counted packet from av_malloc()ed data.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE
Internal time base represented as integer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static void handler(vbi_event *ev, void *user_data)
Memory handling functions.
enum AVMediaType codec_type
#define RTP_PT_IS_RTCP(x)
#define RTCP_TX_RATIO_NUM
#define RTCP_TX_RATIO_DEN
static int find_missing_packets(RTPDemuxContext *s, uint16_t *first_missing, uint16_t *missing_mask)
static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
int ff_parse_fmtp(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *p, int(*parse_fmtp)(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *attr, const char *value))
const RTPDynamicProtocolHandler ff_rdt_live_audio_handler
RTPDemuxContext * ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, int payload_type, int queue_size)
open a new RTP parse context for stream 'st'.
void ff_rtp_parse_close(RTPDemuxContext *s)
static const RTPDynamicProtocolHandler gsm_dynamic_handler
static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len)
void ff_rtp_send_punch_packets(URLContext *rtp_handle)
Send a dummy packet on both port pairs to set up the connection state in potential NAT routers,...
static const RTPDynamicProtocolHandler *const rtp_dynamic_protocol_handler_list[]
void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite, const char *params)
const RTPDynamicProtocolHandler * ff_rtp_handler_find_by_id(int id, enum AVMediaType codec_type)
Find a registered rtp dynamic protocol handler with a matching codec ID.
static const RTPDynamicProtocolHandler * rtp_handler_iterate(void **opaque)
Iterate over all registered rtp dynamic protocol handlers.
const RTPDynamicProtocolHandler ff_rdt_audio_handler
static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt, uint8_t **bufptr, int len)
static const RTPDynamicProtocolHandler l24_dynamic_handler
static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp, uint32_t arrival_timestamp)
int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, AVIOContext *avio, int count)
some rtp servers assume client is dead if they don't hear from them... so we send a Receiver Report t...
void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, const RTPDynamicProtocolHandler *handler)
static int has_next_packet(RTPDemuxContext *s)
static int enqueue_packet(RTPDemuxContext *s, uint8_t *buf, int len)
void ff_rtp_reset_packet_queue(RTPDemuxContext *s)
int ff_rtp_send_rtcp_feedback(RTPDemuxContext *s, URLContext *fd, AVIOContext *avio)
const RTPDynamicProtocolHandler ff_rdt_live_video_handler
static void rtp_init_sequence(RTPStatistics *s, uint16_t seq)
const RTPDynamicProtocolHandler ff_rdt_video_handler
int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, uint8_t **bufptr, int len)
Parse an RTP or RTCP packet directly sent as a buffer.
static const RTPDynamicProtocolHandler t140_dynamic_handler
int64_t ff_rtp_queued_packet_time(RTPDemuxContext *s)
static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
This was the second switch in rtp_parse packet.
static const RTPDynamicProtocolHandler speex_dynamic_handler
static int rtp_add_sr_sidedata(RTPDemuxContext *s, AVPacket *pkt)
static void rtp_init_statistics(RTPStatistics *s, uint16_t base_sequence)
static int rtp_parse_queued_packet(RTPDemuxContext *s, AVPacket *pkt)
static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq)
const RTPDynamicProtocolHandler * ff_rtp_handler_find_by_name(const char *name, enum AVMediaType codec_type)
Find a registered rtp dynamic protocol handler with the specified name.
static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt, const uint8_t *buf, int len)
int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx)
Close the dynamic buffer and make a packet from it.
#define MIN_FEEDBACK_INTERVAL
static const RTPDynamicProtocolHandler realmedia_mp3_dynamic_handler
int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size)
#define RTP_MIN_PACKET_LENGTH
#define RTP_FLAG_MARKER
RTP marker bit was set for this packet.
const RTPDynamicProtocolHandler ff_ac3_dynamic_handler
const RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler
const RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler
const RTPDynamicProtocolHandler ff_av1_dynamic_handler
const RTPDynamicProtocolHandler ff_dv_dynamic_handler
static int parse_fmtp(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *attr, const char *value)
int ff_srtp_set_crypto(struct SRTPContext *s, const char *suite, const char *params)
int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr)
void ff_srtp_free(struct SRTPContext *s)
int nb_channels
Number of channels in this layout.
This struct describes the properties of an encoded stream.
int bits_per_coded_sample
The number of bits per sample in the codedwords.
AVChannelLayout ch_layout
The channel layout and number of channels.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
int block_align
The number of bytes per coded audio frame, required by some formats.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
This structure stores compressed data.
This structure supplies correlation between a packet timestamp and a wall clock production time.
int64_t wallclock
A UTC timestamp, in microseconds, since Unix epoch (e.g, av_gettime()).
RTCP SR (Sender Report) information.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
int index
stream index in AVFormatContext
RTP/AV1 specific private data.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
unbuffered private I/O API
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)