Philipp Hancke | f91ac40 | 2022-10-17 11:05:06 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | /** |
| 6 | * @param {!Object} statsValues The object containing stats, an |
| 7 | * array [key1, val1, key2, val2, ...] so searching a certain |
| 8 | * key needs to ensure it does not collide with a value. |
| 9 | */ |
| 10 | function generateLabel(key, statsValues) { |
| 11 | let label = ''; |
| 12 | const statIndex = statsValues.findIndex((value, index) => { |
| 13 | return value === key && index % 2 === 0; |
| 14 | }); |
| 15 | if (statIndex !== -1) { |
| 16 | label += key + '=' + statsValues[statIndex + 1]; |
| 17 | } |
| 18 | return label; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Formats the display text used for a stats type that is shown |
| 23 | * in the stats table or the stats graph. |
| 24 | * |
| 25 | * @param {!Object} report The object containing stats, which is the object |
| 26 | * containing timestamp and values, which is an array of strings, whose |
| 27 | * even index entry is the name of the stat, and the odd index entry is |
| 28 | * the value. |
| 29 | */ |
| 30 | export function generateStatsLabel(report) { |
| 31 | let label = report.type + ' ('; |
| 32 | let labels = []; |
Philipp Hancke | 7118bbf | 2023-01-09 16:15:59 | [diff] [blame] | 33 | if (['outbound-rtp', 'remote-outbound-rtp', 'inbound-rtp', |
| 34 | 'remote-inbound-rtp'].includes(report.type) && report.stats.values) { |
[email protected] | 4dbb003 | 2023-08-07 12:48:40 | [diff] [blame] | 35 | labels = ['kind', 'mid', 'rid', 'ssrc', 'rtxSsrc', 'fecSsrc', |
Philipp Hancke | 18f9986 | 2025-04-05 22:27:10 | [diff] [blame] | 36 | 'frameHeight', 'contentType', |
[email protected] | 4dbb003 | 2023-08-07 12:48:40 | [diff] [blame] | 37 | 'scalabilityMode', |
Philipp Hancke | b6fb26f | 2023-06-09 14:17:35 | [diff] [blame] | 38 | 'encoderImplementation', 'decoderImplementation', |
| 39 | 'powerEfficientEncoder', 'powerEfficientDecoder', |
| 40 | '[codec]']; |
Philipp Hancke | f91ac40 | 2022-10-17 11:05:06 | [diff] [blame] | 41 | } else if (['local-candidate', 'remote-candidate'].includes(report.type)) { |
Philipp Hancke | 61d227a | 2023-03-06 11:58:28 | [diff] [blame] | 42 | labels = ['candidateType', 'tcpType', 'relayProtocol']; |
Philipp Hancke | f91ac40 | 2022-10-17 11:05:06 | [diff] [blame] | 43 | } else if (report.type === 'codec') { |
Philipp Hancke | 61d227a | 2023-03-06 11:58:28 | [diff] [blame] | 44 | labels = ['mimeType', 'payloadType']; |
Philipp Hancke | 9b386ff7 | 2023-02-15 10:03:09 | [diff] [blame] | 45 | } else if (['media-playout', 'media-source'].includes(report.type)) { |
Philipp Hancke | 61d227a | 2023-03-06 11:58:28 | [diff] [blame] | 46 | labels = ['kind']; |
Philipp Hancke | f91ac40 | 2022-10-17 11:05:06 | [diff] [blame] | 47 | } else if (report.type === 'candidate-pair') { |
Philipp Hancke | 61d227a | 2023-03-06 11:58:28 | [diff] [blame] | 48 | labels = ['state']; |
| 49 | } else if (report.type === 'transport') { |
| 50 | labels = ['iceState', 'dtlsState']; |
Philipp Hancke | ada4cb2 | 2025-06-18 06:28:35 | [diff] [blame] | 51 | } else if (report.type === 'data-channel') { |
| 52 | labels = ['label', 'state']; |
Philipp Hancke | f91ac40 | 2022-10-17 11:05:06 | [diff] [blame] | 53 | } |
Philipp Hancke | 61d227a | 2023-03-06 11:58:28 | [diff] [blame] | 54 | labels = labels |
| 55 | .map(stat => generateLabel(stat, report.stats.values)) |
| 56 | .filter(label => !!label); |
Philipp Hancke | f91ac40 | 2022-10-17 11:05:06 | [diff] [blame] | 57 | if (labels.length) { |
| 58 | label += labels.join(', ') + ', '; |
| 59 | } |
| 60 | label += 'id=' + report.id + ')'; |
| 61 | return label; |
| 62 | } |