Skip to content

Commit 8ab4f83

Browse files
committed
demuxer: Rebase and a few tweaks to file_functions
1 parent 48397ff commit 8ab4f83

File tree

13 files changed

+168
-253
lines changed

13 files changed

+168
-253
lines changed

src/rust/lib_ccxr/src/activity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl ActivityExt for Options {
3030
fn activity_input_file_open(&mut self, filename: &str) {
3131
if self.gui_mode_reports {
3232
let mut stderr = io::stderr();
33-
writeln!(stderr, "###INPUTFILEOPEN#{}", filename).unwrap();
33+
writeln!(stderr, "###INPUTFILEOPEN#{filename}").unwrap();
3434
stderr.flush().unwrap();
3535
}
3636
}

src/rust/src/ctorust.rs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
#![allow(clippy::unnecessary_cast)] // we have to do this as windows has different types for some C types
2-
use crate::bindings::{
3-
cap_info, ccx_boundary_time, ccx_bufferdata_type, ccx_bufferdata_type_CCX_DVB_SUBTITLE,
4-
ccx_bufferdata_type_CCX_DVD_SUBTITLE, ccx_bufferdata_type_CCX_H264,
5-
ccx_bufferdata_type_CCX_HAUPPAGE, ccx_bufferdata_type_CCX_ISDB_SUBTITLE,
6-
ccx_bufferdata_type_CCX_PES, ccx_bufferdata_type_CCX_PRIVATE_MPEG2_CC,
7-
ccx_bufferdata_type_CCX_RAW, ccx_bufferdata_type_CCX_RAW_TYPE,
8-
ccx_bufferdata_type_CCX_TELETEXT, ccx_bufferdata_type_CCX_UNKNOWN, ccx_code_type,
9-
ccx_common_timing_ctx, ccx_decoder_608_color_code, ccx_decoder_608_color_code_COL_MAX,
10-
ccx_decoder_608_report, ccx_decoder_608_settings, ccx_decoder_dtvcc_report,
11-
ccx_decoder_dtvcc_settings, ccx_demux_report, ccx_encoders_transcript_format,
12-
ccx_encoding_type, ccx_frame_type_CCX_FRAME_TYPE_B_FRAME,
13-
ccx_frame_type_CCX_FRAME_TYPE_D_FRAME, ccx_frame_type_CCX_FRAME_TYPE_I_FRAME,
14-
ccx_frame_type_CCX_FRAME_TYPE_P_FRAME, ccx_output_date_format, ccx_output_format, ccx_rational,
15-
ccx_stream_mode_enum, demuxer_cfg, encoder_cfg, list_head, program_info, PMT_entry, PSI_buffer,
16-
};
2+
use crate::bindings::*;
173
use crate::demuxer::common_structs::{
184
CapInfo, CcxDemuxReport, CcxRational, PMTEntry, PSIBuffer, ProgramInfo,
195
};
@@ -493,30 +479,47 @@ impl FromCType<ccx_encoding_type> for Encoding {
493479
// Implementation for DtvccServiceCharset
494480
impl FromCType<DtvccServiceCharsetArgs> for DtvccServiceCharset {
495481
unsafe fn from_ctype(args: DtvccServiceCharsetArgs) -> Option<Self> {
496-
if args.services_charsets.is_null() || args.all_services_charset.is_null() {
497-
return Some(DtvccServiceCharset::None);
482+
// First check if all_services_charset is not null (Same variant)
483+
if !args.all_services_charset.is_null() {
484+
let charset_str = CStr::from_ptr(args.all_services_charset)
485+
.to_string_lossy()
486+
.into_owned();
487+
return Some(DtvccServiceCharset::Same(charset_str));
498488
}
499489

500-
if *args.all_services_charset < ccx_decoder_608_color_code_COL_MAX as i8 {
501-
let charset = format!("Charset_{}", *args.all_services_charset);
502-
Some(DtvccServiceCharset::Same(charset))
503-
} else {
504-
let charsets_slice =
505-
std::slice::from_raw_parts(args.services_charsets, DTVCC_MAX_SERVICES);
506-
let mut charsets = Vec::new();
507-
for &code in charsets_slice {
508-
if *code < ccx_decoder_608_color_code_COL_MAX as i8 {
509-
charsets.push(format!("Charset_{:?}", code));
490+
// Then check if services_charsets is not null (Unique variant)
491+
if !args.services_charsets.is_null() {
492+
let mut charsets = Vec::with_capacity(DTVCC_MAX_SERVICES);
493+
494+
// Read each string pointer from the array
495+
for i in 0..DTVCC_MAX_SERVICES {
496+
let str_ptr = *args.services_charsets.add(i);
497+
498+
let charset_str = if str_ptr.is_null() {
499+
// If individual string pointer is null, use empty string as fallback
500+
String::new()
510501
} else {
511-
charsets.push("Invalid".to_string());
512-
}
513-
}
514-
if let Ok(array) = charsets.try_into() {
515-
Some(DtvccServiceCharset::Unique(Box::new(array)))
516-
} else {
517-
Some(DtvccServiceCharset::None)
502+
CStr::from_ptr(str_ptr).to_string_lossy().into_owned()
503+
};
504+
505+
charsets.push(charset_str);
518506
}
507+
508+
// Convert Vec to Box<[String; DTVCC_MAX_SERVICES]>
509+
let boxed_array = match charsets.try_into() {
510+
Ok(array) => Box::new(array),
511+
Err(_) => {
512+
// This should never happen since we allocated exactly DTVCC_MAX_SERVICES items
513+
// But as a fallback, create array filled with empty strings
514+
Box::new([const { String::new() }; DTVCC_MAX_SERVICES])
515+
}
516+
};
517+
518+
return Some(DtvccServiceCharset::Unique(boxed_array));
519519
}
520+
521+
// Both pointers are null, return None variant
522+
Some(DtvccServiceCharset::None)
520523
}
521524
}
522525

src/rust/src/decoder/output.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'a> Writer<'a> {
7070
pub fn write_done(&mut self) {
7171
if self.write_format == ccx_output_format::CCX_OF_SAMI {
7272
if let Err(err) = self.write_sami_footer() {
73-
warn!("{}", err);
73+
warn!("{err}");
7474
}
7575
} else {
7676
debug!("dtvcc_write_done: no handling required");
@@ -107,8 +107,7 @@ pub fn color_to_hex(color: u8) -> (u8, u8, u8) {
107107
let green = (color >> 2) & 0x3;
108108
let blue = color & 0x3;
109109
debug!(
110-
"Color: {} [{:06x}] {} {} {}",
111-
color, color, red, green, blue
110+
"Color: {color} [{color:06x}] {red} {green} {blue}"
112111
);
113112
(red, green, blue)
114113
}

src/rust/src/decoder/service_decoder.rs

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl dtvcc_service_decoder {
115115
let pd = match dtvcc_window_pd::new(window.attribs.print_direction) {
116116
Ok(val) => val,
117117
Err(e) => {
118-
warn!("{}", e);
118+
warn!("{e}");
119119
return;
120120
}
121121
};
@@ -218,7 +218,7 @@ impl dtvcc_service_decoder {
218218
let pd = match dtvcc_window_pd::new(window.attribs.print_direction) {
219219
Ok(val) => val,
220220
Err(e) => {
221-
warn!("{}", e);
221+
warn!("{e}");
222222
return;
223223
}
224224
};
@@ -283,7 +283,7 @@ impl dtvcc_service_decoder {
283283
return -1;
284284
}
285285

286-
debug!("C1: [{:?}] [{}] ({})", command, name, length);
286+
debug!("C1: [{command:?}] [{name}] ({length})");
287287
match command {
288288
C1CodeSet::CW0
289289
| C1CodeSet::CW1
@@ -344,7 +344,7 @@ impl dtvcc_service_decoder {
344344
for i in 0..CCX_DTVCC_MAX_WINDOWS {
345345
if windows_bitmap & 1 == 1 {
346346
let window = &mut self.windows[i as usize];
347-
debug!("[W{}]", i);
347+
debug!("[W{i}]");
348348
let window_had_content = is_true(window.is_defined)
349349
&& is_true(window.visible)
350350
&& is_false(window.is_empty);
@@ -381,7 +381,7 @@ impl dtvcc_service_decoder {
381381
for i in 0..CCX_DTVCC_MAX_WINDOWS {
382382
if windows_bitmap & 1 == 1 {
383383
let window = &mut self.windows[i as usize];
384-
debug!("[W{}]", i);
384+
debug!("[W{i}]");
385385
if is_true(window.visible) {
386386
screen_content_changed = true;
387387
window.visible = 0;
@@ -418,11 +418,11 @@ impl dtvcc_service_decoder {
418418
let window = &mut self.windows[i as usize];
419419
if windows_bitmap & 1 == 1 && is_true(window.is_defined) {
420420
if is_false(window.visible) {
421-
debug!("[W-{}: 0->1]", i);
421+
debug!("[W-{i}: 0->1]");
422422
window.visible = 1;
423423
window.update_time_show(timing);
424424
} else {
425-
debug!("[W-{}: 1->0]", i);
425+
debug!("[W-{i}: 1->0]");
426426
window.visible = 0;
427427
window.update_time_hide(timing);
428428
if is_false(window.is_empty) {
@@ -456,7 +456,7 @@ impl dtvcc_service_decoder {
456456
} else {
457457
for i in 0..CCX_DTVCC_MAX_WINDOWS {
458458
if windows_bitmap & 1 == 1 {
459-
debug!("Deleting [W{}]", i);
459+
debug!("Deleting [W{i}]");
460460
let window = &mut self.windows[i as usize];
461461
let window_had_content = is_true(window.is_defined)
462462
&& is_true(window.visible)
@@ -501,9 +501,9 @@ impl dtvcc_service_decoder {
501501
for i in 0..CCX_DTVCC_MAX_WINDOWS {
502502
if windows_bitmap & 1 == 1 {
503503
let window = &mut self.windows[i as usize];
504-
debug!("[W{}]", i);
504+
debug!("[W{i}]");
505505
if is_false(window.is_defined) {
506-
error!("Window {} was not defined", i);
506+
error!("Window {i} was not defined");
507507
continue;
508508
}
509509
if is_false(window.visible) {
@@ -526,8 +526,7 @@ impl dtvcc_service_decoder {
526526
timing: &mut ccx_common_timing_ctx,
527527
) {
528528
debug!(
529-
"dtvcc_handle_DFx_DefineWindow: W[{}], attributes:",
530-
window_id
529+
"dtvcc_handle_DFx_DefineWindow: W[{window_id}], attributes:"
531530
);
532531
let window = &mut self.windows[window_id as usize];
533532
let block = &block[..=5];
@@ -562,12 +561,12 @@ impl dtvcc_service_decoder {
562561
let mut do_clear_window = false;
563562

564563
debug!("Visible: [{}]", if is_true(visible) { "Yes" } else { "No" });
565-
debug!("Priority: [{}]", priority);
566-
debug!("Row count: [{}]", row_count);
567-
debug!("Column count: [{}]", col_count);
568-
debug!("Anchor point: [{}]", anchor_point);
569-
debug!("Anchor vertical: [{}]", anchor_vertical);
570-
debug!("Anchor horizontal: [{}]", anchor_horizontal);
564+
debug!("Priority: [{priority}]");
565+
debug!("Row count: [{row_count}]");
566+
debug!("Column count: [{col_count}]");
567+
debug!("Anchor point: [{anchor_point}]");
568+
debug!("Anchor vertical: [{anchor_vertical}]");
569+
debug!("Anchor horizontal: [{anchor_horizontal}]");
571570
debug!(
572571
"Relative pos: [{}]",
573572
if is_true(relative_pos) { "Yes" } else { "No" }
@@ -580,8 +579,8 @@ impl dtvcc_service_decoder {
580579
"Column lock: [{}]",
581580
if is_true(col_lock) { "Yes" } else { "No" }
582581
);
583-
debug!("Pen style: [{}]", pen_style);
584-
debug!("Win style: [{}]", win_style);
582+
debug!("Pen style: [{pen_style}]");
583+
debug!("Win style: [{win_style}]");
585584

586585
// Korean samples have "anchor_vertical" and "anchor_horizontal" mixed up,
587586
// this seems to be an encoder issue, but we can workaround it
@@ -640,7 +639,7 @@ impl dtvcc_service_decoder {
640639
for i in 0..CCX_DTVCC_MAX_ROWS as usize {
641640
let layout = Layout::array::<dtvcc_symbol>(CCX_DTVCC_MAX_COLUMNS as usize);
642641
if let Err(e) = layout {
643-
error!("dtvcc_handle_DFx_DefineWindow: Incorrect Layout, {}", e);
642+
error!("dtvcc_handle_DFx_DefineWindow: Incorrect Layout, {e}");
644643
} else {
645644
let ptr = unsafe { alloc(layout.unwrap()) };
646645
if ptr.is_null() {
@@ -671,7 +670,7 @@ impl dtvcc_service_decoder {
671670
for i in 0..CCX_DTVCC_MAX_ROWS as usize {
672671
let layout = Layout::array::<dtvcc_symbol>(CCX_DTVCC_MAX_COLUMNS as usize);
673672
if let Err(e) = layout {
674-
error!("dtvcc_handle_DFx_DefineWindow: Incorrect Layout, {}", e);
673+
error!("dtvcc_handle_DFx_DefineWindow: Incorrect Layout, {e}");
675674
} else {
676675
unsafe { dealloc(window.rows[i] as *mut u8, layout.unwrap()) };
677676
}
@@ -699,12 +698,10 @@ impl dtvcc_service_decoder {
699698
let italic = (block[1] >> 7) & 0x1;
700699
debug!("dtvcc_handle_SPA_SetPenAttributes: attributes: ");
701700
debug!(
702-
"Pen size: [{}] Offset: [{}] Text tag: [{}] Font tag: [{}]",
703-
pen_size, offset, text_tag, font_tag
701+
"Pen size: [{pen_size}] Offset: [{offset}] Text tag: [{text_tag}] Font tag: [{font_tag}]"
704702
);
705703
debug!(
706-
"Edge type: [{}] Underline: [{}] Italic: [{}]",
707-
edge_type, underline, italic
704+
"Edge type: [{edge_type}] Underline: [{underline}] Italic: [{italic}]"
708705
);
709706

710707
let window = &mut self.windows[self.current_window as usize];
@@ -739,14 +736,12 @@ impl dtvcc_service_decoder {
739736
let edge_color = (block[2]) & 0x3f;
740737
debug!("dtvcc_handle_SPC_SetPenColor: attributes: ");
741738
debug!(
742-
"Foreground color: [{}] Foreground opacity: [{}]",
743-
fg_color, fg_opacity
739+
"Foreground color: [{fg_color}] Foreground opacity: [{fg_opacity}]"
744740
);
745741
debug!(
746-
"Background color: [{}] Background opacity: [{}]",
747-
bg_color, bg_opacity
742+
"Background color: [{bg_color}] Background opacity: [{bg_opacity}]"
748743
);
749-
debug!("Edge color: [{}]", edge_color);
744+
debug!("Edge color: [{edge_color}]");
750745

751746
let window = &mut self.windows[self.current_window as usize];
752747
if window.pen_row == -1 {
@@ -774,7 +769,7 @@ impl dtvcc_service_decoder {
774769
debug!("dtvcc_handle_SPL_SetPenLocation: attributes: ");
775770
let row = block[0] & 0x0f;
776771
let col = block[1] & 0x3f;
777-
debug!("Row: [{}] Column: [{}]", row, col);
772+
debug!("Row: [{row}] Column: [{col}]");
778773

779774
let window = &mut self.windows[self.current_window as usize];
780775
window.pen_row = row as i32;
@@ -804,16 +799,13 @@ impl dtvcc_service_decoder {
804799
let effect_speed = (block[3] >> 4) & 0x0f;
805800
debug!("dtvcc_handle_SWA_SetWindowAttributes: attributes: ");
806801
debug!(
807-
"Fill color: [{}] Fill opacity: [{}] Border color: [{}] Border type: [{}]",
808-
fill_color, fill_opacity, border_color, border_type
802+
"Fill color: [{fill_color}] Fill opacity: [{fill_opacity}] Border color: [{border_color}] Border type: [{border_type}]"
809803
);
810804
debug!(
811-
"Justify: [{}] Scroll dir: [{}] Print dir: [{}] Word wrap: [{}]",
812-
justify, scroll_dir, print_dir, word_wrap
805+
"Justify: [{justify}] Scroll dir: [{scroll_dir}] Print dir: [{print_dir}] Word wrap: [{word_wrap}]"
813806
);
814807
debug!(
815-
"Border type: [{}] Display eff: [{}] Effect dir: [{}] Effect speed: [{}]",
816-
border_type, display_eff, effect_dir, effect_speed
808+
"Border type: [{border_type}] Display eff: [{display_eff}] Effect dir: [{effect_dir}] Effect speed: [{effect_speed}]"
817809
);
818810

819811
let window_attribts = &mut self.windows[self.current_window as usize].attribs;
@@ -834,22 +826,20 @@ impl dtvcc_service_decoder {
834826
///
835827
/// Change current window to the window id provided
836828
pub fn handle_set_current_window(&mut self, window_id: u8) {
837-
debug!("dtvcc_handle_CWx_SetCurrentWindow: [{}]", window_id);
829+
debug!("dtvcc_handle_CWx_SetCurrentWindow: [{window_id}]");
838830
if is_true(self.windows[window_id as usize].is_defined) {
839831
self.current_window = window_id as i32;
840832
} else {
841833
debug!(
842-
"dtvcc_handle_CWx_SetCurrentWindow: window [{}] is not defined",
843-
window_id
834+
"dtvcc_handle_CWx_SetCurrentWindow: window [{window_id}] is not defined"
844835
);
845836
}
846837
}
847838

848839
/// DLY Delay
849840
pub fn handle_delay(&mut self, tenths_of_sec: u8) {
850841
debug!(
851-
"dtvcc_handle_DLY_Delay: dely for {} tenths of second",
852-
tenths_of_sec
842+
"dtvcc_handle_DLY_Delay: dely for {tenths_of_sec} tenths of second"
853843
);
854844
}
855845

@@ -910,7 +900,7 @@ impl dtvcc_service_decoder {
910900
let anchor = match dtvcc_pen_anchor_point::new(window.anchor_point) {
911901
Ok(val) => val,
912902
Err(e) => {
913-
warn!("{}", e);
903+
warn!("{e}");
914904
return;
915905
}
916906
};
@@ -955,7 +945,7 @@ impl dtvcc_service_decoder {
955945
"For window {}: Anchor point -> {}, size {}:{}, real position {}:{}",
956946
window.number, window.anchor_point, window.row_count, window.col_count, top, left
957947
);
958-
debug!("we have top [{}] and left [{}]", top, left);
948+
debug!("we have top [{top}] and left [{left}]");
959949
if top < 0 {
960950
top = 0
961951
}
@@ -972,7 +962,7 @@ impl dtvcc_service_decoder {
972962
} else {
973963
window.col_count
974964
};
975-
debug!("{}*{} will be copied to the TV.", copy_rows, copy_cols);
965+
debug!("{copy_rows}*{copy_cols} will be copied to the TV.");
976966

977967
unsafe {
978968
let tv = &mut *self.tv;
@@ -997,7 +987,7 @@ impl dtvcc_service_decoder {
997987
let (a_x1, a_x2, a_y1, a_y2) = match window.get_dimensions() {
998988
Ok(val) => val,
999989
Err(e) => {
1000-
warn!("{}", e);
990+
warn!("{e}");
1001991
return false;
1002992
}
1003993
};
@@ -1006,7 +996,7 @@ impl dtvcc_service_decoder {
1006996
let (b_x1, b_x2, b_y1, b_y2) = match win_compare.get_dimensions() {
1007997
Ok(val) => val,
1008998
Err(e) => {
1009-
warn!("{}", e);
999+
warn!("{e}");
10101000
return false;
10111001
}
10121002
};
@@ -1156,7 +1146,7 @@ impl dtvcc_service_decoder {
11561146
let pd = match dtvcc_window_pd::new(window.attribs.print_direction) {
11571147
Ok(val) => val,
11581148
Err(e) => {
1159-
warn!("{}", e);
1149+
warn!("{e}");
11601150
return;
11611151
}
11621152
};

0 commit comments

Comments
 (0)