Skip to content

Commit c801932

Browse files
authored
const DAV1D_MAX_{THREADS,FRAME_DELAY}: add missing consts that weren't transpiled (#1455)
2 parents 174df76 + 16d897f commit c801932

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ target/
2020

2121
.gdb_history
2222
.gdbinit
23+
24+
.cache/clangd/index

src/include/dav1d/dav1d.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ pub type Dav1dContext = RawArc<Rav1dContext>;
1616

1717
pub type Dav1dRef = ();
1818

19+
pub const RAV1D_MAX_THREADS: usize = 256;
20+
pub const RAV1D_MAX_FRAME_DELAY: usize = 256;
21+
22+
pub const DAV1D_MAX_THREADS: c_int = RAV1D_MAX_THREADS as _;
23+
pub const DAV1D_MAX_FRAME_DELAY: c_int = RAV1D_MAX_FRAME_DELAY as _;
24+
1925
pub type Dav1dInloopFilterType = c_uint;
2026
pub const DAV1D_INLOOPFILTER_ALL: Dav1dInloopFilterType =
2127
Rav1dInloopFilterType::all().bits() as Dav1dInloopFilterType;
@@ -144,8 +150,8 @@ pub struct Dav1dSettings {
144150

145151
#[repr(C)]
146152
pub(crate) struct Rav1dSettings {
147-
pub n_threads: InRange<u16, 0, 256>,
148-
pub max_frame_delay: InRange<u16, 0, 256>,
153+
pub n_threads: InRange<u16, 0, { RAV1D_MAX_THREADS as _ }>,
154+
pub max_frame_delay: InRange<u16, 0, { RAV1D_MAX_FRAME_DELAY as _ }>,
149155
pub apply_grain: bool,
150156
pub operating_point: InRange<u8, 0, 31>,
151157
pub all_layers: bool,
@@ -177,9 +183,12 @@ impl TryFrom<Dav1dSettings> for Rav1dSettings {
177183
decode_frame_type,
178184
reserved: _,
179185
} = value;
180-
validate_input!(((0..=256).contains(&n_threads), Rav1dError::InvalidArgument))?;
181186
validate_input!((
182-
(0..=256).contains(&max_frame_delay),
187+
(0..=DAV1D_MAX_THREADS).contains(&n_threads),
188+
Rav1dError::InvalidArgument
189+
))?;
190+
validate_input!((
191+
(0..=DAV1D_MAX_FRAME_DELAY).contains(&max_frame_delay),
183192
Rav1dError::InvalidArgument
184193
))?;
185194
validate_input!((

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ use crate::include::dav1d::common::{Dav1dDataProps, Rav1dDataProps};
171171
use crate::include::dav1d::data::{Dav1dData, Rav1dData};
172172
use crate::include::dav1d::dav1d::{
173173
Dav1dContext, Dav1dEventFlags, Dav1dSettings, Rav1dDecodeFrameType, Rav1dInloopFilterType,
174-
Rav1dSettings,
174+
Rav1dSettings, RAV1D_MAX_THREADS,
175175
};
176176
use crate::include::dav1d::headers::{Dav1dSequenceHeader, Rav1dFilmGrainData};
177177
use crate::include::dav1d::picture::{Dav1dPicture, Rav1dPicture};
@@ -230,10 +230,10 @@ pub extern "C" fn dav1d_version_api() -> c_uint {
230230
impl Default for Rav1dSettings {
231231
fn default() -> Self {
232232
Self {
233-
n_threads: InRange::<u16, 0, 256>::new(0).unwrap(),
234-
max_frame_delay: InRange::<u16, 0, 256>::new(0).unwrap(),
233+
n_threads: InRange::new(0).unwrap(),
234+
max_frame_delay: InRange::new(0).unwrap(),
235235
apply_grain: true,
236-
operating_point: InRange::<u8, 0, 31>::new(0).unwrap(),
236+
operating_point: InRange::new(0).unwrap(),
237237
all_layers: true,
238238
frame_size_limit: 0,
239239
allocator: Default::default(),
@@ -268,7 +268,9 @@ fn get_num_threads(s: &Rav1dSettings) -> NumThreads {
268268
let n_tc = if s.n_threads.get() != 0 {
269269
s.n_threads.get() as usize // TODO propagate `InRange`
270270
} else {
271-
rav1d_num_logical_processors().get().clamp(1, 256)
271+
rav1d_num_logical_processors()
272+
.get()
273+
.clamp(1, RAV1D_MAX_THREADS)
272274
};
273275
let n_fc = if s.max_frame_delay.get() != 0 {
274276
cmp::min(s.max_frame_delay.get() as usize, n_tc) // TODO propagate `InRange`

0 commit comments

Comments
 (0)