Index: libavformat/tls_openssl.c
--- libavformat/tls_openssl.c.orig
+++ libavformat/tls_openssl.c
@@ -32,13 +32,18 @@
 #include <openssl/ssl.h>
 #include <openssl/err.h>
 #include <openssl/x509v3.h>
+#include <string.h>
 
+#define TLS_ST_OK SSL_ST_OK
+
 /**
  * Convert an EVP_PKEY to a PEM string.
  */
 static int pkey_to_pem_string(EVP_PKEY *pkey, char *out, size_t out_sz)
 {
     BIO *mem = NULL;
+    char *data = NULL;
+    long data_len;
     size_t read_bytes = 0;
 
     if (!pkey || !out || !out_sz)
@@ -50,9 +55,13 @@ static int pkey_to_pem_string(EVP_PKEY *pkey, char *ou
     if (!PEM_write_bio_PrivateKey(mem, pkey, NULL, NULL, 0, NULL, NULL))
         goto done;
 
-    if (!BIO_read_ex(mem, out, out_sz - 1, &read_bytes))
+    data_len = BIO_get_mem_data(mem, &data);
+    if (data_len <= 0)
         goto done;
 
+    read_bytes = FFMIN((size_t)data_len, out_sz - 1);
+    memcpy(out, data, read_bytes);
+
 done:
     BIO_free(mem);
     if (out && out_sz)
@@ -66,6 +75,8 @@ done:
 static int cert_to_pem_string(X509 *cert, char *out, size_t out_sz)
 {
     BIO *mem = NULL;
+    char *data = NULL;
+    long data_len;
     size_t read_bytes = 0;
 
     if (!cert || !out || !out_sz)
@@ -77,9 +88,13 @@ static int cert_to_pem_string(X509 *cert, char *out, s
     if (!PEM_write_bio_X509(mem, cert))
         goto done;
 
-    if (!BIO_read_ex(mem, out, out_sz - 1, &read_bytes))
+    data_len = BIO_get_mem_data(mem, &data);
+    if (data_len <= 0)
         goto done;
 
+    read_bytes = FFMIN((size_t)data_len, out_sz - 1);
+    memcpy(out, data, read_bytes);
+
 done:
     BIO_free(mem);
     if (out && out_sz)
@@ -801,7 +816,9 @@ static int dtls_start(URLContext *h, const char *url, 
         s->mtu = 1096;
     SSL_set_options(c->ssl, SSL_OP_NO_QUERY_MTU);
     SSL_set_mtu(c->ssl, s->mtu);
+#ifdef DTLS_set_link_mtu
     DTLS_set_link_mtu(c->ssl, s->mtu);
+#endif
     init_bio_method(h);
 
     /* This seems to be necessary despite explicitly setting client/server method above. */
@@ -925,10 +942,12 @@ static int tls_write(URLContext *h, const uint8_t *buf
     uc->flags &= ~AVIO_FLAG_NONBLOCK;
     uc->flags |= h->flags & AVIO_FLAG_NONBLOCK;
 
+#ifdef DTLS_get_link_mtu
     if (s->is_dtls) {
         const size_t mtu_size = DTLS_get_data_mtu(c->ssl);
         size = FFMIN(size, mtu_size);
     }
+#endif
 
     ret = SSL_write(c->ssl, buf, size);
     if (ret > 0)
