-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
194 lines (175 loc) · 6.29 KB
/
Copy pathconfig.ts
File metadata and controls
194 lines (175 loc) · 6.29 KB
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
/*
* This file is part of the libav.js WebCodecs Polyfill implementation. The
* interface implemented is derived from the W3C standard. No attribution is
* required when using this library.
*
* Copyright (c) 2021 Yahweasel
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
import * as eac from "./encoded-audio-chunk";
import * as ad from "./audio-data";
import * as adec from "./audio-decoder";
import * as aenc from "./audio-encoder";
import * as evc from "./encoded-video-chunk";
import * as vf from "./video-frame";
import * as vdec from "./video-decoder";
import * as venc from "./video-encoder";
import '@ungap/global-this';
/**
* An AudioDecoder environment.
*/
export interface AudioDecoderEnvironment {
AudioDecoder: typeof adec.AudioDecoder,
EncodedAudioChunk: typeof eac.EncodedAudioChunk,
AudioData: typeof ad.AudioData
}
/**
* A VideoDecoder environment.
*/
export interface VideoDecoderEnvironment {
VideoDecoder: typeof vdec.VideoDecoder,
EncodedVideoChunk: typeof evc.EncodedVideoChunk,
VideoFrame: typeof vf.VideoFrame
}
/**
* An AudioEncoder environment.
*/
export interface AudioEncoderEnvironment {
AudioEncoder: typeof aenc.AudioEncoder,
EncodedAudioChunk: typeof eac.EncodedAudioChunk,
AudioData: typeof ad.AudioData
}
/**
* A VideoEncoder environment.
*/
export interface VideoEncoderEnvironment {
VideoEncoder: typeof venc.VideoEncoder,
EncodedVideoChunk: typeof evc.EncodedVideoChunk,
VideoFrame: typeof vf.VideoFrame
}
/**
* Error thrown to indicate a configuration is unsupported.
*/
export class UnsupportedException extends Error {
constructor() {
super("The requested configuration is not supported");
}
}
/**
* Get an AudioDecoder environment that supports this configuration. Throws an
* UnsupportedException if no environment supports the configuration.
* @param config Audio decoder configuration
*/
export async function getAudioDecoder(
config: adec.AudioDecoderConfig
): Promise<AudioDecoderEnvironment> {
try {
if (typeof (<any> globalThis).AudioDecoder !== "undefined" &&
(await (<any> globalThis).AudioDecoder.isConfigSupported(config)).supported) {
return {
AudioDecoder: (<any> globalThis).AudioDecoder,
EncodedAudioChunk: (<any> globalThis).EncodedAudioChunk,
AudioData: (<any> globalThis).AudioData
};
}
} catch (ex) {}
if ((await adec.AudioDecoder.isConfigSupported(config)).supported) {
return {
AudioDecoder: adec.AudioDecoder,
EncodedAudioChunk: eac.EncodedAudioChunk,
AudioData: ad.AudioData
};
}
throw new UnsupportedException();
}
/**
* Get an VideoDecoder environment that supports this configuration. Throws an
* UnsupportedException if no environment supports the configuration.
* @param config Video decoder configuration
*/
export async function getVideoDecoder(
config: vdec.VideoDecoderConfig
): Promise<VideoDecoderEnvironment> {
try {
if (typeof (<any> globalThis).VideoDecoder !== "undefined" &&
(await (<any> globalThis).VideoDecoder.isConfigSupported(config)).supported) {
return {
VideoDecoder: (<any> globalThis).VideoDecoder,
EncodedVideoChunk: (<any> globalThis).EncodedVideoChunk,
VideoFrame: (<any> globalThis).VideoFrame
};
}
} catch (ex) {}
if ((await vdec.VideoDecoder.isConfigSupported(config)).supported) {
return {
VideoDecoder: vdec.VideoDecoder,
EncodedVideoChunk: evc.EncodedVideoChunk,
VideoFrame: vf.VideoFrame
};
}
throw new UnsupportedException();
}
/**
* Get an AudioEncoder environment that supports this configuration. Throws an
* UnsupportedException if no environment supports the configuration.
* @param config Audio encoder configuration
*/
export async function getAudioEncoder(
config: aenc.AudioEncoderConfig
): Promise<AudioEncoderEnvironment> {
try {
if (typeof (<any> globalThis).AudioEncoder !== "undefined" &&
(await (<any> globalThis).AudioEncoder.isConfigSupported(config)).supported) {
return {
AudioEncoder: (<any> globalThis).AudioEncoder,
EncodedAudioChunk: (<any> globalThis).EncodedAudioChunk,
AudioData: (<any> globalThis).AudioData
};
}
} catch (ex) {}
if ((await aenc.AudioEncoder.isConfigSupported(config)).supported) {
return {
AudioEncoder: aenc.AudioEncoder,
EncodedAudioChunk: eac.EncodedAudioChunk,
AudioData: ad.AudioData
};
}
throw new UnsupportedException();
}
/**
* Get an VideoEncoder environment that supports this configuration. Throws an
* UnsupportedException if no environment supports the configuration.
* @param config Video encoder configuration
*/
export async function getVideoEncoder(
config: venc.VideoEncoderConfig
): Promise<VideoEncoderEnvironment> {
try {
if (typeof (<any> globalThis).VideoEncoder !== "undefined" &&
(await (<any> globalThis).VideoEncoder.isConfigSupported(config)).supported) {
return {
VideoEncoder: (<any> globalThis).VideoEncoder,
EncodedVideoChunk: (<any> globalThis).EncodedVideoChunk,
VideoFrame: (<any> globalThis).VideoFrame
};
}
} catch (ex) {}
if ((await venc.VideoEncoder.isConfigSupported(config)).supported) {
return {
VideoEncoder: venc.VideoEncoder,
EncodedVideoChunk: evc.EncodedVideoChunk,
VideoFrame: vf.VideoFrame
};
}
throw new UnsupportedException();
}