@@ -26,33 +26,35 @@ const CCX_DTVCC_MAX_SERVICES: usize = 63;
26
26
// const CCX_DTVCC_MAX_WINDOWS: usize = 8;
27
27
28
28
/// Context required for processing 708 data
29
- pub struct Dtvcc < ' a > {
29
+ pub struct Dtvcc {
30
30
pub is_active : bool ,
31
31
pub active_services_count : u8 ,
32
32
pub services_active : [ i32 ; CCX_DTVCC_MAX_SERVICES ] ,
33
33
pub report_enabled : bool ,
34
- pub report : & ' a mut ccx_decoder_dtvcc_report ,
35
- pub decoders : [ Option < dtvcc_service_decoder > ; CCX_DTVCC_MAX_SERVICES ] ,
34
+ pub report : * mut ccx_decoder_dtvcc_report ,
35
+ pub decoders : [ Option < Box < dtvcc_service_decoder > > ; CCX_DTVCC_MAX_SERVICES ] ,
36
36
pub packet : [ u8 ; CCX_DTVCC_MAX_SERVICES ] ,
37
37
pub packet_length : u8 ,
38
38
pub is_header_parsed : bool ,
39
39
pub last_sequence : i32 ,
40
- pub encoder : Option < & ' a mut encoder_ctx > ,
40
+ pub encoder : * mut encoder_ctx ,
41
41
pub no_rollup : bool ,
42
- pub timing : & ' a mut ccx_common_timing_ctx ,
42
+ pub timing : * mut ccx_common_timing_ctx ,
43
43
}
44
44
45
- impl < ' a > Dtvcc < ' a > {
45
+ impl Dtvcc {
46
46
/// Create a new dtvcc context
47
- pub fn new ( opts : & ' _ mut ccx_decoder_dtvcc_settings ) -> Self {
47
+ pub fn new ( opts : & ccx_decoder_dtvcc_settings ) -> Self {
48
48
// closely follows `dtvcc_init` at `src/lib_ccx/ccx_dtvcc.c:76`
49
49
50
- let report = unsafe { opts. report . as_mut ( ) . unwrap ( ) } ;
51
- report. reset_count = 0 ;
50
+ let report = opts. report ;
51
+ unsafe {
52
+ ( * report) . reset_count = 0 ;
53
+ }
52
54
53
55
let is_active = false ;
54
- let _no_rollup = is_true ( opts. no_rollup ) ;
55
- let _active_services_count = opts. active_services_count as u8 ;
56
+ let no_rollup = is_true ( opts. no_rollup ) ;
57
+ let active_services_count = opts. active_services_count as u8 ;
56
58
let services_active = opts. services_enabled ;
57
59
58
60
// `dtvcc_clear_packet` does the following
@@ -63,11 +65,11 @@ impl<'a> Dtvcc<'a> {
63
65
let last_sequence = CCX_DTVCC_NO_LAST_SEQUENCE ;
64
66
65
67
let report_enabled = is_true ( opts. print_file_reports ) ;
66
- let timing = unsafe { opts. timing . as_mut ( ) } . unwrap ( ) ;
68
+ let timing = opts. timing ;
67
69
68
70
// unlike C, here the decoders are allocated on the stack as an array.
69
71
let decoders = {
70
- const INIT : Option < dtvcc_service_decoder > = None ;
72
+ const INIT : Option < Box < dtvcc_service_decoder > > = None ;
71
73
let mut decoders = [ INIT ; CCX_DTVCC_MAX_SERVICES ] ;
72
74
73
75
decoders
@@ -79,7 +81,7 @@ impl<'a> Dtvcc<'a> {
79
81
return ;
80
82
}
81
83
82
- let mut decoder = dtvcc_service_decoder {
84
+ let mut decoder = Box :: new ( dtvcc_service_decoder {
83
85
// we cannot allocate this on the stack as `dtvcc_service_decoder` is a C
84
86
// struct cannot be changed trivially
85
87
tv : Box :: into_raw ( Box :: new ( dtvcc_tv_screen {
@@ -88,27 +90,27 @@ impl<'a> Dtvcc<'a> {
88
90
..dtvcc_tv_screen:: default ( )
89
91
} ) ) ,
90
92
..dtvcc_service_decoder:: default ( )
91
- } ;
93
+ } ) ;
92
94
93
95
decoder. windows . iter_mut ( ) . for_each ( |w| {
94
96
w. memory_reserved = 0 ;
95
97
} ) ;
96
98
97
- unsafe { dtvcc_windows_reset ( & mut decoder) } ;
99
+ unsafe { dtvcc_windows_reset ( decoder. as_mut ( ) ) } ;
98
100
99
101
* d = Some ( decoder) ;
100
102
} ) ;
101
103
102
104
decoders
103
105
} ;
104
106
105
- let encoder = None ; // Unlike C, does not mention `encoder` and is initialised to `null` by default
107
+ let encoder = std :: ptr :: null_mut ( ) ; // Unlike C, does not mention `encoder` and is initialised to `null` by default
106
108
107
109
Self {
108
110
report,
109
111
is_active,
110
- no_rollup : _no_rollup ,
111
- active_services_count : _active_services_count ,
112
+ no_rollup,
113
+ active_services_count,
112
114
services_active,
113
115
packet_length,
114
116
is_header_parsed,
@@ -223,15 +225,15 @@ impl<'a> Dtvcc<'a> {
223
225
}
224
226
225
227
if block_length != 0 {
226
- self . report . services [ service_number as usize ] = 1 ;
228
+ unsafe { ( * self . report ) . services [ service_number as usize ] = 1 } ;
227
229
}
228
230
229
231
if service_number > 0 && is_true ( self . services_active [ ( service_number - 1 ) as usize ] ) {
230
232
let decoder = & mut self . decoders [ ( service_number - 1 ) as usize ] ;
231
- decoder. unwrap ( ) . process_service_block (
233
+ decoder. as_mut ( ) . unwrap ( ) . process_service_block (
232
234
& self . packet [ pos as usize ..( pos + block_length) as usize ] ,
233
- self . encoder . as_mut ( ) . unwrap ( ) ,
234
- self . timing ,
235
+ unsafe { self . encoder . as_mut ( ) . unwrap ( ) } ,
236
+ unsafe { self . timing . as_mut ( ) . unwrap ( ) } ,
235
237
self . no_rollup ,
236
238
) ;
237
239
}
@@ -254,11 +256,11 @@ impl<'a> Dtvcc<'a> {
254
256
}
255
257
}
256
258
257
- impl < ' a > Drop for Dtvcc < ' a > {
259
+ impl Drop for Dtvcc {
258
260
fn drop ( & mut self ) {
259
261
// closely follows `dtvcc_free` at `src/lib_ccx/ccx_dtvcc.c:126`
260
262
for i in 0 ..CCX_DTVCC_MAX_SERVICES {
261
- if let Some ( mut decoder) = self . decoders [ i] {
263
+ if let Some ( decoder) = self . decoders [ i] . as_mut ( ) {
262
264
if !is_true ( self . services_active [ i] ) {
263
265
continue ;
264
266
}
@@ -275,9 +277,7 @@ impl<'a> Drop for Dtvcc<'a> {
275
277
window. memory_reserved = 0 ;
276
278
} ) ;
277
279
278
- unsafe {
279
- decoder. tv . drop_in_place ( ) ;
280
- }
280
+ unsafe { decoder. tv . drop_in_place ( ) } ;
281
281
}
282
282
}
283
283
}
0 commit comments