Changeset 1240


Ignore:
Timestamp:
08/26/10 11:42:54 (3 years ago)
Author:
jeroen
Message:

added dvrcast support to RTMP

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • testing/settings.js

    r1236 r1240  
    147147                }, 
    148148                'RTMP live stream (not always on)': { 
    149                         file:'isight', 
     149                        file:'tuxcast', 
    150150                        streamer:'rtmp://fml.12E5.edgecastcdn.net/2012E5/', 
    151151                        'rtmp.subscribe':true, 
     
    154154                }, 
    155155                'RTMP live dvr stream (not always on)': { 
    156                         file:'isight', 
     156                        file:'tuxcast', 
    157157                        'rtmp.dvr':true, 
    158                         'rtmp.subscribe':true, 
    159158                        streamer:'rtmp://fml.12E5.edgecastcdn.net/3012E5/', 
    160159                        height:240, 
  • trunk/fl5/src/com/longtailvideo/jwplayer/media/RTMPMediaProvider.as

    r1236 r1240  
    6767                /** Whether or not the buffer is full **/ 
    6868                private var _bufferFull:Boolean = false; 
    69                 /** Duration of the DVR stream (grows with a timer). **/ 
    70                 private var _dvrDuration:Number = 0; 
    71                 /** Total duration of the DVR stream (set by configuration). **/ 
    72                 private var _dvrTotalDuration:Number = 0; 
    73                 /** If the item's duration should be set back to 0 on load. **/ 
    74                 private var _dvrResetDuration:Boolean = false; 
    75                 /** How long to wait between updates to DVR duration **/ 
    76                 private var _dvrCheckDelay:Number = 1000; 
    77                 /** Interval ID for growing the DVR duration. **/ 
    78                 private var _dvrInterval:Number; 
     69                /** Duration of the DVR stream at the time the client connects. **/ 
     70                private var _dvrStartDuration:Number = 0; 
     71                /** Is the DVR stream currently recording? **/ 
     72                private var _dvrStartDate:Number = 0; 
    7973                /** Whether we should pause the stream when we first connect to it **/ 
    8074                private var     _lockOnStream:Boolean = false; 
     
    134128                /** Try pulling info from a DVRCast application. **/ 
    135129                private function doDVRInfo(id:String):void { 
    136                                 _connections[_connection].call("DVRGetStreamInfo", new Responder(doDVRInfoCallback), id); 
    137                                 Logger.log("calling DVRGetStreamInfo for "+id); 
     130                        _connections[_connection].call("DVRGetStreamInfo", new Responder(doDVRInfoCallback), id); 
    138131                }; 
    139132 
     
    142135                private function doDVRInfoCallback(info:Object):void { 
    143136                        if(info.code == "NetStream.DVRStreamInfo.Success") { 
    144                                 setStream(); 
    145                                 Logger.log(info.data.currLen,"DVRCast"); 
     137                                if(info.data.currLen < 60) { 
     138                                        setTimeout(doDVRInfo,5000,getID(item.file)) 
     139                                } else {  
     140                                        _dvrStartDuration = info.data.currLen - 10; 
     141                                        if(info.data.isRec) { 
     142                                                _dvrStartDate = new Date().valueOf(); 
     143                                                if(_dvrStartDuration > 60) { 
     144                                                        _timeoffset = _dvrStartDuration - 60; 
     145                                                } 
     146                                        } 
     147                                        setStream(); 
     148                                } 
    146149                        } else if (info.code == "NetStream.DVRStreamInfo.Retry") { 
    147150                                setTimeout(doDVRInfo,2000,getID(item.file)); 
    148151                        } 
     152                        for (var itm:String in info.data) {  
     153                                info[itm] = info.data[itm]; 
     154                        } 
     155                        delete info.data; 
    149156                        sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_META, {metadata: info}); 
    150157                }; 
     
    156163        } 
    157164 
    158  
    159                 /** If there's a DVR stream, calcluate the position by incrementing it via a setInterval(). **/ 
    160                 private function dvrPosition():void { 
    161                         _dvrDuration += Math.ceil(_dvrCheckDelay / 1000); 
    162                         if(_dvrTotalDuration > 0) { 
    163                                 var bufferPct:Number = Math.min(100, Math.ceil(100 * _dvrDuration / _dvrTotalDuration)); 
    164                                 sendBufferEvent(bufferPct);                      
    165                         } else { 
    166                                 if (item.duration == 0) { _dvrResetDuration = true; } 
    167                                 item.duration = _dvrDuration; 
    168                         } 
    169                 } 
    170165 
    171166        /** Catch security errors. **/ 
     
    221216            _position = 0; 
    222217                        _bufferFull = false; 
    223                         _bandwidthSwitch = false;                        
    224                         _lockOnStream = false;                   
     218                        _bandwidthSwitch = false; 
     219                        _lockOnStream = false; 
    225220            _timeoffset = item.start; 
    226221                        if (item.levels.length > 0) { item.setLevel(item.getLevel(config.bandwidth, config.width)); } 
    227                          
    228                         if (_dvrResetDuration) { item.duration = 0; } 
    229                         _dvrTotalDuration = item.duration; 
    230                         _dvrDuration = 0; 
    231                         clearInterval(_dvrInterval); 
    232                         _dvrInterval = 0; 
    233222                         
    234223                        clearInterval(_positionInterval); 
     
    329318                                if (_transitionLevel >= 0) { _transitionLevel = -1; } 
    330319                        } else { 
    331                 if (dat.duration) { 
    332                                         if (isDVR) { 
    333                                                 // Save the DVR duration differently, adding a small buffer. 
    334                                                 _dvrDuration = dat.duration + 3; 
    335                                         } else if (duration <= 0) { 
    336                                 item.duration = dat.duration; 
    337                                         } 
    338                 } 
     320                                if (dat.duration) { 
     321                                        item.duration = dat.duration; 
     322                                } 
    339323                        } 
    340324            if (dat.type == 'complete') { 
     
    356340        } 
    357341 
     342 
    358343        /** Pause playback. **/ 
    359344        override public function pause():void { 
     
    362347                                return; 
    363348                        } 
    364                          
    365                         clearInterval(_positionInterval); 
     349                        //clearInterval(_positionInterval); 
    366350                        super.pause(); 
    367351            if (_stream) { 
     
    371355                        } 
    372356        } 
     357 
    373358 
    374359        /** Resume playing. **/ 
     
    401386            } 
    402387                         
    403             if (state != PlayerState.PLAYING) { 
     388            if (!getConfigProperty('dvr') && state != PlayerState.PLAYING) { 
    404389                return; 
    405390            } 
    406                          
    407391            if (pos < duration) { 
    408392                                _position = pos; 
    409393                                sendMediaEvent(MediaEvent.JWPLAYER_MEDIA_TIME, {position: position, duration: duration}); 
    410             } else if (position > 0 && duration > 0 && (!isDVR || _dvrTotalDuration > 0)) { 
     394            } else if (position > 0 && duration > 0) { 
    411395                _stream.pause(); 
    412396                clearInterval(_positionInterval); 
     
    431415        /** Seek to a new position. **/ 
    432416        override public function seek(pos:Number):void { 
    433                         if (isDVR && pos > _dvrDuration) { pos = _dvrDuration; } 
    434417            _transitionLevel = -1; 
    435418                        _transitionPlanned = false; 
     419                        if(getConfigProperty('dvr') && _dvrStartDate && pos > duration - 60) {  
     420                                pos = duration - 60; 
     421                        } 
    436422                        _timeoffset = pos; 
    437423            clearInterval(_positionInterval); 
     
    449435                                play(); 
    450436                        } 
    451                          
    452                         if(isDVR) { 
    453                                 if(state != PlayerState.PLAYING) { 
    454                                         try { 
    455                                                 _stream.play(getID(item.file),0,-1); 
    456                                         } catch(e:Error) { 
    457                                                 error("Could not play DVR stream: " + e.message); 
    458                                         } 
    459                                 } 
    460                                 if(_timeoffset > 0) { 
    461                                         _stream.seek(_timeoffset); 
    462                                 } 
    463                                 if (!_dvrInterval) { _dvrInterval = setInterval(dvrPosition,1000); } 
    464             } else { 
    465                 if (_currentFile != item.file) { 
    466                     _currentFile = item.file; 
    467                                         try { 
    468                         _stream.play(getID(item.file)); 
    469                                         } catch(e:Error) { 
    470                                                 Logger.log("Error: " + e.message); 
    471                                         } 
    472                 } 
    473                 if (_timeoffset > 0 || state == PlayerState.IDLE) { 
    474                     if (_stream) { 
    475                                                 _stream.seek(_timeoffset); 
    476                                         } 
    477                 } 
    478                 if (_dynamic) { 
    479                     _bandwidthInterval = setInterval(getBandwidth, 1000); 
    480                 } 
    481             } 
    482             _isStreaming = true; 
    483             _positionInterval = setInterval(positionInterval, 100); 
    484         } 
     437 
     438                        if (_currentFile != item.file) { 
     439                                _currentFile = item.file; 
     440                                try { 
     441                                        if(_dvrStartDate) { 
     442                                                _stream.play(getID(item.file),10); 
     443                                        } else { 
     444                                                _stream.play(getID(item.file)); 
     445                                        } 
     446                                } catch(e:Error) { 
     447                                        Logger.log("Error: " + e.message); 
     448                                } 
     449                        } 
     450                        if ((_timeoffset > 0 || state == PlayerState.IDLE) && _stream) { 
     451                                _stream.seek(_timeoffset); 
     452                        } 
     453                        if (_dynamic) { 
     454                                _bandwidthInterval = setInterval(getBandwidth, 1000); 
     455                        } 
     456                        _isStreaming = true; 
     457                        _positionInterval = setInterval(positionInterval, 100); 
     458                } 
     459 
    485460 
    486461        /** Start the netstream object. **/ 
     
    527502                        checkDynamic(evt.info.data.version); 
    528503                                        } 
    529                                         if (getConfigProperty('subscribe')) { 
    530                                                 if(isDVR) { 
    531                                                         _connections[_connection].call("DVRSubscribe", null, getID(item.file)); 
    532                                                         setTimeout(doDVRInfo,2000,getID(item.file)); 
    533                                                 } else { 
    534                                                         _subscribeInterval = setInterval(doSubscribe, 2000, getID(item.file)); 
    535                                                 } 
    536                     } else { 
     504                                        if(getConfigProperty('dvr')) { 
     505                                                _connections[_connection].call("DVRSubscribe", null, getID(item.file)); 
     506                                                setTimeout(doDVRInfo,2000,getID(item.file)); 
     507                                        } else if (getConfigProperty('subscribe')) { 
     508                                                _subscribeInterval = setInterval(doSubscribe, 2000, getID(item.file)); 
     509                                        } else { 
    537510                        if (item.levels.length > 0) { 
    538511                            if (_dynamic || _bandwidthChecked) { 
     
    606579                                        break; 
    607580                                case 'NetStream.Play.Stop': 
    608                                         if(isDVR) { stop(); } 
     581                                        if(getConfigProperty('dvr')) { stop(); } 
    609582                                        break; 
    610583                                         
     
    628601            _position = 0; 
    629602            _timeoffset = item ? item.start : -1; 
     603                        _dvrStartDuration = _dvrStartDate = 0; 
    630604                        super.stop(); 
    631605                        if (item && item.hasOwnProperty('smil')) { 
     
    643617                } 
    644618 
    645         /** Get the streamlength returned from the connection. **/ 
    646         private function streamlengthHandler(len:Number):void { 
    647                         if (isDVR && _dvrTotalDuration > 0) { 
    648                                 _dvrDuration = len; 
    649                         } else if (!isDVR && len && duration <= 0) { 
    650                 item.duration = len; 
    651             } 
    652         } 
     619 
     620                /** Get the streamlength returned from the connection. **/ 
     621                private function streamlengthHandler(len:Number):void { 
     622                        item.duration = len; 
     623                } 
     624 
    653625 
    654626        /** Dynamically switch streams **/ 
     
    690662                        return (!(duration > 0) && _stream && _stream.bufferLength > 0); 
    691663                } 
    692                  
    693                 protected function get isDVR():Boolean { 
    694                         return Boolean(getConfigProperty('dvr')); 
    695                 } 
    696                  
     664 
     665 
    697666                protected function get duration():Number { 
    698                         if (isDVR) { 
    699                                 return _dvrTotalDuration > 0 ? _dvrTotalDuration : item.duration; 
    700                         } else { 
     667                        if(getConfigProperty('dvr')) { 
     668                                var dur:Number = _dvrStartDuration; 
     669                                if(_dvrStartDate) {  
     670                                        dur += (new Date().valueOf() - _dvrStartDate) / 1000; 
     671                                } 
     672                                return Math.round(dur); 
     673                        } else {  
    701674                                return item.duration; 
    702675                        } 
  • trunk/fl5/src/com/longtailvideo/jwplayer/player/PlayerVersion.as

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