You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
avformat/tls: add new option use_srtp to control whether enable it
The SRTP profile string "SRTP_AES128_CM_SHA1_80" is only used when use_srtp is enabled. Move its declaration inside the "if (s->use_srtp)" block to limit scope Signed-off-by: Jack Lau <jacklau1222@qq.com>
This commit is contained in:
committed by
Timo Rothenpieler
parent
fd55c4b5f7
commit
dc9f676b99
@@ -63,6 +63,7 @@ typedef struct TLSShared {
|
||||
URLContext *tcp;
|
||||
|
||||
int is_dtls;
|
||||
int use_srtp;
|
||||
|
||||
enum DTLSState state;
|
||||
|
||||
@@ -97,6 +98,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 }, \
|
||||
|
@@ -822,12 +822,6 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
|
||||
av_assert0(s);
|
||||
s->is_dtls = 1;
|
||||
|
||||
/**
|
||||
* The profile for OpenSSL's SRTP is SRTP_AES128_CM_SHA1_80, see ssl/d1_srtp.c.
|
||||
* The profile for FFmpeg's SRTP is SRTP_AES128_CM_HMAC_SHA1_80, see libavformat/srtp.c.
|
||||
*/
|
||||
const char* profiles = "SRTP_AES128_CM_SHA1_80";
|
||||
|
||||
c->ctx = SSL_CTX_new(s->listen ? DTLS_server_method() : DTLS_client_method());
|
||||
if (!c->ctx) {
|
||||
ret = AVERROR(ENOMEM);
|
||||
@@ -841,12 +835,18 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
|
||||
if (s->verify)
|
||||
SSL_CTX_set_verify(c->ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL);
|
||||
|
||||
/* Setup the SRTP context */
|
||||
if (SSL_CTX_set_tlsext_use_srtp(c->ctx, profiles)) {
|
||||
av_log(c, AV_LOG_ERROR, "Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n",
|
||||
profiles, openssl_get_error(c));
|
||||
ret = AVERROR(EINVAL);
|
||||
return ret;
|
||||
if (s->use_srtp) {
|
||||
/**
|
||||
* The profile for OpenSSL's SRTP is SRTP_AES128_CM_SHA1_80, see ssl/d1_srtp.c.
|
||||
* The profile for FFmpeg's SRTP is SRTP_AES128_CM_HMAC_SHA1_80, see libavformat/srtp.c.
|
||||
*/
|
||||
const char* profiles = "SRTP_AES128_CM_SHA1_80";
|
||||
if (SSL_CTX_set_tlsext_use_srtp(c->ctx, profiles)) {
|
||||
av_log(c, AV_LOG_ERROR, "Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n",
|
||||
profiles, openssl_get_error(c));
|
||||
ret = AVERROR(EINVAL);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* The ssl should not be created unless the ctx has been initialized. */
|
||||
|
@@ -1303,6 +1303,7 @@ next_packet:
|
||||
} else
|
||||
av_dict_set(&opts, "key_pem", whip->key_buf, 0);
|
||||
av_dict_set_int(&opts, "external_sock", 1, 0);
|
||||
av_dict_set_int(&opts, "use_srtp", 1, 0);
|
||||
av_dict_set_int(&opts, "listen", 1, 0);
|
||||
/* If got the first binding response, start DTLS handshake. */
|
||||
ret = ffurl_open_whitelist(&whip->dtls_uc, buf, AVIO_FLAG_READ_WRITE, &s->interrupt_callback,
|
||||
|
Reference in New Issue
Block a user