[FFmpeg-devel] [PATCH v5 12/15] avformat/tls_openssl: directly use mtu in TLSShared

Jack Lau jacklau1222gm at gmail.com
Wed Jul 23 16:42:55 EEST 2025



> On Jul 22, 2025, at 20:43, Timo Rothenpieler <timo at rothenpieler.org> wrote:
> 
> On 22/07/2025 14:36, Jack Lau wrote:
>> Openssl 1.1.0 version haven't DTLS_get_data_mtu API
>> Signed-off-by: Jack Lau <jacklau1222 at qq.com>
>> ---
>>  libavformat/tls_openssl.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
>> index fa852aac18..54860857c0 100644
>> --- a/libavformat/tls_openssl.c
>> +++ b/libavformat/tls_openssl.c
>> @@ -1013,7 +1013,7 @@ static int tls_write(URLContext *h, const uint8_t *buf, int size)
>>      uc->flags |= h->flags & AVIO_FLAG_NONBLOCK;
>>        if (c->tls_shared.is_dtls)
>> -        size = FFMIN(size, DTLS_get_data_mtu(c->ssl));
>> +        size = FFMIN(size, c->tls_shared.mtu);
> 
> This is not the same value, no.
> DTLS_get_data_mtu returns the mtu minus the size of the DTLS header and footer, i.e. the maximum amount of data it can consume.
> Which is exactly what it's used for here.
You’re right.
I think compute the real overhead(DTLS header + cipher tag) for openssl 1.1.0 version is no necessary, 
so I use a conservative overhead covers all cases
How about this one?


diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c
index d42c5c95cf2c1..255e2f8a2e12c 100644
--- a/libavformat/tls_openssl.c
+++ b/libavformat/tls_openssl.c
@@ -1007,13 +1007,17 @@ static int tls_write(URLContext *h, const uint8_t *buf, int size)
     TLSShared *s = &c->tls_shared;
     URLContext *uc = s->is_dtls ? s->udp : s->tcp;
     int ret;
-
+#if OPENSSL_VERSION_NUMBER >= 0x10101000L  // OpenSSL 1.1.1
+    int data_mtu = DTLS_get_data_mtu(c->ssl);
+#else
+    int data_mtu = s->mtu - 64; // Conservative overhead covers all cases
+#endif
     // Set or clear the AVIO_FLAG_NONBLOCK on the underlying socket
     uc->flags &= ~AVIO_FLAG_NONBLOCK;
     uc->flags |= h->flags & AVIO_FLAG_NONBLOCK;
 
     if (s->is_dtls)
-        size = FFMIN(size, s->mtu);
+        size = FFMIN(size, data_mtu);
 
     ret = SSL_write(c->ssl, buf, size);
     if (ret > 0)
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org <mailto:ffmpeg-devel at ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org <mailto:ffmpeg-devel-request at ffmpeg.org> with subject "unsubscribe".



More information about the ffmpeg-devel mailing list