[fix] Optimizing video encoding speed for software encoders

This commit is contained in:
dijunkun
2024-08-20 17:18:29 +08:00
parent def7025abf
commit 89b12136e4
3 changed files with 10 additions and 13 deletions

View File

@@ -159,16 +159,18 @@ int Render::StartScreenCapture() {
rect.top = 0; rect.top = 0;
rect.right = screen_width_; rect.right = screen_width_;
rect.bottom = screen_height_; rect.bottom = screen_height_;
last_frame_time_ = std::chrono::steady_clock::now(); last_frame_time_ = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
int screen_capturer_init_ret = screen_capturer_->Init( int screen_capturer_init_ret = screen_capturer_->Init(
rect, 60, rect, 60,
[this](unsigned char *data, int size, int width, int height) -> void { [this](unsigned char *data, int size, int width, int height) -> void {
auto now_time = std::chrono::steady_clock::now(); auto now_time = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::duration<double> duration = now_time - last_frame_time_; std::chrono::steady_clock::now().time_since_epoch())
auto tc = duration.count() * 1000; .count();
auto duration = now_time - last_frame_time_;
if (tc >= 0 && connection_established_) { if (duration >= 0 && connection_established_) {
SendData(peer_, DATA_TYPE::VIDEO, (const char *)data, SendData(peer_, DATA_TYPE::VIDEO, (const char *)data,
NV12_BUFFER_SIZE); NV12_BUFFER_SIZE);
last_frame_time_ = now_time; last_frame_time_ = now_time;

View File

@@ -249,12 +249,7 @@ class Render {
SpeakerCapturer *speaker_capturer_ = nullptr; SpeakerCapturer *speaker_capturer_ = nullptr;
DeviceControllerFactory *device_controller_factory_ = nullptr; DeviceControllerFactory *device_controller_factory_ = nullptr;
MouseController *mouse_controller_ = nullptr; MouseController *mouse_controller_ = nullptr;
uint32_t last_frame_time_;
#ifdef __linux__
std::chrono::_V2::system_clock::time_point last_frame_time_;
#else
std::chrono::steady_clock::time_point last_frame_time_;
#endif
private: private:
char client_id_[10] = ""; char client_id_[10] = "";