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); } })); }
public static Task <DownloadResponse> DownloadDataAsync(DownloadRequest downloadRequest, CancellationToken cancellationToken, IThroughputHistory throughputHistory) { var dashDownloader = new DashDownloader(downloadRequest, cancellationToken, throughputHistory); return(dashDownloader.DownloadInternalAsync()); }
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; }
public DashDownloaderException(DownloadRequest request, string message, Exception inner) : base(message, inner) { DownloadRequest = request; }
public DashDownloaderException(DownloadRequest request, string message, Exception inner, HttpStatusCode statusCode) : base(message, inner) { DownloadRequest = request; StatusCode = statusCode; }