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

Function whip_write_packet

libavformat/whip.c:2039–2136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2037}
2038
2039static int whip_write_packet(AVFormatContext *s, AVPacket *pkt)
2040{
2041 int ret;
2042 WHIPContext *whip = s->priv_data;
2043 AVStream *st = s->streams[pkt->stream_index];
2044 AVFormatContext *rtp_ctx = st->priv_data;
2045 int64_t now = av_gettime_relative();
2046 /**
2047 * Refer to RFC 7675
2048 * Periodically send Consent Freshness STUN Binding Request
2049 */
2050 if (now - whip->whip_last_consent_tx_time > WHIP_ICE_CONSENT_CHECK_INTERVAL * WHIP_US_PER_MS) {
2051 int size;
2052 ret = ice_create_request(s, whip->buf, sizeof(whip->buf), &size);
2053 if (ret < 0) {
2054 av_log(whip, AV_LOG_ERROR, "Failed to create STUN binding request, size=%d\n", size);
2055 goto end;
2056 }
2057 ret = ffurl_write(whip->udp, whip->buf, size);
2058 if (ret < 0) {
2059 av_log(whip, AV_LOG_ERROR, "Failed to send STUN binding request, size=%d\n", size);
2060 goto end;
2061 }
2062 whip->whip_last_consent_tx_time = now;
2063 av_log(whip, AV_LOG_DEBUG, "Consent Freshness check sent\n");
2064 }
2065
2066 /**
2067 * Receive packets from the server such as ICE binding requests, DTLS messages,
2068 * and RTCP like PLI requests, then respond to them.
2069 */
2070 ret = ffurl_read(whip->udp, whip->buf, sizeof(whip->buf));
2071 if (ret < 0) {
2072 if (ret == AVERROR(EAGAIN))
2073 goto write_packet;
2074 av_log(whip, AV_LOG_ERROR, "Failed to read from UDP socket\n");
2075 goto end;
2076 }
2077 if (!ret) {
2078 av_log(whip, AV_LOG_ERROR, "Receive EOF from UDP socket\n");
2079 goto end;
2080 }
2081 if (ice_is_binding_response(whip->buf, ret)) {
2082 whip->whip_last_consent_rx_time = av_gettime_relative();
2083 av_log(whip, AV_LOG_DEBUG, "Consent Freshness check received\n");
2084 }
2085 if (is_dtls_packet(whip->buf, ret)) {
2086 if ((ret = ffurl_write(whip->dtls_uc, whip->buf, ret)) < 0) {
2087 av_log(whip, AV_LOG_ERROR, "Failed to handle DTLS message\n");
2088 goto end;
2089 }
2090 }
2091 if (media_is_rtcp(whip->buf, ret)) {
2092 uint8_t fmt = whip->buf[0] & 0x1f;
2093 uint8_t pt = whip->buf[1];
2094 /**
2095 * Handle RTCP NACK packet
2096 * Refer to RFC 4585 6.2.1

Callers

nothing calls this directly

Calls 11

av_gettime_relativeFunction · 0.85
ice_create_requestFunction · 0.85
av_logFunction · 0.85
ffurl_writeFunction · 0.85
ffurl_readFunction · 0.85
ice_is_binding_responseFunction · 0.85
is_dtls_packetFunction · 0.85
media_is_rtcpFunction · 0.85
handle_nack_rtxFunction · 0.85
ff_write_chainedFunction · 0.85

Tested by

no test coverage detected