Skip to content

Commit f6d6cbd

Browse files
committed
Windows failing tests
1 parent 90d8c78 commit f6d6cbd

File tree

6 files changed

+69
-23
lines changed

6 files changed

+69
-23
lines changed

src/rust/lib_ccxr/src/activity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
#![allow(static_mut_refs)] // Temporary fix for mutable static variable
12
use std::io;
23
use std::io::Write;
34

45
use crate::common::Options;
56
use std::sync::atomic::{AtomicUsize, Ordering};
6-
77
pub static mut NET_ACTIVITY_GUI: AtomicUsize = AtomicUsize::new(0);
88

99
pub trait ActivityExt {

src/rust/lib_ccxr/src/demuxer/demux.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(non_camel_case_types)]
22
#![allow(unexpected_cfgs)]
33
#![allow(unused_mut)]
4+
#![allow(clippy::needless_lifetimes)]
45

56
use crate::activity::ActivityExt;
67
use crate::common::{
@@ -851,7 +852,7 @@ impl<'a> CcxDemuxer<'a> {
851852
}
852853

853854
/// This function returns the file size for a given demuxer.
854-
/// Translated from the C function `ccx_demuxer_get_file_size`.
855+
/// C function `ccx_demuxer_get_file_size`.
855856
/// LLONG is `int64_t`, so we use `i64` in Rust.
856857
pub fn ccx_demuxer_get_file_size(ctx: &mut CcxDemuxer) -> i64 {
857858
// Get the file descriptor from ctx.
@@ -873,7 +874,10 @@ pub fn ccx_demuxer_get_file_size(ctx: &mut CcxDemuxer) -> i64 {
873874
Ok(pos) => pos,
874875
Err(_) => {
875876
// Return the fd back and then -1.
877+
#[cfg(unix)]
876878
let _ = file.into_raw_fd();
879+
#[cfg(windows)]
880+
let _ = file.into_raw_handle();
877881
return -1;
878882
}
879883
};
@@ -882,7 +886,10 @@ pub fn ccx_demuxer_get_file_size(ctx: &mut CcxDemuxer) -> i64 {
882886
let length = match file.seek(SeekFrom::End(0)) {
883887
Ok(pos) => pos,
884888
Err(_) => {
889+
#[cfg(unix)]
885890
let _ = file.into_raw_fd();
891+
#[cfg(windows)]
892+
let _ = file.into_raw_handle();
886893
return -1;
887894
}
888895
};
@@ -896,24 +903,30 @@ pub fn ccx_demuxer_get_file_size(ctx: &mut CcxDemuxer) -> i64 {
896903
let ret = match file.seek(SeekFrom::Start(current)) {
897904
Ok(pos) => pos,
898905
Err(_) => {
906+
#[cfg(unix)]
899907
let _ = file.into_raw_fd();
908+
#[cfg(windows)]
909+
let _ = file.into_raw_handle();
900910
return -1;
901911
}
902912
};
903913

904914
// Return the fd back to its original owner.
915+
#[cfg(unix)]
905916
let _ = file.into_raw_fd();
917+
#[cfg(windows)]
918+
let _ = file.into_raw_handle();
906919
length as i64
907920
}
908921

909-
/// Translated from the C function `ccx_demuxer_get_stream_mode`.
922+
/// C function `ccx_demuxer_get_stream_mode`.
910923
/// Returns the current stream mode.
911924
pub fn ccx_demuxer_get_stream_mode(ctx: &CcxDemuxer) -> i32 {
912925
// return ctx->stream_mode;
913926
ctx.stream_mode as i32
914927
}
915928

916-
/// Translated from the C function `ccx_demuxer_print_cfg`.
929+
/// C function `ccx_demuxer_print_cfg`.
917930
/// Prints the current `auto_stream` mode for the demuxer.
918931
// Note: `#ifdef WTV_DEBUG` becomes `#[cfg(feature = "wtv_debug")]` in Rust.
919932
pub fn ccx_demuxer_print_cfg(ctx: &CcxDemuxer) {
@@ -973,7 +986,7 @@ fn y_n(count: i32) -> &'static str {
973986
}
974987
}
975988

976-
/// Translated version of the C `print_file_report` function, preserving structure
989+
/// C `print_file_report` function, preserving structure
977990
/// and replacing `#ifdef` with `#[cfg(feature = "wtv_debug")]`.
978991
/// Uses `printf` from libc.
979992
pub fn print_file_report(ctx: &mut LibCcxCtx) {
@@ -1089,9 +1102,9 @@ pub fn print_file_report(ctx: &mut LibCcxCtx) {
10891102
// dec_ctx = update_decoder_list_cinfo(ctx, best_info); // TODO
10901103
if (*dec_ctx).in_bufferdatatype == BufferdataType::Pes
10911104
&& (demux_ctx.stream_mode == StreamMode::Transport
1092-
|| demux_ctx.stream_mode == StreamMode::Program
1093-
|| demux_ctx.stream_mode == StreamMode::Asf
1094-
|| demux_ctx.stream_mode == StreamMode::Wtv)
1105+
|| demux_ctx.stream_mode == StreamMode::Program
1106+
|| demux_ctx.stream_mode == StreamMode::Asf
1107+
|| demux_ctx.stream_mode == StreamMode::Wtv)
10951108
{
10961109
println!("Width: {}", (*dec_ctx).current_hor_size);
10971110
println!("Height: {}", (*dec_ctx).current_vert_size);
@@ -1120,7 +1133,7 @@ pub fn print_file_report(ctx: &mut LibCcxCtx) {
11201133
ptr::write_bytes(&mut ctx.freport as *mut FileReport, 0, 1);
11211134
}
11221135
}
1123-
1136+
#[allow(clippy::manual_c_str_literals)]
11241137
pub fn get_desc_placeholder(_index: usize) -> *const i8 {
11251138
b"Unknown\0".as_ptr() as *const i8
11261139
}
@@ -1259,7 +1272,7 @@ mod tests {
12591272
DebugMessageMask::new(DebugMessageFlag::VERBOSE, DebugMessageFlag::VERBOSE),
12601273
false,
12611274
))
1262-
.ok();
1275+
.ok();
12631276
});
12641277
}
12651278
#[test]

