blob: 8071adcca7974fdb7dd510cf1b99a90026241b5d [file] [log] [blame]
Hongchan Choi7dd0b3e2019-05-13 21:19:031// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Tim van der Lippe305e9482021-04-20 08:22:055import * as i18n from '../../core/i18n/i18n.js';
6import * as UI from '../../ui/legacy/legacy.js';
Tim van der Lippe229a54f2021-05-14 16:59:057import type * as Protocol from '../../generated/protocol.js';
Tim van der Lippe9081c902020-01-24 14:32:428
Simon Zündf6afbca2021-03-02 06:11:149const UIStrings = {
Christy Chen598b98f2020-11-13 23:47:3910 /**
Christy Chen598b98f2020-11-13 23:47:3911 *@description The current state of an item
12 */
13 state: 'State',
14 /**
15 *@description Text in Audio Context Content Builder
16 */
17 sampleRate: 'Sample Rate',
18 /**
19 *@description Text in Audio Context Content Builder
20 */
21 callbackBufferSize: 'Callback Buffer Size',
22 /**
Peter Marshallb8bd00f2021-02-24 08:25:1823 * @description Label in the Audio Context Content Builder for the maximum number of output channels
24 * that this Audio Context has.
Christy Chen598b98f2020-11-13 23:47:3925 */
26 maxOutputChannels: 'Max Output Channels',
27 /**
28 *@description Text in Audio Context Content Builder
29 */
30 currentTime: 'Current Time',
31 /**
32 *@description Text in Audio Context Content Builder
33 */
34 callbackInterval: 'Callback Interval',
35 /**
36 *@description Text in Audio Context Content Builder
37 */
38 renderCapacity: 'Render Capacity',
39};
Tim van der Lippe305e9482021-04-20 08:22:0540const str_ = i18n.i18n.registerUIStrings('panels/web_audio/AudioContextContentBuilder.ts', UIStrings);
Christy Chen598b98f2020-11-13 23:47:3941const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
42
Paul Lewis2766f082019-11-28 13:42:5743export class ContextDetailBuilder {
Jan Scheffler755efdd2021-08-12 09:32:1844 private readonly fragment: DocumentFragment;
45 private readonly container: HTMLDivElement;
Jan Schefflerd862f142021-01-12 10:25:0346 constructor(context: Protocol.WebAudio.BaseAudioContext) {
Jan Scheffler755efdd2021-08-12 09:32:1847 this.fragment = document.createDocumentFragment();
48 this.container = document.createElement('div');
49 this.container.classList.add('context-detail-container');
50 this.fragment.appendChild(this.container);
51 this.build(context);
Hongchan Choi7dd0b3e2019-05-13 21:19:0352 }
53
Jan Scheffler755efdd2021-08-12 09:32:1854 private build(context: Protocol.WebAudio.BaseAudioContext): void {
Simon Zünd67789af2021-03-03 13:54:1355 const title = context.contextType === 'realtime' ? i18n.i18n.lockedString('AudioContext') :
Simon Zünd2bd08292021-03-03 11:25:5856 i18n.i18n.lockedString('OfflineAudioContext');
Jan Scheffler755efdd2021-08-12 09:32:1857 this.addTitle(title, context.contextId);
58 this.addEntry(i18nString(UIStrings.state), context.contextState);
59 this.addEntry(i18nString(UIStrings.sampleRate), context.sampleRate, 'Hz');
Tim van der Lippe1d6e57a2019-09-30 11:55:3460 if (context.contextType === 'realtime') {
Jan Scheffler755efdd2021-08-12 09:32:1861 this.addEntry(i18nString(UIStrings.callbackBufferSize), context.callbackBufferSize, 'frames');
Tim van der Lippe1d6e57a2019-09-30 11:55:3462 }
Jan Scheffler755efdd2021-08-12 09:32:1863 this.addEntry(i18nString(UIStrings.maxOutputChannels), context.maxOutputChannelCount, 'ch');
Hongchan Choi7dd0b3e2019-05-13 21:19:0364 }
65
Jan Scheffler755efdd2021-08-12 09:32:1866 private addTitle(title: string, subtitle: string): void {
67 this.container.appendChild(UI.Fragment.html`
Jan Schefflerd862f142021-01-12 10:25:0368 <div class="context-detail-header">
69 <div class="context-detail-title">${title}</div>
70 <div class="context-detail-subtitle">${subtitle}</div>
71 </div>
72 `);
Hongchan Choi7dd0b3e2019-05-13 21:19:0373 }
74
Jan Scheffler755efdd2021-08-12 09:32:1875 private addEntry(entry: string, value: string|number, unit?: string|undefined): void {
Hongchan Choi7dd0b3e2019-05-13 21:19:0376 const valueWithUnit = value + (unit ? ` ${unit}` : '');
Jan Scheffler755efdd2021-08-12 09:32:1877 this.container.appendChild(UI.Fragment.html`
Jan Schefflerd862f142021-01-12 10:25:0378 <div class="context-detail-row">
79 <div class="context-detail-row-entry">${entry}</div>
80 <div class="context-detail-row-value">${valueWithUnit}</div>
81 </div>
82 `);
Hongchan Choi7dd0b3e2019-05-13 21:19:0383 }
84
Jan Schefflerd862f142021-01-12 10:25:0385 getFragment(): DocumentFragment {
Jan Scheffler755efdd2021-08-12 09:32:1886 return this.fragment;
Hongchan Choi7dd0b3e2019-05-13 21:19:0387 }
Paul Lewis2766f082019-11-28 13:42:5788}
Hongchan Choi7dd0b3e2019-05-13 21:19:0389
Hongchan Choi0927e702020-01-15 20:13:3790export class ContextSummaryBuilder {
Jan Scheffler755efdd2021-08-12 09:32:1891 private readonly fragment: DocumentFragment;
Jan Schefflerd862f142021-01-12 10:25:0392 constructor(contextId: string, contextRealtimeData: Protocol.WebAudio.ContextRealtimeData) {
Hongchan Choi7dd0b3e2019-05-13 21:19:0393 const time = contextRealtimeData.currentTime.toFixed(3);
Hongchan Choi17a74252019-06-05 18:27:5894 const mean = (contextRealtimeData.callbackIntervalMean * 1000).toFixed(3);
95 const stddev = (Math.sqrt(contextRealtimeData.callbackIntervalVariance) * 1000).toFixed(3);
Hongchan Choi7dd0b3e2019-05-13 21:19:0396 const capacity = (contextRealtimeData.renderCapacity * 100).toFixed(3);
Jan Scheffler755efdd2021-08-12 09:32:1897 this.fragment = document.createDocumentFragment();
98 this.fragment.appendChild(UI.Fragment.html`
Jan Schefflerd862f142021-01-12 10:25:0399 <div class="context-summary-container">
100 <span>${i18nString(UIStrings.currentTime)}: ${time} s</span>
101 <span>\u2758</span>
102 <span>${i18nString(UIStrings.callbackInterval)}: μ = ${mean} ms, σ = ${stddev} ms</span>
103 <span>\u2758</span>
104 <span>${i18nString(UIStrings.renderCapacity)}: ${capacity} %</span>
105 </div>
106 `);
Hongchan Choi7dd0b3e2019-05-13 21:19:03107 }
108
Jan Schefflerd862f142021-01-12 10:25:03109 getFragment(): DocumentFragment {
Jan Scheffler755efdd2021-08-12 09:32:18110 return this.fragment;
Hongchan Choi7dd0b3e2019-05-13 21:19:03111 }
Paul Lewis2766f082019-11-28 13:42:57112}