Skip to content

Commit

Permalink
fn {in,out}put_*: Deduplicate declarations into use imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Sep 25, 2023
1 parent aad367a commit d636a7b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 53 deletions.
18 changes: 4 additions & 14 deletions tests/seek_stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ mod dav1d_cli_parse;
use crate::dav1d_cli_parse::parse;
use crate::dav1d_cli_parse::CLISettings;
use crate::dav1d_cli_parse::REALTIME_DISABLE;
use crate::input::input::input_close;
use crate::input::input::input_open;
use crate::input::input::input_read;
use crate::input::input::input_seek;
use crate::input::input::DemuxerContext;
use rav1d::include::dav1d::common::Dav1dDataProps;
use rav1d::include::dav1d::common::Dav1dUserData;
Expand Down Expand Up @@ -67,20 +71,6 @@ use std::ffi::c_uint;
use std::ffi::c_ulonglong;
use std::ffi::c_void;

extern "C" {
fn input_open(
c_out: *mut *mut DemuxerContext,
name: *const c_char,
filename: *const c_char,
fps: *mut c_uint,
num_frames: *mut c_uint,
timebase: *mut c_uint,
) -> c_int;
fn input_read(ctx: *mut DemuxerContext, data: *mut Dav1dData) -> c_int;
fn input_seek(ctx: *mut DemuxerContext, pts: u64) -> c_int;
fn input_close(ctx: *mut DemuxerContext);
}

