From 812617312839782f4d90f7325a18d88b121fd1c1 Mon Sep 17 00:00:00 2001 From: Acaki Date: Tue, 15 Jul 2025 02:27:50 +0800 Subject: [PATCH] fix: overlay level hanling --- VoidLink/Stream/StreamManager.h | 2 +- VoidLink/Stream/StreamManager.m | 48 ++++++++++--------- .../StreamFrameViewController.m | 5 +- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/VoidLink/Stream/StreamManager.h b/VoidLink/Stream/StreamManager.h index 31d9246e..50345496 100644 --- a/VoidLink/Stream/StreamManager.h +++ b/VoidLink/Stream/StreamManager.h @@ -20,6 +20,6 @@ - (void) stopStream; -- (NSString*) getStatsOverlayText; +- (NSString*) getStatsOverlayText: (uint16_t) overlayLevel; @end diff --git a/VoidLink/Stream/StreamManager.m b/VoidLink/Stream/StreamManager.m index 0d83181c..3fd32341 100644 --- a/VoidLink/Stream/StreamManager.m +++ b/VoidLink/Stream/StreamManager.m @@ -154,7 +154,7 @@ return TRUE; } -- (NSString*) getStatsOverlayText { +- (NSString*) getStatsOverlayText: (uint16_t) overlayLevel { video_stats_t stats; if (!_connection) { @@ -168,7 +168,7 @@ uint32_t rtt, variance; NSString* latencyString; if (LiGetEstimatedRttInfo(&rtt, &variance)) { - latencyString = [NSString stringWithFormat:@"%u ms (variance: %u ms)", rtt, variance]; + latencyString = [LocalizationHelper localizedStringForKey:@"%u ms (variance: %u ms)", rtt, variance]; } else { latencyString = @"N/A"; @@ -176,7 +176,7 @@ NSString* hostProcessingString; if (stats.framesWithHostProcessingLatency != 0) { - hostProcessingString = [NSString stringWithFormat:@"Host processing latency min/max/avg: %.1f/%.1f/%.1f ms\n", + hostProcessingString = [LocalizationHelper localizedStringForKey:@"Host processing latency min/max/avg: %.1f/%.1f/%.1f ms\n", stats.minHostProcessingLatency / 10.f, stats.maxHostProcessingLatency / 10.f, (float)stats.totalHostProcessingLatency / stats.framesWithHostProcessingLatency / 10.f]; @@ -192,25 +192,29 @@ double avgVideoMbps = [_connection getBwTracker].averageMbps; double peakVideoMbps = [_connection getBwTracker].peakMbps; - - return [NSString stringWithFormat:@"Video stream: %dx%d %.2f FPS (Codec: %@)\n" - "Bitrate: %.1f Mbps, Peak: %.1f, Renderer: %@\n" - "%@" - "Frames buffered: %.1f, Present \n" - "Frames dropped by network/pacing jitter: %.1f%% / %.1f%%\n" - "Average network latency: %@\n" - "Decode time: %.2f/%.2f/%.2f ms", - _config.width, - _config.height, - fps, - [_connection getActiveCodecName], - avgVideoMbps, peakVideoMbps, (stats.renderingBackend == RENDER_METAL) ? @"Metal" : @"AVSampleBuffer", - hostProcessingString, - stats.frameQueueMetrics.avg, - (stats.networkDroppedFrames / stats.totalFrames) * 100.0, - stats.frameDropMetrics.nsamples > 0 ? (stats.frameDropMetrics.total / stats.frameDropMetrics.nsamples) * 100.0 : 0.0f, - latencyString, - stats.decodeMetrics.min, stats.decodeMetrics.max, stats.decodeMetrics.avg]; + + if(overlayLevel == 1) return [LocalizationHelper localizedStringForKey:@"FPS: %5.2f Network dropped frames: %.2f%% Network latency: %@", + stats.totalFrames / interval, + stats.networkDroppedFrames / interval, + latencyString]; + else return [LocalizationHelper localizedStringForKey:@"Video stream: %dx%d %.2f FPS (Codec: %@)\n" + "Bitrate: %.1f Mbps, Peak: %.1f, Renderer: %@\n" + "%@" + "Frames buffered: %.1f, Present \n" + "Frames dropped by network/pacing jitter: %.1f%% / %.1f%%\n" + "Average network latency: %@\n" + "Decode time: %.2f/%.2f/%.2f ms", + _config.width, + _config.height, + fps, + [_connection getActiveCodecName], + avgVideoMbps, peakVideoMbps, (stats.renderingBackend == RENDER_METAL) ? @"Metal" : @"AVSampleBuffer", + hostProcessingString, + stats.frameQueueMetrics.avg, + (stats.networkDroppedFrames / stats.totalFrames) * 100.0, + stats.frameDropMetrics.nsamples > 0 ? (stats.frameDropMetrics.total / stats.frameDropMetrics.nsamples) * 100.0 : 0.0f, + latencyString, + stats.decodeMetrics.min, stats.decodeMetrics.max, stats.decodeMetrics.avg]; } @end diff --git a/VoidLink/ViewControllers/StreamFrameViewController.m b/VoidLink/ViewControllers/StreamFrameViewController.m index ed632b92..466fde0e 100644 --- a/VoidLink/ViewControllers/StreamFrameViewController.m +++ b/VoidLink/ViewControllers/StreamFrameViewController.m @@ -56,6 +56,7 @@ UITapGestureRecognizer *_menuTapGestureRecognizer; UITapGestureRecognizer *_menuDoubleTapGestureRecognizer; UITapGestureRecognizer *_playPauseTapGestureRecognizer; + uint16_t overlayLevel; UILabel *_stageLabel; UILabel *_tipLabel; UIActivityIndicatorView *_spinner; @@ -335,6 +336,7 @@ if (reloadSettings) { _settings = [[[DataManager alloc] init] getSettings]; //StreamFrameViewController retrieve the settings here. } + overlayLevel = _settings.statsOverlayLevel.intValue; [self configOscLayoutTool]; [self updateToolboxSpecialEntries]; [self configSwipeGestures]; @@ -775,7 +777,8 @@ } else [self.view addSubview:_overlayView]; // don't know why but this is necessary for reactivating overlay. - NSString* overlayText = [self->_streamMan getStatsOverlayText]; + NSString* overlayText = [self->_streamMan getStatsOverlayText:overlayLevel]; + dispatch_async(dispatch_get_main_queue(), ^{ [self updateOverlayText:overlayText]; });