mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-06 07:55:10 +00:00
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -89,12 +89,6 @@ def top_level_boxes(data: bytes) -> list[tuple[str, int]]:
|
||||
return boxes
|
||||
|
||||
|
||||
def test_split_nal_units_drops_start_codes():
|
||||
nals = split_nal_units(bytes.fromhex(VIDEO_HEVC_CPD))
|
||||
# VPS (32), SPS (33), PPS (34) by HEVC NAL type = (first_byte >> 1) & 0x3F.
|
||||
assert [(n[0] >> 1) & 0x3F for n in nals] == [32, 33, 34]
|
||||
|
||||
|
||||
def test_hevc_init_structure():
|
||||
init = build_init_segment(
|
||||
stream_type="video",
|
||||
@@ -196,32 +190,6 @@ def test_stsd_carries_two_entries_for_sample_description_index_2(stream_type, fo
|
||||
walk_box(init, 0, len(init))
|
||||
|
||||
|
||||
def test_avc_init_structure():
|
||||
init = build_init_segment(
|
||||
stream_type="video",
|
||||
fourcc="H264",
|
||||
codec_private_data=VIDEO_AVC_CPD,
|
||||
timescale=10000000,
|
||||
width=1280,
|
||||
height=720,
|
||||
)
|
||||
assert init[4:8] == b"ftyp"
|
||||
assert b"avcC" in init and b"avc1" in init
|
||||
|
||||
|
||||
def test_aac_audio_init_structure():
|
||||
init = build_init_segment(
|
||||
stream_type="audio",
|
||||
fourcc="AACL",
|
||||
codec_private_data=AAC_LC_CPD,
|
||||
timescale=10000000,
|
||||
channels=2,
|
||||
sampling_rate=48000,
|
||||
)
|
||||
assert b"mp4a" in init and b"esds" in init
|
||||
assert b"smhd" in init # sound media header, not video
|
||||
|
||||
|
||||
def test_encrypted_init_has_cenc_boxes():
|
||||
init = build_init_segment(
|
||||
stream_type="video",
|
||||
@@ -328,40 +296,6 @@ def test_aac_init_without_codec_private_data_synthesizes_asc():
|
||||
assert bytes.fromhex(AAC_LC_CPD) in init
|
||||
|
||||
|
||||
def test_dolby_vision_uses_dvh1_sample_entry():
|
||||
init = build_init_segment(
|
||||
stream_type="video",
|
||||
fourcc="DVH1",
|
||||
codec_private_data=VIDEO_HEVC_CPD,
|
||||
timescale=10000000,
|
||||
width=3840,
|
||||
height=1600,
|
||||
)
|
||||
assert b"dvh1" in init and b"hvcC" in init
|
||||
assert b"hvc1" not in init
|
||||
|
||||
|
||||
def test_davc_maps_to_avc1():
|
||||
init = build_init_segment(
|
||||
stream_type="video",
|
||||
fourcc="DAVC",
|
||||
codec_private_data=VIDEO_AVC_CPD,
|
||||
timescale=10000000,
|
||||
)
|
||||
assert b"avc1" in init and b"avcC" in init
|
||||
|
||||
|
||||
def test_lowercase_fourcc_normalized():
|
||||
# Real manifests ship FourCC="hvc1" in lowercase.
|
||||
init = build_init_segment(
|
||||
stream_type="video",
|
||||
fourcc="hvc1",
|
||||
codec_private_data=VIDEO_HEVC_CPD,
|
||||
timescale=10000000,
|
||||
)
|
||||
assert b"hvcC" in init
|
||||
|
||||
|
||||
def test_avcc_selects_sps_pps_by_nal_type_not_position():
|
||||
nals = split_nal_units(bytes.fromhex(VIDEO_AVC_CPD))
|
||||
swapped = NAL_START_CODE + nals[1] + NAL_START_CODE + nals[0] # PPS first
|
||||
@@ -390,20 +324,6 @@ def test_hvcc_signals_10bit_from_sps():
|
||||
assert payload[18] == 0xF8 | 0x02 # bitDepthChromaMinus8 = 2
|
||||
|
||||
|
||||
def test_ttml_init_structure():
|
||||
init = build_init_segment(
|
||||
stream_type="text",
|
||||
fourcc="TTML",
|
||||
codec_private_data="",
|
||||
timescale=10000000,
|
||||
language="eng",
|
||||
)
|
||||
assert b"stpp" in init
|
||||
assert b"sthd" in init # subtitle media header
|
||||
assert b"subt" in init and b"SubtitleHandler\0" in init
|
||||
assert b"http://www.w3.org/ns/ttml\0" in init
|
||||
|
||||
|
||||
def test_constant_iv_tenc_form():
|
||||
constant_iv = bytes(range(16))
|
||||
init = build_init_segment(
|
||||
@@ -455,19 +375,6 @@ def test_iv_size_undetermined_returns_none():
|
||||
assert read_per_sample_iv_size(make_fragment()) is None
|
||||
|
||||
|
||||
def test_hvcc_embeds_vps_sps_pps():
|
||||
hvcc = build_hvcc(bytes.fromhex(VIDEO_HEVC_CPD))
|
||||
nals = split_nal_units(bytes.fromhex(VIDEO_HEVC_CPD))
|
||||
# Each original NAL unit (VPS/SPS/PPS) is embedded verbatim in the arrays.
|
||||
for nal in nals:
|
||||
assert nal in hvcc
|
||||
|
||||
|
||||
def test_avcc_requires_sps_and_pps():
|
||||
with pytest.raises(ValueError):
|
||||
build_avcc(b"\x00\x00\x00\x01\x67only_sps")
|
||||
|
||||
|
||||
def test_read_track_id_from_fragment():
|
||||
# Minimal moof/traf/tfhd carrying track_ID = 7.
|
||||
tfhd = full_box(b"tfhd", 0, 0, struct.pack(">I", 7) + b"\x00" * 4)
|
||||
@@ -477,10 +384,6 @@ def test_read_track_id_from_fragment():
|
||||
assert read_track_id(moof + mdat) == 7
|
||||
|
||||
|
||||
def test_read_track_id_missing_returns_none():
|
||||
assert read_track_id(box(b"mdat", b"\x00\x00")) is None
|
||||
|
||||
|
||||
def test_remove_emulation_prevention():
|
||||
# 00 00 03 XX -> the 0x03 emulation byte is dropped.
|
||||
assert remove_emulation_prevention(b"\x00\x00\x03\x01") == b"\x00\x00\x01"
|
||||
@@ -490,52 +393,6 @@ def test_remove_emulation_prevention():
|
||||
assert remove_emulation_prevention(b"\x00\x00\x03\x03\x00\x00\x03\x01") == b"\x00\x00\x03\x00\x00\x01"
|
||||
|
||||
|
||||
def test_two_letter_or_uppercase_language_falls_back_to_und():
|
||||
# mdhd packs three a-z letters; "en"/"ENG" must not crash struct.pack.
|
||||
for lang in ("en", "ENG", "", "e1x"):
|
||||
init = build_init_segment(
|
||||
stream_type="audio",
|
||||
fourcc="AACL",
|
||||
codec_private_data=AAC_LC_CPD,
|
||||
timescale=10000000,
|
||||
language=lang,
|
||||
)
|
||||
assert init[4:8] == b"ftyp"
|
||||
|
||||
|
||||
def test_high_sampling_rate_does_not_overflow():
|
||||
# 96 kHz exceeds the 16.16 integer field; written as 0 like ffmpeg does.
|
||||
init = build_init_segment(
|
||||
stream_type="audio",
|
||||
fourcc="AACL",
|
||||
codec_private_data="",
|
||||
timescale=10000000,
|
||||
sampling_rate=96000,
|
||||
)
|
||||
assert b"mp4a" in init
|
||||
|
||||
|
||||
def test_read_track_id_truncated_tfhd_returns_none():
|
||||
tfhd = full_box(b"tfhd", 0, 0, b"\x00\x00") # too short for a track_ID
|
||||
fragment = box(b"moof", box(b"traf", tfhd))
|
||||
assert read_track_id(fragment) is None
|
||||
|
||||
|
||||
def test_parse_colour_hevc_pq():
|
||||
# PQ master: bt2020 primaries (9), smpte2084 transfer (16), bt2020nc matrix (9).
|
||||
assert parse_codec_private_data_colour("HVC1", bytes.fromhex(VIDEO_HEVC_PQ_CPD)) == (9, 16, 9)
|
||||
|
||||
|
||||
def test_parse_colour_hevc_hlg():
|
||||
assert parse_codec_private_data_colour("HVC1", bytes.fromhex(VIDEO_HEVC_HLG_CPD)) == (9, 18, 9)
|
||||
|
||||
|
||||
def test_parse_colour_hevc_bt709():
|
||||
assert parse_codec_private_data_colour("HVC1", bytes.fromhex(VIDEO_HEVC_SDR_CPD)) == (1, 1, 1)
|
||||
# The real-manifest 8-bit sample also signals BT.709 explicitly.
|
||||
assert parse_codec_private_data_colour("HVC1", bytes.fromhex(VIDEO_HEVC_CPD)) == (1, 1, 1)
|
||||
|
||||
|
||||
def test_parse_colour_dv_is_unspecified():
|
||||
# DV carries no usable CICP; the DV decision must come from the FourCC.
|
||||
assert parse_codec_private_data_colour("DVHE", bytes.fromhex(VIDEO_HEVC_DV_CPD)) == (2, 2, 2)
|
||||
@@ -732,33 +589,6 @@ def text_fragment(seq: int, begin: str, end: str, text: str, sdi: int) -> bytes:
|
||||
return box(b"moof", mfhd + box(b"traf", tfhd + tfdt + trun)) + box(b"mdat", payload)
|
||||
|
||||
|
||||
def test_unity_matrix_is_nine_int32s():
|
||||
# extras shift every later field (mvhd next_track_ID, tkhd width/height) and desync pymp4
|
||||
from unshackle.core.manifests.ism_init import UNITY_MATRIX
|
||||
|
||||
assert len(UNITY_MATRIX) == 36
|
||||
|
||||
|
||||
@pytest.mark.parametrize("stream_type", ["video", "audio", "text"])
|
||||
def test_mvhd_tkhd_sizes_match_iso_layout(stream_type):
|
||||
# a declared size over the spec payload makes parsers under-read and stop at the moov
|
||||
kwargs = {
|
||||
"video": dict(fourcc="H264", codec_private_data=VIDEO_AVC_CPD, width=1920, height=1080),
|
||||
"audio": dict(fourcc="AACL", codec_private_data=AAC_LC_CPD),
|
||||
"text": dict(fourcc="TTML", codec_private_data=""),
|
||||
}[stream_type]
|
||||
init = build_init_segment(stream_type=stream_type, duration=6_000_000_000, language="eng", **kwargs)
|
||||
|
||||
sizes = {}
|
||||
for name in (b"mvhd", b"tkhd"):
|
||||
at = init.index(name) - 4
|
||||
sizes[name] = struct.unpack(">I", init[at : at + 4])[0]
|
||||
# version-1 mvhd: 8 header + 4 version/flags + 28 time fields + 80 trailer
|
||||
assert sizes[b"mvhd"] == 120
|
||||
# version-1 tkhd: 8 header + 4 version/flags + 32 time fields + 60 trailer
|
||||
assert sizes[b"tkhd"] == 104
|
||||
|
||||
|
||||
def test_tkhd_carries_video_dimensions():
|
||||
# width/height sit after the matrix, so a mis-sized matrix silently zeroes them
|
||||
init = build_init_segment(
|
||||
@@ -770,20 +600,6 @@ def test_tkhd_carries_video_dimensions():
|
||||
assert (width >> 16, height >> 16) == (1920, 1080)
|
||||
|
||||
|
||||
def test_pymp4_consumes_whole_init_and_reaches_fragments():
|
||||
# pymp4 must reach the mdat here, or Subtitle.parse finds nothing to yield cues from
|
||||
from io import BytesIO
|
||||
|
||||
from pymp4.parser import MP4
|
||||
|
||||
init = build_init_segment(
|
||||
stream_type="text", fourcc="TTML", codec_private_data="", duration=6_000_000_000, language="eng"
|
||||
)
|
||||
data = init + text_fragment(1, "00:00:01.000", "00:00:02.000", "first", sdi=1)
|
||||
types = [b.type for b in MP4.parse_stream(BytesIO(data))]
|
||||
assert types == [b"ftyp", b"moov", b"moof", b"mdat"]
|
||||
|
||||
|
||||
def test_fttml_subtitle_parse_yields_cues():
|
||||
from unshackle.core.tracks.subtitle import Subtitle
|
||||
|
||||
|
||||
Reference in New Issue
Block a user