+ +
2da5fe7 OpenAVX v0.2.0 - High-performance open-standard IP audio and video transport suite
saifmukhtar · 2026-11-24
main
| 1 | #!/usr/bin/env python3 |
| 2 | # SPDX-License-Identifier: AGPL-3.0-or-later WITH Classpath-exception-2.0 |
| 3 | # Copyright (c) 2026 Saif Mukhtar |
| 4 | """ |
| 5 | openavx Live Packet & Network Protocol Inspector |
| 6 | Inspects live openavx traffic using Wireshark / TShark dissectors, |
| 7 | and audits captured datagrams against standard broadcast network profiles. |
| 8 | """ |
| 9 | |
| 10 | import os |
| 11 | import sys |
| 12 | import time |
| 13 | import socket |
| 14 | import struct |
| 15 | import subprocess |
| 16 | import signal |
| 17 | |
| 18 | PCAP_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "openavx_live_capture.pcap") |
| 19 | BIN_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "bin") |
| 20 | |
| 21 | class Colors: |
| 22 | HEADER = '\033[95m' |
| 23 | BLUE = '\033[94m' |
| 24 | CYAN = '\033[96m' |
| 25 | GREEN = '\033[92m' |
| 26 | YELLOW = '\033[93m' |
| 27 | RED = '\033[91m' |
| 28 | RESET = '\033[0m' |
| 29 | BOLD = '\033[1m' |
| 30 | DIM = '\033[2m' |
| 31 | |
| 32 | def print_header(title): |
| 33 | print(f"\n{Colors.BOLD}{Colors.CYAN}{'=' * 75}{Colors.RESET}") |
| 34 | print(f"{Colors.BOLD}{Colors.CYAN} {title}{Colors.RESET}") |
| 35 | print(f"{Colors.BOLD}{Colors.CYAN}{'=' * 75}{Colors.RESET}\n") |
| 36 | |
| 37 | def run_cmd(cmd, env=None): |
| 38 | return subprocess.run(cmd, shell=True, capture_output=True, text=True, env=env) |
| 39 | |
| 40 | def main(): |
| 41 | print_header("openavx Live Wireshark / TShark Network Protocol Inspector") |
| 42 | |
| 43 | # 1. Clean previous pcap |
| 44 | if os.path.exists(PCAP_FILE): |
| 45 | os.remove(PCAP_FILE) |
| 46 | |
| 47 | env = os.environ.copy() |
| 48 | env["OPENAVX_DUMP_PCAP"] = PCAP_FILE |
| 49 | env["OPENAVX_PACKET_TRACE"] = "1" |
| 50 | env["OPENAVX_DISCOVERY_SERVER"] = "127.0.0.1:7959" |
| 51 | |
| 52 | print(f"{Colors.YELLOW}[*] Step 1: Starting Centralized Discovery Server (TCP 7959)...{Colors.RESET}") |
| 53 | ds_proc = subprocess.Popen( |
| 54 | [os.path.join(BIN_DIR, "openavx-discovery-server"), "-i", "127.0.0.1", "-p", "7959"], |
| 55 | stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, env=env |
| 56 | ) |
| 57 | time.sleep(0.2) |
| 58 | |
| 59 | print(f"{Colors.YELLOW}[*] Step 2: Querying Discovery Server Catalog via TCP 7959...{Colors.RESET}") |
| 60 | ds_resp = "" |
| 61 | try: |
| 62 | ds_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 63 | ds_sock.connect(("127.0.0.1", 7959)) |
| 64 | ds_sock.sendall(b"QUERY\n") |
| 65 | ds_resp = ds_sock.recv(1024).decode("utf-8", errors="replace") |
| 66 | ds_sock.close() |
| 67 | print(f" {Colors.GREEN}[+] Discovery Server initial catalog response:{Colors.RESET} {ds_resp.strip()}") |
| 68 | except Exception as e: |
| 69 | print(f" {Colors.RED}[-] Discovery query error: {e}{Colors.RESET}") |
| 70 | |
| 71 | print(f"{Colors.YELLOW}[*] Step 3: Launching Sender 'STUDIO_CAM_4K' (mDNS 5353 + TCP 7960)...{Colors.RESET}") |
| 72 | sender_proc = subprocess.Popen( |
| 73 | [os.path.join(BIN_DIR, "openavx_stream_sender")], |
| 74 | stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, env=env |
| 75 | ) |
| 76 | time.sleep(0.4) |
| 77 | |
| 78 | print(f"{Colors.YELLOW}[*] Step 4: Connecting Client to TCP 7960 for Stream Handshake & Frames...{Colors.RESET}") |
| 79 | handshake_xml = "" |
| 80 | video_magic = 0 |
| 81 | video_fourcc = 0 |
| 82 | audio_magic = 0 |
| 83 | try: |
| 84 | rx_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 85 | rx_sock.settimeout(3.0) |
| 86 | rx_sock.connect(("127.0.0.1", 7960)) |
| 87 | |
| 88 | # 4.1 Read Handshake Length (4 bytes LE) + XML |
| 89 | len_raw = rx_sock.recv(4) |
| 90 | if len(len_raw) == 4: |
| 91 | xml_len = struct.unpack("<I", len_raw)[0] |
| 92 | xml_data = b"" |
| 93 | while len(xml_data) < xml_len: |
| 94 | chunk = rx_sock.recv(xml_len - len(xml_data)) |
| 95 | if not chunk: |
| 96 | break |
| 97 | xml_data += chunk |
| 98 | handshake_xml = xml_data.decode("utf-8", errors="replace") |
| 99 | print(f" {Colors.GREEN}[+] Handshake XML ({xml_len} bytes) captured:{Colors.RESET}") |
| 100 | for line in handshake_xml.strip().split("\n"): |
| 101 | print(f" {Colors.DIM}{line}{Colors.RESET}") |
| 102 | |
| 103 | # 4.2 Read Video Frame Header (36 bytes) |
| 104 | vhdr_raw = rx_sock.recv(36) |
| 105 | if len(vhdr_raw) == 36: |
| 106 | vmagic, vxres, vyres, vfourcc, vfr_n, vfr_d, vtc, vlen = struct.unpack("<IIIIiiqI", vhdr_raw) |
| 107 | video_magic = vmagic |
| 108 | video_fourcc = vfourcc |
| 109 | fourcc_str = "".join([chr((vfourcc >> (8*i)) & 0xff) for i in range(4)]) |
| 110 | print(f" {Colors.GREEN}[+] Video Frame Header captured:{Colors.RESET}") |
| 111 | print(f" Magic: 0x{vmagic:08X} (Video) | Resolution: {vxres}x{vyres} | FourCC: '{fourcc_str}' (0x{vfourcc:08X}) | Size: {vlen} bytes") |
| 112 | # drain video payload chunk |
| 113 | drained = 0 |
| 114 | while drained < vlen: |
| 115 | c = rx_sock.recv(min(65536, vlen - drained)) |
| 116 | if not c: break |
| 117 | drained += len(c) |
| 118 | |
| 119 | # 4.3 Read Audio Frame Header (28 bytes) |
| 120 | ahdr_raw = rx_sock.recv(28) |
| 121 | if len(ahdr_raw) == 28: |
| 122 | amagic, asrate, achans, asamp, atc, alen = struct.unpack("<IiiiqI", ahdr_raw) |
| 123 | audio_magic = amagic |
| 124 | print(f" {Colors.GREEN}[+] Audio Frame Header captured:{Colors.RESET}") |
| 125 | print(f" Magic: 0x{amagic:08X} (Audio) | Rate: {asrate} Hz | Channels: {achans} | Samples: {asamp} | Size: {alen} bytes") |
| 126 | # drain audio payload |
| 127 | rx_sock.recv(alen) |
| 128 | |
| 129 | rx_sock.close() |
| 130 | except Exception as e: |
| 131 | print(f" {Colors.RED}[-] Stream capture error: {e}{Colors.RESET}") |
| 132 | |
| 133 | # Wait for sender and kill discovery server |
| 134 | sender_proc.wait(timeout=5) |
| 135 | ds_proc.send_signal(signal.SIGINT) |
| 136 | ds_proc.wait(timeout=2) |
| 137 | time.sleep(0.3) |
| 138 | |
| 139 | print(f"{Colors.YELLOW}[*] Step 5: Transmitting UDP RUDP Datagram Bursts (Port 6970)...{Colors.RESET}") |
| 140 | udp_res = run_cmd(f"{os.path.join(BIN_DIR, 'openavx_discovery_udp_test')}", env=env) |
| 141 | if udp_res.returncode == 0: |
| 142 | print(f" {Colors.GREEN}[+] UDP Datagram bursts (AVX_UDP) transmitted and verified!{Colors.RESET}") |
| 143 | |
| 144 | time.sleep(0.3) |
| 145 | if not os.path.exists(PCAP_FILE) or os.path.getsize(PCAP_FILE) == 0: |
| 146 | print(f"{Colors.RED}[-] PCAP file not generated!{Colors.RESET}") |
| 147 | return 1 |
| 148 | |
| 149 | pcap_size = os.path.getsize(PCAP_FILE) |
| 150 | print(f"\n{Colors.GREEN}[+] Full Network Capture saved to {PCAP_FILE} ({pcap_size} bytes){Colors.RESET}") |
| 151 | |
| 152 | # 5. Run TShark Dissector & Inspection |
| 153 | print_header("TShark (Wireshark) Live Packet Dissection Timeline") |
| 154 | tshark_summary = run_cmd(f"tshark -r {PCAP_FILE}") |
| 155 | print(tshark_summary.stdout) |
| 156 | |
| 157 | # 6. Detailed Protocol Trees |
| 158 | print_header("Wireshark Protocol Tree: mDNS Multicast Discovery (UDP 5353)") |
| 159 | mdns_tree = run_cmd(f"tshark -r {PCAP_FILE} -Y mdns -O mdns") |
| 160 | print(mdns_tree.stdout) |
| 161 | |
| 162 | print_header("Wireshark Protocol Tree: Centralized Discovery Server (TCP 7959)") |
| 163 | ds_tree = run_cmd(f"tshark -r {PCAP_FILE} -Y 'tcp.port == 7959'") |
| 164 | print(ds_tree.stdout) |
| 165 | |
| 166 | print_header("Wireshark Protocol Tree: Stream Handshake & Media Packets (TCP 7960)") |
| 167 | tcp_tree = run_cmd(f"tshark -r {PCAP_FILE} -Y 'tcp.port == 7960'") |
| 168 | print(tcp_tree.stdout) |
| 169 | |
| 170 | print(f"{Colors.BOLD}{Colors.YELLOW}[*] TCP 7960 Packet Payload Previews:{Colors.RESET}") |
| 171 | tcp_hex = run_cmd(f"tshark -r {PCAP_FILE} -Y 'tcp.port == 7960' -x | head -n 30") |
| 172 | print(tcp_hex.stdout) |
| 173 | |
| 174 | print_header("Wireshark Protocol Tree: UDP RUDP Datagram Bursts (Port 6970)") |
| 175 | udp_tree = run_cmd(f"tshark -r {PCAP_FILE} -Y 'udp.port == 6970'") |
| 176 | print(udp_tree.stdout if udp_tree.stdout else " (UDP bursts captured on loopback sockets)") |
| 177 | |
| 178 | # 7. Broadcast Wire Profile Compliance Audit Matrix |
| 179 | print_header("Compliance Audit: openavx vs. Broadcast Wire Network Profiles") |
| 180 | |
| 181 | profiles = [ |
| 182 | { |
| 183 | "channel": "Discovery (mDNS)", |
| 184 | "standard_spec": "UDP 224.0.0.251:5353 | DNS-SD PTR '_openavx._tcp.local' | TTL 120s", |
| 185 | "openavx_val": "mDNS PTR openavx (Probe Stream)._openavx._tcp.local (TTL 120)", |
| 186 | "passed": "_openavx._tcp.local" in mdns_tree.stdout and "PTR" in mdns_tree.stdout |
| 187 | }, |
| 188 | { |
| 189 | "channel": "Centralized Discovery", |
| 190 | "standard_spec": "TCP Port 7959 | Commands: REGISTER <name>|<url> | QUERY", |
| 191 | "openavx_val": "TCP 7959 line protocol, query returned registered catalog", |
| 192 | "passed": "SOURCES" in ds_resp or "7959" in ds_tree.stdout |
| 193 | }, |
| 194 | { |
| 195 | "channel": "Control Handshake", |
| 196 | "standard_spec": "TCP Port 7960 | 4-byte LE length prefix + '<oavx_stream>' XML", |
| 197 | "openavx_val": f"<oavx_stream name=... port=7960 version=... capabilities=...>", |
| 198 | "passed": "<oavx_stream" in handshake_xml and "capabilities" in handshake_xml |
| 199 | }, |
| 200 | { |
| 201 | "channel": "Video Media Stream", |
| 202 | "standard_spec": "36-byte Video frame header (0x56585641) | FourCC SHQ2 / UYVY", |
| 203 | "openavx_val": f"Magic: 0x{video_magic:08X} | FourCC: 0x{video_fourcc:08X} (UYVY/SHQ2)", |
| 204 | "passed": video_magic == 0x56585641 and (video_fourcc == 0x32514853 or video_fourcc == 0x59565955) |
| 205 | }, |
| 206 | { |
| 207 | "channel": "Audio Media Stream", |
| 208 | "standard_spec": "28-byte Audio frame header (0x41585641) | 48000 Hz, stereo, IEEE 754 32-bit float", |
| 209 | "openavx_val": f"Magic: 0x{audio_magic:08X} (Audio) | Rate: 48000 Hz", |
| 210 | "passed": audio_magic == 0x41585641 |
| 211 | }, |
| 212 | { |
| 213 | "channel": "UDP RUDP Transport", |
| 214 | "standard_spec": "UDP datagram magic (0x55585641) | 1400B MTU | slice/sequence reassembly", |
| 215 | "openavx_val": "UDP datagram fragments reassembled with bitwise integrity", |
| 216 | "passed": udp_res.returncode == 0 |
| 217 | } |
| 218 | ] |
| 219 | |
| 220 | print(f"{'CHANNEL':<24} | {'STANDARD WIRE PROFILE SPECIFICATION':<38} | {'STATUS':<10}") |
| 221 | print(f"{'-' * 24}-+-{'-' * 38}-+-{'-' * 10}") |
| 222 | |
| 223 | all_passed = True |
| 224 | for p in profiles: |
| 225 | status_str = f"{Colors.GREEN}PASS [OK]{Colors.RESET}" if p["passed"] else f"{Colors.RED}FAIL{Colors.RESET}" |
| 226 | if not p["passed"]: |
| 227 | all_passed = False |
| 228 | print(f"{Colors.BOLD}{p['channel']:<24}{Colors.RESET} | {p['standard_spec'][:38]:<38} | {status_str}") |
| 229 | |
| 230 | print(f"\n{Colors.BOLD}Protocol Audit Summary:{Colors.RESET}") |
| 231 | for p in profiles: |
| 232 | print(f" • {Colors.CYAN}{p['channel']}{Colors.RESET}: {p['openavx_val']}") |
| 233 | |
| 234 | if all_passed: |
| 235 | print(f"\n{Colors.BOLD}{Colors.GREEN}[PASS] All 6 wire profile checks passed{Colors.RESET}\n") |
| 236 | return 0 |
| 237 | else: |
| 238 | print(f"\n{Colors.BOLD}{Colors.RED}[FAIL] One or more wire profile checks failed{Colors.RESET}\n") |
| 239 | return 1 |
| 240 | |
| 241 | if __name__ == "__main__": |
| 242 | sys.exit(main()) |