@@ -11,54 +11,71 @@ extern "C" fn buf_read(buf: *mut u8, size: usize, userdata: *mut std::os::raw::c
11
11
}
12
12
}
13
13
14
- fn check_loop_count ( path : & str , expected_loop_count : i64 ) {
14
+ unsafe fn parse_file_and_get_info ( path : & str ) -> ( * mut Mp4parseAvifParser , Mp4parseAvifInfo ) {
15
15
let mut file = std:: fs:: File :: open ( path) . expect ( "Unknown file" ) ;
16
16
let io = Mp4parseIo {
17
17
read : Some ( buf_read) ,
18
18
userdata : & mut file as * mut _ as * mut std:: os:: raw:: c_void ,
19
19
} ;
20
20
21
- unsafe {
22
- let mut parser = std:: ptr:: null_mut ( ) ;
23
- let mut rv = mp4parse_avif_new ( & io, ParseStrictness :: Normal , & mut parser) ;
24
- assert_eq ! ( rv, Mp4parseStatus :: Ok ) ;
25
- assert ! ( !parser. is_null( ) ) ;
26
-
27
- let mut info = Mp4parseAvifInfo {
28
- premultiplied_alpha : Default :: default ( ) ,
29
- major_brand : Default :: default ( ) ,
30
- unsupported_features_bitfield : Default :: default ( ) ,
31
- spatial_extents : std:: ptr:: null ( ) ,
32
- nclx_colour_information : std:: ptr:: null ( ) ,
33
- icc_colour_information : Default :: default ( ) ,
34
- image_rotation : mp4parse:: ImageRotation :: D0 ,
35
- image_mirror : std:: ptr:: null ( ) ,
36
- pixel_aspect_ratio : std:: ptr:: null ( ) ,
37
- has_primary_item : Default :: default ( ) ,
38
- primary_item_bit_depth : Default :: default ( ) ,
39
- has_alpha_item : Default :: default ( ) ,
40
- alpha_item_bit_depth : Default :: default ( ) ,
41
- has_sequence : Default :: default ( ) ,
42
- loop_mode : Default :: default ( ) ,
43
- loop_count : Default :: default ( ) ,
44
- color_track_id : Default :: default ( ) ,
45
- color_track_bit_depth : Default :: default ( ) ,
46
- alpha_track_id : Default :: default ( ) ,
47
- alpha_track_bit_depth : Default :: default ( ) ,
48
- } ;
49
- rv = mp4parse_avif_get_info ( parser, & mut info) ;
50
- assert_eq ! ( rv, Mp4parseStatus :: Ok ) ;
51
-
52
- match info. loop_mode {
53
- Mp4parseAvifLoopMode :: NoEdits => assert_eq ! ( expected_loop_count, -1 ) ,
54
- Mp4parseAvifLoopMode :: LoopByCount => {
55
- assert_eq ! ( info. loop_count. to_i64( ) , Some ( expected_loop_count) )
56
- }
57
- Mp4parseAvifLoopMode :: LoopInfinitely => assert_eq ! ( expected_loop_count, std:: i64 :: MIN ) ,
58
- }
21
+ let mut parser = std:: ptr:: null_mut ( ) ;
22
+ let mut rv = mp4parse_avif_new ( & io, ParseStrictness :: Normal , & mut parser) ;
23
+ assert_eq ! ( rv, Mp4parseStatus :: Ok ) ;
24
+ assert ! ( !parser. is_null( ) ) ;
25
+
26
+ let mut info = Mp4parseAvifInfo {
27
+ premultiplied_alpha : Default :: default ( ) ,
28
+ major_brand : Default :: default ( ) ,
29
+ unsupported_features_bitfield : Default :: default ( ) ,
30
+ spatial_extents : std:: ptr:: null ( ) ,
31
+ nclx_colour_information : std:: ptr:: null ( ) ,
32
+ icc_colour_information : Default :: default ( ) ,
33
+ image_rotation : mp4parse:: ImageRotation :: D0 ,
34
+ image_mirror : std:: ptr:: null ( ) ,
35
+ pixel_aspect_ratio : std:: ptr:: null ( ) ,
36
+ has_primary_item : Default :: default ( ) ,
37
+ primary_item_bit_depth : Default :: default ( ) ,
38
+ has_alpha_item : Default :: default ( ) ,
39
+ alpha_item_bit_depth : Default :: default ( ) ,
40
+ has_sequence : Default :: default ( ) ,
41
+ loop_mode : Default :: default ( ) ,
42
+ loop_count : Default :: default ( ) ,
43
+ color_track_id : Default :: default ( ) ,
44
+ color_track_bit_depth : Default :: default ( ) ,
45
+ alpha_track_id : Default :: default ( ) ,
46
+ alpha_track_bit_depth : Default :: default ( ) ,
47
+ } ;
48
+ rv = mp4parse_avif_get_info ( parser, & mut info) ;
49
+ assert_eq ! ( rv, Mp4parseStatus :: Ok ) ;
50
+ ( parser, info)
51
+ }
59
52
60
- mp4parse_avif_free ( parser) ;
53
+ fn check_loop_count ( path : & str , expected_loop_count : i64 ) {
54
+ let ( parser, info) = unsafe { parse_file_and_get_info ( path) } ;
55
+ match info. loop_mode {
56
+ Mp4parseAvifLoopMode :: NoEdits => assert_eq ! ( expected_loop_count, -1 ) ,
57
+ Mp4parseAvifLoopMode :: LoopByCount => {
58
+ assert_eq ! ( info. loop_count. to_i64( ) , Some ( expected_loop_count) )
59
+ }
60
+ Mp4parseAvifLoopMode :: LoopInfinitely => assert_eq ! ( expected_loop_count, std:: i64 :: MIN ) ,
61
61
}
62
+
63
+ unsafe { mp4parse_avif_free ( parser) } ;
64
+ }
65
+
66
+ fn check_timescale ( path : & str , expected_timescale : u64 ) {
67
+ let ( parser, info) = unsafe { parse_file_and_get_info ( path) } ;
68
+
69
+ let mut indices: Mp4parseByteData = Mp4parseByteData :: default ( ) ;
70
+ let mut timescale: u64 = 0 ;
71
+ let rv = unsafe {
72
+ mp4parse_avif_get_indice_table ( parser, info. color_track_id , & mut indices, & mut timescale)
73
+ } ;
74
+
75
+ assert_eq ! ( rv, Mp4parseStatus :: Ok ) ;
76
+ assert_eq ! ( timescale, expected_timescale) ;
77
+
78
+ unsafe { mp4parse_avif_free ( parser) } ;
62
79
}
63
80
64
81
#[ test]
@@ -85,3 +102,12 @@ fn loop_forever() {
85
102
fn no_edts ( ) {
86
103
check_loop_count ( "tests/no_edts.avif" , -1 ) ;
87
104
}
105
+
106
+ #[ test]
107
+ fn check_timescales ( ) {
108
+ check_timescale ( "tests/loop_1.avif" , 2 ) ;
109
+ check_timescale ( "tests/loop_2.avif" , 2 ) ;
110
+ check_timescale ( "tests/loop_ceiled_4.avif" , 2 ) ;
111
+ check_timescale ( "tests/loop_forever.avif" , 2 ) ;
112
+ check_timescale ( "tests/no_edts.avif" , 16384 ) ;
113
+ }
0 commit comments