From 0f6b4a8d13698f94203d9a7302768f2324d464ee Mon Sep 17 00:00:00 2001 From: Chris Kennedy Date: Sat, 9 Dec 2023 08:24:47 -0800 Subject: [PATCH 1/3] extract more from mpegts packets --- src/bin/probe.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/bin/probe.rs b/src/bin/probe.rs index 42b3de13..b0217af6 100644 --- a/src/bin/probe.rs +++ b/src/bin/probe.rs @@ -331,9 +331,41 @@ fn process_mpegts_packet(packet: &[u8]) -> Vec> { // Extract the PID from the MPEG-TS header let pid = ((chunk[1] as u16 & 0x1F) << 8) | chunk[2] as u16; + // Extract the continuity counter from the MPEG-TS header + let continuity_counter = chunk[3] & 0x0F; + + // Extract the adaptation field control from the MPEG-TS header + let adaptation_field_control = (chunk[3] & 0x30) >> 4; + + // Extract the payload unit start indicator from the MPEG-TS header + let payload_unit_start_indicator = chunk[1] & 0x40; + + // Extract the transport scrambling control from the MPEG-TS header + let transport_scrambling_control = (chunk[3] & 0xC0) >> 6; + + // Extract the transport error indicator from the MPEG-TS header + let transport_error_indicator = chunk[1] & 0x80; + + // Extract the transport priority from the MPEG-TS header + let transport_priority = chunk[2] & 0x20; + + // Extract the transport private data from the MPEG-TS header + let transport_private_data = chunk[2] & 0x80; + + // extract the timestamp from the MPEG-TS header + let timestamp = ((chunk[4] as u64) << 25) | ((chunk[5] as u64) << 17) | ((chunk[6] as u64) << 9) | ((chunk[7] as u64) << 1) | ((chunk[8] as u64) >> 7); + // Construct JSON object with MPEG-TS header information let mpegts_header_info = json!({ - "pid": pid + "pid": pid, + "continuity_counter": continuity_counter, + "adaptation_field_control": adaptation_field_control, + "payload_unit_start_indicator": payload_unit_start_indicator, + "transport_scrambling_control": transport_scrambling_control, + "transport_error_indicator": transport_error_indicator, + "transport_priority": transport_priority, + "transport_private_data": transport_private_data, + "timestamp": timestamp }); // Print out the JSON structure From 7eafd4e44dd61b5a6b0d5955c249ec251f8ef4a0 Mon Sep 17 00:00:00 2001 From: Chris Kennedy Date: Sat, 9 Dec 2023 08:27:58 -0800 Subject: [PATCH 2/3] include more rtp header information --- src/bin/probe.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bin/probe.rs b/src/bin/probe.rs index b0217af6..125f02e9 100644 --- a/src/bin/probe.rs +++ b/src/bin/probe.rs @@ -302,11 +302,19 @@ fn process_smpte2110_packet(packet: &[u8]) -> Vec> { let timestamp = u32::from_be_bytes([packet[start + 4], packet[start + 5], packet[start + 6], packet[start + 7]]); let ssrc = u32::from_be_bytes([packet[start + 8], packet[start + 9], packet[start + 10], packet[start + 11]]); + // Extract the payload type from the RTP header + let payload_type = packet[start + 1] & 0x7F; + + // Extract the marker bit from the RTP header + let marker_bit = (packet[start + 1] & 0x80) >> 7; + // Construct JSON object with RTP header information let rtp_header_info = json!({ "sequence_number": sequence_number, "timestamp": timestamp, - "ssrc": ssrc + "ssrc": ssrc, + "payload_type": payload_type, + "marker_bit": marker_bit, }); // Print out the JSON structure From ed6ca731befbe3ab75eb5b92a976fce917dd2ea1 Mon Sep 17 00:00:00 2001 From: Chris Kennedy Date: Sat, 9 Dec 2023 08:35:03 -0800 Subject: [PATCH 3/3] add values we would like to get from mpegts probably need to create a map that stores this information and builds up the channels details over time across packets. --- src/bin/probe.rs | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/bin/probe.rs b/src/bin/probe.rs index 125f02e9..87c9c38e 100644 --- a/src/bin/probe.rs +++ b/src/bin/probe.rs @@ -308,6 +308,21 @@ fn process_smpte2110_packet(packet: &[u8]) -> Vec> { // Extract the marker bit from the RTP header let marker_bit = (packet[start + 1] & 0x80) >> 7; + // Check if interlaced video + let interlaced = (packet[start + 12] & 0x80) >> 7; + + // Check if UHD + let uhd = (packet[start + 12] & 0x40) >> 6; + + // Check if 10-bit + let ten_bit = (packet[start + 12] & 0x20) >> 5; + + // Check if 422 + let four_two_two = (packet[start + 12] & 0x10) >> 4; + + // Check if 444 + let four_four_four = (packet[start + 12] & 0x08) >> 3; + // Construct JSON object with RTP header information let rtp_header_info = json!({ "sequence_number": sequence_number, @@ -315,6 +330,11 @@ fn process_smpte2110_packet(packet: &[u8]) -> Vec> { "ssrc": ssrc, "payload_type": payload_type, "marker_bit": marker_bit, + "interlaced": interlaced, + "uhd": uhd, + "ten_bit": ten_bit, + "four_two_two": four_two_two, + "four_four_four": four_four_four }); // Print out the JSON structure @@ -363,6 +383,23 @@ fn process_mpegts_packet(packet: &[u8]) -> Vec> { // extract the timestamp from the MPEG-TS header let timestamp = ((chunk[4] as u64) << 25) | ((chunk[5] as u64) << 17) | ((chunk[6] as u64) << 9) | ((chunk[7] as u64) << 1) | ((chunk[8] as u64) >> 7); + /* + // extrace the interlaced status from the MPEG-TS header + let interlaced = chunk[8] & 0x40; + + // extract the uhd status from the MPEG-TS header + let uhd = chunk[8] & 0x20; + + // extract the 10-bit status from the MPEG-TS header + let ten_bit = chunk[8] & 0x10; + + // extract the 422 status from the MPEG-TS header + let four_two_two = chunk[8] & 0x08; + + // extract the 444 status from the MPEG-TS header + let four_four_four = chunk[8] & 0x04; + */ + // Construct JSON object with MPEG-TS header information let mpegts_header_info = json!({ "pid": pid, @@ -373,7 +410,12 @@ fn process_mpegts_packet(packet: &[u8]) -> Vec> { "transport_error_indicator": transport_error_indicator, "transport_priority": transport_priority, "transport_private_data": transport_private_data, - "timestamp": timestamp + "timestamp": timestamp, + /*"interlaced": interlaced, + "uhd": uhd, + "ten_bit": ten_bit, + "four_two_two": four_two_two, + "four_four_four": four_four_four*/ }); // Print out the JSON structure