File: MediaDetailsSidebarPanel.js

package info (click to toggle)
webkit2gtk 2.48.3-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 429,620 kB
  • sloc: cpp: 3,696,936; javascript: 194,444; ansic: 169,997; python: 46,499; asm: 19,276; ruby: 18,528; perl: 16,602; xml: 4,650; yacc: 2,360; sh: 2,098; java: 1,993; lex: 1,327; pascal: 366; makefile: 295
file content (323 lines) | stat: -rw-r--r-- 13,050 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
 * Copyright (C) 2023 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

WI.MediaDetailsSidebarPanel = class MediaDetailsSidebarPanel extends WI.DOMDetailsSidebarPanel
{
    // Static

    static StyleClassName = "media";

    // Public

    constructor(delegate)
    {
        super("media-details", WI.UIString("Media"));

        this.#ui.sourceRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Source", "Source @ Media Sidebar", "Title for Source row in Media Sidebar"));
        this.#ui.viewportRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Viewport", "Viewport @ Media Sidebar", "Title for Viewport row in Media Sidebar"));
        this.#ui.framesRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Frames", "Frames @ Media Sidebar Frame Count", "Title for Frames row in Media Sidebar"));
        this.#ui.resolutionRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Resolution", "Resolution @ Media Sidebar", "Title for Resolution row in Media Sidebar"));
        this.#ui.videoFormatRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Video Format", "Video Format @ Media Sidebar", "Title for Video Format row in Media Sidebar"));
        this.#ui.audioFormatRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Audio Format", "Audio Format @ Media Sidebar", "Title for Audio Format row in Media Sidebar"));

        let generalGroup = new WI.DetailsSectionGroup([this.#ui.sourceRow, this.#ui.viewportRow, this.#ui.framesRow, this.#ui.resolutionRow, this.#ui.videoFormatRow, this.#ui.audioFormatRow]);
        this.#ui.generalSection = new WI.DetailsSection("media-details-general", WI.UIString("General", "General @ Media Sidebar", "Title for General Section in Media Sidebar"), [generalGroup]);

        this.#ui.videoCodecRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Video Codec", "Video Codec @ Media Sidebar", "Title for Video Codec row in Media Sidebar"));
        this.#ui.transferRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Transfer Function", "Transfer Function @ Media Sidebar", "Title for Transfer Function row in Media Sidebar"));
        this.#ui.primariesRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Color Primaries", "Color Primaries @ Media Sidebar", "Title for Color Primaries row in Media Sidebar"));
        this.#ui.matrixRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Matrix Coefficients", "Matrix Coefficients @ Media Sidebar", "Title for Matrix Coefficients row in Media Sidebar"));
        this.#ui.fullRangeRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Color Range", "Color Range @ Media Sidebar", "Title for Color Range row in Media Sidebar"));

        let videoGroup = new WI.DetailsSectionGroup([this.#ui.videoCodecRow, this.#ui.primariesRow, this.#ui.transferRow, this.#ui.matrixRow, this.#ui.fullRangeRow]);
        this.#ui.videoSection = new WI.DetailsSection("media-video-details", WI.UIString("Video Details", "Video Details @ Media Sidebar", "Title for Video Details section in Media Sidebar"), [videoGroup]);
        this.#ui.audioCodecRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Audio Codec", "Audio Codec @ Media Sidebar", "Title for Audio Codec row in Media Sidebar"));
        this.#ui.sampleRateRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Sample Rate", "Sample Rate @ Media Sidebar", "Title for Sample Rate row in Media Sidebar"));
        this.#ui.channelsRow = new WI.MediaDetailsSidebarPanel.#Row(WI.UIString("Channels", "Channels @ Media Sidebar", "Title for Channels row in Media Sidebar"));

        let audioGroup = new WI.DetailsSectionGroup([this.#ui.audioCodecRow, this.#ui.sampleRateRow, this.#ui.channelsRow]);
        this.#ui.audioSection = new WI.DetailsSection("media-audio-details", WI.UIString("Audio Details", "Audio Details @ Media Sidebar", "Title for Audio Details section in Media Sidebar"), [audioGroup]);
    }

    layout()
    {
        this.#ui.sourceRow.updateValue();
        this.#ui.viewportRow.updateValue();
        this.#ui.framesRow.updateValue();
        this.#ui.resolutionRow.updateValue();
        this.#ui.videoFormatRow.updateValue();
        this.#ui.audioFormatRow.updateValue();
        this.#ui.videoCodecRow.updateValue();
        this.#ui.transferRow.updateValue();
        this.#ui.primariesRow.updateValue();
        this.#ui.matrixRow.updateValue();
        this.#ui.fullRangeRow.updateValue();
        this.#ui.audioCodecRow.updateValue();
        this.#ui.sampleRateRow.updateValue();
        this.#ui.channelsRow.updateValue();
    }

    // Protected

    // DOMDetailsSidebarPanel Overrides

    supportsDOMNode(nodeToInspect)
    {
        return nodeToInspect.isMediaElement();
    }

    attached()
    {
        super.attached();
        this.#startUpdateTimer();
    }

    detached()
    {
        super.detached();
        this.#cancelUpdateTimer();
    }

    // View Overrides

    initialLayout()
    {
        super.initialLayout();

        this.element.appendChild(this.#ui.generalSection.element);
        this.element.appendChild(this.#ui.videoSection.element);
        this.element.appendChild(this.#ui.audioSection.element);
    }

    // Private

    static #Row = class MediaDetailsSectionSimpleRow extends WI.DetailsSectionSimpleRow
    {
        // Public

        set pendingValue(value)
        {
            this.#pendingValue = value;
            this.#dirty = true;
        }

        updateValue()
        {
            if (!this.#dirty)
                return;
            this.value = this.#pendingValue;
            this.#pendingValue = null;
            this.#dirty = false;
        }

        // Private

        #pendingValue = null;
        #dirty = null;
    };

    #values = {
        source: null,
        viewport: null,
        devicePixelRatio: null,
        quality: null,
        videoFormat: null,
        audioFormat: null,
        video: null,
        audio: null,
    };

    #ui = {
        sourceRow: null,
        viewportRow: null,
        framesRow: null,
        resolutionRow: null,
        videoFormatRow: null,
        audioFormatRow: null,
        generalSection: null,
        videoCodecRow: null,
        transferRow: null,
        primariesRow: null,
        matrixRow: null,
        fullRangeRow: null,
        videoSection: null,
        audioCodecRow: null,
        sampleRateRow: null,
        channelsRow: null,
        audioSection: null,
    };

    #updateTimer = null;
    #updateTimerInterval = 250;

    #startUpdateTimer()
    {
        this.#cancelUpdateTimer();
        this.#updateTimerFired();
    }

    #cancelUpdateTimer()
    {
        if (this.#updateTimer)
            clearTimeout(this.#updateTimer);
    }

    async #updateTimerFired()
    {
        if (!this.domNode)
            return;

        let stats = await this.domNode.getMediaStats();
        this.#setSource(stats.source);
        this.#setViewport(stats.viewport);
        this.#setDevicePixelRatio(stats.devicePixelRatio);
        this.#setQuality(stats.quality);
        this.#setVideoFormat(stats.video?.humanReadableCodecString);
        this.#setAudioFormat(stats.audio?.humanReadableCodecString);
        this.#setVideo(stats.video);
        this.#setAudio(stats.audio);

        if (this.isAttached)
            this.#updateTimer = setTimeout(() => this.#updateTimerFired(), this.#updateTimerInterval);
    }

    #setSource(source)
    {
        if (this.#values.source === source)
            return;

        this.#values.source = source;
        this.#ui.sourceRow.pendingValue = this.#values.source;
        this.needsLayout();
    }

    #setViewport(viewport)
    {
        if (Object.shallowEqual(this.#values.viewport, viewport))
            return;

        this.#values.viewport = viewport;
        this.#updateViewportRow();
    }

    #setDevicePixelRatio(devicePixelRatio)
    {
        if (this.#values.devicePixelRatio === devicePixelRatio)
            return;

        this.#values.devicePixelRatio = devicePixelRatio;
        this.#updateViewportRow();
    }

    #updateViewportRow()
    {
        this.#ui.viewportRow.pendingValue = WI.UIString("%dx%d (%dx)").format(this.#values.viewport?.width ?? 0, this.#values.viewport?.height ?? 0, this.#values.devicePixelRatio ?? 1);
        this.needsLayout();
    }

    #setQuality(quality)
    {
        if (Object.shallowEqual(this.#values.quality, quality))
            return;

        this.#values.quality = quality;
        let formatString = WI.UIString("%d dropped of %d", "Dropped Frame Format @ Media Sidebar", "Format string for Dropped Frame count in Media Sidebar");
        this.#ui.framesRow.pendingValue = formatString.format(quality?.droppedVideoFrames ?? 0, quality?.totalVideoFrames ?? 0);
        this.needsLayout();
    }

    #setVideoFormat(videoFormat)
    {
        if (this.#values.videoFormat === videoFormat)
            return;

        this.#values.videoFormat = videoFormat;
        this.#ui.videoFormatRow.pendingValue = videoFormat;
        this.needsLayout();
    }

    #setAudioFormat(audioFormat)
    {
        if (this.#values.audioFormat === audioFormat)
            return;

        this.#values.audioFormat = audioFormat;
        this.#ui.audioFormatRow.pendingValue = audioFormat;
        this.needsLayout();
    }

    #setVideo(video)
    {
        if (this.#values.video === video)
            return;

        if (this.#values.video?.width === video?.width
            && this.#values.video?.height === video?.height
            && this.#values.video?.framerate === video?.framerate
            && this.#values.video?.codec === video?.codec
            && Object.shallowEqual(this.#values.video?.colorSpace, video?.colorSpace)
            && this.#values.video?.colorSpace?.primaries === video?.colorSpace?.primaries
            && this.#values.video?.colorSpace?.matrix === video?.colorSpace?.matrix
            && this.#values.video?.fullRange === video?.fullRange)
            return;

        this.#values.video = video;
        this.#ui.videoSection.element.classList.toggle("hidden", !video);
        this.#ui.resolutionRow.pendingValue = WI.UIString("%dx%d (%dfps)").format(video?.width ?? 0, video?.height ?? 0, video?.framerate ?? 0);
        this.#ui.resolutionRow.element.classList.toggle("hidden", !video);
        this.#ui.videoCodecRow.pendingValue = video?.codec;
        this.#ui.transferRow.pendingValue = video?.colorSpace?.transfer;
        this.#ui.primariesRow.pendingValue = video?.colorSpace?.primaries;
        this.#ui.matrixRow.pendingValue = video?.colorSpace?.matrix;
        if (video?.fullRange)
            this.#ui.fullRangeRow.pendingValue = WI.UIString("Full range", "Full range @ Media Sidebar", "Value string for Full Range color in the Media Sidebar");
        else
            this.#ui.fullRangeRow.pendingValue = WI.UIString("Video range", "Video range @ Media Sidebar", "Value string for Video Range color in the Media Sidebar");
        this.needsLayout();
    }

    #setAudio(audio)
    {
        if (Object.shallowEqual(this.#values.audio, audio))
            return;

        this.#values.audio = audio;
        this.#ui.audioSection.element.classList.toggle("hidden", !audio);
        this.#ui.audioCodecRow.pendingValue = audio?.codec;
        this.#ui.sampleRateRow.pendingValue = WI.UIString("%d Hz").format(audio?.sampleRate);
        switch (audio?.numberOfChannels) {
        case 1:
            this.#ui.channelsRow.pendingValue = WI.UIString("Mono");
            break;
        case 2:
            this.#ui.channelsRow.pendingValue = WI.UIString("Stereo");
            break;
        default:
            this.#ui.channelsRow.pendingValue = audio?.numberOfChannels;
            break;
        }
        this.needsLayout();
    }
};