Skip to main content

CcData

Struct CcData 

Source
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: bool

Byte 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: bool

process_cc_data_flag — when true, the cc_data is to be processed.

§additional_data_flag: bool

Byte 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: u8

The 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

Source

pub fn cea608(&self) -> impl Iterator<Item = &CcTriplet>

Iterator over the CEA-608 (line-21) triplets.

Examples found in repository?
examples/build_cc_data.rs (line 38)
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
Hide additional examples
examples/parse_cc_data.rs (line 32)
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}
Source

pub fn cea708(&self) -> impl Iterator<Item = &CcTriplet>

Iterator over the CEA-708 (DTVCC) triplets.

Examples found in repository?
examples/build_cc_data.rs (line 39)
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
Hide additional examples
examples/parse_cc_data.rs (line 33)
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§

Source§

impl Clone for CcData

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CcData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CcData

Source§

impl<'a> Parse<'a> for CcData

Source§

type Error = Error

The error type this implementer returns. Typically the enclosing crate’s Error enum.
Source§

fn parse(b: &'a [u8]) -> Result<Self>

Parse bytes as Self. Returns Err(Self::Error) on any protocol violation or buffer underrun.
Source§

impl PartialEq for CcData

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for CcData

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Serialize for CcData

Source§

type Error = Error

The error type this implementer returns (usually the same as the corresponding Parse impl, but need not be).
Source§

fn serialized_len(&self) -> usize

Number of bytes serialize_into will write.
Source§

fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>

Write the serialised form into buf. Returns the number of bytes written (always equal to serialized_len()).
Source§

fn try_to_bytes(&self) -> Result<Vec<u8>, Self::Error>

Allocate a 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).
Source§

impl StructuralPartialEq for CcData

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.