Example #1
0
    def gui_vod_event_callback(self, d, event, params):
        if DEBUG:
            print >> sys.stderr, "bg: gui_vod_event_callback: Event: ", event
            print >> sys.stderr, "bg: gui_vod_event_callback: Params: ", params
        if event == VODEVENT_START:
            if params['filename']:
                stream = open(params['filename'], "rb")
            else:
                stream = params['stream']

            # Ric: small hack for the ogg mimetype (just for windows,
            # linux thinks it's an audio/ogg file)
            if params['mimetype'] == 'video/x-ogg':
                params['mimetype'] = 'application/ogg'

            # Arno: My Win7 thinks this is 'video/mpeg', so patch for that.
            selectedfiles = d.get_selected_files()
            if selectedfiles is not None and len(selectedfiles) > 0:
                for fn in selectedfiles:
                    if is_ogg(fn):
                        params['mimetype'] = 'application/ogg'
            else:
                name = d.get_def().get_name_as_unicode()
                if is_ogg(name):
                    params['mimetype'] = 'application/ogg'

                    if d.get_def().get_live():
                        # Live Ogg stream. To support this we need to do
                        # two things:
                        # 1. Write Ogg headers (stored in .tstream)
                        # 2. Find first Ogg page in stream.
                        stream = OggMagicLiveStream(d.get_def(), stream)

            if not d.get_def().get_live() and not params['filename']:
                # Arno, < 2010-08-10: Firefox reads aggressively, we just
                # give it data at bitrate pace such that we know when we
                # have to fallback to HTTP servers.
                #
                # 2010-08-10: not when file complete on disk ;-)
                stream = AtBitrateStream(stream, params['bitrate'])

            blocksize = d.get_def().get_piece_length()
            #Ric: add svc on streaminfo, added bitrate
            streaminfo = {
                'mimetype': params['mimetype'],
                'stream': stream,
                'length': params['length'],
                'blocksize': blocksize,
                'svc': d.get_mode() == DLMODE_SVC,
                'bitrate': params['bitrate']
            }

            duser = self.dusers[d]
            duser['streaminfo'] = streaminfo
            if duser['uic'] is not None:
                # Only if playback wasn't canceled since starting
                duser['uic'].set_streaminfo(duser['streaminfo'])
                duser['uic'].start_playback(d.get_def().get_infohash())

                self.approxplayerstate = MEDIASTATE_PLAYING
            else:
                self.approxplayerstate = MEDIASTATE_STOPPED

        elif event == VODEVENT_PAUSE:
            duser = self.dusers[d]
            if duser['uic'] is not None:
                duser['uic'].pause()
            self.approxplayerstate = MEDIASTATE_PAUSED

        elif event == VODEVENT_RESUME:
            duser = self.dusers[d]
            if duser['uic'] is not None:
                duser['uic'].resume()
            self.approxplayerstate = MEDIASTATE_PLAYING
Example #2
0
    def gui_vod_event_callback(self, d, event, params):
        """ Also called by SwarmPlayer """

        print >> sys.stderr, "videoplay: gui_vod_event:", event
        if event == VODEVENT_START:
            filename = params["filename"]
            mimetype = params["mimetype"]
            stream = params["stream"]
            length = params["length"]

            if filename:
                self.play_file(filename)
            else:
                if d.get_def().get_live():
                    cachestream = stream
                    blocksize = d.get_def().get_piece_length()
                else:
                    if d.get_def().get_def_type() == "swift":
                        piecelen = 2 ** 16
                    else:
                        piecelen = d.get_def().get_piece_length()

                    if False and piecelen > 2 ** 17:
                        # Arno, 2010-01-21:
                        # Workaround for streams with really large piece
                        # sizes. For some content/containers, VLC can do
                        # GET X-, GET X+10K-, GET X+20K HTTP requests
                        # and we would answer these by putting megabytes
                        # into the stream buffer, of which only 10K would be
                        # used. This kills performance. Hence I add a caching
                        # stream that tries to resolve answers from its internal
                        # buffer, before reading the engine's stream.
                        # This works, but only if the HTTP server doesn't
                        # read too aggressively, i.e., uses small blocksize.
                        #
                        cachestream = SmartCachingStream(stream)

                        blocksize = max(32768, piecelen / 8)
                    else:
                        cachestream = stream
                        blocksize = piecelen

                if d.get_def().get_live() and is_ogg(d.get_def().get_name_as_unicode()):
                    # Live Ogg stream. To support this we need to do
                    # two things:
                    # 1. Write Ogg headers (stored in .tstream)
                    # 2. Find first Ogg page in stream.
                    cachestream = OggMagicLiveStream(d.get_def(), stream)

                # Estimate duration. Video player (e.g. VLC) often can't tell
                # when streaming.
                estduration = None
                if d.get_def().get_def_type() == "torrent":
                    if d.get_def().get_live():
                        # Set correct Ogg MIME type
                        if is_ogg(d.get_def().get_name_as_unicode()):
                            mimetype = 'application/ogg'
                    else:
                        file = None
                        if d.get_def().is_multifile_torrent():
                            file = d.get_selected_files()[0]
                        bitrate = d.get_def().get_bitrate(file)
                        if bitrate is not None:
                            estduration = float(length) / float(bitrate)

                        # Set correct Ogg MIME type
                        if file is None:
                            if is_ogg(d.get_def().get_name_as_unicode()):
                                mimetype = 'application/ogg'
                        else:
                            if is_ogg(file):
                                mimetype = 'application/ogg'


                streaminfo = {'mimetype': mimetype, 'stream': cachestream, 'length':length, 'blocksize':blocksize, 'estduration':estduration}

                if d.get_def().get_def_type() == "swift":
                    streaminfo['url'] = params['url']

                self.play_stream(streaminfo)

        elif event == VODEVENT_PAUSE:
            if self.videoframe is not None:
                self.videoframe.get_videopanel().Pause(gui_vod_event=True)
        elif event == VODEVENT_RESUME:
            if self.videoframe is not None:
                self.videoframe.get_videopanel().Resume()
