Skip to content

Commit

Permalink
WHIP: Update the dependency, requires openssl.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed May 2, 2023
1 parent c0e1296 commit 2ad58fe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 43 additions & 0 deletions libavformat/rtcenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "config.h"

#if CONFIG_OPENSSL
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif

#include "libavutil/dict.h"
#include "libavutil/avassert.h"
#include "libavutil/mathematics.h"
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 2ad58fe

Please sign in to comment.