Skip to content

Commit daed148

Browse files
committed
add extra API for optimizations in gstvvenc
1 parent feb0472 commit daed148

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

src/lib.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,15 @@ impl Config {
578578
self
579579
}
580580

581+
pub fn output_bit_depth(&self) -> [i32; 2] {
582+
self.inner.m_outputBitDepth
583+
}
584+
585+
pub fn set_output_bit_depth(&mut self, output_bit_depth: [i32; 2]) -> &mut Self {
586+
self.inner.m_outputBitDepth = output_bit_depth;
587+
self
588+
}
589+
581590
pub fn num_threads(&self) -> i32 {
582591
self.inner.m_numThreads
583592
}
@@ -833,6 +842,7 @@ pub struct YUVBuffer<Opaque> {
833842
inner: vvencYUVBuffer,
834843
_phantom: std::marker::PhantomData<Opaque>,
835844
opaque: Option<Box<Opaque>>,
845+
owned: bool,
836846
}
837847

838848
unsafe impl<Opaque> Send for YUVBuffer<Opaque> {}
@@ -847,6 +857,23 @@ pub enum YUVComponent {
847857
}
848858

849859
impl<Opaque: Sized + Send + Sync> YUVBuffer<Opaque> {
860+
pub fn from_planes(planes: &[Plane]) -> Self {
861+
let inner = unsafe {
862+
let mut inner: vvencYUVBuffer = std::mem::zeroed();
863+
for (i, plane) in planes.iter().enumerate() {
864+
inner.planes[i] = plane.inner;
865+
}
866+
inner
867+
};
868+
// inner.opaque = ptr::null_mut();
869+
Self {
870+
inner,
871+
_phantom: std::marker::PhantomData::default(),
872+
opaque: None,
873+
owned: false,
874+
}
875+
}
876+
850877
pub fn new(width: i32, height: i32, chroma_format: ChromaFormat) -> Self {
851878
let inner = unsafe {
852879
let mut inner = std::mem::zeroed();
@@ -858,9 +885,14 @@ impl<Opaque: Sized + Send + Sync> YUVBuffer<Opaque> {
858885
inner,
859886
_phantom: std::marker::PhantomData::default(),
860887
opaque: None,
888+
owned: true,
861889
}
862890
}
863891

892+
pub fn is_owned(&self) -> bool {
893+
self.owned
894+
}
895+
864896
pub fn plane_mut<'a>(&'a mut self, component: YUVComponent) -> Plane<'a> {
865897
Plane {
866898
inner: self.inner.planes[component as usize],
@@ -896,8 +928,10 @@ impl<Opaque: Sized + Send + Sync> YUVBuffer<Opaque> {
896928

897929
impl<Opaque> Drop for YUVBuffer<Opaque> {
898930
fn drop(&mut self) {
899-
unsafe {
900-
vvenc_YUVBuffer_free_buffer(&mut self.inner);
931+
if self.owned {
932+
unsafe {
933+
vvenc_YUVBuffer_free_buffer(&mut self.inner);
934+
}
901935
}
902936
}
903937
}
@@ -909,6 +943,21 @@ pub struct Plane<'a> {
909943
}
910944

911945
impl<'a> Plane<'a> {
946+
pub fn from_slice(buf: &'a [i16], width: i32, height: i32, stride: i32) -> Self {
947+
let inner = unsafe {
948+
let mut inner: vvencYUVPlane = std::mem::zeroed();
949+
inner.ptr = buf.as_ptr() as *mut i16;
950+
inner.width = width;
951+
inner.height = height;
952+
inner.stride = stride;
953+
inner
954+
};
955+
Self {
956+
inner,
957+
phantom: std::marker::PhantomData,
958+
}
959+
}
960+
912961
pub fn data(&mut self) -> &[i16] {
913962
unsafe {
914963
std::slice::from_raw_parts(

0 commit comments

Comments
 (0)