Skip to content

Commit

Permalink
const {FRAME,TILE}_ERROR: Deduplicate (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen authored Sep 8, 2023
2 parents c32c860 + 90cb4bf commit 8e7a04b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
10 changes: 4 additions & 6 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::src::cdf::CdfMvComponent;
use crate::src::cdf::CdfMvContext;
use crate::src::ctx::CaseSet;
use crate::src::looprestoration::dav1d_loop_restoration_dsp_init;
use crate::src::thread_task::FRAME_ERROR;
use crate::src::thread_task::TILE_ERROR;

use libc;

Expand Down Expand Up @@ -5827,11 +5829,7 @@ pub unsafe extern "C" fn dav1d_decode_frame_exit(f: *mut Dav1dFrameContext, retv
if !f.out_cdf.progress.is_null() {
::core::intrinsics::atomic_store_seqcst(
f.out_cdf.progress,
if retval == 0 {
1
} else {
i32::MAX as libc::c_uint - 1
},
if retval == 0 { 1 } else { TILE_ERROR as u32 },
);
}
dav1d_cdf_thread_unref(&mut f.out_cdf);
Expand Down Expand Up @@ -5943,7 +5941,7 @@ pub unsafe extern "C" fn dav1d_submit_frame(c: *mut Dav1dContext) -> libc::c_int
&mut *(out_delayed.progress).offset(1) as *mut atomic_uint,
);
if (out_delayed.visible != 0 || c.output_invisible_frames != 0)
&& progress != u32::MAX - 1
&& progress != FRAME_ERROR
{
dav1d_thread_picture_ref(&mut c.out, out_delayed);
c.event_flags |= dav1d_picture_get_event_flags(out_delayed);
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ use crate::src::log::dav1d_log_default_callback;
use crate::src::r#ref::dav1d_ref_dec;
use crate::src::r#ref::Dav1dRef;
use crate::src::thread_task::dav1d_worker_task;
use crate::src::thread_task::FRAME_ERROR;

use crate::include::dav1d::headers::Dav1dWarpedMotionParams;

Expand Down Expand Up @@ -653,6 +654,7 @@ use crate::src::mem::dav1d_freep_aligned;
use crate::src::mem::dav1d_mem_pool_end;
use crate::src::mem::dav1d_mem_pool_init;
use crate::src::mem::freep;

#[cold]
unsafe extern "C" fn init_internal() {
dav1d_init_cpu();
Expand Down Expand Up @@ -1522,7 +1524,7 @@ unsafe extern "C" fn drain_picture(c: *mut Dav1dContext, out: *mut Dav1dPicture)
&mut *((*out_delayed).progress).offset(1) as *mut atomic_uint,
);
if ((*out_delayed).visible != 0 || (*c).output_invisible_frames != 0)
&& progress != u32::MAX - 1
&& progress != FRAME_ERROR
{
dav1d_thread_picture_ref(&mut (*c).out, out_delayed);
(*c).event_flags = ::core::mem::transmute::<libc::c_uint, Dav1dEventFlags>(
Expand Down
7 changes: 4 additions & 3 deletions src/obu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ use crate::include::common::intops::iclip_u8;
use crate::include::common::intops::imax;
use crate::include::common::intops::imin;
use crate::include::common::intops::ulog2;
use crate::src::env::get_poc_diff;
use crate::src::getbits::dav1d_bytealign_get_bits;
use crate::src::getbits::dav1d_get_bit;
use crate::src::getbits::dav1d_get_bits;
Expand All @@ -623,9 +624,9 @@ use crate::src::getbits::dav1d_get_uniform;
use crate::src::getbits::dav1d_get_vlc;
use crate::src::getbits::dav1d_init_get_bits;
use crate::src::getbits::GetBits;

use crate::src::env::get_poc_diff;
use crate::src::r#ref::dav1d_ref_inc;
use crate::src::thread_task::FRAME_ERROR;

#[inline]
unsafe extern "C" fn dav1d_get_bits_pos(c: *const GetBits) -> libc::c_uint {
return (((*c).ptr).offset_from((*c).ptr_start) as libc::c_long as libc::c_uint)
Expand Down Expand Up @@ -2766,7 +2767,7 @@ pub unsafe extern "C" fn dav1d_parse_obus(
&mut *((*out_delayed).progress).offset(1) as *mut atomic_uint,
);
if ((*out_delayed).visible != 0 || (*c).output_invisible_frames != 0)
&& progress != u32::MAX - 1
&& progress != FRAME_ERROR
{
dav1d_thread_picture_ref(&mut (*c).out, out_delayed);
(*c).event_flags = ::core::mem::transmute::<libc::c_uint, Dav1dEventFlags>(
Expand Down
43 changes: 23 additions & 20 deletions src/thread_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ pub type recon_b_intra_fn = Option<
>;
use crate::include::common::attributes::ctz;
use crate::src::internal::ScalableMotionParams;

pub const FRAME_ERROR: u32 = u32::MAX - 1;
pub const TILE_ERROR: i32 = i32::MAX - 1;

#[inline]
unsafe extern "C" fn dav1d_set_thread_name(name: *const libc::c_char) {
cfg_if::cfg_if! {
Expand Down Expand Up @@ -1128,7 +1132,7 @@ unsafe extern "C" fn check_tile(
if p1 < (*t).sby {
return 1 as libc::c_int;
}
let mut error = (p1 == i32::MAX - 1) as libc::c_int;
let mut error = (p1 == TILE_ERROR) as libc::c_int;
error |= ::core::intrinsics::atomic_or_seqcst(&mut (*f).task_thread.error, error);
if error == 0 && frame_mt != 0 && tp == 0 {
let p2 = ::core::intrinsics::atomic_load_seqcst(
Expand All @@ -1137,7 +1141,7 @@ unsafe extern "C" fn check_tile(
if p2 <= (*t).sby {
return 1 as libc::c_int;
}
error = (p2 == i32::MAX - 1) as libc::c_int;
error = (p2 == TILE_ERROR) as libc::c_int;
error |= ::core::intrinsics::atomic_or_seqcst(&mut (*f).task_thread.error, error);
}
if error == 0
Expand Down Expand Up @@ -1192,7 +1196,7 @@ unsafe extern "C" fn check_tile(
}
::core::intrinsics::atomic_or_seqcst(
&mut (*f).task_thread.error,
(p3 == u32::MAX - 1) as libc::c_int,
(p3 == FRAME_ERROR) as libc::c_int,
);
}
_ => {}
Expand All @@ -1215,7 +1219,7 @@ unsafe extern "C" fn get_frame_progress(
} else {
0 as libc::c_int as libc::c_uint
};
if frame_prog >= u32::MAX - 1 {
if frame_prog >= FRAME_ERROR {
return (*f).sbh - 1;
}
let mut idx = (frame_prog >> (*f).sb_shift + 7) as libc::c_int;
Expand Down Expand Up @@ -1261,11 +1265,11 @@ unsafe extern "C" fn abort_frame(f: *mut Dav1dFrameContext, error: libc::c_int)
);
::core::intrinsics::atomic_store_seqcst(
&mut *((*f).sr_cur.progress).offset(0) as *mut atomic_uint,
u32::MAX - 1,
FRAME_ERROR,
);
::core::intrinsics::atomic_store_seqcst(
&mut *((*f).sr_cur.progress).offset(1) as *mut atomic_uint,
u32::MAX - 1,
FRAME_ERROR,
);
dav1d_decode_frame_exit(f, error);
(*f).n_tile_data = 0 as libc::c_int;
Expand Down Expand Up @@ -1506,7 +1510,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
if p1 != 0 {
::core::intrinsics::atomic_or_seqcst(
&mut (*f).task_thread.error,
(p1 == i32::MAX - 1) as libc::c_int,
(p1 == TILE_ERROR) as libc::c_int,
);
current_block = 7012560550443761033;
break;
Expand Down Expand Up @@ -1587,7 +1591,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
} else {
::core::intrinsics::atomic_or_seqcst(
&mut (*f).task_thread.error,
(p1_0 == i32::MAX - 1) as libc::c_int,
(p1_0 == TILE_ERROR) as libc::c_int,
);
current_block = 14832935472441733737;
}
Expand Down Expand Up @@ -1620,7 +1624,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
}
::core::intrinsics::atomic_or_seqcst(
&mut (*f).task_thread.error,
(p2 == i32::MAX - 1) as libc::c_int,
(p2 == TILE_ERROR) as libc::c_int,
);
tc_0 += 1;
}
Expand Down Expand Up @@ -1688,7 +1692,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
if p1_2 >= (*t).deblock_progress {
::core::intrinsics::atomic_or_seqcst(
&mut (*f).task_thread.error,
(p1_2 == i32::MAX - 1) as libc::c_int,
(p1_2 == TILE_ERROR) as libc::c_int,
);
current_block = 7012560550443761033;
continue 's_107;
Expand Down Expand Up @@ -1763,7 +1767,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
1 as libc::c_int as libc::c_uint
})
as libc::c_int;
if res != 0 || p1_3 == i32::MAX - 1 {
if res != 0 || p1_3 == TILE_ERROR {
pthread_mutex_lock(&mut (*ttd).lock);
abort_frame(
f,
Expand Down Expand Up @@ -1798,7 +1802,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
::core::intrinsics::atomic_store_seqcst(
(*f).out_cdf.progress,
(if res_0 < 0 {
i32::MAX - 1
TILE_ERROR
} else {
1 as libc::c_int
})
Expand Down Expand Up @@ -1839,7 +1843,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
&mut *((*f).sr_cur.progress)
.offset((p_0 - 1) as isize)
as *mut atomic_uint,
u32::MAX - 1,
FRAME_ERROR,
);
if p_0 == 2
&& ::core::intrinsics::atomic_load_seqcst(
Expand Down Expand Up @@ -1908,8 +1912,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
if error_0 == 0 {
error_0 = dav1d_decode_tile_sbrow(tc);
}
let progress =
if error_0 != 0 { i32::MAX - 1 } else { 1 + sby };
let progress = if error_0 != 0 { TILE_ERROR } else { 1 + sby };
::core::intrinsics::atomic_or_seqcst(
&mut (*f).task_thread.error,
error_0,
Expand Down Expand Up @@ -1977,7 +1980,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
::core::intrinsics::atomic_store_seqcst(
(*f).out_cdf.progress,
(if error_0 != 0 {
i32::MAX - 1
TILE_ERROR
} else {
1 as libc::c_int
})
Expand Down Expand Up @@ -2104,7 +2107,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
);
::core::intrinsics::atomic_store_seqcst(
&mut (*f).frame_thread.deblock_progress,
if error_0 != 0 { i32::MAX - 1 } else { sby + 1 },
if error_0 != 0 { TILE_ERROR } else { sby + 1 },
);
reset_task_cur_async(ttd, (*t).frame_idx, (*c).n_fc);
if ::core::intrinsics::atomic_or_seqcst(
Expand Down Expand Up @@ -2226,12 +2229,12 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
if !((*f).sr_cur.p.data[0]).is_null() {
::core::intrinsics::atomic_store_seqcst(
&mut *((*f).sr_cur.progress).offset(0) as *mut atomic_uint,
if error_0 != 0 { u32::MAX - 1 } else { y },
if error_0 != 0 { FRAME_ERROR } else { y },
);
}
::core::intrinsics::atomic_store_seqcst(
&mut (*f).frame_thread.entropy_progress,
if error_0 != 0 { i32::MAX - 1 } else { sby + 1 },
if error_0 != 0 { TILE_ERROR } else { sby + 1 },
);
if sby + 1 == sbh {
::core::intrinsics::atomic_store_seqcst(
Expand Down Expand Up @@ -2293,7 +2296,7 @@ pub unsafe extern "C" fn dav1d_worker_task(data: *mut libc::c_void) -> *mut libc
if (*c).n_fc > 1 as libc::c_uint && !((*f).sr_cur.p.data[0]).is_null() {
::core::intrinsics::atomic_store_seqcst(
&mut *((*f).sr_cur.progress).offset(1) as *mut atomic_uint,
if error_0 != 0 { u32::MAX - 1 } else { y_0 },
if error_0 != 0 { FRAME_ERROR } else { y_0 },
);
}
pthread_mutex_unlock(&mut (*f).task_thread.lock);
Expand Down

0 comments on commit 8e7a04b

Please sign in to comment.