Unverified 提交 2744b4ca authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Add transport.setMinOutgoingBitrate() (2) (#1038)

Same PR than https://github.com/versatica/mediasoup/pull/1035/files by @jcague (all credits to him) with some additions such as the ability to reset min/max limits by calling the methods with argument 0 and more tests.
上级 f8e6238d
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
### NEXT ### NEXT
* Add `transport.setMinOutgoingBitrate()` method ([PR #1038](https://github.com/versatica/mediasoup/pull/1038), credits to @ jcague).
* `RTC::RetransmissionBuffer`: Increase `RetransmissionBufferMaxItems` from 2500 to 5000. * `RTC::RetransmissionBuffer`: Increase `RetransmissionBufferMaxItems` from 2500 to 5000.
......
...@@ -166,6 +166,16 @@ export class DirectTransport extends ...@@ -166,6 +166,16 @@ export class DirectTransport extends
'setMaxOutgoingBitrate() not implemented in DirectTransport'); 'setMaxOutgoingBitrate() not implemented in DirectTransport');
} }
/**
* @override
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setMinOutgoingBitrate(bitrate: number): Promise<void>
{
throw new UnsupportedError(
'setMinOutgoingBitrate() not implemented in DirectTransport');
}
/** /**
* Send RTCP packet. * Send RTCP packet.
*/ */
......
...@@ -523,6 +523,19 @@ export class Transport<Events extends TransportEvents = TransportEvents, ...@@ -523,6 +523,19 @@ export class Transport<Events extends TransportEvents = TransportEvents,
'transport.setMaxOutgoingBitrate', this.internal.transportId, reqData); 'transport.setMaxOutgoingBitrate', this.internal.transportId, reqData);
} }
/**
* Set minimum outgoing bitrate for sending media.
*/
async setMinOutgoingBitrate(bitrate: number): Promise<void>
{
logger.debug('setMinOutgoingBitrate() [bitrate:%s]', bitrate);
const reqData = { bitrate };
await this.channel.request(
'transport.setMinOutgoingBitrate', this.internal.transportId, reqData);
}
/** /**
* Create a Producer. * Create a Producer.
*/ */
......
...@@ -340,14 +340,68 @@ test('webRtcTransport.connect() with wrong arguments rejects with TypeError', as ...@@ -340,14 +340,68 @@ test('webRtcTransport.connect() with wrong arguments rejects with TypeError', as
test('webRtcTransport.setMaxIncomingBitrate() succeeds', async () => test('webRtcTransport.setMaxIncomingBitrate() succeeds', async () =>
{ {
await expect(transport.setMaxIncomingBitrate(100000)) await expect(transport.setMaxIncomingBitrate(1000000))
.resolves
.toBeUndefined();
// Remove limit.
await expect(transport.setMaxIncomingBitrate(0))
.resolves .resolves
.toBeUndefined(); .toBeUndefined();
}, 2000); }, 2000);
test('webRtcTransport.setMaxOutgoingBitrate() succeeds', async () => test('webRtcTransport.setMaxOutgoingBitrate() succeeds', async () =>
{ {
await expect(transport.setMaxIncomingBitrate(100000)) await expect(transport.setMaxOutgoingBitrate(2000000))
.resolves
.toBeUndefined();
// Remove limit.
await expect(transport.setMaxOutgoingBitrate(0))
.resolves
.toBeUndefined();
}, 2000);
test('webRtcTransport.setMinOutgoingBitrate() succeeds', async () =>
{
await expect(transport.setMinOutgoingBitrate(100000))
.resolves
.toBeUndefined();
// Remove limit.
await expect(transport.setMinOutgoingBitrate(0))
.resolves
.toBeUndefined();
}, 2000);
test('webRtcTransport.setMaxOutgoingBitrate() fails if value is lower than current min limit', async () =>
{
await expect(transport.setMinOutgoingBitrate(3000000))
.resolves
.toBeUndefined();
await expect(transport.setMaxOutgoingBitrate(2000000))
.rejects
.toThrow(Error);
// Remove limit.
await expect(transport.setMinOutgoingBitrate(0))
.resolves
.toBeUndefined();
}, 2000);
test('webRtcTransport.setMinOutgoingBitrate() fails if value is higher than current max limit', async () =>
{
await expect(transport.setMaxOutgoingBitrate(2000000))
.resolves
.toBeUndefined();
await expect(transport.setMinOutgoingBitrate(3000000))
.rejects
.toThrow(Error);
// Remove limit.
await expect(transport.setMaxOutgoingBitrate(0))
.resolves .resolves
.toBeUndefined(); .toBeUndefined();
}, 2000); }, 2000);
...@@ -500,6 +554,10 @@ test('WebRtcTransport methods reject if closed', async () => ...@@ -500,6 +554,10 @@ test('WebRtcTransport methods reject if closed', async () =>
.rejects .rejects
.toThrow(Error); .toThrow(Error);
await expect(transport.setMinOutgoingBitrate(100000))
.rejects
.toThrow(Error);
await expect(transport.restartIce()) await expect(transport.restartIce())
.rejects .rejects
.toThrow(Error); .toThrow(Error);
......
...@@ -595,6 +595,12 @@ request_response!( ...@@ -595,6 +595,12 @@ request_response!(
TransportSetMaxOutgoingBitrateRequest { bitrate: u32 }, TransportSetMaxOutgoingBitrateRequest { bitrate: u32 },
); );
request_response!(
TransportId,
"transport.setMinOutgoingBitrate",
TransportSetMinOutgoingBitrateRequest { bitrate: u32 },
);
request_response!( request_response!(
TransportId, TransportId,
"transport.restartIce", "transport.restartIce",
......
...@@ -6,7 +6,7 @@ use crate::messages::{ ...@@ -6,7 +6,7 @@ use crate::messages::{
TransportConsumeDataRequest, TransportConsumeRequest, TransportDumpRequest, TransportConsumeDataRequest, TransportConsumeRequest, TransportDumpRequest,
TransportEnableTraceEventRequest, TransportGetStatsRequest, TransportProduceDataRequest, TransportEnableTraceEventRequest, TransportGetStatsRequest, TransportProduceDataRequest,
TransportProduceRequest, TransportSetMaxIncomingBitrateRequest, TransportProduceRequest, TransportSetMaxIncomingBitrateRequest,
TransportSetMaxOutgoingBitrateRequest, TransportSetMaxOutgoingBitrateRequest, TransportSetMinOutgoingBitrateRequest,
}; };
pub use crate::ortc::{ pub use crate::ortc::{
ConsumerRtpParametersError, RtpCapabilitiesError, RtpParametersError, RtpParametersMappingError, ConsumerRtpParametersError, RtpCapabilitiesError, RtpParametersError, RtpParametersMappingError,
...@@ -396,6 +396,12 @@ pub(super) trait TransportImpl: TransportGeneric { ...@@ -396,6 +396,12 @@ pub(super) trait TransportImpl: TransportGeneric {
.await .await
} }
async fn set_min_outgoing_bitrate_impl(&self, bitrate: u32) -> Result<(), RequestError> {
self.channel()
.request(self.id(), TransportSetMinOutgoingBitrateRequest { bitrate })
.await
}
async fn produce_impl( async fn produce_impl(
&self, &self,
producer_options: ProducerOptions, producer_options: ProducerOptions,
......
...@@ -794,6 +794,14 @@ impl WebRtcTransport { ...@@ -794,6 +794,14 @@ impl WebRtcTransport {
self.set_max_outgoing_bitrate_impl(bitrate).await self.set_max_outgoing_bitrate_impl(bitrate).await
} }
/// Set minimum outgoing bitrate for media streams sent by the remote endpoint over this
/// transport.
pub async fn set_min_outgoing_bitrate(&self, bitrate: u32) -> Result<(), RequestError> {
debug!("set_min_outgoing_bitrate() [bitrate:{}]", bitrate);
self.set_min_outgoing_bitrate_impl(bitrate).await
}
/// Local ICE role. Due to the mediasoup ICE Lite design, this is always `Controlled`. /// Local ICE role. Due to the mediasoup ICE Lite design, this is always `Controlled`.
#[must_use] #[must_use]
pub fn ice_role(&self) -> IceRole { pub fn ice_role(&self) -> IceRole {
......
...@@ -436,9 +436,15 @@ fn set_max_incoming_bitrate_succeeds() { ...@@ -436,9 +436,15 @@ fn set_max_incoming_bitrate_succeeds() {
.expect("Failed to create WebRTC transport"); .expect("Failed to create WebRTC transport");
transport transport
.set_max_incoming_bitrate(100000) .set_max_incoming_bitrate(1000000)
.await .await
.expect("Failed to set max incoming bitrate on WebRTC transport"); .expect("Failed to set max incoming bitrate on WebRTC transport");
// Remove limit.
transport
.set_max_incoming_bitrate(0)
.await
.expect("Failed to remove limit in max incoming bitrate on WebRTC transport");
}); });
} }
...@@ -458,9 +464,109 @@ fn set_max_outgoing_bitrate_succeeds() { ...@@ -458,9 +464,109 @@ fn set_max_outgoing_bitrate_succeeds() {
.expect("Failed to create WebRTC transport"); .expect("Failed to create WebRTC transport");
transport transport
.set_max_outgoing_bitrate(100000) .set_max_outgoing_bitrate(2000000)
.await .await
.expect("Failed to set max outgoing bitrate on WebRTC transport"); .expect("Failed to set max outgoing bitrate on WebRTC transport");
// Remove limit.
transport
.set_max_outgoing_bitrate(0)
.await
.expect("Failed to remove limit in max outgoing bitrate on WebRTC transport");
});
}
#[test]
fn set_min_outgoing_bitrate_succeeds() {
future::block_on(async move {
let (_worker, router) = init().await;
let transport = router
.create_webrtc_transport(WebRtcTransportOptions::new(TransportListenIps::new(
ListenIp {
ip: IpAddr::V4(Ipv4Addr::LOCALHOST),
announced_ip: Some("9.9.9.1".parse().unwrap()),
},
)))
.await
.expect("Failed to create WebRTC transport");
transport
.set_min_outgoing_bitrate(100000)
.await
.expect("Failed to set min outgoing bitrate on WebRTC transport");
// Remove limit.
transport
.set_min_outgoing_bitrate(0)
.await
.expect("Failed to remove limit in min outgoing bitrate on WebRTC transport");
});
}
#[test]
fn set_max_outgoing_bitrate_fails_if_value_is_lower_than_current_min_limit() {
future::block_on(async move {
let (_worker, router) = init().await;
let transport = router
.create_webrtc_transport(WebRtcTransportOptions::new(TransportListenIps::new(
ListenIp {
ip: IpAddr::V4(Ipv4Addr::LOCALHOST),
announced_ip: Some("9.9.9.1".parse().unwrap()),
},
)))
.await
.expect("Failed to create WebRTC transport");
transport
.set_min_outgoing_bitrate(3000000)
.await
.expect("Failed to set min outgoing bitrate on WebRTC transport");
assert!(matches!(
transport.set_max_outgoing_bitrate(2000000).await,
Err(RequestError::Response { .. }),
));
// Remove limit.
transport
.set_min_outgoing_bitrate(0)
.await
.expect("Failed to remove limit in min outgoing bitrate on WebRTC transport");
});
}
#[test]
fn set_min_outgoing_bitrate_fails_if_value_is_higher_than_current_max_limit() {
future::block_on(async move {
let (_worker, router) = init().await;
let transport = router
.create_webrtc_transport(WebRtcTransportOptions::new(TransportListenIps::new(
ListenIp {
ip: IpAddr::V4(Ipv4Addr::LOCALHOST),
announced_ip: Some("9.9.9.1".parse().unwrap()),
},
)))
.await
.expect("Failed to create WebRTC transport");
transport
.set_max_outgoing_bitrate(2000000)
.await
.expect("Failed to set max outgoing bitrate on WebRTC transport");
assert!(matches!(
transport.set_min_outgoing_bitrate(3000000).await,
Err(RequestError::Response { .. }),
));
// Remove limit.
transport
.set_max_outgoing_bitrate(0)
.await
.expect("Failed to remove limit in max outgoing bitrate on WebRTC transport");
}); });
} }
......
...@@ -43,6 +43,7 @@ namespace Channel ...@@ -43,6 +43,7 @@ namespace Channel
TRANSPORT_CONNECT, TRANSPORT_CONNECT,
TRANSPORT_SET_MAX_INCOMING_BITRATE, TRANSPORT_SET_MAX_INCOMING_BITRATE,
TRANSPORT_SET_MAX_OUTGOING_BITRATE, TRANSPORT_SET_MAX_OUTGOING_BITRATE,
TRANSPORT_SET_MIN_OUTGOING_BITRATE,
TRANSPORT_RESTART_ICE, TRANSPORT_RESTART_ICE,
TRANSPORT_PRODUCE, TRANSPORT_PRODUCE,
TRANSPORT_CONSUME, TRANSPORT_CONSUME,
......
...@@ -329,6 +329,7 @@ namespace RTC ...@@ -329,6 +329,7 @@ namespace RTC
uint32_t initialAvailableOutgoingBitrate{ 600000u }; uint32_t initialAvailableOutgoingBitrate{ 600000u };
uint32_t maxIncomingBitrate{ 0u }; uint32_t maxIncomingBitrate{ 0u };
uint32_t maxOutgoingBitrate{ 0u }; uint32_t maxOutgoingBitrate{ 0u };
uint32_t minOutgoingBitrate{ 0u };
struct TraceEventTypes traceEventTypes; struct TraceEventTypes traceEventTypes;
}; };
} // namespace RTC } // namespace RTC
......
...@@ -56,7 +56,8 @@ namespace RTC ...@@ -56,7 +56,8 @@ namespace RTC
RTC::TransportCongestionControlClient::Listener* listener, RTC::TransportCongestionControlClient::Listener* listener,
RTC::BweType bweType, RTC::BweType bweType,
uint32_t initialAvailableBitrate, uint32_t initialAvailableBitrate,
uint32_t maxOutgoingBitrate); uint32_t maxOutgoingBitrate,
uint32_t minOutgoingBitrate);
virtual ~TransportCongestionControlClient(); virtual ~TransportCongestionControlClient();
public: public:
...@@ -74,6 +75,7 @@ namespace RTC ...@@ -74,6 +75,7 @@ namespace RTC
void ReceiveRtcpTransportFeedback(const RTC::RTCP::FeedbackRtpTransportPacket* feedback); void ReceiveRtcpTransportFeedback(const RTC::RTCP::FeedbackRtpTransportPacket* feedback);
void SetDesiredBitrate(uint32_t desiredBitrate, bool force); void SetDesiredBitrate(uint32_t desiredBitrate, bool force);
void SetMaxOutgoingBitrate(uint32_t maxBitrate); void SetMaxOutgoingBitrate(uint32_t maxBitrate);
void SetMinOutgoingBitrate(uint32_t minBitrate);
const Bitrates& GetBitrates() const const Bitrates& GetBitrates() const
{ {
return this->bitrates; return this->bitrates;
...@@ -118,6 +120,7 @@ namespace RTC ...@@ -118,6 +120,7 @@ namespace RTC
RTC::BweType bweType; RTC::BweType bweType;
uint32_t initialAvailableBitrate{ 0u }; uint32_t initialAvailableBitrate{ 0u };
uint32_t maxOutgoingBitrate{ 0u }; uint32_t maxOutgoingBitrate{ 0u };
uint32_t minOutgoingBitrate{ 0u };
Bitrates bitrates; Bitrates bitrates;
bool availableBitrateEventCalled{ false }; bool availableBitrateEventCalled{ false };
uint64_t lastAvailableBitrateEventAtMs{ 0u }; uint64_t lastAvailableBitrateEventAtMs{ 0u };
......
...@@ -172,19 +172,27 @@ namespace Utils ...@@ -172,19 +172,27 @@ namespace Utils
{ {
// If size is not multiple of 32 bits then pad it. // If size is not multiple of 32 bits then pad it.
if (size & 0x03) if (size & 0x03)
{
return (size & 0xFFFC) + 4; return (size & 0xFFFC) + 4;
}
else else
{
return size; return size;
} }
}
static uint32_t PadTo4Bytes(uint32_t size) static uint32_t PadTo4Bytes(uint32_t size)
{ {
// If size is not multiple of 32 bits then pad it. // If size is not multiple of 32 bits then pad it.
if (size & 0x03) if (size & 0x03)
{
return (size & 0xFFFFFFFC) + 4; return (size & 0xFFFFFFFC) + 4;
}
else else
{
return size; return size;
} }
}
}; };
class Bits class Bits
...@@ -213,10 +221,14 @@ namespace Utils ...@@ -213,10 +221,14 @@ namespace Utils
// Special case. // Special case.
if (max == 4294967295) if (max == 4294967295)
{
--max; --max;
}
if (min > max) if (min > max)
{
min = max; min = max;
}
return (((Crypto::seed >> 4) & 0x7FFF7FFF) % (max - min + 1)) + min; return (((Crypto::seed >> 4) & 0x7FFF7FFF) % (max - min + 1)) + min;
} }
...@@ -229,7 +241,9 @@ namespace Utils ...@@ -229,7 +241,9 @@ namespace Utils
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
if (len > 64) if (len > 64)
{
len = 64; len = 64;
}
for (size_t i{ 0 }; i < len; ++i) for (size_t i{ 0 }; i < len; ++i)
{ {
...@@ -323,10 +337,12 @@ namespace Utils ...@@ -323,10 +337,12 @@ namespace Utils
// IsNewer(t2,t1)=false // IsNewer(t2,t1)=false
// rather than having IsNewer(t1,t2) = IsNewer(t2,t1) = false. // rather than having IsNewer(t1,t2) = IsNewer(t2,t1) = false.
if (static_cast<uint32_t>(timestamp - prevTimestamp) == 0x80000000) if (static_cast<uint32_t>(timestamp - prevTimestamp) == 0x80000000)
{
return timestamp > prevTimestamp; return timestamp > prevTimestamp;
}
return timestamp != prevTimestamp && return (
static_cast<uint32_t>(timestamp - prevTimestamp) < 0x80000000; timestamp != prevTimestamp && static_cast<uint32_t>(timestamp - prevTimestamp) < 0x80000000);
} }
static uint32_t LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2) static uint32_t LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2)
...@@ -346,12 +362,18 @@ namespace Utils ...@@ -346,12 +362,18 @@ namespace Utils
static bool IsPositiveInteger(const json& value) static bool IsPositiveInteger(const json& value)
{ {
if (value.is_number_unsigned()) if (value.is_number_unsigned())
{
return true; return true;
}
else if (value.is_number_integer()) else if (value.is_number_integer())
{
return value.get<int64_t>() >= 0; return value.get<int64_t>() >= 0;
}
else else
{
return false; return false;
} }
}
}; };
} // namespace Utils } // namespace Utils
......
...@@ -37,6 +37,7 @@ namespace Channel ...@@ -37,6 +37,7 @@ namespace Channel
{ "transport.connect", ChannelRequest::MethodId::TRANSPORT_CONNECT }, { "transport.connect", ChannelRequest::MethodId::TRANSPORT_CONNECT },
{ "transport.setMaxIncomingBitrate", ChannelRequest::MethodId::TRANSPORT_SET_MAX_INCOMING_BITRATE }, { "transport.setMaxIncomingBitrate", ChannelRequest::MethodId::TRANSPORT_SET_MAX_INCOMING_BITRATE },
{ "transport.setMaxOutgoingBitrate", ChannelRequest::MethodId::TRANSPORT_SET_MAX_OUTGOING_BITRATE }, { "transport.setMaxOutgoingBitrate", ChannelRequest::MethodId::TRANSPORT_SET_MAX_OUTGOING_BITRATE },
{ "transport.setMinOutgoingBitrate", ChannelRequest::MethodId::TRANSPORT_SET_MIN_OUTGOING_BITRATE },
{ "transport.restartIce", ChannelRequest::MethodId::TRANSPORT_RESTART_ICE }, { "transport.restartIce", ChannelRequest::MethodId::TRANSPORT_RESTART_ICE },
{ "transport.produce", ChannelRequest::MethodId::TRANSPORT_PRODUCE }, { "transport.produce", ChannelRequest::MethodId::TRANSPORT_PRODUCE },
{ "transport.consume", ChannelRequest::MethodId::TRANSPORT_CONSUME }, { "transport.consume", ChannelRequest::MethodId::TRANSPORT_CONSUME },
......
...@@ -69,7 +69,9 @@ namespace RTC ...@@ -69,7 +69,9 @@ namespace RTC
if (jsonInitialAvailableOutgoingBitrateIt != data.end()) if (jsonInitialAvailableOutgoingBitrateIt != data.end())
{ {
if (!Utils::Json::IsPositiveInteger(*jsonInitialAvailableOutgoingBitrateIt)) if (!Utils::Json::IsPositiveInteger(*jsonInitialAvailableOutgoingBitrateIt))
{
MS_THROW_TYPE_ERROR("wrong initialAvailableOutgoingBitrate (not a number)"); MS_THROW_TYPE_ERROR("wrong initialAvailableOutgoingBitrate (not a number)");
}
this->initialAvailableOutgoingBitrate = jsonInitialAvailableOutgoingBitrateIt->get<uint32_t>(); this->initialAvailableOutgoingBitrate = jsonInitialAvailableOutgoingBitrateIt->get<uint32_t>();
} }
...@@ -163,7 +165,9 @@ namespace RTC ...@@ -163,7 +165,9 @@ namespace RTC
bool isDataChannel{ false }; bool isDataChannel{ false };
if (jsonIsDataChannelIt != data.end() && jsonIsDataChannelIt->is_boolean()) if (jsonIsDataChannelIt != data.end() && jsonIsDataChannelIt->is_boolean())
{
isDataChannel = jsonIsDataChannelIt->get<bool>(); isDataChannel = jsonIsDataChannelIt->get<bool>();
}
// This may throw. // This may throw.
this->sctpAssociation = new RTC::SctpAssociation( this->sctpAssociation = new RTC::SctpAssociation(
...@@ -382,20 +386,30 @@ namespace RTC ...@@ -382,20 +386,30 @@ namespace RTC
auto jsonRtpHeaderExtensionsIt = jsonObject.find("recvRtpHeaderExtensions"); auto jsonRtpHeaderExtensionsIt = jsonObject.find("recvRtpHeaderExtensions");
if (this->recvRtpHeaderExtensionIds.mid != 0u) if (this->recvRtpHeaderExtensionIds.mid != 0u)
{
(*jsonRtpHeaderExtensionsIt)["mid"] = this->recvRtpHeaderExtensionIds.mid; (*jsonRtpHeaderExtensionsIt)["mid"] = this->recvRtpHeaderExtensionIds.mid;
}
if (this->recvRtpHeaderExtensionIds.rid != 0u) if (this->recvRtpHeaderExtensionIds.rid != 0u)
{
(*jsonRtpHeaderExtensionsIt)["rid"] = this->recvRtpHeaderExtensionIds.rid; (*jsonRtpHeaderExtensionsIt)["rid"] = this->recvRtpHeaderExtensionIds.rid;
}
if (this->recvRtpHeaderExtensionIds.rrid != 0u) if (this->recvRtpHeaderExtensionIds.rrid != 0u)
{
(*jsonRtpHeaderExtensionsIt)["rrid"] = this->recvRtpHeaderExtensionIds.rrid; (*jsonRtpHeaderExtensionsIt)["rrid"] = this->recvRtpHeaderExtensionIds.rrid;
}
if (this->recvRtpHeaderExtensionIds.absSendTime != 0u) if (this->recvRtpHeaderExtensionIds.absSendTime != 0u)
{
(*jsonRtpHeaderExtensionsIt)["absSendTime"] = this->recvRtpHeaderExtensionIds.absSendTime; (*jsonRtpHeaderExtensionsIt)["absSendTime"] = this->recvRtpHeaderExtensionIds.absSendTime;
}
if (this->recvRtpHeaderExtensionIds.transportWideCc01 != 0u) if (this->recvRtpHeaderExtensionIds.transportWideCc01 != 0u)
{
(*jsonRtpHeaderExtensionsIt)["transportWideCc01"] = (*jsonRtpHeaderExtensionsIt)["transportWideCc01"] =
this->recvRtpHeaderExtensionIds.transportWideCc01; this->recvRtpHeaderExtensionIds.transportWideCc01;
}
// Add rtpListener. // Add rtpListener.
this->rtpListener.FillJson(jsonObject["rtpListener"]); this->rtpListener.FillJson(jsonObject["rtpListener"]);
...@@ -437,9 +451,14 @@ namespace RTC ...@@ -437,9 +451,14 @@ namespace RTC
std::ostringstream traceEventTypesStream; std::ostringstream traceEventTypesStream;
if (this->traceEventTypes.probation) if (this->traceEventTypes.probation)
{
traceEventTypes.emplace_back("probation"); traceEventTypes.emplace_back("probation");
}
if (this->traceEventTypes.bwe) if (this->traceEventTypes.bwe)
{
traceEventTypes.emplace_back("bwe"); traceEventTypes.emplace_back("bwe");
}
if (!traceEventTypes.empty()) if (!traceEventTypes.empty())
{ {
...@@ -535,24 +554,34 @@ namespace RTC ...@@ -535,24 +554,34 @@ namespace RTC
// Add availableOutgoingBitrate. // Add availableOutgoingBitrate.
if (this->tccClient) if (this->tccClient)
{
jsonObject["availableOutgoingBitrate"] = this->tccClient->GetAvailableBitrate(); jsonObject["availableOutgoingBitrate"] = this->tccClient->GetAvailableBitrate();
}
// Add availableIncomingBitrate. // Add availableIncomingBitrate.
if (this->tccServer && this->tccServer->GetAvailableBitrate() != 0u) if (this->tccServer && this->tccServer->GetAvailableBitrate() != 0u)
{
jsonObject["availableIncomingBitrate"] = this->tccServer->GetAvailableBitrate(); jsonObject["availableIncomingBitrate"] = this->tccServer->GetAvailableBitrate();
}
// Add maxIncomingBitrate. // Add maxIncomingBitrate.
if (this->maxIncomingBitrate != 0u) if (this->maxIncomingBitrate != 0u)
{
jsonObject["maxIncomingBitrate"] = this->maxIncomingBitrate; jsonObject["maxIncomingBitrate"] = this->maxIncomingBitrate;
}
// Add packetLossReceived. // Add packetLossReceived.
if (this->tccServer) if (this->tccServer)
{
jsonObject["rtpPacketLossReceived"] = this->tccServer->GetPacketLoss(); jsonObject["rtpPacketLossReceived"] = this->tccServer->GetPacketLoss();
}
// Add packetLossSent. // Add packetLossSent.
if (this->tccClient) if (this->tccClient)
{
jsonObject["rtpPacketLossSent"] = this->tccClient->GetPacketLoss(); jsonObject["rtpPacketLossSent"] = this->tccClient->GetPacketLoss();
} }
}
void Transport::HandleRequest(Channel::ChannelRequest* request) void Transport::HandleRequest(Channel::ChannelRequest* request)
{ {
...@@ -603,7 +632,9 @@ namespace RTC ...@@ -603,7 +632,9 @@ namespace RTC
request->Accept(); request->Accept();
if (this->tccServer) if (this->tccServer)
{
this->tccServer->SetMaxIncomingBitrate(this->maxIncomingBitrate); this->tccServer->SetMaxIncomingBitrate(this->maxIncomingBitrate);
}
break; break;
} }
...@@ -624,10 +655,17 @@ namespace RTC ...@@ -624,10 +655,17 @@ namespace RTC
const uint32_t bitrate = jsonBitrateIt->get<uint32_t>(); const uint32_t bitrate = jsonBitrateIt->get<uint32_t>();
if (bitrate < RTC::TransportCongestionControlMinOutgoingBitrate) if (bitrate > 0u && bitrate < RTC::TransportCongestionControlMinOutgoingBitrate)
{ {
MS_THROW_TYPE_ERROR( MS_THROW_TYPE_ERROR(
"bitrate must be >= %" PRIu32 " bps", RTC::TransportCongestionControlMinOutgoingBitrate); "bitrate must be >= %" PRIu32 " or 0 (unlimited)",
RTC::TransportCongestionControlMinOutgoingBitrate);
}
else if (bitrate > 0u && bitrate < this->minOutgoingBitrate)
{
MS_THROW_TYPE_ERROR(
"bitrate must be >= current min outgoing bitrate (%" PRIu32 ") or 0 (unlimited)",
this->minOutgoingBitrate);
} }
if (this->tccClient) if (this->tccClient)
...@@ -651,6 +689,56 @@ namespace RTC ...@@ -651,6 +689,56 @@ namespace RTC
break; break;
} }
case Channel::ChannelRequest::MethodId::TRANSPORT_SET_MIN_OUTGOING_BITRATE:
{
auto jsonBitrateIt = request->data.find("bitrate");
// clang-format off
if (
jsonBitrateIt == request->data.end() ||
!Utils::Json::IsPositiveInteger(*jsonBitrateIt)
)
// clang-format on
{
MS_THROW_TYPE_ERROR("missing bitrate");
}
const uint32_t bitrate = jsonBitrateIt->get<uint32_t>();
if (bitrate > 0u && bitrate < RTC::TransportCongestionControlMinOutgoingBitrate)
{
MS_THROW_TYPE_ERROR(
"bitrate must be >= %" PRIu32 " or 0 (unlimited)",
RTC::TransportCongestionControlMinOutgoingBitrate);
}
else if (bitrate > 0u && this->maxOutgoingBitrate > 0 && bitrate > this->maxOutgoingBitrate)
{
MS_THROW_TYPE_ERROR(
"bitrate must be <= current max outgoing bitrate (%" PRIu32 ") or 0 (unlimited)",
this->maxOutgoingBitrate);
}
if (this->tccClient)
{
// NOTE: This may throw so don't update things before calling this
// method.
this->tccClient->SetMinOutgoingBitrate(bitrate);
this->minOutgoingBitrate = bitrate;
MS_DEBUG_TAG(bwe, "minimum outgoing bitrate set to %" PRIu32, this->minOutgoingBitrate);
ComputeOutgoingDesiredBitrate();
}
else
{
this->minOutgoingBitrate = bitrate;
}
request->Accept();
break;
}
case Channel::ChannelRequest::MethodId::TRANSPORT_PRODUCE: case Channel::ChannelRequest::MethodId::TRANSPORT_PRODUCE:
{ {
std::string producerId; std::string producerId;
...@@ -799,12 +887,16 @@ namespace RTC ...@@ -799,12 +887,16 @@ namespace RTC
std::make_shared<RTC::TransportCongestionControlServer>(this, bweType, RTC::MtuSize); std::make_shared<RTC::TransportCongestionControlServer>(this, bweType, RTC::MtuSize);
if (this->maxIncomingBitrate != 0u) if (this->maxIncomingBitrate != 0u)
{
this->tccServer->SetMaxIncomingBitrate(this->maxIncomingBitrate); this->tccServer->SetMaxIncomingBitrate(this->maxIncomingBitrate);
}
if (IsConnected()) if (IsConnected())
{
this->tccServer->TransportConnected(); this->tccServer->TransportConnected();
} }
} }
}
break; break;
} }
...@@ -828,7 +920,9 @@ namespace RTC ...@@ -828,7 +920,9 @@ namespace RTC
auto jsonTypeIt = request->data.find("type"); auto jsonTypeIt = request->data.find("type");
if (jsonTypeIt == request->data.end() || !jsonTypeIt->is_string()) if (jsonTypeIt == request->data.end() || !jsonTypeIt->is_string())
{
MS_THROW_TYPE_ERROR("missing type"); MS_THROW_TYPE_ERROR("missing type");
}
// This may throw. // This may throw.
auto type = RTC::RtpParameters::GetType(jsonTypeIt->get<std::string>()); auto type = RTC::RtpParameters::GetType(jsonTypeIt->get<std::string>());
...@@ -1002,17 +1096,25 @@ namespace RTC ...@@ -1002,17 +1096,25 @@ namespace RTC
}; };
this->tccClient = std::make_shared<RTC::TransportCongestionControlClient>( this->tccClient = std::make_shared<RTC::TransportCongestionControlClient>(
this, bweType, this->initialAvailableOutgoingBitrate, this->maxOutgoingBitrate); this,
bweType,
this->initialAvailableOutgoingBitrate,
this->maxOutgoingBitrate,
this->minOutgoingBitrate);
if (IsConnected()) if (IsConnected())
{
this->tccClient->TransportConnected(); this->tccClient->TransportConnected();
} }
} }
}
// If applicable, tell the new Consumer that we are gonna manage its // If applicable, tell the new Consumer that we are gonna manage its
// bitrate. // bitrate.
if (this->tccClient) if (this->tccClient)
{
consumer->SetExternallyManagedBitrate(); consumer->SetExternallyManagedBitrate();
}
#ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
// Create SenderBandwidthEstimator if: // Create SenderBandwidthEstimator if:
...@@ -1052,17 +1154,23 @@ namespace RTC ...@@ -1052,17 +1154,23 @@ namespace RTC
this, this->initialAvailableOutgoingBitrate); this, this->initialAvailableOutgoingBitrate);
if (IsConnected()) if (IsConnected())
{
this->senderBwe->TransportConnected(); this->senderBwe->TransportConnected();
} }
}
// If applicable, tell the new Consumer that we are gonna manage its // If applicable, tell the new Consumer that we are gonna manage its
// bitrate. // bitrate.
if (this->senderBwe) if (this->senderBwe)
{
consumer->SetExternallyManagedBitrate(); consumer->SetExternallyManagedBitrate();
}
#endif #endif
if (IsConnected()) if (IsConnected())
{
consumer->TransportConnected(); consumer->TransportConnected();
}
break; break;
} }
...@@ -1255,7 +1363,9 @@ namespace RTC ...@@ -1255,7 +1363,9 @@ namespace RTC
request->Accept(data); request->Accept(data);
if (IsConnected()) if (IsConnected())
{
dataConsumer->TransportConnected(); dataConsumer->TransportConnected();
}
if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP) if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
{ {
...@@ -1277,7 +1387,9 @@ namespace RTC ...@@ -1277,7 +1387,9 @@ namespace RTC
// Disable all if no entries. // Disable all if no entries.
if (jsonTypesIt == request->data.end() || !jsonTypesIt->is_array()) if (jsonTypesIt == request->data.end() || !jsonTypesIt->is_array())
{
MS_THROW_TYPE_ERROR("wrong types (not an array)"); MS_THROW_TYPE_ERROR("wrong types (not an array)");
}
// Reset traceEventTypes. // Reset traceEventTypes.
struct TraceEventTypes newTraceEventTypes; struct TraceEventTypes newTraceEventTypes;
...@@ -1285,15 +1397,21 @@ namespace RTC ...@@ -1285,15 +1397,21 @@ namespace RTC
for (const auto& type : *jsonTypesIt) for (const auto& type : *jsonTypesIt)
{ {
if (!type.is_string()) if (!type.is_string())
{
MS_THROW_TYPE_ERROR("wrong type (not a string)"); MS_THROW_TYPE_ERROR("wrong type (not a string)");
}
const std::string typeStr = type.get<std::string>(); const std::string typeStr = type.get<std::string>();
if (typeStr == "probation") if (typeStr == "probation")
{
newTraceEventTypes.probation = true; newTraceEventTypes.probation = true;
}
if (typeStr == "bwe") if (typeStr == "bwe")
{
newTraceEventTypes.bwe = true; newTraceEventTypes.bwe = true;
} }
}
this->traceEventTypes = newTraceEventTypes; this->traceEventTypes = newTraceEventTypes;
...@@ -1321,8 +1439,10 @@ namespace RTC ...@@ -1321,8 +1439,10 @@ namespace RTC
RecvStreamClosed(rtpStream->GetSsrc()); RecvStreamClosed(rtpStream->GetSsrc());
if (rtpStream->HasRtx()) if (rtpStream->HasRtx())
{
RecvStreamClosed(rtpStream->GetRtxSsrc()); RecvStreamClosed(rtpStream->GetRtxSsrc());
} }
}
// Notify the listener. // Notify the listener.
this->listener->OnTransportProducerClosed(this, producer); this->listener->OnTransportProducerClosed(this, producer);
...@@ -1371,9 +1491,12 @@ namespace RTC ...@@ -1371,9 +1491,12 @@ namespace RTC
request->Accept(); request->Accept();
// This may be the latest active Consumer with BWE. If so we have to stop probation. // This may be the latest active Consumer with BWE. If so we have to stop
// probation.
if (this->tccClient) if (this->tccClient)
{
ComputeOutgoingDesiredBitrate(/*forceBitrate*/ true); ComputeOutgoingDesiredBitrate(/*forceBitrate*/ true);
}
break; break;
} }
...@@ -1493,23 +1616,31 @@ namespace RTC ...@@ -1493,23 +1616,31 @@ namespace RTC
// Tell the SctpAssociation. // Tell the SctpAssociation.
if (this->sctpAssociation) if (this->sctpAssociation)
{
this->sctpAssociation->TransportConnected(); this->sctpAssociation->TransportConnected();
}
// Start the RTCP timer. // Start the RTCP timer.
this->rtcpTimer->Start(static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs / 2)); this->rtcpTimer->Start(static_cast<uint64_t>(RTC::RTCP::MaxVideoIntervalMs / 2));
// Tell the TransportCongestionControlClient. // Tell the TransportCongestionControlClient.
if (this->tccClient) if (this->tccClient)
{
this->tccClient->TransportConnected(); this->tccClient->TransportConnected();
}
// Tell the TransportCongestionControlServer. // Tell the TransportCongestionControlServer.
if (this->tccServer) if (this->tccServer)
{
this->tccServer->TransportConnected(); this->tccServer->TransportConnected();
}
#ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
// Tell the SenderBandwidthEstimator. // Tell the SenderBandwidthEstimator.
if (this->senderBwe) if (this->senderBwe)
{
this->senderBwe->TransportConnected(); this->senderBwe->TransportConnected();
}
#endif #endif
} }
...@@ -1538,16 +1669,22 @@ namespace RTC ...@@ -1538,16 +1669,22 @@ namespace RTC
// Tell the TransportCongestionControlClient. // Tell the TransportCongestionControlClient.
if (this->tccClient) if (this->tccClient)
{
this->tccClient->TransportDisconnected(); this->tccClient->TransportDisconnected();
}
// Tell the TransportCongestionControlServer. // Tell the TransportCongestionControlServer.
if (this->tccServer) if (this->tccServer)
{
this->tccServer->TransportDisconnected(); this->tccServer->TransportDisconnected();
}
#ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
// Tell the SenderBandwidthEstimator. // Tell the SenderBandwidthEstimator.
if (this->senderBwe) if (this->senderBwe)
{
this->senderBwe->TransportDisconnected(); this->senderBwe->TransportDisconnected();
}
#endif #endif
} }
...@@ -1566,7 +1703,9 @@ namespace RTC ...@@ -1566,7 +1703,9 @@ namespace RTC
// Feed the TransportCongestionControlServer. // Feed the TransportCongestionControlServer.
if (this->tccServer) if (this->tccServer)
{
this->tccServer->IncomingPacket(nowMs, packet); this->tccServer->IncomingPacket(nowMs, packet);
}
// Get the associated Producer. // Get the associated Producer.
RTC::Producer* producer = this->rtpListener.GetProducer(packet); RTC::Producer* producer = this->rtpListener.GetProducer(packet);
...@@ -1679,7 +1818,9 @@ namespace RTC ...@@ -1679,7 +1818,9 @@ namespace RTC
auto it = this->mapProducers.find(jsonProducerIdIt->get<std::string>()); auto it = this->mapProducers.find(jsonProducerIdIt->get<std::string>());
if (it == this->mapProducers.end()) if (it == this->mapProducers.end())
{
MS_THROW_ERROR("Producer not found"); MS_THROW_ERROR("Producer not found");
}
RTC::Producer* producer = it->second; RTC::Producer* producer = it->second;
...@@ -1719,7 +1860,9 @@ namespace RTC ...@@ -1719,7 +1860,9 @@ namespace RTC
auto it = this->mapConsumers.find(jsonConsumerIdIt->get<std::string>()); auto it = this->mapConsumers.find(jsonConsumerIdIt->get<std::string>());
if (it == this->mapConsumers.end()) if (it == this->mapConsumers.end())
{
MS_THROW_ERROR("Consumer not found"); MS_THROW_ERROR("Consumer not found");
}
RTC::Consumer* consumer = it->second; RTC::Consumer* consumer = it->second;
...@@ -1733,7 +1876,9 @@ namespace RTC ...@@ -1733,7 +1876,9 @@ namespace RTC
auto mapSsrcConsumerIt = this->mapSsrcConsumer.find(ssrc); auto mapSsrcConsumerIt = this->mapSsrcConsumer.find(ssrc);
if (mapSsrcConsumerIt == this->mapSsrcConsumer.end()) if (mapSsrcConsumerIt == this->mapSsrcConsumer.end())
{
return nullptr; return nullptr;
}
auto* consumer = mapSsrcConsumerIt->second; auto* consumer = mapSsrcConsumerIt->second;
...@@ -1747,7 +1892,9 @@ namespace RTC ...@@ -1747,7 +1892,9 @@ namespace RTC
auto mapRtxSsrcConsumerIt = this->mapRtxSsrcConsumer.find(ssrc); auto mapRtxSsrcConsumerIt = this->mapRtxSsrcConsumer.find(ssrc);
if (mapRtxSsrcConsumerIt == this->mapRtxSsrcConsumer.end()) if (mapRtxSsrcConsumerIt == this->mapRtxSsrcConsumer.end())
{
return nullptr; return nullptr;
}
auto* consumer = mapRtxSsrcConsumerIt->second; auto* consumer = mapRtxSsrcConsumerIt->second;
...@@ -1787,7 +1934,9 @@ namespace RTC ...@@ -1787,7 +1934,9 @@ namespace RTC
auto it = this->mapDataProducers.find(jsonDataProducerIdIt->get<std::string>()); auto it = this->mapDataProducers.find(jsonDataProducerIdIt->get<std::string>());
if (it == this->mapDataProducers.end()) if (it == this->mapDataProducers.end())
{
MS_THROW_ERROR("DataProducer not found"); MS_THROW_ERROR("DataProducer not found");
}
RTC::DataProducer* dataProducer = it->second; RTC::DataProducer* dataProducer = it->second;
...@@ -1827,7 +1976,9 @@ namespace RTC ...@@ -1827,7 +1976,9 @@ namespace RTC
auto it = this->mapDataConsumers.find(jsonDataConsumerIdIt->get<std::string>()); auto it = this->mapDataConsumers.find(jsonDataConsumerIdIt->get<std::string>());
if (it == this->mapDataConsumers.end()) if (it == this->mapDataConsumers.end())
{
MS_THROW_ERROR("DataConsumer not found"); MS_THROW_ERROR("DataConsumer not found");
}
RTC::DataConsumer* dataConsumer = it->second; RTC::DataConsumer* dataConsumer = it->second;
...@@ -2085,12 +2236,16 @@ namespace RTC ...@@ -2085,12 +2236,16 @@ namespace RTC
auto* feedback = static_cast<RTC::RTCP::FeedbackRtpTransportPacket*>(packet); auto* feedback = static_cast<RTC::RTCP::FeedbackRtpTransportPacket*>(packet);
if (this->tccClient) if (this->tccClient)
{
this->tccClient->ReceiveRtcpTransportFeedback(feedback); this->tccClient->ReceiveRtcpTransportFeedback(feedback);
}
#ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR #ifdef ENABLE_RTC_SENDER_BANDWIDTH_ESTIMATOR
// Pass it to the SenderBandwidthEstimator client. // Pass it to the SenderBandwidthEstimator client.
if (this->senderBwe) if (this->senderBwe)
{
this->senderBwe->ReceiveRtcpTransportFeedback(feedback); this->senderBwe->ReceiveRtcpTransportFeedback(feedback);
}
#endif #endif
break; break;
...@@ -2176,7 +2331,9 @@ namespace RTC ...@@ -2176,7 +2331,9 @@ namespace RTC
// SSRC should be filled in the sub-block. // SSRC should be filled in the sub-block.
if (ssrcInfo->GetSsrc() == 0) if (ssrcInfo->GetSsrc() == 0)
{
ssrcInfo->SetSsrc(xr->GetSsrc()); ssrcInfo->SetSsrc(xr->GetSsrc());
}
auto* producer = this->rtpListener.GetProducer(ssrcInfo->GetSsrc()); auto* producer = this->rtpListener.GetProducer(ssrcInfo->GetSsrc());
...@@ -2293,12 +2450,16 @@ namespace RTC ...@@ -2293,12 +2450,16 @@ namespace RTC
auto priority = consumer->GetBitratePriority(); auto priority = consumer->GetBitratePriority();
if (priority > 0u) if (priority > 0u)
{
multimapPriorityConsumer.emplace(priority, consumer); multimapPriorityConsumer.emplace(priority, consumer);
} }
}
// Nobody wants bitrate. Exit. // Nobody wants bitrate. Exit.
if (multimapPriorityConsumer.empty()) if (multimapPriorityConsumer.empty())
{
return; return;
}
bool baseAllocation = true; bool baseAllocation = true;
uint32_t availableBitrate = this->tccClient->GetAvailableBitrate(); uint32_t availableBitrate = this->tccClient->GetAvailableBitrate();
...@@ -2334,13 +2495,17 @@ namespace RTC ...@@ -2334,13 +2495,17 @@ namespace RTC
// Exit the loop fast if used bitrate is 0. // Exit the loop fast if used bitrate is 0.
if (usedBitrate == 0u) if (usedBitrate == 0u)
{
break; break;
} }
} }
}
// If no Consumer used bitrate, exit the loop. // If no Consumer used bitrate, exit the loop.
if (availableBitrate == previousAvailableBitrate) if (availableBitrate == previousAvailableBitrate)
{
break; break;
}
baseAllocation = false; baseAllocation = false;
} }
...@@ -2382,7 +2547,9 @@ namespace RTC ...@@ -2382,7 +2547,9 @@ namespace RTC
MS_TRACE(); MS_TRACE();
if (!this->traceEventTypes.probation) if (!this->traceEventTypes.probation)
{
return; return;
}
json data = json::object(); json data = json::object();
...@@ -2401,7 +2568,9 @@ namespace RTC ...@@ -2401,7 +2568,9 @@ namespace RTC
MS_TRACE(); MS_TRACE();
if (!this->traceEventTypes.bwe) if (!this->traceEventTypes.bwe)
{
return; return;
}
json data = json::object(); json data = json::object();
...@@ -2740,8 +2909,10 @@ namespace RTC ...@@ -2740,8 +2909,10 @@ namespace RTC
// This may be the latest active Consumer with BWE. If so we have to stop probation. // This may be the latest active Consumer with BWE. If so we have to stop probation.
if (this->tccClient) if (this->tccClient)
{
ComputeOutgoingDesiredBitrate(/*forceBitrate*/ true); ComputeOutgoingDesiredBitrate(/*forceBitrate*/ true);
} }
}
inline void Transport::OnDataProducerMessageReceived( inline void Transport::OnDataProducerMessageReceived(
RTC::DataProducer* dataProducer, uint32_t ppid, const uint8_t* msg, size_t len) RTC::DataProducer* dataProducer, uint32_t ppid, const uint8_t* msg, size_t len)
...@@ -2870,11 +3041,15 @@ namespace RTC ...@@ -2870,11 +3041,15 @@ namespace RTC
// its destructor is called first and then the parent Transport's destructor, // its destructor is called first and then the parent Transport's destructor,
// and we would end here calling SendSctpData() which is an abstract method. // and we would end here calling SendSctpData() which is an abstract method.
if (this->destroying) if (this->destroying)
{
return; return;
}
if (this->sctpAssociation) if (this->sctpAssociation)
{
SendSctpData(data, len); SendSctpData(data, len);
} }
}
inline void Transport::OnSctpAssociationMessageReceived( inline void Transport::OnSctpAssociationMessageReceived(
RTC::SctpAssociation* /*sctpAssociation*/, RTC::SctpAssociation* /*sctpAssociation*/,
...@@ -2916,9 +3091,11 @@ namespace RTC ...@@ -2916,9 +3091,11 @@ namespace RTC
auto* dataConsumer = kv.second; auto* dataConsumer = kv.second;
if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP) if (dataConsumer->GetType() == RTC::DataConsumer::Type::SCTP)
{
dataConsumer->SctpAssociationBufferedAmount(bufferedAmount); dataConsumer->SctpAssociationBufferedAmount(bufferedAmount);
} }
} }
}
inline void Transport::OnTransportCongestionControlClientBitrates( inline void Transport::OnTransportCongestionControlClientBitrates(
RTC::TransportCongestionControlClient* /*tccClient*/, RTC::TransportCongestionControlClient* /*tccClient*/,
......
...@@ -27,11 +27,12 @@ namespace RTC ...@@ -27,11 +27,12 @@ namespace RTC
RTC::TransportCongestionControlClient::Listener* listener, RTC::TransportCongestionControlClient::Listener* listener,
RTC::BweType bweType, RTC::BweType bweType,
uint32_t initialAvailableBitrate, uint32_t initialAvailableBitrate,
uint32_t maxOutgoingBitrate) uint32_t maxOutgoingBitrate,
uint32_t minOutgoingBitrate)
: listener(listener), bweType(bweType), : listener(listener), bweType(bweType),
initialAvailableBitrate(std::max<uint32_t>( initialAvailableBitrate(std::max<uint32_t>(
initialAvailableBitrate, RTC::TransportCongestionControlMinOutgoingBitrate)), initialAvailableBitrate, RTC::TransportCongestionControlMinOutgoingBitrate)),
maxOutgoingBitrate(maxOutgoingBitrate) maxOutgoingBitrate(maxOutgoingBitrate), minOutgoingBitrate(minOutgoingBitrate)
{ {
MS_TRACE(); MS_TRACE();
...@@ -281,6 +282,16 @@ namespace RTC ...@@ -281,6 +282,16 @@ namespace RTC
} }
} }
void TransportCongestionControlClient::SetMinOutgoingBitrate(uint32_t minBitrate)
{
this->minOutgoingBitrate = minBitrate;
ApplyBitrateUpdates();
this->bitrates.minBitrate = std::max<uint32_t>(
this->minOutgoingBitrate, RTC::TransportCongestionControlMinOutgoingBitrate);
}
void TransportCongestionControlClient::SetDesiredBitrate(uint32_t desiredBitrate, bool force) void TransportCongestionControlClient::SetDesiredBitrate(uint32_t desiredBitrate, bool force)
{ {
MS_TRACE(); MS_TRACE();
...@@ -305,7 +316,9 @@ namespace RTC ...@@ -305,7 +316,9 @@ namespace RTC
this->bitrates.effectiveDesiredBitrate = desiredBitrate; this->bitrates.effectiveDesiredBitrate = desiredBitrate;
#endif #endif
this->bitrates.minBitrate = RTC::TransportCongestionControlMinOutgoingBitrate; this->bitrates.minBitrate = std::max<uint32_t>(
this->minOutgoingBitrate, RTC::TransportCongestionControlMinOutgoingBitrate);
// NOTE: Setting 'startBitrate' to 'availableBitrate' has proven to generate // NOTE: Setting 'startBitrate' to 'availableBitrate' has proven to generate
// more stable values. // more stable values.
this->bitrates.startBitrate = std::max<uint32_t>( this->bitrates.startBitrate = std::max<uint32_t>(
...@@ -333,9 +346,10 @@ namespace RTC ...@@ -333,9 +346,10 @@ namespace RTC
this->bitrates.desiredBitrate * MaxBitrateIncrementFactor); this->bitrates.desiredBitrate * MaxBitrateIncrementFactor);
#endif #endif
// If max bitrate requested didn't change by more than a small % keep the previous settings // If max bitrate requested didn't change by more than a small % keep the
// to avoid constant small fluctuations requiring extra probing and making the estimation // previous settings to avoid constant small fluctuations requiring extra
// less stable (requires constant redistribution of bitrate accross consumers). // probing and making the estimation less stable (requires constant
// redistribution of bitrate accross consumers).
auto maxBitrateMargin = newMaxBitrate * MaxBitrateMarginFactor; auto maxBitrateMargin = newMaxBitrate * MaxBitrateMarginFactor;
if (currentMaxBitrate > newMaxBitrate - maxBitrateMargin && currentMaxBitrate < newMaxBitrate + maxBitrateMargin) if (currentMaxBitrate > newMaxBitrate - maxBitrateMargin && currentMaxBitrate < newMaxBitrate + maxBitrateMargin)
{ {
...@@ -358,6 +372,9 @@ namespace RTC ...@@ -358,6 +372,9 @@ namespace RTC
this->bitrates.maxBitrate = newMaxBitrate; this->bitrates.maxBitrate = newMaxBitrate;
} }
this->bitrates.minBitrate = std::max<uint32_t>(
this->minOutgoingBitrate, RTC::TransportCongestionControlMinOutgoingBitrate);
MS_DEBUG_DEV( MS_DEBUG_DEV(
"[desiredBitrate:%" PRIu32 ", desiredBitrateTrend:%" PRIu32 ", startBitrate:%" PRIu32 "[desiredBitrate:%" PRIu32 ", desiredBitrateTrend:%" PRIu32 ", startBitrate:%" PRIu32
", minBitrate:%" PRIu32 ", maxBitrate:%" PRIu32 ", maxPaddingBitrate:%" PRIu32 "]", ", minBitrate:%" PRIu32 ", maxBitrate:%" PRIu32 ", maxPaddingBitrate:%" PRIu32 "]",
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论