mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[fix] fix resolution adapter
This commit is contained in:
@@ -681,8 +681,8 @@ int NvDecoder::HandlePictureDisplay(CUVIDPARSERDISPINFO *pDispInfo) {
|
||||
if (result == CUDA_SUCCESS &&
|
||||
(DecodeStatus.decodeStatus == cuvidDecodeStatus_Error ||
|
||||
DecodeStatus.decodeStatus == cuvidDecodeStatus_Error_Concealed)) {
|
||||
printf("Decode Error occurred for picture %d\n",
|
||||
m_nPicNumInDecodeOrder[pDispInfo->picture_index]);
|
||||
// printf("Decode Error occurred for picture %d\n",
|
||||
// m_nPicNumInDecodeOrder[pDispInfo->picture_index]);
|
||||
}
|
||||
|
||||
uint8_t *pDecodedFrame = nullptr;
|
||||
|
||||
@@ -6,31 +6,24 @@
|
||||
int ResolutionAdapter::GetResolution(int target_bitrate, int current_width,
|
||||
int current_height, int* target_width,
|
||||
int* target_height) {
|
||||
if (target_bitrate < GetBitrateLimits().front().min_start_bitrate_bps) {
|
||||
*target_width = GetBitrateLimits().front().width;
|
||||
*target_height = GetBitrateLimits().front().height;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (auto& resolution : GetBitrateLimits()) {
|
||||
if (target_bitrate >= resolution.min_start_bitrate_bps &&
|
||||
target_bitrate <= resolution.max_bitrate_bps) {
|
||||
if (current_width * current_height <= resolution.frame_size_pixels) {
|
||||
*target_width = current_width;
|
||||
*target_height = current_height;
|
||||
LOG_INFO("1 source resolution {}x{}, target resolution {}x{}",
|
||||
current_width, current_height, *target_width, *target_height);
|
||||
return 0;
|
||||
} else {
|
||||
*target_width = current_width * 3 / 5;
|
||||
*target_height = current_height * 3 / 5;
|
||||
LOG_INFO("2 source resolution {}x{}, target resolution {}x{}",
|
||||
current_width, current_height, *target_width, *target_height);
|
||||
return 0;
|
||||
}
|
||||
target_bitrate < resolution.max_bitrate_bps) {
|
||||
*target_width = resolution.width;
|
||||
*target_height = resolution.height;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
*target_width = -1;
|
||||
*target_height = -1;
|
||||
|
||||
LOG_INFO("3 source resolution {}x{}, target resolution {}x{}", current_width,
|
||||
current_height, *target_width, *target_height);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -41,8 +34,6 @@ int ResolutionAdapter::ResolutionDowngrade(const XVideoFrame* video_frame,
|
||||
return -1;
|
||||
}
|
||||
|
||||
target_width = video_frame->width * 3 / 5;
|
||||
target_height = video_frame->height * 3 / 5;
|
||||
new_frame->width = target_width;
|
||||
new_frame->height = target_height;
|
||||
new_frame->data = new char[target_width * target_height * 3 / 2];
|
||||
|
||||
@@ -26,13 +26,12 @@ class ResolutionAdapter {
|
||||
|
||||
public:
|
||||
std::vector<ResolutionBitrateLimits> GetBitrateLimits() {
|
||||
return {{0 * 0, 0, 0, 0},
|
||||
{320 * 180, 0, 30000, 300000},
|
||||
{480 * 270, 300000, 30000, 500000},
|
||||
{640 * 360, 500000, 30000, 800000},
|
||||
{960 * 540, 800000, 30000, 1500000},
|
||||
{1280 * 720, 1500000, 30000, 2500000},
|
||||
{1920 * 1080, 2500000, 30000, 4000000}};
|
||||
return {{320, 180, 0, 30000, 300000},
|
||||
{480, 270, 300000, 30000, 500000},
|
||||
{640, 360, 500000, 30000, 800000},
|
||||
{960, 540, 800000, 30000, 1500000},
|
||||
{1280, 720, 1500000, 30000, 2500000},
|
||||
{1920, 1080, 2500000, 30000, 4000000}};
|
||||
}
|
||||
|
||||
int SetTargetBitrate(int bitrate);
|
||||
|
||||
@@ -8,13 +8,15 @@
|
||||
#define _RESOLUTION_BITRATE_LIMITS_H_
|
||||
|
||||
struct ResolutionBitrateLimits {
|
||||
ResolutionBitrateLimits(int frame_size_pixels, int min_start_bitrate_bps,
|
||||
ResolutionBitrateLimits(int width, int height, int min_start_bitrate_bps,
|
||||
int min_bitrate_bps, int max_bitrate_bps)
|
||||
: frame_size_pixels(frame_size_pixels),
|
||||
: width(width),
|
||||
height(height),
|
||||
min_start_bitrate_bps(min_start_bitrate_bps),
|
||||
min_bitrate_bps(min_bitrate_bps),
|
||||
max_bitrate_bps(max_bitrate_bps) {}
|
||||
int frame_size_pixels = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int min_start_bitrate_bps = 0;
|
||||
int min_bitrate_bps = 0;
|
||||
int max_bitrate_bps = 0;
|
||||
|
||||
@@ -263,7 +263,6 @@ int NvidiaVideoEncoder::ResetEncodeResolution(unsigned int width,
|
||||
|
||||
frame_width_ = width;
|
||||
frame_height_ = height;
|
||||
LOG_WARN("Reset resolution to [{}x{}]", frame_width_, frame_height_);
|
||||
|
||||
NV_ENC_RECONFIGURE_PARAMS reconfig_params = {NV_ENC_RECONFIGURE_PARAMS_VER};
|
||||
NV_ENC_INITIALIZE_PARAMS init_params = {NV_ENC_INITIALIZE_PARAMS_VER};
|
||||
|
||||
@@ -13,8 +13,6 @@ IceTransportController::IceTransportController(
|
||||
: last_report_block_time_(
|
||||
webrtc::Timestamp::Millis(webrtc_clock_->TimeInMilliseconds())),
|
||||
b_force_i_frame_(true),
|
||||
target_width_(1280),
|
||||
target_height_(720),
|
||||
video_codec_inited_(false),
|
||||
audio_codec_inited_(false),
|
||||
load_nvcodec_dll_success_(false),
|
||||
@@ -472,13 +470,13 @@ void IceTransportController::PostUpdates(webrtc::NetworkControlUpdate update) {
|
||||
target_height_ = target_height;
|
||||
|
||||
b_force_i_frame_ = true;
|
||||
LOG_WARN("Set target resolution [{}x{}]", target_width_.value(),
|
||||
LOG_INFO("Set target resolution [{}x{}]", target_width_.value(),
|
||||
target_height_.value());
|
||||
}
|
||||
} else {
|
||||
} else if (target_width_.has_value() && target_height_.has_value()) {
|
||||
target_width_.reset();
|
||||
target_height_.reset();
|
||||
LOG_WARN("Use original resolution [{}x{}]", source_width_,
|
||||
LOG_INFO("Use original resolution [{}x{}]", source_width_,
|
||||
source_height_);
|
||||
}
|
||||
video_encoder_->SetTargetBitrate(target_bitrate_);
|
||||
|
||||
Reference in New Issue
Block a user