@@ -23,7 +23,7 @@ const CCX_DTVCC_SCREENGRID_COLUMNS: u8 = 210;
23
23
const CCX_DTVCC_MAX_ROWS : u8 = 15 ;
24
24
const CCX_DTVCC_MAX_COLUMNS : u8 = 32 * 2 ;
25
25
const CCX_DTVCC_MAX_SERVICES : usize = 63 ;
26
- const CCX_DTVCC_MAX_WINDOWS : usize = 8 ;
26
+ // const CCX_DTVCC_MAX_WINDOWS: usize = 8;
27
27
28
28
/// Context required for processing 708 data
29
29
pub struct Dtvcc < ' a > {
@@ -44,18 +44,16 @@ pub struct Dtvcc<'a> {
44
44
45
45
impl < ' a > Dtvcc < ' a > {
46
46
/// Create a new dtvcc context
47
- pub fn new < ' b > ( opts : & ' b mut ccx_decoder_dtvcc_settings ) -> Self {
47
+ pub fn new ( opts : & ' _ mut ccx_decoder_dtvcc_settings ) -> Self {
48
48
// closely follows `dtvcc_init` at `src/lib_ccx/ccx_dtvcc.c:76`
49
49
50
50
let report = unsafe { opts. report . as_mut ( ) . unwrap ( ) } ;
51
51
report. reset_count = 0 ;
52
52
53
53
let is_active = false ;
54
- let no_rollup = opts. no_rollup ;
55
- let active_services_count = opts. active_services_count ;
56
- let no_rollup = is_true ( opts. no_rollup ) ;
57
- let active_services_count = opts. active_services_count as u8 ;
58
- let services_active = opts. services_enabled . clone ( ) ;
54
+ let _no_rollup = is_true ( opts. no_rollup ) ;
55
+ let _active_services_count = opts. active_services_count as u8 ;
56
+ let services_active = opts. services_enabled ;
59
57
60
58
// `dtvcc_clear_packet` does the following
61
59
let packet_length = 0 ;
@@ -70,43 +68,47 @@ impl<'a> Dtvcc<'a> {
70
68
// unlike C, here the decoders are allocated on the stack as an array.
71
69
let decoders = {
72
70
const INIT : Option < dtvcc_service_decoder > = None ;
73
- let mut val = [ INIT ; CCX_DTVCC_MAX_SERVICES ] ;
74
-
75
- for i in 0 ..CCX_DTVCC_MAX_SERVICES {
76
- if is_false ( opts. services_enabled [ i] ) {
77
- continue ;
78
- }
71
+ let mut decoders = [ INIT ; CCX_DTVCC_MAX_SERVICES ] ;
72
+
73
+ decoders
74
+ . iter_mut ( )
75
+ . zip ( opts. services_enabled )
76
+ . enumerate ( )
77
+ . for_each ( |( i, ( d, se) ) | {
78
+ if is_false ( se) {
79
+ return ;
80
+ }
79
81
80
- let mut decoder = dtvcc_service_decoder {
81
- // we cannot allocate this on the stack as `dtvcc_service_decoder` is a C
82
- // struct cannot be changed trivially
83
- tv : Box :: into_raw ( Box :: new ( dtvcc_tv_screen {
84
- cc_count : 0 ,
85
- service_number : i as i32 + 1 ,
86
- ..dtvcc_tv_screen:: default ( )
87
- } ) ) ,
88
- ..dtvcc_service_decoder:: default ( )
89
- } ;
90
-
91
- decoder. windows . iter_mut ( ) . for_each ( |w| {
92
- w. memory_reserved = 0 ;
93
- } ) ;
82
+ let mut decoder = dtvcc_service_decoder {
83
+ // we cannot allocate this on the stack as `dtvcc_service_decoder` is a C
84
+ // struct cannot be changed trivially
85
+ tv : Box :: into_raw ( Box :: new ( dtvcc_tv_screen {
86
+ cc_count : 0 ,
87
+ service_number : i as i32 + 1 ,
88
+ ..dtvcc_tv_screen:: default ( )
89
+ } ) ) ,
90
+ ..dtvcc_service_decoder:: default ( )
91
+ } ;
92
+
93
+ decoder. windows . iter_mut ( ) . for_each ( |w| {
94
+ w. memory_reserved = 0 ;
95
+ } ) ;
94
96
95
- unsafe { dtvcc_windows_reset ( & mut decoder) } ;
97
+ unsafe { dtvcc_windows_reset ( & mut decoder) } ;
96
98
97
- val [ i ] = Some ( decoder) ;
98
- }
99
+ * d = Some ( decoder) ;
100
+ } ) ;
99
101
100
- val
102
+ decoders
101
103
} ;
102
104
103
105
let encoder = None ; // Unlike C, does not mention `encoder` and is initialised to `null` by default
104
106
105
107
Self {
106
108
report,
107
109
is_active,
108
- no_rollup,
109
- active_services_count,
110
+ no_rollup : _no_rollup ,
111
+ active_services_count : _active_services_count ,
110
112
services_active,
111
113
packet_length,
112
114
is_header_parsed,
0 commit comments