Skip to content

Commit 42af813

Browse files
committed
avformat/whip: add whip_flags ignore_ipv6 to skip IPv6 candidates
mark this ignore_ipv6 flag could ignore any ipv6 ICE candidate, preventing “No route to host” errors on devices without IPv6 connectivity. Signed-off-by: Jack Lau <[email protected]>
1 parent c5b7462 commit 42af813

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

libavformat/whip.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,14 @@ enum WHIPState {
193193
WHIP_STATE_FAILED,
194194
};
195195

196+
typedef enum WHIPFlags {
197+
WHIP_FLAG_IGNORE_IPV6 = (1 << 0) // Ignore ipv6 candidate
198+
} WHIPFlags;
199+
196200
typedef struct WHIPContext {
197201
AVClass *av_class;
198202

203+
uint32_t flags; // enum WHIPFlags
199204
/* The state of the RTC connection. */
200205
enum WHIPState state;
201206
/* The callback return value for DTLS. */
@@ -871,6 +876,7 @@ static int parse_answer(AVFormatContext *s)
871876
if (ptr && av_stristr(ptr, "host")) {
872877
char protocol[17], host[129];
873878
int priority, port;
879+
struct in6_addr addr6;
874880
ret = sscanf(ptr, "%16s %d %128s %d typ host", protocol, &priority, host, &port);
875881
if (ret != 4) {
876882
av_log(whip, AV_LOG_ERROR, "WHIP: Failed %d to parse line %d %s from %s\n",
@@ -879,6 +885,11 @@ static int parse_answer(AVFormatContext *s)
879885
goto end;
880886
}
881887

888+
if (whip->flags & WHIP_FLAG_IGNORE_IPV6 && inet_pton(AF_INET6, host, &addr6) == 1) {
889+
av_log(whip, AV_LOG_DEBUG, "WHIP: Ignore ipv6 %s, line %d %s \n", host, i, line);
890+
continue;
891+
}
892+
882893
if (av_strcasecmp(protocol, "udp")) {
883894
av_log(whip, AV_LOG_ERROR, "WHIP: Protocol %s is not supported by RTC, choose udp, line %d %s of %s\n",
884895
protocol, i, line, whip->sdp_answer);
@@ -1892,6 +1903,8 @@ static const AVOption options[] = {
18921903
{ "authorization", "The optional Bearer token for WHIP Authorization", OFFSET(authorization), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, ENC },
18931904
{ "cert_file", "The optional certificate file path for DTLS", OFFSET(cert_file), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, ENC },
18941905
{ "key_file", "The optional private key file path for DTLS", OFFSET(key_file), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, ENC },
1906+
{ "whip_flags", "set flags affecting WHIP connection behavior", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, UINT_MAX, ENC, .unit = "flags" },
1907+
{ "ignore_ipv6", "ignore any IPv6 ICE candidate", 0, AV_OPT_TYPE_CONST, { .i64 = WHIP_FLAG_IGNORE_IPV6 }, 0, UINT_MAX, ENC, .unit = "flags" },
18951908
{ NULL },
18961909
};
18971910

0 commit comments

Comments
 (0)