* Checks if the encoder can support the given configuration.
(config: AudioEncoderConfig)
| 153 | * Checks if the encoder can support the given configuration. |
| 154 | */ |
| 155 | static async isConfigSupported(config: AudioEncoderConfig): Promise<AudioEncoderSupport> { |
| 156 | const inferred = inferCodecFromCodecString(config.codec); |
| 157 | if (!inferred) { |
| 158 | return { config, supported: false }; |
| 159 | } |
| 160 | |
| 161 | const cacheKey = configToCacheKey(inferred, config.sampleRate, config.numberOfChannels, config.bitrate); |
| 162 | if (configSupportCache.has(cacheKey)) { |
| 163 | return { config, supported: configSupportCache.get(cacheKey)! }; |
| 164 | } |
| 165 | |
| 166 | const result = this.createCodecContext(config); |
| 167 | if (!result) { |
| 168 | return { config, supported: false }; |
| 169 | } |
| 170 | |
| 171 | const { codecContext } = result; |
| 172 | const ret = await codecContext.open2(); |
| 173 | const supported = ret >= 0; |
| 174 | codecContext.freeContext(); |
| 175 | |
| 176 | configSupportCache.set(cacheKey, supported); |
| 177 | |
| 178 | return { config, supported }; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Configures the encoder with the given configuration. |
nothing calls this directly
no test coverage detected