use crate::table_id::TableId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
pub struct SubTableQualifier {
pub transport_stream_id: Option<u16>,
pub original_network_id: u16,
}
const ONID_AT: usize = 0;
const EIT_TSID_AT: usize = 0;
const EIT_ONID_AT: usize = 2;
const EIT_FIRST_TABLE_ID: u8 = TableId::EventInformationPfActual as u8;
const EIT_LAST_TABLE_ID: u8 = 0x6F;
impl SubTableQualifier {
#[must_use]
pub fn of(table_id: u8, payload: &[u8]) -> Option<Self> {
let be16 = |at: usize| crate::wire::be_u16(payload, at, "sub_table qualifier").ok();
if table_id == TableId::ServiceDescriptionActual as u8
|| table_id == TableId::ServiceDescriptionOther as u8
{
return Some(Self {
transport_stream_id: None,
original_network_id: be16(ONID_AT)?,
});
}
if (EIT_FIRST_TABLE_ID..=EIT_LAST_TABLE_ID).contains(&table_id) {
return Some(Self {
transport_stream_id: Some(be16(EIT_TSID_AT)?),
original_network_id: be16(EIT_ONID_AT)?,
});
}
None
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
pub struct SubTableId {
pub table_id_extension: u16,
pub current_next_indicator: bool,
pub qualifier: Option<SubTableQualifier>,
}
impl SubTableId {
#[must_use]
pub const fn new(table_id_extension: u16, current_next_indicator: bool) -> Self {
Self {
table_id_extension,
current_next_indicator,
qualifier: None,
}
}
#[must_use]
pub fn of_section(section: &mpeg_ts::section::Section<'_>) -> Self {
Self {
table_id_extension: section.extension_id,
current_next_indicator: section.current_next_indicator,
qualifier: SubTableQualifier::of(section.table_id, section.payload),
}
}
#[must_use]
pub const fn with_qualifier(mut self, qualifier: SubTableQualifier) -> Self {
self.qualifier = Some(qualifier);
self
}
}