use crate::descriptors::SpliceDescriptor;
use crate::time::{BreakDuration, SpliceTime};
use std::fmt;
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SpliceInfoSection {
pub table_id: u8,
pub section_syntax_indicator: u8,
pub private_indicator: u8,
pub sap_type: u8,
pub section_length: u16,
pub protocol_version: u8,
pub encrypted_packet: u8,
pub encryption_algorithm: u8,
pub pts_adjustment: u64,
pub cw_index: u8,
pub tier: u16,
pub splice_command_length: u16,
pub splice_command_type: u8,
pub splice_command: SpliceCommand,
pub descriptor_loop_length: u16,
pub splice_descriptors: Vec<SpliceDescriptor>,
#[cfg_attr(
feature = "serde",
serde(
serialize_with = "crate::serde::serialize_bytes",
deserialize_with = "crate::serde::deserialize_bytes"
)
)]
pub alignment_stuffing_bits: Vec<u8>,
pub e_crc_32: Option<u32>,
pub crc_32: u32,
}
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(tag = "type"))]
pub enum SpliceCommand {
SpliceNull,
SpliceSchedule(SpliceSchedule),
SpliceInsert(SpliceInsert),
TimeSignal(TimeSignal),
BandwidthReservation(BandwidthReservation),
PrivateCommand(PrivateCommand),
Unknown,
}
#[derive(Debug, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SpliceNull {}
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SpliceSchedule {
pub splice_event_id: u32,
pub splice_event_cancel_indicator: u8,
pub reserved: u8,
pub out_of_network_indicator: u8,
pub duration_flag: u8,
pub splice_duration: Option<u32>,
pub utc_splice_time: Option<u32>,
pub unique_program_id: u16,
pub num_splice: u8,
pub component_list: Vec<ComponentSplice>,
}
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SpliceInsert {
pub splice_event_id: u32,
pub splice_event_cancel_indicator: u8,
pub reserved: u8,
pub out_of_network_indicator: u8,
pub program_splice_flag: u8,
pub duration_flag: u8,
pub splice_immediate_flag: u8,
pub reserved2: u8,
pub splice_time: Option<SpliceTime>,
pub component_count: u8,
pub components: Vec<SpliceInsertComponent>,
pub break_duration: Option<BreakDuration>,
pub unique_program_id: u16,
pub avail_num: u8,
pub avails_expected: u8,
}
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TimeSignal {
pub splice_time: SpliceTime,
}
#[derive(Debug, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BandwidthReservation {
pub reserved: u8,
pub dwbw_reservation: u32,
}
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PrivateCommand {
pub private_command_id: u16,
pub private_command_length: u8,
#[cfg_attr(
feature = "serde",
serde(
serialize_with = "crate::serde::serialize_bytes",
deserialize_with = "crate::serde::deserialize_bytes"
)
)]
pub private_bytes: Vec<u8>,
}
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ComponentSplice {
pub component_tag: u8,
pub reserved: u8,
pub splice_mode_indicator: u8,
pub duration_flag: u8,
pub splice_duration: Option<u32>,
pub utc_splice_time: Option<u32>,
}
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SpliceInsertComponent {
pub component_tag: u8,
pub splice_time: Option<SpliceTime>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum SegmentationType {
#[default]
NotIndicated,
ContentIdentification,
ProgramStart,
ProgramEnd,
ProgramEarlyTermination,
ProgramBreakaway,
ProgramResumption,
ProgramRunoverPlanned,
ProgramRunoverUnplanned,
ProgramOverlapStart,
ProgramBlackoutOverride,
ProgramJoin,
ChapterStart,
ChapterEnd,
BreakStart,
BreakEnd,
OpeningCreditStartDeprecated,
OpeningCreditEndDeprecated,
ClosingCreditStartDeprecated,
ClosingCreditEndDeprecated,
ProviderAdvertisementStart,
ProviderAdvertisementEnd,
DistributorAdvertisementStart,
DistributorAdvertisementEnd,
ProviderPlacementOpportunityStart,
ProviderPlacementOpportunityEnd,
DistributorPlacementOpportunityStart,
DistributorPlacementOpportunityEnd,
ProviderOverlayPlacementOpportunityStart,
ProviderOverlayPlacementOpportunityEnd,
DistributorOverlayPlacementOpportunityStart,
DistributorOverlayPlacementOpportunityEnd,
ProviderPromoStart,
ProviderPromoEnd,
DistributorPromoStart,
DistributorPromoEnd,
UnscheduledEventStart,
UnscheduledEventEnd,
AlternateContentOpportunityStart,
AlternateContentOpportunityEnd,
ProviderAdBlockStart,
ProviderAdBlockEnd,
DistributorAdBlockStart,
DistributorAdBlockEnd,
NetworkStart,
NetworkEnd,
}
impl SegmentationType {
pub fn id(&self) -> u8 {
use SegmentationType::*;
match self {
NotIndicated => 0x00,
ContentIdentification => 0x01,
ProgramStart => 0x10,
ProgramEnd => 0x11,
ProgramEarlyTermination => 0x12,
ProgramBreakaway => 0x13,
ProgramResumption => 0x14,
ProgramRunoverPlanned => 0x15,
ProgramRunoverUnplanned => 0x16,
ProgramOverlapStart => 0x17,
ProgramBlackoutOverride => 0x18,
ProgramJoin => 0x19,
ChapterStart => 0x20,
ChapterEnd => 0x21,
BreakStart => 0x22,
BreakEnd => 0x23,
OpeningCreditStartDeprecated => 0x24,
OpeningCreditEndDeprecated => 0x25,
ClosingCreditStartDeprecated => 0x26,
ClosingCreditEndDeprecated => 0x27,
ProviderAdvertisementStart => 0x30,
ProviderAdvertisementEnd => 0x31,
DistributorAdvertisementStart => 0x32,
DistributorAdvertisementEnd => 0x33,
ProviderPlacementOpportunityStart => 0x34,
ProviderPlacementOpportunityEnd => 0x35,
DistributorPlacementOpportunityStart => 0x36,
DistributorPlacementOpportunityEnd => 0x37,
ProviderOverlayPlacementOpportunityStart => 0x38,
ProviderOverlayPlacementOpportunityEnd => 0x39,
DistributorOverlayPlacementOpportunityStart => 0x3A,
DistributorOverlayPlacementOpportunityEnd => 0x3B,
ProviderPromoStart => 0x3C,
ProviderPromoEnd => 0x3D,
DistributorPromoStart => 0x3E,
DistributorPromoEnd => 0x3F,
UnscheduledEventStart => 0x40,
UnscheduledEventEnd => 0x41,
AlternateContentOpportunityStart => 0x42,
AlternateContentOpportunityEnd => 0x43,
ProviderAdBlockStart => 0x44,
ProviderAdBlockEnd => 0x45,
DistributorAdBlockStart => 0x46,
DistributorAdBlockEnd => 0x47,
NetworkStart => 0x50,
NetworkEnd => 0x51,
}
}
pub fn from_id(id: u8) -> Self {
use SegmentationType::*;
match id {
0x00 => NotIndicated,
0x01 => ContentIdentification,
0x10 => ProgramStart,
0x11 => ProgramEnd,
0x12 => ProgramEarlyTermination,
0x13 => ProgramBreakaway,
0x14 => ProgramResumption,
0x15 => ProgramRunoverPlanned,
0x16 => ProgramRunoverUnplanned,
0x17 => ProgramOverlapStart,
0x18 => ProgramBlackoutOverride,
0x19 => ProgramJoin,
0x20 => ChapterStart,
0x21 => ChapterEnd,
0x22 => BreakStart,
0x23 => BreakEnd,
0x24 => OpeningCreditStartDeprecated,
0x25 => OpeningCreditEndDeprecated,
0x26 => ClosingCreditStartDeprecated,
0x27 => ClosingCreditEndDeprecated,
0x30 => ProviderAdvertisementStart,
0x31 => ProviderAdvertisementEnd,
0x32 => DistributorAdvertisementStart,
0x33 => DistributorAdvertisementEnd,
0x34 => ProviderPlacementOpportunityStart,
0x35 => ProviderPlacementOpportunityEnd,
0x36 => DistributorPlacementOpportunityStart,
0x37 => DistributorPlacementOpportunityEnd,
0x38 => ProviderOverlayPlacementOpportunityStart,
0x39 => ProviderOverlayPlacementOpportunityEnd,
0x3A => DistributorOverlayPlacementOpportunityStart,
0x3B => DistributorOverlayPlacementOpportunityEnd,
0x3C => ProviderPromoStart,
0x3D => ProviderPromoEnd,
0x3E => DistributorPromoStart,
0x3F => DistributorPromoEnd,
0x40 => UnscheduledEventStart,
0x41 => UnscheduledEventEnd,
0x42 => AlternateContentOpportunityStart,
0x43 => AlternateContentOpportunityEnd,
0x44 => ProviderAdBlockStart,
0x45 => ProviderAdBlockEnd,
0x46 => DistributorAdBlockStart,
0x47 => DistributorAdBlockEnd,
0x50 => NetworkStart,
0x51 => NetworkEnd,
_ => NotIndicated, }
}
}
impl fmt::Display for SegmentationType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use SegmentationType::*;
let description = match self {
NotIndicated => "Not Indicated",
ContentIdentification => "Content Identification",
ProgramStart => "Program Start",
ProgramEnd => "Program End",
ProgramEarlyTermination => "Program Early Termination",
ProgramBreakaway => "Program Breakaway",
ProgramResumption => "Program Resumption",
ProgramRunoverPlanned => "Program Runover Planned",
ProgramRunoverUnplanned => "Program Runover Unplanned",
ProgramOverlapStart => "Program Overlap Start",
ProgramBlackoutOverride => "Program Blackout Override",
ProgramJoin => "Program Join",
ChapterStart => "Chapter Start",
ChapterEnd => "Chapter End",
BreakStart => "Break Start",
BreakEnd => "Break End",
OpeningCreditStartDeprecated => "Opening Credit Start (Deprecated)",
OpeningCreditEndDeprecated => "Opening Credit End (Deprecated)",
ClosingCreditStartDeprecated => "Closing Credit Start (Deprecated)",
ClosingCreditEndDeprecated => "Closing Credit End (Deprecated)",
ProviderAdvertisementStart => "Provider Advertisement Start",
ProviderAdvertisementEnd => "Provider Advertisement End",
DistributorAdvertisementStart => "Distributor Advertisement Start",
DistributorAdvertisementEnd => "Distributor Advertisement End",
ProviderPlacementOpportunityStart => "Provider Placement Opportunity Start",
ProviderPlacementOpportunityEnd => "Provider Placement Opportunity End",
DistributorPlacementOpportunityStart => "Distributor Placement Opportunity Start",
DistributorPlacementOpportunityEnd => "Distributor Placement Opportunity End",
ProviderOverlayPlacementOpportunityStart => {
"Provider Overlay Placement Opportunity Start"
}
ProviderOverlayPlacementOpportunityEnd => "Provider Overlay Placement Opportunity End",
DistributorOverlayPlacementOpportunityStart => {
"Distributor Overlay Placement Opportunity Start"
}
DistributorOverlayPlacementOpportunityEnd => {
"Distributor Overlay Placement Opportunity End"
}
ProviderPromoStart => "Provider Promo Start",
ProviderPromoEnd => "Provider Promo End",
DistributorPromoStart => "Distributor Promo Start",
DistributorPromoEnd => "Distributor Promo End",
UnscheduledEventStart => "Unscheduled Event Start",
UnscheduledEventEnd => "Unscheduled Event End",
AlternateContentOpportunityStart => "Alternate Content Opportunity Start",
AlternateContentOpportunityEnd => "Alternate Content Opportunity End",
ProviderAdBlockStart => "Provider Ad Block Start",
ProviderAdBlockEnd => "Provider Ad Block End",
DistributorAdBlockStart => "Distributor Ad Block Start",
DistributorAdBlockEnd => "Distributor Ad Block End",
NetworkStart => "Network Start",
NetworkEnd => "Network End",
};
write!(f, "{}", description)
}
}