Skip to content

Commit

Permalink
fix: tests and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekmedia committed Aug 21, 2024
1 parent ac832a6 commit 8e03558
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 111 deletions.
207 changes: 103 additions & 104 deletions src/rust/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,27 @@ impl FromRust<Options> for ccx_s_options {
///
/// This function is unsafe because it dereferences the pointer passed to it.
unsafe fn copy_from_rust(self: &mut ccx_s_options, options: Options) {
(*self).extract = options.extract as _;
(*self).no_rollup = options.no_rollup as _;
(*self).noscte20 = options.noscte20 as _;
(*self).webvtt_create_css = options.webvtt_create_css as _;
(*self).cc_channel = options.cc_channel as _;
(*self).buffer_input = options.buffer_input as _;
(*self).nofontcolor = options.nofontcolor as _;
(*self).write_format = options.write_format.to_ctype();
(*self).send_to_srv = options.send_to_srv as _;
(*self).nohtmlescape = options.nohtmlescape as _;
(*self).notypesetting = options.notypesetting as _;
(*self).extraction_start = options.extraction_start.to_ctype();
(*self).extraction_end = options.extraction_end.to_ctype();
(*self).print_file_reports = options.print_file_reports as _;
(*self).settings_608 = options.settings_608.to_ctype();
(*self).settings_dtvcc = options.settings_dtvcc.to_ctype();
(*self).is_608_enabled = options.is_608_enabled as _;
(*self).is_708_enabled = options.is_708_enabled as _;
(*self).millis_separator = options.date_format.millis_separator() as _;
(*self).binary_concat = options.binary_concat as _;
(*self).use_gop_as_pts = if let Some(usegops) = options.use_gop_as_pts {
self.extract = options.extract as _;
self.no_rollup = options.no_rollup as _;
self.noscte20 = options.noscte20 as _;
self.webvtt_create_css = options.webvtt_create_css as _;
self.cc_channel = options.cc_channel as _;
self.buffer_input = options.buffer_input as _;
self.nofontcolor = options.nofontcolor as _;
self.write_format = options.write_format.to_ctype();
self.send_to_srv = options.send_to_srv as _;
self.nohtmlescape = options.nohtmlescape as _;
self.notypesetting = options.notypesetting as _;
self.extraction_start = options.extraction_start.to_ctype();
self.extraction_end = options.extraction_end.to_ctype();
self.print_file_reports = options.print_file_reports as _;
self.settings_608 = options.settings_608.to_ctype();
self.settings_dtvcc = options.settings_dtvcc.to_ctype();
self.is_608_enabled = options.is_608_enabled as _;
self.is_708_enabled = options.is_708_enabled as _;
self.millis_separator = options.date_format.millis_separator() as _;
self.binary_concat = options.binary_concat as _;
self.use_gop_as_pts = if let Some(usegops) = options.use_gop_as_pts {
if usegops {
1
} else {
Expand All @@ -80,12 +80,12 @@ impl FromRust<Options> for ccx_s_options {
} else {
0
};
(*self).fix_padding = options.fix_padding as _;
(*self).gui_mode_reports = options.gui_mode_reports as _;
(*self).no_progress_bar = options.no_progress_bar as _;
self.fix_padding = options.fix_padding as _;
self.gui_mode_reports = options.gui_mode_reports as _;
self.no_progress_bar = options.no_progress_bar as _;

if options.sentence_cap_file.try_exists().unwrap_or_default() {
(*self).sentence_cap_file = string_to_c_char(
self.sentence_cap_file = string_to_c_char(
options
.sentence_cap_file
.clone()
Expand All @@ -94,7 +94,7 @@ impl FromRust<Options> for ccx_s_options {
);
}

(*self).live_stream = if let Some(live_stream) = options.live_stream {
self.live_stream = if let Some(live_stream) = options.live_stream {
live_stream.seconds() as _
} else {
-1
Expand All @@ -104,131 +104,130 @@ impl FromRust<Options> for ccx_s_options {
.try_exists()
.unwrap_or_default()
{
(*self).filter_profanity_file = string_to_c_char(
self.filter_profanity_file = string_to_c_char(
options
.filter_profanity_file
.clone()
.to_str()
.unwrap_or_default(),
);
}
(*self).messages_target = options.messages_target as _;
(*self).timestamp_map = options.timestamp_map as _;
(*self).dolevdist = options.dolevdist.into();
(*self).levdistmincnt = options.levdistmincnt as _;
(*self).levdistmaxpct = options.levdistmaxpct as _;
(*self).investigate_packets = options.investigate_packets as _;
(*self).fullbin = options.fullbin as _;
(*self).nosync = options.nosync as _;
(*self).hauppauge_mode = options.hauppauge_mode as _;
(*self).wtvconvertfix = options.wtvconvertfix as _;
(*self).wtvmpeg2 = options.wtvmpeg2 as _;
(*self).auto_myth = if let Some(auto_myth) = options.auto_myth {
self.messages_target = options.messages_target as _;
self.timestamp_map = options.timestamp_map as _;
self.dolevdist = options.dolevdist.into();
self.levdistmincnt = options.levdistmincnt as _;
self.levdistmaxpct = options.levdistmaxpct as _;
self.investigate_packets = options.investigate_packets as _;
self.fullbin = options.fullbin as _;
self.nosync = options.nosync as _;
self.hauppauge_mode = options.hauppauge_mode as _;
self.wtvconvertfix = options.wtvconvertfix as _;
self.wtvmpeg2 = options.wtvmpeg2 as _;
self.auto_myth = if let Some(auto_myth) = options.auto_myth {
auto_myth as _
} else {
2
};
(*self).mp4vidtrack = options.mp4vidtrack as _;
(*self).extract_chapters = options.extract_chapters as _;
(*self).usepicorder = options.usepicorder as _;
(*self).xmltv = options.xmltv as _;
(*self).xmltvliveinterval = options.xmltvliveinterval.seconds() as _;
(*self).xmltvoutputinterval = options.xmltvoutputinterval.seconds() as _;
(*self).xmltvonlycurrent = options.xmltvonlycurrent.into();
(*self).keep_output_closed = options.keep_output_closed as _;
(*self).force_flush = options.force_flush as _;
(*self).append_mode = options.append_mode as _;
(*self).ucla = options.ucla as _;
(*self).tickertext = options.tickertext as _;
(*self).hardsubx = options.hardsubx as _;
(*self).hardsubx_and_common = options.hardsubx_and_common as _;
self.mp4vidtrack = options.mp4vidtrack as _;
self.extract_chapters = options.extract_chapters as _;
self.usepicorder = options.usepicorder as _;
self.xmltv = options.xmltv as _;
self.xmltvliveinterval = options.xmltvliveinterval.seconds() as _;
self.xmltvoutputinterval = options.xmltvoutputinterval.seconds() as _;
self.xmltvonlycurrent = options.xmltvonlycurrent.into();
self.keep_output_closed = options.keep_output_closed as _;
self.force_flush = options.force_flush as _;
self.append_mode = options.append_mode as _;
self.ucla = options.ucla as _;
self.tickertext = options.tickertext as _;
self.hardsubx = options.hardsubx as _;
self.hardsubx_and_common = options.hardsubx_and_common as _;
if let Some(dvblang) = options.dvblang {
(*self).dvblang = string_to_c_char(dvblang.to_ctype().as_str());
self.dvblang = string_to_c_char(dvblang.to_ctype().as_str());
}
if options.ocrlang.try_exists().unwrap_or_default() {
(*self).ocrlang = string_to_c_char(options.ocrlang.to_str().unwrap());
self.ocrlang = string_to_c_char(options.ocrlang.to_str().unwrap());
}
(*self).ocr_oem = options.ocr_oem as _;
(*self).ocr_quantmode = options.ocr_quantmode as _;
self.ocr_oem = options.ocr_oem as _;
self.ocr_quantmode = options.ocr_quantmode as _;
if let Some(mkvlang) = options.mkvlang {
(*self).mkvlang = string_to_c_char(mkvlang.to_ctype().as_str());
}
(*self).analyze_video_stream = options.analyze_video_stream as _;
(*self).hardsubx_ocr_mode = options.hardsubx_ocr_mode.to_ctype();
(*self).hardsubx_subcolor = options.hardsubx_hue.to_ctype();
(*self).hardsubx_min_sub_duration = options.hardsubx_min_sub_duration.seconds() as _;
(*self).hardsubx_detect_italics = options.hardsubx_detect_italics as _;
(*self).hardsubx_conf_thresh = options.hardsubx_conf_thresh as _;
(*self).hardsubx_hue = options.hardsubx_hue.get_hue() as _;
(*self).hardsubx_lum_thresh = options.hardsubx_lum_thresh as _;
(*self).transcript_settings = options.transcript_settings.to_ctype();
(*self).date_format = options.date_format.to_ctype();
(*self).write_format_rewritten = options.write_format_rewritten as _;
(*self).use_ass_instead_of_ssa = options.use_ass_instead_of_ssa as _;
(*self).use_webvtt_styling = options.use_webvtt_styling as _;
(*self).debug_mask = options.debug_mask.normal_mask().bits() as _;
(*self).debug_mask_on_debug = options.debug_mask.debug_mask().bits() as _;
self.mkvlang = string_to_c_char(mkvlang.to_ctype().as_str());
}
self.analyze_video_stream = options.analyze_video_stream as _;
self.hardsubx_ocr_mode = options.hardsubx_ocr_mode.to_ctype();
self.hardsubx_subcolor = options.hardsubx_hue.to_ctype();
self.hardsubx_min_sub_duration = options.hardsubx_min_sub_duration.seconds() as _;
self.hardsubx_detect_italics = options.hardsubx_detect_italics as _;
self.hardsubx_conf_thresh = options.hardsubx_conf_thresh as _;
self.hardsubx_hue = options.hardsubx_hue.get_hue() as _;
self.hardsubx_lum_thresh = options.hardsubx_lum_thresh as _;
self.transcript_settings = options.transcript_settings.to_ctype();
self.date_format = options.date_format.to_ctype();
self.write_format_rewritten = options.write_format_rewritten as _;
self.use_ass_instead_of_ssa = options.use_ass_instead_of_ssa as _;
self.use_webvtt_styling = options.use_webvtt_styling as _;
self.debug_mask = options.debug_mask.normal_mask().bits() as _;
self.debug_mask_on_debug = options.debug_mask.debug_mask().bits() as _;
if options.udpsrc.is_some() {
(*self).udpsrc = string_to_c_char(&options.udpsrc.clone().unwrap());
self.udpsrc = string_to_c_char(&options.udpsrc.clone().unwrap());
}
if options.udpaddr.is_some() {
(*self).udpaddr = string_to_c_char(&options.udpaddr.clone().unwrap());
self.udpaddr = string_to_c_char(&options.udpaddr.clone().unwrap());
}
(*self).udpport = options.udpport as _;
self.udpport = options.udpport as _;
if options.tcpport.is_some() {
(*self).tcpport = string_to_c_char(&options.tcpport.unwrap().to_string());
self.tcpport = string_to_c_char(&options.tcpport.unwrap().to_string());
}
if options.tcp_password.is_some() {
(*self).tcp_password = string_to_c_char(&options.tcp_password.clone().unwrap());
self.tcp_password = string_to_c_char(&options.tcp_password.clone().unwrap());
}
if options.tcp_desc.is_some() {
(*self).tcp_desc = string_to_c_char(&options.tcp_desc.clone().unwrap());
self.tcp_desc = string_to_c_char(&options.tcp_desc.clone().unwrap());
}
if options.srv_addr.is_some() {
(*self).srv_addr = string_to_c_char(&options.srv_addr.clone().unwrap());
self.srv_addr = string_to_c_char(&options.srv_addr.clone().unwrap());
}
if options.srv_port.is_some() {
(*self).srv_port = string_to_c_char(&options.srv_port.unwrap().to_string());
self.srv_port = string_to_c_char(&options.srv_port.unwrap().to_string());
}
(*self).noautotimeref = options.noautotimeref as _;
(*self).input_source = options.input_source as _;
self.noautotimeref = options.noautotimeref as _;
self.input_source = options.input_source as _;
if options.output_filename.is_some() {
(*self).output_filename = string_to_c_char(&options.output_filename.clone().unwrap());
self.output_filename = string_to_c_char(&options.output_filename.clone().unwrap());
}
if options.inputfile.is_some() {
(*self).inputfile = string_to_c_chars(options.inputfile.clone().unwrap());
(*self).num_input_files =
options.inputfile.iter().filter(|s| !s.is_empty()).count() as _;
}
(*self).demux_cfg = options.demux_cfg.to_ctype();
(*self).enc_cfg = options.enc_cfg.to_ctype();
(*self).subs_delay = options.subs_delay.millis();
(*self).cc_to_stdout = options.cc_to_stdout as _;
(*self).pes_header_to_stdout = options.pes_header_to_stdout as _;
(*self).ignore_pts_jumps = options.ignore_pts_jumps as _;
(*self).multiprogram = options.multiprogram as _;
(*self).out_interval = options.out_interval;
(*self).segment_on_key_frames_only = options.segment_on_key_frames_only as _;
self.inputfile = string_to_c_chars(options.inputfile.clone().unwrap());
self.num_input_files = options.inputfile.iter().filter(|s| !s.is_empty()).count() as _;
}
self.demux_cfg = options.demux_cfg.to_ctype();
self.enc_cfg = options.enc_cfg.to_ctype();
self.subs_delay = options.subs_delay.millis();
self.cc_to_stdout = options.cc_to_stdout as _;
self.pes_header_to_stdout = options.pes_header_to_stdout as _;
self.ignore_pts_jumps = options.ignore_pts_jumps as _;
self.multiprogram = options.multiprogram as _;
self.out_interval = options.out_interval;
self.segment_on_key_frames_only = options.segment_on_key_frames_only as _;
#[cfg(feature = "with_libcurl")]
{
if options.curlposturl.is_some() {
(*self).curlposturl =
self.curlposturl =
string_to_c_char(&options.curlposturl.as_ref().unwrap_or_default().as_str());
}
}
#[cfg(feature = "enable_sharing")]
{
(*self).sharing_enabled = options.sharing_enabled as _;
self.sharing_enabled = options.sharing_enabled as _;
if options.sharing_url.is_some() {
(*self).sharing_url =
self.sharing_url =
string_to_c_char(&options.sharing_url.as_ref().unwrap().as_str());
}
(*self).translate_enabled = options.translate_enabled as _;
self.translate_enabled = options.translate_enabled as _;
if options.translate_langs.is_some() {
(*self).translate_langs = string_to_c_char(&options.translate_langs.unwrap());
self.translate_langs = string_to_c_char(&options.translate_langs.unwrap());
}
if options.translate_key.is_some() {
(*self).translate_key = string_to_c_char(&options.translate_key.unwrap());
self.translate_key = string_to_c_char(&options.translate_key.unwrap());
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/rust/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,20 @@ impl PartialEq for dtvcc_symbol {

#[cfg(test)]
mod test {
use lib_ccxr::util::log::{set_logger, CCExtractorLogger, DebugMessageMask, OutputTarget};

use crate::utils::get_zero_allocated_obj;

use super::*;

#[test]
fn test_process_cc_data() {
set_logger(CCExtractorLogger::new(
OutputTarget::Stdout,
DebugMessageMask::new(DebugMessageFlag::VERBOSE, DebugMessageFlag::VERBOSE),
false,
))
.ok();
let mut dtvcc_ctx = get_zero_allocated_obj::<dtvcc_ctx>();
let mut decoder = Dtvcc::new(&mut dtvcc_ctx);

Expand Down Expand Up @@ -286,6 +294,12 @@ mod test {

#[test]
fn test_process_current_packet() {
set_logger(CCExtractorLogger::new(
OutputTarget::Stdout,
DebugMessageMask::new(DebugMessageFlag::VERBOSE, DebugMessageFlag::VERBOSE),
false,
))
.ok();
let mut dtvcc_ctx = get_zero_allocated_obj::<dtvcc_ctx>();
let mut decoder = Dtvcc::new(&mut dtvcc_ctx);

Expand Down
1 change: 0 additions & 1 deletion src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ extern "C" {
/// Parse parameters from argv and argc
#[no_mangle]
pub unsafe extern "C" fn ccxr_parse_parameters(argc: c_int, argv: *mut *mut c_char) -> c_int {
ccxr_init_logger();
// Convert argv to Vec<String> and pass it to parse_parameters
let args = std::slice::from_raw_parts(argv, argc as usize)
.iter()
Expand Down
17 changes: 11 additions & 6 deletions src/rust/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ use time::OffsetDateTime;

use crate::args::CCXCodec;
use crate::args::{self, InFormat};
use crate::{usercolor_rgb, FILEBUFFERSIZE};

cfg_if! {
if #[cfg(test)] {
use crate::parser::tests::{set_binary_mode, MPEG_CLOCK_FREQ};
use crate::parser::tests::{set_binary_mode, MPEG_CLOCK_FREQ, usercolor_rgb, FILEBUFFERSIZE};
} else {
use crate::{set_binary_mode, MPEG_CLOCK_FREQ};
use crate::{set_binary_mode, MPEG_CLOCK_FREQ, usercolor_rgb, FILEBUFFERSIZE};
}
}

Expand Down Expand Up @@ -57,6 +56,12 @@ fn set_usercolor_rgb(color: &str) {
}
}

fn set_mpeg_clock_freq(freq: i32) {
unsafe {
MPEG_CLOCK_FREQ = freq as _;
}
}

fn atol(bufsize: &str) -> i32 {
let mut val = bufsize[0..bufsize.len() - 1].parse::<i32>().unwrap();
let size = bufsize
Expand Down Expand Up @@ -869,9 +874,7 @@ impl OptionsExt for Options {
}

if args.mpeg90090 {
unsafe {
MPEG_CLOCK_FREQ = 90090;
}
set_mpeg_clock_freq(90090);
}
if args.no_scte20 {
self.noscte20 = true;
Expand Down Expand Up @@ -1657,6 +1660,8 @@ pub mod tests {
#[no_mangle]
pub unsafe extern "C" fn set_binary_mode() {}
pub static mut MPEG_CLOCK_FREQ: u64 = 0;
pub static mut FILEBUFFERSIZE: i32 = 0;
pub static mut usercolor_rgb: [i32; 8] = [0; 8];

fn parse_args(args: &[&str]) -> (Options, TeletextConfig) {
let mut common_args = vec!["./ccextractor", "input_file"];
Expand Down

0 comments on commit 8e03558

Please sign in to comment.