Skip to content

Conversation

@AhmedAlian7
Copy link
Contributor

@AhmedAlian7 AhmedAlian7 commented Feb 9, 2026

[IMPROVEMENT]

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.

closes #2101

Summary

Resolves the TODO in file_functions.c:311 by encapsulating demuxer-related options within the ccx_demuxer struct instead of accessing the global ccx_options.

Problem

Multiple functions directly accessed global ccx_options for 4 options that logically belong to the demuxer context:

  • live_stream - Live stream mode and timeout
  • buffer_input - Whether to buffer input data
  • input_source - Source type (file, stdin, network, tcp)
  • binary_concat - Whether to concatenate binary files

This caused issues with testability, encapsulation, thread safety, and library reusability.

Changes

src/lib_ccx/ccx_demuxer.h

Added 4 new fields to struct ccx_demuxer:

// Options moved from global ccx_options for encapsulation
int live_stream;                   // -1=live no timeout, 0=regular file, >0=live with timeout
int buffer_input;                  // Buffer input data
enum ccx_datasource input_source;  // Source type (file, stdin, network, tcp)
int binary_concat;                 // Concatenate binary files

src/lib_ccx/ccx_demuxer.c

init_demuxer() - Initialize new fields from global options:

ctx->live_stream = ccx_options.live_stream;
ctx->buffer_input = ccx_options.buffer_input;
ctx->input_source = ccx_options.input_source;
ctx->binary_concat = ccx_options.binary_concat;

ccx_demuxer_close() - Updated to use ctx->input_source.
ccx_demuxer_open() - Updated all input source checks to use ctx->input_source.

src/lib_ccx/file_functions.c

sleepandchecktimeout() - Added ctx parameter.
buffered_read_opt() - Updated all 4 options to use ctx->.
get_total_file_size() - Updated to use ctx->demux_ctx->live_stream.
switch_to_next_file() - Updated all options to use ctx->demux_ctx->.

Testing

  • Build succeeds on Linux (make in linux directory)
  • Executable runs correctly (ccextractor --version)
  • No remaining global references for the 4 options in affected functions
  • I have mentioned this change in the changelog.

Impact

  • No breaking changes - Options are still initialized from global ccx_options at demuxer creation
  • Improved encapsulation - Demuxer now owns its configuration
  • Better testability - Functions can be tested with different option values via context

…_demuxer struct

Resolves the TODO in file_functions.c:311 by encapsulating demuxer-related options within the ccx_demuxer struct instead of accessing the global ccx_options.

Changes:
- Added live_stream, buffer_input, input_source, binary_concat to struct ccx_demuxer
- Updated init_demuxer() to initialize these from global options
- Updated file_functions.c and ccx_demuxer.c to use context fields instead of globals
- Updated changelog
@AhmedAlian7 AhmedAlian7 force-pushed the refactor/move-demuxer-options-to-struct branch from 8b9acf1 to 42e513d Compare February 9, 2026 16:55
@AhmedAlian7
Copy link
Contributor Author

Code passes all tests locally, but failed on GitHub CI cuz github server issues

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Move demuxer-related options from global ccx_options to ccx_demuxer struct

1 participant