-
Notifications
You must be signed in to change notification settings - Fork 32
/
mediacapabilities.js
128 lines (120 loc) · 4.69 KB
/
mediacapabilities.js
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
function addCodecsGroup(select, desc, getter) {
if(getter) {
var group = document.createElement("optgroup");
group.label = desc;
select.appendChild(group);
getter().forEach(function(e) {
var opt = document.createElement("option");
opt.value = e.codec;
opt.innerHTML = e.description + " ("+e.codec+")";
group.appendChild(opt);
});
}
}
window.onload = function() {
const sourceselector = document.getElementById("source-select");
const mimeselector = document.getElementById("mime-select");
const codecsselector = document.getElementById("codecs-select");
addCodecsGroup(codecsselector, "VP9 codecs", getAllVP9Codecs);
addCodecsGroup(codecsselector, "AV1 codecs", getAllAV1Codecs);
addCodecsGroup(codecsselector, "AVC codecs", getAllAVCCodecs);
addCodecsGroup(codecsselector, "AVC codecs", getAllHEVCCodecs);
const fpsselector = document.getElementById("fps-select");
const bitrateeselector = document.getElementById("bitrate-select");
const dimensionselector = document.getElementById("maxdimension-select");
const hdrselector = document.getElementById("hdr-select");
const colorselector = document.getElementById("color-select");
const tranferselector = document.getElementById("transfer-select");
const alphaCheckbox = document.getElementById("alpha");
const supportedCheckbox = document.getElementById("supported");
const smoothCheckbox = document.getElementById("smooth");
const powerEfficientCheckbox = document.getElementById("powerEfficient");
const ctx = {};
ctx.svg = document.getElementById('s');
function run() {
const sourcevalue = sourceselector.value;
const mime = mimeselector.value;
const codecs = codecsselector.value;
const fps = fpsselector.value;
const bitrate = bitrateeselector.value;
const dimension = dimensionselector.value;
const hdrvalue = hdrselector.value;
const colorvalue = colorselector.value;
const transfervalue = tranferselector.value;
ctx.width_min = 0;
ctx.height_min = 0;
ctx.width_max = +(dimension.substring(0, dimension.indexOf('x')));
ctx.height_max = +(dimension.substring(dimension.indexOf('x')+1, dimension.length));
ctx.stepw = ctx.width_max >> 4;
ctx.steph = ctx.height_max >> 4;
ctx.svg.setAttribute("viewBox","0 0 "+ctx.width_max+" "+ctx.height_max);
while (ctx.svg.firstChild) {
ctx.svg.removeChild(ctx.svg.firstChild);
}
for (let w = ctx.stepw; w <= ctx.width_max; w+=ctx.stepw) {
for (let h = ctx.steph; h <= ctx.height_max; h+=ctx.steph) {
testConfig(sourcevalue, mime, codecs,
w, h, bitrate, fps,
alphaCheckbox.checked,
hdrvalue, colorvalue, transfervalue,
ctx,
supportedCheckbox.checked,
powerEfficient.checked,
smoothCheckbox.checked);
}
}
}
const runbutton = document.getElementById('runbutton');
runbutton.onclick = run;
}
function testConfig(sourcevalue, mime, codecs, vw, vh, b, fps,
alpha, hdr, color, transfer,
ctx, wantsSupported, wantsPowerEfficient, wantsSmooth) {
const fullmime = mime+';codecs='+codecs;
//const fullmime = 'video/mp4;codecs=avc1.640028';
let configuration = {
type: sourcevalue,
video: {
contentType: fullmime,
width: vw,
height: vh,
bitrate: b,
framerate: fps,
}
};
configuration.video.hasAlphaChannel = alpha;
if (hdr) configuration.video.hdrMetadataType = hdr;
if (color) configuration.video.colorGamut = color;
if (transfer) configuration.video.transferFunction = transfer;
navigator.mediaCapabilities.decodingInfo(configuration)
.then((result) => {
drawValue(ctx, configuration, vw, vh,
result.supported && wantsSupported,
result.powerEfficient && wantsPowerEfficient,
result.smooth && wantsSmooth);
})
.catch((err) => {
console.error(err, ' caused decodingInfo to reject');
});
}
function drawValue(ctx, configuration, w, h, supported, powerEfficient, smooth) {
const scalew = ctx.stepw*.9;
const offsetw = ctx.stepw*.05-ctx.stepw;
const scaleh = ctx.steph*.9;
const offseth = ctx.steph*.05-ctx.steph;
let rect = document.createElementNS("http://www.w3.org/2000/svg","rect");
rect.setAttribute("x",w+offsetw+"");
rect.setAttribute("y",h+offseth+"");
rect.setAttribute("width",scalew+"");
rect.setAttribute("height",scaleh+"");
rect.setAttribute("fill", "rgb("+supported*255+","+powerEfficient*255+","+smooth*255+")");
let tooltip = document.createElementNS("http://www.w3.org/2000/svg","title");
let tooltipString = (""+w+"x"+h+":");
tooltipString += ("\nsupported:"+supported);
tooltipString += ("\npowerEfficient:"+powerEfficient);
tooltipString += ("\nsmooth:"+smooth);
tooltipString += ("\nconfiguration:"+JSON.stringify(configuration));
tooltip.textContent = tooltipString;
rect.appendChild(tooltip);
ctx.svg.appendChild(rect);
}