Skip to content

Commit faa225b

Browse files
committed
fixing format issues
1 parent 3a905d7 commit faa225b

File tree

7 files changed

+109
-46
lines changed

7 files changed

+109
-46
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,8 @@ impl<'a> CcxDemuxer<'a> {
817817
if matches!(
818818
self.stream_mode,
819819
StreamMode::ElementaryOrNotFound | StreamMode::Program
820-
) && detect_myth(self) != 0 {
820+
) && detect_myth(self) != 0
821+
{
821822
self.stream_mode = StreamMode::Myth;
822823
}
823824
}
@@ -1064,9 +1065,9 @@ pub fn print_file_report(ctx: &mut LibCcxCtx) {
10641065
// dec_ctx = update_decoder_list_cinfo(ctx, best_info); // TODO
10651066
if (*dec_ctx).in_bufferdatatype == BufferdataType::Pes
10661067
&& (demux_ctx.stream_mode == StreamMode::Transport
1067-
|| demux_ctx.stream_mode == StreamMode::Program
1068-
|| demux_ctx.stream_mode == StreamMode::Asf
1069-
|| demux_ctx.stream_mode == StreamMode::Wtv)
1068+
|| demux_ctx.stream_mode == StreamMode::Program
1069+
|| demux_ctx.stream_mode == StreamMode::Asf
1070+
|| demux_ctx.stream_mode == StreamMode::Wtv)
10701071
{
10711072
println!("Width: {}", (*dec_ctx).current_hor_size);
10721073
println!("Height: {}", (*dec_ctx).current_vert_size);
@@ -1218,12 +1219,12 @@ mod tests {
12181219
use crate::util::log::{
12191220
set_logger, CCExtractorLogger, DebugMessageFlag, DebugMessageMask, OutputTarget,
12201221
};
1222+
use serial_test::serial;
12211223
use std::fs::OpenOptions;
12221224
use std::io::Write;
12231225
use std::os::fd::AsRawFd;
12241226
use std::slice;
12251227
use std::sync::Once;
1226-
use serial_test::serial;
12271228
use tempfile::NamedTempFile;
12281229
static INIT: Once = Once::new();
12291230

@@ -1234,7 +1235,7 @@ mod tests {
12341235
DebugMessageMask::new(DebugMessageFlag::VERBOSE, DebugMessageFlag::VERBOSE),
12351236
false,
12361237
))
1237-
.ok();
1238+
.ok();
12381239
});
12391240
}
12401241
#[test]
@@ -1729,7 +1730,8 @@ mod tests {
17291730
.expect("Failed to open file");
17301731
// Move the file cursor to a nonzero position.
17311732
file.seek(SeekFrom::Start(5)).expect("Failed to seek");
1732-
let pos_before = file.stream_position()
1733+
let pos_before = file
1734+
.stream_position()
17331735
.expect("Failed to get current position");
17341736

17351737
// Create a demuxer with the same file descriptor.
@@ -1741,7 +1743,8 @@ mod tests {
17411743
let _ = get_filesize(&CcxDemuxer::default(), &mut demuxer);
17421744

17431745
// After calling the function, the file position should be restored.
1744-
let pos_after = file.stream_position()
1746+
let pos_after = file
1747+
.stream_position()
17451748
.expect("Failed to get current position");
17461749
assert_eq!(
17471750
pos_before, pos_after,

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ pub unsafe fn detect_stream_type(ctx: &mut CcxDemuxer) {
102102
}
103103

104104
// Check for ASF magic bytes
105-
if ctx.startbytes_avail >= 4 && ctx.startbytes[0] == 0x30
105+
if ctx.startbytes_avail >= 4
106+
&& ctx.startbytes[0] == 0x30
106107
&& ctx.startbytes[1] == 0x26
107-
&& ctx.startbytes[2] == 0xb2 && ctx.startbytes[3] == 0x75 {
108+
&& ctx.startbytes[2] == 0xb2
109+
&& ctx.startbytes[3] == 0x75
110+
{
108111
ctx.stream_mode = StreamMode::Asf;
109112
}
110113

@@ -138,9 +141,13 @@ pub unsafe fn detect_stream_type(ctx: &mut CcxDemuxer) {
138141
}
139142

140143
// WTV check
141-
if ctx.stream_mode == StreamMode::ElementaryOrNotFound && ctx.startbytes_avail >= 4 && ctx.startbytes[0] == 0xb7
144+
if ctx.stream_mode == StreamMode::ElementaryOrNotFound
145+
&& ctx.startbytes_avail >= 4
146+
&& ctx.startbytes[0] == 0xb7
142147
&& ctx.startbytes[1] == 0xd8
143-
&& ctx.startbytes[2] == 0x00 && ctx.startbytes[3] == 0x20 {
148+
&& ctx.startbytes[2] == 0x00
149+
&& ctx.startbytes[3] == 0x20
150+
{
144151
ctx.stream_mode = StreamMode::Wtv;
145152
}
146153

@@ -163,16 +170,19 @@ pub unsafe fn detect_stream_type(ctx: &mut CcxDemuxer) {
163170
}
164171

165172
// Check for CCExtractor magic bytes
166-
if ctx.stream_mode == StreamMode::ElementaryOrNotFound && ctx.startbytes_avail >= 11 && ctx.startbytes[0] == 0xCC
173+
if ctx.stream_mode == StreamMode::ElementaryOrNotFound
174+
&& ctx.startbytes_avail >= 11
175+
&& ctx.startbytes[0] == 0xCC
167176
&& ctx.startbytes[1] == 0xCC
168177
&& ctx.startbytes[2] == 0xED
169178
&& ctx.startbytes[8] == 0
170-
&& ctx.startbytes[9] == 0 && ctx.startbytes[10] == 0 {
179+
&& ctx.startbytes[9] == 0
180+
&& ctx.startbytes[10] == 0
181+
{
171182
ctx.stream_mode = StreamMode::Rcwt;
172183
}
173184
// MP4 check. "Still not found" or we want file reports.
174-
if (ctx.stream_mode == StreamMode::ElementaryOrNotFound
175-
|| ccx_options.print_file_reports)
185+
if (ctx.stream_mode == StreamMode::ElementaryOrNotFound || ccx_options.print_file_reports)
176186
&& ctx.startbytes_avail >= 4
177187
{
178188
let mut idx = 0usize;
@@ -368,9 +378,9 @@ pub fn is_valid_mp4_box(
368378
// If the box type is "moov", check if it contains a valid movie header (mvhd)
369379
if idx == 2
370380
&& !(buffer[position + 12] == b'm'
371-
&& buffer[position + 13] == b'v'
372-
&& buffer[position + 14] == b'h'
373-
&& buffer[position + 15] == b'd')
381+
&& buffer[position + 13] == b'v'
382+
&& buffer[position + 14] == b'h'
383+
&& buffer[position + 15] == b'd')
374384
{
375385
// If "moov" doesn't have "mvhd", skip it.
376386
continue;

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ pub unsafe fn sleepandchecktimeout(start: u64) {
9393
}
9494
return;
9595
}
96-
if ccx_options.live_stream.unwrap().seconds() != 0 && ccx_options.live_stream.unwrap().seconds() == -1 {
96+
if ccx_options.live_stream.unwrap().seconds() != 0
97+
&& ccx_options.live_stream.unwrap().seconds() == -1
98+
{
9799
// Sleep without timeout check
98100
sleep_secs(1);
99101
return;
@@ -300,8 +302,7 @@ pub unsafe fn buffered_read_opt(
300302
if (op + bytes as i64) < 0 {
301303
return 0;
302304
}
303-
let np =
304-
file.seek(SeekFrom::Current(bytes as i64)).unwrap() as i64;
305+
let np = file.seek(SeekFrom::Current(bytes as i64)).unwrap() as i64;
305306
i = (np - op) as isize;
306307
}
307308
if i == 0 && ccx_options.live_stream.unwrap().millis() != 0 {
@@ -364,10 +365,13 @@ pub unsafe fn buffered_read_opt(
364365
if i == -1 {
365366
fatal!(cause = ExitCause::NoInputFiles; "Error reading input stream!\n");
366367
}
367-
if i == 0 && (ccx_options.live_stream.unwrap().millis() > 0
368-
|| ctx.parent.as_mut().unwrap().inputsize <= origin_buffer_size as i64 || !(ccx_options.binary_concat
368+
if i == 0
369+
&& (ccx_options.live_stream.unwrap().millis() > 0
370+
|| ctx.parent.as_mut().unwrap().inputsize <= origin_buffer_size as i64
371+
|| !(ccx_options.binary_concat
369372
&& switch_to_next_file(ctx.parent.as_mut().unwrap(), copied as i64)
370-
!= 0)) {
373+
!= 0))
374+
{
371375
eof = true;
372376
}
373377
ctx.filebuffer_pos = keep as u32;
@@ -673,10 +677,10 @@ mod tests {
673677
use crate::common::{Codec, StreamMode};
674678
use crate::util::log::{set_logger, CCExtractorLogger, DebugMessageMask, OutputTarget};
675679
// use std::io::{Seek, SeekFrom, Write};
680+
use serial_test::serial;
676681
use std::os::unix::io::IntoRawFd;
677682
use std::slice;
678683
use std::sync::Once;
679-
use serial_test::serial;
680684

681685
static INIT: Once = Once::new();
682686

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,6 @@ pub unsafe fn parse_ad_field(demux: &mut CcxDemuxer, mut len: i32, data: &mut De
11951195
let mut result;
11961196
let mut tag = [0u8; 5]; // 4-byte tag plus null terminator
11971197

1198-
11991198
tag[4] = 0;
12001199

12011200
// Read "finf" tag
@@ -1600,13 +1599,11 @@ pub unsafe fn parse_media(demux: &mut CcxDemuxer, mut len: i32, data: &mut Demux
16001599

16011600
let ctx = &mut *(demux.private_data as *mut CcxGxf);
16021601

1603-
16041602
let mut first_field_nb: u16 = 0;
16051603
let mut last_field_nb: u16 = 0;
16061604
let mut mpeg_pic_size: u32 = 0;
16071605
let mut mpeg_frame_desc_flag: u8 = 0;
16081606

1609-
16101607
len -= 1;
16111608

16121609
let media_type_0 = GXFTrackType::try_from(buffered_get_byte(demux));
@@ -1892,7 +1889,7 @@ mod tests {
18921889
DebugMessageMask::new(DebugMessageFlag::VERBOSE, DebugMessageFlag::VERBOSE),
18931890
false,
18941891
))
1895-
.ok();
1892+
.ok();
18961893
});
18971894
}
18981895

@@ -2707,7 +2704,7 @@ mod tests {
27072704
payload.extend_from_slice(&[0x01, 0x00]); // d_id
27082705
payload.extend_from_slice(&[0x02, 0x00]); // sd_id
27092706
payload.extend_from_slice(&[0xFF, 0x00]); // dc (masked to 0xFF)
2710-
// Remaining payload: one 16-bit word.
2707+
// Remaining payload: one 16-bit word.
27112708
payload.extend_from_slice(&[0xFF, 0x00]); // This will produce 0x00FF stored in cdp[0]
27122709
payload
27132710
}
@@ -2748,7 +2745,7 @@ mod tests {
27482745
payload.extend_from_slice(&[0x01, 0x00]); // d_id
27492746
payload.extend_from_slice(&[0x03, 0x00]); // sd_id = 0x0003 for CEA-608
27502747
payload.extend_from_slice(&[0x00, 0x00]); // dc (arbitrary)
2751-
// Append some extra payload (e.g., 4 bytes).
2748+
// Append some extra payload (e.g., 4 bytes).
27522749
payload.extend_from_slice(&[0x11, 0x22, 0x33, 0x44]);
27532750
let total_len = payload.len() as i32;
27542751
let mut demux = create_demuxer_with_buffer(&payload);
@@ -2776,7 +2773,7 @@ mod tests {
27762773
payload.extend_from_slice(&[0x02, 0x00]); // d_id = 0x0002 (does not match)
27772774
payload.extend_from_slice(&[0x02, 0x00]); // sd_id = 0x0002 (irrelevant)
27782775
payload.extend_from_slice(&[0x00, 0x00]); // dc
2779-
// Append extra payload (4 bytes).
2776+
// Append extra payload (4 bytes).
27802777
payload.extend_from_slice(&[0x55, 0x66, 0x77, 0x88]);
27812778
let total_len = payload.len() as i32;
27822779
let mut demux = create_demuxer_with_buffer(&payload);
@@ -2822,9 +2819,7 @@ mod tests {
28222819

28232820
// --- Tests for when VBI support is enabled ---
28242821
#[test]
2825-
#[cfg(
2826-
feature = "ccx_gxf_enable_ad_vbi"
2827-
)] // to run use ccx_gxf_enable_ad_vbi=1 RUST_TEST_THREADS=1 cargo test
2822+
#[cfg(feature = "ccx_gxf_enable_ad_vbi")] // to run use ccx_gxf_enable_ad_vbi=1 RUST_TEST_THREADS=1 cargo test
28282823
fn test_parse_ad_vbi_enabled() {
28292824
// Create a buffer with known content.
28302825
let payload = vec![0xBB; 20]; // 20 bytes of data.
@@ -3025,7 +3020,7 @@ mod tests {
30253020
fn test_parse_ad_packet_incorrect_riff() {
30263021
let mut data = Vec::new();
30273022
data.extend_from_slice(b"RIFX"); // Incorrect RIFF
3028-
// ... rest of data setup similar to correct test but with incorrect header
3023+
// ... rest of data setup similar to correct test but with incorrect header
30293024

30303025
let mut demux = create_ccx_demuxer_with_header(&data);
30313026
let mut ctx = CcxGxf {
@@ -3262,8 +3257,8 @@ mod tests {
32623257
buf.extend_from_slice(&[0xCC; 14]);
32633258
#[allow(unused_variables)]
32643259
let total_len = buf.len() as i32; // should be 40 + 14 = 54? Let's check:
3265-
// Actually: 2+2+2+10+2+8+14 = 40 bytes.
3266-
// Let's set total length = buf.len() as i32.
3260+
// Actually: 2+2+2+10+2+8+14 = 40 bytes.
3261+
// Let's set total length = buf.len() as i32.
32673262
let total_len = buf.len() as i32;
32683263

32693264
// Create demuxer with this buffer.

src/rust/src/libccxr_exports/demuxer.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use lib_ccxr::demuxer::demux::{
44
};
55
use std::ffi::CStr;
66
use std::os::raw::{c_char, c_int, c_longlong};
7-
7+
/// # Safety
8+
/// This function is unsafe because it dereferences a raw pointer.
89
#[no_mangle]
910
pub unsafe extern "C" fn ccxr_demuxer_reset(ctx: *mut CcxDemuxer) {
1011
// Check for a null pointer to avoid undefined behavior.
@@ -18,6 +19,8 @@ pub unsafe extern "C" fn ccxr_demuxer_reset(ctx: *mut CcxDemuxer) {
1819
}
1920

2021
// Extern function for ccx_demuxer_close
22+
/// # Safety
23+
/// This function is unsafe because it dereferences a raw pointer.
2124
#[no_mangle]
2225
pub unsafe extern "C" fn ccxr_demuxer_close(ctx: *mut CcxDemuxer) {
2326
if ctx.is_null() {
@@ -28,6 +31,8 @@ pub unsafe extern "C" fn ccxr_demuxer_close(ctx: *mut CcxDemuxer) {
2831
}
2932

3033
// Extern function for ccx_demuxer_isopen
34+
/// # Safety
35+
/// This function is unsafe because it dereferences a raw pointer.
3136
#[no_mangle]
3237
pub unsafe extern "C" fn ccxr_demuxer_isopen(ctx: *const CcxDemuxer) -> c_int {
3338
if ctx.is_null() {
@@ -42,6 +47,8 @@ pub unsafe extern "C" fn ccxr_demuxer_isopen(ctx: *const CcxDemuxer) -> c_int {
4247
}
4348

4449
// Extern function for ccx_demuxer_open
50+
/// # Safety
51+
/// This function is unsafe because it dereferences a raw pointer and calls unsafe function `open`
4552
#[no_mangle]
4653
pub unsafe extern "C" fn ccxr_demuxer_open(ctx: *mut CcxDemuxer, file: *const c_char) -> c_int {
4754
if ctx.is_null() || file.is_null() {
@@ -60,6 +67,8 @@ pub unsafe extern "C" fn ccxr_demuxer_open(ctx: *mut CcxDemuxer, file: *const c_
6067
}
6168

6269
// Extern function for ccx_demuxer_get_file_size
70+
/// # Safety
71+
/// This function is unsafe because it dereferences a raw pointer.
6372
#[no_mangle]
6473
pub unsafe extern "C" fn ccxr_demuxer_get_file_size(ctx: *mut CcxDemuxer) -> c_longlong {
6574
if ctx.is_null() {
@@ -70,6 +79,8 @@ pub unsafe extern "C" fn ccxr_demuxer_get_file_size(ctx: *mut CcxDemuxer) -> c_l
7079
}
7180

7281
// Extern function for ccx_demuxer_get_stream_mode
82+
/// # Safety
83+
/// This function is unsafe because it dereferences a raw pointer.
7384
#[no_mangle]
7485
pub unsafe extern "C" fn ccxr_demuxer_get_stream_mode(ctx: *const CcxDemuxer) -> c_int {
7586
if ctx.is_null() {
@@ -80,6 +91,8 @@ pub unsafe extern "C" fn ccxr_demuxer_get_stream_mode(ctx: *const CcxDemuxer) ->
8091
}
8192

8293
// Extern function for ccx_demuxer_print_cfg
94+
/// # Safety
95+
/// This function is unsafe because it dereferences a raw pointer.
8396
#[no_mangle]
8497
pub unsafe extern "C" fn ccxr_demuxer_print_cfg(ctx: *const CcxDemuxer) {
8598
if ctx.is_null() {
@@ -89,6 +102,8 @@ pub unsafe extern "C" fn ccxr_demuxer_print_cfg(ctx: *const CcxDemuxer) {
89102
ccx_demuxer_print_cfg(&*ctx)
90103
}
91104

105+
/// # Safety
106+
/// This function is unsafe because it dereferences a raw pointer and calls unsafe function `dinit_cap`
92107
#[no_mangle]
93108
pub unsafe extern "C" fn ccxr_demuxer_delete(ctx: *mut *mut CcxDemuxer) {
94109
// Check if the pointer itself or the pointed-to pointer is null.

0 commit comments

Comments
 (0)