Skip to content

add NACK, RTX, DTLS active support #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: workflows
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1e0856e
avformat/whip: add whip_flags ignore_ipv6 to skip IPv6 ICE candidates
JackLau1222 Jun 28, 2025
02eec1e
avformat/whip: fix typos
JackLau1222 Jun 28, 2025
fbcb367
avformat/whip: fix H264 profile_iop bit map for SDP
JackLau1222 Jun 18, 2025
f63f38e
avformat/tls_openssl: fix X509 cert serial number might be negative
winlinvip Jun 10, 2025
b5fe81d
avformat/whip: correct rtcp fixed header size
JackLau1222 Jul 25, 2025
bee7823
avformat/whip: implement NACK and RTX suppport
JackLau1222 Jul 31, 2025
5261796
avformat/whip: add generate_unique_ssrc to avoid ssrc collision
JackLau1222 Jul 26, 2025
1c14d6d
avformat/whip: optimize the rtp history indexing performance
JackLau1222 Jul 31, 2025
5182db2
avformat/whip: reindent whip options
JackLau1222 Jul 2, 2025
c6b0b58
avformat/whip: add support for active dtls role
JackLau1222 Jul 17, 2025
840eb9b
avformat/whip: remove DTLSState enum
JackLau1222 Jul 21, 2025
6a2471d
avformat/whip: check the peer whether is ice lite
JackLau1222 Jul 21, 2025
af0617e
avformat/whip: remove WHIP_STATE_DTLS_CONNECTING
JackLau1222 Jul 21, 2025
f8b7751
avformat/whip: simplify and modularize the ICE and DTLS
JackLau1222 Jul 21, 2025
7eda183
avformat/tls: add new option use_srtp to control whether enable it
JackLau1222 Jul 22, 2025
0cc6e4b
avformat/tls_openssl: cleanup the pointer name of TLSContext and TLSS…
JackLau1222 Jul 22, 2025
d888695
doc: add doc for dtls and whip
JackLau1222 Jul 22, 2025
83d128f
avformat/whip: use av_gettime_relative() for better measure
JackLau1222 Jul 31, 2025
89bff41
avformat/tls_openssl: simplify the external_sock check
JackLau1222 Aug 4, 2025
7f3a5fe
avformat/tls_openssl: add check to avoid tls_shared is null
JackLau1222 Aug 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions doc/muxers.texi
Original file line number Diff line number Diff line change
Expand Up @@ -3915,16 +3915,37 @@ Default value is 5000.

@item pkt_size @var{integer}
Set the maximum size, in bytes, of RTP packets that send out.
Default value is 1500.
Default value is 1200.

@item authorization @var{string}
The optional Bearer token for WHIP Authorization.
Optional Bearer token for WHIP Authorization.

@item cert_file @var{string}
The optional certificate file path for DTLS.
Optional certificate file path for DTLS.

@item key_file @var{string}
The optional private key file path for DTLS.
Optional private key file path for DTLS.

@item whip_flags @var{flags}
Possible values:

@table @samp
@item ignore_ipv6
Ignore any IPv6 ICE candidates.

@item disable_rtx
Disable RFC 4588 RTX (Retransmission) support.
This disables the retransmission mechanism for lost RTP packets.

@item dtls_active
Set DTLS role as active (client role) instead of passive (server role).
By default, WHIP uses passive DTLS role, but some servers may require active role.
@end table

@item rtx_history_size @var{integer}
Set the packet history size for RTX (retransmission) support.
This determines how many recent RTP packets are kept in memory for potential
retransmission requests. Range is 64 to 2048, default is 256.

@end table

Expand Down
78 changes: 78 additions & 0 deletions doc/protocols.texi
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,84 @@ To play back a stream from the TLS/SSL server using @command{ffplay}:
ffplay tls://@var{hostname}:@var{port}
@end example

@section dtls

Datagram Transport Layer Security (DTLS)

The required syntax for a DTLS URL is:
@example
dtls://@var{hostname}:@var{port}
@end example

DTLS shares most options with TLS, but operates over UDP instead of TCP.
The following parameters can be set via command line options
(or in code via @code{AVOption}s):