unsafe extern "C" fn get_seed() -> c_uint {
let mut ts: libc::timespec = libc::timespec {
tv_sec: 0,
Expand Down
30 changes: 7 additions & 23 deletions tools/dav1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ use crate::dav1d_cli_parse::parse;
use crate::dav1d_cli_parse::CLISettings;
use crate::dav1d_cli_parse::REALTIME_CUSTOM;
use crate::dav1d_cli_parse::REALTIME_DISABLE;
use crate::input::input::input_close;
use crate::input::input::input_open;
use crate::input::input::input_read;
use crate::input::input::DemuxerContext;
use crate::output::output::output_close;
use crate::output::output::output_open;
use crate::output::output::output_verify;
use crate::output::output::output_write;
use crate::output::output::MuxerContext;
use libc::fclose;
use libc::fflush;
Expand Down Expand Up @@ -81,29 +88,6 @@ use std::ffi::c_uint;
use std::ffi::c_ulonglong;
use std::ffi::c_void;

extern "C" {
fn input_open(
c_out: *mut *mut DemuxerContext,
name: *const c_char,
filename: *const c_char,
fps: *mut c_uint,
num_frames: *mut c_uint,
timebase: *mut c_uint,
) -> c_int;
fn input_read(ctx: *mut DemuxerContext, data: *mut Dav1dData) -> c_int;
fn input_close(ctx: *mut DemuxerContext);
fn output_open(
c: *mut *mut MuxerContext,
name: *const c_char,
filename: *const c_char,
p: *const Dav1dPictureParameters,
fps: *const c_uint,
) -> c_int;
fn output_write(ctx: *mut MuxerContext, pic: *mut Dav1dPicture) -> c_int;
fn output_close(ctx: *mut MuxerContext);
fn output_verify(ctx: *mut MuxerContext, hash_string: *const c_char) -> c_int;
}

unsafe extern "C" fn get_time_nanos() -> u64 {
let mut ts: libc::timespec = libc::timespec {
tv_sec: 0,
Expand Down
15 changes: 7 additions & 8 deletions tools/input/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ static mut demuxers: [*const Demuxer; 4] = unsafe {
]
};

#[no_mangle]
pub unsafe extern "C" fn input_open(
pub unsafe fn input_open(
c_out: *mut *mut DemuxerContext,
name: *const c_char,
filename: *const c_char,
Expand Down Expand Up @@ -181,22 +180,22 @@ pub unsafe extern "C" fn input_open(
return 0 as c_int;
}

#[no_mangle]
pub unsafe extern "C" fn input_read(ctx: *mut DemuxerContext, data: *mut Dav1dData) -> c_int {
pub unsafe fn input_read(ctx: *mut DemuxerContext, data: *mut Dav1dData) -> c_int {
return ((*(*ctx).impl_0).read).expect("non-null function pointer")((*ctx).data, data);
}

#[no_mangle]
pub unsafe extern "C" fn input_seek(ctx: *mut DemuxerContext, pts: u64) -> c_int {
// TODO(kkysen) These are used in `dav1d.rs` and `seek_stress.rs`
// but are still marked as unused since `[[bin]]` are only supposed to be one file in `cargo`.
#[allow(dead_code)]
pub unsafe fn input_seek(ctx: *mut DemuxerContext, pts: u64) -> c_int {
return if ((*(*ctx).impl_0).seek).is_some() {
((*(*ctx).impl_0).seek).expect("non-null function pointer")((*ctx).data, pts)
} else {
-(1 as c_int)
};
}

#[no_mangle]
pub unsafe extern "C" fn input_close(ctx: *mut DemuxerContext) {
pub unsafe fn input_close(ctx: *mut DemuxerContext) {
((*(*ctx).impl_0).close).expect("non-null function pointer")((*ctx).data);
free(ctx as *mut c_void);
}
24 changes: 16 additions & 8 deletions tools/output/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ unsafe extern "C" fn find_extension(f: *const c_char) -> *const c_char {
};
}

#[no_mangle]
pub unsafe extern "C" fn output_open(
// TODO(kkysen) These are used in `dav1d.rs` and `seek_stress.rs`
// but are still marked as unused since `[[bin]]` are only supposed to be one file in `cargo`.
#[allow(dead_code)]
pub unsafe fn output_open(
c_out: *mut *mut MuxerContext,
name: *const c_char,
filename: *const c_char,
Expand Down Expand Up @@ -348,8 +350,10 @@ unsafe extern "C" fn assemble_filename(
safe_strncat(filename, filename_size, ptr, strlen(ptr) as c_int);
}

#[no_mangle]
pub unsafe extern "C" fn output_write(ctx: *mut MuxerContext, p: *mut Dav1dPicture) -> c_int {
// TODO(kkysen) These are used in `dav1d.rs` and `seek_stress.rs`
// but are still marked as unused since `[[bin]]` are only supposed to be one file in `cargo`.
#[allow(dead_code)]
pub unsafe fn output_write(ctx: *mut MuxerContext, p: *mut Dav1dPicture) -> c_int {
let mut res;
if (*ctx).one_file_per_frame != 0 && ((*(*ctx).impl_0).write_header).is_some() {
let mut filename: [c_char; 1024] = [0; 1024];
Expand Down Expand Up @@ -379,16 +383,20 @@ pub unsafe extern "C" fn output_write(ctx: *mut MuxerContext, p: *mut Dav1dPictu
return 0 as c_int;
}

#[no_mangle]
pub unsafe extern "C" fn output_close(ctx: *mut MuxerContext) {
// TODO(kkysen) These are used in `dav1d.rs` and `seek_stress.rs`
// but are still marked as unused since `[[bin]]` are only supposed to be one file in `cargo`.
#[allow(dead_code)]
pub unsafe fn output_close(ctx: *mut MuxerContext) {
if (*ctx).one_file_per_frame == 0 && ((*(*ctx).impl_0).write_trailer).is_some() {
((*(*ctx).impl_0).write_trailer).expect("non-null function pointer")((*ctx).data);
}
free(ctx as *mut c_void);
}

#[no_mangle]
pub unsafe extern "C" fn output_verify(ctx: *mut MuxerContext, md5_str: *const c_char) -> c_int {
// TODO(kkysen) These are used in `dav1d.rs` and `seek_stress.rs`
// but are still marked as unused since `[[bin]]` are only supposed to be one file in `cargo`.
#[allow(dead_code)]
pub unsafe fn output_verify(ctx: *mut MuxerContext, md5_str: *const c_char) -> c_int {
let res = if ((*(*ctx).impl_0).verify).is_some() {
((*(*ctx).impl_0).verify).expect("non-null function pointer")((*ctx).data, md5_str)
} else {
Expand Down

0 comments on commit d636a7b

Please sign in to comment.