diff --git a/configure b/configure index 6e363eb47025d..53fe51de41967 100755 --- a/configure +++ b/configure @@ -3480,6 +3480,7 @@ ogg_demuxer_select="dirac_parse" ogv_muxer_select="ogg_muxer" opus_muxer_select="ogg_muxer" psp_muxer_select="mov_muxer" +rtc_muxer_deps_any="openssl" rtp_demuxer_select="sdp_demuxer" rtp_mpegts_muxer_select="mpegts_muxer rtp_muxer" rtpdec_select="asf_demuxer mov_demuxer mpegts_demuxer rm_demuxer rtp_protocol srtp" diff --git a/libavformat/rtcenc.c b/libavformat/rtcenc.c index fbd64b856a351..100457c81e6b2 100644 --- a/libavformat/rtcenc.c +++ b/libavformat/rtcenc.c @@ -19,6 +19,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" + +#if CONFIG_OPENSSL +#include +#include +#endif + #include "libavutil/dict.h" #include "libavutil/avassert.h" #include "libavutil/mathematics.h" @@ -632,6 +639,34 @@ static int ice_handshake(AVFormatContext *s) return ret; } +#if CONFIG_OPENSSL +/** + * DTLS handshake with server, as a client in active mode, using openssl. + * + * @return 0 if OK, AVERROR_xxx on error + */ +static int dtls_handshake_openssl(AVFormatContext *s) +{ + int ret = 0; + SSL_CTX *dtls_ctx = NULL; + +#if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2 + dtls_ctx = SSL_CTX_new(DTLSv1_method()); +#else + dtls_ctx = SSL_CTX_new(DTLS_client_method()); +#endif + if (!dtls_ctx) { + av_log(s, AV_LOG_ERROR, "Failed to create DTLS context\n"); + ret = AVERROR(ENOMEM); + goto end; + } + +end: + SSL_CTX_free(dtls_ctx); + return ret; +} +#endif + static av_cold int rtc_init(AVFormatContext *s) { int ret; @@ -658,6 +693,14 @@ static int rtc_write_header(AVFormatContext *s) if ((ret = ice_handshake(s)) < 0) return ret; +#if CONFIG_OPENSSL + if ((ret = dtls_handshake_openssl(s)) < 0) + return ret; +#else + av_log(s, AV_LOG_ERROR, "DTLS is not supported, please enable openssl\n"); + return AVERROR(ENOSYS); +#endif + return ret; }