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.
93 lines
2.1 KiB
Rust
93 lines
2.1 KiB
Rust
use ffmpeg_sys_next::{av_dict_free, av_dict_get, av_dict_set, av_dict_set_int, AVDictionary};
|
|
use std::ffi::CString;
|
|
use std::ptr::{null, null_mut};
|
|
|
|
pub struct Dictionary {
|
|
pub ptr: *mut AVDictionary,
|
|
pub owned: bool,
|
|
}
|
|
|
|
impl Dictionary {
|
|
#[inline]
|
|
pub fn as_ptr(&self) -> *const AVDictionary {
|
|
self.ptr
|
|
}
|
|
|
|
#[inline]
|
|
pub fn as_mut_ptr(&mut self) -> *mut AVDictionary {
|
|
self.ptr
|
|
}
|
|
|
|
pub fn new() -> Dictionary {
|
|
Dictionary {
|
|
ptr: null_mut(),
|
|
owned: false,
|
|
}
|
|
}
|
|
|
|
pub fn disown(&mut self) {
|
|
self.owned = false;
|
|
}
|
|
|
|
pub fn own(&mut self) {
|
|
self.owned = true;
|
|
}
|
|
|
|
pub fn set(&mut self, key: &str, value: &str) {
|
|
let key_c = CString::new(key).unwrap();
|
|
let value_c = CString::new(value).unwrap();
|
|
unsafe {
|
|
av_dict_set(&mut self.ptr, key_c.as_ptr(), value_c.as_ptr(), 0);
|
|
}
|
|
}
|
|
|
|
pub fn delete(&mut self, key: &str) {
|
|
let key_c = CString::new(key).unwrap();
|
|
unsafe {
|
|
av_dict_set(&mut self.ptr, key_c.as_ptr(), null(), 0);
|
|
}
|
|
}
|
|
|
|
pub fn get(&self, key: &str) -> Option<String> {
|
|
let key_c = CString::new(key).unwrap();
|
|
unsafe {
|
|
let entry = av_dict_get(self.ptr, key_c.as_ptr(), null(), 0);
|
|
if entry.is_null() {
|
|
None
|
|
} else {
|
|
Some(
|
|
CString::from_raw((*entry).value)
|
|
.to_str()
|
|
.unwrap()
|
|
.to_string(),
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Drop for Dictionary {
|
|
fn drop(&mut self) {
|
|
if !self.owned {
|
|
return;
|
|
}
|
|
|
|
unsafe {
|
|
av_dict_free(&mut self.ptr);
|
|
}
|
|
}
|
|
}
|
|
|
|
impl DictionaryInt for Dictionary {
|
|
fn set(&mut self, key: &str, value: i64) {
|
|
let key_c = CString::new(key).unwrap();
|
|
unsafe {
|
|
av_dict_set_int(&mut self.ptr, key_c.as_ptr(), value, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub trait DictionaryInt {
|
|
fn set(&mut self, key: &str, value: i64);
|
|
}
|