@table @option

@item ca_file, cafile=@var{filename}
A file containing certificate authority (CA) root certificates to treat
as trusted. If the linked TLS library contains a default this might not
need to be specified for verification to work, but not all libraries and
setups have defaults built in.
The file must be in OpenSSL PEM format.

@item tls_verify=@var{1|0}
If enabled, try to verify the peer that we are communicating with.
Note, if using OpenSSL, this currently only makes sure that the
peer certificate is signed by one of the root certificates in the CA
database, but it does not validate that the certificate actually
matches the host name we are trying to connect to.

This is disabled by default since it requires a CA database to be
provided by the caller in many cases.

@item cert_file, cert=@var{filename}
A file containing a certificate to use in the handshake with the peer.
(When operating as server, in listen mode, this is more often required
by the peer, while client certificates only are mandated in certain
setups.)

@item key_file, key=@var{filename}
A file containing the private key for the certificate.

@item cert_pem=@var{string}
A PEM-encoded certificate string to use in the handshake with the peer.

@item key_pem=@var{string}
A PEM-encoded private key string for the certificate.

@item listen=@var{1|0}
If enabled, listen for connections on the provided port, and assume
the server role in the handshake instead of the client role.

@item mtu=@var{size}
Set the Maximum Transmission Unit (MTU) for DTLS packets.

@item use_srtp=@var{1|0}
Enable the use_srtp DTLS extension.
This is used in WebRTC applications to establish SRTP encryption keys
through the DTLS handshake. Default is disabled.

@item external_sock=@var{1|0}
Use an external socket instead of creating a new one. Default is disabled.

@end table

Example command lines:

To create a DTLS server:

@example
ffmpeg -listen 1 -i dtls://@var{hostname}:@var{port} @var{output}
@end example

To create a DTLS client and send data to server:

@example
ffmpeg -i @var{input} -f @var{format} dtls://@var{hostname}:@var{port}
@end example

@section udp

User Datagram Protocol.
Expand Down
17 changes: 2 additions & 15 deletions libavformat/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@
*/
#define MAX_CERTIFICATE_SIZE 8192

enum DTLSState {
DTLS_STATE_NONE,

/* Whether DTLS handshake is finished. */
DTLS_STATE_FINISHED,
/* Whether DTLS session is closed. */
DTLS_STATE_CLOSED,
/* Whether DTLS handshake is failed. */
DTLS_STATE_FAILED,
};

typedef struct TLSShared {
char *ca_file;
int verify;
Expand All @@ -62,8 +51,7 @@ typedef struct TLSShared {
URLContext *tcp;

int is_dtls;

enum DTLSState state;
int use_srtp;

/* The certificate and private key content used for DTLS handshake */
char* cert_buf;
Expand All @@ -90,6 +78,7 @@ typedef struct TLSShared {
{"listen", "Listen for incoming connections", offsetof(pstruct, options_field . listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
{"http_proxy", "Set proxy to tunnel through", offsetof(pstruct, options_field . http_proxy), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
{"external_sock", "Use external socket", offsetof(pstruct, options_field . external_sock), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
{"use_srtp", "Enable use_srtp DTLS extension", offsetof(pstruct, options_field . use_srtp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
{"mtu", "Maximum Transmission Unit", offsetof(pstruct, options_field . mtu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = TLS_OPTFL}, \
{"cert_pem", "Certificate PEM string", offsetof(pstruct, options_field . cert_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
{"key_pem", "Private key PEM string", offsetof(pstruct, options_field . key_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
Expand All @@ -103,8 +92,6 @@ int ff_tls_set_external_socket(URLContext *h, URLContext *sock);

int ff_dtls_export_materials(URLContext *h, char *dtls_srtp_materials, size_t materials_sz);

int ff_dtls_state(URLContext *h);

int ff_ssl_read_key_cert(char *key_url, char *cert_url, char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint);

int ff_ssl_gen_key_cert(char *key_buf, size_t key_sz, char *cert_buf, size_t cert_sz, char **fingerprint);
Expand Down
Loading
Loading