Skip to content

[FEAT] Add module decoder_xds to lib_ccxr #1679

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 2 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions src/lib_ccx/ccx_decoders_xds.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@
#include "ccx_common_common.h"
#include "utility.h"

#ifndef DISABLE_RUST
extern void ccxr_process_xds_bytes(
struct ccx_decoders_xds_context *ctx,
unsigned char hi,
unsigned char lo);

extern void ccxr_do_end_of_xds(
struct cc_subtitle *sub,
struct ccx_decoders_xds_context *ctx,
unsigned char expected_checksum);

extern struct ccx_decoders_xds_context *ccxr_ccx_decoders_xds_init_library(
struct ccx_common_timing_ctx *timing,
int xds_write_to_file);

extern void ccxr_xds_cea608_test(
struct ccx_decoders_xds_context *ctx,
struct cc_subtitle *sub);
#endif

LLONG ts_start_of_xds = -1; // Time at which we switched to XDS mode, =-1 hasn't happened yet

static const char *XDSclasses[] =
Expand Down Expand Up @@ -80,6 +100,9 @@ static const char *XDSProgramTypes[] =

struct ccx_decoders_xds_context *ccx_decoders_xds_init_library(struct ccx_common_timing_ctx *timing, int xds_write_to_file)
{
#ifndef DISABLE_RUST
return ccxr_ccx_decoders_xds_init_library(timing, xds_write_to_file); // Use the Rust implementation
#else
int i;
struct ccx_decoders_xds_context *ctx = NULL;

Expand Down Expand Up @@ -121,6 +144,7 @@ struct ccx_decoders_xds_context *ccx_decoders_xds_init_library(struct ccx_common
ctx->xds_write_to_file = xds_write_to_file;

return ctx;
#endif
}

int write_xds_string(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx, char *p, size_t len)
Expand All @@ -138,13 +162,15 @@ int write_xds_string(struct cc_subtitle *sub, struct ccx_decoders_xds_context *c
{
sub->data = data;
sub->datatype = CC_DATATYPE_GENERIC;

data = (struct eia608_screen *)sub->data + sub->nb_data;
data->format = SFORMAT_XDS;
data->start_time = ts_start_of_xds;
data->end_time = get_fts(ctx->timing, 2);
data->xds_str = p;
data->xds_len = len;
data->cur_xds_packet_class = ctx->cur_xds_packet_class;

sub->nb_data++;
sub->type = CC_608;
sub->got_output = 1;
Expand Down Expand Up @@ -203,6 +229,9 @@ void xds_debug_test(struct ccx_decoders_xds_context *ctx, struct cc_subtitle *su

void xds_cea608_test(struct ccx_decoders_xds_context *ctx, struct cc_subtitle *sub)
{
#ifndef DISABLE_RUST
return ccxr_xds_cea608_test(ctx, sub);
#else
/* This test is the sample data that comes in CEA-608. It sets the program name
to be "Star Trek". The checksum is 0x1d and the validation must succeed. */
process_xds_bytes(ctx, 0x01, 0x03);
Expand All @@ -214,6 +243,7 @@ void xds_cea608_test(struct ccx_decoders_xds_context *ctx, struct cc_subtitle *s
process_xds_bytes(ctx, 0x02, 0x03);
process_xds_bytes(ctx, 0x6b, 0x00);
do_end_of_xds(sub, ctx, 0x1d);
#endif
}

int how_many_used(struct ccx_decoders_xds_context *ctx)
Expand All @@ -236,6 +266,9 @@ void clear_xds_buffer(struct ccx_decoders_xds_context *ctx, int num)

void process_xds_bytes(struct ccx_decoders_xds_context *ctx, const unsigned char hi, int lo)
{
#ifndef DISABLE_RUST
return ccxr_process_xds_bytes(ctx, hi, lo); // Use the Rust implementation
#else
int is_new;
if (!ctx)
return;
Expand Down Expand Up @@ -305,7 +338,9 @@ void process_xds_bytes(struct ccx_decoders_xds_context *ctx, const unsigned char
ctx->xds_buffers[ctx->cur_xds_buffer_idx].bytes[ctx->xds_buffers[ctx->cur_xds_buffer_idx].used_bytes++] = lo;
ctx->xds_buffers[ctx->cur_xds_buffer_idx].bytes[ctx->xds_buffers[ctx->cur_xds_buffer_idx].used_bytes] = 0;
}
#endif
}

/**
* ctx XDS context can be NULL, if user don't want to write xds in transcript
*/
Expand Down Expand Up @@ -857,6 +892,10 @@ int xds_do_misc(struct ccx_decoders_xds_context *ctx)

void do_end_of_xds(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx, unsigned char expected_checksum)
{
#ifndef DISABLE_RUST
return ccxr_do_end_of_xds(sub, ctx, expected_checksum);
#else

int cs = 0;
int i;

Expand Down Expand Up @@ -935,4 +974,5 @@ void do_end_of_xds(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx
dump(CCX_DMT_DECODER_XDS, ctx->cur_xds_payload, ctx->cur_xds_payload_length, 0, 0);
}
clear_xds_buffer(ctx, ctx->cur_xds_buffer_idx);
#endif
}
2 changes: 1 addition & 1 deletion src/lib_ccx/ccx_decoders_xds.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void do_end_of_xds (struct cc_subtitle *sub, struct ccx_decoders_xds_context *ct

struct ccx_decoders_xds_context *ccx_decoders_xds_init_library(struct ccx_common_timing_ctx *timing, int xds_write_to_file);

void xds_cea608_test();
void xds_cea608_test(struct ccx_decoders_xds_context *ctx, struct cc_subtitle *sub);

struct xds_buffer
{
Expand Down
1 change: 1 addition & 0 deletions src/rust/lib_ccxr/src/common/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl Default for EncodersTranscriptFormat {
}
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub enum FrameType {
#[default]
Expand Down
43 changes: 43 additions & 0 deletions src/rust/lib_ccxr/src/decoder_xds/exit_codes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// codes for do_end_of_xds
pub const XDS_CLASS_FUTURE: i64 = 1;
pub const XDS_CLASS_CHANNEL: i64 = 2;
pub const XDS_CLASS_MISC: i64 = 3;
pub const XDS_CLASS_PRIVATE: i64 = 6;
pub const XDS_CLASS_OUT_OF_BAND: i64 = 0x40;

// codes for xds_do_misc
pub const XDS_TYPE_TIME_OF_DAY: i64 = 1;
pub const XDS_TYPE_LOCAL_TIME_ZONE: i64 = 4;

// codes for xds_do_channel
pub const XDS_TYPE_NETWORK_NAME: i64 = 1;
pub const XDS_TYPE_CALL_LETTERS_AND_CHANNEL: i64 = 2;
pub const XDS_TYPE_TSID: i64 = 4;

// codes for xds_do_current_and_future
pub const XDS_CLASS_CURRENT: i64 = 0;

pub const XDS_TYPE_PIN_START_TIME: i64 = 1;
pub const XDS_TYPE_LENGTH_AND_CURRENT_TIME: i64 = 2;
pub const XDS_TYPE_PROGRAM_NAME: i64 = 3;
pub const XDS_TYPE_PROGRAM_TYPE: i64 = 4;
pub const XDS_TYPE_CONTENT_ADVISORY: i64 = 5;
pub const XDS_TYPE_AUDIO_SERVICES: i64 = 6;
pub const XDS_TYPE_CGMS: i64 = 8;
pub const XDS_TYPE_ASPECT_RATIO_INFO: i64 = 9;

pub const XDS_TYPE_PROGRAM_DESC_1: i64 = 0x10;
pub const XDS_TYPE_PROGRAM_DESC_8: i64 = 0x17;

// codes for write_xds_string
pub const TS_START_OF_XDS: i64 = -1; // Time at which we switched to XDS mode, =-1 hasn't happened yet

// codes for Eia608Screen::default
pub const CCX_DECODER_608_SCREEN_ROWS: usize = 15;
pub const CCX_DECODER_608_SCREEN_WIDTH: usize = 32;

// codes for CcxDecodersXdsContext::default
pub const NUM_XDS_BUFFERS: usize = 9;

// codes for XdsBuffer::default
pub const NUM_BYTES_PER_PACKET: usize = 35;
Loading
Loading