[feat] bandwidth probing supported

This commit is contained in:
dijunkun
2025-03-11 17:36:07 +08:00
parent 7f2ebbde5a
commit 092e894622
7 changed files with 281 additions and 34 deletions

View File

@@ -49,6 +49,7 @@ int IceTransport::InitIceTransmission(
std::string &turn_username, std::string &turn_password,
rtp::PAYLOAD_TYPE video_codec_payload_type) {
ice_transport_controller_ = std::make_shared<IceTransportController>(clock_);
ice_agent_ = std::make_unique<IceAgent>(
offer_peer_, use_trickle_ice_, use_reliable_ice_, enable_turn_,
force_turn_, stun_ip, stun_port, turn_ip, turn_port, turn_username,
@@ -642,6 +643,7 @@ std::string IceTransport::GetRemoteCapabilities(const std::string &remote_sdp) {
remote_user_id_, negotiated_video_pt_, hardware_acceleration_,
ice_agent_, ice_io_statistics_, on_receive_video_, on_receive_audio_,
on_receive_data_, user_data_);
ice_transport_controller_->Start();
}
remote_capabilities_got_ = true;

View File

@@ -18,7 +18,9 @@ IceTransportController::IceTransportController(
load_nvcodec_dll_success_(false),
hardware_acceleration_(false),
clock_(clock),
webrtc_clock_(webrtc::Clock::GetWebrtcClockShared(clock)) {}
webrtc_clock_(webrtc::Clock::GetWebrtcClockShared(clock)) {
SetPeriod(std::chrono::milliseconds(25));
}
IceTransportController::~IceTransportController() {
user_data_ = nullptr;
@@ -429,6 +431,12 @@ void IceTransportController::HandleTransportPacketsFeedback(
UpdateCongestedState();
}
void IceTransportController::UpdateControllerWithTimeInterval() {
ProcessInterval msg;
msg.at_time = Timestamp::Millis(webrtc_clock_->TimeInMilliseconds());
PostUpdates(controller_->OnProcessInterval(msg));
}
void IceTransportController::OnSentRtpPacket(
const webrtc::RtpPacketToSend& packet) {
webrtc::PacedPacketInfo pacing_info;
@@ -452,35 +460,37 @@ void IceTransportController::OnSentRtpPacket(
void IceTransportController::PostUpdates(webrtc::NetworkControlUpdate update) {
// UpdateControlState();
int target_bitrate = update.target_rate.has_value()
? (update.target_rate->target_rate.bps() == 0
? target_bitrate_
: update.target_rate->target_rate.bps())
: target_bitrate_;
if (target_bitrate != target_bitrate_) {
target_bitrate_ = target_bitrate;
int width, height, target_width, target_height;
video_encoder_->GetResolution(&width, &height);
if (update.target_rate) {
int target_bitrate = update.target_rate.has_value()
? (update.target_rate->target_rate.bps() == 0
? target_bitrate_
: update.target_rate->target_rate.bps())
: target_bitrate_;
if (target_bitrate != target_bitrate_) {
target_bitrate_ = target_bitrate;
int width, height, target_width, target_height;
video_encoder_->GetResolution(&width, &height);
if (0 == resolution_adapter_->GetResolution(target_bitrate_, width, height,
&target_width,
&target_height)) {
if (target_width != target_width_ || target_height != target_height_) {
target_width_ = target_width;
target_height_ = target_height;
if (0 == resolution_adapter_->GetResolution(target_bitrate_, width,
height, &target_width,
&target_height)) {
if (target_width != target_width_ || target_height != target_height_) {
target_width_ = target_width;
target_height_ = target_height;
b_force_i_frame_ = true;
LOG_INFO("Set target resolution [{}x{}]", target_width_.value(),
target_height_.value());
b_force_i_frame_ = true;
// LOG_INFO("Set target resolution [{}x{}]", target_width_.value(),
// target_height_.value());
}
} else if (target_width_.has_value() && target_height_.has_value()) {
target_width_.reset();
target_height_.reset();
// LOG_INFO("Use original resolution [{}x{}]", source_width_,
// source_height_);
}
} else if (target_width_.has_value() && target_height_.has_value()) {
target_width_.reset();
target_height_.reset();
LOG_INFO("Use original resolution [{}x{}]", source_width_,
source_height_);
video_encoder_->SetTargetBitrate(target_bitrate_);
LOG_WARN("Set target bitrate [{}]bps", target_bitrate_);
}
video_encoder_->SetTargetBitrate(target_bitrate_);
LOG_WARN("Set target bitrate [{}]bps", target_bitrate_);
}
}
@@ -493,3 +503,10 @@ void IceTransportController::UpdateCongestedState() {
if (controller_) {
}
}
bool IceTransportController::Process() {
webrtc::ProcessInterval msg;
msg.at_time = Timestamp::Millis(webrtc_clock_->TimeInMilliseconds());
PostUpdates(controller_->OnProcessInterval(msg));
return true;
}

View File

@@ -35,7 +35,8 @@ typedef void (*OnReceiveData)(const char *, size_t, const char *, const size_t,
void *);
class IceTransportController
: public std::enable_shared_from_this<IceTransportController> {
: public std::enable_shared_from_this<IceTransportController>,
public ThreadBase {
public:
IceTransportController(std::shared_ptr<SystemClock> clock);
~IceTransportController();
@@ -74,6 +75,7 @@ class IceTransportController
int CreateAudioCodec();
private:
void UpdateControllerWithTimeInterval();
void OnSentRtpPacket(const webrtc::RtpPacketToSend &packet);
void HandleTransportPacketsFeedback(
const webrtc::TransportPacketsFeedback &feedback);
@@ -81,6 +83,9 @@ class IceTransportController
void UpdateControlState();
void UpdateCongestedState();
private:
bool Process() override;
private:
std::unique_ptr<VideoChannelSend> video_channel_send_ = nullptr;
std::unique_ptr<AudioChannelSend> audio_channel_send_ = nullptr;