def testReceivingTagEvent(self):
        d = self._initComp()
        d.addCallback(lambda _: comptest.delayed_d(0.1, _))

        def assertTitleSet(title):
            self.assertEqual(title, \
                      self.comp.muxer.get_property('iradio-title'))

        # check if we respond currectly for title events
        d.addCallback(lambda _: self._sendTitleEvent('some title'))
        d.addCallback(lambda _: comptest.delayed_d(0.8, 'some title'))
        d.addCallback(assertTitleSet)

        d.addCallback(lambda _: self._sendTitleEvent('some other title'))
        d.addCallback(lambda _: comptest.delayed_d(0.8, 'some other title'))
        d.addCallback(assertTitleSet)

        # now check if the events setting response headers work
        mapping = {'icy-name': 'organization',
                   'icy-genre': 'genre',
                   'icy-url': 'location'}
        struc = gst.Structure(name='taglist')
        for key in mapping:
            struc.set_value(mapping[key], mapping[key])
        d.addCallback(lambda _: self._sendEvent(struc))

        def assertValuesInResponseHeadersSet(_):
            for key in mapping:
                self.assertTrue(key in self.comp.icyHeaders, key)
                self.assertEqual(mapping[key], self.comp.icyHeaders[key])
        d.addCallback(lambda _: comptest.delayed_d(0.5, _))
        d.addCallback(assertValuesInResponseHeadersSet)

        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def testStreamingICY(self):
        d = self._initComp()
        d.addCallback(lambda _: comptest.delayed_d(1, _))

        def getStream():
            icyMetaint = self.comp.muxer.get_property('icy-metaint')
            toDownload = 2 * icyMetaint + 200
            return downloadStream(self.comp.getUrl(),\
                           headers={'Icy-MetaData': 1}, limit=toDownload)

        def assertsOnStream(factory):
            icyMetaint = self.comp.muxer.get_property('icy-metaint')
            self.assertTrue('icy-metaint' in factory.response_headers)
            self.assertEqual(\
                str(icyMetaint), factory.response_headers['icy-metaint'][0])

            self.assertTrue('icy-br' in factory.response_headers)

            ct = factory.response_headers['content-type'][0]
            self.assertEqual('audio/mpeg', ct)

            self.assertEqual(1, self.comp.getClients())


        d.addCallback(lambda _: getStream())
        d.addCallback(assertsOnStream)
        d.addCallback(lambda _: comptest.delayed_d(0.1, _))
        d.addCallback(lambda _: self.assertEqual(0, self.comp.getClients()))

        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def testStreamingICY(self):
        d = self._initComp()
        d.addCallback(lambda _: comptest.delayed_d(1, _))

        def getStream():
            icyMetaint = self.comp.muxer.get_property('icy-metaint')
            toDownload = 2 * icyMetaint + 200
            return downloadStream(self.comp.getUrl(),\
                           headers={'Icy-MetaData': 1}, limit=toDownload)

        def assertsOnStream(factory):
            icyMetaint = self.comp.muxer.get_property('icy-metaint')
            self.assertTrue('icy-metaint' in factory.response_headers)
            self.assertEqual(\
                str(icyMetaint), factory.response_headers['icy-metaint'][0])

            self.assertTrue('icy-br' in factory.response_headers)

            ct = factory.response_headers['content-type'][0]
            self.assertEqual('application/x-icy', ct)

            self.assertEqual(1, self.comp.getClients())

        d.addCallback(lambda _: getStream())
        d.addCallback(assertsOnStream)
        d.addCallback(lambda _: comptest.delayed_d(0.1, _))
        d.addCallback(lambda _: self.assertEqual(0, self.comp.getClients()))

        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def testInitialization(self):
        d = self._initComp()

        d.addCallback(lambda _: comptest.delayed_d(0.1, _))

        def _assertsOnSinks(_):
            # check if sinks and caps are initialized properly
            self.assertTrue(self.comp.hasCaps())
            capsExpected = {True: 'application/x-icy',
                            False: 'audio/mpeg'}
            for withID3 in capsExpected:
                # check caps
                sink = self.comp.sinksByID3[withID3]
                self.assertEqual(capsExpected[withID3],\
                    sink.caps[0].get_name())
                # check sync method (latest-keyframe)
                self.assertEqual(2, sink.get_property('sync-method'))
        d.addCallback(_assertsOnSinks)

        def assertBrSet(_):
            self.assertTrue('icy-br' in self.comp.icyHeaders)
        d.addCallback(assertBrSet)

        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def test_time_disker_running_and_happy(self):
        properties = {
            'directory': '/tmp',
            'rotate-type': 'time',
            'time': 10,
            'symlink-to-current-recording': 'current'
        }

        dc = comptest.ComponentWrapper('disk-consumer',
                                       disker.Disker,
                                       name='disk-video',
                                       props=properties,
                                       plugs=self.build_plugs([self.s]))

        self.tp.set_flow([self.prod, dc])

        d = self.tp.start_flow()

        # wait for the disker to go happy
        d.addCallback(lambda _: dc.wait_for_mood(moods.happy))
        # let it run for a few seconds
        d.addCallback(lambda _: comptest.delayed_d(30, _))
        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def testInitialization(self):
        d = self._initComp()

        d.addCallback(lambda _: comptest.delayed_d(0.1, _))

        def _assertsOnSinks(_):
            # check if sinks and caps are initialized properly
            self.assertTrue(self.comp.hasCaps())
            capsExpected = {True: 'application/x-icy', False: 'audio/mpeg'}
            for withID3 in capsExpected:
                # check caps
                sink = self.comp.sinksByID3[withID3]
                self.assertEqual(capsExpected[withID3],\
                    sink.caps[0].get_name())
                # check sync method (latest-keyframe)
                self.assertEqual(2, sink.get_property('sync-method'))

        d.addCallback(_assertsOnSinks)

        def assertBrSet(_):
            self.assertTrue('icy-br' in self.comp.icyHeaders)

        d.addCallback(assertBrSet)

        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def testStreamingNonICY(self):
        d = self._initComp()
        d.addCallback(lambda _: comptest.delayed_d(1, _))

        def getStream():
            icyMetaint = self.comp.muxer.get_property('icy-metaint')
            toDownload = 2 * icyMetaint + 200
            return downloadStream(self.comp.getUrl(), limit=toDownload)

        def assertsOnStream(factory):
            ct = factory.response_headers['content-type'][0]
            self.assertEqual('audio/mpeg', ct)

            self.assertEqual(1, self.comp.getClients())

        d.addCallback(lambda _: getStream())
        d.addCallback(assertsOnStream)
        d.addCallback(lambda _: comptest.delayed_d(0.1, _))
        d.addCallback(lambda _: self.assertEqual(0, self.comp.getClients()))
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def testReceivingTagEvent(self):
        d = self._initComp()
        d.addCallback(lambda _: comptest.delayed_d(0.1, _))

        def assertTitleSet(title):
            self.assertEqual(title, \
                      self.comp.muxer.get_property('iradio-title'))

        # check if we respond currectly for title events
        d.addCallback(lambda _: self._sendTitleEvent('some title'))
        d.addCallback(lambda _: comptest.delayed_d(0.8, 'some title'))
        d.addCallback(assertTitleSet)

        d.addCallback(lambda _: self._sendTitleEvent('some other title'))
        d.addCallback(lambda _: comptest.delayed_d(0.8, 'some other title'))
        d.addCallback(assertTitleSet)

        # now check if the events setting response headers work
        mapping = {
            'icy-name': 'organization',
            'icy-genre': 'genre',
            'icy-url': 'location'
        }
        struc = gst.Structure(name='taglist')
        for key in mapping:
            struc.set_value(mapping[key], mapping[key])
        d.addCallback(lambda _: self._sendEvent(struc))

        def assertValuesInResponseHeadersSet(_):
            for key in mapping:
                self.assertTrue(key in self.comp.icyHeaders, key)
                self.assertEqual(mapping[key], self.comp.icyHeaders[key])

        d.addCallback(lambda _: comptest.delayed_d(0.5, _))
        d.addCallback(assertValuesInResponseHeadersSet)

        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def _videoscale_test(self, properties, par, w, h, exact=False):
        vc = comptest.ComponentWrapper('video-converter', video.Converter,
                                       name='video-converter',
                                       cfg={'properties': properties})
        self.tp.set_flow([self.prod, vc])

        d = self.tp.start_flow()

        # wait for the converter to go happy
        d.addCallback(lambda _: vc.wait_for_mood(moods.happy))
        d.addCallback(self._test_videoscale, vc, par, w, h, exact=exact)
        # let it run for a few seconds
        d.addCallback(lambda _: comptest.delayed_d(2, _))
        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def test_running_and_happy(self):
        vc = comptest.ComponentWrapper('video-converter', video.Converter,
                                       name='video-converter',
                                       cfg={'properties':
                                            {'deinterlace-mode': 'disabled'}})

        self.tp.set_flow([self.prod, vc])

        d = self.tp.start_flow()

        # wait for the converter to go happy
        d.addCallback(lambda _: vc.wait_for_mood(moods.happy))
        # let it run for a few seconds
        d.addCallback(lambda _: comptest.delayed_d(5, _))
        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
Exemple #11
0
    def _videoscale_test(self, properties, par, w, h, exact=False):
        vc = comptest.ComponentWrapper('video-converter',
                                       video.Converter,
                                       name='video-converter',
                                       cfg={'properties': properties})
        self.tp.set_flow([self.prod, vc])

        d = self.tp.start_flow()

        # wait for the converter to go happy
        d.addCallback(lambda _: vc.wait_for_mood(moods.happy))
        d.addCallback(self._test_videoscale, vc, par, w, h, exact=exact)
        # let it run for a few seconds
        d.addCallback(lambda _: comptest.delayed_d(2, _))
        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def test_deinterlace_auto_True(self):
        properties = {'deinterlace-method': "tomsmocomp"}
        vc = comptest.ComponentWrapper('video-converter', video.Converter,
                                       name='video-converter',
                                       cfg={'properties': properties})

        self.tp.set_flow([self.prod, vc])

        d = self.tp.start_flow()

        # wait for the converter to go happy
        d.addCallback(lambda _: vc.wait_for_mood(moods.happy))
        # let it run for a few seconds
        d.addCallback(lambda _: comptest.delayed_d(10, _))
        d.addCallback(self._test_interlaced, vc, False)
        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
Exemple #13
0
    def test_deinterlace_auto_True(self):
        properties = {'deinterlace-method': "tomsmocomp"}
        vc = comptest.ComponentWrapper('video-converter',
                                       video.Converter,
                                       name='video-converter',
                                       cfg={'properties': properties})

        self.tp.set_flow([self.prod, vc])

        d = self.tp.start_flow()

        # wait for the converter to go happy
        d.addCallback(lambda _: vc.wait_for_mood(moods.happy))
        # let it run for a few seconds
        d.addCallback(lambda _: comptest.delayed_d(10, _))
        d.addCallback(self._test_interlaced, vc, False)
        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
