File: test_xmltompd.py

package info (click to toggle)
python-mpegdash 0.1.5-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 216 kB
  • sloc: python: 776; makefile: 5
file content (47 lines) | stat: -rw-r--r-- 2,215 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
try:
    import unittest2 as unittest
except:
    import unittest

from mpegdash.parser import MPEGDASHParser


class XML2MPDTestCase(unittest.TestCase):
    def test_xml2mpd_from_string(self):
        mpd_string = '''
        <MPD xmlns="urn:mpeg:DASH:schema:MPD:2011" mediaPresentationDuration="PT0H1M52.43S" minBufferTime="PT1.5S"
        profiles="urn:mpeg:dash:profile:isoff-on-demand:2011" type="static">
          <Period duration="PT0H1M52.43S" start="PT0S">
            <AdaptationSet>
              <ContentComponent contentType="video" id="1" />
              <Representation bandwidth="4190760" codecs="avc1.640028" height="1080" id="1" mimeType="video/mp4" width="1920">
                <BaseURL>motion-20120802-89.mp4</BaseURL>
                <SegmentBase indexRange="674-981">
                  <Initialization range="0-673" />
                </SegmentBase>
              </Representation>
            </AdaptationSet>
          </Period>
        </MPD>
        '''
        self.assert_mpd(MPEGDASHParser.parse(mpd_string))

    def test_xml2mpd_from_file(self):
        self.assert_mpd(MPEGDASHParser.parse('./tests/mpd-samples/sample-001.mpd'))
        self.assert_mpd(MPEGDASHParser.parse('./tests/mpd-samples/motion-20120802-manifest.mpd'))
        self.assert_mpd(MPEGDASHParser.parse('./tests/mpd-samples/oops-20120802-manifest.mpd'))
        self.assert_mpd(MPEGDASHParser.parse('./tests/mpd-samples/360p_speciment_dash.mpd'))

    @unittest.skip("Prevent internet access")
    def test_xml2mpd_from_url(self):
        mpd_url = 'http://yt-dash-mse-test.commondatastorage.googleapis.com/media/motion-20120802-manifest.mpd'
        self.assert_mpd(MPEGDASHParser.parse(mpd_url))

    def assert_mpd(self, mpd):
        self.assertTrue(mpd is not None)
        self.assertTrue(len(mpd.periods) > 0)
        self.assertTrue(mpd.periods[0].adaptation_sets is not None)
        self.assertTrue(len(mpd.periods[0].adaptation_sets) > 0)
        self.assertTrue(mpd.periods[0].adaptation_sets[0].representations is not None)
        self.assertTrue(len(mpd.periods[0].adaptation_sets[0].representations) > 0)
        self.assertTrue(len(mpd.periods[0].adaptation_sets[0].representations[0].id) > 0)