MCPcopy Create free account
hub / github.com/Recordscript/recordscript / new

Method new

libs/scrap/src/common/codec.rs:128–168  ·  view source on GitHub ↗
(config: EncoderCfg, i444: bool)

Source from the content-addressed store, hash-verified

126
127impl Encoder {
128 pub fn new(config: EncoderCfg, i444: bool) -> ResultType<Encoder> {
129 log::info!("new encoder: {config:?}, i444: {i444}");
130 match config {
131 EncoderCfg::VPX(_) => Ok(Encoder {
132 codec: Box::new(VpxEncoder::new(config, i444)?),
133 }),
134 EncoderCfg::AOM(_) => Ok(Encoder {
135 codec: Box::new(AomEncoder::new(config, i444)?),
136 }),
137
138 #[cfg(feature = "hwcodec")]
139 EncoderCfg::HWRAM(_) => match HwRamEncoder::new(config, i444) {
140 Ok(hw) => Ok(Encoder {
141 codec: Box::new(hw),
142 }),
143 Err(e) => {
144 log::error!("new hw encoder failed: {e:?}, clear config");
145 #[cfg(target_os = "android")]
146 crate::android::ffi::clear_codec_info();
147 #[cfg(not(target_os = "android"))]
148 hbb_common::config::HwCodecConfig::clear_ram();
149 Self::update(EncodingUpdate::Check);
150 *ENCODE_CODEC_FORMAT.lock().unwrap() = CodecFormat::VP9;
151 Err(e)
152 }
153 },
154 #[cfg(feature = "vram")]
155 EncoderCfg::VRAM(_) => match VRamEncoder::new(config, i444) {
156 Ok(tex) => Ok(Encoder {
157 codec: Box::new(tex),
158 }),
159 Err(e) => {
160 log::error!("new vram encoder failed: {e:?}, clear config");
161 hbb_common::config::HwCodecConfig::clear_vram();
162 Self::update(EncodingUpdate::Check);
163 *ENCODE_CODEC_FORMAT.lock().unwrap() = CodecFormat::VP9;
164 Err(e)
165 }
166 },
167 }
168 }
169
170 pub fn update(update: EncodingUpdate) {
171 log::info!("update:{:?}", update);

Callers

nothing calls this directly

Calls 4

clear_codec_infoFunction · 0.85
enable_vram_optionFunction · 0.85
enable_hwcodec_optionFunction · 0.85
cloneMethod · 0.45

Tested by

no test coverage detected