1919 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2020 */
2121
22+ #include "config.h"
23+
24+ #if CONFIG_OPENSSL
25+ #include <openssl/ssl.h>
26+ #include <openssl/err.h>
27+ #endif
28+
2229#include "libavutil/dict.h"
2330#include "libavutil/avassert.h"
2431#include "libavutil/mathematics.h"
@@ -632,6 +639,34 @@ static int ice_handshake(AVFormatContext *s)
632639 return ret ;
633640}
634641
642+ #if CONFIG_OPENSSL
643+ /**
644+ * DTLS handshake with server, as a client in active mode, using openssl.
645+ *
646+ * @return 0 if OK, AVERROR_xxx on error
647+ */
648+ static int dtls_handshake_openssl (AVFormatContext * s )
649+ {
650+ int ret = 0 ;
651+ SSL_CTX * dtls_ctx = NULL ;
652+
653+ #if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2
654+ dtls_ctx = SSL_CTX_new (DTLSv1_method ());
655+ #else
656+ dtls_ctx = SSL_CTX_new (DTLS_client_method ());
657+ #endif
658+ if (!dtls_ctx ) {
659+ av_log (s , AV_LOG_ERROR , "Failed to create DTLS context\n" );
660+ ret = AVERROR (ENOMEM );
661+ goto end ;
662+ }
663+
664+ end :
665+ SSL_CTX_free (dtls_ctx );
666+ return ret ;
667+ }
668+ #endif
669+
635670static av_cold int rtc_init (AVFormatContext * s )
636671{
637672 int ret ;
@@ -658,6 +693,16 @@ static int rtc_write_header(AVFormatContext *s)
658693 if ((ret = ice_handshake (s )) < 0 )
659694 return ret ;
660695
696+ #if CONFIG_OPENSSL
697+ if ((ret = dtls_handshake_openssl (s )) < 0 )
698+ return ret ;
699+ #else
700+ av_log (s , AV_LOG_ERROR , "DTLS is not supported, please enable openssl\n" );
701+ ret = AVERROR (ENOSYS );
702+ goto end ;
703+ #endif
704+
705+ end :
661706 return ret ;
662707}
663708
0 commit comments