Пример #1
0
        /// <summary>
        /// Asynchronous public API for getting next stream to play.
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IAsyncResult BeginGetNextStream(AsyncCallback callback, Object state)
        {
            if (_program == null)
                throw new InvalidOperationException("program not set");

            if ( IsWebRequestPending() )
                throw new InvalidOperationException("operation is already in progress");

            _asyncResult = new HLSCallbackImpl(callback);

            if (_playlist == null)
            {
                _playlist = SelectNextVariant();
                _playlist.Playback = this;
                _currentPosition = 0;
                _currentMediaSequenceNumber = 0;
                _discontinuity = true;

                if (IsEndList || _playlist.PlaylistDuration > _liveDvrMinDuration)
                    _duration = _playlist.PlaylistDuration;

                if (_downloadBitrateChanged != null)
                    _downloadBitrateChanged(this, _playlist.Bitrate);
            }
            else
            {
                _currentPosition++;
                _currentMediaSequenceNumber++;

                HLSPlaylistImpl newPlaylist = SelectNextVariant();

                if (newPlaylist != _playlist)
                {
                    _discontinuity = true;

                    if (_downloadBitrateChanged != null &&
                        newPlaylist.Bitrate != _playlist.Bitrate)
                        _downloadBitrateChanged(this, newPlaylist.Bitrate);

                    _playlist.Playback = null;
                    _playlist = newPlaylist;
                    _playlist.Playback = this;

                }
                else
                {
                    _discontinuity = false;
                }
            }

            if (!_playlist.IsLoaded)
            {
                _asyncResult.Purpose = HLSCallbackPurpose.WaitForPlaylist;
                _playlist.Load();
                return _asyncResult;
            }
            bool a = _playlist.IsDueForReload;
            if (!IsEndList && ((_currentPosition >= _playlist.Streams.Count) || a))
            {
                _asyncResult.Purpose = HLSCallbackPurpose.WaitForPlaylist;
                _playlist.Reload();
                return _asyncResult;
            }

            if (!BeginLoadingNextStream())
            {
                _asyncResult.Dispose();
                _asyncResult = null;
            }

            return _asyncResult;
        }
Пример #2
0
 public void EndPendingWebRequest()
 {
     if (null != _asyncResult)
     {
         _asyncResult.Dispose();
         _asyncResult = null;
     }
 }
Пример #3
0
        /// <summary>
        /// If a stream download is in progress using HttpWebRequest, then this method will flag 
        /// that request to discard its download stream. After this call, no more data is 
        /// pushed into TSDemux or audio/video buffers. Also no new stream download is started 
        /// after this method is called and until ResumeDownloads is called.
        /// </summary>
        public void AbortStreamDownloads()
        {
            lock (_requestLock)
            {
                _downloadAbortInProgress = true;

                if (_currentWebRequestState != null)
                {
                    _currentWebRequestState.DiscardData = true;
                    _currentWebRequestState.WebRequest.Abort();
                    _currentWebRequestState = null;
                }

                if (null != _asyncResult)
                {
                    _asyncResult.Abort();
                    _asyncResult = null;
                }
            }
        }