src/rust/lib_ccxr/src/demuxer/lib_ccx.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::needless_lifetimes)]
12
use crate::common::{Decoder608Report, DecoderDtvccReport, OutputFormat};
23
use crate::demuxer::demux::{CcxDemuxer, DecodersCommonSettings, EITProgram, HList, PSI_buffer};
34

src/rust/lib_ccxr/src/demuxer/stream_functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub fn detect_myth(ctx: &mut CcxDemuxer) -> i32 {
351351
0
352352
}
353353

354-
/// Translated version of the C `isValidMP4Box` function with comments preserved.
354+
/// C `isValidMP4Box` function
355355
pub fn is_valid_mp4_box(
356356
buffer: &[u8],
357357
position: usize,

src/rust/lib_ccxr/src/file_functions/file.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![allow(unexpected_cfgs)]
2-
#![allow(unused_mut)]
1+
#![allow(unexpected_cfgs)] // Temporary
2+
#![allow(unused_mut)] // Temporary
3+
#![allow(static_mut_refs)] // Temporary fix for mutable static variable
34

45
use crate::activity::{update_net_activity_gui, ActivityExt, NET_ACTIVITY_GUI};
56
use crate::common::{DataSource, Options};
@@ -45,18 +46,31 @@ pub fn position_sanity_check(ctx: &mut CcxDemuxer) {
4546

4647
let fd = ctx.infd;
4748
// Convert raw fd to a File without taking ownership
49+
#[cfg(unix)]
4850
let mut file = unsafe { File::from_raw_fd(fd) };
51+
#[cfg(windows)]
52+
let mut file = unsafe { File::from_raw_handle(fd as *mut _) };
4953
let realpos_result = file.seek(SeekFrom::Current(0));
5054
let realpos = match realpos_result {
5155
Ok(pos) => pos as i64, // Convert to i64 to match C's LLONG
5256
Err(_) => {
5357
// Return the fd to avoid closing it
54-
let _ = file.into_raw_fd();
58+
#[cfg(unix)]
59+
{
60+
let _ = file.into_raw_fd();
61+
}
62+
#[cfg(windows)]
63+
{
64+
let _ = file.into_raw_handle();
65+
}
5566
return;
5667
}
5768
};
5869
// Return the fd to avoid closing it
70+
#[cfg(unix)]
5971
let _ = file.into_raw_fd();
72+
#[cfg(windows)]
73+
let _ = file.into_raw_handle();
6074

6175
let expected_pos = ctx.past - ctx.filebuffer_pos as i64 + ctx.bytesinbuffer as i64;
6276

@@ -707,7 +721,10 @@ mod tests {
707721
// Create temp file
708722
let mut file = tempfile().unwrap();
709723
file.write_all(b"test data").unwrap();
724+
#[cfg(unix)]
710725
let fd = file.into_raw_fd(); // Now owns the fd
726+
#[cfg(windows)]
727+
let fd = file.into_raw_handle(); // Now owns the handle
711728

712729
// SAFETY: Initialize directly on heap without stack intermediate
713730
let mut ctx = Box::new(CcxDemuxer::default());
@@ -722,11 +739,17 @@ mod tests {
722739
// Example for one array - repeat for others:
723740
ctx.startbytes = vec![0u8; STARTBYTESLENGTH];
724741
// Set file position
742+
#[cfg(unix)]
725743
let mut file = unsafe { File::from_raw_fd(fd) };
744+
#[cfg(windows)]
745+
let mut file = unsafe { File::from_raw_handle(fd as *mut _) };
726746
file.seek(SeekFrom::Start(130)).unwrap();
727747

728748
// Prevent double-closing when 'file' drops
749+
#[cfg(unix)]
729750
let _ = file.into_raw_fd();
751+
#[cfg(windows)]
752+
let _ = file.into_raw_handle();
730753

731754
// Run test
732755
position_sanity_check(&mut ctx);
@@ -900,7 +923,14 @@ mod tests {
900923
.expect("Unable to seek to start");
901924
// Get the file descriptor. Ensure the file stays open.
902925
let file = tmp.reopen().expect("Unable to reopen temp file");
903-
file.into_raw_fd()
926+
#[cfg(unix)]
927+
{
928+
file.into_raw_fd()
929+
}
930+
#[cfg(windows)]
931+
{
932+
file.into_raw_handle() as i32
933+
}
904934
}
905935

906936
// Dummy allocation for filebuffer.

src/rust/lib_ccxr/src/gxf_demuxer/gxf.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,8 +1315,7 @@ pub unsafe fn parse_ad_field(demux: &mut CcxDemuxer, mut len: i32, data: &mut De
13151315
ret
13161316
}
13171317

1318-
/**
1319-
* @param vid_format following format are supported to set valid timebase
1318+
/* * @param vid_format following format are supported to set valid timebase
13201319
* in demuxer data
13211320
* value | Meaning
13221321
*=====================================
@@ -1346,7 +1345,6 @@ pub unsafe fn parse_ad_field(demux: &mut CcxDemuxer, mut len: i32, data: &mut De
13461345
* data len may be zero, while setting timebase we don not care about
13471346
* actual data
13481347
*/
1349-
13501348
pub fn set_data_timebase(vid_format: i32, data: &mut DemuxerData) {
13511349
dbg!("LOG: Format Video {}", vid_format);
13521350

@@ -1554,11 +1552,8 @@ pub unsafe fn parse_ad_packet(demux: &mut CcxDemuxer, len: i32, data: &mut Demux
15541552
* | 4:7 | Not Used MUST be 0 |
15551553
* +-----------------------------+-----------------------------+
15561554
*/
1557-
/// Translated version of the C `set_mpeg_frame_desc` function.
1558-
1555+
/// C `set_mpeg_frame_desc` function.
15591556
pub fn set_mpeg_frame_desc(vid_track: &mut CcxGxfVideoTrack, mpeg_frame_desc_flag: u8) {
1560-
// vid_track.p_code = MpegPictureCoding::from(mpeg_frame_desc_flag & 0x03);
1561-
// vid_track.p_struct = MpegPictureStruct::from((mpeg_frame_desc_flag >> 2) & 0x03);
15621557
vid_track.p_code = MpegPictureCoding::try_from(mpeg_frame_desc_flag & 0x03).unwrap();
15631558
vid_track.p_struct = MpegPictureStruct::try_from((mpeg_frame_desc_flag >> 2) & 0x03).unwrap();
15641559
}
@@ -2008,7 +2003,14 @@ mod tests {
20082003
.expect("Unable to seek to start");
20092004
// Get the file descriptor. Ensure the file stays open.
20102005
let file = tmp.reopen().expect("Unable to reopen temp file");
2011-
file.into_raw_fd()
2006+
#[cfg(unix)]
2007+
{
2008+
file.into_raw_fd()
2009+
}
2010+
#[cfg(windows)]
2011+
{
2012+
file.into_raw_handle() as i32
2013+
}
20122014
}
20132015
/// Create a dummy CcxDemuxer with a filebuffer containing `header_data`.
20142016
fn create_ccx_demuxer_with_header(header_data: &[u8]) -> CcxDemuxer<'static> {

0 commit comments

Comments
 (0)