+ +
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 Terminal Packet & Protocol Probe |
| 6 | Connects to openavx TCP control port (7960), captures the live wire protocol, |
| 7 | and verifies handshake and frame delivery. |
| 8 | """ |
| 9 | |
| 10 | import socket |
| 11 | import struct |
| 12 | import sys |
| 13 | import time |
| 14 | |
| 15 | def main(): |
| 16 | host = "127.0.0.1" |
| 17 | port = 7960 |
| 18 | |
| 19 | print("=" * 60) |
| 20 | print(" openavx Live Terminal Wire Protocol Probe") |
| 21 | print("=" * 60) |
| 22 | print(f"[*] Connecting to {host}:{port} via TCP...") |
| 23 | |
| 24 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 25 | s.settimeout(5.0) |
| 26 | |
| 27 | try: |
| 28 | s.connect((host, port)) |
| 29 | print(f"\033[1;32m[+] Connected successfully to openavx on port {port}!\033[0m\n") |
| 30 | |
| 31 | # 1. Read Handshake Payload Length (4 bytes) |
| 32 | len_bytes = s.recv(4) |
| 33 | if len(len_bytes) < 4: |
| 34 | print("[-] Failed to read handshake length") |
| 35 | return 1 |
| 36 | |
| 37 | xml_len = struct.unpack("<I", len_bytes)[0] |
| 38 | print(f"\033[1;36m[RX WIRE PACKET 1: HANDSHAKE HEADER]\033[0m") |
| 39 | print(f" Length: {xml_len} bytes") |
| 40 | |
| 41 | # 2. Read XML Handshake Payload |
| 42 | xml_data = b"" |
| 43 | while len(xml_data) < xml_len: |
| 44 | chunk = s.recv(xml_len - len(xml_data)) |
| 45 | if not chunk: |
| 46 | break |
| 47 | xml_data += chunk |
| 48 | |
| 49 | xml_str = xml_data.decode("utf-8", errors="replace") |
| 50 | print(f"\033[1;33m[RX XML DESCRIPTOR]\033[0m:\n{xml_str.strip()}\n") |
| 51 | |
| 52 | assert "<oavx_stream" in xml_str, "XML missing <oavx_stream" |
| 53 | print("\033[1;32m[+] Handshake XML validated successfully!\033[0m\n") |
| 54 | |
| 55 | # 3. Read Video Frame Header (36 bytes) |
| 56 | # struct { uint32 magic, uint32 xres, uint32 yres, uint32 fourcc, int32 n, int32 d, int64 tc, uint32 len } |
| 57 | hdr_fmt = "<IIIIiiqI" |
| 58 | hdr_size = struct.calcsize(hdr_fmt) |
| 59 | print(f"[*] Waiting for live video frame from sender (Header size: {hdr_size} bytes)...") |
| 60 | |
| 61 | hdr_bytes = s.recv(hdr_size) |
| 62 | if len(hdr_bytes) < hdr_size: |
| 63 | print(f"[-] Incomplete video header received: {len(hdr_bytes)}/{hdr_size}") |
| 64 | return 1 |
| 65 | |
| 66 | magic, xres, yres, fourcc, fr_n, fr_d, tc, payload_len = struct.unpack(hdr_fmt, hdr_bytes) |
| 67 | fourcc_str = "".join([chr((fourcc >> (8*i)) & 0xff) for i in range(4)]) |
| 68 | magic_str = "".join([chr((magic >> (8*i)) & 0xff) for i in range(4)]) |
| 69 | |
| 70 | print(f"\033[1;36m[RX WIRE PACKET 2: VIDEO FRAME]\033[0m") |
| 71 | print(f" Magic: 0x{magic:08X} ('{magic_str}')") |
| 72 | print(f" Resolution: {xres} x {yres}") |
| 73 | print(f" FourCC: 0x{fourcc:08X} ('{fourcc_str}')") |
| 74 | print(f" Frame Rate: {fr_n} / {fr_d} ({fr_n/fr_d:.2f} FPS)") |
| 75 | print(f" Timecode: {tc}") |
| 76 | print(f" Payload Len: {payload_len} bytes ({payload_len / 1024 / 1024:.2f} MB)") |
| 77 | |
| 78 | assert magic == 0x56585641, f"Invalid magic: 0x{magic:08X}" |
| 79 | assert xres == 1920, f"Expected xres 1920, got {xres}" |
| 80 | assert yres == 1080, f"Expected yres 1080, got {yres}" |
| 81 | |
| 82 | # 4. Read sample payload chunk |
| 83 | sample_chunk = s.recv(min(4096, payload_len)) |
| 84 | hex_preview = " ".join([f"{b:02X}" for b in sample_chunk[:32]]) |
| 85 | print(f" Sample Hex: {hex_preview} ...\n") |
| 86 | |
| 87 | print("\033[1;32m[+] LIVE PROTOCOL VERIFICATION PASSED!\033[0m") |
| 88 | print("[+] openavx successfully streamed verified AVX packets over TCP!") |
| 89 | return 0 |
| 90 | |
| 91 | except Exception as e: |
| 92 | print(f"\033[1;31m[-] Error during socket probe: {e}\033[0m") |
| 93 | return 1 |
| 94 | finally: |
| 95 | s.close() |
| 96 | |
| 97 | if __name__ == "__main__": |
| 98 | sys.exit(main()) |