Skip to content

Commit abe3fd8

Browse files
authored
some serious code refactoring (#6)
Co-authored-by: vats004 <=>
1 parent 32fd02f commit abe3fd8

File tree

7 files changed

+1345
-1946
lines changed

7 files changed

+1345
-1946
lines changed

src/lib_ccx/ccx_decoders_xds.c

Lines changed: 12 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,23 @@
55
#include "utility.h"
66

77
#ifndef DISABLE_RUST
8-
9-
extern struct ccx_decoders_xds_context *ccxr_ccx_decoders_xds_init_library(
10-
struct ccx_common_timing_ctx timing,
11-
int xds_write_to_file);
12-
13-
extern int ccxr_write_xds_string(
14-
struct cc_subtitle *sub,
15-
struct ccx_decoders_xds_context *ctx,
16-
const char *p,
17-
size_t len);
18-
19-
extern void ccxr_xdsprint(
20-
struct cc_subtitle *sub,
21-
struct ccx_decoders_xds_context *ctx,
22-
const char *_fmt,
23-
va_list args);
24-
25-
extern void ccxr_clear_xds_buffer(
26-
struct ccx_decoders_xds_context *ctx,
27-
int64_t num);
28-
29-
extern int64_t ccxr_how_many_used(
30-
const struct ccx_decoders_xds_context *ctx);
31-
328
extern void ccxr_process_xds_bytes(
339
struct ccx_decoders_xds_context *ctx,
34-
uint8_t hi,
35-
int64_t lo);
36-
37-
extern void ccxr_xds_do_copy_generation_management_system(
38-
struct cc_subtitle *sub,
39-
struct ccx_decoders_xds_context *ctx,
40-
uint8_t c1,
41-
uint8_t c2);
42-
43-
extern void ccxr_xds_do_content_advisory(
44-
struct cc_subtitle *sub,
45-
struct ccx_decoders_xds_context *ctx,
46-
uint8_t c1,
47-
uint8_t c2);
48-
49-
extern int64_t ccxr_xds_do_private_data(
50-
struct cc_subtitle *sub,
51-
struct ccx_decoders_xds_context *ctx);
52-
53-
extern int64_t ccxr_xds_do_misc(
54-
const struct ccx_decoders_xds_context *ctx);
55-
56-
extern int64_t ccxr_xds_do_current_and_future(
57-
struct cc_subtitle *sub,
58-
struct ccx_decoders_xds_context *ctx);
10+
unsigned char hi,
11+
unsigned char lo);
5912

6013
extern void ccxr_do_end_of_xds(
6114
struct cc_subtitle *sub,
6215
struct ccx_decoders_xds_context *ctx,
63-
int64_t expected_checksum);
64-
65-
extern int64_t ccxr_xds_do_channel(
66-
struct cc_subtitle *sub,
67-
struct ccx_decoders_xds_context *ctx);
16+
unsigned char expected_checksum);
6817

69-
extern void ccxr_xds_debug_test(
70-
struct ccx_decoders_xds_context *ctx,
71-
struct cc_subtitle *sub);
18+
extern struct ccx_decoders_xds_context *ccxr_ccx_decoders_xds_init_library(
19+
struct ccx_common_timing_ctx *timing,
20+
int xds_write_to_file);
7221

7322
extern void ccxr_xds_cea608_test(
7423
struct ccx_decoders_xds_context *ctx,
7524
struct cc_subtitle *sub);
76-
7725
#endif
7826

7927
LLONG ts_start_of_xds = -1; // Time at which we switched to XDS mode, =-1 hasn't happened yet
@@ -153,7 +101,7 @@ static const char *XDSProgramTypes[] =
153101
struct ccx_decoders_xds_context *ccx_decoders_xds_init_library(struct ccx_common_timing_ctx *timing, int xds_write_to_file)
154102
{
155103
#ifndef DISABLE_RUST
156-
return ccxr_ccx_decoders_xds_init_library(*timing, xds_write_to_file);
104+
return ccxr_ccx_decoders_xds_init_library(timing, xds_write_to_file); // Use the Rust implementation
157105
#else
158106
int i;
159107
struct ccx_decoders_xds_context *ctx = NULL;
@@ -201,9 +149,6 @@ struct ccx_decoders_xds_context *ccx_decoders_xds_init_library(struct ccx_common
201149

202150
int write_xds_string(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx, char *p, size_t len)
203151
{
204-
#ifndef DISABLE_RUST
205-
return ccxr_write_xds_string(sub, ctx, p, len);
206-
#else
207152
struct eia608_screen *data = NULL;
208153
data = (struct eia608_screen *)realloc(sub->data, (sub->nb_data + 1) * sizeof(*data));
209154
if (!data)
@@ -217,31 +162,25 @@ int write_xds_string(struct cc_subtitle *sub, struct ccx_decoders_xds_context *c
217162
{
218163
sub->data = data;
219164
sub->datatype = CC_DATATYPE_GENERIC;
165+
220166
data = (struct eia608_screen *)sub->data + sub->nb_data;
221167
data->format = SFORMAT_XDS;
222168
data->start_time = ts_start_of_xds;
223169
data->end_time = get_fts(ctx->timing, 2);
224170
data->xds_str = p;
225171
data->xds_len = len;
226172
data->cur_xds_packet_class = ctx->cur_xds_packet_class;
173+
227174
sub->nb_data++;
228175
sub->type = CC_608;
229176
sub->got_output = 1;
230177
}
231178

232179
return 0;
233-
#endif
234180
}
235181

236182
void xdsprint(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx, const char *fmt, ...)
237183
{
238-
#ifndef DISABLE_RUST
239-
va_list ap;
240-
va_start(ap, fmt);
241-
ccxr_xdsprint(sub, ctx, fmt, ap);
242-
va_end(ap);
243-
#else
244-
245184
if (!ctx->xds_write_to_file)
246185
return;
247186
/* Guess we need no more than 100 bytes. */
@@ -279,24 +218,19 @@ void xdsprint(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx, con
279218
p = np;
280219
}
281220
}
282-
#endif
283221
}
284222

285223
void xds_debug_test(struct ccx_decoders_xds_context *ctx, struct cc_subtitle *sub)
286224
{
287-
#ifndef DISABLE_RUST
288-
ccxr_xds_debug_test(ctx, sub);
289-
#else
290225
process_xds_bytes(ctx, 0x05, 0x02);
291226
process_xds_bytes(ctx, 0x20, 0x20);
292227
do_end_of_xds(sub, ctx, 0x2a);
293-
#endif
294228
}
295229

296230
void xds_cea608_test(struct ccx_decoders_xds_context *ctx, struct cc_subtitle *sub)
297231
{
298232
#ifndef DISABLE_RUST
299-
ccxr_xds_cea608_test(ctx, sub);
233+
return ccxr_xds_cea608_test(ctx, sub);
300234
#else
301235
/* This test is the sample data that comes in CEA-608. It sets the program name
302236
to be "Star Trek". The checksum is 0x1d and the validation must succeed. */
@@ -314,34 +248,26 @@ void xds_cea608_test(struct ccx_decoders_xds_context *ctx, struct cc_subtitle *s
314248

315249
int how_many_used(struct ccx_decoders_xds_context *ctx)
316250
{
317-
#ifndef DISABLE_RUST
318-
ccxr_how_many_used(ctx);
319-
#else
320251
int c = 0;
321252
for (int i = 0; i < NUM_XDS_BUFFERS; i++)
322253
if (ctx->xds_buffers[i].in_use)
323254
c++;
324255
return c;
325-
#endif
326256
}
327257

328258
void clear_xds_buffer(struct ccx_decoders_xds_context *ctx, int num)
329259
{
330-
#ifndef DISABLE_RUST
331-
ccxr_clear_xds_buffer(ctx, num);
332-
#else
333260
ctx->xds_buffers[num].in_use = 0;
334261
ctx->xds_buffers[num].xds_class = -1;
335262
ctx->xds_buffers[num].xds_type = -1;
336263
ctx->xds_buffers[num].used_bytes = 0;
337264
memset(ctx->xds_buffers[num].bytes, 0, NUM_BYTES_PER_PACKET);
338-
#endif
339265
}
340266

341267
void process_xds_bytes(struct ccx_decoders_xds_context *ctx, const unsigned char hi, int lo)
342268
{
343269
#ifndef DISABLE_RUST
344-
ccxr_process_xds_bytes(ctx, hi, lo);
270+
return ccxr_process_xds_bytes(ctx, hi, lo); // Use the Rust implementation
345271
#else
346272
int is_new;
347273
if (!ctx)
@@ -420,9 +346,6 @@ void process_xds_bytes(struct ccx_decoders_xds_context *ctx, const unsigned char
420346
*/
421347
void xds_do_copy_generation_management_system(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx, unsigned c1, unsigned c2)
422348
{
423-
#ifndef DISABLE_RUST
424-
ccxr_xds_do_copy_generation_management_system(sub, ctx, c1, c2);
425-
#else
426349
static unsigned last_c1 = -1, last_c2 = -1;
427350
static char copy_permited[256];
428351
static char aps[256];
@@ -476,14 +399,10 @@ void xds_do_copy_generation_management_system(struct cc_subtitle *sub, struct cc
476399
ccx_common_logging.debug_ftn(CCX_DMT_DECODER_XDS, "\rXDS: %s\n", copy_permited);
477400
ccx_common_logging.debug_ftn(CCX_DMT_DECODER_XDS, "\rXDS: %s\n", aps);
478401
ccx_common_logging.debug_ftn(CCX_DMT_DECODER_XDS, "\rXDS: %s\n", rcd);
479-
#endif
480402
}
481403

482404
void xds_do_content_advisory(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx, unsigned c1, unsigned c2)
483405
{
484-
#ifndef DISABLE_RUST
485-
ccxr_xds_do_content_advisory(sub, ctx, c1, c2);
486-
#else
487406
static unsigned last_c1 = -1, last_c2 = -1;
488407
static char age[256];
489408
static char content[256];
@@ -593,14 +512,10 @@ void xds_do_content_advisory(struct cc_subtitle *sub, struct ccx_decoders_xds_co
593512

594513
if (changed && !supported)
595514
ccx_common_logging.log_ftn("XDS: Unsupported ContentAdvisory encoding, please submit sample.\n");
596-
#endif
597515
}
598516

599517
int xds_do_current_and_future(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx)
600518
{
601-
#ifndef DISABLE_RUST
602-
ccxr_xds_do_current_and_future(sub, ctx);
603-
#else
604519
int was_proc = 0;
605520

606521
char *str = malloc(1024);
@@ -847,14 +762,10 @@ int xds_do_current_and_future(struct cc_subtitle *sub, struct ccx_decoders_xds_c
847762

848763
free(str);
849764
return was_proc;
850-
#endif
851765
}
852766

853767
int xds_do_channel(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx)
854768
{
855-
#ifndef DISABLE_RUST
856-
ccxr_xds_do_channel(sub, ctx);
857-
#else
858769
int was_proc = 0;
859770
if (!ctx)
860771
return CCX_EINVAL;
@@ -914,14 +825,10 @@ int xds_do_channel(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx
914825
break;
915826
}
916827
return was_proc;
917-
#endif
918828
}
919829

920830
int xds_do_private_data(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx)
921831
{
922-
#ifndef DISABLE_RUST
923-
ccxr_xds_do_private_data(sub, ctx);
924-
#else
925832
char *str;
926833
int i;
927834

@@ -938,14 +845,10 @@ int xds_do_private_data(struct cc_subtitle *sub, struct ccx_decoders_xds_context
938845
xdsprint(sub, ctx, str);
939846
free(str);
940847
return 1;
941-
#endif
942848
}
943849

944850
int xds_do_misc(struct ccx_decoders_xds_context *ctx)
945851
{
946-
#ifndef DISABLE_RUST
947-
ccxr_xds_do_misc(ctx);
948-
#else
949852
int was_proc = 0;
950853
if (!ctx)
951854
return CCX_EINVAL;
@@ -985,13 +888,12 @@ int xds_do_misc(struct ccx_decoders_xds_context *ctx)
985888
break;
986889
}
987890
return was_proc;
988-
#endif
989891
}
990892

991893
void do_end_of_xds(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx, unsigned char expected_checksum)
992894
{
993895
#ifndef DISABLE_RUST
994-
ccxr_do_end_of_xds(sub, ctx, expected_checksum);
896+
return ccxr_do_end_of_xds(sub, ctx, expected_checksum);
995897
#else
996898

997899
int cs = 0;

src/lib_ccx/ccx_decoders_xds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void do_end_of_xds (struct cc_subtitle *sub, struct ccx_decoders_xds_context *ct
1212

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

15-
void xds_cea608_test();
15+
void xds_cea608_test(struct ccx_decoders_xds_context *ctx, struct cc_subtitle *sub);
1616

1717
struct xds_buffer
1818
{
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// codes for do_end_of_xds
2+
pub const XDS_CLASS_FUTURE: i64 = 1;
3+
pub const XDS_CLASS_CHANNEL: i64 = 2;
4+
pub const XDS_CLASS_MISC: i64 = 3;
5+
pub const XDS_CLASS_PRIVATE: i64 = 6;
6+
pub const XDS_CLASS_OUT_OF_BAND: i64 = 0x40;
7+
8+
// codes for xds_do_misc
9+
pub const XDS_TYPE_TIME_OF_DAY: i64 = 1;
10+
pub const XDS_TYPE_LOCAL_TIME_ZONE: i64 = 4;
11+
12+
// codes for xds_do_channel
13+
pub const XDS_TYPE_NETWORK_NAME: i64 = 1;
14+
pub const XDS_TYPE_CALL_LETTERS_AND_CHANNEL: i64 = 2;
15+
pub const XDS_TYPE_TSID: i64 = 4;
16+
17+
// codes for xds_do_current_and_future
18+
pub const XDS_CLASS_CURRENT: i64 = 0;
19+
20+
pub const XDS_TYPE_PIN_START_TIME: i64 = 1;
21+
pub const XDS_TYPE_LENGTH_AND_CURRENT_TIME: i64 = 2;
22+
pub const XDS_TYPE_PROGRAM_NAME: i64 = 3;
23+
pub const XDS_TYPE_PROGRAM_TYPE: i64 = 4;
24+
pub const XDS_TYPE_CONTENT_ADVISORY: i64 = 5;
25+
pub const XDS_TYPE_AUDIO_SERVICES: i64 = 6;
26+
pub const XDS_TYPE_CGMS: i64 = 8;
27+
pub const XDS_TYPE_ASPECT_RATIO_INFO: i64 = 9;
28+
29+
pub const XDS_TYPE_PROGRAM_DESC_1: i64 = 0x10;
30+
pub const XDS_TYPE_PROGRAM_DESC_8: i64 = 0x17;
31+
32+
// codes for write_xds_string
33+
pub const TS_START_OF_XDS: i64 = -1; // Time at which we switched to XDS mode, =-1 hasn't happened yet
34+
35+
// codes for Eia608Screen::default
36+
pub const CCX_DECODER_608_SCREEN_ROWS: usize = 15;
37+
pub const CCX_DECODER_608_SCREEN_WIDTH: usize = 32;
38+
39+
// codes for CcxDecodersXdsContext::default
40+
pub const NUM_XDS_BUFFERS: usize = 9;
41+
42+
// codes for XdsBuffer::default
43+
pub const NUM_BYTES_PER_PACKET: usize = 35;

0 commit comments

Comments
 (0)