mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-08-04 16:50:31 +08:00
[fix] request stream keyframes when capture resumes
This commit is contained in:
+25
-4
@@ -42,6 +42,8 @@
|
|||||||
namespace crossdesk {
|
namespace crossdesk {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
constexpr uint64_t kCaptureResumeKeyFrameGapMs = 500;
|
||||||
|
|
||||||
const ImWchar* GetMultilingualGlyphRanges() {
|
const ImWchar* GetMultilingualGlyphRanges() {
|
||||||
static std::vector<ImWchar> glyph_ranges;
|
static std::vector<ImWchar> glyph_ranges;
|
||||||
if (glyph_ranges.empty()) {
|
if (glyph_ranges.empty()) {
|
||||||
@@ -651,18 +653,37 @@ int Render::ScreenCapturerInit() {
|
|||||||
fps,
|
fps,
|
||||||
[this, fps](unsigned char* data, int size, int width, int height,
|
[this, fps](unsigned char* data, int size, int width, int height,
|
||||||
const char* display_name) -> void {
|
const char* display_name) -> void {
|
||||||
auto now_time = std::chrono::duration_cast<std::chrono::milliseconds>(
|
const auto now_time =
|
||||||
std::chrono::steady_clock::now().time_since_epoch())
|
static_cast<uint64_t>(std::chrono::duration_cast<
|
||||||
.count();
|
std::chrono::milliseconds>(
|
||||||
|
std::chrono::steady_clock::now()
|
||||||
|
.time_since_epoch())
|
||||||
|
.count());
|
||||||
auto duration = now_time - last_frame_time_;
|
auto duration = now_time - last_frame_time_;
|
||||||
if (duration * fps >= 1000) { // ~60 FPS
|
if (duration * fps >= 1000) { // ~60 FPS
|
||||||
|
const std::string stream_id = display_name ? display_name : "";
|
||||||
|
const bool resumed_after_gap =
|
||||||
|
last_frame_time_ != 0 &&
|
||||||
|
duration >= kCaptureResumeKeyFrameGapMs;
|
||||||
|
const bool stream_changed =
|
||||||
|
!last_video_frame_stream_id_.empty() &&
|
||||||
|
last_video_frame_stream_id_ != stream_id;
|
||||||
|
if (resumed_after_gap || stream_changed) {
|
||||||
|
if (RequestVideoKeyFrame(peer_, stream_id.c_str()) == 0) {
|
||||||
|
LOG_INFO(
|
||||||
|
"Request video key frame before sending captured frame, "
|
||||||
|
"stream='{}', gap_ms={}, stream_changed={}",
|
||||||
|
stream_id, duration, stream_changed);
|
||||||
|
}
|
||||||
|
}
|
||||||
XVideoFrame frame;
|
XVideoFrame frame;
|
||||||
frame.data = (const char*)data;
|
frame.data = (const char*)data;
|
||||||
frame.size = size;
|
frame.size = size;
|
||||||
frame.width = width;
|
frame.width = width;
|
||||||
frame.height = height;
|
frame.height = height;
|
||||||
frame.captured_timestamp = GetSystemTimeMicros(peer_);
|
frame.captured_timestamp = GetSystemTimeMicros(peer_);
|
||||||
SendVideoFrame(peer_, &frame, display_name);
|
SendVideoFrame(peer_, &frame, stream_id.c_str());
|
||||||
|
last_video_frame_stream_id_ = stream_id;
|
||||||
last_frame_time_ = now_time;
|
last_frame_time_ = now_time;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -672,6 +672,7 @@ class Render {
|
|||||||
KeyboardCapturer* keyboard_capturer_ = nullptr;
|
KeyboardCapturer* keyboard_capturer_ = nullptr;
|
||||||
std::vector<DisplayInfo> display_info_list_;
|
std::vector<DisplayInfo> display_info_list_;
|
||||||
uint64_t last_frame_time_;
|
uint64_t last_frame_time_;
|
||||||
|
std::string last_video_frame_stream_id_;
|
||||||
bool show_new_version_icon_ = false;
|
bool show_new_version_icon_ = false;
|
||||||
bool show_new_version_icon_in_menu_ = true;
|
bool show_new_version_icon_in_menu_ = true;
|
||||||
double new_version_icon_last_trigger_time_ = 0.0;
|
double new_version_icon_last_trigger_time_ = 0.0;
|
||||||
|
|||||||
Reference in New Issue
Block a user