mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
[feat] support FIR
This commit is contained in:
@@ -1,25 +1,36 @@
|
||||
#include "resolution_adapter.h"
|
||||
|
||||
#include "libyuv.h"
|
||||
#include "log.h"
|
||||
|
||||
int ResolutionAdapter::GetResolution(int target_bitrate, int current_width,
|
||||
int current_height, int& target_width,
|
||||
int& target_height) {
|
||||
int current_height, int* target_width,
|
||||
int* target_height) {
|
||||
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;
|
||||
*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;
|
||||
*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_width = -1;
|
||||
*target_height = -1;
|
||||
|
||||
LOG_INFO("3 source resolution {}x{}, target resolution {}x{}", current_width,
|
||||
current_height, *target_width, *target_height);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class ResolutionAdapter {
|
||||
|
||||
public:
|
||||
int GetResolution(int target_bitrate, int current_width, int current_height,
|
||||
int& target_width, int& target_height);
|
||||
int* target_width, int* target_height);
|
||||
|
||||
int ResolutionDowngrade(const XVideoFrame* video_frame, int target_width,
|
||||
int target_height, XVideoFrame* new_frame);
|
||||
|
||||
@@ -75,7 +75,7 @@ int NvidiaVideoDecoder::Decode(
|
||||
#endif
|
||||
|
||||
if ((*(data + 4) & 0x1f) == 0x07) {
|
||||
// LOG_WARN("Receive key frame");
|
||||
LOG_WARN("Receive key frame");
|
||||
}
|
||||
|
||||
int num_frame_returned = decoder->Decode(data, (int)size);
|
||||
|
||||
@@ -310,7 +310,7 @@ int AomAv1Encoder::Encode(
|
||||
frame_for_encode_->stride[AOM_PLANE_V] = 0;
|
||||
|
||||
VideoFrameType frame_type;
|
||||
if (0 == seq_++ % 300) {
|
||||
if (0 == seq_++ % key_frame_interval_) {
|
||||
force_i_frame_flags_ = AOM_EFLAG_FORCE_KF;
|
||||
frame_type = VideoFrameType::kVideoFrameKey;
|
||||
} else {
|
||||
|
||||
@@ -46,9 +46,9 @@ class AomAv1Encoder : public VideoEncoder {
|
||||
|
||||
int SetTargetBitrate(int bitrate);
|
||||
|
||||
int GetResolution(int& width, int& height) {
|
||||
width = frame_width_;
|
||||
height = frame_height_;
|
||||
int GetResolution(int* width, int* height) {
|
||||
*width = frame_width_;
|
||||
*height = frame_height_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class AomAv1Encoder : public VideoEncoder {
|
||||
private:
|
||||
uint32_t frame_width_ = 1280;
|
||||
uint32_t frame_height_ = 720;
|
||||
int key_frame_interval_ = 300;
|
||||
int key_frame_interval_ = I_FRAME_INTERVAL;
|
||||
int target_bitrate_ = 1000;
|
||||
int max_bitrate_ = 2500000;
|
||||
int max_payload_size_ = 1400;
|
||||
|
||||
@@ -151,7 +151,7 @@ int NvidiaVideoEncoder::Encode(
|
||||
}
|
||||
|
||||
VideoFrameType frame_type;
|
||||
if (0 == seq_++ % 300) {
|
||||
if (0 == seq_++ % key_frame_interval_) {
|
||||
ForceIdr();
|
||||
frame_type = VideoFrameType::kVideoFrameKey;
|
||||
} else {
|
||||
@@ -263,6 +263,7 @@ 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};
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <functional>
|
||||
|
||||
#include "NvEncoderCuda.h"
|
||||
#include "log.h"
|
||||
#include "video_encoder.h"
|
||||
|
||||
class NvidiaVideoEncoder : public VideoEncoder {
|
||||
@@ -22,9 +23,9 @@ class NvidiaVideoEncoder : public VideoEncoder {
|
||||
|
||||
int SetTargetBitrate(int bitrate);
|
||||
|
||||
int GetResolution(int& width, int& height) {
|
||||
width = frame_width_;
|
||||
height = frame_height_;
|
||||
int GetResolution(int* width, int* height) {
|
||||
*width = frame_width_;
|
||||
*height = frame_height_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ int OpenH264Encoder::Encode(
|
||||
video_frame->height, yuv420p_frame_);
|
||||
|
||||
VideoFrameType frame_type;
|
||||
if (0 == seq_++ % 300) {
|
||||
if (0 == seq_++ % key_frame_interval_) {
|
||||
ForceIdr();
|
||||
frame_type = VideoFrameType::kVideoFrameKey;
|
||||
} else {
|
||||
|
||||
@@ -33,9 +33,9 @@ class OpenH264Encoder : public VideoEncoder {
|
||||
|
||||
int SetTargetBitrate(int bitrate);
|
||||
|
||||
int GetResolution(int& width, int& height) {
|
||||
width = frame_width_;
|
||||
height = frame_height_;
|
||||
int GetResolution(int* width, int* height) {
|
||||
*width = frame_width_;
|
||||
*height = frame_height_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class OpenH264Encoder : public VideoEncoder {
|
||||
private:
|
||||
uint32_t frame_width_ = 1280;
|
||||
uint32_t frame_height_ = 720;
|
||||
int key_frame_interval_ = 300;
|
||||
int key_frame_interval_ = 3000;
|
||||
int target_bitrate_ = 10000000;
|
||||
int max_bitrate_ = 10000000;
|
||||
int max_payload_size_ = 1400;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "video_frame_wrapper.h"
|
||||
#include "x.h"
|
||||
|
||||
#define I_FRAME_INTERVAL 3000
|
||||
class VideoEncoder {
|
||||
public:
|
||||
virtual int Init() = 0;
|
||||
@@ -24,7 +25,7 @@ class VideoEncoder {
|
||||
|
||||
virtual int SetTargetBitrate(int bitrate) = 0;
|
||||
|
||||
virtual int GetResolution(int& width, int& height) = 0;
|
||||
virtual int GetResolution(int* width, int* height) = 0;
|
||||
|
||||
virtual std::string GetEncoderName() = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user