@@ -67,10 +67,22 @@ type MaxBitrate = {
6767 data : Record < MediaKinds , number >
6868}
6969
70+ type FrameKind = Extends < MetricKind , "frames-dropped" | "frames-total" >
71+
72+ type Frames = {
73+ category : "union"
74+ kind : "frames"
75+ data : {
76+ total ?: number
77+ dropped ?: number
78+ }
79+ }
80+
7081type DynamicEntry = TimestampedMessage | TimestampedTrace | Timestamp
7182
7283type StaticEntry =
73- | Exclude < TimestampedMetric , MetricForKind < MediaElementStateKind | AudioQualityKind | VideoQualityKind > >
84+ | Exclude < TimestampedMetric , MetricForKind < MediaElementStateKind | AudioQualityKind | VideoQualityKind | FrameKind > >
85+ | Timestamped < Frames >
7486 | Timestamped < MediaElementState >
7587 | Timestamped < AudioQuality >
7688 | Timestamped < VideoQuality >
@@ -107,6 +119,32 @@ class DebugViewController {
107119 private dynamicEntries : DynamicEntry [ ] = [ ]
108120 private latestMetricByKey : Partial < Record < StaticEntryKind , StaticEntry > > = { }
109121
122+ private isFrameStat ( metric : TimestampedMetric ) : metric is Timestamped < MetricForKind < FrameKind > > {
123+ const { kind } = metric
124+ return kind === "frames-dropped" || kind === "frames-total"
125+ }
126+
127+ private mergeFrameStat ( entry : Timestamped < MetricForKind < FrameKind > > ) : Timestamped < Frames > {
128+ const prevEntry : Frames =
129+ this . latestMetricByKey . frames == null
130+ ? { category : "union" , kind : "frames" , data : { } }
131+ : ( this . latestMetricByKey . frames as Frames )
132+
133+ const { sessionTime, currentElementTime, kind : metricKind , data : metricData } = entry
134+
135+ const keyForKind : Record < FrameKind , string > = {
136+ "frames-dropped" : "dropped" ,
137+ "frames-total" : "total" ,
138+ }
139+
140+ return {
141+ ...prevEntry ,
142+ sessionTime,
143+ currentElementTime,
144+ data : { ...prevEntry . data , [ keyForKind [ metricKind ] ] : metricData } ,
145+ }
146+ }
147+
110148 private isMediaState ( metric : TimestampedMetric ) : metric is Timestamped < MetricForKind < MediaElementStateKind > > {
111149 const { kind } = metric
112150 const mediaStateMetrics = [ "ended" , "paused" , "playback-rate" , "ready-state" , "seeking" ]
@@ -219,6 +257,11 @@ class DebugViewController {
219257
220258 switch ( category ) {
221259 case EntryCategory . METRIC :
260+ if ( this . isFrameStat ( entry ) ) {
261+ this . cacheStaticEntry ( this . mergeFrameStat ( entry ) )
262+ return
263+ }
264+
222265 if ( this . isMediaState ( entry ) ) {
223266 this . cacheStaticEntry ( this . mergeMediaState ( entry ) )
224267 return
@@ -477,6 +520,14 @@ class DebugViewController {
477520 return `${ bitratePart } kbps`
478521 }
479522
523+ if ( kind === "frames" ) {
524+ if ( data . total == null ) {
525+ return null
526+ }
527+
528+ return `${ ( data . dropped ?? ( 0 / data . total ) * 100 ) . toFixed ( 2 ) } % dropped (${ data . dropped } /${ data . total } )`
529+ }
530+
480531 return data . join ( ", " )
481532 }
482533
0 commit comments