Go to the documentation of this file.
37 #define MIN_FEEDBACK_INTERVAL 200000
149 uintptr_t
i = (uintptr_t)*opaque;
153 *opaque = (
void*)(
i + 1);
178 if (
handler->static_payload_id &&
handler->static_payload_id ==
id &&
194 if (payload_len < 20) {
200 s->last_rtcp_ntp_time =
AV_RB64(buf + 8);
201 s->last_rtcp_timestamp =
AV_RB32(buf + 16);
203 s->first_rtcp_ntp_time =
s->last_rtcp_ntp_time;
204 if (!
s->base_timestamp)
205 s->base_timestamp =
s->last_rtcp_timestamp;
206 s->rtcp_ts_offset = (
int32_t)(
s->last_rtcp_timestamp -
s->base_timestamp);
220 #define RTP_SEQ_MOD (1 << 16)
225 s->max_seq = base_sequence;
237 s->base_seq = seq - 1;
240 s->expected_prior = 0;
241 s->received_prior = 0;
249 uint16_t udelta = seq -
s->max_seq;
250 const int MAX_DROPOUT = 3000;
251 const int MAX_MISORDER = 100;
252 const int MIN_SEQUENTIAL = 2;
257 if (seq ==
s->max_seq + 1) {
260 if (
s->probation == 0) {
266 s->probation = MIN_SEQUENTIAL - 1;
269 }
else if (udelta < MAX_DROPOUT) {
271 if (seq < s->max_seq) {
278 if (seq ==
s->bad_seq) {
294 uint32_t arrival_timestamp)
297 uint32_t transit = arrival_timestamp - sent_timestamp;
298 uint32_t prev_transit =
s->transit;
305 s->transit = transit;
308 s->jitter +=
d - (
int32_t) ((
s->jitter + 8) >> 4);
320 uint32_t extended_max;
321 uint32_t expected_interval;
322 uint32_t received_interval;
327 if ((!fd && !avio) || (count < 1))
332 s->octet_count += count;
338 s->last_octet_count =
s->octet_count;
354 extended_max =
stats->cycles +
stats->max_seq;
355 expected = extended_max -
stats->base_seq;
356 lost = expected -
stats->received;
357 lost =
FFMIN(lost, 0xffffff);
358 expected_interval = expected -
stats->expected_prior;
359 stats->expected_prior = expected;
360 received_interval =
stats->received -
stats->received_prior;
362 lost_interval = expected_interval - received_interval;
363 if (expected_interval == 0 || lost_interval <= 0)
366 fraction = (lost_interval << 8) / expected_interval;
368 fraction = (fraction << 24) | lost;
378 uint32_t middle_32_bits =
s->last_rtcp_ntp_time >> 16;
389 len = strlen(
s->hostname);
404 if ((
len > 0) && buf) {
421 bytestream_put_byte(&ptr, 0);
422 bytestream_put_be16(&ptr, 0);
423 bytestream_put_be32(&ptr, 0);
424 bytestream_put_be32(&ptr, 0);
431 bytestream_put_byte(&ptr,
RTCP_RR);
432 bytestream_put_be16(&ptr, 1);
433 bytestream_put_be32(&ptr, 0);
439 uint16_t *missing_mask)
442 uint16_t next_seq =
s->seq + 1;
445 if (!
pkt ||
pkt->seq == next_seq)
449 for (
i = 1;
i <= 16;
i++) {
450 uint16_t missing_seq = next_seq +
i;
452 int16_t
diff =
pkt->seq - missing_seq;
459 if (
pkt->seq == missing_seq)
461 *missing_mask |= 1 << (
i - 1);
464 *first_missing = next_seq;
471 int len, need_keyframe, missing_packets;
475 uint16_t first_missing = 0, missing_mask = 0;
480 need_keyframe =
s->handler &&
s->handler->need_keyframe &&
481 s->handler->need_keyframe(
s->dynamic_protocol_context);
484 if (!need_keyframe && !missing_packets)
491 if (
s->last_feedback_time &&
494 s->last_feedback_time = now;
510 if (missing_packets) {
525 if (
len > 0 && buf) {
554 bytestream_put_byte (&bs, 0x1);
558 bytestream_put_le16 (&bs, 0);
560 bytestream_put_le32 (&bs, 48000);
562 bytestream_put_le16 (&bs, 0x0);
564 bytestream_put_byte (&bs, 0x0);
574 int payload_type,
int queue_size)
582 s->payload_type = payload_type;
587 s->queue_size = queue_size;
605 "Error creating opus extradata: %s\n",
616 gethostname(
s->hostname,
sizeof(
s->hostname));
623 s->dynamic_protocol_context =
ctx;
635 int64_t rtcp_time, delta_timestamp, delta_time;
644 delta_timestamp = (int64_t)timestamp - (int64_t)
s->last_rtcp_timestamp;
647 prft->
wallclock = rtcp_time + delta_time;
674 delta_timestamp = timestamp -
s->last_rtcp_timestamp;
676 addend =
av_rescale(
s->last_rtcp_ntp_time -
s->first_rtcp_ntp_time,
677 s->st->time_base.den,
678 (uint64_t)
s->st->time_base.num << 32);
679 pkt->
pts =
s->range_start_offset +
s->rtcp_ts_offset + addend +
684 if (!
s->base_timestamp)
685 s->base_timestamp = timestamp;
689 s->unwrapped_timestamp += timestamp;
691 s->unwrapped_timestamp += (
int32_t)(timestamp -
s->timestamp);
692 s->timestamp = timestamp;
693 pkt->
pts =
s->unwrapped_timestamp +
s->range_start_offset -
698 const uint8_t *buf,
int len)
701 int payload_type, seq,
flags = 0;
707 csrc = buf[0] & 0x0f;
709 payload_type = buf[1] & 0x7f;
719 if (
s->payload_type != payload_type)
726 "RTP: PT=%02x: bad cseq %04x expected=%04x\n",
727 payload_type, seq, ((
s->seq + 1) & 0xffff));
732 int padding = buf[
len - 1];
733 if (
len >= 12 + padding)
752 ext = (
AV_RB16(buf + 2) + 1) << 2;
761 if (
s->handler &&
s->handler->parse_packet) {
762 rv =
s->handler->parse_packet(
s->ic,
s->dynamic_protocol_context,
763 s->st,
pkt, ×tamp, buf,
len, seq,
795 uint16_t seq =
AV_RB16(buf + 2);
800 int16_t
diff = seq - (*cur)->seq;
822 return s->queue &&
s->queue->seq == (uint16_t) (
s->seq + 1);
827 return s->queue ?
s->queue->recvtime : 0;
835 if (
s->queue_len <= 0)
839 int pkt_missed =
s->queue->seq -
s->seq - 1;
842 pkt_missed += UINT16_MAX;
844 "RTP: missed %d packets\n", pkt_missed);
849 next =
s->queue->next;
858 uint8_t **bufptr,
int len)
860 uint8_t *buf = bufptr ? *bufptr :
NULL;
869 if (
s->prev_ret <= 0)
872 if (
s->handler &&
s->handler->parse_packet) {
876 rv =
s->handler->parse_packet(
s->ic,
s->dynamic_protocol_context,
903 if ((
s->seq == 0 && !
s->queue) ||
s->queue_size <= 1) {
907 uint16_t seq =
AV_RB16(buf + 2);
908 int16_t
diff = seq -
s->seq;
912 "RTP: dropping old packet received too late\n");
914 }
else if (
diff <= 1) {
926 if (
s->queue_len >=
s->queue_size) {
945 uint8_t **bufptr,
int len)
969 const char *attr,
const char *
value))
974 int value_size = strlen(p) + 1;
982 while (*p && *p ==
' ')
984 while (*p && *p !=
' ')
986 while (*p && *p ==
' ')
991 value, value_size)) {
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
#define AV_LOG_WARNING
Something somehow does not look correct.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
static const RTPDynamicProtocolHandler *const rtp_dynamic_protocol_handler_list[]
const RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int ff_rtp_send_rtcp_feedback(RTPDemuxContext *s, URLContext *fd, AVIOContext *avio)
This struct describes the properties of an encoded stream.
static void stats(AVPacket *const *in, int n_in, unsigned *_max, unsigned *_sum)
static int parse_fmtp(AVFormatContext *s, AVStream *stream, PayloadContext *data, const char *attr, const char *value)
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))
static int enqueue_packet(RTPDemuxContext *s, uint8_t *buf, int len)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
static const RTPDynamicProtocolHandler l24_dynamic_handler
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
int64_t wallclock
A UTC timestamp, in microseconds, since Unix epoch (e.g, av_gettime()).
#define RTP_FLAG_MARKER
RTP marker bit was set for this packet.
#define AV_LOG_VERBOSE
Detailed information.
int nb_channels
Number of channels in this layout.
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...
enum AVMediaType codec_type
int ff_rtp_finalize_packet(AVPacket *pkt, AVIOContext **dyn_buf, int stream_idx)
Close the dynamic buffer and make a packet from it.
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,...
int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr)
void ff_rtp_parse_set_crypto(RTPDemuxContext *s, const char *suite, const char *params)
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const RTPDynamicProtocolHandler gsm_dynamic_handler
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
static const RTPDynamicProtocolHandler t140_dynamic_handler
#define RTCP_TX_RATIO_NUM
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
const RTPDynamicProtocolHandler ff_rdt_live_video_handler
static int opus_write_extradata(AVCodecParameters *codecpar)
#define RTCP_TX_RATIO_DEN
static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
This was the second switch in rtp_parse packet.
const RTPDynamicProtocolHandler ff_dv_dynamic_handler
static void rtp_init_statistics(RTPStatistics *s, uint16_t base_sequence)
static int has_next_packet(RTPDemuxContext *s)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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.
@ AV_PKT_DATA_PRFT
Producer Reference Time data corresponding to the AVProducerReferenceTime struct, usually exported by...
static void handler(vbi_event *ev, void *user_data)
static int rtp_set_prft(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define MIN_FEEDBACK_INTERVAL
and forward the result(frame or status change) to the corresponding input. If nothing is possible
static int find_missing_packets(RTPDemuxContext *s, uint16_t *first_missing, uint16_t *missing_mask)
int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int64_t ff_rtp_queued_packet_time(RTPDemuxContext *s)
void avio_w8(AVIOContext *s, int b)
This structure supplies correlation between a packet timestamp and a wall clock production time.
AVChannelLayout ch_layout
Audio only.
const RTPDynamicProtocolHandler ff_rdt_audio_handler
#define RTP_MIN_PACKET_LENGTH
int sample_rate
Audio only.
@ AV_CODEC_ID_GSM
as in Berlin toast format
const RTPDynamicProtocolHandler ff_rdt_video_handler
FFmpeg currently uses a custom build this text attempts to document some of its obscure features and options Makefile the full command issued by make and its output will be shown on the screen DBG Preprocess x86 external assembler files to a dbg asm file in the object which then gets compiled Helps in developing those assembler files DESTDIR Destination directory for the install useful to prepare packages or install FFmpeg in cross environments GEN Set to ‘1’ to generate the missing or mismatched references Makefile builds all the libraries and the executables fate Run the fate test suite
void ff_rtp_parse_close(RTPDemuxContext *s)
#define RTP_PT_IS_RTCP(x)
static const RTPDynamicProtocolHandler realmedia_mp3_dynamic_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'.
int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size)
Initialize a reference-counted packet from av_malloc()ed data.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_NOPTS_VALUE
Undefined timestamp value.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
const RTPDynamicProtocolHandler ff_ac3_dynamic_handler
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
void avio_wb32(AVIOContext *s, unsigned int val)
void ff_srtp_free(struct SRTPContext *s)
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 const RTPDynamicProtocolHandler speex_dynamic_handler
static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt, const uint8_t *buf, int len)
static const RTPDynamicProtocolHandler * rtp_handler_iterate(void **opaque)
Iterate over all registered rtp dynamic protocol handlers.
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len)
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_TIME_BASE
Internal time base represented as integer.
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.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int ff_srtp_set_crypto(struct SRTPContext *s, const char *suite, const char *params)
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
static const RTPDynamicProtocolHandler opus_dynamic_handler
const RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler
@ AV_CODEC_ID_TEXT
raw UTF-8 text
int index
stream index in AVFormatContext
static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt, uint8_t **bufptr, int len)
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, size_t size)
Allocate new information of a packet.
static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp, uint32_t arrival_timestamp)
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
const RTPDynamicProtocolHandler ff_rdt_live_audio_handler
static void rtp_init_sequence(RTPStatistics *s, uint16_t seq)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, const RTPDynamicProtocolHandler *handler)
This structure stores compressed data.
void ff_rtp_reset_packet_queue(RTPDemuxContext *s)
void avio_wb16(AVIOContext *s, unsigned int val)
#define flags(name, subs,...)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
RTP/JPEG specific private data.
static int rtp_parse_queued_packet(RTPDemuxContext *s, AVPacket *pkt)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16