You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.2 KiB
Rust

use crate::av::as_ptr::AsMutVoidPtr;
use crate::av::dictionary::Dictionary;
use ffmpeg_sys_next::{av_opt_find, av_opt_get_int, av_opt_set_dict, av_opt_set_int};
use std::ffi::CString;
use std::ptr::null;
pub trait Options: AsMutVoidPtr {
fn set_options(&mut self, mut options: Dictionary) {
options.disown();
unsafe {
av_opt_set_dict(self.as_mut_void_ptr(), &mut options.as_mut_ptr());
}
}
fn set_flag(&self, option: &str, flag: &str) -> bool {
let option_c = CString::new(option).unwrap();
let flag_c = CString::new(flag).unwrap();
unsafe {
let option = av_opt_find(self.as_mut_void_ptr(), option_c.as_ptr(), null(), 0, 0);
let flag = av_opt_find(self.as_mut_void_ptr(), flag_c.as_ptr(), null(), 0, 0);
if flag.is_null() || option.is_null() {
return false;
}
let mut val: i64 = 0;
av_opt_get_int(self.as_mut_void_ptr(), option_c.as_ptr(), 0, &mut val);
av_opt_set_int(
self.as_mut_void_ptr(),
option_c.as_ptr(),
val | (*flag).default_val.i64,
0,
);
}
true
}
}