[fix] fix crash duo to invalid target resolution

This commit is contained in:
dijunkun
2025-04-18 15:34:03 +08:00
parent 38c88e27e0
commit fb00234498

View File

@@ -212,18 +212,17 @@ int IceTransportController::SendVideo(const XVideoFrame* video_frame) {
new_frame.height = video_frame_copy->height; new_frame.height = video_frame_copy->height;
new_frame.size = video_frame_copy->size; new_frame.size = video_frame_copy->size;
new_frame.captured_timestamp = video_frame_copy->captured_timestamp; new_frame.captured_timestamp = video_frame_copy->captured_timestamp;
if (target_width_.has_value() && target_height_.has_value()) { if (target_width_.has_value() && target_height_.has_value() &&
if (target_width_.value() < video_frame_copy->width && target_width_.value() < video_frame_copy->width &&
target_height_.value() < video_frame_copy->height) { target_height_.value() < video_frame_copy->height) {
resolution_adapter_->ResolutionDowngrade( resolution_adapter_->ResolutionDowngrade(
video_frame_copy.get(), target_width_.value(), video_frame_copy.get(), target_width_.value(),
target_height_.value(), &new_frame); target_height_.value(), &new_frame);
} else { } else {
new_frame.data = new char[video_frame_copy->size]; new_frame.data = new char[video_frame_copy->size];
memcpy((void*)new_frame.data, (void*)video_frame_copy->data, memcpy((void*)new_frame.data, video_frame_copy->data,
video_frame_copy->size); video_frame_copy->size);
} }
}
RawFrame raw_frame((const uint8_t*)new_frame.data, new_frame.size, RawFrame raw_frame((const uint8_t*)new_frame.data, new_frame.size,
new_frame.width, new_frame.height); new_frame.width, new_frame.height);
@@ -600,15 +599,12 @@ void IceTransportController::PostUpdates(webrtc::NetworkControlUpdate update) {
if (target_bitrate != target_bitrate_ && video_encoder_) { if (target_bitrate != target_bitrate_ && video_encoder_) {
target_bitrate_ = target_bitrate; target_bitrate_ = target_bitrate;
int width, height, target_width, target_height; int width, height, target_width, target_height;
int valid = video_encoder_->GetResolution(&width, &height); if (!video_encoder_->GetResolution(&width, &height)) {
if (valid != 0) {
width = source_width_;
height = source_height_;
}
if (0 == resolution_adapter_->GetResolution(target_bitrate_, width, if (0 == resolution_adapter_->GetResolution(target_bitrate_, width,
height, &target_width, height, &target_width,
&target_height)) { &target_height)) {
if (target_width != target_width_ || target_height != target_height_) { if (target_width != target_width_ ||
target_height != target_height_) {
target_width_ = target_width; target_width_ = target_width;
target_height_ = target_height; target_height_ = target_height;
@@ -618,6 +614,7 @@ void IceTransportController::PostUpdates(webrtc::NetworkControlUpdate update) {
target_width_.reset(); target_width_.reset();
target_height_.reset(); target_height_.reset();
} }
}
video_encoder_->SetTargetBitrate(target_bitrate_); video_encoder_->SetTargetBitrate(target_bitrate_);
// LOG_WARN("Set target bitrate [{}]bps", target_bitrate_); // LOG_WARN("Set target bitrate [{}]bps", target_bitrate_);
} }