@@ -25,15 +25,15 @@ const CCX_DTVCC_MAX_SERVICES: usize = 63;
25
25
pub struct Dtvcc < ' a > {
26
26
pub is_active : bool ,
27
27
pub active_services_count : u8 ,
28
- pub services_active : Vec < i32 > ,
28
+ pub services_active : [ i32 ; CCX_DTVCC_MAX_SERVICES ] ,
29
29
pub report_enabled : bool ,
30
30
pub report : & ' a mut ccx_decoder_dtvcc_report ,
31
- pub decoders : Vec < & ' a mut dtvcc_service_decoder > ,
32
- pub packet : Vec < u8 > ,
31
+ pub decoders : [ Option < & ' a mut dtvcc_service_decoder > ; CCX_DTVCC_MAX_SERVICES ] ,
32
+ pub packet : [ u8 ; CCX_DTVCC_MAX_SERVICES ] ,
33
33
pub packet_length : u8 ,
34
34
pub is_header_parsed : bool ,
35
35
pub last_sequence : i32 ,
36
- pub encoder : & ' a mut encoder_ctx ,
36
+ pub encoder : Option < & ' a mut encoder_ctx > ,
37
37
pub no_rollup : bool ,
38
38
pub timing : & ' a mut ccx_common_timing_ctx ,
39
39
}
@@ -44,30 +44,30 @@ impl<'a> Dtvcc<'a> {
44
44
let report = unsafe { & mut * opts. report } ;
45
45
report. reset_count = 0 ;
46
46
47
- let decoders = ( 0 ..CCX_DTVCC_MAX_SERVICES )
48
- . map ( |i| {
49
- if !is_true ( opts. services_enabled [ i] ) {
50
- return unsafe { & mut * std:: ptr:: null_mut ( ) } ;
51
- }
47
+ const INIT : Option < & mut dtvcc_service_decoder > = None ;
48
+ let decoders = [ INIT ; CCX_DTVCC_MAX_SERVICES ] ;
49
+ decoders. iter_mut ( ) . enumerate ( ) . for_each ( |( i, val) | {
50
+ if !is_true ( opts. services_enabled [ i] ) {
51
+ return ;
52
+ }
52
53
53
- let decoder = Box :: leak ( Box :: new ( dtvcc_service_decoder {
54
- tv : Box :: leak ( Box :: new ( dtvcc_tv_screen {
55
- cc_count : 0 ,
56
- service_number : i as i32 + 1 ,
57
- ..dtvcc_tv_screen:: default ( )
58
- } ) ) ,
59
- ..dtvcc_service_decoder:: default ( )
60
- } ) ) ;
54
+ let decoder = Box :: leak ( Box :: new ( dtvcc_service_decoder {
55
+ tv : Box :: leak ( Box :: new ( dtvcc_tv_screen {
56
+ cc_count : 0 ,
57
+ service_number : i as i32 + 1 ,
58
+ ..dtvcc_tv_screen:: default ( )
59
+ } ) ) ,
60
+ ..dtvcc_service_decoder:: default ( )
61
+ } ) ) ;
61
62
62
- decoder. windows . iter_mut ( ) . for_each ( |w| {
63
- w. memory_reserved = 0 ;
64
- } ) ;
63
+ decoder. windows . iter_mut ( ) . for_each ( |w| {
64
+ w. memory_reserved = 0 ;
65
+ } ) ;
65
66
66
- unsafe { dtvcc_windows_reset ( decoder) } ;
67
+ unsafe { dtvcc_windows_reset ( decoder) } ;
67
68
68
- decoder
69
- } )
70
- . collect ( ) ;
69
+ val = & mut Some ( decoder) ;
70
+ } ) ;
71
71
72
72
for i in 0 ..CCX_DTVCC_MAX_SERVICES {
73
73
if !is_true ( opts. services_enabled [ i] ) {
@@ -83,14 +83,14 @@ impl<'a> Dtvcc<'a> {
83
83
is_active : false ,
84
84
no_rollup : is_true ( opts. no_rollup ) ,
85
85
active_services_count : opts. active_services_count as u8 ,
86
- services_active : opts. services_enabled . to_vec ( ) ,
86
+ services_active : opts. services_enabled . clone ( ) ,
87
87
packet_length : 0 ,
88
88
is_header_parsed : false ,
89
- packet : vec ! [ 0 ; CCX_DTVCC_MAX_SERVICES ] ,
89
+ packet : [ 0 ; CCX_DTVCC_MAX_SERVICES ] ,
90
90
last_sequence : CCX_DTVCC_NO_LAST_SEQUENCE ,
91
91
report_enabled : is_true ( opts. print_file_reports ) ,
92
92
timing : unsafe { & mut * opts. timing } ,
93
- encoder : unsafe { & mut * std :: ptr :: null_mut ( ) } ,
93
+ encoder : None ,
94
94
}
95
95
96
96
// notes: import CCX_DTVCC_MAX_SERVICES, initialize the decoders
0 commit comments