Skip to main content

decode_cea608/
decode_cea608.rs

1//! Decode a CEA-608 (line-21) pop-on caption to on-screen text.
2//!
3//! Run with: `cargo run -p cc-data --example decode_cea608`
4
5use broadcast_common::parity::set_odd_parity;
6use cc_data::decode::{Cea608Channel, Cea608Decoder};
7
8fn main() {
9    let mut dec = Cea608Decoder::new();
10
11    // A pop-on caption on CC1 (field 1):
12    //   RCL  (14 20)  — Resume Caption Loading (pop-on)
13    //   PAC  (14 70)  — row 15, white, indent 0
14    //   "HELLO"
15    //   EOC  (14 2F)  — flip back buffer to the screen
16    let pairs: &[(u8, u8)] = &[
17        (0x14, 0x20),
18        (0x14, 0x70),
19        (b'H', b'E'),
20        (b'L', b'L'),
21        (b'O', 0x00),
22        (0x14, 0x2F),
23    ];
24    for &(b1, b2) in pairs {
25        dec.push_pair(false, set_odd_parity(b1), set_odd_parity(b2));
26    }
27
28    println!("CC1 mode : {}", dec.mode(Cea608Channel::Cc1));
29    println!("CC1 text : {:?}", dec.channel_text(Cea608Channel::Cc1));
30
31    // A roll-up caption (2 rows) on CC1.
32    let mut dec2 = Cea608Decoder::new();
33    let roll: &[(u8, u8)] = &[
34        (0x14, 0x25), // RU2
35        (b'O', b'N'),
36        (b'E', 0x00),
37        (0x14, 0x2D), // CR
38        (b'T', b'W'),
39        (b'O', 0x00),
40    ];
41    for &(b1, b2) in roll {
42        dec2.push_pair(false, set_odd_parity(b1), set_odd_parity(b2));
43    }
44    println!("\nRoll-up mode : {}", dec2.mode(Cea608Channel::Cc1));
45    println!("Roll-up text :\n{}", dec2.channel_text(Cea608Channel::Cc1));
46}