pub struct CcData {
pub process_em_data_flag: bool,
pub process_cc_data_flag: bool,
pub additional_data_flag: bool,
pub reserved_byte1: u8,
pub triplets: Vec<CcTriplet>,
}Expand description
cc_data() — the DVB closed-caption carriage structure (Table B.9).
Fields§
§process_em_data_flag: boolByte 0 bit 7. Table B.9 calls it reserved (set to "1"); in the ATSC
A/53 / CEA-708 lineage the same bit is process_em_data_flag, and real
A/53 captures (shaka-player’s captions-test.ts) carry 0 here.
Parsed tolerantly and preserved so the round-trip stays byte-exact;
construct with true to match Table B.9’s own default.
process_cc_data_flag: boolprocess_cc_data_flag — when true, the cc_data is to be processed.
additional_data_flag: boolByte 0 bit 5. Table B.9 calls it zero_bit (set to "0"); in the A/53 /
CEA-708 lineage it is additional_data_flag. Parsed tolerantly and
preserved; construct with false to match Table B.9’s default.
reserved_byte1: u8The byte after cc_count, Table B.9’s reserved (set to "1111 1111").
Real streams (this byte is em_data in the ATSC A/53 lineage this
syntax is shared with) don’t always hold 0xFF here, so it is
preserved verbatim rather than assumed, to keep the round-trip
byte-exact. Construct with 0xFF to match Table B.9’s own default.
triplets: Vec<CcTriplet>The caption constructs (cc_count is triplets.len()).
Implementations§
Source§impl CcData
impl CcData
Sourcepub fn cea608(&self) -> impl Iterator<Item = &CcTriplet>
pub fn cea608(&self) -> impl Iterator<Item = &CcTriplet>
Iterator over the CEA-608 (line-21) triplets.
Examples found in repository?
8fn main() {
9 let cc = CcData {
10 process_em_data_flag: true,
11 process_cc_data_flag: true,
12 additional_data_flag: false,
13 reserved_byte1: 0xFF,
14 triplets: vec![
15 CcTriplet {
16 cc_valid: true,
17 cc_type: CcType::Dtvcc708Start,
18 cc_data_1: 0xC1,
19 cc_data_2: 0x02,
20 },
21 CcTriplet {
22 cc_valid: true,
23 cc_type: CcType::Ntsc608Field1,
24 cc_data_1: 0x94,
25 cc_data_2: 0x2C,
26 },
27 ],
28 };
29
30 let bytes = cc.try_to_bytes().unwrap();
31 println!("serialized {} bytes: {:02X?}", bytes.len(), bytes);
32
33 let back = CcData::parse(&bytes).expect("round-trip parse");
34 assert_eq!(back, cc, "round-trip must be lossless");
35 println!(
36 "round-trip OK — {} triplets ({} 608, {} 708)",
37 back.triplets.len(),
38 back.cea608().count(),
39 back.cea708().count()
40 );
41}More examples
8fn main() {
9 // cc_data: process_cc_data_flag=1, cc_count=2; one DTVCC-start triplet + one
10 // 608-field-1 triplet; trailing 0xFF marker.
11 #[rustfmt::skip]
12 let bytes = [
13 0b1100_0010, // reserved=1, process=1, zero=0, cc_count=2
14 0xFF, // reserved
15 0xFF, 0xC1, 0x02, // one_bit+rsvd(F8) | valid=1 | type=3 (708 start); data C1 02
16 0xFC, 0x94, 0x2C, // F8 | valid=1 | type=0 (608 field1); data 94 2C
17 0xFF, // marker
18 ];
19
20 let cc = CcData::parse(&bytes).expect("valid cc_data");
21 println!("process_cc_data_flag : {}", cc.process_cc_data_flag);
22 println!("triplets : {}", cc.triplets.len());
23 for t in &cc.triplets {
24 println!(
25 " {:<16} valid={} data={:02X} {:02X}",
26 t.cc_type.name(),
27 t.cc_valid,
28 t.cc_data_1,
29 t.cc_data_2
30 );
31 }
32 println!("CEA-608 triplets : {}", cc.cea608().count());
33 println!("CEA-708 triplets : {}", cc.cea708().count());
34}Sourcepub fn cea708(&self) -> impl Iterator<Item = &CcTriplet>
pub fn cea708(&self) -> impl Iterator<Item = &CcTriplet>
Iterator over the CEA-708 (DTVCC) triplets.
Examples found in repository?
8fn main() {
9 let cc = CcData {
10 process_em_data_flag: true,
11 process_cc_data_flag: true,
12 additional_data_flag: false,
13 reserved_byte1: 0xFF,
14 triplets: vec![
15 CcTriplet {
16 cc_valid: true,
17 cc_type: CcType::Dtvcc708Start,
18 cc_data_1: 0xC1,
19 cc_data_2: 0x02,
20 },
21 CcTriplet {
22 cc_valid: true,
23 cc_type: CcType::Ntsc608Field1,
24 cc_data_1: 0x94,
25 cc_data_2: 0x2C,
26 },
27 ],
28 };
29
30 let bytes = cc.try_to_bytes().unwrap();
31 println!("serialized {} bytes: {:02X?}", bytes.len(), bytes);
32
33 let back = CcData::parse(&bytes).expect("round-trip parse");
34 assert_eq!(back, cc, "round-trip must be lossless");
35 println!(
36 "round-trip OK — {} triplets ({} 608, {} 708)",
37 back.triplets.len(),
38 back.cea608().count(),
39 back.cea708().count()
40 );
41}More examples
8fn main() {
9 // cc_data: process_cc_data_flag=1, cc_count=2; one DTVCC-start triplet + one
10 // 608-field-1 triplet; trailing 0xFF marker.
11 #[rustfmt::skip]
12 let bytes = [
13 0b1100_0010, // reserved=1, process=1, zero=0, cc_count=2
14 0xFF, // reserved
15 0xFF, 0xC1, 0x02, // one_bit+rsvd(F8) | valid=1 | type=3 (708 start); data C1 02
16 0xFC, 0x94, 0x2C, // F8 | valid=1 | type=0 (608 field1); data 94 2C
17 0xFF, // marker
18 ];
19
20 let cc = CcData::parse(&bytes).expect("valid cc_data");
21 println!("process_cc_data_flag : {}", cc.process_cc_data_flag);
22 println!("triplets : {}", cc.triplets.len());
23 for t in &cc.triplets {
24 println!(
25 " {:<16} valid={} data={:02X} {:02X}",
26 t.cc_type.name(),
27 t.cc_valid,
28 t.cc_data_1,
29 t.cc_data_2
30 );
31 }
32 println!("CEA-608 triplets : {}", cc.cea608().count());
33 println!("CEA-708 triplets : {}", cc.cea708().count());
34}Trait Implementations§
impl Eq for CcData
Source§impl Serialize for CcData
impl Serialize for CcData
Source§type Error = Error
type Error = Error
Parse impl, but need not be).Source§fn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
serialize_into will write.Source§fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
buf. Returns the number of bytes
written (always equal to serialized_len()).Source§fn try_to_bytes(&self) -> Result<Vec<u8>, Self::Error>
fn try_to_bytes(&self) -> Result<Vec<u8>, Self::Error>
Vec and serialize into it, returning the serializer’s error instead of
panicking. This is the only
allocate-and-serialize entry point: there is deliberately no panicking
to_bytes (hand-built values, or values assembled from damaged wire data,
can violate a wire constraint, so the error must reach the caller).