MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / rtp_write_header

Function rtp_write_header

libavformat/rtpenc.c:99–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99static int rtp_write_header(AVFormatContext *s1)
100{
101 RTPMuxContext *s = s1->priv_data;
102 int n, ret = AVERROR(EINVAL);
103 AVStream *st;
104
105 if (s1->nb_streams != 1) {
106 av_log(s1, AV_LOG_ERROR, "Only one stream supported in the RTP muxer\n");
107 return AVERROR(EINVAL);
108 }
109 st = s1->streams[0];
110 if (!is_supported(st->codecpar->codec_id)) {
111 av_log(s1, AV_LOG_ERROR, "Unsupported codec %s\n", avcodec_get_name(st->codecpar->codec_id));
112
113 return -1;
114 }
115
116 if (s->payload_type < 0) {
117 /* Re-validate non-dynamic payload types */
118 if (st->id < RTP_PT_PRIVATE)
119 st->id = ff_rtp_get_payload_type(s1, st->codecpar, -1);
120
121 s->payload_type = st->id;
122 } else {
123 /* private option takes priority */
124 st->id = s->payload_type;
125 }
126
127 s->base_timestamp = av_get_random_seed();
128 s->timestamp = s->base_timestamp;
129 s->cur_timestamp = 0;
130 if (!s->ssrc)
131 s->ssrc = av_get_random_seed();
132 s->first_packet = 1;
133 s->first_rtcp_ntp_time = ff_ntp_time();
134 if (s1->start_time_realtime != 0 && s1->start_time_realtime != AV_NOPTS_VALUE)
135 /* Round the NTP time to whole milliseconds. */
136 s->first_rtcp_ntp_time = (s1->start_time_realtime / 1000) * 1000 +
137 NTP_OFFSET_US;
138 // Pick a random sequence start number, but in the lower end of the
139 // available range, so that any wraparound doesn't happen immediately.
140 // (Immediate wraparound would be an issue for SRTP.)
141 if (s->seq < 0) {
142 if (s1->flags & AVFMT_FLAG_BITEXACT) {
143 s->seq = 0;
144 } else
145 s->seq = av_get_random_seed() & 0x0fff;
146 } else
147 s->seq &= 0xffff; // Use the given parameter, wrapped to the right interval
148
149 if (s1->packet_size) {
150 if (s1->pb->max_packet_size)
151 s1->packet_size = FFMIN(s1->packet_size,
152 s1->pb->max_packet_size);
153 } else
154 s1->packet_size = s1->pb->max_packet_size;
155 if (s1->packet_size <= 12) {
156 av_log(s1, AV_LOG_ERROR, "Max packet size %u too low\n", s1->packet_size);

Callers

nothing calls this directly

Calls 9

av_logFunction · 0.85
is_supportedFunction · 0.85
avcodec_get_nameFunction · 0.85
ff_rtp_get_payload_typeFunction · 0.85
av_get_random_seedFunction · 0.85
ff_ntp_timeFunction · 0.85
avpriv_set_pts_infoFunction · 0.85
av_freepFunction · 0.85
av_mallocFunction · 0.50

Tested by

no test coverage detected