Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build status](https://github.com/ystreet/cdp-types/workflows/Build/badge.svg?branch=main)](https://github.com/ystreet/cdp-types/actions)
[![Build status](https://github.com/ystreet/cdp-types/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/ystreet/cdp-types/actions)
[![Dependencies](https://deps.rs/repo/github/ystreet/cdp-types/status.svg)](https://deps.rs/repo/github/ystreet/cdp-types)
[![crates.io](https://img.shields.io/crates/v/cdp-types.svg)](https://crates.io/crates/cdp-types)
[![docs.rs](https://docs.rs/cdp-types/badge.svg)](https://docs.rs/cdp-types)
Expand Down
17 changes: 15 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum ParserError {
Cea608AfterCea708,
/// Failed to validate the checksum
ChecksumFailed,
/// Sequence count differs between the header and the footer. Usuall indicates this packet was
/// Sequence count differs between the header and the footer. Usually indicates this packet was
/// spliced together incorrectly.
SequenceCountMismatch,
}
Expand Down Expand Up @@ -109,32 +109,39 @@ static FRAMERATES: [Framerate; 8] = [
},
];

/// A framerate as found in a CDP.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Framerate {
id: u8,
numer: u32,
denom: u32,
}

/// A CDP framerate.
impl Framerate {
/// Create a [`Framerate`] from an identifier as found in a CDP.
pub fn from_id(id: u8) -> Option<Framerate> {
FRAMERATES.iter().find(|f| f.id == id).copied()
}

/// The identifier for this [`Framerate`] in a CDP.
pub fn id(&self) -> u8 {
self.id
}

/// The numerator component of this [`Framerate`]
pub fn numer(&self) -> u32 {
self.numer
}

/// The denominator component of this [`Framerate`]
pub fn denom(&self) -> u32 {
self.denom
}
}

pub struct Flags {
/// A set of flags available in a CDP.
struct Flags {
time_code: bool,
cc_data: bool,
svc_info: bool,
Expand Down Expand Up @@ -198,6 +205,7 @@ impl From<Flags> for u8 {
}
}

/// A time code as available in a CDP.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TimeCode {
hours: u8,
Expand All @@ -208,6 +216,7 @@ pub struct TimeCode {
drop_frame: bool,
}

/// Parses CDP packets.
#[derive(Debug, Default)]
pub struct CDPParser {
cc_data_parser: cea708_types::CCDataParser,
Expand Down Expand Up @@ -446,14 +455,17 @@ impl CDPParser {
*self = Self::default();
}

/// The latest CDP time code that has been parsed
pub fn time_code(&self) -> Option<TimeCode> {
self.time_code
}

/// The latest CDP framerate that has been parsed
pub fn framerate(&self) -> Option<Framerate> {
self.framerate
}

/// The latest CDP sequence number that has been parsed
pub fn sequence(&self) -> u16 {
self.sequence
}
Expand All @@ -463,6 +475,7 @@ impl CDPParser {
self.cc_data_parser.pop_packet()
}

/// Pop the list of [`cea708_types::Cea608`] contained in this packet
pub fn cea608(&mut self) -> Option<&[cea708_types::Cea608]> {
self.cc_data_parser.cea608()
}
Expand Down