Ejemplo 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);
             }
     }));
 }
Ejemplo n.º 2
0
        public static Task <DownloadResponse> DownloadDataAsync(DownloadRequest downloadRequest,
                                                                CancellationToken cancellationToken, IThroughputHistory throughputHistory)
        {
            var dashDownloader = new DashDownloader(downloadRequest, cancellationToken, throughputHistory);

            return(dashDownloader.DownloadInternalAsync());
        }