Skip to content

Conversation

steel-bucket
Copy link
Contributor

@steel-bucket steel-bucket commented Feb 11, 2025

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog.

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor(2 previous contributions).

In this PR, I have attempted to port the large demuxer module to Rust, the primary logic of the heavily interconnected C libraries file_functions.c and, ccx_demuxer.c and their corresponding header files has aleady been implemented here.
This PR was inspired by the ones done for the 708 Decoder in CCextractor.
The part of the codebase that the demuxer part of this PR migrates to Rust is the part that Opens a File(ccx_demuxer_open), points the codebase towards that file, detects the stream type and some other parameters like myth, and then closes the file or gets the file size.
The file_functions part of this PR is tested locally, and in unit tests, but integrating it into C made the codebase really slow, due to the constant copying back and forth C and Rust, so it was left to be used in future Rust Libraries like MythTV, MXF, GXF, etc.
Any criticism or suggestion is wholeheartedly welcome.

  • It is built and ready to be reviewed now.

@cfsmp3 cfsmp3 requested a review from prateekmedia February 12, 2025 20:45
@prateekmedia
Copy link
Member

@steel-bucket Is it still WIP?

@steel-bucket
Copy link
Contributor Author

@steel-bucket Is it still WIP?

Yes, I'm done with the hard part though, file_functions module is fully tested and ready. And the demuxer module just needs a couple more tests. Then I just have the gxf one to do. It won't be long though. Sorry to be late with it, I had some exams which are cleared out now.

@steel-bucket steel-bucket changed the title [WIP] feat: added demuxer module [FEAT]feat: added demuxer module Mar 27, 2025
@prateekmedia prateekmedia changed the title [FEAT]feat: added demuxer module [FEAT] added demuxer module Mar 29, 2025
@steel-bucket
Copy link
Contributor Author

steel-bucket commented Mar 31, 2025

Hi, @prateekmedia the builds and tests are all working(other than regression). Please review it if time permits. Also should I squash the commits together?
Thank you so much.

@steel-bucket steel-bucket changed the title [FEAT] added demuxer module [FEAT] added demuxer and file_functions module Jun 7, 2025
@steel-bucket steel-bucket force-pushed the migration-demuxer-module branch from 5268a7d to bfbe1d6 Compare June 7, 2025 08:21
@prateekmedia prateekmedia requested a review from Copilot June 12, 2025 10:06
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ports the C demuxer and file_functions modules to Rust, adds corresponding FFI bindings for MXF/GXF, and updates build configuration.

  • Introduced new Rust modules (demuxer, file_functions) and added them to the crate root.
  • Extended the C wrapper (wrapper.h) and extern "C" block in lib.rs for MXF/GXF and demuxer functions.
  • Updated C source (ccx_gxf.*, ccx_demuxer_mxf.*, ccx_demuxer.c) to remove duplicate definitions and conditionally call Rust implementations.

Reviewed Changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/rust/wrapper.h Added headers for GXF and MXF demuxer
src/rust/src/parser.rs Tightened cast to usize for input file capacity check
src/rust/src/libccxr_exports/mod.rs Exported the new demuxer module
src/rust/src/lib.rs Declared new Rust modules and FFI externs
src/rust/src/file_functions/mod.rs Added file_functions module with documentation stub
src/rust/src/demuxer/common_structs.rs New demuxer data structures and defaults
src/lib_ccx/ccx_gxf.h Defined ccx_gxf struct for GXF support
src/lib_ccx/ccx_gxf.c Removed duplicate struct; left stray comments
src/lib_ccx/ccx_demuxer_mxf.h Added MXF context and type definitions
src/lib_ccx/ccx_demuxer_mxf.c Cleaned up duplicate MXF definitions
src/lib_ccx/ccx_demuxer.c Wrapped demuxer calls under DISABLE_RUST
docs/CHANGES.TXT Updated changelog with new entries
Comments suppressed due to low confidence (5)

src/lib_ccx/ccx_demuxer_mxf.c:1

  • This file uses uint8_t and other fixed-width types but does not include <stdint.h>. Add the proper include to avoid compilation errors.
#define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))

docs/CHANGES.TXT:44

  • The leading -- appears duplicated in this changelog entry. Use a single - to match the existing formatting.
-- Fix: Unit Test Rust failing due to changes in Rust Version 1.86.0

