Skip to content

Commit

Permalink
Support Low Latency playlists with omitted LAST-MSN (globocom#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbayles authored Oct 3, 2024
1 parent 49417d0 commit 1108edc
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
5 changes: 3 additions & 2 deletions m3u8/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ def __str__(self):


class RenditionReport(BasePathMixin):
def __init__(self, base_uri, uri, last_msn, last_part=None):
def __init__(self, base_uri, uri, last_msn=None, last_part=None):
self.base_uri = base_uri
self.uri = uri
self.last_msn = last_msn
Expand All @@ -1303,7 +1303,8 @@ def __init__(self, base_uri, uri, last_msn, last_part=None):
def dumps(self):
report = []
report.append("URI=" + quoted(self.uri))
report.append("LAST-MSN=" + str(self.last_msn))
if self.last_msn is not None:
report.append("LAST-MSN=" + str(self.last_msn))
if self.last_part is not None:
report.append("LAST-PART=" + str(self.last_part))

Expand Down
52 changes: 52 additions & 0 deletions tests/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,58 @@
#EXT-X-RENDITION-REPORT:URI="../4M/waitForMSN.php",LAST-MSN=273,LAST-PART=3
"""

LOW_LATENCY_OMITTED_ATTRIBUTES = """
#EXTM3U
#EXT-X-VERSION:7
#EXT-X-TARGETDURATION:2
#EXT-X-SERVER-CONTROL:CAN-BLOCK-RELOAD=YES,PART-HOLD-BACK=2.171
#EXT-X-PART-INF:PART-TARGET=1.034
#EXT-X-MAP:URI="init_data.m4s"
#EXT-X-MEDIA-SEQUENCE:6342
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:31:57.350+00:00
#EXTINF:2,
chunk_6342.m4s
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:31:59.350+00:00
#EXTINF:2,
chunk_6343.m4s
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:32:01.350+00:00
#EXTINF:2,
chunk_6344.m4s
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:32:03.350+00:00
#EXTINF:2,
chunk_6345.m4s
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:32:05.350+00:00
#EXTINF:2,
chunk_6346.m4s
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:32:07.350+00:00
#EXTINF:2,
chunk_6347.m4s
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:32:09.350+00:00
#EXTINF:2,
chunk_6348.m4s
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:32:11.350+00:00
#EXT-X-PART:DURATION=1,URI="chunk_6349.0.m4s",INDEPENDENT=YES
#EXT-X-PART:DURATION=1,URI="chunk_6349.1.m4s"
#EXTINF:2,
chunk_6349.m4s
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:32:13.350+00:00
#EXT-X-PART:DURATION=1,URI="chunk_6350.0.m4s",INDEPENDENT=YES
#EXT-X-PART:DURATION=1,URI="chunk_6350.1.m4s"
#EXTINF:2,
chunk_6350.m4s
#EXT-X-PROGRAM-DATE-TIME:2024-09-24T15:32:15.350+00:00
#EXT-X-PART:DURATION=1,URI="chunk_6351.0.m4s?skid=default&signature=NjZmYzFjODBfYzY3NGRlODc4Zjk1MjM1OGNmMmE3NjhiM2E2NTUyNGI1Y2JiYzMyZDU5YTFjNTQzODI2MjI5ZTllZmNhMDZmNQ==&zone=1",INDEPENDENT=YES
#EXT-X-PART:DURATION=1,URI="chunk_6351.1.m4s?skid=default&signature=NjZmYzFjODBfMDcwMjA0OTZlMTE3Y2RiN2VjOGY2YjE2MDE2NTAwZThlN2Q3NjUyZTAzM2YxZTZlZmFlZTg1ZThmZWEyZmQ4Ng==&zone=1"
#EXTINF:2,
chunk_6350.m4s
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="chunk_6352.0.m4s?skid=default&signature=NjZmYzFjODBfMzkyZmNiOWNjNmY5N2EwN2QwNTU3YTA3M2Q0ZTRlMWU2YjliZDMyM2Y0MTRmYTY5OTdhODIyMmIwY2QwOWY1NQ==&zone=1"
#EXT-X-RENDITION-REPORT:URI="rendition_1.m3u8"
#EXT-X-RENDITION-REPORT:URI="rendition_2.m3u8"
#EXT-X-RENDITION-REPORT:URI="rendition_3.m3u8"
#EXT-X-RENDITION-REPORT:URI="rendition_4.m3u8"
#EXT-X-RENDITION-REPORT:URI="rendition_5.m3u8"
"""

LOW_LATENCY_WITH_PRELOAD_AND_BYTERANGES_PLAYLIST = """
#EXTM3U
#EXTINF:4.08,
Expand Down
8 changes: 8 additions & 0 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,14 @@ def test_ll_playlist():
assert obj.preload_hint.base_uri == "http://localhost/test_base_uri"


def test_ll_playlist_omitted_attributes():
# RFC 8216 4.4.5.4 states that even the required attribute LAST-MSN
# can be omitted in certain conditions.
obj = m3u8.M3U8(playlists.LOW_LATENCY_OMITTED_ATTRIBUTES)
text = obj.dumps()
assert '#EXT-X-RENDITION-REPORT:URI="rendition_1.m3u8"\n' in text


def test_add_rendition_report_to_playlist():
obj = m3u8.M3U8()

Expand Down

0 comments on commit 1108edc

Please sign in to comment.