@@ -15,7 +15,6 @@ const TILE_SIZE: u16 = 64;
15
15
pub type FrameId = u32 ;
16
16
17
17
pub struct DecodingContext {
18
- state : SequenceState ,
19
18
context : rfx:: ContextPdu ,
20
19
channels : rfx:: ChannelsPdu ,
21
20
decoding_tiles : DecodingTileContext ,
@@ -24,7 +23,6 @@ pub struct DecodingContext {
24
23
impl Default for DecodingContext {
25
24
fn default ( ) -> Self {
26
25
Self {
27
- state : SequenceState :: HeaderMessages ,
28
26
context : rfx:: ContextPdu {
29
27
flags : rfx:: OperatingMode :: empty ( ) ,
30
28
entropy_algorithm : rfx:: EntropyAlgorithm :: Rlgr1 ,
@@ -47,20 +45,31 @@ impl DecodingContext {
47
45
input : & mut & [ u8 ] ,
48
46
) -> SessionResult < ( FrameId , InclusiveRectangle ) > {
49
47
loop {
50
- match self . state {
51
- SequenceState :: HeaderMessages => {
52
- self . process_headers ( input) ?;
48
+ let block_header = rfx:: BlockHeader :: from_buffer_consume ( input) ?;
49
+ match block_header. ty {
50
+ rfx:: BlockType :: Sync => {
51
+ self . process_sync ( input, block_header) ?;
53
52
}
54
- SequenceState :: DataMessages => {
55
- return self . process_data_messages ( image, destination, input) ;
53
+ rfx:: BlockType :: FrameBegin => {
54
+ return self . process_frame ( input, block_header, image, destination) ;
55
+ }
56
+ _ => {
57
+ return Err ( reason_err ! (
58
+ "rfx::DecodingContext" ,
59
+ "unexpected RFX block type: {:?}" ,
60
+ block_header. ty
61
+ ) ) ;
56
62
}
57
63
}
58
64
}
59
65
}
60
66
61
- fn process_headers ( & mut self , input : & mut & [ u8 ] ) -> SessionResult < ( ) > {
62
- let _sync = rfx:: SyncPdu :: from_buffer_consume ( input) ?;
67
+ fn process_sync ( & mut self , input : & mut & [ u8 ] , header : rfx:: BlockHeader ) -> SessionResult < ( ) > {
68
+ let _sync = rfx:: SyncPdu :: from_buffer_consume_with_header ( input, header) ?;
69
+ self . process_headers ( input)
70
+ }
63
71
72
+ fn process_headers ( & mut self , input : & mut & [ u8 ] ) -> SessionResult < ( ) > {
64
73
let mut context = None ;
65
74
let mut channels = None ;
66
75
@@ -81,24 +90,24 @@ impl DecodingContext {
81
90
82
91
self . context = context;
83
92
self . channels = channels;
84
- self . state = SequenceState :: DataMessages ;
85
93
86
94
Ok ( ( ) )
87
95
}
88
96
89
97
#[ instrument( skip_all) ]
90
- fn process_data_messages (
98
+ fn process_frame (
91
99
& mut self ,
100
+ input : & mut & [ u8 ] ,
101
+ header : rfx:: BlockHeader ,
92
102
image : & mut DecodedImage ,
93
103
destination : & InclusiveRectangle ,
94
- input : & mut & [ u8 ] ,
95
104
) -> SessionResult < ( FrameId , InclusiveRectangle ) > {
96
105
let channel = self . channels . 0 . first ( ) . unwrap ( ) ;
97
106
let width = channel. width . as_u16 ( ) ;
98
107
let height = channel. height . as_u16 ( ) ;
99
108
let entropy_algorithm = self . context . entropy_algorithm ;
100
109
101
- let frame_begin = rfx:: FrameBeginPdu :: from_buffer_consume ( input) ?;
110
+ let frame_begin = rfx:: FrameBeginPdu :: from_buffer_consume_with_header ( input, header ) ?;
102
111
let mut region = rfx:: RegionPdu :: from_buffer_consume ( input) ?;
103
112
let tile_set = rfx:: TileSetPdu :: from_buffer_consume ( input) ?;
104
113
let _frame_end = rfx:: FrameEndPdu :: from_buffer_consume ( input) ?;
@@ -145,10 +154,6 @@ impl DecodingContext {
145
154
final_update_rectangle = final_update_rectangle. union ( & current_update_rectangle) ;
146
155
}
147
156
148
- if self . context . flags . contains ( rfx:: OperatingMode :: IMAGE_MODE ) {
149
- self . state = SequenceState :: HeaderMessages ;
150
- }
151
-
152
157
Ok ( ( frame_begin. index , final_update_rectangle) )
153
158
}
154
159
}
@@ -258,8 +263,3 @@ struct TileData<'a> {
258
263
quants : [ Quant ; 3 ] ,
259
264
data : [ & ' a [ u8 ] ; 3 ] ,
260
265
}
261
-
262
- enum SequenceState {
263
- HeaderMessages ,
264
- DataMessages ,
265
- }
0 commit comments