CDPWriter

Struct CDPWriter 

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

A struct for writing a stream of CDPs

§Examples

use cdp_types::cea708_types::{Cea608, DTVCCPacket, Service, tables};

let mut writer = CDPWriter::new();
writer.set_sequence_count(3);
let mut packet = DTVCCPacket::new(0);
let mut service = Service::new(1);
service.push_code(&tables::Code::LatinCapitalA).unwrap();
packet.push_service(service).unwrap();
writer.push_packet(packet);

writer.push_cea608(Cea608::Field1(0x41, 0x80));

writer.set_time_code(Some(TimeCode::new(1, 2, 3, 4, true, false)));

let mut service_info = ServiceInfo::default();
service_info.set_start(true);
service_info.set_complete(true);
let entry = ServiceEntry::new([b'e', b'n', b'g'], FieldOrService::Field(true));
service_info.add_service(entry);
let entry = ServiceEntry::new(
    [b'e', b'n', b'g'],
    FieldOrService::Service(DigitalServiceEntry::new(1, false, true))
);
service_info.add_service(entry);
writer.set_service_info(Some(service_info));

let framerate = Framerate::from_id(4).unwrap();
let mut data = vec![];
writer.write(framerate, &mut data).unwrap();

let expected = [
    0x96, 0x69,         // magic
    0x5e,               // CDP length
    0x4f,               // framerate
    0xf7,               // flags
    0x00, 0x03,         // sequence counter
    0x71,               // time code start
    0xc1,               // hours
    0x82,               // minutes
    0x83,               // seconds
    0x04,               // frames
    0x72,               // cc_data id
    0xf4,               // cc_data count
    0xfc, 0x41, 0x80,   // CEA-608 field 1
    0xf9, 0x80, 0x80,   // CEA-608 field 2
    0xff, 0x02, 0x21,   // CEA-708 start
    0xfe, 0x41, 0x00,   // CEA-708 continued
    0xfa, 0x00, 0x00,   // CEA-708 padding
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0xfa, 0x00, 0x00,   // .
    0x73,               // service info id
    0xd2,               // start | change | complete | count
    0x80,               // service no
    b'e', b'n', b'g',   // language
    0x7e,               // is_digital | ignored
    0x3f, 0xff,         // ignored | reserved
    0x81,               // service no
    b'e', b'n', b'g',   // language
    0xc1,               // is_digital | service no
    0x7f, 0xff,         // easy_reader | wide_aspect_ratio | reserved
    0x74,               // footer id
    0x00, 0x03,         // sequence counter
    0xd6,               // checksum
];
assert_eq!(&data, &expected);

Implementations§

Source§

impl CDPWriter

Source

pub fn new() -> Self

Construct a new CDPWriter.

Source

pub fn push_packet(&mut self, packet: DTVCCPacket)

Push a cea708_types::DTVCCPacket for writing

Source

pub fn push_cea608(&mut self, cea608: Cea608)

Push a cea708_types::Cea608 byte pair for writing

Source

pub fn set_time_code(&mut self, time_code: Option<TimeCode>)

Set the optional time code to use for the next CDP packet that is generated.

Source

pub fn set_service_info(&mut self, service_info: Option<ServiceInfo>)

Set the optional ServiceInfo for the next CDP packet that is generated.

Source

pub fn set_sequence_count(&mut self, sequence: u16)

Set the next packet’s sequence count to a specific value

Source

pub fn flush(&mut self)

Clear all stored data

Source

pub fn write<W: Write>( &mut self, framerate: Framerate, w: &mut W, ) -> Result<(), Error>

Write the next CDP packet taking the next relevant CEA-608 byte pairs and cea708_types::DTVCCPackets.

Trait Implementations§

Source§

impl Debug for CDPWriter

Source§

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

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

impl Default for CDPWriter

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.