Exemple #14
0
    def test_running_and_happy(self):
        vc = comptest.ComponentWrapper(
            'video-converter',
            video.Converter,
            name='video-converter',
            cfg={'properties': {
                'deinterlace-mode': 'disabled'
            }})

        self.tp.set_flow([self.prod, vc])

        d = self.tp.start_flow()

        # wait for the converter to go happy
        d.addCallback(lambda _: vc.wait_for_mood(moods.happy))
        # let it run for a few seconds
        d.addCallback(lambda _: comptest.delayed_d(5, _))
        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def test_time_disker_running_and_happy(self):
        properties = {'directory': '/tmp',
                      'rotate-type': 'time',
                      'time': 10,
                      'symlink-to-current-recording': 'current'}

        dc = comptest.ComponentWrapper('disk-consumer', disker.Disker,
                                       name='disk-video', props=properties,
                                       plugs=self.build_plugs([self.s]))

        self.tp.set_flow([self.prod, dc])

        d = self.tp.start_flow()

        # wait for the disker to go happy
        d.addCallback(lambda _: dc.wait_for_mood(moods.happy))
        # let it run for a few seconds
        d.addCallback(lambda _: comptest.delayed_d(30, _))
        # and finally stop the flow
        d.addCallback(lambda _: self.tp.stop_flow())
        return d
    def testFlow(self):
        enc = comptest.pipeline_cnv('flumch264enc max-keyframe-distance=15'
                                    'min-keyframe-distance=15')

        properties = {'fragment-duration': 500}
        mux = comptest.ComponentWrapper('fmp4-muxer', fmp4.FMP4,
                                       name='muxer', props=properties,
                                       plugs={})
        tester = comptest.ComponentWrapper('fmp4-tester', FMP4Tester,
                                       name='tester', props=properties,
                                       plugs={})

        self.tp.set_flow([self.prod, enc, mux, tester])

        d = self.tp.start_flow()
        tester.comp.test = self

        # wait for the muxer to go happy
        d.addCallback(lambda _: mux.wait_for_mood(moods.happy))

        # let it run for a few seconds
        d.addCallback(lambda _: comptest.delayed_d(3, _))
        return d
    def testManifestAndFragment(self):
        d = self._initComp()

        d.addCallback(lambda _: comptest.delayed_d(2.0, _))

        def check_manifest(r):
            from xml.dom.minidom import parseString
            media = parseString(r)
            c = media.getElementsByTagName("SmoothStreamingMedia")[0]\
                      .getElementsByTagName("StreamIndex")[0]\
                      .getElementsByTagName("c")
            # in 2 seconds after being happy we should really have at
            # least 2 fragments (1 second of encoded data more)
            self.failIf(len(c) < 2)
            # return last known timestamp
            return int(c[-1].getAttribute("t"))

        d.addCallback(lambda _: \
                client.getPage(self.getURL('/mytest/Manifest')))
        d.addCallback(check_manifest)

        def check_fragment(f):
            # make sure we get at least 1k of encoded video fragment..
            self.failIf(len(f) < 1000)
            # and that we got a moof
            self.assertEqual(f[4:8], "moof")

        url = '/mytest/QualityLevels(400000)/Fragments(video=%d)'
        d.addCallback(lambda t: client.getPage(
            self.getURL(url % t)))
        d.addCallback(check_fragment)

        # and finally stop the flow
        # d.addCallback(lambda _: self.tp.stop_flow())

        return d
 def tearDown(self):
     d = comptest.delayed_d(1, None)
     d.addCallback(comptest.cleanup_reactor)
     return d
 def tearDown(self):
     d = comptest.delayed_d(1, None)
     d.addCallback(comptest.cleanup_reactor)
     return d