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.
56 lines
1.1 KiB
Rust
56 lines
1.1 KiB
Rust
use crate::av::as_ptr::{AsMutPtr, AsPtr};
|
|
use ffmpeg_sys_next::{avio_close_dyn_buf, avio_open_dyn_buf, AVIOContext};
|
|
use std::ptr::null_mut;
|
|
|
|
struct Dynbuf {
|
|
ptr: *mut AVIOContext,
|
|
freed: bool,
|
|
}
|
|
|
|
impl Dynbuf {
|
|
fn new() -> Dynbuf {
|
|
let mut ctx = null_mut();
|
|
unsafe {
|
|
avio_open_dyn_buf(&mut ctx);
|
|
}
|
|
|
|
Dynbuf {
|
|
ptr: ctx,
|
|
freed: false,
|
|
}
|
|
}
|
|
|
|
fn close(&mut self) -> Vec<u8> {
|
|
let mut buffer = null_mut();
|
|
self.freed = true;
|
|
unsafe {
|
|
let size = avio_close_dyn_buf(self.ptr, &mut buffer);
|
|
Vec::from_raw_parts(buffer, size as usize, size as usize)
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Drop for Dynbuf {
|
|
fn drop(&mut self) {
|
|
if self.freed {
|
|
return;
|
|
}
|
|
|
|
unsafe {
|
|
avio_close_dyn_buf(self.ptr, null_mut());
|
|
}
|
|
}
|
|
}
|
|
|
|
impl AsPtr<AVIOContext> for Dynbuf {
|
|
fn as_ptr(&self) -> *const AVIOContext {
|
|
self.ptr
|
|
}
|
|
}
|
|
|
|
impl AsMutPtr<AVIOContext> for Dynbuf {
|
|
fn as_mut_ptr(&self) -> *mut AVIOContext {
|
|
self.ptr
|
|
}
|
|
}
|