fix(hls): keep the EXT-X-KEY of another KEYFORMAT in force when a playlist renews one key tag

This commit is contained in:
imSp4rky
2026-12-01 18:58:20 -07:00
parent 3963e80ec3
commit 7a5bac7878
5 changed files with 94 additions and 13 deletions
+57 -1
View File
@@ -38,6 +38,9 @@ NONE = "#EXT-X-KEY:METHOD=NONE"
MAP = '#EXT-X-MAP:URI="init.mp4"'
DISCONTINUITY_SEQUENCE = "#EXT-X-DISCONTINUITY-SEQUENCE:0"
SKD = '#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://keys.example/a",KEYFORMAT="com.apple.streamingkeydelivery"'
SKD_B = SKD.replace("/a", "/b")
ID_A = '#EXT-X-KEY:METHOD=SAMPLE-AES,URI="id-a"'
ID_B = '#EXT-X-KEY:METHOD=SAMPLE-AES,URI="id-b",KEYFORMAT="Identity"'
KID_A, KID_B = UUID(int=0xA1), UUID(int=0xB2)
WV_A, WV_B = key_tag(KID_A), key_tag(KID_B)
@@ -68,6 +71,40 @@ def playlist(tags: dict[int, list[str]]) -> str:
pytest.param({0: [K1], 2: [NONE]}, [0, 1, 4], [(0, ["k1"], None), (2, [None], None)], id="clear-ad-not-tagged"),
pytest.param({0: [K1], 2: [K1]}, range(6), [(0, ["k1"], None)], id="same-tag-again"),
pytest.param({0: [SKD, WV_A]}, [3], [(0, ["skd", "data"], None)], id="two-systems"),
pytest.param(
{0: [WV_A, SKD], 3: [SKD_B]},
range(6),
[(0, ["data", "skd"], None), (3, ["data", "skd"], None)],
id="other-system-stays-in-force",
),
pytest.param(
{0: [ID_A, SKD], 3: [ID_B]},
range(6),
[(0, ["id-a", "skd"], None), (3, ["id-b", "skd"], None)],
id="identity-renewed",
),
pytest.param({0: [WV_A, SKD], 3: [WV_A]}, range(6), [(0, ["data", "skd"], None)], id="first-tag-again"),
pytest.param(
{0: [ID_A], 1: [SKD]}, range(6), [(0, ["id-a"], None), (1, ["id-a", "skd"], None)], id="tag-on-each"
),
pytest.param(
{0: [SKD, DISCONTINUITY_SEQUENCE, ID_A], 1: [SKD_B]},
range(6),
[(0, ["skd", "id-a"], None), (1, ["skd", "id-a"], None)],
id="lost-tag-beside-a-tag",
),
pytest.param(
{0: [SKD], 2: [K1], 4: [SKD_B]},
range(6),
[(0, ["skd"], None), (2, ["k1"], None), (4, ["skd"], None)],
id="other-method",
),
pytest.param(
{0: [WV_A, SKD], 2: [NONE], 4: [SKD]},
range(6),
[(0, ["data", "skd"], None), (2, [None], None), (4, ["skd"], None)],
id="none-ends-every-system",
),
pytest.param(
{0: [MAP, K1], 3: [MAP.replace("init", "next")]},
[1, 4],
@@ -427,7 +464,7 @@ def test_the_first_licence_reads_the_init_segment_of_its_own_key(
[
pytest.param({0: [MAP, SKD]}, id="first-segment"),
pytest.param({0: [MAP, SKD, DISCONTINUITY_SEQUENCE]}, id="lost"),
pytest.param({0: [MAP, WV_A], 3: [SKD]}, id="second-key"),
pytest.param({0: [MAP, WV_A], 2: [NONE], 3: [SKD]}, id="second-key"),
],
)
@pytest.mark.parametrize("cdm", ["widevine", None])
@@ -446,6 +483,25 @@ def test_a_tag_unshackle_cannot_license_is_refused_before_a_segment(
assert not [path for path in server.requests if path.endswith(".ts")]
def test_a_tag_of_another_keyformat_keeps_the_licensed_tag_in_force(
server: Any, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
DOWNLOAD_LICENCE_ONLY.set()
monkeypatch.setattr(Audio, "get_key_id", lambda self, data: KID_A)
licensed: list[UUID | None] = []
download(
server,
tmp_path,
monkeypatch,
{0: [MAP, WV_A, SKD], 3: [SKD_B]},
cdm=cdm_type_stub("widevine"),
licence=lambda drm, track_kid=None: licensed.append(track_kid),
)
assert licensed == [KID_A]
def test_a_lost_tag_is_bridged_with_the_first_init_segment(
server: Any, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None: