Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C-string literals for EL type in C-API #298

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions dolby_vision/src/c_structs/rpu_data_header.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use libc::c_char;
use std::{ffi::CString, ptr::null};
use std::ptr::null;

use crate::rpu::rpu_data_header::RpuDataHeader as RuRpuDataHeader;

Expand Down Expand Up @@ -43,16 +43,6 @@ pub struct RpuDataHeader {
prev_vdr_rpu_id: u64,
}

impl RpuDataHeader {
/// # Safety
/// The buffer pointers should be valid.
pub unsafe fn free(&self) {
if !self.el_type.is_null() {
drop(CString::from_raw(self.el_type as *mut c_char));
}
}
}

impl From<&RuRpuDataHeader> for RpuDataHeader {
fn from(header: &RuRpuDataHeader) -> Self {
#[allow(deprecated)]
Expand Down
19 changes: 18 additions & 1 deletion dolby_vision/src/c_structs/rpu_data_nlq.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use crate::rpu::{rpu_data_nlq::RpuDataNlq as RuRpuDataNlq, NUM_COMPONENTS};
use std::ffi::CStr;

use crate::rpu::{
rpu_data_nlq::{DoviELType, RpuDataNlq as RuRpuDataNlq},
NUM_COMPONENTS,
};

const FEL_CSTR: &CStr = c"FEL";
const MEL_CSTR: &CStr = c"MEL";

/// C struct for rpu_data_nlq()
#[repr(C)]
Expand All @@ -12,6 +20,15 @@ pub struct RpuDataNlq {
linear_deadzone_threshold: [u64; NUM_COMPONENTS],
}

impl DoviELType {
pub const fn as_cstr(&self) -> &'static CStr {
match self {
DoviELType::MEL => MEL_CSTR,
DoviELType::FEL => FEL_CSTR,
}
}
}

impl From<&RuRpuDataNlq> for RpuDataNlq {
fn from(data: &RuRpuDataNlq) -> Self {
Self {
Expand Down
5 changes: 2 additions & 3 deletions dolby_vision/src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ pub unsafe extern "C" fn dovi_rpu_get_header(ptr: *const RpuOpaque) -> *const Rp
let mut header = RpuDataHeader::from(&rpu.header);

if let Some(el_type) = rpu.el_type.as_ref() {
header.el_type = CString::new(el_type.as_str()).unwrap().into_raw();
header.el_type = el_type.as_cstr().as_ptr();
}

Box::into_raw(Box::new(header))
Expand All @@ -230,8 +230,7 @@ pub unsafe extern "C" fn dovi_rpu_get_header(ptr: *const RpuOpaque) -> *const Rp
#[no_mangle]
pub unsafe extern "C" fn dovi_rpu_free_header(ptr: *const RpuDataHeader) {
if !ptr.is_null() {
let header = Box::from_raw(ptr as *mut RpuDataHeader);
header.free();
drop(Box::from_raw(ptr as *mut RpuDataHeader));
}
}

Expand Down
Loading