refactor: separate metrics calculation for legacy and queue pacing

This commit is contained in:
Acaki committed 2025-08-26 03:18:52 +08:00
1 parent 91f95f13ae
commit 0a2fdbf0c0
1 file changed
+63 -21
+63 -21
View File
@@ -14,6 +14,7 @@
#import "HttpManager.h" #import "HttpManager.h"
#import "Plot.h" #import "Plot.h"
#import "Utils.h" #import "Utils.h"
#import "DataManager.h"
#import "StreamView.h" #import "StreamView.h"
#import "ServerInfoResponse.h" #import "ServerInfoResponse.h"
@@ -187,34 +188,75 @@
} }
float interval = stats.endTime - stats.startTime; float interval = stats.endTime - stats.startTime;
float scalePlotMetrics = stats.frameDropMetrics.nsamples > 0 ? ((float)stats.frameDropMetrics.nsamples / stats.totalFrames) : 1.0f;
float fps = (stats.totalFrames - stats.networkDroppedFrames - (stats.frameDropMetrics.total / scalePlotMetrics)) / interval; // Check if we're using legacy pacing mode
DataManager* dataMan = [[DataManager alloc] init];
BOOL isLegacyPacing = [[dataMan getSettings].framePacingMode integerValue] == FramePacingModeLegacy;
// Calculate FPS differently based on pacing mode
float fps;
if (isLegacyPacing) {
fps = stats.totalFrames / interval;
} else {
float scalePlotMetrics = stats.frameDropMetrics.nsamples > 0 ? ((float)stats.frameDropMetrics.nsamples / stats.totalFrames) : 1.0f;
fps = (stats.totalFrames - stats.networkDroppedFrames - (stats.frameDropMetrics.total / scalePlotMetrics)) / interval;
}
double avgVideoMbps = [_connection getBwTracker].averageMbps; double avgVideoMbps = [_connection getBwTracker].averageMbps;
double peakVideoMbps = [_connection getBwTracker].peakMbps; double peakVideoMbps = [_connection getBwTracker].peakMbps;
if(overlayLevel == 1) return [LocalizationHelper localizedStringForKey:@"FPS: %5.2f Network dropped frames: %.2f%% Network latency: %@", if(overlayLevel == 1) return [LocalizationHelper localizedStringForKey:@"FPS: %5.2f Network dropped frames: %.2f%% Network latency: %@",
stats.totalFrames / interval, fps,
stats.networkDroppedFrames / interval, stats.networkDroppedFrames / interval,
latencyString]; latencyString];
else return [LocalizationHelper localizedStringForKey:@"Video stream: %dx%d %.2f FPS (Codec: %@)\n" else {
"Bitrate: %.1f Mbps, Peak: %.1f, Frames buffered: %.1f\n" if (isLegacyPacing) {
"%@" NSString* rendererWithPacing = stats.renderingBackendString;
"Renderer: %@\n" if ([stats.renderingBackendString isEqualToString:@"AVSampleBuffer"]) {
"Frames dropped by network/pacing jitter: %.1f%% / %.1f%%\n" rendererWithPacing = @"AVSampleBuffer (Legacy Pacing)";
"Average network latency: %@\n" }
"Decode time: %.2f/%.2f/%.2f ms",
_config.width, return [LocalizationHelper localizedStringForKey:@"Video stream: %dx%d %.2f FPS (Codec: %@)\n"
_config.height, "Bitrate: %.1f Mbps, Peak: %.1f\n"
fps, "%@"
[_connection getActiveCodecName], "Renderer: %@\n"
avgVideoMbps, peakVideoMbps, stats.frameQueueMetrics.avg, "Frames dropped by network: %.1f%%\n"
hostProcessingString, "Average network latency: %@",
stats.renderingBackendString, _config.width,
(stats.networkDroppedFrames / stats.totalFrames) * 100.0, _config.height,
stats.frameDropMetrics.nsamples > 0 ? (stats.frameDropMetrics.total / stats.frameDropMetrics.nsamples) * 100.0 : 0.0f, fps,
latencyString, [_connection getActiveCodecName],
stats.decodeMetrics.min, stats.decodeMetrics.max, stats.decodeMetrics.avg]; avgVideoMbps, peakVideoMbps,
hostProcessingString,
rendererWithPacing,
(stats.networkDroppedFrames / stats.totalFrames) * 100.0,
latencyString];
} else {
NSString* rendererWithPacing = stats.renderingBackendString;
if ([stats.renderingBackendString isEqualToString:@"AVSampleBuffer"]) {
rendererWithPacing = @"AVSampleBuffer (Queue Pacing)";
}
return [LocalizationHelper localizedStringForKey:@"Video stream: %dx%d %.2f FPS (Codec: %@)\n"
"Bitrate: %.1f Mbps, Peak: %.1f, Frames buffered: %.1f\n"
"%@"
"Renderer: %@\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.frameQueueMetrics.avg,
hostProcessingString,
rendererWithPacing,
(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 @end