use std::path::PathBuf;
use lazy_static::lazy_static;
use tempfile::{NamedTempFile, TempDir};
const buildtype_docs_only_stub_msg: &'static str =
"stub for docs.rs only (when cargo feature = 'buildtype-docs-only')";
#[cfg(not(feature="buildtype-docs-only"))]
pub fn get_vmaf_def_model() -> (&'static str, &'static str) {
let x = include_str!(concat!(env!("OUT_DIR"), "/vmaf/release/vmaf_v0.6.1.pkl"));
let y = include_str!(concat!(env!("OUT_DIR"), "/vmaf/release/vmaf_v0.6.1.pkl.model"));
(x, y)
}
#[cfg(not(feature="buildtype-docs-only"))]
pub fn get_vmaf_4k_model() -> (&'static str, &'static str) {
let x = include_str!(concat!(env!("OUT_DIR"), "/vmaf/release/vmaf_4k_v0.6.1.pkl"));
let y = include_str!(concat!(env!("OUT_DIR"), "/vmaf/release/vmaf_4k_v0.6.1.pkl.model"));
(x, y)
}
#[cfg(feature="buildtype-docs-only")]
pub fn get_vmaf_def_model() -> (&'static str, &'static str) {panic!(buildtype_docs_only_stub_msg)}
#[cfg(feature="buildtype-docs-only")]
pub fn get_vmaf_4k_model() -> (&'static str, &'static str) {panic!(buildtype_docs_only_stub_msg)}
struct TmpVmafModelFile {
dir: TempDir,
path: PathBuf,
}
lazy_static! {
static ref TMP_VMAF_DEF_MODEL_FILE: TmpVmafModelFile = {
let mut root_dir = TempDir::new().expect("TempDir::new() failed");
let mut model_pkg = PathBuf::from(root_dir.path())
.join("vmaf_v0.6.1.pkl");
let mut model_other = PathBuf::from(root_dir.path())
.join("vmaf_v0.6.1.pkl.model");
let (pkg, other) = get_vmaf_def_model();
std::fs::write(&model_pkg, pkg).expect("TmpVmafModelFile::new_tmp");
std::fs::write(&model_other, other).expect("TmpVmafModelFile::new_tmp");
TmpVmafModelFile {
dir: root_dir,
path: model_pkg,
}
};
static ref TMP_VMAF_4K_MODEL_FILE: TmpVmafModelFile = {
let mut root_dir = TempDir::new().expect("TempDir::new() failed");
let mut model_pkg = PathBuf::from(root_dir.path())
.join("vmaf_4k_v0.6.1.pkl");
let mut model_other = PathBuf::from(root_dir.path())
.join("vmaf_4k_v0.6.1.pkl.model");
let (pkg, other) = get_vmaf_4k_model();
std::fs::write(&model_pkg, pkg).expect("TmpVmafModelFile::new_tmp");
std::fs::write(&model_other, other).expect("TmpVmafModelFile::new_tmp");
TmpVmafModelFile {
dir: root_dir,
path: model_pkg,
}
};
}
pub fn get_def_model_path() -> PathBuf {
TMP_VMAF_DEF_MODEL_FILE.path.clone()
}
pub fn get_4k_model_path() -> PathBuf {
TMP_VMAF_4K_MODEL_FILE.path.clone()
}