MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / verify_segment

Function verify_segment

apps/proxy/hls_proxy/server.py:622–676  ·  view source on GitHub ↗

Verify MPEG-TS segment integrity and structure. Args: data: Raw segment data bytes Returns: dict containing: valid (bool): True if segment passes all checks packets (int): Number of valid packets found size (int): Total s

(data: bytes)

Source from the content-addressed store, hash-verified

620
621# Update verify_segment with more thorough checks
622def verify_segment(data: bytes) -> dict:
623 """
624 Verify MPEG-TS segment integrity and structure.
625
626 Args:
627 data: Raw segment data bytes
628
629 Returns:
630 dict containing:
631 valid (bool): True if segment passes all checks
632 packets (int): Number of valid packets found
633 size (int): Total segment size in bytes
634 error (str): Description if validation fails
635
636 Checks:
637 - Minimum size requirements
638 - Packet size alignment
639 - Sync byte presence
640 - Transport error indicators
641 """
642
643 # Check minimum size
644 if len(data) < 188:
645 return {'valid': False, 'error': 'Segment too short'}
646
647 # Verify segment size is multiple of packet size
648 if len(data) % 188 != 0:
649 return {'valid': False, 'error': 'Invalid segment size'}
650
651 valid_packets = 0
652 total_packets = len(data) // 188
653
654 # Scan all packets in segment
655 for i in range(0, len(data), 188):
656 packet = data[i:i+188]
657
658 # Check packet completeness
659 if len(packet) != 188:
660 return {'valid': False, 'error': 'Incomplete packet'}
661
662 # Verify sync byte
663 if packet[0] != 0x47:
664 return {'valid': False, 'error': f'Invalid sync byte at offset {i}'}
665
666 # Check transport error indicator
667 if packet[1] & 0x80:
668 return {'valid': False, 'error': 'Transport error indicator set'}
669
670 valid_packets += 1
671
672 return {
673 'valid': True,
674 'packets': valid_packets,
675 'size': len(data)
676 }
677
678def fetch_stream(fetcher: StreamFetcher, stop_event: threading.Event, start_sequence: int = 0):
679 """

Callers 2

fetch_loopMethod · 0.85
fetch_streamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected