"""Atmos on an AC-4 track comes only from a manifest signal that a Dolby or ETSI document defines as Atmos.""" from __future__ import annotations import pytest from unshackle.core.export_name import audio_token from unshackle.core.manifests.dash import DASH from unshackle.core.manifests.hls import HLS from unshackle.core.tracks import Audio, Tracks from unshackle.core.wire import deserialize_audio, serialize_audio_track, track_from_dict, track_to_dict VIRTUALIZED = '' def hls_audio(channels: str, codecs: str = "ac-4") -> Audio: text = ( "#EXTM3U\n" f'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="a",NAME="English",LANGUAGE="en",CHANNELS="{channels}",URI="ac4.m3u8"\n' f'#EXT-X-STREAM-INF:BANDWIDTH=3000000,RESOLUTION=1920x1080,CODECS="avc1.640028,{codecs}",AUDIO="a"\n' "video.m3u8\n" ) (audio,) = HLS.from_text(text, "https://cdn.example/master.m3u8").to_tracks(language="en").audio return audio def dash_audio(codecs: str, channels: str, extra: str = "") -> Audio: text = f""" {extra} audio.mp4 """ (audio,) = DASH.from_text(text, "https://cdn.example/manifest.mpd").to_tracks(language="en").audio return audio def test_an_hls_ac4_rendition_with_the_atmos_identifier_is_atmos_without_a_joc_count() -> None: audio = hls_audio("2/IMSA,ATMOS") assert audio.codec == Audio.Codec.AC4 assert audio.atmos assert audio.channels == 2.0 assert not audio.joc assert "2.0, Atmos |" in str(audio) assert "JOC" not in str(audio) def test_an_hls_immersive_stereo_rendition_without_the_atmos_identifier_is_not_atmos() -> None: audio = hls_audio("2/IMSA") assert not audio.atmos assert audio.channels == 2.0 @pytest.mark.parametrize("channels", ["2", "6"]) def test_a_plain_hls_ac4_rendition_is_not_atmos(channels: str) -> None: assert not hls_audio(channels, codecs="ac-4.02.01.00").atmos def test_an_hls_joc_rendition_keeps_its_joc_count() -> None: audio = hls_audio("16/JOC", codecs="ec-3") assert audio.atmos assert audio.joc == 16 @pytest.mark.parametrize( ("codecs", "channels", "extra"), [ ("ac-4.02.01.00", "6", ""), ("ac-4.02.01.00", "2", ""), ("ac-4.02.02.00", "2", VIRTUALIZED), ], ids=["plain-5.1", "plain-2.0", "immersive-stereo"], ) def test_a_dash_ac4_representation_without_a_cited_atmos_signal_is_not_atmos( codecs: str, channels: str, extra: str ) -> None: """Neither presentation_version 2 nor virtualized_content proves Atmos: an IMS presentation may carry any content.""" audio = dash_audio(codecs, channels, extra) assert audio.codec == Audio.Codec.AC4 assert not audio.atmos def test_the_export_name_reads_atmos_without_a_joc_count() -> None: assert audio_token(hls_audio("2/IMSA,ATMOS")).endswith("2.0atmos") def test_atmos_without_a_joc_count_is_part_of_the_track_signature() -> None: assert Tracks.signature(hls_audio("2/IMSA,ATMOS")) != Tracks.signature(hls_audio("2/IMSA")) def test_atmos_without_a_joc_count_survives_the_export_track_dict() -> None: audio = track_from_dict(track_to_dict(hls_audio("2/IMSA,ATMOS"))) assert audio.atmos assert not audio.joc def test_hls_atmos_without_a_joc_count_survives_the_remote_round_trip() -> None: audio = deserialize_audio(serialize_audio_track(hls_audio("2/IMSA,ATMOS"))) assert audio.atmos assert not audio.joc