Skip to content

[FEAT] added demuxer and file_functions module #1662

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d677f98
feat: added demuxer module
steel-bucket Feb 11, 2025
c919330
Cargo Lock Update
steel-bucket Mar 23, 2025
2a5f5fe
Completed file_functions and demuxer
steel-bucket Mar 25, 2025
4c148c3
Completed file_functions and demuxer
steel-bucket Mar 25, 2025
8dd043f
written extern functions for demuxer
steel-bucket Mar 25, 2025
b8cd075
Removed libc completely, added tests for gxf and ported gxf to C
steel-bucket Mar 27, 2025
08106b2
Hardsubx error fixed
steel-bucket Mar 29, 2025
b164623
Fixing format issues
steel-bucket Mar 29, 2025
a51203c
clippy errors fixed
steel-bucket Mar 30, 2025
d1b3c48
fixing format issues
steel-bucket Mar 30, 2025
681b5ad
fixing format issues
steel-bucket Mar 30, 2025
90d8c78
Windows failing tests
steel-bucket Mar 30, 2025
f6d6cbd
Windows failing tests
steel-bucket Mar 30, 2025
a1c71b6
demuxer: added demuxer data transfer functions and removed some structs
steel-bucket May 19, 2025
c10e5c8
made Demuxer and File Functions
steel-bucket Jun 7, 2025
bfbe1d6
Minor formatting changes
steel-bucket Jun 7, 2025
bdfced0
Minor Rebasing changes
steel-bucket Jun 7, 2025
1cd4ad0
demuxer: format rust and unit test rust checks
steel-bucket Jun 7, 2025
625fc46
C formatting
steel-bucket Jun 7, 2025
df8c075
Windows Failing test
steel-bucket Jun 7, 2025
1262e8a
Windows Failing test
steel-bucket Jun 7, 2025
a0f0b59
Update CHANGES.TXT
steel-bucket Jun 7, 2025
c90f91f
Update CHANGES.TXT
steel-bucket Jun 11, 2025
f4698f0
Windows Failing Tests
steel-bucket Jun 11, 2025
ddcdf5f
Windows Failing Tests
steel-bucket Jun 11, 2025
ff2925e
Problem in Copy to Rust and some typos that copilot review suggested
steel-bucket Jun 13, 2025
5d66be0
Minor Formatting Error
steel-bucket Jun 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/CHANGES.TXT
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
1.0 (to be released)
-----------------
- New: Add demuxer and file_functions module (#1662)
- Fix: Unit Test Rust failing due to changes in Rust Version 1.86.0 (#1694)
- IMPROVEMENT: Refactor and optimize Dockerfile
- Fix: Improved handling of IETF language tags in Matroska files (#1665)
- New: Create unit test for rust code (#1615)
Expand Down Expand Up @@ -40,7 +42,6 @@
- New: Add tesseract page segmentation modes control with `--psm` flag
- Fix: Resolve compile-time error about implicit declarations (#1646)
- Fix: fatal out of memory error extracting from a VOB PS
- Fix: Unit Test Rust failing due to changes in Rust Version 1.86.0

0.94 (2021-12-14)
-----------------
Expand Down
2 changes: 1 addition & 1 deletion src/ccextractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ int api_start(struct ccx_s_options api_options)
api_options.use_gop_as_pts = 0;
if (api_options.ignore_pts_jumps)
ccx_common_timing_settings.disable_sync_check = 1;
mprint("\rAnalyzing data in general mode\n");
mprint("\r\n Analyzing data in general mode\n");
tmp = general_loop(ctx);
if (!ret)
ret = tmp;
Expand Down
36 changes: 35 additions & 1 deletion src/lib_ccx/ccx_demuxer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
#include "lib_ccx.h"
#include "utility.h"
#include "ffmpeg_intgr.h"
#ifndef DISABLE_RUST
void ccxr_demuxer_reset(struct ccx_demuxer *ctx);
void ccxr_demuxer_close(struct ccx_demuxer *ctx);
int ccxr_demuxer_isopen(const struct ccx_demuxer *ctx);
int ccxr_demuxer_open(struct ccx_demuxer *ctx, const char *file);
LLONG ccxr_demuxer_get_file_size(struct ccx_demuxer *ctx);
void ccxr_demuxer_print_cfg(const struct ccx_demuxer *ctx);
#endif

static void ccx_demuxer_reset(struct ccx_demuxer *ctx)
{
#ifndef DISABLE_RUST
ccxr_demuxer_reset(ctx);
#else
ctx->startbytes_pos = 0;
ctx->startbytes_avail = 0;
ctx->num_of_PIDs = 0;
Expand All @@ -17,25 +28,38 @@ static void ccx_demuxer_reset(struct ccx_demuxer *ctx)
}
memset(ctx->stream_id_of_each_pid, 0, (MAX_PSI_PID + 1) * sizeof(uint8_t));
memset(ctx->PIDs_programs, 0, 65536 * sizeof(struct PMT_entry *));
#endif
}

static void ccx_demuxer_close(struct ccx_demuxer *ctx)
{
#ifndef DISABLE_RUST
ccxr_demuxer_close(ctx);
#else
ctx->past = 0;
if (ctx->infd != -1 && ccx_options.input_source == CCX_DS_FILE)
{
close(ctx->infd);
ctx->infd = -1;
activity_input_file_closed();
}
#endif
}

static int ccx_demuxer_isopen(struct ccx_demuxer *ctx)
{
#ifndef DISABLE_RUST
return ccxr_demuxer_isopen(ctx);
#else
return ctx->infd != -1;
#endif
}

static int ccx_demuxer_open(struct ccx_demuxer *ctx, const char *file)
{
#ifndef DISABLE_RUST
return ccxr_demuxer_open(ctx, file);
#else
ctx->past = 0;
ctx->min_global_timestamp = 0;
ctx->global_timestamp_inited = 0;
Expand Down Expand Up @@ -193,9 +217,14 @@ static int ccx_demuxer_open(struct ccx_demuxer *ctx, const char *file)
}

return 0;
#endif
}

LLONG ccx_demuxer_get_file_size(struct ccx_demuxer *ctx)
{
#ifndef DISABLE_RUST
return ccxr_demuxer_get_file_size(ctx);
#else
LLONG ret = 0;
int in = ctx->infd;
LLONG current = LSEEK(in, 0, SEEK_CUR);
Expand All @@ -208,6 +237,7 @@ LLONG ccx_demuxer_get_file_size(struct ccx_demuxer *ctx)
return -1;

return length;
#endif
}

static int ccx_demuxer_get_stream_mode(struct ccx_demuxer *ctx)
Expand All @@ -217,6 +247,9 @@ static int ccx_demuxer_get_stream_mode(struct ccx_demuxer *ctx)

static void ccx_demuxer_print_cfg(struct ccx_demuxer *ctx)
{
#ifndef DISABLE_RUST
ccxr_demuxer_print_cfg(ctx);
#else
switch (ctx->auto_stream)
{
case CCX_SM_ELEMENTARY_OR_NOT_FOUND:
Expand Down Expand Up @@ -261,6 +294,7 @@ static void ccx_demuxer_print_cfg(struct ccx_demuxer *ctx)
fatal(CCX_COMMON_EXIT_BUG_BUG, "BUG: Unknown stream mode. Please file a bug report on Github.\n");
break;
}
#endif
}

void ccx_demuxer_delete(struct ccx_demuxer **ctx)
Expand Down Expand Up @@ -407,4 +441,4 @@ struct demuxer_data *alloc_demuxer_data(void)
data->next_stream = 0;
data->next_program = 0;
return data;
}
}
24 changes: 0 additions & 24 deletions src/lib_ccx/ccx_demuxer_mxf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
#define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
#define IS_KLV_KEY_ANY_VERSION(x, y) (!memcmp(x, y, 7) && !memcmp(x + 8, y + 8, sizeof(y) - 8))

enum MXFCaptionType
{
MXF_CT_VBI,
MXF_CT_ANC,
};

typedef uint8_t UID[16];
typedef struct KLVPacket
{
UID key;
Expand All @@ -35,29 +28,12 @@ typedef struct MXFCodecUL

typedef int ReadFunc(struct ccx_demuxer *ctx, uint64_t size);

typedef struct
{
int track_id;
uint8_t track_number[4];
} MXFTrack;

typedef struct MXFReadTableEntry
{
const UID key;
ReadFunc *read;
} MXFReadTableEntry;

typedef struct MXFContext
{
enum MXFCaptionType type;
int cap_track_id;
UID cap_essence_key;
MXFTrack tracks[32];
int nb_tracks;
int cap_count;
struct ccx_rational edit_rate;
} MXFContext;

typedef struct MXFLocalTAGS
{
uint16_t tag;
Expand Down
29 changes: 27 additions & 2 deletions src/lib_ccx/ccx_demuxer_mxf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@

#include "ccx_demuxer.h"

int ccx_probe_mxf(struct ccx_demuxer *ctx);
struct MXFContext *ccx_mxf_init(struct ccx_demuxer *demux);
typedef uint8_t UID[16];

enum MXFCaptionType
{
MXF_CT_VBI,
MXF_CT_ANC,
};

typedef struct
{
int track_id;
uint8_t track_number[4];
} MXFTrack;

typedef struct MXFContext
{
enum MXFCaptionType type;
int cap_track_id;
UID cap_essence_key;
MXFTrack tracks[32];
int nb_tracks;
int cap_count;
struct ccx_rational edit_rate;
} MXFContext;

int ccx_probe_mxf(struct ccx_demuxer* ctx);
struct MXFContext* ccx_mxf_init(struct ccx_demuxer* demux);
#endif
53 changes: 3 additions & 50 deletions src/lib_ccx/ccx_gxf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "ccx_demuxer.h"
#include "file_buffer.h"

#define STR_LEN 256u

#define CLOSED_CAP_DID 0x61
#define CLOSED_C708_SDID 0x01
#define CLOSED_C608_SDID 0x02
Expand All @@ -29,6 +27,7 @@
#define log(fmt, ...) ccx_common_logging.log_ftn("GXF:%d: " fmt, __LINE__, ##__VA_ARGS__)

#undef CCX_GXF_ENABLE_AD_VBI

typedef enum
{
PKT_MAP = 0xbc,
Expand Down Expand Up @@ -279,53 +278,6 @@ struct ccx_gxf_ancillary_data_track
uint32_t field_per_frame;
};

struct ccx_gxf
{
int nb_streams;

/* Name of Media File */
char media_name[STR_LEN];

/**
* The first field number shall represent the position on a playout
* time line of the first recorded field on a track
*/
int32_t first_field_nb;

/**
* The last field number shall represent the position on a playout
* time line of the last recorded field plus one.
*/
int32_t last_field_nb;

/**
* The mark in field number shall represent the position on a playout
* time line of the first field to be played from a track.
*/
int32_t mark_in;

/**
* The mark out field number shall represent the position on a playout
* time line of the last field to be played plus one
*/
int32_t mark_out;

/**
* Estimated size in kb for bytes multiply by 1024
*/
int32_t stream_size;

struct ccx_gxf_ancillary_data_track *ad_track;

struct ccx_gxf_video_track *vid_track;

/**
* cdp data buffer
*/
unsigned char *cdp;
size_t cdp_len;
};

/**
* @brief parses a packet header, extracting type and length
* @param ctx Demuxer Ctx used for reading from file
Expand Down Expand Up @@ -781,7 +733,6 @@ static int parse_track_sec(struct ccx_demuxer *demux, int len, struct demuxer_da

int parse_ad_cdp(unsigned char *cdp, size_t len, struct demuxer_data *data)
{

int ret = CCX_OK;
uint16_t cdp_length;
uint16_t cdp_framerate;
Expand Down Expand Up @@ -1218,6 +1169,7 @@ static void set_data_timebase(int32_t vid_format, struct demuxer_data *data)
default:
break;
}
// #endif
}

static int parse_mpeg_packet(struct ccx_demuxer *demux, int len, struct demuxer_data *data)
Expand Down Expand Up @@ -1660,6 +1612,7 @@ int ccx_gxf_probe(unsigned char *buf, int len)
if (!memcmp(buf, startcode, sizeof(startcode)))
return CCX_TRUE;
return CCX_FALSE;
// #endif
}

int ccx_gxf_get_more_data(struct lib_ccx_ctx *ctx, struct demuxer_data **ppdata)
Expand Down
49 changes: 49 additions & 0 deletions src/lib_ccx/ccx_gxf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,55 @@
#include "ccx_demuxer.h"
#include "lib_ccx.h"

#define STR_LEN 256u

struct ccx_gxf
{
int nb_streams;

/* Name of Media File */
char media_name[STR_LEN];

/**
* The first field number shall represent the position on a playout
* time line of the first recorded field on a track
*/
int32_t first_field_nb;

/**
* The last field number shall represent the position on a playout
* time line of the last recorded field plus one.
*/
int32_t last_field_nb;

/**
* The mark in field number shall represent the position on a playout
* time line of the first field to be played from a track.
*/
int32_t mark_in;

/**
* The mark out field number shall represent the position on a playout
* time line of the last field to be played plus one
*/
int32_t mark_out;

/**
* Estimated size in kb for bytes multiply by 1024
*/
int32_t stream_size;

struct ccx_gxf_ancillary_data_track *ad_track;

struct ccx_gxf_video_track *vid_track;

/**
* cdp data buffer
*/
unsigned char *cdp;
size_t cdp_len;
};

int ccx_gxf_probe(unsigned char *buf, int len);
int ccx_gxf_get_more_data(struct lib_ccx_ctx *ctx, struct demuxer_data **data);
struct ccx_gxf *ccx_gxf_init(struct ccx_demuxer *arg);
Expand Down
Loading
Loading