File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ pub unsafe extern "C" fn ccxr_millis_to_time(
138138/// # Safety
139139///
140140/// `ctx` should not be null.
141- unsafe fn generate_timing_context ( ctx : * const ccx_common_timing_ctx ) -> TimingContext {
141+ pub unsafe fn generate_timing_context ( ctx : * const ccx_common_timing_ctx ) -> TimingContext {
142142 let pts_set = match ( * ctx) . pts_set {
143143 0 => PtsSet :: No ,
144144 1 => PtsSet :: Received ,
Original file line number Diff line number Diff line change @@ -87,19 +87,20 @@ pub unsafe fn write_xds_string(
8787 let data_element = & mut * new_data. add ( sub. nb_data as usize ) ;
8888 let c_str = CString :: new ( p) . map_err ( |_| XDSError :: Err ) ?;
8989
90- let len = c_str. as_bytes_with_nul ( ) . len ( ) ;
91- let ptr = unsafe { malloc ( len) as * mut i8 } ; // fixing c/rust mem mismatch
90+ let len = c_str. as_bytes ( ) . len ( ) ; // length w/o null terminator - matching C's vsnprintf return
91+ let alloc_len = len + 1 ; // allocate space for null terminator
92+ let ptr = unsafe { malloc ( alloc_len) as * mut i8 } ; // fixing c/rust mem mismatch
9293 if ptr. is_null ( ) {
9394 return Err ( XDSError :: Err ) ;
9495 }
9596 unsafe {
96- std:: ptr:: copy_nonoverlapping ( c_str. as_ptr ( ) , ptr, len ) ; // fixing c/rust mem mismatch
97+ std:: ptr:: copy_nonoverlapping ( c_str. as_ptr ( ) , ptr, alloc_len ) ; // copy including null terminator
9798 }
9899
99100 data_element. format = 2 ;
100101 data_element. start_time = ts_start_of_xds;
101102 if let Some ( timing) = ctx. timing . as_mut ( ) {
102- data_element. end_time = get_fts ( timing, CaptionField :: Cea708 ) . millis ( ) ;
103+ data_element. end_time = get_fts ( timing, CaptionField :: Field2 ) . millis ( ) ;
103104 }
104105 data_element. xds_str = ptr;
105106 data_element. xds_len = len;
@@ -179,15 +180,15 @@ impl CcxDecodersXdsContext<'_> {
179180 for i in 0 ..NUM_XDS_BUFFERS {
180181 if self . xds_buffers [ i] . in_use != 0
181182 && self . xds_buffers [ i]
182- . xds_class
183- . map ( |c| c. to_c_int ( ) )
184- . unwrap_or ( -1 )
185- == xds_class
183+ . xds_class
184+ . map ( |c| c. to_c_int ( ) )
185+ . unwrap_or ( -1 )
186+ == xds_class
186187 && self . xds_buffers [ i]
187- . xds_type
188- . map ( |t| t. to_c_int ( ) )
189- . unwrap_or ( -1 )
190- == lo as i32
188+ . xds_type
189+ . map ( |t| t. to_c_int ( ) )
190+ . unwrap_or ( -1 )
191+ == lo as i32
191192 {
192193 matching_buf = i as i32 ;
193194 break ;
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ pub mod types;
1717
1818use crate :: bindings:: * ;
1919use crate :: ctorust:: FromCType ;
20+ use crate :: libccxr_exports:: time:: generate_timing_context;
2021use crate :: xds:: handlers:: { do_end_of_xds, TS_START_OF_XDS } ;
2122use crate :: xds:: types:: { copy_xds_context_from_rust_to_c, CcxDecodersXdsContext } ;
2223use std:: os:: raw:: c_int;
@@ -47,6 +48,15 @@ pub unsafe extern "C" fn ccxr_do_end_of_xds(
4748 None => return ,
4849 } ;
4950
51+ // populate timing from the C ctx's timing ptr
52+ let c_timing_ptr = ( * ctx) . timing ;
53+ let mut timing_ctx = if !c_timing_ptr. is_null ( ) {
54+ Some ( generate_timing_context ( c_timing_ptr) )
55+ } else {
56+ None
57+ } ;
58+ rust_ctx. timing = timing_ctx. as_mut ( ) ;
59+
5060 // Call the Rust implementation
5161 do_end_of_xds ( & mut * sub, & mut rust_ctx, expected_checksum) ;
5262
Original file line number Diff line number Diff line change @@ -503,6 +503,7 @@ pub unsafe fn copy_xds_context_from_rust_to_c(
503503 if bitstream_ptr. is_null ( ) {
504504 return ;
505505 }
506+ let original_timing = ( * bitstream_ptr) . timing ;
506507 let output = ccx_decoders_xds_context {
507508 current_xds_min : rust_ctx. current_xds_min ,
508509 current_xds_hour : rust_ctx. current_xds_hour ,
@@ -522,7 +523,7 @@ pub unsafe fn copy_xds_context_from_rust_to_c(
522523 cur_xds_payload : rust_ctx. cur_xds_payload ,
523524 cur_xds_payload_length : rust_ctx. cur_xds_payload_length ,
524525 cur_xds_packet_type : rust_ctx. cur_xds_packet_type ,
525- timing : null_mut ( ) ,
526+ timing : original_timing ,
526527 current_ar_start : rust_ctx. current_ar_start ,
527528 current_ar_end : rust_ctx. current_ar_end ,
528529 xds_write_to_file : if rust_ctx. xds_write_to_file { 1 } else { 0 } ,
You can’t perform that action at this time.
0 commit comments