decoding-info 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/LICENSE +1 -1
- package/README.md +11 -6
- package/dist/consts.d.ts +3 -0
- package/dist/getMaxSize.d.ts +11 -0
- package/dist/getMinSize.d.ts +11 -0
- package/dist/index.common.js +253 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.esm.js +251 -0
- package/dist/utils/binarySearch.d.ts +1 -0
- package/dist/utils/binarySearch.test.d.ts +1 -0
- package/dist/utils/getDecodingInfo.d.ts +1 -0
- package/package.json +9 -7
package/CHANGELOG.md
CHANGED
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -4,8 +4,15 @@
|
|
|
4
4
|
[](https://www.npmjs.org/package/decoding-info)
|
|
5
5
|
[](https://packagephobia.com/result?p=decoding-info)
|
|
6
6
|
|
|
7
|
+
[Demo](https://vvideo.github.io/decoding-info/index.html)
|
|
8
|
+
|
|
7
9
|
This npm package allows you to determine the resolution of a supported video codec using the [MediaCapabilities API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/mediaCapabilities).
|
|
8
10
|
|
|
11
|
+
Finding video codec resolution:
|
|
12
|
+
- Minimum and maximum resolutions for a video codec.
|
|
13
|
+
- Minimum and maximum resolutions for a video codec with smooth playback.
|
|
14
|
+
- Minimum and maximum resolutions for a video codec in power-efficiency mode (similar to hardware acceleration).
|
|
15
|
+
|
|
9
16
|
## Installation
|
|
10
17
|
```bash
|
|
11
18
|
npm install --save-dev decoding-info
|
|
@@ -18,8 +25,6 @@ import { getVideoCodecSupportedResolution } from 'decoding-info';
|
|
|
18
25
|
const configuration = {
|
|
19
26
|
video: {
|
|
20
27
|
codec: 'video/mp4; codecs="hvc1.1.6.L123.B0"',
|
|
21
|
-
width: 1920,
|
|
22
|
-
height: 1080,
|
|
23
28
|
framerate: 25,
|
|
24
29
|
bitrate: 1000000,
|
|
25
30
|
},
|
|
@@ -29,7 +34,6 @@ getVideoCodecSupportedResolution(configuration).then((result) => {
|
|
|
29
34
|
console.log(result);
|
|
30
35
|
// {
|
|
31
36
|
// "error": null,
|
|
32
|
-
// "attempts": 103,
|
|
33
37
|
// "supported": {
|
|
34
38
|
// "value": true,
|
|
35
39
|
// "minHeight": 16,
|
|
@@ -56,9 +60,10 @@ getVideoCodecSupportedResolution(configuration).then((result) => {
|
|
|
56
60
|
```
|
|
57
61
|
|
|
58
62
|
## Links
|
|
59
|
-
- [
|
|
60
|
-
- [Test
|
|
61
|
-
- [Test .
|
|
63
|
+
- [Demo](https://vvideo.github.io/decoding-info/index.html)
|
|
64
|
+
- [Test navigator.mediaCapabilities.decodingInfo()](https://vvideo.github.io/decoding-info/decoding-info.html)
|
|
65
|
+
- [Test MediaSource.isTypeSupported()](https://vvideo.github.io/decoding-info/is-type-supported.html)
|
|
66
|
+
- [Test .canPlayType()](https://vvideo.github.io/decoding-info/can-play-type.html)
|
|
62
67
|
|
|
63
68
|
## [License](./LICENSE)
|
|
64
69
|
MIT
|
package/dist/consts.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function getMaxSize(configuration: MediaDecodingConfiguration, getSupported: (result: MediaCapabilitiesDecodingInfo) => boolean, maxSize: number): Promise<{
|
|
2
|
+
result: number;
|
|
3
|
+
attempts: number;
|
|
4
|
+
maxWidth: number;
|
|
5
|
+
maxHeight: number;
|
|
6
|
+
} | {
|
|
7
|
+
attempts: number;
|
|
8
|
+
maxWidth: undefined;
|
|
9
|
+
maxHeight: undefined;
|
|
10
|
+
result: number | null;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function getMinSize(configuration: MediaDecodingConfiguration, getSupported: (result: MediaCapabilitiesDecodingInfo) => boolean, minSize: number): Promise<{
|
|
2
|
+
attempts: number;
|
|
3
|
+
minWidth: number;
|
|
4
|
+
minHeight: number;
|
|
5
|
+
result: number;
|
|
6
|
+
} | {
|
|
7
|
+
attempts: number;
|
|
8
|
+
minWidth: undefined;
|
|
9
|
+
minHeight: undefined;
|
|
10
|
+
result: number | null;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getDecodingInfo(configuration) {
|
|
4
|
+
return navigator.mediaCapabilities.decodingInfo(configuration);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const MIN_SIZE = 1;
|
|
8
|
+
const MAX_SIZE = 64000;
|
|
9
|
+
const START_SIZE = 320;
|
|
10
|
+
|
|
11
|
+
async function binarySearch(compareFn, minValue, maxValue) {
|
|
12
|
+
let left = minValue;
|
|
13
|
+
let right = maxValue;
|
|
14
|
+
while (left <= right) {
|
|
15
|
+
const middle = Math.floor((right + left) / 2);
|
|
16
|
+
const cmp = await compareFn(middle);
|
|
17
|
+
if (cmp === 0) {
|
|
18
|
+
return middle;
|
|
19
|
+
}
|
|
20
|
+
else if (cmp < 0) {
|
|
21
|
+
left = middle + 1;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
right = middle - 1;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function getMaxSize(configuration, getSupported, maxSize) {
|
|
31
|
+
let maxWidth = undefined;
|
|
32
|
+
let attempts = 1;
|
|
33
|
+
const dataMaxSize = await getDecodingInfo({
|
|
34
|
+
...configuration,
|
|
35
|
+
video: {
|
|
36
|
+
...configuration.video,
|
|
37
|
+
width: maxSize,
|
|
38
|
+
height: maxSize,
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const supportedMaxSize = getSupported(dataMaxSize);
|
|
42
|
+
if (supportedMaxSize) {
|
|
43
|
+
return {
|
|
44
|
+
result: maxSize,
|
|
45
|
+
attempts,
|
|
46
|
+
maxWidth: maxSize,
|
|
47
|
+
maxHeight: maxSize,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const result = await binarySearch(async (value) => {
|
|
51
|
+
attempts++;
|
|
52
|
+
const data1 = await getDecodingInfo({
|
|
53
|
+
...configuration,
|
|
54
|
+
video: {
|
|
55
|
+
...configuration.video,
|
|
56
|
+
width: value,
|
|
57
|
+
height: value,
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const supported1 = getSupported(data1);
|
|
61
|
+
if (!supported1) {
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
if (supported1) {
|
|
65
|
+
maxWidth = Math.max(maxWidth || 0, value);
|
|
66
|
+
}
|
|
67
|
+
attempts++;
|
|
68
|
+
const data2 = await getDecodingInfo({
|
|
69
|
+
...configuration,
|
|
70
|
+
video: {
|
|
71
|
+
...configuration.video,
|
|
72
|
+
width: value + 1,
|
|
73
|
+
height: value + 1,
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const supported2 = getSupported(data2);
|
|
77
|
+
if (supported2) {
|
|
78
|
+
maxWidth = Math.max(maxWidth || 0, value + 1);
|
|
79
|
+
}
|
|
80
|
+
if (supported1 !== supported2) {
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
if (supported1 && supported2) {
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
86
|
+
return 1;
|
|
87
|
+
}, START_SIZE, maxSize);
|
|
88
|
+
return {
|
|
89
|
+
attempts,
|
|
90
|
+
maxWidth,
|
|
91
|
+
maxHeight: maxWidth,
|
|
92
|
+
result,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function getMinSize(configuration, getSupported, minSize) {
|
|
97
|
+
let minWidth = undefined;
|
|
98
|
+
let attempts = 1;
|
|
99
|
+
const dataMinSize = await getDecodingInfo({
|
|
100
|
+
...configuration,
|
|
101
|
+
video: {
|
|
102
|
+
...configuration.video,
|
|
103
|
+
width: minSize,
|
|
104
|
+
height: minSize,
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const supportedMinSize = getSupported(dataMinSize);
|
|
108
|
+
if (supportedMinSize) {
|
|
109
|
+
return {
|
|
110
|
+
attempts,
|
|
111
|
+
minWidth: minSize,
|
|
112
|
+
minHeight: minSize,
|
|
113
|
+
result: minSize,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const result = await binarySearch(async (value) => {
|
|
117
|
+
attempts++;
|
|
118
|
+
const data1 = await getDecodingInfo({
|
|
119
|
+
...configuration,
|
|
120
|
+
video: {
|
|
121
|
+
...configuration.video,
|
|
122
|
+
width: value - 1,
|
|
123
|
+
height: value - 1,
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
const supported1 = getSupported(data1);
|
|
127
|
+
if (supported1) {
|
|
128
|
+
minWidth = Math.min(minWidth || Infinity, value - 1);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
attempts++;
|
|
132
|
+
const data2 = await getDecodingInfo({
|
|
133
|
+
...configuration,
|
|
134
|
+
video: {
|
|
135
|
+
...configuration.video,
|
|
136
|
+
width: value,
|
|
137
|
+
height: value,
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
const supported2 = getSupported(data2);
|
|
141
|
+
if (supported2) {
|
|
142
|
+
minWidth = Math.min(minWidth || Infinity, value);
|
|
143
|
+
}
|
|
144
|
+
if (supported1 !== supported2) {
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
if (supported1 && supported2) {
|
|
148
|
+
return 1;
|
|
149
|
+
}
|
|
150
|
+
return -1;
|
|
151
|
+
}, minSize, START_SIZE);
|
|
152
|
+
return {
|
|
153
|
+
attempts,
|
|
154
|
+
minWidth,
|
|
155
|
+
minHeight: minWidth,
|
|
156
|
+
result,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function getVideoCodecSupportedResolution(configuration, options) {
|
|
161
|
+
const minSize = options?.minSize || MIN_SIZE;
|
|
162
|
+
const maxSize = options?.maxSize || MAX_SIZE;
|
|
163
|
+
const startSize = options?.startSize || START_SIZE;
|
|
164
|
+
const resultData = {
|
|
165
|
+
error: null,
|
|
166
|
+
attempts: 1,
|
|
167
|
+
supported: {
|
|
168
|
+
value: false,
|
|
169
|
+
minWidth: undefined,
|
|
170
|
+
minHeight: undefined,
|
|
171
|
+
maxWidth: undefined,
|
|
172
|
+
maxHeight: undefined,
|
|
173
|
+
},
|
|
174
|
+
smooth: {
|
|
175
|
+
value: false,
|
|
176
|
+
minWidth: undefined,
|
|
177
|
+
minHeight: undefined,
|
|
178
|
+
maxWidth: undefined,
|
|
179
|
+
maxHeight: undefined,
|
|
180
|
+
},
|
|
181
|
+
powerEfficient: {
|
|
182
|
+
value: false,
|
|
183
|
+
minWidth: undefined,
|
|
184
|
+
minHeight: undefined,
|
|
185
|
+
maxWidth: undefined,
|
|
186
|
+
maxHeight: undefined,
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
let decodingInfo;
|
|
190
|
+
try {
|
|
191
|
+
decodingInfo = await getDecodingInfo({
|
|
192
|
+
...configuration,
|
|
193
|
+
video: {
|
|
194
|
+
...configuration.video,
|
|
195
|
+
width: startSize,
|
|
196
|
+
height: startSize,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
resultData.error = error;
|
|
202
|
+
return resultData;
|
|
203
|
+
}
|
|
204
|
+
if (!decodingInfo.supported) {
|
|
205
|
+
return resultData;
|
|
206
|
+
}
|
|
207
|
+
resultData.supported.value = true;
|
|
208
|
+
const [supportedMinSize, supportedMaxSize, smoothMinSize, smoothMaxSize, powerEfficientMinSize, powerEfficientMaxSize] = await Promise.all([
|
|
209
|
+
getMinSize(configuration, (result) => result.supported, minSize),
|
|
210
|
+
getMaxSize(configuration, (result) => result.supported, maxSize),
|
|
211
|
+
getMinSize(configuration, (result) => result.supported && result.smooth, minSize),
|
|
212
|
+
getMaxSize(configuration, (result) => result.supported && result.smooth, maxSize),
|
|
213
|
+
getMinSize(configuration, (result) => result.supported && result.powerEfficient, minSize),
|
|
214
|
+
getMaxSize(configuration, (result) => result.supported && result.powerEfficient, maxSize),
|
|
215
|
+
]);
|
|
216
|
+
if (supportedMinSize.minWidth) {
|
|
217
|
+
resultData.supported.minWidth = supportedMinSize.minWidth;
|
|
218
|
+
resultData.supported.minHeight = supportedMinSize.minHeight;
|
|
219
|
+
}
|
|
220
|
+
if (supportedMaxSize.maxWidth) {
|
|
221
|
+
resultData.supported.maxWidth = supportedMaxSize.maxWidth;
|
|
222
|
+
resultData.supported.maxHeight = supportedMaxSize.maxHeight;
|
|
223
|
+
}
|
|
224
|
+
if (smoothMinSize.minWidth) {
|
|
225
|
+
resultData.smooth.value = true;
|
|
226
|
+
resultData.smooth.minWidth = smoothMinSize.minWidth;
|
|
227
|
+
resultData.smooth.minHeight = smoothMinSize.minHeight;
|
|
228
|
+
}
|
|
229
|
+
if (smoothMaxSize.maxWidth) {
|
|
230
|
+
resultData.smooth.value = true;
|
|
231
|
+
resultData.smooth.maxWidth = smoothMaxSize.maxWidth;
|
|
232
|
+
resultData.smooth.maxHeight = smoothMaxSize.maxHeight;
|
|
233
|
+
}
|
|
234
|
+
if (powerEfficientMinSize.minHeight) {
|
|
235
|
+
resultData.powerEfficient.value = true;
|
|
236
|
+
resultData.powerEfficient.minWidth = powerEfficientMinSize.minWidth;
|
|
237
|
+
resultData.powerEfficient.minHeight = powerEfficientMinSize.minHeight;
|
|
238
|
+
}
|
|
239
|
+
if (powerEfficientMaxSize.maxWidth) {
|
|
240
|
+
resultData.powerEfficient.value = true;
|
|
241
|
+
resultData.powerEfficient.maxWidth = powerEfficientMaxSize.maxWidth;
|
|
242
|
+
resultData.powerEfficient.maxHeight = powerEfficientMaxSize.maxHeight;
|
|
243
|
+
}
|
|
244
|
+
resultData.attempts += (supportedMinSize.attempts +
|
|
245
|
+
supportedMaxSize.attempts +
|
|
246
|
+
smoothMinSize.attempts +
|
|
247
|
+
smoothMaxSize.attempts +
|
|
248
|
+
powerEfficientMinSize.attempts +
|
|
249
|
+
powerEfficientMaxSize.attempts);
|
|
250
|
+
return resultData;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
exports.getVideoCodecSupportedResolution = getVideoCodecSupportedResolution;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface ResultData {
|
|
2
|
+
error: null | Error;
|
|
3
|
+
attempts: number;
|
|
4
|
+
supported: {
|
|
5
|
+
value: boolean;
|
|
6
|
+
minWidth: number | undefined;
|
|
7
|
+
minHeight: number | undefined;
|
|
8
|
+
maxWidth: number | undefined;
|
|
9
|
+
maxHeight: number | undefined;
|
|
10
|
+
};
|
|
11
|
+
smooth: {
|
|
12
|
+
value: boolean;
|
|
13
|
+
minWidth: number | undefined;
|
|
14
|
+
minHeight: number | undefined;
|
|
15
|
+
maxWidth: number | undefined;
|
|
16
|
+
maxHeight: number | undefined;
|
|
17
|
+
};
|
|
18
|
+
powerEfficient: {
|
|
19
|
+
value: boolean;
|
|
20
|
+
minWidth: number | undefined;
|
|
21
|
+
minHeight: number | undefined;
|
|
22
|
+
maxWidth: number | undefined;
|
|
23
|
+
maxHeight: number | undefined;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface GetVideoCodecSupportedResolutionOptions {
|
|
27
|
+
minSize?: number;
|
|
28
|
+
maxSize?: number;
|
|
29
|
+
startSize?: number;
|
|
30
|
+
}
|
|
31
|
+
export declare function getVideoCodecSupportedResolution(configuration: MediaDecodingConfiguration, options?: GetVideoCodecSupportedResolutionOptions): Promise<ResultData>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
function getDecodingInfo(configuration) {
|
|
2
|
+
return navigator.mediaCapabilities.decodingInfo(configuration);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
const MIN_SIZE = 1;
|
|
6
|
+
const MAX_SIZE = 64000;
|
|
7
|
+
const START_SIZE = 320;
|
|
8
|
+
|
|
9
|
+
async function binarySearch(compareFn, minValue, maxValue) {
|
|
10
|
+
let left = minValue;
|
|
11
|
+
let right = maxValue;
|
|
12
|
+
while (left <= right) {
|
|
13
|
+
const middle = Math.floor((right + left) / 2);
|
|
14
|
+
const cmp = await compareFn(middle);
|
|
15
|
+
if (cmp === 0) {
|
|
16
|
+
return middle;
|
|
17
|
+
}
|
|
18
|
+
else if (cmp < 0) {
|
|
19
|
+
left = middle + 1;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
right = middle - 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function getMaxSize(configuration, getSupported, maxSize) {
|
|
29
|
+
let maxWidth = undefined;
|
|
30
|
+
let attempts = 1;
|
|
31
|
+
const dataMaxSize = await getDecodingInfo({
|
|
32
|
+
...configuration,
|
|
33
|
+
video: {
|
|
34
|
+
...configuration.video,
|
|
35
|
+
width: maxSize,
|
|
36
|
+
height: maxSize,
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const supportedMaxSize = getSupported(dataMaxSize);
|
|
40
|
+
if (supportedMaxSize) {
|
|
41
|
+
return {
|
|
42
|
+
result: maxSize,
|
|
43
|
+
attempts,
|
|
44
|
+
maxWidth: maxSize,
|
|
45
|
+
maxHeight: maxSize,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const result = await binarySearch(async (value) => {
|
|
49
|
+
attempts++;
|
|
50
|
+
const data1 = await getDecodingInfo({
|
|
51
|
+
...configuration,
|
|
52
|
+
video: {
|
|
53
|
+
...configuration.video,
|
|
54
|
+
width: value,
|
|
55
|
+
height: value,
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const supported1 = getSupported(data1);
|
|
59
|
+
if (!supported1) {
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
if (supported1) {
|
|
63
|
+
maxWidth = Math.max(maxWidth || 0, value);
|
|
64
|
+
}
|
|
65
|
+
attempts++;
|
|
66
|
+
const data2 = await getDecodingInfo({
|
|
67
|
+
...configuration,
|
|
68
|
+
video: {
|
|
69
|
+
...configuration.video,
|
|
70
|
+
width: value + 1,
|
|
71
|
+
height: value + 1,
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const supported2 = getSupported(data2);
|
|
75
|
+
if (supported2) {
|
|
76
|
+
maxWidth = Math.max(maxWidth || 0, value + 1);
|
|
77
|
+
}
|
|
78
|
+
if (supported1 !== supported2) {
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
if (supported1 && supported2) {
|
|
82
|
+
return -1;
|
|
83
|
+
}
|
|
84
|
+
return 1;
|
|
85
|
+
}, START_SIZE, maxSize);
|
|
86
|
+
return {
|
|
87
|
+
attempts,
|
|
88
|
+
maxWidth,
|
|
89
|
+
maxHeight: maxWidth,
|
|
90
|
+
result,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function getMinSize(configuration, getSupported, minSize) {
|
|
95
|
+
let minWidth = undefined;
|
|
96
|
+
let attempts = 1;
|
|
97
|
+
const dataMinSize = await getDecodingInfo({
|
|
98
|
+
...configuration,
|
|
99
|
+
video: {
|
|
100
|
+
...configuration.video,
|
|
101
|
+
width: minSize,
|
|
102
|
+
height: minSize,
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const supportedMinSize = getSupported(dataMinSize);
|
|
106
|
+
if (supportedMinSize) {
|
|
107
|
+
return {
|
|
108
|
+
attempts,
|
|
109
|
+
minWidth: minSize,
|
|
110
|
+
minHeight: minSize,
|
|
111
|
+
result: minSize,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const result = await binarySearch(async (value) => {
|
|
115
|
+
attempts++;
|
|
116
|
+
const data1 = await getDecodingInfo({
|
|
117
|
+
...configuration,
|
|
118
|
+
video: {
|
|
119
|
+
...configuration.video,
|
|
120
|
+
width: value - 1,
|
|
121
|
+
height: value - 1,
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const supported1 = getSupported(data1);
|
|
125
|
+
if (supported1) {
|
|
126
|
+
minWidth = Math.min(minWidth || Infinity, value - 1);
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
attempts++;
|
|
130
|
+
const data2 = await getDecodingInfo({
|
|
131
|
+
...configuration,
|
|
132
|
+
video: {
|
|
133
|
+
...configuration.video,
|
|
134
|
+
width: value,
|
|
135
|
+
height: value,
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
const supported2 = getSupported(data2);
|
|
139
|
+
if (supported2) {
|
|
140
|
+
minWidth = Math.min(minWidth || Infinity, value);
|
|
141
|
+
}
|
|
142
|
+
if (supported1 !== supported2) {
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
if (supported1 && supported2) {
|
|
146
|
+
return 1;
|
|
147
|
+
}
|
|
148
|
+
return -1;
|
|
149
|
+
}, minSize, START_SIZE);
|
|
150
|
+
return {
|
|
151
|
+
attempts,
|
|
152
|
+
minWidth,
|
|
153
|
+
minHeight: minWidth,
|
|
154
|
+
result,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function getVideoCodecSupportedResolution(configuration, options) {
|
|
159
|
+
const minSize = options?.minSize || MIN_SIZE;
|
|
160
|
+
const maxSize = options?.maxSize || MAX_SIZE;
|
|
161
|
+
const startSize = options?.startSize || START_SIZE;
|
|
162
|
+
const resultData = {
|
|
163
|
+
error: null,
|
|
164
|
+
attempts: 1,
|
|
165
|
+
supported: {
|
|
166
|
+
value: false,
|
|
167
|
+
minWidth: undefined,
|
|
168
|
+
minHeight: undefined,
|
|
169
|
+
maxWidth: undefined,
|
|
170
|
+
maxHeight: undefined,
|
|
171
|
+
},
|
|
172
|
+
smooth: {
|
|
173
|
+
value: false,
|
|
174
|
+
minWidth: undefined,
|
|
175
|
+
minHeight: undefined,
|
|
176
|
+
maxWidth: undefined,
|
|
177
|
+
maxHeight: undefined,
|
|
178
|
+
},
|
|
179
|
+
powerEfficient: {
|
|
180
|
+
value: false,
|
|
181
|
+
minWidth: undefined,
|
|
182
|
+
minHeight: undefined,
|
|
183
|
+
maxWidth: undefined,
|
|
184
|
+
maxHeight: undefined,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
let decodingInfo;
|
|
188
|
+
try {
|
|
189
|
+
decodingInfo = await getDecodingInfo({
|
|
190
|
+
...configuration,
|
|
191
|
+
video: {
|
|
192
|
+
...configuration.video,
|
|
193
|
+
width: startSize,
|
|
194
|
+
height: startSize,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
resultData.error = error;
|
|
200
|
+
return resultData;
|
|
201
|
+
}
|
|
202
|
+
if (!decodingInfo.supported) {
|
|
203
|
+
return resultData;
|
|
204
|
+
}
|
|
205
|
+
resultData.supported.value = true;
|
|
206
|
+
const [supportedMinSize, supportedMaxSize, smoothMinSize, smoothMaxSize, powerEfficientMinSize, powerEfficientMaxSize] = await Promise.all([
|
|
207
|
+
getMinSize(configuration, (result) => result.supported, minSize),
|
|
208
|
+
getMaxSize(configuration, (result) => result.supported, maxSize),
|
|
209
|
+
getMinSize(configuration, (result) => result.supported && result.smooth, minSize),
|
|
210
|
+
getMaxSize(configuration, (result) => result.supported && result.smooth, maxSize),
|
|
211
|
+
getMinSize(configuration, (result) => result.supported && result.powerEfficient, minSize),
|
|
212
|
+
getMaxSize(configuration, (result) => result.supported && result.powerEfficient, maxSize),
|
|
213
|
+
]);
|
|
214
|
+
if (supportedMinSize.minWidth) {
|
|
215
|
+
resultData.supported.minWidth = supportedMinSize.minWidth;
|
|
216
|
+
resultData.supported.minHeight = supportedMinSize.minHeight;
|
|
217
|
+
}
|
|
218
|
+
if (supportedMaxSize.maxWidth) {
|
|
219
|
+
resultData.supported.maxWidth = supportedMaxSize.maxWidth;
|
|
220
|
+
resultData.supported.maxHeight = supportedMaxSize.maxHeight;
|
|
221
|
+
}
|
|
222
|
+
if (smoothMinSize.minWidth) {
|
|
223
|
+
resultData.smooth.value = true;
|
|
224
|
+
resultData.smooth.minWidth = smoothMinSize.minWidth;
|
|
225
|
+
resultData.smooth.minHeight = smoothMinSize.minHeight;
|
|
226
|
+
}
|
|
227
|
+
if (smoothMaxSize.maxWidth) {
|
|
228
|
+
resultData.smooth.value = true;
|
|
229
|
+
resultData.smooth.maxWidth = smoothMaxSize.maxWidth;
|
|
230
|
+
resultData.smooth.maxHeight = smoothMaxSize.maxHeight;
|
|
231
|
+
}
|
|
232
|
+
if (powerEfficientMinSize.minHeight) {
|
|
233
|
+
resultData.powerEfficient.value = true;
|
|
234
|
+
resultData.powerEfficient.minWidth = powerEfficientMinSize.minWidth;
|
|
235
|
+
resultData.powerEfficient.minHeight = powerEfficientMinSize.minHeight;
|
|
236
|
+
}
|
|
237
|
+
if (powerEfficientMaxSize.maxWidth) {
|
|
238
|
+
resultData.powerEfficient.value = true;
|
|
239
|
+
resultData.powerEfficient.maxWidth = powerEfficientMaxSize.maxWidth;
|
|
240
|
+
resultData.powerEfficient.maxHeight = powerEfficientMaxSize.maxHeight;
|
|
241
|
+
}
|
|
242
|
+
resultData.attempts += (supportedMinSize.attempts +
|
|
243
|
+
supportedMaxSize.attempts +
|
|
244
|
+
smoothMinSize.attempts +
|
|
245
|
+
smoothMaxSize.attempts +
|
|
246
|
+
powerEfficientMinSize.attempts +
|
|
247
|
+
powerEfficientMaxSize.attempts);
|
|
248
|
+
return resultData;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export { getVideoCodecSupportedResolution };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function binarySearch(compareFn: (value: number) => Promise<number> | number, minValue: number, maxValue: number): Promise<number | null>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDecodingInfo(configuration: MediaDecodingConfiguration): Promise<MediaCapabilitiesDecodingInfo>;
|
package/package.json
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "decoding-info",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Testing audio and video codec support in a browser with or without a key system",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.common.js",
|
|
7
7
|
"module": "src/index.esm.js",
|
|
8
8
|
"typings": "src/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
|
+
"prepare": "npm run build",
|
|
10
11
|
"clean": "del ./dist/*",
|
|
12
|
+
"build": "npm run clean && rollup --config rollup.config.mjs && cp -f ./dist/index.esm.js ./pages",
|
|
11
13
|
"test": "jest . && npm run typecheck",
|
|
12
|
-
"typecheck": "tsc --noEmit"
|
|
13
|
-
"build": "npm run clean && rollup --config rollup.config.mjs"
|
|
14
|
+
"typecheck": "tsc --noEmit"
|
|
14
15
|
},
|
|
15
16
|
"files": [
|
|
16
17
|
"dist",
|
|
17
18
|
"README.md",
|
|
18
|
-
"CHANGELOG.md"
|
|
19
|
+
"CHANGELOG.md",
|
|
20
|
+
"LICENSE.md"
|
|
19
21
|
],
|
|
20
22
|
"keywords": [
|
|
21
23
|
"media",
|
|
@@ -34,12 +36,12 @@
|
|
|
34
36
|
"@jest/globals": "^30.2.0",
|
|
35
37
|
"@rollup/plugin-typescript": "12.3.0",
|
|
36
38
|
"@types/jest": "^30.0.0",
|
|
37
|
-
"@types/node": "^
|
|
39
|
+
"@types/node": "^25.0.10",
|
|
38
40
|
"del-cli": "^7.0.0",
|
|
39
41
|
"jest": "^30.2.0",
|
|
40
42
|
"jest-environment-jsdom": "^30.2.0",
|
|
41
|
-
"rollup": "4.
|
|
42
|
-
"ts-jest": "^29.4.
|
|
43
|
+
"rollup": "4.56.0",
|
|
44
|
+
"ts-jest": "^29.4.6",
|
|
43
45
|
"tslib": "2.8.1",
|
|
44
46
|
"typescript": "5.9.3"
|
|
45
47
|
}
|