Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 14 additions & 3 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Format code
id: format
run: |
find src/ -type f -not -path "src/thirdparty/*" -not -path "src/lib_ccx/zvbi/*" -name '*.c' -not -path "src/GUI/icon_data.c" | xargs clang-format -i
git diff-index --quiet HEAD -- || (git diff && exit 1)
git diff-index --quiet HEAD -- || echo "changes_detected=true" >> $GITHUB_ENV
- name: Commit changes
if: env.changes_detected == 'true'
run: |
git add .
git commit -m "Automated code formatting by GitHub Actions"
git push
format_rust:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -51,7 +62,7 @@ jobs:
- name: dependencies
run: sudo apt update && sudo apt install libtesseract-dev libavformat-dev libavdevice-dev libswscale-dev yasm
- name: rustfmt
run: cargo fmt --all -- --check
run: cargo fmt --all
- name: clippy
run: |
cargo clippy -- -D warnings
cargo clippy -- -D warnings
16 changes: 16 additions & 0 deletions src/lib_ccx/ccx_decoders_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ made to reuse, not duplicate, as many functions as possible */
#ifndef DISABLE_RUST
extern int ccxr_process_cc_data(struct lib_cc_decode *dec_ctx, unsigned char *cc_data, int cc_count);
extern void ccxr_flush_decoder(struct dtvcc_ctx *dtvcc, struct dtvcc_service_decoder *decoder);
extern int ccxr_dtvcc_init(struct lib_cc_decode *ctx);
extern void ccxr_dtvcc_free(struct lib_cc_decode *ctx);
#endif

uint64_t utc_refvalue = UINT64_MAX; /* _UI64_MAX/UINT64_MAX means don't use UNIX, 0 = use current system time as reference, +1 use a specific reference */
Expand Down Expand Up @@ -263,6 +265,12 @@ struct lib_cc_decode *init_cc_decode(struct ccx_decoders_common_settings_t *sett

ctx->dtvcc = dtvcc_init(setting->settings_dtvcc);
ctx->dtvcc->is_active = setting->settings_dtvcc->enabled;
ctx->dtvcc_rust = NULL; // Initialize dtvcc_rust to NULL

// Initialize the Rust Dtvcc instance
if (ccxr_dtvcc_init(ctx) != 0) {
ccx_log("Failed to initialize Rust Dtvcc instance\n");
}

if (setting->codec == CCX_CODEC_ATSC_CC)
{
Expand Down Expand Up @@ -540,6 +548,10 @@ struct lib_cc_decode *copy_decoder_context(struct lib_cc_decode *ctx)
ctx_copy->dtvcc = malloc(sizeof(struct dtvcc_ctx));
memcpy(ctx_copy->dtvcc, ctx->dtvcc, sizeof(struct dtvcc_ctx));
}

// dtvcc_rust will be initialized later by ccxr_dtvcc_init
ctx_copy->dtvcc_rust = NULL;

if (ctx->xds_ctx)
{
ctx_copy->xds_ctx = malloc(sizeof(struct ccx_decoders_xds_context));
Expand Down Expand Up @@ -593,6 +605,10 @@ void free_decoder_context(struct lib_cc_decode *ctx)
freep(&ctx->timing);
freep(&ctx->avc_ctx);
freep(&ctx->private_data);

// Free the Rust Dtvcc instance
ccxr_dtvcc_free(ctx);

freep(&ctx->dtvcc);
freep(&ctx->xds_ctx);
freep(&ctx->vbi_decoder);
Expand Down
6 changes: 6 additions & 0 deletions src/lib_ccx/ccx_decoders_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ struct cc_subtitle* copy_subtitle(struct cc_subtitle *sub);
void free_encoder_context(struct encoder_ctx *ctx);
void free_decoder_context(struct lib_cc_decode *ctx);
void free_subtitle(struct cc_subtitle* sub);

extern int ccxr_process_cc_data(struct lib_cc_decode *dec_ctx, unsigned char *cc_data, int cc_count);
extern void ccxr_flush_decoder(struct dtvcc_ctx *dtvcc, struct dtvcc_service_decoder *decoder);
extern int ccxr_dtvcc_init(struct lib_cc_decode *ctx);
extern void ccxr_dtvcc_free(struct lib_cc_decode *ctx);

#endif
1 change: 1 addition & 0 deletions src/lib_ccx/ccx_decoders_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ struct lib_cc_decode
int false_pict_header;

dtvcc_ctx *dtvcc;
void *dtvcc_rust; // Rust Dtvcc instance
int current_field;
// Analyse/use the picture information
int maxtref; // Use to remember the temporal reference number
Expand Down
45 changes: 45 additions & 0 deletions src/lib_ccx/mp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,25 @@
#include "ccx_mp4.h"
#include "activity.h"
#include "ccx_dtvcc.h"
#include "ccx_demuxer.h"
#include "png.h"
#include "ccx_decoders_common.h"

#ifndef DISABLE_RUST
extern int ccxr_dtvcc_init(struct lib_cc_decode *ctx);
extern int ccxr_process_cc_data(struct lib_cc_decode *dec_ctx, unsigned char *cc_data, int cc_count);
#endif

#define MEDIA_TYPE(type, subtype) (((u64)(type) << 32) + (subtype))

#define GF_ISOM_SUBTYPE_C708 GF_4CC('c', '7', '0', '8')

// Convert a 4-byte type to 4 separate bytes for printing
#define PRINT_TYPE(t) (t) & 0xFF, ((t) >> 8) & 0xFF, ((t) >> 16) & 0xFF, ((t) >> 24) & 0xFF
#define ATOMPRINT mprint("Atom: [%c%c%c%c]", PRINT_TYPE(head.type))

#define ATOM_CONTAINS(a, b) (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3])

static short bswap16(short v)
{
return ((v >> 8) & 0x00FF) | ((v << 8) & 0xFF00);
Expand Down Expand Up @@ -418,7 +432,38 @@ static int process_clcp(struct lib_ccx_ctx *ctx, struct encoder_ctx *enc_ctx,
}
// WARN: otherwise cea-708 will not work
dec_ctx->dtvcc->encoder = (void *)enc_ctx;

// Use Rust implementation if available
#ifndef DISABLE_RUST
// Initialize Rust Dtvcc if not already done
if (dec_ctx->dtvcc_rust == NULL) {
if (ccxr_dtvcc_init(dec_ctx) != 0) {
ccx_log("Failed to initialize Rust Dtvcc instance\n");
// Fall back to C implementation
dtvcc_process_data(dec_ctx->dtvcc, (unsigned char *)temp);
return -1;
}
}

if (dec_ctx->dtvcc_rust != NULL)
{
// Process data using Rust implementation
unsigned char cc_block[3];
cc_block[0] = (cc_valid << 2) | cc_type;
cc_block[1] = cc_data[1];
cc_block[2] = cc_data[2];

// For Rust, we send the whole cc_block instead of temp
ccxr_process_cc_data(dec_ctx, cc_block, 1);
}
else
{
// Fallback to C implementation
dtvcc_process_data(dec_ctx->dtvcc, (unsigned char *)temp);
}
#else
dtvcc_process_data(dec_ctx->dtvcc, (unsigned char *)temp);
#endif
cb_708++;
}
if (ctx->write_format == CCX_OF_MCC)
Expand Down
Loading
Loading