>::as_mut(&mut a).copy_from_slice(slice);
a
}
fn touch_file(p: P) -> io::Result<()>
where
P: AsRef + std::fmt::Debug
{
let f = File::create(p)?;
let now = FileTime::now();
set_file_handle_times(&f, Some(now), Some(now))?;
Ok(())
}
fn steam_compat_shader_path() -> Option
{
match std::env::var("STEAM_COMPAT_SHADER_PATH") {
Err(_) => None,
Ok(c) => Some(Path::new(&c).to_path_buf()),
}
}
/* rust has a hard time with large heap allocations. below macro works around that.
*
* by @simias from https://github.com/rust-lang/rust/issues/53827 */
#[macro_export]
macro_rules! box_array {
($val:expr ; $len:expr) => {{
// Use a generic function so that the pointer cast remains type-safe
fn vec_to_boxed_array(vec: Vec) -> Box<[T; $len]> {
let boxed_slice = vec.into_boxed_slice();
let ptr = ::std::boxed::Box::into_raw(boxed_slice) as *mut [T; $len];
unsafe { Box::from_raw(ptr) }
}
vec_to_boxed_array(vec![$val; $len])
}};
}
/* you MUST use this to consistently format the hash bytes into a string */
fn format_hash(hash: u128) -> String {
format!("{:032x}", hash)
}
/* changing this will invalidate the cache. you MUST clear it. */
const HASH_SEED: u32 = 0x4AA61F63;
pub struct BufferedReader<'a> {
dat: &'a [u8],
len: usize,
ofs: usize,
}
impl<'a> BufferedReader<'a> {
fn new(dat: &'a [u8], len: usize) -> Self {
BufferedReader {
dat,
len,
ofs: 0,
}
}
}
impl<'a> Read for BufferedReader<'a> {
fn read(&mut self, out: &mut [u8]) -> io::Result {
let to_copy = std::cmp::min(self.len - self.ofs, out.len());
if to_copy == 0 {
return Ok(0);
}
if to_copy == out.len() {
out.copy_from_slice(&self.dat[self.ofs..(self.ofs + to_copy)]);
}else{
out[0..to_copy].copy_from_slice(&self.dat[self.ofs..(self.ofs + to_copy)]);
}
self.ofs += to_copy;
Ok(to_copy)
}
}
fn discarding_disabled() -> bool {
let v = match std::env::var("MEDIACONV_DONT_DISCARD") {
Err(_) => { return false; },
Ok(c) => c,
};
v != "0"
}
fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
videoconv::register(plugin)?;
audioconvbin::register(plugin)?;
audioconv::register(plugin)?;
Ok(())
}
plugin_define!(
protonmediaconverter,
env!("CARGO_PKG_DESCRIPTION"),
plugin_init,
concat!(env!("CARGO_PKG_VERSION"), "-", env!("COMMIT_ID")),
"MIT/X11",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_REPOSITORY"),
env!("BUILD_REL_DATE")
);