From 99566ebd3215b4a6a53b0d58a6dd98d1a17ca9f6 Mon Sep 17 00:00:00 2001 From: Ar1es-XD <247913128+Ar1es-XD@users.noreply.github.com> Date: Thu, 6 Aug 2026 01:36:34 +0530 Subject: [PATCH] networking: add NETWORKING_DEBUG CMake opt-in and route errors to stderr - Add NETWORKING_DEBUG CMake option to build flags to replace integer toggle. - Route networking error messages to stderr via fprintf(stderr, ...). - Fix formatting specifiers for size_t variables to avoid compiler warnings/errors on 64-bit platforms. - Fix clippy compiler warnings/errors in Rust source code to pass CI checks. --- src/CMakeLists.txt | 6 ++++++ src/lib_ccx/networking.c | 14 +++++++++----- src/rust/src/demuxer/scc.rs | 4 ++-- src/rust/src/demuxer/stream_functions.rs | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aadef346c..6071501e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,7 @@ option (WITH_FFMPEG "Build using FFmpeg demuxer and decoder" OFF) option (WITH_OCR "Build with OCR (Optical Character Recognition) feature" OFF) option (WITH_HARDSUBX "Build with support for burned-in subtitles" OFF) option (VBI_DEBUG "Enable VBI decoder debug output" OFF) +option (NETWORKING_DEBUG "Enable networking debug output" OFF) # HARDSUBX requires OCR (tesseract/leptonica) and FFmpeg if (WITH_HARDSUBX) @@ -164,6 +165,11 @@ if (VBI_DEBUG) add_definitions(-DVBI_DEBUG) message(STATUS "VBI debug output enabled") endif (VBI_DEBUG) + +if (NETWORKING_DEBUG) + add_definitions(-DNETWORKING_DEBUG) + message(STATUS "Networking debug output enabled") +endif (NETWORKING_DEBUG) add_subdirectory (lib_ccx) aux_source_directory(${PROJECT_SOURCE_DIR} SOURCEFILE) diff --git a/src/lib_ccx/networking.c b/src/lib_ccx/networking.c index bd0337daf..62ecc84bb 100644 --- a/src/lib_ccx/networking.c +++ b/src/lib_ccx/networking.c @@ -8,7 +8,11 @@ #include #include +#ifdef NETWORKING_DEBUG +#define DEBUG_OUT 1 +#else #define DEBUG_OUT 0 +#endif /* Protocol constants: */ #define INT_LEN 10 @@ -144,14 +148,14 @@ void net_send_header(const unsigned char *data, size_t len) assert(srv_sd > 0); #if DEBUG_OUT - fprintf(stderr, "Sending header (len = %u): \n", len); + fprintf(stderr, "Sending header (len = %zu): \n", len); fprintf(stderr, "File created by %02X version %02X%02X\n", data[3], data[4], data[5]); fprintf(stderr, "File format revision: %02X%02X\n", data[6], data[7]); #endif if (write_block(srv_sd, BIN_HEADER, data, len) <= 0) { - printf("Can't send BIN header\n"); + fprintf(stderr, "Can't send BIN header\n"); return; } @@ -178,7 +182,7 @@ int net_send_cc(const unsigned char *data, int len, void *private_data, struct c if (write_block(srv_sd, BIN_DATA, data, len) <= 0) { - printf("Can't send BIN data\n"); + fprintf(stderr, "Can't send BIN data\n"); return -1; } @@ -238,7 +242,7 @@ void net_check_conn() { if (write_block(srv_sd, PING, NULL, 0) < 0) { - printf("Unable to send data\n"); + fprintf(stderr, "Unable to send data\n"); exit(EXIT_FAILURE); } @@ -325,7 +329,7 @@ void net_send_epg( end += c; #if DEBUG_OUT - fprintf(stderr, "[C] Sending EPG: %u bytes\n", len); + fprintf(stderr, "[C] Sending EPG: %zu bytes\n", len); #endif if (write_block(srv_sd, EPG_DATA, epg, len) <= 0) diff --git a/src/rust/src/demuxer/scc.rs b/src/rust/src/demuxer/scc.rs index debedf5fd..afdddf440 100644 --- a/src/rust/src/demuxer/scc.rs +++ b/src/rust/src/demuxer/scc.rs @@ -292,11 +292,11 @@ mod tests { // 24fps - 24 frames = 1 second let time_24 = parse_smpte_timecode("00:00:00:24", SccFrameRate::Fps24).unwrap(); - assert!(time_24 >= 999 && time_24 <= 1001); // Approximately 1 second + assert!((999..=1001).contains(&time_24)); // Approximately 1 second // 30fps - 30 frames = 1 second let time_30 = parse_smpte_timecode("00:00:00:30", SccFrameRate::Fps30).unwrap(); - assert!(time_30 >= 999 && time_30 <= 1001); // Approximately 1 second + assert!((999..=1001).contains(&time_30)); // Approximately 1 second // Drop-frame separator (semicolon) assert_eq!( diff --git a/src/rust/src/demuxer/stream_functions.rs b/src/rust/src/demuxer/stream_functions.rs index 59422725e..e561d1552 100644 --- a/src/rust/src/demuxer/stream_functions.rs +++ b/src/rust/src/demuxer/stream_functions.rs @@ -392,7 +392,7 @@ pub fn detect_myth(ctx: &mut CcxDemuxer) -> i32 { uc.copy_from_slice(&ctx.startbytes[..3]); for &byte in &ctx.startbytes[3..ctx.startbytes_avail as usize] { - if (uc == [b't', b'v', b'0']) || (uc == [b'T', b'V', b'0']) { + if (uc == *b"tv0") || (uc == *b"TV0") { vbi_blocks += 1; }