19
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
*/
21
21
22
+ #include "config.h"
23
+
24
+ #if CONFIG_OPENSSL
25
+ #include <openssl/ssl.h>
26
+ #include <openssl/err.h>
27
+ #endif
28
+
22
29
#include "libavutil/dict.h"
23
30
#include "libavutil/avassert.h"
24
31
#include "libavutil/mathematics.h"
@@ -632,6 +639,34 @@ static int ice_handshake(AVFormatContext *s)
632
639
return ret ;
633
640
}
634
641
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
+
635
670
static av_cold int rtc_init (AVFormatContext * s )
636
671
{
637
672
int ret ;
@@ -658,6 +693,14 @@ static int rtc_write_header(AVFormatContext *s)
658
693
if ((ret = ice_handshake (s )) < 0 )
659
694
return ret ;
660
695
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
+ return AVERROR (ENOSYS );
702
+ #endif
703
+
661
704
return ret ;
662
705
}
663
706
0 commit comments