/// <summary>
        /// Initializes a new instance of the <see cref="GATAudioThreadStreamToCache"/> class.
        /// </summary>
        /// <param name="stream">The observed multichannel or mono stream.</param>
        /// <param name="caches">The caches to record to, one per channel must be provided.</param>
        /// <param name="handler">Optional callback fired when the cache is full.</param>
        public GATAudioThreadStreamToCache( IGATAudioThreadStream stream, GATData[] caches, AtEndHandler handler = null )
        {
            _numFramesPerRead = stream.BufferSizePerChannel;

            Caches = caches;

            _stream = stream;

            _onEnd = handler;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GATAudioThreadStreamToCache"/> class.
        /// </summary>
        /// <param name="stream">The observed multichannel or mono stream.</param>
        /// <param name="caches">The caches to record to, one per channel must be provided.</param>
        /// <param name="handler">Optional callback fired when the cache is full.</param>
        public GATAudioThreadStreamToCache(IGATAudioThreadStream stream, GATData[] caches, AtEndHandler handler = null)
        {
            _numFramesPerRead = stream.BufferSizePerChannel;

            Caches = caches;

            _stream = stream;

            _onEnd = handler;
        }
Beispiel #3
0
        /// <summary>
        /// Start caching the stream.
        /// </summary>
        /// <param name="targetDspTime">The dsp time at which caching should start. Pass 0 to start as soon as possible.</param>
        /// <param name="handler">Optional callback fired when the cache is full.</param>
        public void Start(double targetDspTime = 0d, AtEndHandler handler = null)
        {
            if (_vDoCache || _waiting)
            {
                return;
            }

            _waiting       = true;
            _vPosition     = 0;
            _onEnd         = handler;
            _targetDspTime = targetDspTime;
            _stream.AddAudioThreadStreamClient(this);
        }
    // Virtual solely so that we can subclass for testing, because mocks don't work with delegates.
    public virtual void Download(string pid, AtStartHandler atStart, ProgressHandler progress, AtEndHandler atEnd) {
      var page = GetIphonePage(pid);

      if (!page.IsAvailable) {
        atEnd(DownloadStatus.Unavailable, pid);
        return;
      }

      var finalPath = FilenameSafe(GetTitle(pid)) + page.FileExtension;
      var tempPath  = finalPath + ".partial";

      if (File.Exists(finalPath)){
        atEnd(DownloadStatus.AlreadyExists, finalPath);
        return;
      }

      atStart(finalPath);

      var request       = new CoreMediaRequest(page.EmbeddedMediaUrl, cookies);
      var contentLength = request.ContentLength;
      int totalReceived = 0;

      using (var localStream = new FileStream(tempPath, FileMode.Append, FileAccess.Write, FileShare.Read)) {
        totalReceived = (int)localStream.Position;
        request.GetResponseStreamFromOffset(totalReceived, remoteStream => {
          ReadFromStream(remoteStream, (buffer, bytesRead) => {
            localStream.Write(buffer, 0, bytesRead);
            totalReceived += bytesRead;
            progress(totalReceived, contentLength);
          });
        });
      }

      if (totalReceived >= contentLength) {
        File.Move(tempPath, finalPath);
        atEnd(DownloadStatus.Complete, finalPath);
      } else {
        atEnd(DownloadStatus.Incomplete, tempPath);
      }
    }
        /// <summary>
        /// Start caching the stream.
        /// </summary>
        /// <param name="targetDspTime">The dsp time at which caching should start. Pass 0 to start as soon as possible.</param>
        /// <param name="handler">Optional callback fired when the cache is full.</param>
        public void Start( double targetDspTime = 0d, AtEndHandler handler = null )
        {
            if( _vDoCache || _waiting )
                return;

            _waiting = true;
            _vPosition = 0;
            _onEnd = handler;
            _targetDspTime = targetDspTime;
            _stream.AddAudioThreadStreamClient( this );
        }