def testMPDwithStartand2Durations(self): urlParts = [ 'pdash', 'start_1200', 'dur_600', 'dur_300', 'testpic', 'Manifest.mpd' ] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=900) d = dp.handle_request() if dash_proxy.PUBLISH_TIME: self.assertTrue(d.find('publishTime="1970-01-01T00:15:00Z"') > 0) self.assertTrue( d.find('availabilityEndTime="1970-01-01T00:30:00Z"') > 0) dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=1795) d = dp.handle_request() if dash_proxy.PUBLISH_TIME: self.assertTrue(d.find('publishTime="1970-01-01T00:29:00Z"') > 0) self.assertTrue( d.find('availabilityEndTime="1970-01-01T00:35:00Z"') > 0)
def testThatTimesDontJump(self): "Test that times don't jump as reported in ISSUE #91." # First get the MPD corresponding to 5.mpd.txt now = 1578681199 urlParts = ['livesim', 'segtimeline_1', 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("server.org", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=now) d = mpd_proxy.get_mpd(dp) root = ElementTree.fromstring(d) first_t, first_d = find_first_audio_t(root) # tsbd = 300 # TimeShiftBufferDepth self.assertTrue(now - first_t / 48000 > 300, "Did not get before timeshift window start") later = now + 6 urlParts = ['livesim', 'segtimeline_1', 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("server.org", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=later) d = mpd_proxy.get_mpd(dp) root = ElementTree.fromstring(d) second_t, second_d = find_first_audio_t(root) self.assertEqual(second_t, first_t + first_d, "Second t is not first t + first d ")
def testNewSegmentsAdded(self): urlParts = [ 'livesim', 'baseurl_u10_d20', 'segtimeline_1', 'segtimelineloss_1', 'testpic', 'Manifest.mpd' ] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=10) d = mpd_proxy.get_mpd(dp) start = d.find('<SegmentTimeline>') end = d.find('</SegmentTimeline>') testOutputFile = "SegTimeline3.txt" write_data_to_outfile(d[start:end + 18].encode('utf-8'), testOutputFile) segTimeline = d[start:end + 18] dp2 = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=31) d2 = mpd_proxy.get_mpd(dp2) start2 = d2.find('<SegmentTimeline>') end2 = d2.find('</SegmentTimeline>') testOutputFile = "SegTimeline4.txt" write_data_to_outfile(d2[start2:end2 + 18].encode('utf-8'), testOutputFile) segTimeline2 = d2[start2:end2 + 18] self.assertNotEqual(segTimeline, segTimeline2)
def testThatTimeSegmentIsSameAsNumber(self): urlParts = [ 'livesim', 'segtimeline_1', 'testpic', 'A1', 't%d.m4s' % self.seg_time ] dp = dash_proxy.DashProvider("server.org", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=self.now) time_seg = dp.handle_request() urlParts = [ 'livesim', 'segtimeline_1', 'testpic', 'A1', '%d.m4s' % self.seg_nr ] dp = dash_proxy.DashProvider("server.org", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=self.now) nr_seg = dp.handle_request() self.assertEqual(len(time_seg), len(nr_seg)) self.assertEqual(time_seg, nr_seg)
def testMpdPeriodReplaced(self): " Check whether appropriate periods have been replaced by in .mpd file" collectresult = 1 for k in [1, 2, 5, 10]: nr_period_per_hour = 10 nr_xlink_periods_per_hour = k urlParts = [ 'livesim', 'periods_%s' % nr_period_per_hour, 'xlink_%s' % nr_xlink_periods_per_hour, 'testpic_2s', 'Manifest.mpd' ] dp = dash_proxy.DashProvider("10.4.247.98", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=10000) d = dp.handle_request() period_id_all = findall('Period id="([^"]*)"', d) # Find all period ids in the .mpd file returned. # We will check whether the correct periods have been xlinked here. one_xlinks_for_how_many_periods = nr_period_per_hour / nr_xlink_periods_per_hour period_id_xlinks = [ int(x[1:]) % one_xlinks_for_how_many_periods for x in period_id_all ] # All the period ids. # If there were any periods, that were not supposed to be there, # then one of the elements in period_id_xlinks would be zero. result = reduce(mul, period_id_xlinks, 1) collectresult = result * collectresult self.assertTrue(collectresult != 0)
def testMpdPeriodReplaced(self): " Check whether appropriate periods have been replaced by in .mpd file" collectresult = 0 for k in [1, 2, 5, 10, 20, 30]: nr_period_per_hour = 60 nr_etp_periods_per_hour = k urlParts = ['livesim', 'periods_%s' % nr_period_per_hour, 'etp_%s' % nr_etp_periods_per_hour, 'testpic_2s', 'Manifest.mpd'] dp = dash_proxy.DashProvider("10.4.247.98", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=10000) d = mpd_proxy.get_mpd(dp) xml = ET.fromstring(d) # Make the string as a xml document. periods_containing_duration_attribute = [] # This array would contain all the period id that have duration attributes. # In the following, we will check if the correct period element have been assigned duration attributes. for child in xml.findall('{urn:mpeg:dash:schema:mpd:2011}Period'): # Collect all period elements first if 'duration' in child.attrib: # If the period element has the duration attribute. periods_containing_duration_attribute.append(child.attrib['id']) # Then collect its period id in this array one_etp_for_how_many_periods = nr_period_per_hour/nr_etp_periods_per_hour checker_array = [int(x[1:]) % one_etp_for_how_many_periods for x in periods_containing_duration_attribute] # In the above line, we check if each period id evaluates to zero or not. # Ideally, if everything worked well, then the checker array would be all zero. collectresult = collectresult + sum(checker_array) # Here, we keep collecting the sum of checker array. Even if one element evaluates to non zero values, then # the whole test will fail. self.assertTrue(collectresult == 0)
def testMpdGenerationHttps(self): "Check if availabilityTimeOffset works with https" urlParts = ['livesim', 'ato_2.5', 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=0, is_https=True) d = mpd_proxy.get_mpd(dp) self.assertEqual(d.find('availabilityTimeOffset="2.5')-d.find('<BaseURL'), len('<BaseURL')+1)
def testMpdPeriodReplaced(self): "Check whether before every xlink period, duration attribute has been inserted." collect_result = [] urlParts = [ 'livesim', 'periods_60', 'xlink_30', 'insertad_1', 'testpic_2s', 'Manifest.mpd' ] dp = dash_proxy.DashProvider("10.4.247.98", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=10000) d = mpd_proxy.get_mpd(dp) xml = ET.fromstring(d) # Make the string as a xml document. # In the following, we will check if for every period before every xlink period, duration attribute has been # added or not. prev_child = [] for child in xml.findall('{urn:mpeg:dash:schema:mpd:2011}Period' ): # Collect all period elements first if '{http://www.w3.org/1999/xlink}actuate' in child.attrib: # If the period element has the duration attribute. collect_result.append( 'duration' in prev_child.attrib) # Then collect its period id in this prev_child = child # Ideally, at the periods should have a duration attribute, if no then the test fails. self.assertFalse(False in collect_result)
def testMpdAtoSettings(self): "availabilityTimeOffset shouldn't appear if the setting is invalid" testelem = ['ato_0', 'ato_-10', 'ato_aa'] for test in testelem: urlParts = ['livesim', test, 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=0) d = mpd_proxy.get_mpd(dp) self.assertTrue(d.find('availabilityTimeOffset') < 0)
def testCheckDowAndUpDependingOnTime(self): urlParts = [ 'livesim', 'ato_inf', 'baseurl_d40_u20', 'testpic', 'A1', '0.m4s' ] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=68) self.assertFalse(isMediaSegment(dash_proxy.get_media(dp))) dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=108) self.assertTrue(isMediaSegment(dash_proxy.get_media(dp)))
def testMpdGeneration(self): "Check if availabilityTimeOffset is added correctly to the MPD file." testOutputFile = "ato.mpd" rm_outfile(testOutputFile) urlParts = ['livesim', 'ato_30', 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=0) d = mpd_proxy.get_mpd(dp) write_data_to_outfile(d.encode('utf-8'), testOutputFile) self.assertEqual(d.find('availabilityTimeOffset="30')-d.find('<BaseURL'), len('<BaseURL')+1)
def get_segment(nr, now): urlParts = [ 'pdash', 'start_3540', 'stop_3660', 'timeoffset_0', 'testpic', 'A1', '%d.m4s' % nr ] dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now) return dp.handle_request()
def testCheckUpAndDownDependingOnTime(self): urlParts = [ 'livesim', 'ato_inf', 'baseurl_u40_d20', 'testpic', 'A1', '0.m4s' ] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=68) self.assertTrue(isMediaSegment(dp.handle_request())) dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=108) self.assertFalse(isMediaSegment(dp.handle_request()))
def testCheckAvailabilityTimeFractional(self): "Check if timing with fractional seconds is correct with availabilityTimeOffset." urlParts = ['livesim', 'start_60', 'ato_1.5', 'testpic', 'A1', '0.m4s'] expected_results = [False, True, True] # should be available from 60+6-1.5=64.5s (segment duration is 6s) times = [64.3, 64.6, 64.9] for (exp, now) in zip(expected_results, times): dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=now) d = dash_proxy.get_media(dp) self.assertEqual(isMediaSegment(d), exp, "Did not match for time %s" % now)
def testCheckAvailabilityTimeErrorMsg(self): "Check if error message is correct with availabilityTimeOffset." testelem = ['ato_30', 'ato_1.5', 'ato_inf'] expected_results = ['1.0s', '29.5s', '25.0s'] for (exp, elem) in zip(expected_results, testelem): urlParts = ['livesim', 'start_60', elem, 'testpic', 'A1', '0.m4s'] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=35) d = dash_proxy.get_media(dp) self.assertEqual(str(d), "{'ok': False, 'pl': 'Request 0.m4s before first seg AST. " + exp + " too early\\n'}")
def setUp(self): now = 1356998460 urlParts = ['pdash', 'scte35_1', 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=now) self.mpd = dp.handle_request()
def testInit(self): urlParts = ['pdash', 'testpic', 'en', 'A1', 'init.mp4'] dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=0) d = dp.handle_request() self.assertEqual(len(d), 617)
def testMediaSegmentTooEarlyWithAST(self): urlParts = ['pdash', 'start_6', 'testpic', 'A1', '0.m4s'] # Should be available after 12s dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=10) d = dp.handle_request() self.assertEqual(d['ok'], False) dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=14) d = dp.handle_request() self.assertEqual(len(d), 40346) # A full media segment
def testStartNumber(self): "Check that all 3 media components have startNumber=0" urlParts = ['livesim', 'testpic_stpp', 'Manifest_stpp.mpd'] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=0) d = mpd_proxy.get_mpd(dp) self.assertEqual(d.count('startNumber="0'), 3)
def testMediaSegmentTooEarly(self): urlParts = ['pdash', 'testpic', 'A1', '5.m4s'] # Should be available after 36s dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=34) d = dp.handle_request() self.assertEqual(d['ok'], False)
def testSuggestedPresentationDelayPresent(self): "Check that suggestedPresentationDelay get the right value." urlParts = ['pdash', 'spd_10', 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=0) d = dp.handle_request() self.assertTrue(d.find('suggestedPresentationDelay="PT10S"') > 0)
def testSuggestedPresentationDelayNotPresent(self): "Check that suggestedPresentationDelayIsNotPresent." urlParts = ['pdash', 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=0) d = dp.handle_request() self.assertTrue(d.find('suggestedPresentationDelay') < 0)
def testOtherOrderOfOptions(self): urlParts = [ 'livesim', 'baseurl_u20_d10', 'ato_inf', 'testpic', 'A1', '0.m4s' ] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=10) d = dash_proxy.get_media(dp) self.assertTrue(isMediaSegment(d), "Not a media segment, but %r" % d) dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=25) self.assertFalse(isMediaSegment(dash_proxy.get_media(dp)), "Is a media segment, but should not be")
def testThatNoPresentationTimeOffsetForTfdt32(self): now = 1393936560 segNr = 232322749 urlParts = ['pdash', 'tfdt_32', 'testpic', 'V1', 'Manifest.mpd'] dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=now) d = dp.handle_request() self.assertFalse(d.find('presentationTimeOffset') > 0)
def testMediaSegmentBeforeTimeShiftBufferDepth(self): now = 1356999060 segment = "%d.m4s" % ((now - 330) / 6) urlParts = ['pdash', 'testpic', 'A1', segment] dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=now) d = dp.handle_request() self.assertEqual(d['ok'], False)
def testEmsgInSegment(self): urlParts = [ 'livesim', 'baseurl_u10_d20', 'segtimeline_1', 'segtimelineloss_1', 'testpic', 'A1', '0.m4s' ] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=10) d = dash_proxy.get_media(dp) self.assertTrue(isEmsgPresentInSegment(d))
def testInitMux(self): testOutputFile = "test_mux_init.mp4" rm_outfile(testOutputFile) now = 1356998460 urlParts = ['pdash', 'testpic', 'V1__A1', "init.mp4"] dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=now) d = dp.handle_request() write_data_to_outfile(d, testOutputFile)
def testMPDhandling(self): mpdprocessor.SET_BASEURL = True urlParts = ['pdash', 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=0) d = dp.handle_request() self.assertTrue( d.find("<BaseURL>http://streamtest.eu/pdash/testpic/</BaseURL>") > 0)
def testMediaSegmentInIntervalWithoutOffset(self): "Check that segment 5 is available after an hour." urlParts = [ 'pdash', 'start_3600', 'stop_3660', 'testpic', 'A1', '5.m4s' ] dp = dash_proxy.DashProvider("127.0.0.1", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=3650) d = dp.handle_request() self.assertEqual(d[4:8], 'styp')
def testMPDGet(self): mpdprocessor.SET_BASEURL = True urlParts = ['pdash', 'testpic', 'Manifest.mpd'] dp = dash_proxy.DashProvider("streamtest.eu", urlParts, None, VOD_CONFIG_DIR, CONTENT_ROOT, now=0) d = mpd_proxy.get_mpd(dp) self.assertGreater( d.find("<BaseURL>http://streamtest.eu/pdash/testpic/</BaseURL>"), 0)