@@ -20,7 +20,7 @@ class VideoDecoderIssueDetector extends BaseIssueDetector {
2020
2121 constructor ( params : VideoDecoderIssueDetectorParams = { } ) {
2222 super ( params ) ;
23- this . #volatilityThreshold = params . volatilityThreshold ?? 1.5 ;
23+ this . #volatilityThreshold = params . volatilityThreshold ?? 8 ;
2424 this . #affectedStreamsPercentThreshold = params . affectedStreamsPercentThreshold ?? 50 ;
2525 }
2626
@@ -51,9 +51,8 @@ class VideoDecoderIssueDetector extends BaseIssueDetector {
5151 ] ;
5252
5353 const throtthedStreams = data . video . inbound
54- . map ( ( incomeVideoStream ) : { ssrc : number , allDecodeTimePerFrame : number [ ] , volatility : number } | undefined => {
55- const allDecodeTimePerFrame : number [ ] = [ ] ;
56- const allFpss : number [ ] = [ ] ;
54+ . map ( ( incomeVideoStream ) : { ssrc : number , allFps : number [ ] , volatility : number } | undefined => {
55+ const allFps : number [ ] = [ ] ;
5756
5857 const isSpatialLayerChanged = isSvcSpatialLayerChanged ( incomeVideoStream . ssrc , allProcessedStats ) ;
5958 if ( isSpatialLayerChanged ) {
@@ -65,61 +64,20 @@ class VideoDecoderIssueDetector extends BaseIssueDetector {
6564 return undefined ;
6665 }
6766
68- // exclude first element to calculate accurate delta
69- for ( let i = 1 ; i < allProcessedStats . length ; i += 1 ) {
70- let deltaFramesDecoded = 0 ;
71- let deltaTotalDecodeTime = 0 ;
72- let decodeTimePerFrame = 0 ;
73-
74- const videoStreamStats = allProcessedStats [ i ] . video . inbound . find (
75- ( stream ) => stream . ssrc === incomeVideoStream . ssrc ,
76- ) ;
77-
78- if ( ! videoStreamStats ) {
79- continue ;
80- }
81-
82- const prevVideoStreamStats = allProcessedStats [ i - 1 ] . video . inbound . find (
83- ( stream ) => stream . ssrc === incomeVideoStream . ssrc ,
84- ) ;
85-
86- if ( prevVideoStreamStats ) {
87- deltaFramesDecoded = videoStreamStats . framesDecoded - prevVideoStreamStats . framesDecoded ;
88- deltaTotalDecodeTime = videoStreamStats . totalDecodeTime - prevVideoStreamStats . totalDecodeTime ;
89- }
90-
91- if ( deltaTotalDecodeTime > 0 && deltaFramesDecoded > 0 ) {
92- decodeTimePerFrame = ( deltaTotalDecodeTime * 1000 ) / deltaFramesDecoded ;
93- }
94-
95- allDecodeTimePerFrame . push ( decodeTimePerFrame ) ;
96- allFpss . push ( videoStreamStats . framesPerSecond ) ;
97- }
98-
99- // Calculate volatility decode time
100- const mean = allDecodeTimePerFrame . reduce ( ( acc , val ) => acc + val , 0 ) / allDecodeTimePerFrame . length ;
101- const squaredDiffs = allDecodeTimePerFrame . map ( ( val ) => ( val - mean ) ** 2 ) ;
102- const variance = squaredDiffs . reduce ( ( acc , val ) => acc + val , 0 ) / squaredDiffs . length ;
103- const volatility = Math . sqrt ( variance ) ;
104-
105- const isDecodeTimePerFrameIncrease = allDecodeTimePerFrame . every (
106- ( decodeTimePerFrame , index ) => index === 0 || decodeTimePerFrame > allDecodeTimePerFrame [ index - 1 ] ,
107- ) ;
108-
10967 // Calculate volatility fps
110- const meanFps = allFpss . reduce ( ( acc , val ) => acc + val , 0 ) / allDecodeTimePerFrame . length ;
111- const squaredDiffsFps = allFpss . map ( ( val ) => ( val - meanFps ) ** 2 ) ;
112- const varianceFps = squaredDiffsFps . reduce ( ( acc , val ) => acc + val , 0 ) / squaredDiffsFps . length ;
113- const volatilityFps = Math . sqrt ( varianceFps ) ;
68+ const meanFps = allFps . reduce ( ( acc , val ) => acc + val , 0 ) / allFps . length ;
69+ const meanAbsoluteDeviationFps = allFps
70+ . reduce ( ( acc , val ) => acc + Math . abs ( val - meanFps ) , 0 ) / allFps . length ;
71+ const volatility = ( meanAbsoluteDeviationFps * 100 ) / meanFps ;
11472
11573 console . log ( 'THROTTLE' , {
116- volatilityFps ,
117- allFpss ,
74+ volatility ,
75+ allFps ,
11876 } ) ;
11977
120- if ( volatility > this . #volatilityThreshold && isDecodeTimePerFrameIncrease ) {
121- console . log ( 'THROTTLE DETECTED' ) ;
122- return { ssrc : incomeVideoStream . ssrc , allDecodeTimePerFrame , volatility } ;
78+ if ( volatility > this . #volatilityThreshold) {
79+ console . log ( 'THROTTLE DETECTED on Single stream ' ) ;
80+ return { ssrc : incomeVideoStream . ssrc , allFps , volatility } ;
12381 }
12482
12583 return undefined ;
@@ -128,6 +86,7 @@ class VideoDecoderIssueDetector extends BaseIssueDetector {
12886
12987 const affectedStreamsPercent = throtthedStreams . length / ( data . video . inbound . length / 100 ) ;
13088 if ( affectedStreamsPercent > this . #affectedStreamsPercentThreshold) {
89+ console . log ( 'THROTTLE DETECTED !!!!' ) ;
13190 issues . push ( {
13291 type : IssueType . CPU ,
13392 reason : IssueReason . DecoderCPUThrottling ,
0 commit comments