@@ -44,24 +44,35 @@ pub struct Dtvcc<'a> {
4444impl < ' a > Dtvcc < ' a > {
4545 /// Create a new dtvcc context
4646 pub fn new ( ctx : & ' a mut dtvcc_ctx ) -> Self {
47- let report = unsafe { & mut * ctx. report } ;
48- let encoder = unsafe { & mut * ( ctx. encoder as * mut encoder_ctx ) } ;
49- let timing = unsafe { & mut * ctx. timing } ;
50-
47+ let report = if !ctx. report . is_null ( ) {
48+ unsafe { Box :: new ( * ( ctx. report ) ) }
49+ } else {
50+ Box :: new ( ccx_decoder_dtvcc_report:: default ( ) )
51+ } ;
52+ let encoder = if !ctx. encoder . is_null ( ) {
53+ unsafe { Box :: new ( * ( ctx. encoder as * mut encoder_ctx ) ) }
54+ } else {
55+ Box :: new ( encoder_ctx:: default ( ) )
56+ } ;
57+ let timing = if !ctx. timing . is_null ( ) {
58+ unsafe { Box :: new ( * ( ctx. timing ) ) }
59+ } else {
60+ Box :: new ( ccx_common_timing_ctx:: default ( ) )
61+ } ;
5162 Self {
5263 is_active : is_true ( ctx. is_active ) ,
5364 active_services_count : ctx. active_services_count as u8 ,
5465 services_active : ctx. services_active . to_vec ( ) ,
5566 report_enabled : is_true ( ctx. report_enabled ) ,
56- report,
67+ report : Box :: leak ( report ) ,
5768 decoders : ctx. decoders . iter_mut ( ) . collect ( ) ,
5869 packet : ctx. current_packet . to_vec ( ) ,
5970 packet_length : ctx. current_packet_length as u8 ,
6071 is_header_parsed : is_true ( ctx. is_current_packet_header_parsed ) ,
6172 last_sequence : ctx. last_sequence ,
62- encoder,
73+ encoder : Box :: leak ( encoder ) ,
6374 no_rollup : is_true ( ctx. no_rollup ) ,
64- timing,
75+ timing : Box :: leak ( timing ) ,
6576 }
6677 }
6778 /// Process cc data and add it to the dtvcc packet
0 commit comments