Beispiel #1
0
def select_player():
    log.startLogging(sys.stdout)

    persistent_conn = False
    check_warning_buffering = False

    mqtime = 1
    if float(options['min_queue_time']) >= 0:
        mqtime = float(options['min_queue_time'])

    #MediaEngine
    if options['media_engine'] == 'gst':
        #gst_init()
        from media_engines.GstMediaEngine import GstMediaEngine
        media_engine = GstMediaEngine(decode_video=True, min_queue_time=mqtime)
    elif options['media_engine'] == 'nodec':
        #gst_init()
        from media_engines.GstMediaEngine import GstMediaEngine
        media_engine = GstMediaEngine(decode_video=False,
                                      min_queue_time=mqtime)
    elif options['media_engine'] == 'fake':
        from media_engines.FakeMediaEngine import FakeMediaEngine
        media_engine = FakeMediaEngine(min_queue_time=mqtime)
    else:
        print 'Error. Unknown Media Engine'
        sys.exit()

    from twisted.internet import reactor

    #Controller
    if options['controller'] == 'conventional':
        from controllers.ConventionalController import ConventionalController
        controller = ConventionalController()
        controller.setIdleDuration(4)
    elif options['controller'] == 'tobasco':
        from controllers.TOBASCOController import TOBASCOController
        controller = TOBASCOController()
    elif options['controller'] == 'max':
        check_warning_buffering = False
        from controllers.MaxQualityController import MaxQualityController
        controller = MaxQualityController()
    else:
        print 'Error. Unknown Control Algorithm'
        sys.exit()

    if not options['log_sub_dir']:
        log_sub_dir = options['controller']
    else:
        log_sub_dir = options['log_sub_dir']

    #Parser
    url_playlist = options['url']
    if ".mpd" in url_playlist:
        from parsers.DASH_mp4Parser import DASH_mp4Parser
        parser = DASH_mp4Parser(url_playlist)
    elif ".m3u8" in url_playlist:
        from parsers.HLS_mpegtsParser import HLS_mpegtsParser
        parser = HLS_mpegtsParser(url_playlist)
    else:
        print 'Error. Unknown Parser'
        sys.exit()

    p = 40
    if float(options['max_buffer_time']) >= 0:
        p = float(options['max_buffer_time'])

    #StartPlayer
    from TapasPlayer import TapasPlayer
    player = TapasPlayer(controller=controller,
                         parser=parser,
                         media_engine=media_engine,
                         log_sub_dir=log_sub_dir,
                         log_period=1,
                         max_buffer_time=p,
                         inactive_cycle=1,
                         initial_level=0,
                         use_persistent_connection=persistent_conn,
                         check_warning_buffering=check_warning_buffering,
                         stress_test=options['stress_test'])

    if options['bw_var'] is not None:
        player.setBandwidthVariation(options['bw_var'])

    #print 'Ready to play'
    player.play()

    from twisted.internet import task

    def check_stop_flag():
        if player.isTerminated():
            reactor.stop()

    lc = task.LoopingCall(check_stop_flag)
    lc.start(3)

    try:
        reactor.run()
    except Exception as e:
        print str(e)
        player.terminated = True
def select_player():
    log.startLogging(sys.stdout)

    persistent_conn = True
    check_warning_buffering = True

    #MediaEngine
    if options['media_engine'] == 'gst':
        #gst_init()
        from media_engines.GstMediaEngine import GstMediaEngine
        media_engine = GstMediaEngine(decode_video=True)
    elif options['media_engine'] == 'nodec':
        #gst_init()
        from media_engines.GstMediaEngine import GstMediaEngine
        media_engine = GstMediaEngine(decode_video=False)
    elif options['media_engine'] == 'fake':
        from media_engines.FakeMediaEngine import FakeMediaEngine
        media_engine = FakeMediaEngine()
    else:
        print 'Error. Unknown Media Engine'
        sys.exit()

    from twisted.internet import reactor

    #Controller
    if options['controller'] == 'conventional':
        from controllers.ConventionalController import ConventionalController
        controller = ConventionalController()
    elif options['controller'] == 'tobasco':
        from controllers.TOBASCOController import TOBASCOController
        controller = TOBASCOController()
    elif options['controller'] == 'max':
        check_warning_buffering = False
        from controllers.MaxQualityController import MaxQualityController
        controller = MaxQualityController()
    elif options['controller'] == 'BBA0':
        from controllers.BBA0Controller import BBA0Controller
        controller = BBA0Controller()
    elif options['controller'] == 'BBA2':
        from controllers.BBA2Controller import BBA2Controller
        controller = BBA2Controller()
    else:
        print 'Error. Unknown Control Algorithm'
        sys.exit()

    if not options['log_sub_dir']:
        log_sub_dir = options['controller']
    else:
        log_sub_dir = options['log_sub_dir']

    #Parser
    url_playlist = options['url']
    if ".mpd" in url_playlist:
        from parsers.DASH_mp4Parser import DASH_mp4Parser
        parser = DASH_mp4Parser(url_playlist)
    elif ".m3u8" in url_playlist:
        from parsers.HLS_mpegtsParser import HLS_mpegtsParser
        parser = HLS_mpegtsParser(url_playlist)
    else:
        print 'Error. Unknown Parser'
        sys.exit()

    #StartPlayer
    from TapasPlayer import TapasPlayer
    player = TapasPlayer(controller=controller,
                         parser=parser,
                         media_engine=media_engine,
                         log_sub_dir=log_sub_dir,
                         log_period=0.1,
                         max_buffer_time=80,
                         inactive_cycle=1,
                         initial_level=0,
                         use_persistent_connection=persistent_conn,
                         check_warning_buffering=check_warning_buffering,
                         stress_test=options['stress_test'])
    #print 'Ready to play'
    player.play()

    try:
        reactor.run()
    except Exception, e:
        pass