Skip to content

Commit 77cedd9

Browse files
committed
avformat/tls: add new option use_srtp to control whether enable it
Signed-off-by: Jack Lau <[email protected]>
1 parent b270faa commit 77cedd9

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

libavformat/tls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ typedef struct TLSShared {
5151
URLContext *tcp;
5252

5353
int is_dtls;
54+
int use_srtp;
5455

5556
/* The certificate and private key content used for DTLS handshake */
5657
char* cert_buf;
@@ -77,6 +78,7 @@ typedef struct TLSShared {
7778
{"listen", "Listen for incoming connections", offsetof(pstruct, options_field . listen), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
7879
{"http_proxy", "Set proxy to tunnel through", offsetof(pstruct, options_field . http_proxy), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
7980
{"external_sock", "Use external socket", offsetof(pstruct, options_field . external_sock), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
81+
{"use_srtp", "Enable use_srtp DTLS extension", offsetof(pstruct, options_field . use_srtp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = TLS_OPTFL }, \
8082
{"mtu", "Maximum Transmission Unit", offsetof(pstruct, options_field . mtu), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, .flags = TLS_OPTFL}, \
8183
{"cert_pem", "Certificate PEM string", offsetof(pstruct, options_field . cert_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \
8284
{"key_pem", "Private key PEM string", offsetof(pstruct, options_field . key_buf), AV_OPT_TYPE_STRING, .flags = TLS_OPTFL }, \

libavformat/tls_openssl.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -818,12 +818,6 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
818818
int ret = 0;
819819
c->is_dtls = 1;
820820

821-
/**
822-
* The profile for OpenSSL's SRTP is SRTP_AES128_CM_SHA1_80, see ssl/d1_srtp.c.
823-
* The profile for FFmpeg's SRTP is SRTP_AES128_CM_HMAC_SHA1_80, see libavformat/srtp.c.
824-
*/
825-
const char* profiles = "SRTP_AES128_CM_SHA1_80";
826-
827821
p->ctx = SSL_CTX_new(c->listen ? DTLS_server_method() : DTLS_client_method());
828822
if (!p->ctx) {
829823
ret = AVERROR(ENOMEM);
@@ -837,12 +831,18 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
837831
if (c->verify)
838832
SSL_CTX_set_verify(p->ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
839833

840-
/* Setup the SRTP context */
841-
if (SSL_CTX_set_tlsext_use_srtp(p->ctx, profiles)) {
842-
av_log(p, AV_LOG_ERROR, "Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n",
843-
profiles, openssl_get_error(p));
844-
ret = AVERROR(EINVAL);
845-
return ret;
834+
if (c->use_srtp) {
835+
/**
836+
* The profile for OpenSSL's SRTP is SRTP_AES128_CM_SHA1_80, see ssl/d1_srtp.c.
837+
* The profile for FFmpeg's SRTP is SRTP_AES128_CM_HMAC_SHA1_80, see libavformat/srtp.c.
838+
*/
839+
const char* profiles = "SRTP_AES128_CM_SHA1_80";
840+
if (SSL_CTX_set_tlsext_use_srtp(p->ctx, profiles)) {
841+
av_log(p, AV_LOG_ERROR, "Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n",
842+
profiles, openssl_get_error(p));
843+
ret = AVERROR(EINVAL);
844+
return ret;
845+
}
846846
}
847847

848848
/* The ssl should not be created unless the ctx has been initialized. */

libavformat/whip.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ static int dtls_handshake(AVFormatContext *s)
13661366
} else
13671367
av_dict_set(&opts, "key_pem", whip->key_buf, 0);
13681368
av_dict_set_int(&opts, "external_sock", 1, 0);
1369+
av_dict_set_int(&opts, "use_srtp", 1, 0);
13691370
av_dict_set_int(&opts, "listen", whip->flags & WHIP_FLAG_DTLS_ACTIVE ? 0 : 1, 0);
13701371
/* If got the first binding response, start DTLS handshake. */
13711372
ret = ffurl_open_whitelist(&whip->dtls_uc, buf, AVIO_FLAG_READ_WRITE, &s->interrupt_callback,

0 commit comments

Comments
 (0)