src/rust/src/lib.rs:43

  • [nitpick] The imported types c_uchar, c_ulong, and c_void are not used elsewhere in this file; consider removing this import.
use std::os::raw::{c_uchar, c_ulong, c_void};

src/lib_ccx/ccx_gxf.h:9

  • Ensure this header has proper include guards or #pragma once to prevent duplicate definitions when included multiple times.
struct ccx_gxf

src/lib_ccx/ccx_demuxer_mxf.h:6

  • Add include guards or #pragma once to this header to prevent multiple inclusion, and verify that <stdint.h> is included for uint8_t.
typedef uint8_t UID[16];

Comment on lines 4 to 7
* @param ctx ccx_demuxer context properly initilaized ccx_demuxer with some input
* Not to be NULL, since ctx is derefrenced inside this function
*
* @param buffer if buffer then it must be allocated to at;east bytes len as
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix typos in the documentation: change "initilaized" to "initialized", "derefrenced" to "dereferenced", and "at;east" to "at least".

Suggested change
* @param ctx ccx_demuxer context properly initilaized ccx_demuxer with some input
* Not to be NULL, since ctx is derefrenced inside this function
*
* @param buffer if buffer then it must be allocated to at;east bytes len as
* @param ctx ccx_demuxer context properly initialized ccx_demuxer with some input
* Not to be NULL, since ctx is dereferenced inside this function
*
* @param buffer if buffer then it must be allocated to at least bytes len as

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

Comment on lines 119 to 127
#[allow(unused)] // used in tests
pub(crate) fn default() -> PSIBuffer {
PSIBuffer {
prev_ccounter: 0,
buffer: Box::into_raw(Box::new(0u8)),
buffer_length: 0,
ccounter: 0,
}
}
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have both an impl Default for PSIBuffer and an inherent default() method; consider removing the duplicate inherent method or merging them to avoid confusion.

Suggested change
#[allow(unused)] // used in tests
pub(crate) fn default() -> PSIBuffer {
PSIBuffer {
prev_ccounter: 0,
buffer: Box::into_raw(Box::new(0u8)),
buffer_length: 0,
ccounter: 0,
}
}

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

if (result != len)
ret = CCX_EOF;
return ret;
// #endif
Copy link

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove stray commented // #endif lines inside function bodies to clean up leftover conditional compilation markers.

Suggested change
// #endif

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

Comment on lines 146 to 148
drop(file); // This closes the file descriptor
self.infd = -1;
ccx_options.activity_input_file_closed();
Copy link
Member

@prateekmedia prateekmedia Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only first line is different, right? You can keep either last three lines outside this or either last two lines outside this, depending on if you can extract drop(file).

Unless there is another case other than these unix and windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

Comment on lines 228 to 235
if self.infd != -1 {
if ccx_options.print_file_reports {
{
print_file_report(*self.parent.as_mut().unwrap());
}
}
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extract this since it is used for three cases beginning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit 24f7184...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 7/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 0/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 86/86
Teletext 21/21
WTV 13/13
XDS 34/34

NOTE: The following tests have been failing on the master branch as well as the PR:

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=ttxt --xds --latin1 --ucla e274a73653..., Last passed: Never

All tests passing on the master branch were passed completely.

Check the result page for more info.

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit c2a1f0d...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 7/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 0/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 86/86
Teletext 21/21
WTV 13/13
XDS 33/34

Your PR breaks these cases:

  • ccextractor --autoprogram --out=ttxt --xds --latin1 --ucla e274a73653...

NOTE: The following tests have been failing on the master branch as well as the PR:

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=srt --latin1 f1422b8bfe..., Last passed: Never
  • ccextractor --datapid 5603 --autoprogram --out=srt --latin1 --teletext 85c7fc1ad7..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 c0d2fba8c0..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 006fdc391a..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 e92a1d4d2a..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 7e4ebf7fd7..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 9256a60e4b..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 27d7a43dd6..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 297a44921a..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 efbe129086..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 eae0077731..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 e2e2b501e0..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 c6407fb294..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --datets dcada745de..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 --tpage 398 5d5838bde9..., Last passed: Never
  • ccextractor --autoprogram --out=srt --latin1 --teletext --tpage 398 3b276ad8bf..., Last passed: Never

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants