From 0e0a00108274801a7d895b1511baa448edc5763a Mon Sep 17 00:00:00 2001 From: IshanGrover2004 Date: Fri, 19 Apr 2024 18:10:10 +0530 Subject: [PATCH 1/7] feat: Add `decoder/encoding` new module This `decoder/encoding.rs` file will contain the content of `lib_ccx/ccx_708_decoder_encoding.c` file --- src/rust/src/decoder/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rust/src/decoder/mod.rs b/src/rust/src/decoder/mod.rs index e13c7ed2d..2ee5c26bc 100644 --- a/src/rust/src/decoder/mod.rs +++ b/src/rust/src/decoder/mod.rs @@ -3,6 +3,7 @@ //! Provides a CEA 708 decoder as defined by ANSI/CTA-708-E R-2018 mod commands; +mod encoding; mod output; mod service_decoder; mod timing; From fc39970e83254272ab1fe5fd4bb85bbb03680713 Mon Sep 17 00:00:00 2001 From: IshanGrover2004 Date: Fri, 19 Apr 2024 18:13:10 +0530 Subject: [PATCH 2/7] feat: Add encoding functions --- src/rust/src/decoder/encoding.rs | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/rust/src/decoder/encoding.rs diff --git a/src/rust/src/decoder/encoding.rs b/src/rust/src/decoder/encoding.rs new file mode 100644 index 000000000..b91e7bd07 --- /dev/null +++ b/src/rust/src/decoder/encoding.rs @@ -0,0 +1,48 @@ +/// 256 BYTES IS ENOUGH FOR ALL THE SUPPORTED CHARACTERS IN +/// EIA-708, SO INTERNALLY WE USE THIS TABLE (FOR CONVENIENCE) +/// +/// 00-1F -> Characters that are in the G2 group in 20-3F, +/// except for 06, which is used for the closed captions +/// sign "CC" which is defined in group G3 as 00. (this +/// is by the article 33). +/// 20-7F -> Group G0 as is - corresponds to the ASCII code +/// 80-9F -> Characters that are in the G2 group in 60-7F +/// (there are several blank characters here, that's OK) +/// A0-FF -> Group G1 as is - non-English characters and symbols + +// NOTE: Same as `lib_ccx/ccx_decoder_708_encoding.c` file + +#[no_mangle] +pub extern "C" fn dtvcc_get_internal_from_G0(g0_char: u8) -> u8 { + g0_char +} + +#[no_mangle] +pub extern "C" fn dtvcc_get_internal_from_G1(g1_char: u8) -> u8 { + g1_char +} + +/// G2: Extended Control Code Set 1 +#[no_mangle] +pub extern "C" fn dtvcc_get_internal_from_G2(g2_char: u8) -> u8 { + if (0x20..=0x3F).contains(&g2_char) { + g2_char - 0x20 + } else if (0x60..=0x7F).contains(&g2_char) { + g2_char + 0x20 + } else { + // Rest unmapped, so we return a blank space + 0x20 + } +} + +/// G3: Future Characters and Icon Expansion +#[no_mangle] +pub extern "C" fn dtvcc_get_internal_from_G3(g3_char: u8) -> u8 { + if g3_char == 0xa0 { + // The "CC" (closed captions) sign + 0x06 + } else { + // Rest unmapped, so we return a blank space + 0x20 + } +} From 0d42f3e5fea16b104be1a942997816a26769b849 Mon Sep 17 00:00:00 2001 From: IshanGrover2004 Date: Fri, 19 Apr 2024 18:14:17 +0530 Subject: [PATCH 3/7] feat: Add conditional compilation to include Rust functions --- src/lib_ccx/ccx_decoders_708_encoding.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib_ccx/ccx_decoders_708_encoding.c b/src/lib_ccx/ccx_decoders_708_encoding.c index 5cf9c74f6..02ebf9203 100644 --- a/src/lib_ccx/ccx_decoders_708_encoding.c +++ b/src/lib_ccx/ccx_decoders_708_encoding.c @@ -12,6 +12,8 @@ EIA-708, SO INTERNALLY WE USE THIS TABLE (FOR CONVENIENCE) A0-FF -> Group G1 as is - non-English characters and symbols */ +#if !defined(DISABLE_RUST) + unsigned char dtvcc_get_internal_from_G0(unsigned char g0_char) { return g0_char; @@ -43,3 +45,5 @@ unsigned char dtvcc_get_internal_from_G3(unsigned char g3_char) // Rest unmapped, so we return a blank space return 0x20; } + +#endif From 37c74f2deb3ee560982061f8409022c17bacfb44 Mon Sep 17 00:00:00 2001 From: IshanGrover2004 Date: Fri, 19 Apr 2024 18:27:06 +0530 Subject: [PATCH 4/7] fix: conditional compilation logic --- src/lib_ccx/ccx_decoders_708_encoding.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_ccx/ccx_decoders_708_encoding.c b/src/lib_ccx/ccx_decoders_708_encoding.c index 02ebf9203..b3d9508d4 100644 --- a/src/lib_ccx/ccx_decoders_708_encoding.c +++ b/src/lib_ccx/ccx_decoders_708_encoding.c @@ -12,7 +12,7 @@ EIA-708, SO INTERNALLY WE USE THIS TABLE (FOR CONVENIENCE) A0-FF -> Group G1 as is - non-English characters and symbols */ -#if !defined(DISABLE_RUST) +#if defined(DISABLE_RUST) unsigned char dtvcc_get_internal_from_G0(unsigned char g0_char) { From b8a7fd6385deeda4f012fb200b801925ed742d4e Mon Sep 17 00:00:00 2001 From: IshanGrover2004 Date: Tue, 21 May 2024 14:09:05 +0530 Subject: [PATCH 5/7] refactor: Use of match statement instead of if-else --- src/rust/src/decoder/encoding.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/rust/src/decoder/encoding.rs b/src/rust/src/decoder/encoding.rs index b91e7bd07..2671cedd9 100644 --- a/src/rust/src/decoder/encoding.rs +++ b/src/rust/src/decoder/encoding.rs @@ -25,13 +25,10 @@ pub extern "C" fn dtvcc_get_internal_from_G1(g1_char: u8) -> u8 { /// G2: Extended Control Code Set 1 #[no_mangle] pub extern "C" fn dtvcc_get_internal_from_G2(g2_char: u8) -> u8 { - if (0x20..=0x3F).contains(&g2_char) { - g2_char - 0x20 - } else if (0x60..=0x7F).contains(&g2_char) { - g2_char + 0x20 - } else { - // Rest unmapped, so we return a blank space - 0x20 + match g2_char { + 0x20..=0x3F => g2_char - 0x20, + 0x60..=0x7F => g2_char + 0x20, + _ => 0x20, } } From 031ac7d2bbdf81068abc95ac9caeecc58e064134 Mon Sep 17 00:00:00 2001 From: IshanGrover2004 Date: Tue, 21 May 2024 14:22:23 +0530 Subject: [PATCH 6/7] fix: Calling C function for rust --- src/lib_ccx/ccx_decoders_708_encoding.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib_ccx/ccx_decoders_708_encoding.h b/src/lib_ccx/ccx_decoders_708_encoding.h index 0318a0f1c..ef7ca2a84 100644 --- a/src/lib_ccx/ccx_decoders_708_encoding.h +++ b/src/lib_ccx/ccx_decoders_708_encoding.h @@ -1,11 +1,18 @@ #ifndef _CCX_DECODERS_708_ENCODING_H_ #define _CCX_DECODERS_708_ENCODING_H_ -#define CCX_DTVCC_MUSICAL_NOTE_CHAR 9836 // Unicode Character 'BEAMED SIXTEENTH NOTES' +#define CCX_DTVCC_MUSICAL_NOTE_CHAR 9836 // Unicode Character 'BEAMED SIXTEENTH NOTES' +#ifndef DISABLE_RUST +extern unsigned char dtvcc_get_internal_from_G0(unsigned char g0_char); +extern unsigned char dtvcc_get_internal_from_G1(unsigned char g1_char); +extern unsigned char dtvcc_get_internal_from_G2(unsigned char g2_char); +extern unsigned char dtvcc_get_internal_from_G3(unsigned char g3_char); +#else unsigned char dtvcc_get_internal_from_G0(unsigned char g0_char); unsigned char dtvcc_get_internal_from_G1(unsigned char g1_char); unsigned char dtvcc_get_internal_from_G2(unsigned char g2_char); unsigned char dtvcc_get_internal_from_G3(unsigned char g3_char); +#endif #endif /*_CCX_DECODERS_708_ENCODING_H_*/ From d79087edf6f936654a298819351a28331574741e Mon Sep 17 00:00:00 2001 From: IshanGrover2004 Date: Sun, 26 May 2024 13:31:01 +0530 Subject: [PATCH 7/7] feat: Enable `derive_default` feature --- src/rust/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rust/build.rs b/src/rust/build.rs index f8ecc04c8..03e6157f6 100644 --- a/src/rust/build.rs +++ b/src/rust/build.rs @@ -59,6 +59,8 @@ fn main() { } let bindings = builder + .derive_default(true) + .no_default("dtvcc_pen_attribs|dtvcc_pen_color|dtvcc_symbol") // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure.