diff options
author | Jack Lau <jacklau1222@qq.com> | 2025-05-16 20:15:05 +0800 |
---|---|---|
committer | Steven Liu <lq@chinaffmpeg.org> | 2025-06-04 11:17:07 +0800 |
commit | 167e343bbe75515a80db8ee72ffa0c607c944a00 (patch) | |
tree | b0810df5368369a80f749453e8ec0a26f2f70601 /libavformat/tls.c | |
parent | d4556c98f02e4f2d3deb86efeb060ebe4659be96 (diff) | |
download | ffmpeg-167e343bbe75515a80db8ee72ffa0c607c944a00.tar.gz |
avformat/whip: Add WHIP muxer support for subsecond latency streaming
0. WHIP Version 3.
1. The WHIP muxer has been renamed and refined,
with improved logging context and error messages for SSL, DTLS, and RTC.
2. Magic numbers have been replaced with macros and extracted to functions,
and log levels have been altered for better clarity.
3. DTLS curve list has been updated,
and SRTP profile names have been refined for FFmpeg and OpenSSL.
4. ICE STUN magic number has been refined,
and RTP payload types have been updated based on Chrome's definition.
5. Fixed frame size has been refined to rtc->audio_par->frame_size,
and h264_mp4toannexb is now used to convert MP4/ISOM to annexb.
6. OPUS timestamp issue has been addressed,
and marker setting has been corrected after utilizing BSF.
7. DTLS handshake and ICE handling have been optimized for improved performance,
with a single handshake timeout and server role to prevent ARQ.
8. Consolidated ICE request/response handling and DTLS handshake into a single function,
and fixed OpenSSL build errors to work with Pion.
9. Merge TLS & DTLS implementation, shared BIO callbacks, read, write,
print_ssl_error, openssl_init_ca_key_cert,
init_bio_method function and shared same data structure
10. Modify configure that whip is enabled only dtls is
enabled(just support openssl for now) to fix build error
Co-authored-by: winlin <winlinvip@gmail.com>
Co-authored-by: yangrtc <yangrtc@aliyun.com>
Co-authored-by: cloudwebrtc <duanweiwei1982@gmail.com>
Co-authored-by: Haibo Chen <495810242@qq.com>
Co-authored-by: Steven Liu <lq@chinaffmpeg.org>
Co-authored-by: Jun Zhao <barryjzhao@tencent.com>
Signed-off-by: Jack Lau <jacklau1222@qq.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
Diffstat (limited to 'libavformat/tls.c')
-rw-r--r-- | libavformat/tls.c | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/libavformat/tls.c b/libavformat/tls.c index f96ff6215d..da53835200 100644 --- a/libavformat/tls.c +++ b/libavformat/tls.c @@ -1,6 +1,7 @@ /* - * TLS/SSL Protocol + * TLS/DTLS/SSL Protocol * Copyright (c) 2011 Martin Storsjo + * Copyright (c) 2025 Jack Lau * * This file is part of FFmpeg. * @@ -20,6 +21,7 @@ */ #include "avformat.h" +#include "internal.h" #include "network.h" #include "os_support.h" #include "url.h" @@ -93,7 +95,7 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV c->listen = 1; } - ff_url_join(buf, sizeof(buf), "tcp", NULL, c->underlying_host, port, "%s", p); + ff_url_join(buf, sizeof(buf), c->is_dtls ? "udp" : "tcp", NULL, c->underlying_host, port, "%s", p); hints.ai_flags = AI_NUMERICHOST; if (!getaddrinfo(c->underlying_host, NULL, &hints, &ai)) { @@ -124,7 +126,65 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV } freeenv_utf8(env_http_proxy); - return ffurl_open_whitelist(&c->tcp, buf, AVIO_FLAG_READ_WRITE, - &parent->interrupt_callback, options, - parent->protocol_whitelist, parent->protocol_blacklist, parent); + if (c->is_dtls) { + av_dict_set_int(options, "connect", 1, 0); + av_dict_set_int(options, "fifo_size", 0, 0); + /* Set the max packet size to the buffer size. */ + av_dict_set_int(options, "pkt_size", c->mtu, 0); + } + ret = ffurl_open_whitelist(c->is_dtls ? &c->udp : &c->tcp, buf, AVIO_FLAG_READ_WRITE, + &parent->interrupt_callback, options, + parent->protocol_whitelist, parent->protocol_blacklist, parent); + if (c->is_dtls) { + if (ret < 0) { + av_log(c, AV_LOG_ERROR, "WHIP: Failed to connect udp://%s:%d\n", c->underlying_host, port); + return ret; + } + /* Make the socket non-blocking, set to READ and WRITE mode after connected */ + ff_socket_nonblock(ffurl_get_file_handle(c->udp), 1); + c->udp->flags |= AVIO_FLAG_READ | AVIO_FLAG_NONBLOCK; + } + return ret; +} + +/** + * Read all data from the given URL url and store it in the given buffer bp. + */ +int ff_url_read_all(const char *url, AVBPrint *bp) +{ + int ret = 0; + AVDictionary *opts = NULL; + URLContext *uc = NULL; + char buf[MAX_URL_SIZE]; + + ret = ffurl_open_whitelist(&uc, url, AVIO_FLAG_READ, NULL, &opts, NULL, NULL, NULL); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "TLS: Failed to open url %s\n", url); + goto end; + } + + while (1) { + ret = ffurl_read(uc, buf, sizeof(buf)); + if (ret == AVERROR_EOF) { + /* Reset the error because we read all response as answer util EOF. */ + ret = 0; + break; + } + if (ret <= 0) { + av_log(NULL, AV_LOG_ERROR, "TLS: Failed to read from url=%s, key is %s\n", url, bp->str); + goto end; + } + + av_bprintf(bp, "%.*s", ret, buf); + if (!av_bprint_is_complete(bp)) { + av_log(NULL, AV_LOG_ERROR, "TLS: Exceed max size %.*s, %s\n", ret, buf, bp->str); + ret = AVERROR(EIO); + goto end; + } + } + +end: + ffurl_closep(&uc); + av_dict_free(&opts); + return ret; } |