From 0093a54b34ceaea91e8be01039d0c6e1ad6a6f2b Mon Sep 17 00:00:00 2001 From: ChenGH Date: Mon, 4 Oct 2021 13:40:17 +0800 Subject: [PATCH 1/2] fix bandwidth kbps caculate bug (#2648) --- trunk/src/app/srs_app_bandwidth.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trunk/src/app/srs_app_bandwidth.cpp b/trunk/src/app/srs_app_bandwidth.cpp index 38584a7cf..dd8e930f4 100644 --- a/trunk/src/app/srs_app_bandwidth.cpp +++ b/trunk/src/app/srs_app_bandwidth.cpp @@ -264,7 +264,7 @@ srs_error_t SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit limit->send_limit(); } srs_update_system_time(); - sample->calc_kbps((int)_rtmp->get_send_bytes(), srsu2msi(srs_get_system_time() - starttime)); + sample->calc_kbps((int)_rtmp->get_send_bytes(), srs_get_system_time() - starttime); return err; } @@ -342,7 +342,7 @@ srs_error_t SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLi limit->recv_limit(); } srs_update_system_time(); - sample->calc_kbps((int)_rtmp->get_recv_bytes(), srsu2msi(srs_get_system_time() - starttime)); + sample->calc_kbps((int)_rtmp->get_recv_bytes(), srs_get_system_time() - starttime); return err; } From 7a4de9ffe74022de5a7d407a768a113e63241b64 Mon Sep 17 00:00:00 2001 From: ChenGH Date: Thu, 7 Oct 2021 21:05:30 +0800 Subject: [PATCH 2/2] Fix #2415, refine dtls fragment and rtp payload size (#2652) --- trunk/src/app/srs_app_rtc_dtls.cpp | 8 ++++++-- trunk/src/app/srs_app_rtc_source.cpp | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/trunk/src/app/srs_app_rtc_dtls.cpp b/trunk/src/app/srs_app_rtc_dtls.cpp index 555ff0604..582f8a8d7 100644 --- a/trunk/src/app/srs_app_rtc_dtls.cpp +++ b/trunk/src/app/srs_app_rtc_dtls.cpp @@ -25,6 +25,10 @@ using namespace std; #include #include +// to avoid dtls negotiate failed, set max fragment size 1200. +// @see https://github.com/ossrs/srs/issues/2415 +const int DTLS_FRAGMENT_MAX_SIZE = 1200; + // Defined in HTTP/HTTPS client. extern int srs_verify_callback(int preverify_ok, X509_STORE_CTX *ctx); @@ -439,7 +443,7 @@ srs_error_t SrsDtlsImpl::initialize(std::string version, std::string role) // set dtls fragment // @see https://stackoverflow.com/questions/62413602/openssl-server-packets-get-fragmented-into-270-bytes-per-packet SSL_set_options(dtls, SSL_OP_NO_QUERY_MTU); - SSL_set_mtu(dtls, kRtpPacketSize); + SSL_set_mtu(dtls, DTLS_FRAGMENT_MAX_SIZE); // @see https://linux.die.net/man/3/openssl_version_number // MM NN FF PP S @@ -699,7 +703,7 @@ srs_error_t SrsDtlsClientImpl::initialize(std::string version, std::string role) // Dtls setup active, as client role. SSL_set_connect_state(dtls); - SSL_set_max_send_fragment(dtls, kRtpPacketSize); + SSL_set_max_send_fragment(dtls, DTLS_FRAGMENT_MAX_SIZE); return err; } diff --git a/trunk/src/app/srs_app_rtc_source.cpp b/trunk/src/app/srs_app_rtc_source.cpp index 371b4d3ff..d53534940 100644 --- a/trunk/src/app/srs_app_rtc_source.cpp +++ b/trunk/src/app/srs_app_rtc_source.cpp @@ -64,7 +64,11 @@ const int kVideoSamplerate = 90000; // kRtpPacketSize = kRtpMaxPayloadSize + paddings // For example, if kRtpPacketSize is 1500, recommend to set kRtpMaxPayloadSize to 1400, // which reserves 100 bytes for SRTP or paddings. -const int kRtpMaxPayloadSize = kRtpPacketSize - 200; +// otherwise, the kRtpPacketSize must less than MTU, in webrtc source code, +// the rtp max size is assigned by kVideoMtu = 1200. +// so we set kRtpMaxPayloadSize = 1200. +// see @doc https://groups.google.com/g/discuss-webrtc/c/gH5ysR3SoZI +const int kRtpMaxPayloadSize = kRtpPacketSize - 300; using namespace std;