mirror of
https://github.com/v0l/zap-stream-core.git
synced 2025-06-20 10:47:02 +00:00
Progress
This commit is contained in:
52
src/utils.rs
52
src/utils.rs
@ -1,6 +1,11 @@
|
||||
use ffmpeg_sys_next::av_make_error_string;
|
||||
use std::ffi::CStr;
|
||||
|
||||
use anyhow::Error;
|
||||
use ffmpeg_sys_next::{av_buffer_allocz, av_make_error_string, AVBufferRef, memcpy};
|
||||
use uuid::{Bytes, Uuid};
|
||||
|
||||
use crate::variant::{VariantStream, VideoVariant};
|
||||
|
||||
pub fn get_ffmpeg_error_msg(ret: libc::c_int) -> String {
|
||||
unsafe {
|
||||
const BUF_SIZE: usize = 512;
|
||||
@ -9,3 +14,48 @@ pub fn get_ffmpeg_error_msg(ret: libc::c_int) -> String {
|
||||
String::from(CStr::from_ptr(buf.as_ptr()).to_str().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn variant_id_ref(var: &VariantStream) -> Result<*mut AVBufferRef, Error> {
|
||||
unsafe {
|
||||
match var {
|
||||
VariantStream::Audio(va) => {
|
||||
let buf = av_buffer_allocz(16);
|
||||
memcpy(
|
||||
(*buf).data as *mut libc::c_void,
|
||||
va.id.as_bytes().as_ptr() as *const libc::c_void,
|
||||
16,
|
||||
);
|
||||
Ok(buf)
|
||||
}
|
||||
VariantStream::Video(vv) => {
|
||||
let buf = av_buffer_allocz(16);
|
||||
memcpy(
|
||||
(*buf).data as *mut libc::c_void,
|
||||
vv.id.as_bytes().as_ptr() as *const libc::c_void,
|
||||
16,
|
||||
);
|
||||
Ok(buf)
|
||||
}
|
||||
_ => return Err(Error::msg("Cannot assign pkt stream index")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn video_variant_id_ref(var: &VideoVariant) -> *mut AVBufferRef {
|
||||
unsafe {
|
||||
let buf = av_buffer_allocz(16);
|
||||
memcpy(
|
||||
(*buf).data as *mut libc::c_void,
|
||||
var.id.as_bytes().as_ptr() as *const libc::c_void,
|
||||
16,
|
||||
);
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
||||
pub fn id_ref_to_uuid(buf: *mut AVBufferRef) -> Uuid {
|
||||
unsafe {
|
||||
let binding = Bytes::from(*((*buf).data as *const [u8; 16]));
|
||||
Uuid::from_bytes_ref(&binding).clone()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user