Exemplo n.º 1
0
 private Task <DownloadResponse> CreateDownloadTask(Segment segment, bool ignoreError, uint?segmentId,
                                                    CancellationToken cancelToken)
 {
     return(Task.Run(async() =>
     {
         var timeout = CalculateDownloadTimeout(segment);
         Logger.Info($"Calculated download timeout is {timeout.TotalMilliseconds}");
         var requestData = new DownloadRequest
         {
             DownloadSegment = segment,
             IgnoreError = ignoreError,
             SegmentId = segmentId,
             StreamType = streamType
         };
         var timeoutCancellationTokenSource = new CancellationTokenSource();
         if (timeout != TimeSpan.MaxValue)
         {
             timeoutCancellationTokenSource.CancelAfter(timeout);
         }
         using (timeoutCancellationTokenSource)
             using (var downloadCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(
                        cancelToken, timeoutCancellationTokenSource.Token))
             {
                 return await DashDownloader.DownloadDataAsync(requestData, downloadCancellationTokenSource.Token,
                                                               throughputHistory);
             }
     }));
 }
Exemplo n.º 2
0
        public static Task <DownloadResponse> DownloadDataAsync(DownloadRequest downloadRequest,
                                                                CancellationToken cancellationToken, IThroughputHistory throughputHistory)
        {
            var dashDownloader = new DashDownloader(downloadRequest, cancellationToken, throughputHistory);

            return(dashDownloader.DownloadInternalAsync());
        }
Exemplo n.º 3
0
        private DashDownloader(DownloadRequest downloadRequest, CancellationToken cancellationToken,
                               IThroughputHistory throughputHistory)
        {
            request = downloadRequest;

            if (!string.IsNullOrEmpty(request.DownloadSegment.ByteRange))
            {
                downloadRange = new ByteRange(request.DownloadSegment.ByteRange);
            }

            this.cancellationToken = cancellationToken;
            this.throughputHistory = throughputHistory;
        }
Exemplo n.º 4
0
 public DashDownloaderException(DownloadRequest request, string message, Exception inner) : base(message, inner)
 {
     DownloadRequest = request;
 }
Exemplo n.º 5
0
 public DashDownloaderException(DownloadRequest request, string message, Exception inner,
                                HttpStatusCode statusCode) : base(message, inner)
 {
     DownloadRequest = request;
     StatusCode      = statusCode;
 }