1
-
2
- use :: CumulativeDistributionFrequency ;
1
+ use CumulativeDistributionFrequency ;
3
2
4
3
use opus:: imported_decode;
5
4
6
5
use std;
7
6
8
- pub struct Reader < R > where R : std:: io:: Read {
7
+ pub struct Reader < R >
8
+ where
9
+ R : std:: io:: Read ,
10
+ {
9
11
state : imported_decode:: ec_dec < R > ,
10
12
}
11
13
12
- impl < R > Reader < R > where R : std:: io:: Read {
13
- /*
14
- pub fn from_boxed_slice(mut source: Box<[u8]>) -> Self {
15
- let state = unsafe {
16
- let mut state : imported_decode::ec_dec = std::mem::uninitialized();
17
- imported_decode::ec_dec_init(&mut state, source.as_mut_ptr(), source.len() as u32);
18
- state
19
- };
20
- Reader {
21
- source,
22
- state
14
+ impl < R > Reader < R >
15
+ where
16
+ R : std:: io:: Read ,
17
+ {
18
+ /*
19
+ pub fn from_boxed_slice(mut source: Box<[u8]>) -> Self {
20
+ let state = unsafe {
21
+ let mut state : imported_decode::ec_dec = std::mem::uninitialized();
22
+ imported_decode::ec_dec_init(&mut state, source.as_mut_ptr(), source.len() as u32);
23
+ state
24
+ };
25
+ Reader {
26
+ source,
27
+ state
28
+ }
23
29
}
24
- }
25
- */
30
+ */
26
31
pub fn new ( input : R ) -> Result < Self , std:: io:: Error > {
27
32
let mut state = imported_decode:: ec_dec {
28
33
inp : input,
@@ -35,39 +40,48 @@ impl<R> Reader<R> where R: std::io::Read {
35
40
val : 0 ,
36
41
ext : 0 ,
37
42
} ;
38
- unsafe { imported_decode :: ec_dec_init ( & mut state ) ? ; }
39
- Ok ( Reader {
40
- state
41
- } )
43
+ unsafe {
44
+ imported_decode :: ec_dec_init ( & mut state ) ? ;
45
+ }
46
+ Ok ( Reader { state } )
42
47
}
43
48
44
49
/// Decode the next symbol in line.
45
- pub fn symbol ( & mut self , icdf : & CumulativeDistributionFrequency ) -> Result < u32 , std:: io:: Error > {
50
+ pub fn symbol (
51
+ & mut self ,
52
+ icdf : & CumulativeDistributionFrequency ,
53
+ ) -> Result < u32 , std:: io:: Error > {
46
54
let index = unsafe {
47
55
let frequency = imported_decode:: ec_decode ( & mut self . state , icdf. width ( ) ) ;
48
- let indexed= icdf. find ( frequency)
49
- . ok_or_else ( || std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidInput , "Invalid probability" ) ) ?;
50
- imported_decode:: ec_dec_update ( & mut self . state , indexed. segment . low , indexed. segment . next , icdf. width ( ) ) ?;
56
+ let indexed = icdf. find ( frequency) . ok_or_else ( || {
57
+ std:: io:: Error :: new ( std:: io:: ErrorKind :: InvalidInput , "Invalid probability" )
58
+ } ) ?;
59
+ imported_decode:: ec_dec_update (
60
+ & mut self . state ,
61
+ indexed. segment . low ,
62
+ indexed. segment . next ,
63
+ icdf. width ( ) ,
64
+ ) ?;
51
65
indexed. index
52
66
} ;
53
67
Ok ( index as u32 )
54
68
}
55
69
56
- /*
57
- // FIXME: I actually don't understand `bits()` well enough
58
- // to publish it. /// Encode a sequence of raw bits, without any frequency information.
59
- pub fn bits(&mut self, size: usize) -> Result<u16, std::io::Error> {
60
- let result = unsafe {
61
- let result = imported_decode::ec_dec_bits(&mut self.state,
62
- size as u32);
63
- self.check_status()?;
64
- result as u16
65
- };
66
- Ok(result)
67
- }
68
- */
70
+ /*
71
+ // FIXME: I actually don't understand `bits()` well enough
72
+ // to publish it. /// Encode a sequence of raw bits, without any frequency information.
73
+ pub fn bits(&mut self, size: usize) -> Result<u16, std::io::Error> {
74
+ let result = unsafe {
75
+ let result = imported_decode::ec_dec_bits(&mut self.state,
76
+ size as u32);
77
+ self.check_status()?;
78
+ result as u16
79
+ };
80
+ Ok(result)
81
+ }
82
+ */
69
83
70
84
pub fn done ( self ) {
71
85
// FIXME: Nothing to do?
72
86
}
73
- }
87
+ }
0 commit comments