Skip to content

Commit

Permalink
fn llround: Replace with .round().
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Sep 25, 2023
1 parent fe6b706 commit 91d7cb3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
47 changes: 20 additions & 27 deletions tests/seek_stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ use std::ffi::c_char;
use std::ffi::c_double;
use std::ffi::c_float;
use std::ffi::c_int;
use std::ffi::c_longlong;
use std::ffi::c_uint;
use std::ffi::c_ulonglong;
use std::ffi::c_void;

extern "C" {
pub type DemuxerContext;
fn llround(_: c_double) -> c_longlong;
fn input_open(
c_out: *mut *mut DemuxerContext,
name: *const c_char,
Expand Down Expand Up @@ -478,9 +476,9 @@ unsafe fn main_0(argc: c_int, argv: *const *mut c_char) -> c_int {
current_block = 5948590327928692120;
break;
}
pts = llround(
(xor128_rand() as c_uint).wrapping_rem(total) as c_double * spf * 1000000000.0f64,
) as u64;
pts =
((xor128_rand() as c_uint).wrapping_rem(total) as c_double * spf * 1000000000.0f64)
.round() as u64;
if !(seek(in_0, c, pts, &mut data) != 0) {
if decode_rand(in_0, c, &mut data, fps) != 0 {
current_block = 1928200949476507836;
Expand All @@ -492,7 +490,7 @@ unsafe fn main_0(argc: c_int, argv: *const *mut c_char) -> c_int {
match current_block {
1928200949476507836 => {}
_ => {
pts = llround(data.m.timestamp as c_double * timebase * 1000000000.0f64) as u64;
pts = (data.m.timestamp as c_double * timebase * 1000000000.0f64).round() as u64;
let mut i_0 = 0;
let mut tries = 0;
loop {
Expand All @@ -506,34 +504,31 @@ unsafe fn main_0(argc: c_int, argv: *const *mut c_char) -> c_int {
1 as c_int
};
let diff: c_float = (xor128_rand() % 100 as c_int) as c_float / 100.0f32;
let mut new_pts: i64 = pts.wrapping_add(
(sign as u64).wrapping_mul(llround(
diff as c_double * fps * spf * 1000000000.0f64,
) as u64),
) as i64;
let mut new_pts: i64 = pts.wrapping_add((sign as u64).wrapping_mul(
(diff as c_double * fps * spf * 1000000000.0f64).round() as u64,
)) as i64;
let new_ts: i64 =
llround(new_pts as c_double / (timebase * 1000000000.0f64)) as i64;
(new_pts as c_double / (timebase * 1000000000.0f64)).round() as i64;
new_pts =
llround(new_ts as c_double * timebase * 1000000000.0f64) as u64 as i64;
(new_ts as c_double * timebase * 1000000000.0f64).round() as u64 as i64;
if new_pts < 0
|| new_pts as u64
>= llround(total as c_double * spf * 1000000000.0f64) as u64
>= (total as c_double * spf * 1000000000.0f64).round() as u64
{
if seek(
in_0,
c,
llround(
total.wrapping_div(2 as c_int as c_uint) as c_double
* spf
* 1000000000.0f64,
) as u64,
(total.wrapping_div(2 as c_int as c_uint) as c_double
* spf
* 1000000000.0f64)
.round() as u64,
&mut data,
) != 0
{
current_block = 8693738493027456495;
break;
}
pts = llround(data.m.timestamp as c_double * timebase * 1000000000.0f64)
pts = (data.m.timestamp as c_double * timebase * 1000000000.0f64).round()
as u64;
tries += 1;
} else {
Expand All @@ -547,7 +542,7 @@ unsafe fn main_0(argc: c_int, argv: *const *mut c_char) -> c_int {
current_block = 1928200949476507836;
break;
}
pts = llround(data.m.timestamp as c_double * timebase * 1000000000.0f64)
pts = (data.m.timestamp as c_double * timebase * 1000000000.0f64).round()
as u64;
}
i_0 += 1;
Expand All @@ -564,9 +559,8 @@ unsafe fn main_0(argc: c_int, argv: *const *mut c_char) -> c_int {
if !(seek(
in_0,
c,
llround(
total.wrapping_sub(shift) as c_double * spf * 1000000000.0f64,
) as u64,
(total.wrapping_sub(shift) as c_double * spf * 1000000000.0f64)
.round() as u64,
&mut data,
) != 0)
{
Expand All @@ -579,9 +573,8 @@ unsafe fn main_0(argc: c_int, argv: *const *mut c_char) -> c_int {
if seek(
in_0,
c,
llround(
total.wrapping_sub(shift) as c_double * spf * 1000000000.0f64,
) as u64,
(total.wrapping_sub(shift) as c_double * spf * 1000000000.0f64)
.round() as u64,
&mut data,
) != 0
{
Expand Down
7 changes: 1 addition & 6 deletions tools/input/ivf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@ use rav1d::stderr;
use std::ffi::c_char;
use std::ffi::c_double;
use std::ffi::c_int;
use std::ffi::c_longlong;
use std::ffi::c_uint;
use std::ffi::c_ulong;
use std::ffi::c_void;

extern "C" {
fn llround(_: c_double) -> c_longlong;
}

#[repr(C)]
pub struct DemuxerPriv {
pub f: *mut libc::FILE,
Expand Down Expand Up @@ -279,7 +274,7 @@ unsafe extern "C" fn ivf_read(c: *mut IvfInputContext, buf: *mut Dav1dData) -> c
unsafe extern "C" fn ivf_seek(c: *mut IvfInputContext, pts: u64) -> c_int {
let mut current_block: u64;
let mut cur: u64 = 0;
let ts: u64 = llround(pts as c_double * (*c).timebase / 1000000000.0f64) as u64;
let ts: u64 = (pts as c_double * (*c).timebase / 1000000000.0f64).round() as u64;
if ts <= (*c).last_ts {
if fseeko((*c).f, 32, 0) != 0 {
current_block = 679495355492430298;
Expand Down

0 comments on commit 91d7cb3

Please sign in to comment.