CDPParser

Struct CDPParser 

Source
pub struct CDPParser { /* private fields */ }
Expand description

Parses CDP packets.

§Examples

let mut parser = CDPParser::new();
let data = [
    0x96, 0x69,                // magic
    0x27,                      // cdp_len
    0x3f,                      // framerate
    0x80 | 0x40 | 0x20 | 0x10 | 0x04 | 0x02 | 0x01, // flags
    0x12, 0x34,                // sequence counter
    0x71,                      // time code id
    0xc0 | 0x17,               // hours
    0x80 | 0x59,               // minutes
    0x80 | 0x57,               // seconds
    0x80 | 0x18,               // frames
    0x72,                      // cc_data id
    0xe0 | 0x04,               // cc_count
    0xFC, 0x20, 0x41,          // CEA608 field 1
    0xFD, 0x42, 0x43,          // CEA608 field 2
    0xFF, 0x02, 0x21,          // start CEA708 data
    0xFE, 0x41, 0x00,
    0x73,                      // svc_info id
    0x80 | 0x40 | 0x10 | 0x01, // reserved | start | change | complete | count
    0x80,                      // reserved | service number
    b'e', b'n', b'g',          // language
    0x40 | 0x3e,               // is_digital | reserved | field/service
    0x3f,                      // reader | wide | reserved
    0xff,                      // reserved
    0x74,                      // cdp footer
    0x12, 0x34,                // sequence counter
    0xc4,                      // checksum
];
parser.parse(&data).unwrap();

assert_eq!(parser.sequence(), 0x1234);
assert_eq!(parser.framerate(), Framerate::from_id(0x3));

// Service information
let service_info = parser.service_info().unwrap();
assert!(service_info.is_start());
assert!(!service_info.is_change());
assert!(service_info.is_complete());
let entries = service_info.services();
assert_eq!(entries[0].language(), [b'e', b'n', b'g']);
let FieldOrService::Field(field) = entries[0].service() else {
    unreachable!();
};
assert!(field);

// Time code information
let time_code = parser.time_code().unwrap();
assert_eq!(time_code.hours(), 17);
assert_eq!(time_code.minutes(), 59);
assert_eq!(time_code.seconds(), 57);
assert_eq!(time_code.frames(), 18);
assert!(time_code.field());
assert!(time_code.drop_frame());

// CEA-708 cc_data
let packet = parser.pop_packet().unwrap();
assert_eq!(packet.sequence_no(), 0);

// CEA-608 data
let cea608 = parser.cea608().unwrap();
assert_eq!(cea608, &[Cea608::Field1(0x20, 0x41), Cea608::Field2(0x42, 0x43)]);

Implementations§

Source§

impl CDPParser

Source

pub fn new() -> Self

Create a new CDPParser

Source

pub fn parse(&mut self, data: &[u8]) -> Result<(), ParserError>

Push a complete CDP packet into the parser for processing.

Source

pub fn flush(&mut self)

Clear any internal buffers

Source

pub fn time_code(&self) -> Option<TimeCode>

The latest CDP time code that has been parsed

Source

pub fn framerate(&self) -> Option<Framerate>

The latest CDP framerate that has been parsed

Source

pub fn sequence(&self) -> u16

The latest CDP sequence number that has been parsed

Source

pub fn service_info(&self) -> Option<&ServiceInfo>

The latest Service Descriptor that has been parsed.

Source

pub fn pop_packet(&mut self) -> Option<DTVCCPacket>

Pop a valid cea708_types::DTVCCPacket or None if no packet could be parsed

Source

pub fn cea608(&mut self) -> Option<&[Cea608]>

Pop the list of cea708_types::Cea608 contained in this packet

Trait Implementations§

Source§

impl Debug for CDPParser

Source§

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

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

impl Default for CDPParser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.