pub struct TsHeader {
pub tei: bool,
pub pusi: bool,
pub pid: u16,
pub scrambling: u8,
pub has_adaptation: bool,
pub has_payload: bool,
pub continuity_counter: u8,
}Expand description
Parsed TS header — the 4-byte transport header fields.
Fields§
§tei: boolTransport Error Indicator — set by the demodulator when an uncorrectable error is present in the packet.
pusi: boolPayload Unit Start Indicator — first byte of the payload is a new PES packet or PSI section header when set.
pid: u1613-bit Packet Identifier.
scrambling: u82-bit transport_scrambling_control (0 = not scrambled).
has_adaptation: boolAdaptation field present flag (adaptation_field_control bit 1).
has_payload: boolPayload present flag (adaptation_field_control bit 0).
continuity_counter: u84-bit continuity_counter (wraps 0..=15 per PID).
Implementations§
Source§impl TsHeader
impl TsHeader
Sourcepub const fn serialized_len() -> usize
pub const fn serialized_len() -> usize
Number of bytes written by serialize_into.
Sourcepub fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
pub fn serialize_into(&self, buf: &mut [u8]) -> Result<usize>
Serialize this header into the first 4 bytes of buf.
Sourcepub fn scrambling_control(&self) -> ScramblingControl
pub fn scrambling_control(&self) -> ScramblingControl
Typed view of the 2-bit transport_scrambling_control field.
See ScramblingControl for the spec citation (H.222.0 Table 2-4 +
ETSI TS 100 289 §5.1 Table 1).
Examples found in repository?
16fn main() {
17 let path = env::args()
18 .nth(1)
19 .unwrap_or_else(|| "mpeg-ts/tests/fixtures/m6-single.ts".to_string());
20
21 let buf = fs::read(&path).unwrap_or_else(|e| {
22 eprintln!("error: cannot read {path}: {e}");
23 std::process::exit(1);
24 });
25
26 let mut total = 0u64;
27 let mut scrambled = 0u64;
28 let mut pid_counts: HashMap<u16, u64> = HashMap::new();
29
30 for pkt in iter_packets(&buf) {
31 total += 1;
32 let hdr = &pkt.header;
33 *pid_counts.entry(hdr.pid).or_insert(0) += 1;
34
35 let sc = hdr.scrambling_control();
36 let afc = hdr.adaptation_field_control();
37
38 if sc != ScramblingControl::NotScrambled {
39 scrambled += 1;
40 }
41
42 if total <= 5 || hdr.pusi {
43 println!(
44 "pkt {:>6}: pid=0x{:04X} cc={:2} scrambling={} afc={}",
45 total, hdr.pid, hdr.continuity_counter, sc, afc,
46 );
47 }
48 }
49
50 let clear = total - scrambled;
51 println!("\n--- summary ---");
52 println!("total packets : {total}");
53 println!("clear packets : {clear}");
54 println!("scrambled pkts: {scrambled}");
55 println!("distinct PIDs : {}", pid_counts.len());
56
57 if total == 0 {
58 eprintln!("warning: no packets found in {path}");
59 std::process::exit(1);
60 }
61}Sourcepub fn adaptation_field_control(&self) -> AdaptationFieldControl
pub fn adaptation_field_control(&self) -> AdaptationFieldControl
Typed view of the adaptation_field_control 2-bit field, derived from the
has_adaptation/has_payload flags.
See AdaptationFieldControl for the spec citation (H.222.0 Table 2-5).
Examples found in repository?
16fn main() {
17 let path = env::args()
18 .nth(1)
19 .unwrap_or_else(|| "mpeg-ts/tests/fixtures/m6-single.ts".to_string());
20
21 let buf = fs::read(&path).unwrap_or_else(|e| {
22 eprintln!("error: cannot read {path}: {e}");
23 std::process::exit(1);
24 });
25
26 let mut total = 0u64;
27 let mut scrambled = 0u64;
28 let mut pid_counts: HashMap<u16, u64> = HashMap::new();
29
30 for pkt in iter_packets(&buf) {
31 total += 1;
32 let hdr = &pkt.header;
33 *pid_counts.entry(hdr.pid).or_insert(0) += 1;
34
35 let sc = hdr.scrambling_control();
36 let afc = hdr.adaptation_field_control();
37
38 if sc != ScramblingControl::NotScrambled {
39 scrambled += 1;
40 }
41
42 if total <= 5 || hdr.pusi {
43 println!(
44 "pkt {:>6}: pid=0x{:04X} cc={:2} scrambling={} afc={}",
45 total, hdr.pid, hdr.continuity_counter, sc, afc,
46 );
47 }
48 }
49
50 let clear = total - scrambled;
51 println!("\n--- summary ---");
52 println!("total packets : {total}");
53 println!("clear packets : {clear}");
54 println!("scrambled pkts: {scrambled}");
55 println!("distinct PIDs : {}", pid_counts.len());
56
57 if total == 0 {
58 eprintln!("warning: no packets found in {path}");
59 std::process::exit(1);
60 }
61}Trait Implementations§
impl Eq for TsHeader
Source§impl Serialize for TsHeader
impl Serialize for TsHeader
Source§type Error = Error
type Error = Error
Parse impl, but need not be).Source§fn serialized_len(&self) -> usize
fn serialized_len(&self) -> usize
serialize_into will write.