mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] use original resolution ratio when upgrade/downgrade source frame
This commit is contained in:
@@ -15,8 +15,22 @@ int ResolutionAdapter::GetResolution(int target_bitrate, int current_width,
|
|||||||
for (auto& resolution : GetBitrateLimits()) {
|
for (auto& resolution : GetBitrateLimits()) {
|
||||||
if (target_bitrate >= resolution.min_start_bitrate_bps &&
|
if (target_bitrate >= resolution.min_start_bitrate_bps &&
|
||||||
target_bitrate < resolution.max_bitrate_bps) {
|
target_bitrate < resolution.max_bitrate_bps) {
|
||||||
|
// Adjust the resolution to maintain the same aspect ratio as the current
|
||||||
|
// resolution
|
||||||
|
float aspect_ratio = static_cast<float>(current_width) / current_height;
|
||||||
|
if (static_cast<float>(resolution.width) / resolution.height !=
|
||||||
|
aspect_ratio) {
|
||||||
|
if (aspect_ratio > 1.0f) {
|
||||||
|
*target_width = resolution.width;
|
||||||
|
*target_height = static_cast<int>(resolution.width / aspect_ratio);
|
||||||
|
} else {
|
||||||
|
*target_height = resolution.height;
|
||||||
|
*target_width = static_cast<int>(resolution.height * aspect_ratio);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
*target_width = resolution.width;
|
*target_width = resolution.width;
|
||||||
*target_height = resolution.height;
|
*target_height = resolution.height;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ class AomAv1Encoder : public VideoEncoder {
|
|||||||
int SetTargetBitrate(int bitrate);
|
int SetTargetBitrate(int bitrate);
|
||||||
|
|
||||||
int GetResolution(int* width, int* height) {
|
int GetResolution(int* width, int* height) {
|
||||||
|
if (seq_ == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*width = frame_width_;
|
*width = frame_width_;
|
||||||
*height = frame_height_;
|
*height = frame_height_;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ class NvidiaVideoEncoder : public VideoEncoder {
|
|||||||
int SetTargetBitrate(int bitrate);
|
int SetTargetBitrate(int bitrate);
|
||||||
|
|
||||||
int GetResolution(int* width, int* height) {
|
int GetResolution(int* width, int* height) {
|
||||||
|
if (seq_ == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*width = frame_width_;
|
*width = frame_width_;
|
||||||
*height = frame_height_;
|
*height = frame_height_;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ class OpenH264Encoder : public VideoEncoder {
|
|||||||
int SetTargetBitrate(int bitrate);
|
int SetTargetBitrate(int bitrate);
|
||||||
|
|
||||||
int GetResolution(int* width, int* height) {
|
int GetResolution(int* width, int* height) {
|
||||||
|
if (seq_ == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*width = frame_width_;
|
*width = frame_width_;
|
||||||
*height = frame_height_;
|
*height = frame_height_;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -600,7 +600,11 @@ 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;
|
||||||
video_encoder_->GetResolution(&width, &height);
|
int valid = 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)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user