@@ -161,6 +161,7 @@ use crate::decode::rav1d_decode_frame_exit;
161
161
pub use crate :: error:: Dav1dResult ;
162
162
use crate :: error:: { Rav1dError , Rav1dResult } ;
163
163
use crate :: extensions:: OptionError as _;
164
+ use crate :: in_range:: InRange ;
164
165
#[ cfg( feature = "bitdepth_16" ) ]
165
166
use crate :: include:: common:: bitdepth:: BitDepth16 ;
166
167
#[ cfg( feature = "bitdepth_8" ) ]
@@ -229,10 +230,10 @@ pub extern "C" fn dav1d_version_api() -> c_uint {
229
230
impl Default for Rav1dSettings {
230
231
fn default ( ) -> Self {
231
232
Self {
232
- n_threads : 0 ,
233
- max_frame_delay : 0 ,
233
+ n_threads : InRange :: < u16 , 0 , 256 > :: new ( 0 ) . unwrap ( ) ,
234
+ max_frame_delay : InRange :: < u16 , 0 , 256 > :: new ( 0 ) . unwrap ( ) ,
234
235
apply_grain : true ,
235
- operating_point : 0 ,
236
+ operating_point : InRange :: < u8 , 0 , 31 > :: new ( 0 ) . unwrap ( ) ,
236
237
all_layers : true ,
237
238
frame_size_limit : 0 ,
238
239
allocator : Default :: default ( ) ,
@@ -264,13 +265,13 @@ struct NumThreads {
264
265
265
266
#[ cold]
266
267
fn get_num_threads ( s : & Rav1dSettings ) -> NumThreads {
267
- let n_tc = if s. n_threads != 0 {
268
- s. n_threads as usize
268
+ let n_tc = if s. n_threads . get ( ) != 0 {
269
+ s. n_threads . get ( ) as usize // TODO propagate `InRange`
269
270
} else {
270
271
rav1d_num_logical_processors ( ) . get ( ) . clamp ( 1 , 256 )
271
272
} ;
272
- let n_fc = if s. max_frame_delay != 0 {
273
- cmp:: min ( s. max_frame_delay as usize , n_tc)
273
+ let n_fc = if s. max_frame_delay . get ( ) != 0 {
274
+ cmp:: min ( s. max_frame_delay . get ( ) as usize , n_tc) // TODO propagate `InRange`
274
275
} else {
275
276
cmp:: min ( ( n_tc as f64 ) . sqrt ( ) . ceil ( ) as usize , 8 )
276
277
} ;
@@ -279,14 +280,6 @@ fn get_num_threads(s: &Rav1dSettings) -> NumThreads {
279
280
280
281
#[ cold]
281
282
pub ( crate ) fn rav1d_get_frame_delay ( s : & Rav1dSettings ) -> Rav1dResult < usize > {
282
- validate_input ! ( (
283
- s. n_threads >= 0 && s. n_threads <= 256 ,
284
- Rav1dError :: InvalidArgument
285
- ) ) ?;
286
- validate_input ! ( (
287
- s. max_frame_delay >= 0 && s. max_frame_delay <= 256 ,
288
- Rav1dError :: InvalidArgument
289
- ) ) ?;
290
283
let NumThreads { n_tc : _, n_fc } = get_num_threads ( s) ;
291
284
Ok ( n_fc)
292
285
}
@@ -312,15 +305,6 @@ pub(crate) fn rav1d_open(s: &Rav1dSettings) -> Rav1dResult<Arc<Rav1dContext>> {
312
305
static INITTED : Once = Once :: new ( ) ;
313
306
INITTED . call_once ( || init_internal ( ) ) ;
314
307
315
- validate_input ! ( (
316
- s. n_threads >= 0 && s. n_threads <= 256 ,
317
- Rav1dError :: InvalidArgument
318
- ) ) ?;
319
- validate_input ! ( (
320
- s. max_frame_delay >= 0 && s. max_frame_delay <= 256 ,
321
- Rav1dError :: InvalidArgument
322
- ) ) ?;
323
- validate_input ! ( ( s. operating_point <= 31 , Rav1dError :: InvalidArgument ) ) ?;
324
308
validate_input ! ( (
325
309
!s. allocator. is_default( ) || s. allocator. cookie. is_none( ) ,
326
310
Rav1dError :: InvalidArgument
@@ -405,7 +389,7 @@ pub(crate) fn rav1d_open(s: &Rav1dSettings) -> Rav1dResult<Arc<Rav1dContext>> {
405
389
allocator : s. allocator . clone ( ) ,
406
390
logger : s. logger . clone ( ) ,
407
391
apply_grain : s. apply_grain ,
408
- operating_point : s. operating_point ,
392
+ operating_point : s. operating_point . get ( ) , // TODO propagate `InRange`
409
393
all_layers : s. all_layers ,
410
394
frame_size_limit,
411
395
strict_std_compliance : s. strict_std_compliance ,
0 commit comments