Changeset 810


Ignore:
Timestamp:
01/27/10 17:36:32 (3 years ago)
Author:
pablo
Message:
  • Bitrate switching for HTTP Streams
Location:
trunk/fl5
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/fl5/src/com/longtailvideo/jwplayer/media/HTTPMediaProvider.as

    r806 r810  
    2525                protected var _transformer:SoundTransform; 
    2626                /** ID for the _position interval. **/ 
    27                 protected var _positionInterval:Number; 
     27                protected var _positionInterval:uint; 
    2828                /** Save whether metadata has already been sent. **/ 
    2929                protected var _meta:Boolean; 
     
    3636                /** Boolean for mp4 / flv streaming. **/ 
    3737                protected var _mp4:Boolean; 
    38                 /** Load offset for bandwidth checking. **/ 
    39                 protected var _loadtimer:Number; 
    4038                /** Variable that takes reloading into account. **/ 
    4139                protected var _iterator:Number; 
     
    4644                /** Whether the enitre video has been buffered **/ 
    4745                private var _bufferingComplete:Boolean; 
     46                /** Whether we have checked the bandwidth. **/ 
     47                private var _bandwidthSwitch:Boolean = true; 
     48                /** Whether we have checked bandwidth **/ 
     49                private var _bandwidthChecked:Boolean; 
     50                /** Bandwidth check delay **/ 
     51                private var _bandwidthTimeout:Number = 2000; 
    4852                 
    4953                /** Constructor; sets up the connection and display. **/ 
     
    152156                        _bufferFull = false; 
    153157                        _bufferingComplete = false; 
     158                        _bandwidthChecked = false; 
     159                        _bandwidthSwitch = true; 
     160                         
     161                        if (item.levels.length > 0) { item.setLevel(item.getLevel(config.bandwidth, config.width)); } 
     162                         
    154163                        if (_stream.bytesLoaded + _byteoffset < _stream.bytesTotal) { 
    155164                                _stream.close(); 
     
    157166                        media = _video; 
    158167                        _stream.play(getURL()); 
    159  
    160                         if (!_positionInterval) { 
    161                                 _positionInterval = setInterval(positionInterval, 100); 
    162                         } 
    163                         if (!_loadtimer) { 
    164                                 _loadtimer = setTimeout(loadTimeout, 3000); 
    165                         } 
     168                         
     169                        clearInterval(_positionInterval); 
     170                        _positionInterval = setInterval(positionInterval, 100); 
     171                         
    166172                        setState(PlayerState.BUFFERING); 
    167173                        sendBufferEvent(0, 0); 
     
    171177 
    172178 
    173                 /** timeout for checking the bitrate. **/ 
    174                 protected function loadTimeout():void { 
    175                         var obj:Object = new Object(); 
    176                         obj.bandwidth = Math.round(_stream.bytesLoaded / 1024 / 3 * 8); 
    177                         if (item.duration) { 
    178                                 obj.bitrate = Math.round(_stream.bytesTotal / 1024 * 8 / item.duration); 
    179                         } 
    180                         sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_META, {metadata: obj}); 
    181                 } 
    182  
     179                /** Bandwidth is checked as long the stream hasn't completed loading. **/ 
     180                private function checkBandwidth(lastLoaded:Number):void { 
     181                        var currentLoaded:Number = _stream.bytesLoaded; 
     182                        var bandwidth:Number = Math.ceil((currentLoaded - lastLoaded) / 1024) * 8 / (_bandwidthTimeout / 1000); 
     183 
     184                        if (currentLoaded < _stream.bytesTotal) { 
     185                                if (bandwidth > 0) { 
     186                                        config.bandwidth = bandwidth; 
     187                                        var obj:Object = {bandwidth:bandwidth}; 
     188                                        if (item.duration > 0) { 
     189                                                obj.bitrate = Math.ceil(_stream.bytesTotal / 1024 * 8 / item.duration); 
     190                                        } 
     191                                        sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_META, {metadata: obj}); 
     192                                } 
     193                                if (_bandwidthSwitch) { 
     194                                        _bandwidthSwitch = false; 
     195                                        if (item.currentLevel != item.getLevel(config.bandwidth, config.width)) { 
     196                                                load(item); 
     197                                                return; 
     198                                        } 
     199                                } 
     200                                setTimeout(checkBandwidth, _bandwidthTimeout, currentLoaded); 
     201                        } 
     202                } 
    183203 
    184204                /** Get metadata information from netstream class. **/ 
     
    246266                                bufferFill = _stream.bufferLength/_stream.bufferTime * 100; 
    247267                        } 
    248  
     268         
     269                        if (!_bandwidthChecked && _stream.bytesLoaded > 0 && _stream.bytesLoaded < _stream.bytesTotal) { 
     270                                _bandwidthChecked = true; 
     271                                setTimeout(checkBandwidth, _bandwidthTimeout, _stream.bytesLoaded); 
     272                        } 
     273                         
    249274                        if (bufferFill < 25 && state == PlayerState.PLAYING) { 
    250275                                _bufferFull = false; 
     
    344369                        super.setVolume(vol); 
    345370                } 
     371 
     372                /** Handle a resize event **/ 
     373                override public function resize(width:Number, height:Number):void { 
     374                        super.resize(width, height); 
     375                        if (item.levels.length > 0 && item.getLevel(config.bandwidth, config.width) != item.currentLevel) { 
     376                                _byteoffset = getOffset(position); 
     377                                _timeoffset = _position = getOffset(position,true); 
     378                                load(item); 
     379                        } 
     380                } 
    346381        } 
    347382} 
  • trunk/fl5/src/com/longtailvideo/jwplayer/media/MediaProvider.as

    r806 r810  
    320320                        if (m) { 
    321321                                _media = new MovieClip(); 
    322                                 //_media.visible = false; 
     322                                _media.visible = false; 
    323323                                _media.addChild(m); 
    324324                                if (_width * _height > 0) { 
  • trunk/fl5/src/com/longtailvideo/jwplayer/media/RTMPMediaProvider.as

    r807 r810  
    3131     **/ 
    3232    public class RTMPMediaProvider extends MediaProvider { 
    33         /** Save if the bandwidth checkin already occurs. **/ 
    34         private var _bandwidthChecked:Boolean; 
     33                /** Save if the bandwidth checkin already occurs. **/ 
     34                private var _bandwidthChecked:Boolean; 
    3535        /** Interval for bw checking - with dynamic streaming. **/ 
    3636        private var _bandwidthInterval:Number; 
     37                /** Whether to connect to a stream when bandwidth is detected. **/ 
     38                private var _bandwidthSwitch:Boolean; 
    3739        /** NetConnection object for setup of the video stream. **/ 
    3840        private var _connection:NetConnection; 
     
    147149            _position = 0; 
    148150                        _bufferFull = false; 
     151                        _bandwidthSwitch = false;                        
    149152            _timeoffset = item.start; 
    150153                        if (item.levels.length > 0) { item.setLevel(item.getLevel(config.bandwidth, config.width)); } 
     
    237240                config.bandwidth = dat.bandwidth; 
    238241                Configger.saveCookie('bandwidth', dat.bandwidth); 
    239                 setStream(); 
     242                                if (_bandwidthSwitch) { 
     243                                        _bandwidthSwitch = false; 
     244                        setStream(); 
     245                                } 
    240246            } 
    241247            if (dat.code == 'NetStream.Play.TransitionComplete') { 
     
    395401                            } else { 
    396402                                                                _bandwidthChecked = true; 
     403                                                                _bandwidthSwitch = true; 
    397404                                _connection.call('checkBandwidth', null); 
    398405                            } 
  • trunk/fl5/src/com/longtailvideo/jwplayer/media/VideoMediaProvider.as

    r806 r810  
    176176                private function checkBandwidth(lastLoaded:Number):void { 
    177177                        var currentLoaded:Number = _stream.bytesLoaded; 
    178                         var bandwidth:Number = ((currentLoaded - lastLoaded) / 1024) * 8 / (_bandwidthTimeout / 1000); 
     178                        var bandwidth:Number = Math.ceil((currentLoaded - lastLoaded) / 1024) * 8 / (_bandwidthTimeout / 1000); 
    179179                        if (currentLoaded < _stream.bytesTotal) { 
    180180                                if (bandwidth > 0) { 
     
    182182                                        var obj:Object = {bandwidth:bandwidth}; 
    183183                                        if (item.duration > 0) { 
    184                                                 obj.bitrate = Math.round(_stream.bytesTotal / 1024 * 8 / item.duration); 
     184                                                obj.bitrate = Math.ceil(_stream.bytesTotal / 1024 * 8 / item.duration); 
    185185                                        } 
    186186                                        sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_META, {metadata: obj}); 
  • trunk/fl5/src/com/longtailvideo/jwplayer/player/PlayerVersion.as

    r809 r810  
    33         
    44        public class PlayerVersion { 
    5                 protected static var _version:String = "5.1.809"; 
     5                protected static var _version:String = "5.1.810"; 
    66                 
    77                public static function get version():String { 
Note: See TracChangeset for help on using the changeset viewer.