Example #3
0
            print_exc()
            authcfg = RSALiveSourceAuthConfig()
            authcfg.save(authfilename)
    else:
        try:
            authcfg = ECDSALiveSourceAuthConfig.load(authfilename)
        except:
            print_exc()
            authcfg = ECDSALiveSourceAuthConfig()
            authcfg.save(authfilename)

    print >>sys.stderr, "main: Source auth pubkey", repr(authcfg.get_pubkey())

    # Support for Ogg as transport stream
    ogg_header_pages = []
    if not config['url'] and is_ogg(config['source']):
        if config['source'].startswith('http:'):
            # HTTP source
            source = urllib2.urlopen(config['source'])
        else:
            # File source
            source = open(config['source'], "rb")
        while True:
            (isheader, header, body) = ogg_grab_page(source)
            if not isheader:
                break
            else:
                ogg_header_pages.append((header, body))
        source.close()

    tdef = TorrentDef()
Example #4
0
    def gui_vod_event_callback( self, d, event, params ):
        if DEBUG:
            print >>sys.stderr,"bg: gui_vod_event_callback: Event: ", event
            print >>sys.stderr,"bg: gui_vod_event_callback: Params: ", params
        if event == VODEVENT_START:
            if params['filename']:
                stream = open( params['filename'], "rb" )
            else:
                stream = params['stream']
    
            # Ric: small hack for the ogg mimetype (just for windows, 
            # linux thinks it's an audio/ogg file)
            if params['mimetype'] == 'video/x-ogg':
                params['mimetype'] = 'application/ogg'
                
            # Arno: My Win7 thinks this is 'video/mpeg', so patch for that.  
            selectedfiles = d.get_selected_files()
            if selectedfiles is not None and len(selectedfiles) > 0:
                for fn in selectedfiles:
                    if is_ogg(fn):
                        params['mimetype'] = 'application/ogg'
            else:
                name = d.get_def().get_name_as_unicode()
                if is_ogg(name):
                    params['mimetype'] = 'application/ogg'
                    
                    if d.get_def().get_live():
                        # Live Ogg stream. To support this we need to do
                        # two things:
                        # 1. Write Ogg headers (stored in .tstream)
                        # 2. Find first Ogg page in stream.
                        stream = OggMagicLiveStream(d.get_def(),stream)

            if not d.get_def().get_live() and not params['filename']:
                # Arno, < 2010-08-10: Firefox reads aggressively, we just
                # give it data at bitrate pace such that we know when we
                # have to fallback to HTTP servers.
                #
                # 2010-08-10: not when file complete on disk ;-)
                stream = AtBitrateStream( stream, params['bitrate'] )

            
            blocksize = d.get_def().get_piece_length()
            #Ric: add svc on streaminfo, added bitrate
            streaminfo = { 'mimetype': params['mimetype'], 'stream': stream, 'length': params['length'], 'blocksize':blocksize, 'svc': d.get_mode() == DLMODE_SVC, 'bitrate': params['bitrate'] }

            duser = self.dusers[d]
            duser['streaminfo'] = streaminfo
            if duser['uic'] is not None:
                # Only if playback wasn't canceled since starting
                duser['uic'].set_streaminfo(duser['streaminfo'])
                duser['uic'].start_playback(d.get_def().get_infohash())
            
                self.approxplayerstate = MEDIASTATE_PLAYING
            else:
                self.approxplayerstate = MEDIASTATE_STOPPED
            
        elif event == VODEVENT_PAUSE:
            duser = self.dusers[d]
            if duser['uic'] is not None:
                duser['uic'].pause()
            self.approxplayerstate = MEDIASTATE_PAUSED
            
        elif event == VODEVENT_RESUME:
            duser = self.dusers[d]
            if duser['uic'] is not None:
                duser['uic'].resume()
            self.approxplayerstate = MEDIASTATE_PLAYING
Example #5
0
            print_exc()
            authcfg = RSALiveSourceAuthConfig()
            authcfg.save(authfilename)
    else:
        try:
            authcfg = ECDSALiveSourceAuthConfig.load(authfilename)
        except:
            print_exc()
            authcfg = ECDSALiveSourceAuthConfig()
            authcfg.save(authfilename)

    print >> sys.stderr, "main: Source auth pubkey", repr(authcfg.get_pubkey())

    # Support for Ogg as transport stream
    ogg_header_pages = []
    if not config['url'] and is_ogg(config['source']):
        if config['source'].startswith('http:'):
            # HTTP source
            source = urllib2.urlopen(config['source'])
        else:
            # File source
            source = open(config['source'], "rb")
        while True:
            (isheader, header, body) = ogg_grab_page(source)
            if not isheader:
                break
            else:
                ogg_header_pages.append((header, body))
        source.close()

    tdef = TorrentDef()